Skip to contentSkip to conversation

virtio-9p: Add fidtype so that we can do type specific operation

PATCH New Aneesh Kumar K.V 1 participant 4 messages Jun 1, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 virtio-9p: Add fidtype so that we can do type specific operation

We want to add type specific operation during read/write

---
 hw/virtio-9p.c |   99 +++++++++++++++++++++++++++++++-------------------------
 hw/virtio-9p.h |   24 ++++++++++++-
 2 files changed, 77 insertions(+), 46 deletions(-)
hw/virtio-9p.c +55 -44
index 1c7a428..2558e0e 100644
@@ -415,8 +415,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
     f = qemu_mallocz(sizeof(V9fsFidState));
 
     f->fid = fid;
-    f->fd = -1;
-    f->dir = NULL;
+    f->fid_type = P9_FID_NONE;
 
     f->next = s->fid_list;
     s->fid_list = f;
@@ -441,11 +440,20 @@ static int free_fid(V9fsState *s, int32_t fid)
     fidp = *fidpp;
     *fidpp = fidp->next;
 
-    if (fidp->fd != -1) {
-        v9fs_do_close(s, fidp->fd);
+    if (fidp->fid_type == P9_FID_FILE) {
+        if (fidp->fs.fd != -1) {
+	    v9fs_do_close(s, fidp->fs.fd);
+        }
+    }
+    if (fidp->fid_type == P9_FID_DIR) {
+        if (fidp->fs.dir) {
+	    v9fs_do_closedir(s, fidp->fs.dir);
+        }
     }
-    if (fidp->dir) {
-        v9fs_do_closedir(s, fidp->dir);
+    if (fidp->fid_type == P9_FID_XATTR) {
+	if (fidp->fs.xattr.value) {
+	    qemu_free(fidp->fs.xattr.value);
+	}
     }
     v9fs_string_free(&fidp->path);
     qemu_free(fidp);
@@ -1343,8 +1351,7 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
     /* FIXME: is this really valid? */
     if (fid == newfid) {
 
-        BUG_ON(vs->fidp->fd != -1);
-        BUG_ON(vs->fidp->dir);
+        BUG_ON(vs->fidp->fid_type != P9_FID_NONE);
         v9fs_string_init(&vs->path);
         vs->name_idx = 0;
 
@@ -1388,11 +1395,12 @@ out:
 
 static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err)
 {
-    if (vs->fidp->dir == NULL) {
+    if (vs->fidp->fs.dir == NULL) {
         err = -errno;
         goto out;
     }
 
+    vs->fidp->fid_type = P9_FID_DIR;
     vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0);
     err = vs->offset;
 out:
@@ -1403,11 +1411,12 @@ out:
 
 static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err)
 {
-    if (vs->fidp->fd == -1) {
+    if (vs->fidp->fs.fd == -1) {
         err = -errno;
         goto out;
     }
 
+    vs->fidp->fid_type = P9_FID_FILE;
     vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0);
     err = vs->offset;
 out:
@@ -1425,10 +1434,10 @@ static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
     stat_to_qid(&vs->stbuf, &vs->qid);
 
     if (S_ISDIR(vs->stbuf.st_mode)) {
-        vs->fidp->dir = v9fs_do_opendir(s, &vs->fidp->path);
+        vs->fidp->fs.dir = v9fs_do_opendir(s, &vs->fidp->path);
         v9fs_open_post_opendir(s, vs, err);
     } else {
-        vs->fidp->fd = v9fs_do_open(s, &vs->fidp->path,
+        vs->fidp->fs.fd = v9fs_do_open(s, &vs->fidp->path,
                                     omode_to_uflags(vs->mode));
         v9fs_open_post_open(s, vs, err);
     }
@@ -1457,8 +1466,7 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
         goto out;
     }
 
-    BUG_ON(vs->fidp->fd != -1);
-    BUG_ON(vs->fidp->dir);
+    BUG_ON(vs->fidp->fid_type != P9_FID_NONE);
 
     err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf);
 
@@ -1522,7 +1530,7 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, V9fsReadState *vs,
                             &vs->v9stat);
     if ((vs->len != (vs->v9stat.size + 2)) ||
             ((vs->count + vs->len) > vs->max_count)) {
-        v9fs_do_seekdir(s, vs->fidp->dir, vs->dir_pos);
+        v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->dir_pos);
         v9fs_read_post_seekdir(s, vs, err);
         return;
     }
