]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: don't bother tracking is_dir
authorSasha Levin <levinsasha928@gmail.com>
Sun, 22 Jul 2012 16:29:54 +0000 (18:29 +0200)
committerPekka Enberg <penberg@kernel.org>
Sat, 4 Aug 2012 09:13:02 +0000 (12:13 +0300)
This is something we can calculate on the fly, and doesn't justify the overhead
of tracking it all over fid transitions.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/include/kvm/virtio-9p.h
tools/kvm/virtio/9p.c

index 186fe05ddbc539d26d7befd9e527ca08089431d9..cb590d185db3b0e5f9f9b45c6d94869f5f982e9b 100644 (file)
@@ -26,7 +26,6 @@ struct p9_msg {
 struct p9_fid {
        u32                     fid;
        u32                     uid;
-       u8                      is_dir;
        char                    abs_path[PATH_MAX];
        char                    *path;
        DIR                     *dir;
index 99279f19ead1fddd2e0502139d43649298881e49..27ef57b8d06dea17516b458b42dec2956e6a636e 100644 (file)
@@ -228,6 +228,15 @@ static int virtio_p9_openflags(int flags)
        return flags;
 }
 
+static bool is_dir(struct p9_fid *fid)
+{
+       struct stat st;
+
+       stat(fid->abs_path, &st);
+
+       return S_ISDIR(st.st_mode);
+}
+
 static void virtio_p9_open(struct p9_dev *p9dev,
                           struct p9_pdu *pdu, u32 *outlen)
 {
@@ -245,7 +254,7 @@ static void virtio_p9_open(struct p9_dev *p9dev,
 
        stat2qid(&st, &qid);
 
-       if (new_fid->is_dir) {
+       if (is_dir(new_fid)) {
                new_fid->dir = opendir(new_fid->abs_path);
                if (!new_fid->dir)
                        goto err_out;
@@ -394,7 +403,6 @@ static void virtio_p9_walk(struct p9_dev *p9dev,
                                goto err_out;
 
                        stat2qid(&st, &wqid);
-                       new_fid->is_dir = S_ISDIR(st.st_mode);
                        strcpy(new_fid->path, tmp);
                        new_fid->uid = fid->uid;
                        nwqid++;
@@ -406,7 +414,6 @@ static void virtio_p9_walk(struct p9_dev *p9dev,
                 */
                pdu->write_offset += sizeof(u16);
                old_fid = get_fid(p9dev, fid_val);
-               new_fid->is_dir = old_fid->is_dir;
                strcpy(new_fid->path, old_fid->path);
                new_fid->uid    = old_fid->uid;
        }
@@ -445,7 +452,6 @@ static void virtio_p9_attach(struct p9_dev *p9dev,
 
        fid = get_fid(p9dev, fid_val);
        fid->uid = uid;
-       fid->is_dir = 1;
        strcpy(fid->path, "/");
 
        virtio_p9_pdu_writef(pdu, "Q", &qid);
@@ -547,7 +553,7 @@ static void virtio_p9_readdir(struct p9_dev *p9dev,
        virtio_p9_pdu_readf(pdu, "dqd", &fid_val, &offset, &count);
        fid = get_fid(p9dev, fid_val);
 
-       if (!fid->is_dir) {
+       if (!is_dir(fid)) {
                errno = EINVAL;
                goto err_out;
        }