@@ -1530,11 +1538,11 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, V9fsReadState *vs,
     v9fs_stat_free(&vs->v9stat);
     v9fs_string_free(&vs->name);
     vs->dir_pos = vs->dent->d_off;
-    vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+    vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir);
     v9fs_read_post_readdir(s, vs, err);
     return;
 out:
-    v9fs_do_seekdir(s, vs->fidp->dir, vs->dir_pos);
+    v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->dir_pos);
     v9fs_read_post_seekdir(s, vs, err);
     return;
 
@@ -1562,7 +1570,7 @@ static void v9fs_read_post_readdir(V9fsState *s, V9fsReadState *vs, ssize_t err)
 
 static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t err)
 {
-    vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+    vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir);
     v9fs_read_post_readdir(s, vs, err);
     return;
 }
@@ -1570,7 +1578,7 @@ static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t err)
 static void v9fs_read_post_rewinddir(V9fsState *s, V9fsReadState *vs,
                                        ssize_t err)
 {
-    vs->dir_pos = v9fs_do_telldir(s, vs->fidp->dir);
+    vs->dir_pos = v9fs_do_telldir(s, vs->fidp->fs.dir);
     v9fs_read_post_telldir(s, vs, err);
     return;
 }
@@ -1589,7 +1597,7 @@ static void v9fs_read_post_readv(V9fsState *s, V9fsReadState *vs, ssize_t err)
             if (0) {
                 print_sg(vs->sg, vs->cnt);
             }
-            vs->len = v9fs_do_readv(s, vs->fidp->fd, vs->sg, vs->cnt);
+            vs->len = v9fs_do_readv(s, vs->fidp->fs.fd, vs->sg, vs->cnt);
         } while (vs->len == -1 && errno == EINTR);
         if (vs->len == -1) {
             err  = -errno;
@@ -1619,7 +1627,7 @@ static void v9fs_read_post_lseek(V9fsState *s, V9fsReadState *vs, ssize_t err)
             if (0) {
                 print_sg(vs->sg, vs->cnt);
             }
-            vs->len = v9fs_do_readv(s, vs->fidp->fd, vs->sg, vs->cnt);
+            vs->len = v9fs_do_readv(s, vs->fidp->fs.fd, vs->sg, vs->cnt);
         } while (vs->len == -1 && errno == EINTR);
         if (vs->len == -1) {
             err  = -errno;
@@ -1653,18 +1661,18 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
         goto out;
     }
 
-    if (vs->fidp->dir) {
+    if (vs->fidp->fs.dir) {
         vs->max_count = vs->count;
         vs->count = 0;
         if (vs->off == 0) {
-            v9fs_do_rewinddir(s, vs->fidp->dir);
+            v9fs_do_rewinddir(s, vs->fidp->fs.dir);
         }
         v9fs_read_post_rewinddir(s, vs, err);
         return;
-    } else if (vs->fidp->fd != -1) {
+    } else if (vs->fidp->fs.fd != -1) {
         vs->sg = vs->iov;
         pdu_marshal(vs->pdu, vs->offset + 4, "v", vs->sg, &vs->cnt);
-        err = v9fs_do_lseek(s, vs->fidp->fd, vs->off, SEEK_SET);
+        err = v9fs_do_lseek(s, vs->fidp->fs.fd, vs->off, SEEK_SET);
         v9fs_read_post_lseek(s, vs, err);
         return;
     } else {
@@ -1711,7 +1719,7 @@ static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs)
 
         if ((vs->count + V9_READDIR_DATA_SZ) > vs->max_count) {
             /* Ran out of buffer. Set dir back to old position and return */
-            v9fs_do_seekdir(s, vs->fidp->dir, vs->saved_dir_pos);
+            v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->saved_dir_pos);
             v9fs_readdir_post_seekdir(s, vs);
             return;
         }
@@ -1722,7 +1730,7 @@ static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs)
         vs->count += len;
         v9fs_string_free(&vs->name);
         vs->saved_dir_pos = vs->dent->d_off;
-        vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+        vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir);
         v9fs_readdir_post_readdir(s, vs);
         return;
     }
@@ -1736,14 +1744,14 @@ static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs)
 
 static void v9fs_readdir_post_telldir(V9fsState *s, V9fsReadDirState *vs)
 {
-    vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+    vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir);
     v9fs_readdir_post_readdir(s, vs);
     return;
 }
 
 static void v9fs_readdir_post_setdir(V9fsState *s, V9fsReadDirState *vs)
 {
-    vs->saved_dir_pos = v9fs_do_telldir(s, vs->fidp->dir);
+    vs->saved_dir_pos = v9fs_do_telldir(s, vs->fidp->fs.dir);
     v9fs_readdir_post_telldir(s, vs);
     return;
 }
@@ -1764,15 +1772,17 @@ static void v9fs_readdir(V9fsState *s, V9fsPDU *pdu)
                                                         &vs->max_count);
 
     vs->fidp = lookup_fid(s, fid);
-    if (vs->fidp == NULL || !(vs->fidp->dir)) {
+    if (vs->fidp == NULL ||
+        vs->fidp->fid_type != P9_FID_DIR ||
+        !(vs->fidp->fs.dir)) {
         err = -EINVAL;
         goto out;
     }
 
     if (vs->initial_offset == 0) {
-        v9fs_do_rewinddir(s, vs->fidp->dir);
+        v9fs_do_rewinddir(s, vs->fidp->fs.dir);
     } else {
-        v9fs_do_seekdir(s, vs->fidp->dir, vs->initial_offset);
+        v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->initial_offset);
     }
 
     v9fs_readdir_post_setdir(s, vs);
@@ -1799,7 +1809,7 @@ static void v9fs_write_post_writev(V9fsState *s, V9fsWriteState *vs,
             if (0) {
                 print_sg(vs->sg, vs->cnt);
             }
-            vs->len =  v9fs_do_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
+            vs->len =  v9fs_do_writev(s, vs->fidp->fs.fd, vs->sg, vs->cnt);
         } while (vs->len == -1 && errno == EINTR);
         if (vs->len == -1) {
             err  = -errno;
@@ -1828,7 +1838,7 @@ static void v9fs_write_post_lseek(V9fsState *s, V9fsWriteState *vs, ssize_t err)
             if (0) {
                 print_sg(vs->sg, vs->cnt);
             }
-            vs->len = v9fs_do_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
+            vs->len = v9fs_do_writev(s, vs->fidp->fs.fd, vs->sg, vs->cnt);
         } while (vs->len == -1 && errno == EINTR);
         if (vs->len == -1) {
             err  = -errno;
@@ -1865,12 +1875,12 @@ static void v9fs_write(V9fsState *s, V9fsPDU *pdu)
         goto out;
     }
 
-    if (vs->fidp->fd == -1) {
+    if (vs->fidp->fs.fd == -1) {
         err = -EINVAL;
         goto out;
     }
 
-    err = v9fs_do_lseek(s, vs->fidp->fd, vs->off, SEEK_SET);
+    err = v9fs_do_lseek(s, vs->fidp->fs.fd, vs->off, SEEK_SET);
 
     v9fs_write_post_lseek(s, vs, err);
     return;
@@ -1909,9 +1919,10 @@ static void v9fs_create_post_perms(V9fsState *s, V9fsCreateState *vs, int err)
 static void v9fs_create_post_opendir(V9fsState *s, V9fsCreateState *vs,
                                                                     int err)
 {
-    if (!vs->fidp->dir) {
+    if (!vs->fidp->fs.dir) {
         err = -errno;
     }
+    vs->fidp->fid_type = P9_FID_DIR;
     v9fs_post_create(s, vs, err);
 }
 
@@ -1923,7 +1934,7 @@ static void v9fs_create_post_dir_lstat(V9fsState *s, V9fsCreateState *vs,
         goto out;
     }
 
-    vs->fidp->dir = v9fs_do_opendir(s, &vs->fullname);
+    vs->fidp->fs.dir = v9fs_do_opendir(s, &vs->fullname);
     v9fs_create_post_opendir(s, vs, err);
     return;
 
@@ -1949,7 +1960,7 @@ out:
 static void v9fs_create_post_fstat(V9fsState *s, V9fsCreateState *vs, int err)
 {
     if (err) {
-        vs->fidp->fd = -1;
+        vs->fidp->fs.fd = -1;
         err = -errno;
     }
 
@@ -1959,12 +1970,12 @@ static void v9fs_create_post_fstat(V9fsState *s, V9fsCreateState *vs, int err)
 
 static void v9fs_create_post_open2(V9fsState *s, V9fsCreateState *vs, int err)
 {
-    if (vs->fidp->fd == -1) {
+    if (vs->fidp->fs.fd == -1) {
         err = -errno;
         goto out;
     }
-
-    err = v9fs_do_fstat(s, vs->fidp->fd, &vs->stbuf);
+    vs->fidp->fid_type = P9_FID_FILE;
+    err = v9fs_do_fstat(s, vs->fidp->fs.fd, &vs->stbuf);
     v9fs_create_post_fstat(s, vs, err);
 
     return;
@@ -2031,7 +2042,7 @@ static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err)
         err = v9fs_do_mknod(s, vs, S_IFSOCK | (vs->perm & 0777), 0);
         v9fs_post_create(s, vs, err);
     } else {
-        vs->fidp->fd = v9fs_do_open2(s, vs);
+        vs->fidp->fs.fd = v9fs_do_open2(s, vs);
         v9fs_create_post_open2(s, vs, err);
     }
 
@@ -2420,7 +2431,7 @@ static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu)
 
     /* do we need to sync the file? */
     if (donttouch_stat(&vs->v9stat)) {
-        err = v9fs_do_fsync(s, vs->fidp->fd);
+        err = v9fs_do_fsync(s, vs->fidp->fs.fd);
         v9fs_wstat_post_fsync(s, vs, err);
         return;
     }
hw/virtio-9p.h +22 -2
index d033271..942e448 100644
@@ -137,12 +137,32 @@ typedef struct V9fsStat
     int32_t n_muid;
 } V9fsStat;
 
+enum {
+    P9_FID_NONE = 0,
+    P9_FID_FILE,
+    P9_FID_DIR,
+    P9_FID_XATTR,
+};
+
+typedef struct V9fsXattr
+{
+    int64_t copied_len;
+    int64_t len;
+    void *value;
+    V9fsString name;
+    int flags;
+} V9fsXattr;
+
 struct V9fsFidState
 {
+    int fid_type;
     int32_t fid;
     V9fsString path;
-    int fd;
-    DIR *dir;
+    union {
+	int fd;
+	DIR *dir;
+	V9fsXattr xattr;
+    } fs;
     uid_t uid;
     V9fsFidState *next;
 };
Signature · 1 line
1.7.1.236.g81fa0
#1 lore raw

PATCH 2/4 virtio-9p: Implement TXATTRWALK

TXATTRWALK: Descend a ATTR namespace

size[4] TXATTRWALK tag[2] fid[4] newfid[4] name[s] size [4] RXATTRWALK tag[2] size[8]

txattrwalk gets a fid pointing to xattr. This fid can later be used to get read the xattr value. If name is NULL the fid returned can be used to get the list of extended attribute associated to the file system object.

---
 hw/file-op-9p.h      |    2 +
 hw/virtio-9p-debug.c |   10 +++
 hw/virtio-9p-local.c |   14 ++++
 hw/virtio-9p.c       |  202 +++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/virtio-9p.h       |    2 +
 5 files changed, 228 insertions(+), 2 deletions(-)
hw/file-op-9p.h +2 -0
index 120c803..d5bab9a 100644
@@ -75,6 +75,8 @@ typedef struct FileOperations
     int (*truncate)(FsContext *, const char *, off_t);
     int (*fsync)(FsContext *, int);
     int (*statfs)(FsContext *s, const char *path, struct statfs *stbuf);
+    int (*lgetxattr)(FsContext *, const char *, const char *, void *, size_t);
+    int (*llistxattr)(FsContext *, const char *, void *, size_t);
     void *opaque;
 } FileOperations;
 #endif
hw/virtio-9p-debug.c +10 -0
index 7325418..5be1670 100644
@@ -540,6 +540,16 @@ void pprint_pdu(V9fsPDU *pdu)
     case P9_RWSTAT:
         fprintf(llogfile, "RWSTAT: (");
         break;
+    case P9_TXATTRWALK:
+        fprintf(llogfile, "TXATTRWALK: (");
+        pprint_int32(pdu, 0, &offset, "fid");
+        pprint_int32(pdu, 0, &offset, ", newfid");
+        pprint_str(pdu, 0, &offset, ", xattr name");
+        break;
+    case P9_RXATTRWALK:
+        fprintf(llogfile, "RXATTRWALK: (");
+        pprint_int64(pdu, 1, &offset, "xattrsize");
+        break;
     default:
         fprintf(llogfile, "unknown(%d): (", pdu->id);
         break;
hw/virtio-9p-local.c +14 -0
index dd60354..97b1544 100644
@@ -472,6 +472,18 @@ static int local_statfs(FsContext *s, const char *path, struct statfs *stbuf)
    return statfs(rpath(s, path), stbuf);
 }
 
+static int local_lgetxattr(FsContext *ctx, const char *path, const char *name,
+                           void *value, size_t size)
+{
+    return lgetxattr(rpath(ctx, path), name, value, size);
+}
+
+static int local_llistxattr(FsContext *ctx, const char *path,
+                            void *value, size_t size)
+{
+    return llistxattr(rpath(ctx, path), value, size);
+}
+
 FileOperations local_ops = {
     .lstat = local_lstat,
     .readlink = local_readlink,
@@ -500,4 +512,6 @@ FileOperations local_ops = {
     .remove = local_remove,
     .fsync = local_fsync,
     .statfs = local_statfs,
+    .lgetxattr = local_lgetxattr,
+    .llistxattr = local_llistxattr,
 };
hw/virtio-9p.c +200 -2

243 lines not on this page · raw message

hw/virtio-9p.h +2 -0
index 942e448..c534923 100644
@@ -19,6 +19,8 @@ enum {
     P9_RSYMLINK,
     P9_TGETATTR = 24,
     P9_RGETATTR,
+    P9_TXATTRWALK = 30,
+    P9_RXATTRWALK,
     P9_TREADDIR = 40,
     P9_RREADDIR,
     P9_TLINK = 70,
Signature · 1 line
1.7.1.236.g81fa0
#3 lore raw

PATCH 4/4 virtio-9p: Hide user.virtfs xattr in case of mapped security.

In reply to Aneesh Kumar K.V

With mapped security mode we use "user.virtfs" namespace is used to store the virtFs related attributes. So hide it from user.

---
 hw/virtio-9p-local.c |   73 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 71 insertions(+), 2 deletions(-)
hw/virtio-9p-local.c +71 -2
index 4799fa9..a52e9e8 100644
@@ -475,18 +475,87 @@ static int local_statfs(FsContext *s, const char *path, struct statfs *stbuf)
 static int local_lgetxattr(FsContext *ctx, const char *path, const char *name,
                            void *value, size_t size)
 {
+
+    if ((ctx->fs_sm == SM_MAPPED) &&
+        (strncmp(name, "user.virtfs.", 12) == 0)) {
+        /*
+         * Don't allow fetch of user.virtfs namesapce
+         * in case of mapped security
+         */
+        errno = ENOATTR;
+        return -1;
+    }
     return lgetxattr(rpath(ctx, path), name, value, size);
 }
 
-static int local_llistxattr(FsContext *ctx, const char *path,
+static ssize_t local_llistxattr(FsContext *ctx, const char *path,
                             void *value, size_t size)
 {
-    return llistxattr(rpath(ctx, path), value, size);
+    ssize_t retval;
+    ssize_t actual_len = 0;
+    char *orig_value, *orig_value_start;
+    char *temp_value, *temp_value_start;
+    ssize_t xattr_len, parsed_len = 0, attr_len;
+
+    if (ctx->fs_sm != SM_MAPPED) {
+        return llistxattr(rpath(ctx, path), value, size);
+    }
+
+    /* Get the actual len */
+    xattr_len = llistxattr(rpath(ctx, path), value, 0);
+
+    /* Now fetch the xattr and find the actual size */
+    orig_value = qemu_malloc(xattr_len);
+    xattr_len = llistxattr(rpath(ctx, path), orig_value, xattr_len);
+
+    /*
+     * For mapped security model drop user.virtfs namespace
+     * from the list
+     */
+    temp_value = qemu_mallocz(xattr_len);
+    temp_value_start = temp_value;
+    orig_value_start = orig_value;
+    while (xattr_len > parsed_len) {
+        attr_len = strlen(orig_value) + 1;
+        if (strncmp(orig_value, "user.virtfs.", 12) != 0) {
+            /* Copy this entry */
+            strcat(temp_value, orig_value);
+            temp_value  += attr_len;
+            actual_len += attr_len;
+        }
+        parsed_len += attr_len;
+        orig_value += attr_len;
+    }
+    if (!size) {
+        retval = actual_len;
+        goto out;
+    } else if (size >= actual_len) {
+        /* now copy the parsed attribute list back */
+        memset(value, 0, size);
+        memcpy(value, temp_value_start, actual_len);
+        retval = actual_len;
+        goto out;
+    }
+    errno = ERANGE;
+    retval = -1;
+out:
+    qemu_free(orig_value_start);
+    qemu_free(temp_value_start);
+    return retval;
 }
 
 static int local_lsetxattr(FsContext *ctx, const char *path, const char *name,
 			   void *value, size_t size, int flags)
 {
+    if ((ctx->fs_sm == SM_MAPPED) &&
+        (strncmp(name, "user.virtfs.", 12) == 0)) {
+        /*
+         * Don't allow fetch of user.virtfs namesapce
+         * in case of mapped security
+         */
+        errno = EACCES;
+        return -1;
+    }
     return lsetxattr(rpath(ctx, path), name, value, size, flags);
 }
 
Signature · 1 line
1.7.1.236.g81fa0
#2 lore raw

PATCH 3/4 virtio-9p: Implement TXATTRCREATE

In reply to Aneesh Kumar K.V

TXATTRCREATE: Prepare a fid for setting xattr value on a file system object.

size[4] TXATTRCREATE tag[2] fid[4] name[s] attr_size[8] flags[4] size[4] RXATTRWALK tag[2]

txattrcreate gets a fid pointing to xattr. This fid can later be used to get set the xattr value.

flag value is derived from set Linux setxattr. The manpage says "The flags parameter can be used to refine the semantics of the operation. XATTR_CREATE specifies a pure create, which fails if the named attribute exists already. XATTR_REPLACE specifies a pure replace operation, which fails if the named attribute does not already exist. By default (no flags), the extended attribute will be created if need be, or will simply replace the value if the attribute exists."

The actual setxattr operation happens when the fid is clunked. At that point the written byte count and the attr_size specified in TXATTRCREATE should be same otherwise an error will be returned.

---
 hw/file-op-9p.h      |    1 +
 hw/virtio-9p-debug.c |   10 ++++
 hw/virtio-9p-local.c |    7 +++
 hw/virtio-9p.c       |  145 ++++++++++++++++++++++++++++++++++++++++++++++---
 hw/virtio-9p.h       |    2 +
 5 files changed, 156 insertions(+), 9 deletions(-)
hw/file-op-9p.h +1 -0
index d5bab9a..a33fc9c 100644
@@ -77,6 +77,7 @@ typedef struct FileOperations
     int (*statfs)(FsContext *s, const char *path, struct statfs *stbuf);
     int (*lgetxattr)(FsContext *, const char *, const char *, void *, size_t);
     int (*llistxattr)(FsContext *, const char *, void *, size_t);
+    int (*lsetxattr)(FsContext *, const char *, const char *, void *, size_t, int);
     void *opaque;
 } FileOperations;
 #endif
hw/virtio-9p-debug.c +10 -0
index 5be1670..0916a07 100644
@@ -550,6 +550,16 @@ void pprint_pdu(V9fsPDU *pdu)
         fprintf(llogfile, "RXATTRWALK: (");
         pprint_int64(pdu, 1, &offset, "xattrsize");
         break;
+    case P9_TXATTRCREATE:
+        fprintf(llogfile, "TXATTRCREATE: (");
+        pprint_int32(pdu, 0, &offset, "fid");
+        pprint_str(pdu, 0, &offset, ", name");
+        pprint_int64(pdu, 0, &offset, ", xattrsize");
+        pprint_int32(pdu, 0, &offset, ", flags");
+        break;
+    case P9_RXATTRCREATE:
+        fprintf(llogfile, "RXATTRCREATE: (");
+        break;
     default:
         fprintf(llogfile, "unknown(%d): (", pdu->id);
         break;
hw/virtio-9p-local.c +7 -0
index 97b1544..4799fa9 100644
@@ -484,6 +484,12 @@ static int local_llistxattr(FsContext *ctx, const char *path,
     return llistxattr(rpath(ctx, path), value, size);
 }
 
+static int local_lsetxattr(FsContext *ctx, const char *path, const char *name,
+			   void *value, size_t size, int flags)
+{
+    return lsetxattr(rpath(ctx, path), name, value, size, flags);
+}
+
 FileOperations local_ops = {
     .lstat = local_lstat,
     .readlink = local_readlink,
@@ -514,4 +520,5 @@ FileOperations local_ops = {
     .statfs = local_statfs,
     .lgetxattr = local_lgetxattr,
     .llistxattr = local_llistxattr,
+    .lsetxattr = local_lsetxattr,
 };
hw/virtio-9p.c +136 -9

200 lines not on this page · raw message

hw/virtio-9p.h +2 -0
index c534923..172eb3d 100644
@@ -21,6 +21,8 @@ enum {
     P9_RGETATTR,
     P9_TXATTRWALK = 30,
     P9_RXATTRWALK,
+    P9_TXATTRCREATE = 32,
+    P9_RXATTRCREATE,
     P9_TREADDIR = 40,
     P9_RREADDIR,
     P9_TLINK = 70,
Signature · 1 line
1.7.1.236.g81fa0