Consolidated VirtFS work
v5 cover Consolidated VirtFS work
This patch series is a consolidated view of various VirtFS patches on the Mailing List. None of these patches are new in this series. For sometime all these patches were on the mainling list individually.
Changes from V4:
- Added two patches:
o 0024-virtio-9p-Add-support-for-removing-xattr.patch
o 0025-virtio-9p-Make-sure-virtfs-option-works-correctly.patch
Changes from V3:
- Rebased to latest master.
Changes from V2:
- Couple of formatting issues
- Fixed fid_type checks in BUG_ON()
PATCH v5 1/28 qemu: virtio-9p: Recognize 9P2000.L protocol
From: M. Mohan Kumar <[email protected]>
Make 9P server recognize 9P2000.L protocol version
--- hw/virtio-9p.c | 6 +++++- hw/virtio-9p.h | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletions(-)
hw/virtio-9p.c +5 -1
@@ -1025,7 +1025,11 @@ static void v9fs_version(V9fsState *s, V9fsPDU *pdu)pdu_unmarshal (pdu, offset,"ds" , &msize, &version); -if (strcmp (version.data,"9P2000.u" )) { +if (!strcmp (version.data,"9P2000.u" )) { + s->proto_version =V9FS_PROTO_2000U ; + }else if (!strcmp (version.data,"9P2000.L" )) { + s->proto_version =V9FS_PROTO_2000L ; + }else {v9fs_string_sprintf (&version,"unknown" ); }
hw/virtio-9p.h +6 -0
@@ -57,6 +57,11 @@ enum { P9_QTFILE = 0x00, }; +enum p9_proto_version { +V9FS_PROTO_2000U =0x01 , +V9FS_PROTO_2000L =0x02 , +}; +#define P9_NOTAG (u16)(~0)#define P9_NOFID (u32)(~0)#define P9_MAXWELEM 16
@@ -144,6 +149,7 @@ typedef struct V9fsStateuint16_t tag_len;uint8_t *tag;size_t config_size; +enum p9_proto_version proto_version; } V9fsState; typedef struct V9fsCreateState {
Signature · 1 line
1.6.5.2
PATCH v4 4/28 virtio-9p: readdir implementation for 9p2000.L
In reply to Venkateswararao Jujjuri (JV)From: Sripathi Kodi <[email protected]>
This patch implements the server part of readdir() implementation for 9p2000.L
SYNOPSIS
size[4] Treaddir tag[2] fid[4] offset[8] count[4] size[4] Rreaddir tag[2] count[4] data[count]
DESCRIPTION
The readdir request asks the server to read the directory specified by 'fid' at an offset specified by 'offset' and return as many dirent structures as possible that fit into count bytes. Each dirent structure is laid out as follows.
qid.type[1]
the type of the file (directory, etc.), represented as a bit vector corresponding to the high 8 bits of the file's mode word.
qid.vers[4]
version number for given path
qid.path[8]
the file server's unique identification for the file
offset[8]
offset into the next dirent.
type[1]
type of this directory entry.
name[256]
name of this directory entry.
--- hw/virtio-9p-debug.c | 13 +++++ hw/virtio-9p.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p.h | 2 + 3 files changed, 137 insertions(+), 0 deletions(-)
hw/virtio-9p-debug.c +13 -0
@@ -330,6 +330,19 @@ void pprint_pdu(V9fsPDU *pdu)BUG_ON (!llogfile);switch (pdu->id) { +case P9_TREADDIR : +fprintf (llogfile,"TREADDIR: (" ); +pprint_int32 (pdu,0 , &offset,"fid" ); +pprint_int64 (pdu,0 , &offset,", initial offset" ); +pprint_int32 (pdu,0 , &offset,", max count" ); +break ; +case P9_RREADDIR : +fprintf (llogfile,"RREADDIR: (" ); +pprint_int32 (pdu,1 , &offset,"count" ); +#ifdef DEBUG_DATA +pprint_data (pdu,1 , &offset,", data" ); +#endif +break ;case P9_TVERSION :fprintf (llogfile,"TVERSION: (" );pprint_int32 (pdu,0 , &offset,"msize" );
hw/virtio-9p.c +122 -0
134 lines not on this page · raw message
hw/virtio-9p.h +2 -0
@@ -15,6 +15,8 @@enum {P9_TSTATFS =8 ,P9_RSTATFS , +P9_TREADDIR =40 , +P9_RREADDIR ,P9_TVERSION =100 ,P9_RVERSION ,P9_TAUTH =102 ,
Signature · 1 line
1.6.5.2
PATCH v5 2/28 qemu: virtio-9p: Implement statfs support in server
In reply to Venkateswararao Jujjuri (JV)From: M. Mohan Kumar <[email protected]>
Implement statfs support in qemu server based on Sripathi's initial statfs patch.
--- hw/file-op-9p.h | 1 + hw/virtio-9p-local.c | 6 ++++ hw/virtio-9p.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p.h | 24 +++++++++++++++++++ 4 files changed, 94 insertions(+), 0 deletions(-)
hw/file-op-9p.h +1 -0
@@ -74,6 +74,7 @@ typedef struct FileOperationsint (*rename)(FsContext *,const char *,const char *);int (*truncate)(FsContext *,const char *,off_t );int (*fsync)(FsContext *,int ); +int (*statfs)(FsContext *s,const char *path,struct statfs *stbuf); void *opaque; } FileOperations;#endif
hw/virtio-9p-local.c +6 -0
@@ -466,6 +466,11 @@ static int local_fsync(FsContext *ctx, int fd)return fsync (fd); } +static int local_statfs (FsContext *s,const char *path,struct statfs *stbuf) +{ +return statfs (rpath (s, path), stbuf); +} +FileOperations local_ops = { .lstat = local_lstat, .readlink = local_readlink,
@@ -493,4 +498,5 @@ FileOperations local_ops = { .utime = local_utime, .remove = local_remove, .fsync = local_fsync, + .statfs = local_statfs, };
hw/virtio-9p.c +63 -0
72 lines not on this page · raw message
hw/virtio-9p.h +24 -0
@@ -13,6 +13,8 @@#define VIRTIO_9P_MOUNT_TAG 0enum { +P9_TSTATFS =8 , +P9_RSTATFS ,P9_TVERSION =100 ,P9_RVERSION ,P9_TAUTH =102 ,
@@ -252,6 +254,28 @@ struct virtio_9p_configuint8_t tag[0 ]; } __attribute__((packed)); +typedef struct V9fsStatfs +{ +uint32_t f_type; +uint32_t f_bsize; +uint64_t f_blocks; +uint64_t f_bfree; +uint64_t f_bavail; +uint64_t f_files; +uint64_t f_ffree; +uint64_t fsid_val; +uint32_t f_namelen; +}V9fsStatfs ; + +typedef struct V9fsStatfsState { +V9fsPDU *pdu; +size_t offset; +int32_t fid; +V9fsStatfs v9statfs; +V9fsFidState *fidp; +struct statfs stbuf; +}V9fsStatfsState ; +extern size_t pdu_packunpack (void *addr,struct iovec *sg,int sg_count,size_t offset,size_t size,int pack);
Signature · 1 line
1.6.5.2
PATCH v5 3/28 virtio-9p: Return correct error from v9fs_remove
In reply to Venkateswararao Jujjuri (JV)From: Sripathi Kodi <[email protected]>
In v9fs_remove_post_remove() we currently ignore the error returned by the previous call to remove() and return an error only if freeing the fid fails. However, the client expects to see the error from remove(). Currently the client falsely thinks that the remove call has always succeeded. For example, doing rmdir on a non-empty directory does not return ENOTEMPTY.
With this patch we ignore the error from free_fid(). The client cannot use this error value anyway.
--- hw/virtio-9p.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
hw/virtio-9p.c +6 -5
@@ -1877,14 +1877,15 @@ static void v9fs_flush(V9fsState *s, V9fsPDU *pdu)static void v9fs_remove_post_remove (V9fsState *s,V9fsRemoveState *vs,int err) { -/* For TREMOVE we need to clunk the fid even on failed remove */ - err =free_fid (s, vs->fidp->fid);if (err <0 ) { - goto out; + err = -errno; + }else { + err = vs->offset; } - err = vs->offset; -out: +/* For TREMOVE we need to clunk the fid even on failed remove */ +free_fid (s, vs->fidp->fid); +complete_pdu (s, vs->pdu, err);qemu_free (vs); }
Signature · 1 line
1.6.5.2
PATCH v5 5/28 virtio-9p: Compute iounit based on host filesystem block size
In reply to Venkateswararao Jujjuri (JV)From: M. Mohan Kumar <[email protected]>
Compute iounit based on the host filesystem block size and pass it to client with open/create response. Also return iounit as statfs's f_bsize for optimal block size transfers.
--- hw/virtio-9p.c | 96 +++++++++++++++++++++++++++++++++++++++++++++----------- hw/virtio-9p.h | 9 +++++ 2 files changed, 86 insertions(+), 19 deletions(-)
hw/virtio-9p.c +77 -19
@@ -253,6 +253,11 @@ static int v9fs_do_fsync(V9fsState *s, int fd)return s->ops->fsync (&s->ctx, fd); } +static int v9fs_do_statfs (V9fsState *s,V9fsString *path,struct statfs *stbuf) +{ +return s->ops->statfs (&s->ctx, path->data, stbuf); +} +static void v9fs_string_init (V9fsString *str) { str->data =NULL ;
@@ -1019,11 +1024,10 @@ static void v9fs_fix_path(V9fsString *dst, V9fsString *src, int len)static void v9fs_version (V9fsState *s,V9fsPDU *pdu) { -int32_t msize;V9fsString version;size_t offset =7 ; -pdu_unmarshal (pdu, offset,"ds" , &msize, &version); +pdu_unmarshal (pdu, offset,"ds" , &s->msize, &version);if (!strcmp (version.data,"9P2000.u" )) { s->proto_version =V9FS_PROTO_2000U ;
@@ -1033,7 +1037,7 @@ static void v9fs_version(V9fsState *s, V9fsPDU *pdu)v9fs_string_sprintf (&version,"unknown" ); } - offset +=pdu_marshal (pdu, offset,"ds" , msize, &version); + offset +=pdu_marshal (pdu, offset,"ds" , s->msize, &version);complete_pdu (s, pdu, offset);v9fs_string_free (&version);
@@ -1288,6 +1292,26 @@ out:v9fs_walk_complete (s, vs, err); } +static int32_t get_iounit (V9fsState *s,V9fsString *name) +{ +struct statfs stbuf; +int32_t iounit =0 ; + +/* +* iounit should be multiples of f_bsize (host filesystem block size +* and as well as less than (client msize - P9_IOHDRSZ)) +*/ +if (!v9fs_do_statfs (s, name, &stbuf)) { + iounit = stbuf.f_bsize; + iounit *= (s->msize -P9_IOHDRSZ )/stbuf.f_bsize; + } + +if (!iounit) { + iounit = s->msize -P9_IOHDRSZ ; + } +return iounit; +} +static void v9fs_open_post_opendir (V9fsState *s,V9fsOpenState *vs,int err) {if (vs->fidp->dir ==NULL ) {
@@ -1303,6 +1327,15 @@ out: } +static void v9fs_open_post_getiounit (V9fsState *s,V9fsOpenState *vs) +{ +int err; + vs->offset +=pdu_marshal (vs->pdu, vs->offset,"Qd" , &vs->qid, vs->iounit); + err = vs->offset; +complete_pdu (s, vs->pdu, err); +qemu_free (vs); +} +static void v9fs_open_post_open (V9fsState *s,V9fsOpenState *vs,int err) {if (vs->fidp->fd ==-1 ) {
@@ -1310,8 +1343,9 @@ static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err) goto out; } - vs->offset +=pdu_marshal (vs->pdu, vs->offset,"Qd" , &vs->qid,0 ); - err = vs->offset; + vs->iounit =get_iounit (s, &vs->fidp->path); +v9fs_open_post_getiounit (s, vs); +return ; out:complete_pdu (s, vs->pdu, err);qemu_free (vs);
@@ -1794,15 +1828,28 @@ out:qemu_free (vs); } -static void v9fs_post_create (V9fsState *s,V9fsCreateState *vs,int err) +static void v9fs_create_post_getiounit (V9fsState *s,V9fsCreateState *vs) { -if (err ==0 ) { -v9fs_string_copy (&vs->fidp->path, &vs->fullname); -stat_to_qid (&vs->stbuf, &vs->qid); +int err; +v9fs_string_copy (&vs->fidp->path, &vs->fullname); +stat_to_qid (&vs->stbuf, &vs->qid); - vs->offset +=pdu_marshal (vs->pdu, vs->offset,"Qd" , &vs->qid,0 ); + vs->offset +=pdu_marshal (vs->pdu, vs->offset,"Qd" , &vs->qid, vs->iounit); + err = vs->offset; - err = vs->offset; +complete_pdu (s, vs->pdu, err); +v9fs_string_free (&vs->name); +v9fs_string_free (&vs->extension); +v9fs_string_free (&vs->fullname); +qemu_free (vs); +} + +static void v9fs_post_create (V9fsState *s,V9fsCreateState *vs,int err) +{ +if (err ==0 ) { + vs->iounit =get_iounit (s, &vs->fidp->path); +v9fs_create_post_getiounit (s, vs); +return ; }complete_pdu (s, vs->pdu, err);
@@ -2266,23 +2313,34 @@ out:qemu_free (vs); } -static int v9fs_do_statfs (V9fsState *s,V9fsString *path,struct statfs *stbuf) -{ -return s->ops->statfs (&s->ctx, path->data, stbuf); -} -static void v9fs_statfs_post_statfs (V9fsState *s,V9fsStatfsState *vs,int err) { +int32_t bsize_factor; +if (err) { err = -errno; goto out; } +/* +* compute bsize factor based on host file system block size +* and client msize +*/ + bsize_factor = (s->msize -P9_IOHDRSZ )/vs->stbuf.f_bsize; +if (!bsize_factor) { + bsize_factor =1 ; + } vs->v9statfs.f_type = vs->stbuf.f_type; vs->v9statfs.f_bsize = vs->stbuf.f_bsize; - vs->v9statfs.f_blocks = vs->stbuf.f_blocks; - vs->v9statfs.f_bfree = vs->stbuf.f_bfree; - vs->v9statfs.f_bavail = vs->stbuf.f_bavail; + vs->v9statfs.f_bsize *= bsize_factor; +/* +* f_bsize is adjusted(multiplied) by bsize factor, so we need to +* adjust(divide) the number of blocks, free blocks and available +* blocks by bsize factor +*/ + vs->v9statfs.f_blocks = vs->stbuf.f_blocks/bsize_factor; + vs->v9statfs.f_bfree = vs->stbuf.f_bfree/bsize_factor; + vs->v9statfs.f_bavail = vs->stbuf.f_bavail/bsize_factor; vs->v9statfs.f_files = vs->stbuf.f_files; vs->v9statfs.f_ffree = vs->stbuf.f_ffree; vs->v9statfs.fsid_val = (unsigned int) vs->stbuf.f_fsid.__val[0] |
hw/virtio-9p.h +9 -0
@@ -70,6 +70,12 @@ enum p9_proto_version {#define P9_NOFID (u32)(~0)#define P9_MAXWELEM 16 +/* +* ample room for Twrite/Rread header +* size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4] +*/ +#define P9_IOHDRSZ 24 +typedef struct V9fsPDU V9fsPDU ;struct V9fsPDU
@@ -154,6 +160,7 @@ typedef struct V9fsStateuint8_t *tag;size_t config_size;enum p9_proto_version proto_version; +int32_t msize; } V9fsState; typedef struct V9fsCreateState {
@@ -167,6 +174,7 @@ typedef struct V9fsCreateState {V9fsString name;V9fsString extension;V9fsString fullname; +int iounit; } V9fsCreateState; typedef struct V9fsStatState {
@@ -197,6 +205,7 @@ typedef struct V9fsOpenState {V9fsFidState *fidp;V9fsQID qid;struct stat stbuf; +int iounit; } V9fsOpenState; typedef struct V9fsReadState {
Signature · 1 line
1.6.5.2
PATCH v5 6/28 virtio-9p: getattr server implementation for 9P2000.L protocol.
In reply to Venkateswararao Jujjuri (JV)From: Sripathi Kodi <[email protected]>
SYNOPSIS
size[4] Tgetattr tag[2] fid[4] request_mask[8]
size[4] Rgetattr tag[2] lstat[n]
DESCRIPTION
The getattr transaction inquires about the file identified by fid.
request_mask is a bit mask that specifies which fields of the
stat structure is the client interested in.
The reply will contain a machine-independent directory entry,
laid out as follows:
st_result_mask[8]
Bit mask that indicates which fields in the stat structure
have been populated by the server
qid.type[1]
the type of the file (directory, etc.), represented as a bit
vector corresponding to the high 8 bits of the file's mode
word.
qid.vers[4]
version number for given path
qid.path[8]
the file server's unique identification for the file
st_mode[4]
Permission and flags
st_uid[4]
User id of owner
st_gid[4]
Group ID of owner
st_nlink[8]
Number of hard links
st_rdev[8]
Device ID (if special file)
st_size[8]
Size, in bytes
st_blksize[8]
Block size for file system IO
st_blocks[8]
Number of file system blocks allocated
st_atime_sec[8]
Time of last access, seconds
st_atime_nsec[8]
Time of last access, nanoseconds
st_mtime_sec[8]
Time of last modification, seconds
st_mtime_nsec[8]
Time of last modification, nanoseconds
st_ctime_sec[8]
Time of last status change, seconds
st_ctime_nsec[8]
Time of last status change, nanoseconds
st_btime_sec[8]
Time of creation (birth) of file, seconds
st_btime_nsec[8]
Time of creation (birth) of file, nanoseconds
st_gen[8]
Inode generation
st_data_version[8]
Data version number
request_mask and result_mask bit masks contain the following bits
#define P9_STATS_MODE 0x00000001ULL
#define P9_STATS_NLINK 0x00000002ULL
#define P9_STATS_UID 0x00000004ULL
#define P9_STATS_GID 0x00000008ULL
#define P9_STATS_RDEV 0x00000010ULL
#define P9_STATS_ATIME 0x00000020ULL
#define P9_STATS_MTIME 0x00000040ULL
#define P9_STATS_CTIME 0x00000080ULL
#define P9_STATS_INO 0x00000100ULL
#define P9_STATS_SIZE 0x00000200ULL
#define P9_STATS_BLOCKS 0x00000400ULL
#define P9_STATS_BTIME 0x00000800ULL
#define P9_STATS_GEN 0x00001000ULL
#define P9_STATS_DATA_VERSION 0x00002000ULL
#define P9_STATS_BASIC 0x000007ffULL
#define P9_STATS_ALL 0x00003fffULLThis patch implements the client side of getattr implementation for 9P2000.L. It introduces a new structure p9_stat_dotl for getting Linux stat information along with QID. The data layout is similar to stat structure in Linux user space with the following major differences:
inode (st_ino) is not part of data. Instead qid is.
device (st_dev) is not part of data because this doesn't make sense on the client.
All time variables are 64 bit wide on the wire. The kernel seems to use 32 bit variables for these variables. However, some of the architectures have used 64 bit variables and glibc exposes 64 bit variables to user space on some architectures. Hence to be on the safer side we have made these 64 bit in the protocol. Refer to the comments in include/asm-generic/stat.h
There are some additional fields: st_btime_sec, st_btime_nsec, st_gen, st_data_version apart from the bitmask, st_result_mask. The bit mask is filled by the server to indicate which stat fields have been populated by the server. Currently there is no clean way for the server to obtain these additional fields, so it sends back just the basic fields.
--- hw/virtio-9p-debug.c | 32 ++++++++++++++ hw/virtio-9p.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p.h | 33 +++++++++++++++ 3 files changed, 177 insertions(+), 0 deletions(-)
hw/virtio-9p-debug.c +32 -0
@@ -178,6 +178,30 @@ static void pprint_stat(V9fsPDU *pdu, int rx, size_t *offsetp, const char *name)fprintf (llogfile,"}" ); } +static void pprint_stat_dotl (V9fsPDU *pdu,int rx,size_t *offsetp, +const char *name) +{ +fprintf (llogfile,"%s={" , name); +pprint_qid (pdu, rx, offsetp,"qid" ); +pprint_int32 (pdu, rx, offsetp,", st_mode" ); +pprint_int64 (pdu, rx, offsetp,", st_nlink" ); +pprint_int32 (pdu, rx, offsetp,", st_uid" ); +pprint_int32 (pdu, rx, offsetp,", st_gid" ); +pprint_int64 (pdu, rx, offsetp,", st_rdev" ); +pprint_int64 (pdu, rx, offsetp,", st_size" ); +pprint_int64 (pdu, rx, offsetp,", st_blksize" ); +pprint_int64 (pdu, rx, offsetp,", st_blocks" ); +pprint_int64 (pdu, rx, offsetp,", atime" ); +pprint_int64 (pdu, rx, offsetp,", atime_nsec" ); +pprint_int64 (pdu, rx, offsetp,", mtime" ); +pprint_int64 (pdu, rx, offsetp,", mtime_nsec" ); +pprint_int64 (pdu, rx, offsetp,", ctime" ); +pprint_int64 (pdu, rx, offsetp,", ctime_nsec" ); +fprintf (llogfile,"}" ); +} + + +static void pprint_strs (V9fsPDU *pdu,int rx,size_t *offsetp,const char *name) {int sg_count =get_sg_count (pdu, rx);
@@ -353,6 +377,14 @@ void pprint_pdu(V9fsPDU *pdu)pprint_int32 (pdu,1 , &offset,"msize" );pprint_str (pdu,1 , &offset,", version" );break ; +case P9_TGETATTR : +fprintf (llogfile,"TGETATTR: (" ); +pprint_int32 (pdu,0 , &offset,"fid" ); +break ; +case P9_RGETATTR : +fprintf (llogfile,"RGETATTR: (" ); +pprint_stat_dotl (pdu,1 , &offset,"getattr" ); +break ;case P9_TAUTH :fprintf (llogfile,"TAUTH: (" );pprint_int32 (pdu,0 , &offset,"afid" );
hw/virtio-9p.c +112 -0
136 lines not on this page · raw message
hw/virtio-9p.h +33 -0
@@ -15,6 +15,8 @@enum {P9_TSTATFS =8 ,P9_RSTATFS , +P9_TGETATTR =24 , +P9_RGETATTR ,P9_TREADDIR =40 ,P9_RREADDIR ,P9_TVERSION =100 ,
@@ -185,6 +187,37 @@ typedef struct V9fsStatState {struct stat stbuf; } V9fsStatState; +typedef struct V9fsStatDotl { +uint64_t st_result_mask; +V9fsQID qid; +uint32_t st_mode; +uint32_t st_uid; +uint32_t st_gid; +uint64_t st_nlink; +uint64_t st_rdev; +uint64_t st_size; +uint64_t st_blksize; +uint64_t st_blocks; +uint64_t st_atime_sec; +uint64_t st_atime_nsec; +uint64_t st_mtime_sec; +uint64_t st_mtime_nsec; +uint64_t st_ctime_sec; +uint64_t st_ctime_nsec; +uint64_t st_btime_sec; +uint64_t st_btime_nsec; +uint64_t st_gen; +uint64_t st_data_version; +}V9fsStatDotl ; + +typedef struct V9fsStatStateDotl { +V9fsPDU *pdu; +size_t offset; +V9fsStatDotl v9stat_dotl; +struct stat stbuf; +}V9fsStatStateDotl ; + + typedef struct V9fsWalkState { V9fsPDU *pdu; size_t offset;
Signature · 1 line
1.6.5.2
PATCH v5 7/28 virtio-9p: Do not reset atime
In reply to Venkateswararao Jujjuri (JV)From: M. Mohan Kumar <[email protected]>
Current code resets file's atime to 0 when there is a change in mtime. This results in resetting the atime to "1970-01-01 05:30:00". For example, truncate -s 0 filename results in changing the mtime to the truncate time, but resets the atime to "1970-01-01 05:30:00". utime system call does not have any provision to set only mtime or atime. So change v9fs_wstat_post_chmod function to use utimensat function to change the atime and mtime fields. If tv_nsec field is set to the special value "UTIME_OMIT", corresponding file time stamp is not updated.
--- hw/file-op-9p.h | 2 +- hw/virtio-9p-local.c | 8 ++++---- hw/virtio-9p.c | 28 ++++++++++++++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-)
hw/file-op-9p.h +1 -1
@@ -52,7 +52,7 @@ typedef struct FileOperationsint (*chmod)(FsContext *,const char *,FsCred *);int (*chown)(FsContext *,const char *,FsCred *);int (*mknod)(FsContext *,const char *,FsCred *); -int (*utime)(FsContext *,const char *,const struct utimbuf *); +int (*utimensat)(FsContext *,const char *,const struct timespec *);int (*remove)(FsContext *,const char *);int (*symlink)(FsContext *,const char *,const char *,FsCred *);int (*link)(FsContext *,const char *,const char *);
hw/virtio-9p-local.c +4 -4
@@ -450,10 +450,10 @@ static int local_chown(FsContext *fs_ctx, const char *path, FsCred *credp)return -1 ; } -static int local_utime (FsContext *ctx,const char *path, -const struct utimbuf *buf) +static int local_utimensat (FsContext *s,const char *path, +const struct timespec *buf) { -return utime (rpath (ctx, path), buf); +return utimensat (AT_FDCWD ,rpath (s, path), buf,AT_SYMLINK_NOFOLLOW ); }static int local_remove (FsContext *ctx,const char *path)
@@ -495,7 +495,7 @@ FileOperations local_ops = { .truncate = local_truncate, .rename = local_rename, .chown = local_chown, - .utime = local_utime, + .utimensat = local_utimensat, .remove = local_remove, .fsync = local_fsync, .statfs = local_statfs,
hw/virtio-9p.c +20 -8
@@ -237,10 +237,25 @@ static int v9fs_do_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)return s->ops->chown (&s->ctx, path->data, &cred); } -static int v9fs_do_utime (V9fsState *s,V9fsString *path, -const struct utimbuf *buf) +static int v9fs_do_utimensat (V9fsState *s,V9fsString *path,V9fsStat v9stat) { -return s->ops->utime (&s->ctx, path->data, buf); +struct timespec ts[2 ]; + +if (v9stat.atime !=-1 ) { + ts[0 ].tv_sec = v9stat.atime; + ts[0 ].tv_nsec =0 ; + }else { + ts[0 ].tv_nsec =UTIME_OMIT ; + } + +if (v9stat.mtime !=-1 ) { + ts[1 ].tv_sec = v9stat.mtime; + ts[1 ].tv_nsec =0 ; + }else { + ts[1 ].tv_nsec =UTIME_OMIT ; + } + +return s->ops->utimensat (&s->ctx, path->data, ts); }static int v9fs_do_remove (V9fsState *s,V9fsString *path)
@@ -2325,11 +2340,8 @@ static void v9fs_wstat_post_chmod(V9fsState *s, V9fsWstatState *vs, int err) goto out; } -if (vs->v9stat.mtime !=-1 ) { -struct utimbuf tb; - tb.actime =0 ; - tb.modtime = vs->v9stat.mtime; -if (v9fs_do_utime (s, &vs->fidp->path, &tb)) { +if (vs->v9stat.mtime !=-1 || vs->v9stat.atime !=-1 ) { +if (v9fs_do_utimensat (s, &vs->fidp->path, vs->v9stat)) { err = -errno; } }
Signature · 1 line
1.6.5.2
PATCH v5 8/28 Make v9fs_do_utimensat accept timespec structures instead of v9stat.
In reply to Venkateswararao Jujjuri (JV)From: Sripathi Kodi <[email protected]>
Currently v9fs_do_utimensat takes a V9fsStat argument and builds timespec structures. It sets tv_nsec values to 0 by default. Instead of this it should take struct timespec[2] and pass it down to the system directly. This will make it more generic and useful elsewhere.
--- hw/virtio-9p.c | 37 ++++++++++++++++++------------------- 1 files changed, 18 insertions(+), 19 deletions(-)
hw/virtio-9p.c +18 -19
@@ -237,25 +237,10 @@ static int v9fs_do_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)return s->ops->chown (&s->ctx, path->data, &cred); } -static int v9fs_do_utimensat (V9fsState *s,V9fsString *path,V9fsStat v9stat) +static int v9fs_do_utimensat (V9fsState *s,V9fsString *path, +const struct timespec times[2 ]) { -struct timespec ts[2 ]; - -if (v9stat.atime !=-1 ) { - ts[0 ].tv_sec = v9stat.atime; - ts[0 ].tv_nsec =0 ; - }else { - ts[0 ].tv_nsec =UTIME_OMIT ; - } - -if (v9stat.mtime !=-1 ) { - ts[1 ].tv_sec = v9stat.mtime; - ts[1 ].tv_nsec =0 ; - }else { - ts[1 ].tv_nsec =UTIME_OMIT ; - } - -return s->ops->utimensat (&s->ctx, path->data, ts); +return s->ops->utimensat (&s->ctx, path->data, times); }static int v9fs_do_remove (V9fsState *s,V9fsString *path)
@@ -2341,7 +2326,21 @@ static void v9fs_wstat_post_chmod(V9fsState *s, V9fsWstatState *vs, int err) }if (vs->v9stat.mtime !=-1 || vs->v9stat.atime !=-1 ) { -if (v9fs_do_utimensat (s, &vs->fidp->path, vs->v9stat)) { +struct timespec times[2 ]; +if (vs->v9stat.atime !=-1 ) { + times[0 ].tv_sec = vs->v9stat.atime; + times[0 ].tv_nsec =0 ; + }else { + times[0 ].tv_nsec =UTIME_OMIT ; + } +if (vs->v9stat.mtime !=-1 ) { + times[1 ].tv_sec = vs->v9stat.mtime; + times[1 ].tv_nsec =0 ; + }else { + times[1 ].tv_nsec =UTIME_OMIT ; + } + +if (v9fs_do_utimensat (s, &vs->fidp->path, times)) { err = -errno; } }
Signature · 1 line
1.6.5.2
PATCH v5 9/28 virtio-9p: Implement server side of setattr for 9P2000.L protocol.
In reply to Venkateswararao Jujjuri (JV)From: Sripathi Kodi <[email protected]>
SYNOPSIS
size[4] Tsetattr tag[2] attr[n]
size[4] Rsetattr tag[2]DESCRIPTION
The setattr command changes some of the file status information.
attr resembles the iattr structure used in Linux kernel. It
specifies which status parameter is to be changed and to what
value. It is laid out as follows:
valid[4]
specifies which status information is to be changed. Possible
values are:
ATTR_MODE (1 << 0)
ATTR_UID (1 << 1)
ATTR_GID (1 << 2)
ATTR_SIZE (1 << 3)
ATTR_ATIME (1 << 4)
ATTR_MTIME (1 << 5)
ATTR_CTIME (1 << 5)
ATTR_ATIME_SET (1 << 7)
ATTR_MTIME_SET (1 << 8)
The last two bits represent whether the time information
is being sent by the client's user space. In the absense
of these bits the server always uses server's time.
mode[4]
File permission bits
uid[4]
Owner id of file
gid[4]
Group id of the file
size[8]
File size
atime_sec[8]
Time of last file access, seconds
atime_nsec[8]
Time of last file access, nanoseconds
mtime_sec[8]
Time of last file modification, seconds
mtime_nsec[8]
Time of last file modification, nanosecondsExplanation of the patches:
--------------------------
*) The kernel just copies relevent contents of iattr structure to p9_iattr_dotl
structure and passes it down to the client. The only check it has is calling inode_change_ok()
*) The p9_iattr_dotl structure does not have ctime and ia_file parameters because
I don't think these are needed in our case. The client user space can request updating just ctime by calling chown(fd, -1, -1). This is handled on server side without a need for putting ctime on the wire.
*) The server currently supports changing mode, time, ownership and size of the
file.
*) 9P RFC says "Either all the changes in wstat request happen, or none of them
does: if the request succeeds, all changes were made; if it fails, none were." I have not done anything to implement this specifically because I don't see a reason.
[[email protected]: Parts of code for handling chown(-1,-1)
--- hw/virtio-9p-local.c | 5 +- hw/virtio-9p.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p.h | 23 ++++++++ 3 files changed, 182 insertions(+), 1 deletions(-)
hw/virtio-9p-local.c +4 -1
@@ -442,7 +442,10 @@ static int local_rename(FsContext *ctx, const char *oldpath,static int local_chown (FsContext *fs_ctx,const char *path,FsCred *credp) { -if (fs_ctx->fs_sm ==SM_MAPPED ) { +if ((credp->fc_uid ==-1 && credp->fc_gid ==-1 ) || + (fs_ctx->fs_sm ==SM_PASSTHROUGH )) { +return lchown (rpath (fs_ctx, path), credp->fc_uid, credp->fc_gid); + }else if (fs_ctx->fs_sm ==SM_MAPPED ) {return local_set_xattr (rpath (fs_ctx, path), credp); }else if (fs_ctx->fs_sm ==SM_PASSTHROUGH ) {return lchown (rpath (fs_ctx, path), credp->fc_uid, credp->fc_gid);
hw/virtio-9p.c +155 -0
173 lines not on this page · raw message
hw/virtio-9p.h +23 -0
@@ -17,6 +17,8 @@ enum {P9_RSTATFS ,P9_TGETATTR =24 ,P9_RGETATTR , +P9_TSETATTR =26 , +P9_RSETATTR ,P9_TREADDIR =40 ,P9_RREADDIR , P9_TVERSION = 100,
@@ -290,6 +292,27 @@ typedef struct V9fsWstatStateV9fsString nname; } V9fsWstatState; +typedef struct V9fsIattr +{ +int32_t valid; +int32_t mode; +int32_t uid; +int32_t gid; +int64_t size; +int64_t atime_sec; +int64_t atime_nsec; +int64_t mtime_sec; +int64_t mtime_nsec; +}V9fsIattr ; + +typedef struct V9fsSetattrState +{ +V9fsPDU *pdu; +size_t offset; +V9fsIattr v9iattr; +V9fsFidState *fidp; +}V9fsSetattrState ; +struct virtio_9p_config {/* number of characters in tag */
Signature · 1 line
1.6.5.2
PATCH v5 10/28 Implement TLINK for 9P2000.L
In reply to Venkateswararao Jujjuri (JV)Create a Hardlink.
SYNOPSIS
size[4] Tlink tag[2] dfid[4] oldfid[4] newpath[s]
size[4] Rlink tag[2]
DESCRIPTION
Create a link 'newpath' in directory pointed by dfid linking to oldfid path.
--- hw/virtio-9p-debug.c | 9 +++++++++ hw/virtio-9p.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/virtio-9p.h | 2 ++ 3 files changed, 49 insertions(+), 0 deletions(-)
hw/virtio-9p-debug.c +9 -0
@@ -497,6 +497,15 @@ void pprint_pdu(V9fsPDU *pdu)case P9_RCLUNK :fprintf (llogfile,"RCLUNK: (" );break ; +case P9_TLINK : +fprintf (llogfile,"TLINK: (" ); +pprint_int32 (pdu,0 , &offset,"fid" ); +pprint_str (pdu,0 , &offset,", oldpath" ); +pprint_str (pdu,0 , &offset,", newpath" ); +break ; +case P9_RLINK : +fprintf (llogfile,"RLINK: (" ); +break ;case P9_TREMOVE :fprintf (llogfile,"TREMOVE: (" );pprint_int32 (pdu,0 , &offset,"fid" );
hw/virtio-9p.c +38 -0
@@ -2307,6 +2307,43 @@ static void v9fs_flush(V9fsState *s, V9fsPDU *pdu)complete_pdu (s, pdu,7 ); } +static void v9fs_link (V9fsState *s,V9fsPDU *pdu) +{ +int32_t dfid, oldfid; +V9fsFidState *dfidp, *oldfidp; +V9fsString name, fullname; +size_t offset =7 ; +int err =0 ; + +v9fs_string_init (&fullname); + +pdu_unmarshal (pdu, offset,"dds" , &dfid, &oldfid, &name); + + dfidp =lookup_fid (s, dfid); +if (dfidp ==NULL ) { + err = -errno; + goto out; + } + + oldfidp =lookup_fid (s, oldfid); +if (oldfidp ==NULL ) { + err = -errno; + goto out; + } + +v9fs_string_sprintf (&fullname,"%s/%s" , dfidp->path.data, name.data); + err = offset; + err =v9fs_do_link (s, &oldfidp->path, &fullname); +if (err) { + err = -errno; + } +v9fs_string_free (&fullname); + +out: +v9fs_string_free (&name); +complete_pdu (s, pdu, err); +} +static void v9fs_remove_post_remove (V9fsState *s,V9fsRemoveState *vs,int err) {
@@ -2680,6 +2717,7 @@ static pdu_handler_t *pdu_handlers[] = { [P9_TAUTH] = v9fs_auth, #endif [P9_TFLUSH] = v9fs_flush, + [P9_TLINK] = v9fs_link, [P9_TCREATE] = v9fs_create, [P9_TWRITE] = v9fs_write, [P9_TWSTAT] = v9fs_wstat,
hw/virtio-9p.h +2 -0
@@ -21,6 +21,8 @@ enum {P9_RSETATTR ,P9_TREADDIR =40 ,P9_RREADDIR , +P9_TLINK =70 , +P9_RLINK ,P9_TVERSION =100 ,P9_RVERSION , P9_TAUTH = 102,
Signature · 1 line
1.6.5.2
PATCH v5 11/28 Define and implement TSYMLINK for 9P2000.L
In reply to Venkateswararao Jujjuri (JV)This patch implements creating a symlink for TSYMLINK request and responds with RSYMLINK. In the case of error, we return RERROR.
SYNOPSIS
size[4] Tsymlink tag[2] fid[4] name[s] symtgt[s] gid[4]
size[4] Rsymlink tag[2] qid[13]
DESCRIPTION
Create a symbolic link named 'name' pointing to 'symtgt'. gid represents the effective group id of the caller.
The permissions of a symbolic link are irrelevant hence it is omitted from the protocol.
--- hw/virtio-9p-debug.c | 11 +++++++ hw/virtio-9p.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++---- hw/virtio-9p.h | 14 +++++++++ 3 files changed, 97 insertions(+), 6 deletions(-)
hw/virtio-9p-debug.c +11 -0
@@ -464,6 +464,17 @@ void pprint_pdu(V9fsPDU *pdu)pprint_qid (pdu,1 , &offset,"qid" );pprint_int32 (pdu,1 , &offset,", iounit" );break ; +case P9_TSYMLINK : +fprintf (llogfile,"TSYMLINK: (" ); +pprint_int32 (pdu,0 , &offset,"fid" ); +pprint_str (pdu,0 , &offset,", name" ); +pprint_str (pdu,0 , &offset,", symname" ); +pprint_int32 (pdu,0 , &offset,", gid" ); +break ; +case P9_RSYMLINK : +fprintf (llogfile,"RSYMLINK: (" ); +pprint_qid (pdu,1 , &offset,"qid" ); +break ;case P9_TREAD :fprintf (llogfile,"TREAD: (" );pprint_int32 (pdu,0 , &offset,"fid" );
hw/virtio-9p.c +72 -6
106 lines not on this page · raw message
hw/virtio-9p.h +14 -0
@@ -15,6 +15,8 @@enum {P9_TSTATFS =8 ,P9_RSTATFS , +P9_TSYMLINK =16 , +P9_RSYMLINK ,P9_TGETATTR =24 ,P9_RGETATTR ,P9_TSETATTR =26 ,
@@ -294,6 +296,18 @@ typedef struct V9fsWstatStateV9fsString nname; } V9fsWstatState; +typedef struct V9fsSymlinkState +{ +V9fsPDU *pdu; +size_t offset; +V9fsString name; +V9fsString symname; +V9fsString fullname; +V9fsFidState *dfidp; +V9fsQID qid; +struct stat stbuf; +}V9fsSymlinkState ; + typedef struct V9fsIattr { int32_t valid;
Signature · 1 line
1.6.5.2
PATCH v5 12/28 This patch implements TLCREATE for 9p2000.L protocol.
In reply to Venkateswararao Jujjuri (JV)SYNOPSIS
size[4] Tlcreate tag[2] fid[4] name[s] flags[4] mode[4] gid[4]
size[4] Rlcreate tag[2] qid[13] iounit[4]DESCRIPTION
The Tlreate request asks the file server to create a new regular file with the name supplied, in the directory (dir) represented by fid.
The mode argument specifies the permissions to use. New file is created with the uid if the fid and with supplied gid.
The flags argument represent Linux access mode flags with which the caller is requesting to open the file with. Protocol allows all the Linux access modes but it is upto the server to allow/disallow any of these acess modes. If the server doesn't support any of the access mode, it is expected to return error.
To start with we will not restricit/limit any Linux flags on this server. If needed, We can start restricting as we move forward with various use cases.
--- hw/virtio-9p-debug.c | 13 ++++++ hw/virtio-9p.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++--- hw/virtio-9p.h | 13 ++++++ 3 files changed, 119 insertions(+), 7 deletions(-)
hw/virtio-9p-debug.c +13 -0
@@ -475,6 +475,19 @@ void pprint_pdu(V9fsPDU *pdu)fprintf (llogfile,"RSYMLINK: (" );pprint_qid (pdu,1 , &offset,"qid" );break ; +case P9_TLCREATE : +fprintf (llogfile,"TLCREATE: (" ); +pprint_int32 (pdu,0 , &offset,"dfid" ); +pprint_str (pdu,0 , &offset,", name" ); +pprint_int32 (pdu,0 , &offset,", flags" ); +pprint_int32 (pdu,0 , &offset,", mode" ); +pprint_int32 (pdu,0 , &offset,", gid" ); +break ; +case P9_RLCREATE : +fprintf (llogfile,"RLCREATE: (" ); +pprint_qid (pdu,1 , &offset,"qid" ); +pprint_int32 (pdu,1 , &offset,", iounit" ); +break ;case P9_TREAD :fprintf (llogfile,"TREAD: (" );pprint_int32 (pdu,0 , &offset,"fid" );
hw/virtio-9p.c +93 -7
129 lines not on this page · raw message
hw/virtio-9p.h +13 -0
@@ -15,6 +15,8 @@enum {P9_TSTATFS =8 ,P9_RSTATFS , +P9_TLCREATE =14 , +P9_RLCREATE ,P9_TSYMLINK =16 ,P9_RSYMLINK ,P9_TGETATTR =24 ,
@@ -185,6 +187,17 @@ typedef struct V9fsCreateState {int iounit; } V9fsCreateState; +typedef struct V9fsLcreateState { +V9fsPDU *pdu; +size_t offset; +V9fsFidState *fidp; +V9fsQID qid; +int32_t iounit; +struct stat stbuf; +V9fsString name; +V9fsString fullname; +}V9fsLcreateState ; + typedef struct V9fsStatState { V9fsPDU *pdu; size_t offset;
Signature · 1 line
1.6.5.2
PATCH v5 13/28 qemu: virtio-9p: Implement TMKNOD
In reply to Venkateswararao Jujjuri (JV)From: M. Mohan Kumar <[email protected]>
Implement TMKNOD as part of 2000.L Work
Synopsis
size[4] Tmknod tag[2] fid[4] name[s] mode[4] major[4] minor[4] gid[4]
size[4] Rmknod tag[2] qid[13]Description
mknod asks the file server to create a device node with given device type, mode and gid. The qid for the new device node is returned with the mknod reply message.
--- hw/virtio-9p-debug.c | 13 +++++++ hw/virtio-9p.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++---- hw/virtio-9p.h | 11 ++++++ 3 files changed, 107 insertions(+), 7 deletions(-)
hw/virtio-9p-debug.c +13 -0
@@ -488,6 +488,19 @@ void pprint_pdu(V9fsPDU *pdu)pprint_qid (pdu,1 , &offset,"qid" );pprint_int32 (pdu,1 , &offset,", iounit" );break ; +case P9_TMKNOD : +fprintf (llogfile,"TMKNOD: (" ); +pprint_int32 (pdu,0 , &offset,"fid" ); +pprint_str (pdu,0 , &offset,"name" ); +pprint_int32 (pdu,0 , &offset,"mode" ); +pprint_int32 (pdu,0 , &offset,"major" ); +pprint_int32 (pdu,0 , &offset,"minor" ); +pprint_int32 (pdu,0 , &offset,"gid" ); +break ; +case P9_RMKNOD : +fprintf (llogfile,"RMKNOD: )" ); +pprint_qid (pdu,0 , &offset,"qid" ); +break ;case P9_TREAD :fprintf (llogfile,"TREAD: (" );pprint_int32 (pdu,0 , &offset,"fid" );
hw/virtio-9p.c +83 -7
123 lines not on this page · raw message
hw/virtio-9p.h +11 -0
@@ -19,6 +19,8 @@ enum {P9_RLCREATE ,P9_TSYMLINK =16 ,P9_RSYMLINK , +P9_TMKNOD =18 , +P9_RMKNOD ,P9_TGETATTR =24 ,P9_RGETATTR , P9_TSETATTR = 26,
@@ -372,6 +374,15 @@ typedef struct V9fsStatfsState {struct statfs stbuf; } V9fsStatfsState; +typedef struct V9fsMkState { +V9fsPDU *pdu; +size_t offset; +V9fsQID qid; +struct stat stbuf; +V9fsString name; +V9fsString fullname; +}V9fsMkState ; +extern size_t pdu_packunpack (void *addr,struct iovec *sg,int sg_count,size_t offset,size_t size,int pack);
Signature · 1 line
1.6.5.2
PATCH v5 14/28 qemu: virtio-9p: Implement TMKDIR
In reply to Venkateswararao Jujjuri (JV)From: M. Mohan Kumar <[email protected]>
Synopsis
size[4] Tmkdir tag[2] fid[4] name[s] mode[4] gid[4]
size[4] Rmkdir tag[2] qid[13]Description
mkdir asks the file server to create a directory with given name, mode and gid. The qid for the new directory is returned with the mkdir reply message.
Note: 72 is selected as the opcode for TMKDIR from the reserved list.
--- hw/virtio-9p-debug.c | 11 ++++++ hw/virtio-9p.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++--- hw/virtio-9p.h | 2 + 3 files changed, 91 insertions(+), 5 deletions(-)
hw/virtio-9p-debug.c +11 -0
@@ -367,6 +367,17 @@ void pprint_pdu(V9fsPDU *pdu)pprint_data (pdu,1 , &offset,", data" );#endif break ; +case P9_TMKDIR : +fprintf (llogfile,"TMKDIR: (" ); +pprint_int32 (pdu,0 , &offset,"fid" ); +pprint_str (pdu,0 , &offset,"name" ); +pprint_int32 (pdu,0 , &offset,"mode" ); +pprint_int32 (pdu,0 , &offset,"gid" ); +break ; +case P9_RMKDIR : +fprintf (llogfile,"RMKDIR: (" ); +pprint_qid (pdu,0 , &offset,"qid" ); +break ;case P9_TVERSION :fprintf (llogfile,"TVERSION: (" );pprint_int32 (pdu,0 , &offset,"msize" );
hw/virtio-9p.c +78 -5
112 lines not on this page · raw message
hw/virtio-9p.h +2 -0
@@ -29,6 +29,8 @@ enum {P9_RREADDIR ,P9_TLINK =70 ,P9_RLINK , +P9_TMKDIR =72 , +P9_RMKDIR ,P9_TVERSION =100 ,P9_RVERSION , P9_TAUTH = 102,
Signature · 1 line
1.6.5.2
PATCH v5 15/28 rename - change name of file or directory
In reply to Venkateswararao Jujjuri (JV)From: M. Mohan Kumar <[email protected]>
size[4] Trename tag[2] fid[4] newdirfid[4] name[s] size[4] Rrename tag[2]
Implement the 2000.L rename operation. A new function v9fs_complete_rename is introduced that acts as a common entry point for 2000.L rename operation and 2000.U rename opearation (via wstat). As part of this change the field 'nname' (used only for rename) is removed from the structure V9fsWstatState. Instead a new structure V9fsRenameState is used for rename operations both by 2000.U and 2000.L code paths. Both 2000.U and 2000.L rename code paths construct the V9fsRenameState structure and passes that to v9fs_complete_rename function.
Changes from previous version:
Use qemu_mallocz to initialize
Use strcpy,strcat functions instead of memcpy
Changed the variable name to newdirfid
Introduced post rename function
Error checking
Removed nname field from V9fsWstatState
--- hw/virtio-9p.c | 156 ++++++++++++++++++++++++++++++++++++++++--------------- hw/virtio-9p.h | 11 ++++- 2 files changed, 123 insertions(+), 44 deletions(-)
hw/virtio-9p.c +113 -43
@@ -2563,11 +2563,6 @@ static void v9fs_wstat_post_rename(V9fsState *s, V9fsWstatState *vs, int err)if (err <0 ) { goto out; } - -if (vs->v9stat.name.size !=0 ) { -v9fs_string_free (&vs->nname); - } -if (vs->v9stat.length !=-1 ) {if (v9fs_do_truncate (s, &vs->fidp->path, vs->v9stat.length) <0 ) { err = -errno;
@@ -2582,17 +2577,30 @@ out:qemu_free (vs); } -static void v9fs_wstat_post_chown (V9fsState *s,V9fsWstatState *vs,int err) +static int v9fs_complete_rename (V9fsState *s,V9fsRenameState *vs) { -V9fsFidState *fidp; -if (err <0 ) { - goto out; - } +int err =0 ; +char *old_name, *new_name; +char *end; -if (vs->v9stat.name.size !=0 ) { -char *old_name, *new_name; -char *end; +if (vs->newdirfid !=-1 ) { +V9fsFidState *dirfidp; + dirfidp =lookup_fid (s, vs->newdirfid); + +if (dirfidp ==NULL ) { + err = -ENOENT ; + goto out; + } + +BUG_ON (dirfidp->fd !=-1 ); +BUG_ON (dirfidp->dir); + new_name =qemu_mallocz (dirfidp->path.size + vs->name.size +2 ); + +strcpy (new_name, dirfidp->path.data); +strcat (new_name,"/" ); +strcat (new_name + dirfidp->path.size, vs->name.data); + }else { old_name = vs->fidp->path.data; end =strrchr (old_name,'/' );if (end) {
@@ -2600,43 +2608,75 @@ static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err) }else { end = old_name; } + new_name =qemu_mallocz (end - old_name + vs->name.size +1 ); - new_name =qemu_mallocz (end - old_name + vs->v9stat.name.size +1 ); +strncat (new_name, old_name, end - old_name); +strncat (new_name + (end - old_name), vs->name.data, vs->name.size); + } -memcpy (new_name, old_name, end - old_name); -memcpy (new_name + (end - old_name), vs->v9stat.name.data, - vs->v9stat.name.size); - vs->nname.data = new_name; - vs->nname.size =strlen (new_name); +v9fs_string_free (&vs->name); + vs->name.data =qemu_strdup (new_name); + vs->name.size =strlen (new_name); -if (strcmp (new_name, vs->fidp->path.data) !=0 ) { -if (v9fs_do_rename (s, &vs->fidp->path, &vs->nname)) { - err = -errno; - }else { -/* -* Fixup fid's pointing to the old name to -* start pointing to the new name -*/ -for (fidp = s->fid_list; fidp; fidp = fidp->next) { - -if (vs->fidp == fidp) { -/* -* we replace name of this fid towards the end -* so that our below strcmp will work -*/ -continue ; - } -if (!strncmp (vs->fidp->path.data, fidp->path.data, -strlen (vs->fidp->path.data))) { -/* replace the name */ -v9fs_fix_path (&fidp->path, &vs->nname, -strlen (vs->fidp->path.data)); - } +if (strcmp (new_name, vs->fidp->path.data) !=0 ) { +if (v9fs_do_rename (s, &vs->fidp->path, &vs->name)) { + err = -errno; + }else { +V9fsFidState *fidp; +/* +* Fixup fid's pointing to the old name to +* start pointing to the new name +*/ +for (fidp = s->fid_list; fidp; fidp = fidp->next) { +if (vs->fidp == fidp) { +/* +* we replace name of this fid towards the end +* so that our below strcmp will work +*/ +continue ; + } +if (!strncmp (vs->fidp->path.data, fidp->path.data, +strlen (vs->fidp->path.data))) { +/* replace the name */ +v9fs_fix_path (&fidp->path, &vs->name, +strlen (vs->fidp->path.data)); } -v9fs_string_copy (&vs->fidp->path, &vs->nname); } +v9fs_string_copy (&vs->fidp->path, &vs->name); } } +out: +v9fs_string_free (&vs->name); +return err; +} + +static void v9fs_rename_post_rename (V9fsState *s,V9fsRenameState *vs,int err) +{ +complete_pdu (s, vs->pdu, err); +qemu_free (vs); +} + +static void v9fs_wstat_post_chown (V9fsState *s,V9fsWstatState *vs,int err) +{ +if (err <0 ) { + goto out; + } + +if (vs->v9stat.name.size !=0 ) { +V9fsRenameState *vr; + + vr =qemu_malloc (sizeof (V9fsRenameState)); +memset (vr,sizeof (*vr),0 ); + vr->newdirfid =-1 ; + vr->pdu = vs->pdu; + vr->fidp = vs->fidp; + vr->offset = vs->offset; + vr->name.size = vs->v9stat.name.size; + vr->name.data =qemu_strdup (vs->v9stat.name.data); + + err =v9fs_complete_rename (s, vr); +qemu_free (vr); + }v9fs_wstat_post_rename (s, vs, err);return ;
@@ -2646,6 +2686,35 @@ out:qemu_free (vs); } +static void v9fs_rename (V9fsState *s,V9fsPDU *pdu) +{ +int32_t fid; +V9fsRenameState *vs; +ssize_t err =0 ; + + vs =qemu_malloc (sizeof (*vs)); + vs->pdu = pdu; + vs->offset =7 ; + +pdu_unmarshal (vs->pdu, vs->offset,"dds" , &fid, &vs->newdirfid, &vs->name); + + vs->fidp =lookup_fid (s, fid); +if (vs->fidp ==NULL ) { + err = -ENOENT ; + goto out; + } + +BUG_ON (vs->fidp->fd !=-1 ); +BUG_ON (vs->fidp->dir); + + err =v9fs_complete_rename (s, vs); +v9fs_rename_post_rename (s, vs, err); +return ; +out: +complete_pdu (s, vs->pdu, err); +qemu_free (vs); +} +static void v9fs_wstat_post_utime (V9fsState *s,V9fsWstatState *vs,int err) {if (err <0 ) {
@@ -3004,6 +3073,7 @@ static pdu_handler_t *pdu_handlers[] = { [P9_TGETATTR] = v9fs_getattr, [P9_TSETATTR] = v9fs_setattr, [P9_TMKNOD] = v9fs_mknod, + [P9_TRENAME] = v9fs_rename, [P9_TMKDIR] = v9fs_mkdir, [P9_TVERSION] = v9fs_version, [P9_TATTACH] = v9fs_attach,
hw/virtio-9p.h +10 -1
@@ -21,6 +21,8 @@ enum {P9_RSYMLINK ,P9_TMKNOD =18 ,P9_RMKNOD , +P9_TRENAME =20 , +P9_RRENAME ,P9_TGETATTR =24 ,P9_RGETATTR , P9_TSETATTR = 26,
@@ -310,7 +312,6 @@ typedef struct V9fsWstatStateV9fsStat v9stat;V9fsFidState *fidp;struct stat stbuf; -V9fsString nname; } V9fsWstatState; typedef struct V9fsSymlinkState
@@ -385,6 +386,14 @@ typedef struct V9fsMkState {V9fsString fullname; } V9fsMkState; +typedef struct V9fsRenameState { +V9fsPDU *pdu; +V9fsFidState *fidp; +size_t offset; +int32_t newdirfid; +V9fsString name; +}V9fsRenameState ; +extern size_t pdu_packunpack (void *addr,struct iovec *sg,int sg_count,size_t offset,size_t size,int pack);
Signature · 1 line
1.6.5.2
PATCH v5 16/28 qemu: virtio-9p: Implement LOPEN
In reply to Venkateswararao Jujjuri (JV)From: M. Mohan Kumar <[email protected]>
Implement 9p2000.L version of open(LOPEN) interface in qemu 9p server.
For LOPEN, no need to convert the flags to and from 9p mode to VFS mode.
Synopsis:
size[4] Tlopen tag[2] fid[4] mode[4]
size[4] Rlopen tag[2] qid[13] iounit[4]Current qemu 9p server does not support following flags:
O_NOCTTY, O_NONBLOCK, O_ASYNC & O_CLOEXEC
[Fix mode format - [email protected]]
--- hw/virtio-9p.c | 32 ++++++++++++++++++++++++++++---- hw/virtio-9p.h | 4 +++- 2 files changed, 31 insertions(+), 5 deletions(-)
hw/virtio-9p.c +28 -4
@@ -1621,8 +1621,19 @@ out:qemu_free (vs); } +static inline int valid_flags (int flag) +{ +if (flag &O_NOCTTY || flag &O_NONBLOCK || flag &O_ASYNC || + flag &O_CLOEXEC ) +return 0 ; +else +return 1 ; +} +static void v9fs_open_post_lstat (V9fsState *s,V9fsOpenState *vs,int err) { +int flags; +if (err) { err = -errno; goto out;
@@ -1634,8 +1645,16 @@ static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err) vs->fidp->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, -omode_to_uflags (vs->mode)); +if (s->proto_version ==V9FS_PROTO_2000L ) { +if (!valid_flags (vs->mode)) { + err = -EINVAL ; + goto out; + } + flags = vs->mode; + }else { + flags =omode_to_uflags (vs->mode); + } + vs->fidp->fd =v9fs_do_open (s, &vs->fidp->path, flags);v9fs_open_post_open (s, vs, err); }return ;
@@ -1650,12 +1669,16 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu)V9fsOpenState *vs;ssize_t err =0 ; - vs =qemu_malloc (sizeof (*vs)); vs->pdu = pdu; vs->offset =7 ; + vs->mode =0 ; -pdu_unmarshal (vs->pdu, vs->offset,"db" , &fid, &vs->mode); +if (s->proto_version ==V9FS_PROTO_2000L ) { +pdu_unmarshal (vs->pdu, vs->offset,"dd" , &fid, &vs->mode); + }else { +pdu_unmarshal (vs->pdu, vs->offset,"db" , &fid, &vs->mode); + } vs->fidp =lookup_fid (s, fid);if (vs->fidp ==NULL ) {
@@ -3076,6 +3099,7 @@ static pdu_handler_t *pdu_handlers[] = { [P9_TRENAME] = v9fs_rename, [P9_TMKDIR] = v9fs_mkdir, [P9_TVERSION] = v9fs_version, + [P9_TLOPEN] = v9fs_open, [P9_TATTACH] = v9fs_attach, [P9_TSTAT] = v9fs_stat, [P9_TWALK] = v9fs_walk,
hw/virtio-9p.h +3 -1
@@ -15,6 +15,8 @@enum {P9_TSTATFS =8 ,P9_RSTATFS , +P9_TLOPEN =12 , +P9_RLOPEN ,P9_TLCREATE =14 ,P9_RLCREATE ,P9_TSYMLINK =16 ,
@@ -259,7 +261,7 @@ typedef struct V9fsWalkState { typedef struct V9fsOpenState { V9fsPDU *pdu; size_t offset; - int8_t mode; + int32_t mode; V9fsFidState *fidp; V9fsQID qid; struct stat stbuf;
Signature · 1 line
1.6.5.2
PATCH v5 17/28 virtio-9p: Add fidtype so that we can do type specific operation
In reply to Venkateswararao Jujjuri (JV)From: Aneesh Kumar K.V <[email protected]>
We want to add type specific operation during read/write
--- hw/virtio-9p.c | 110 ++++++++++++++++++++++++++++--------------------------- hw/virtio-9p.h | 24 +++++++++++- 2 files changed, 78 insertions(+), 56 deletions(-)
hw/virtio-9p.c +56 -54
@@ -408,8 +408,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;
@@ -434,11 +433,14 @@ 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->dir) { -v9fs_do_closedir (s, fidp->dir); +if (fidp->fid_type ==P9_FID_FILE ) { +v9fs_do_close (s, fidp->fs.fd); + }else if (fidp->fid_type ==P9_FID_DIR ) { +v9fs_do_closedir (s, fidp->fs.dir); + }else 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);
@@ -1519,8 +1521,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 ;
@@ -1584,11 +1585,11 @@ static int32_t get_iounit(V9fsState *s, V9fsString *name)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:
@@ -1608,11 +1609,11 @@ static void v9fs_open_post_getiounit(V9fsState *s, V9fsOpenState *vs)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->iounit =get_iounit (s, &vs->fidp->path);v9fs_open_post_getiounit (s, vs);return ;
@@ -1642,7 +1643,7 @@ 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 {if (s->proto_version ==V9FS_PROTO_2000L ) {
@@ -1654,7 +1655,7 @@ static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err) }else { flags =omode_to_uflags (vs->mode); } - vs->fidp->fd =v9fs_do_open (s, &vs->fidp->path, flags); + vs->fidp->fs.fd =v9fs_do_open (s, &vs->fidp->path, flags);v9fs_open_post_open (s, vs, err); }return ;
@@ -1686,8 +1687,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);
@@ -1707,6 +1707,8 @@ static void v9fs_post_lcreate(V9fsState *s, V9fsLcreateState *vs, int err) &vs->iounit); err = vs->offset; }else { + vs->fidp->fid_type =P9_FID_NONE ; +close (vs->fidp->fs.fd); err = -errno; }
@@ -1732,10 +1734,11 @@ out:static void v9fs_lcreate_post_do_open2 (V9fsState *s,V9fsLcreateState *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->iounit =get_iounit (s, &vs->fullname);v9fs_lcreate_post_get_iounit (s, vs, err);return ;
@@ -1769,7 +1772,7 @@ static void v9fs_lcreate(V9fsState *s, V9fsPDU *pdu)v9fs_string_sprintf (&vs->fullname,"%s/%s" , vs->fidp->path.data, vs->name.data); - vs->fidp->fd =v9fs_do_open2 (s, vs->fullname.data, vs->fidp->uid, + vs->fidp->fs.fd =v9fs_do_open2 (s, vs->fullname.data, vs->fidp->uid, gid, flags, mode);v9fs_lcreate_post_do_open2 (s, vs, err);return ;
@@ -1833,7 +1836,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 ; }
@@ -1841,11 +1844,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 ;
@@ -1873,7 +1876,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 ; }
@@ -1881,7 +1884,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 ; }
@@ -1900,7 +1903,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;
@@ -1930,7 +1933,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;
@@ -1964,18 +1967,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 {
@@ -2024,7 +2027,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 ; }
@@ -2045,7 +2048,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 ; }
@@ -2059,14 +2062,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 ; }
@@ -2087,15 +2090,15 @@ 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->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);
@@ -2122,7 +2125,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;
@@ -2151,7 +2154,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;
@@ -2188,12 +2191,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 ;
@@ -2245,9 +2248,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); }
@@ -2259,7 +2263,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 ;
@@ -2285,22 +2289,22 @@ out:static void v9fs_create_post_fstat (V9fsState *s,V9fsCreateState *vs,int err) {if (err) { - vs->fidp->fd =-1 ; + vs->fidp->fid_type =P9_FID_NONE ; +close (vs->fidp->fs.fd); err = -errno; } -v9fs_post_create (s, vs, err);return ; }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 ;
@@ -2371,7 +2375,7 @@ static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err) 0, vs->fidp->uid, -1);v9fs_post_create (s, vs, err); }else { - vs->fidp->fd =v9fs_do_open2 (s, vs->fullname.data, vs->fidp->uid, + vs->fidp->fs.fd =v9fs_do_open2 (s, vs->fullname.data, vs->fidp->uid,-1 ,omode_to_uflags (vs->mode)|O_CREAT , vs->perm);v9fs_create_post_open2 (s, vs, err);
@@ -2615,8 +2619,7 @@ static int v9fs_complete_rename(V9fsState *s, V9fsRenameState *vs) goto out; } -BUG_ON (dirfidp->fd !=-1 ); -BUG_ON (dirfidp->dir); +BUG_ON (dirfidp->fid_type !=P9_FID_NONE ); new_name =qemu_mallocz (dirfidp->path.size + vs->name.size +2 );
@@ -2727,8 +2730,7 @@ static void v9fs_rename(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_complete_rename (s, vs);v9fs_rename_post_rename (s, vs, err);
@@ -2855,7 +2857,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
@@ -155,12 +155,32 @@ typedef struct V9fsStatint32_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.6.5.2
PATCH v5 18/28 virtio-9p: Implement TXATTRWALK
In reply to Venkateswararao Jujjuri (JV)From: Aneesh Kumar K.V <[email protected]>
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 | 3 + hw/virtio-9p-debug.c | 10 +++ hw/virtio-9p-local.c | 14 ++++ hw/virtio-9p.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++++- hw/virtio-9p.h | 14 ++++ 5 files changed, 231 insertions(+), 2 deletions(-)
hw/file-op-9p.h +3 -0
@@ -75,6 +75,9 @@ typedef struct FileOperationsint (*truncate)(FsContext *,const char *,off_t );int (*fsync)(FsContext *,int );int (*statfs)(FsContext *s,const char *path,struct statfs *stbuf); +ssize_t (*lgetxattr)(FsContext *,const char *, +const char *,void *,size_t ); +ssize_t (*llistxattr)(FsContext *,const char *,void *,size_t ); void *opaque; } FileOperations;#endif
hw/virtio-9p-debug.c +10 -0
@@ -579,6 +579,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
@@ -474,6 +474,18 @@ static int local_statfs(FsContext *s, const char *path, struct statfs *stbuf)return statfs (rpath (s, path), stbuf); } +static ssize_t local_lgetxattr (FsContext *ctx,const char *path, +const char *name,void *value,size_t size) +{ +return lgetxattr (rpath (ctx, path), name, value, size); +} + +static ssize_t 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,
@@ -502,4 +514,6 @@ FileOperations local_ops = { .remove = local_remove, .fsync = local_fsync, .statfs = local_statfs, + .lgetxattr = local_lgetxattr, + .llistxattr = local_llistxattr, };
hw/virtio-9p.c +190 -2
233 lines not on this page · raw message
hw/virtio-9p.h +14 -0
@@ -29,6 +29,8 @@ enum {P9_RGETATTR ,P9_TSETATTR =26 ,P9_RSETATTR , +P9_TXATTRWALK =30 , +P9_RXATTRWALK ,P9_TREADDIR =40 ,P9_RREADDIR , P9_TLINK = 70,
@@ -416,6 +418,18 @@ typedef struct V9fsRenameState {V9fsString name; } V9fsRenameState; +typedef struct V9fsXattrState +{ +V9fsPDU *pdu; +size_t offset; +V9fsFidState *file_fidp; +V9fsFidState *xattr_fidp; +V9fsString name; +int64_t size; +int flags; +void *value; +}V9fsXattrState ; +extern size_t pdu_packunpack (void *addr,struct iovec *sg,int sg_count,size_t offset,size_t size,int pack);
Signature · 1 line
1.6.5.2
PATCH v5 19/28 virtio-9p: Implement TXATTRCREATE
In reply to Venkateswararao Jujjuri (JV)From: Aneesh Kumar K.V <[email protected]>
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 | 2 + hw/virtio-9p-debug.c | 9 +++ hw/virtio-9p-local.c | 7 +++ hw/virtio-9p.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++--- hw/virtio-9p.h | 2 + 5 files changed, 152 insertions(+), 7 deletions(-)
hw/file-op-9p.h +2 -0
@@ -78,6 +78,8 @@ typedef struct FileOperationsssize_t (*lgetxattr)(FsContext *,const char *,const char *,void *,size_t );ssize_t (*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 +9 -0
@@ -588,6 +588,15 @@ void pprint_pdu(V9fsPDU *pdu)case P9_RXATTRWALK :fprintf (llogfile,"RXATTRWALK: (" );pprint_int64 (pdu,1 , &offset,"xattrsize" ); +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);
hw/virtio-9p-local.c +7 -0
@@ -486,6 +486,12 @@ static ssize_t 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,
@@ -516,4 +522,5 @@ FileOperations local_ops = { .statfs = local_statfs, .lgetxattr = local_lgetxattr, .llistxattr = local_llistxattr, + .lsetxattr = local_lsetxattr, };
hw/virtio-9p.c +132 -7
196 lines not on this page · raw message
hw/virtio-9p.h +2 -0
@@ -31,6 +31,8 @@ enum {P9_RSETATTR ,P9_TXATTRWALK =30 ,P9_RXATTRWALK , +P9_TXATTRCREATE =32 , +P9_RXATTRCREATE ,P9_TREADDIR =40 ,P9_RREADDIR , P9_TLINK = 70,
Signature · 1 line
1.6.5.2
PATCH v5 20/28 virtio-9p: Hide user.virtfs xattr in case of mapped security.
In reply to Venkateswararao Jujjuri (JV)From: Aneesh Kumar K.V <[email protected]>
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 | 71 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 70 insertions(+), 1 deletions(-)
hw/virtio-9p-local.c +70 -1
@@ -477,18 +477,87 @@ static int local_statfs(FsContext *s, const char *path, struct statfs *stbuf)static ssize_t 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 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.6.5.2
PATCH v5 21/28 virtio-9p: Add SM_NONE security model
In reply to Venkateswararao Jujjuri (JV)From: Aneesh Kumar K.V <[email protected]>
This is equivalent to SM_PASSTHROUGH security model. The only exception is, failure of privilige operation like chown are ignored. This makes a passthrough like security model usable for people who runs kvm as non root
--- hw/file-op-9p.h | 15 +++++++++++++-- hw/virtio-9p-local.c | 40 ++++++++++++++++++++++++++++++---------- hw/virtio-9p.c | 12 +++++++++--- qemu-options.hx | 4 ++-- vl.c | 2 +- 5 files changed, 55 insertions(+), 18 deletions(-)
hw/file-op-9p.h +13 -2
@@ -24,8 +24,19 @@typedef enum { -SM_PASSTHROUGH =1 ,/* uid/gid set on fileserver files */ -SM_MAPPED ,/* uid/gid part of xattr */ +/* +* Server will try to set uid/gid. +* On failure ignore the error. +*/ +SM_NONE =0 , +/* +* uid/gid set on fileserver files +*/ +SM_PASSTHROUGH =1 , +/* +* uid/gid part of xattr +*/ +SM_MAPPED , }SecModel ; typedef struct FsCred
hw/virtio-9p-local.c +30 -10
@@ -102,7 +102,13 @@ static int local_post_create_passthrough(FsContext *fs_ctx, const char *path,return -1 ; }if (chown (rpath (fs_ctx, path), credp->fc_uid, credp->fc_gid) <0 ) { -return -1 ; +/* +* If we fail to change ownership and if we are +* using security model none. Ignore the error +*/ +if (fs_ctx->fs_sm !=SM_NONE ) { +return -1 ; + } }return 0 ; }
@@ -122,7 +128,8 @@ static ssize_t local_readlink(FsContext *fs_ctx, const char *path, }while (tsize ==-1 && errno ==EINTR );close (fd);return tsize; - }else if (fs_ctx->fs_sm ==SM_PASSTHROUGH ) { + }else if ((fs_ctx->fs_sm ==SM_PASSTHROUGH ) || + (fs_ctx->fs_sm ==SM_NONE )) { tsize =readlink (rpath (fs_ctx, path), buf, bufsz); }return tsize;
@@ -189,7 +196,8 @@ static int local_chmod(FsContext *fs_ctx, const char *path, FsCred *credp) {if (fs_ctx->fs_sm ==SM_MAPPED ) {return local_set_xattr (rpath (fs_ctx, path), credp); - }else if (fs_ctx->fs_sm ==SM_PASSTHROUGH ) { + }else if ((fs_ctx->fs_sm ==SM_PASSTHROUGH ) || + (fs_ctx->fs_sm ==SM_NONE )) {return chmod (rpath (fs_ctx, path), credp->fc_mode); }return -1 ;
@@ -211,7 +219,8 @@ static int local_mknod(FsContext *fs_ctx, const char *path, FsCred *credp) serrno = errno; goto err_end; } - }else if (fs_ctx->fs_sm ==SM_PASSTHROUGH ) { + }else if ((fs_ctx->fs_sm ==SM_PASSTHROUGH ) || + (fs_ctx->fs_sm ==SM_NONE )) { err =mknod (rpath (fs_ctx, path), credp->fc_mode, credp->fc_rdev);if (err ==-1 ) {return err;
@@ -247,7 +256,8 @@ static int local_mkdir(FsContext *fs_ctx, const char *path, FsCred *credp) serrno = errno; goto err_end; } - }else if (fs_ctx->fs_sm ==SM_PASSTHROUGH ) { + }else if ((fs_ctx->fs_sm ==SM_PASSTHROUGH ) || + (fs_ctx->fs_sm ==SM_NONE )) { err =mkdir (rpath (fs_ctx, path), credp->fc_mode);if (err ==-1 ) {return err;
@@ -316,7 +326,8 @@ static int local_open2(FsContext *fs_ctx, const char *path, int flags, serrno = errno; goto err_end; } - }else if (fs_ctx->fs_sm ==SM_PASSTHROUGH ) { + }else if ((fs_ctx->fs_sm ==SM_PASSTHROUGH ) || + (fs_ctx->fs_sm ==SM_NONE )) { fd =open (rpath (fs_ctx, path), flags, credp->fc_mode);if (fd ==-1 ) {return fd;
@@ -372,15 +383,23 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath, serrno = errno; goto err_end; } - }else if (fs_ctx->fs_sm ==SM_PASSTHROUGH ) { + }else if ((fs_ctx->fs_sm ==SM_PASSTHROUGH ) || + (fs_ctx->fs_sm ==SM_NONE )) { err =symlink (oldpath,rpath (fs_ctx, newpath));if (err) {return err; } err =lchown (rpath (fs_ctx, newpath), credp->fc_uid, credp->fc_gid);if (err ==-1 ) { - serrno = errno; - goto err_end; +/* +* If we fail to change ownership and if we are +* using security model none. Ignore the error +*/ +if (fs_ctx->fs_sm !=SM_NONE ) { + serrno = errno; + goto err_end; + }else + err =0 ; } }return err;
@@ -447,7 +466,8 @@ static int local_chown(FsContext *fs_ctx, const char *path, FsCred *credp)return lchown (rpath (fs_ctx, path), credp->fc_uid, credp->fc_gid); }else if (fs_ctx->fs_sm ==SM_MAPPED ) {return local_set_xattr (rpath (fs_ctx, path), credp); - }else if (fs_ctx->fs_sm ==SM_PASSTHROUGH ) { + }else if ((fs_ctx->fs_sm ==SM_PASSTHROUGH ) || + (fs_ctx->fs_sm ==SM_NONE )) {return lchown (rpath (fs_ctx, path), credp->fc_uid, credp->fc_gid); }return -1 ;
hw/virtio-9p.c +9 -3
@@ -3546,12 +3546,18 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)* Client user credentials are saved in extended attributes. */ s->ctx.fs_sm =SM_MAPPED ; + }else if (!strcmp (fse->security_model,"none" )) { +/* +* Files on the fileserver are set to QEMU credentials. +*/ + s->ctx.fs_sm =SM_NONE ; + }else { -/* user haven't specified a correct security option */ -fprintf (stderr,"one of the following must be specified as the" +fprintf (stderr,"Default to security_model=none. You may want" +" enable advanced security model using " "security option:\n\t security_model=passthrough \n\t " "security_model=mapped\n" ); -return NULL ; + s->ctx.fs_sm =SM_NONE ; }if (lstat (fse->path, &stat)) {
qemu-options.hx +2 -2
@@ -485,7 +485,7 @@ ETEXI DEFHEADING(File system options:) DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, - "-fsdev local,id=id,path=path,security_model=[mapped|passthrough]\n", + "-fsdev local,id=id,path=path,security_model=[mapped|passthrough|none]\n", QEMU_ARCH_ALL) STEXI
@@ -518,7 +518,7 @@ ETEXI DEFHEADING(Virtual File system pass-through options:) DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs, - "-virtfs local,path=path,mount_tag=tag,security_model=[mapped|passthrough]\n", + "-virtfs local,path=path,mount_tag=tag,security_model=[mapped|passthrough|none]\n", QEMU_ARCH_ALL) STEXI
vl.c +1 -1
@@ -2320,7 +2320,7 @@ int main(int argc, char **argv, char **envp) qemu_opt_get(opts, "path") == NULL || qemu_opt_get(opts, "security_model") == NULL) {fprintf (stderr,"Usage: -virtfs fstype,path=/share_path/," -"security_model=[mapped|passthrough]," +"security_model=[mapped|passthrough|none]," "mnt_tag=tag.\n" );exit (1 ); }
Signature · 1 line
1.6.5.2
PATCH v5 22/28 virtio-9p: Use lchown which won't follow symlink
In reply to Venkateswararao Jujjuri (JV)From: Aneesh Kumar K.V <[email protected]>
We should always use functions which don't follow
symlink on the server
--- hw/virtio-9p-local.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/virtio-9p-local.c +1 -1
@@ -101,7 +101,7 @@ static int local_post_create_passthrough(FsContext *fs_ctx, const char *path,if (chmod (rpath (fs_ctx, path), credp->fc_mode &07777 ) <0 ) {return -1 ; } -if (chown (rpath (fs_ctx, path), credp->fc_uid, credp->fc_gid) <0 ) { +if (lchown (rpath (fs_ctx, path), credp->fc_uid, credp->fc_gid) <0 ) {/* * If we fail to change ownership and if we are * using security model none. Ignore the error
Signature · 1 line
1.6.5.2
PATCH v5 23/28 virtio-9p: Fix the memset usage
In reply to Venkateswararao Jujjuri (JV)From: Aneesh Kumar K.V <[email protected]>
The arguments are wrong. Use qemu_mallocz directly
--- hw/virtio-9p.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
hw/virtio-9p.c +1 -2
@@ -2823,8 +2823,7 @@ static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err)if (vs->v9stat.name.size !=0 ) {V9fsRenameState *vr; - vr =qemu_malloc (sizeof (V9fsRenameState)); -memset (vr,sizeof (*vr),0 ); + vr =qemu_mallocz (sizeof (V9fsRenameState)); vr->newdirfid =-1 ; vr->pdu = vs->pdu; vr->fidp = vs->fidp;
Signature · 1 line
1.6.5.2
PATCH v5 24/28 virtio-9p: Add support for removing xattr
In reply to Venkateswararao Jujjuri (JV)From: Aneesh Kumar K.V <[email protected]>
--- hw/file-op-9p.h | 1 + hw/virtio-9p-local.c | 17 +++++++++++++++++ hw/virtio-9p.c | 25 ++++++++++++++++++++----- 3 files changed, 38 insertions(+), 5 deletions(-)
hw/file-op-9p.h +1 -0
@@ -91,6 +91,7 @@ typedef struct FileOperationsssize_t (*llistxattr)(FsContext *,const char *,void *,size_t );int (*lsetxattr)(FsContext *,const char *,const char *,void *,size_t ,int ); +int (*lremovexattr)(FsContext *,const char *,const char *); void *opaque; } FileOperations;#endif
hw/virtio-9p-local.c +17 -0
@@ -581,6 +581,22 @@ static int local_lsetxattr(FsContext *ctx, const char *path, const char *name,return lsetxattr (rpath (ctx, path), name, value, size, flags); } +static int local_lremovexattr (FsContext *ctx, +const char *path,const char *name) +{ +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 lremovexattr (rpath (ctx, path), name); +} + +FileOperations local_ops = { .lstat = local_lstat, .readlink = local_readlink,
@@ -612,4 +628,5 @@ FileOperations local_ops = { .lgetxattr = local_lgetxattr, .llistxattr = local_llistxattr, .lsetxattr = local_lsetxattr, + .lremovexattr = local_lremovexattr, };
hw/virtio-9p.c +20 -5
@@ -286,6 +286,14 @@ static int v9fs_do_lsetxattr(V9fsState *s, V9fsString *path, xattr_name->data, value, size, flags); } +static int v9fs_do_lremovexattr (V9fsState *s,V9fsString *path, +V9fsString *xattr_name) +{ +return s->ops->lremovexattr (&s->ctx, path->data, + xattr_name->data); +} + +static void v9fs_string_init (V9fsString *str) { str->data =NULL ;
@@ -456,10 +464,14 @@ static int v9fs_xattr_fid_clunk(V9fsState *s, V9fsFidState *fidp) retval = -EINVAL ; goto free_out; } - retval =v9fs_do_lsetxattr (s, &fidp->path, &fidp->fs.xattr.name, - fidp->fs.xattr.value, - fidp->fs.xattr.len, - fidp->fs.xattr.flags); +if (fidp->fs.xattr.len) { + retval =v9fs_do_lsetxattr (s, &fidp->path, &fidp->fs.xattr.name, + fidp->fs.xattr.value, + fidp->fs.xattr.len, + fidp->fs.xattr.flags); + }else { + retval =v9fs_do_lremovexattr (s, &fidp->path, &fidp->fs.xattr.name); + } free_out:v9fs_string_free (&fidp->fs.xattr.name); free_value:
@@ -3392,7 +3404,10 @@ static void v9fs_xattrcreate(V9fsState *s, V9fsPDU *pdu) vs->xattr_fidp->fs.xattr.flags = flags;v9fs_string_init (&vs->xattr_fidp->fs.xattr.name);v9fs_string_copy (&vs->xattr_fidp->fs.xattr.name, &vs->name); - vs->xattr_fidp->fs.xattr.value =qemu_malloc (vs->size); +if (vs->size) + vs->xattr_fidp->fs.xattr.value =qemu_malloc (vs->size); +else + vs->xattr_fidp->fs.xattr.value =NULL ; out:complete_pdu (s, vs->pdu, err);
Signature · 1 line
1.6.5.2
PATCH v5 25/28 virtio-9p: Make sure -virtfs option works correctly
In reply to Venkateswararao Jujjuri (JV)From: Aneesh Kumar K.V <[email protected]>
When making copy of arguments we were doing partial copy
--- vl.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
@@ -2332,7 +2332,7 @@ int main(int argc, char **argv, char **envp) len +=strlen (qemu_opt_get (opts,"security_model" )); arg_fsdev =qemu_malloc ((len +1 ) *sizeof (*arg_fsdev)); - snprintf(arg_fsdev, len * sizeof(*arg_fsdev), + snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev), "%s,id=%s,path=%s,security_model=%s", qemu_opt_get(opts, "fstype"), qemu_opt_get(opts, "mount_tag"),
@@ -2343,7 +2343,7 @@ int main(int argc, char **argv, char **envp) len +=2 *strlen (qemu_opt_get (opts,"mount_tag" )); arg_9p =qemu_malloc ((len +1 ) *sizeof (*arg_9p)); -snprintf (arg_9p, len *sizeof (*arg_9p), +snprintf (arg_9p, (len +1 ) *sizeof (*arg_9p),"virtio-9p-pci,fsdev=%s,mount_tag=%s" ,qemu_opt_get (opts,"mount_tag" ),qemu_opt_get (opts,"mount_tag" ));
Signature · 1 line
1.6.5.2
PATCH v5 26/28 Remove all instances of unnecessary dotu variable.
In reply to Venkateswararao Jujjuri (JV)From: Arun R Bharadwaj <[email protected]>
--- hw/virtio-9p-debug.c | 26 ++++-------- hw/virtio-9p-debug.h | 1 - hw/virtio-9p.c | 115 +++++++++++++++++++++++--------------------------- 3 files changed, 61 insertions(+), 81 deletions(-)
hw/virtio-9p-debug.c +8 -18
@@ -169,12 +169,10 @@ static void pprint_stat(V9fsPDU *pdu, int rx, size_t *offsetp, const char *name)pprint_str (pdu, rx, offsetp,", uid" );pprint_str (pdu, rx, offsetp,", gid" );pprint_str (pdu, rx, offsetp,", muid" ); -if (dotu) { -pprint_str (pdu, rx, offsetp,", extension" ); -pprint_int32 (pdu, rx, offsetp,", uid" ); -pprint_int32 (pdu, rx, offsetp,", gid" ); -pprint_int32 (pdu, rx, offsetp,", muid" ); - } +pprint_str (pdu, rx, offsetp,", extension" ); +pprint_int32 (pdu, rx, offsetp,", uid" ); +pprint_int32 (pdu, rx, offsetp,", gid" ); +pprint_int32 (pdu, rx, offsetp,", muid" );fprintf (llogfile,"}" ); }
@@ -401,9 +399,7 @@ void pprint_pdu(V9fsPDU *pdu)pprint_int32 (pdu,0 , &offset,"afid" );pprint_str (pdu,0 , &offset,", uname" );pprint_str (pdu,0 , &offset,", aname" ); -if (dotu) { -pprint_int32 (pdu,0 , &offset,", n_uname" ); - } +pprint_int32 (pdu,0 , &offset,", n_uname" );break ;case P9_RAUTH :fprintf (llogfile,"RAUTH: (" );
@@ -415,9 +411,7 @@ void pprint_pdu(V9fsPDU *pdu)pprint_int32 (pdu,0 , &offset,", afid" );pprint_str (pdu,0 , &offset,", uname" );pprint_str (pdu,0 , &offset,", aname" ); -if (dotu) { -pprint_int32 (pdu,0 , &offset,", n_uname" ); - } +pprint_int32 (pdu,0 , &offset,", n_uname" );break ;case P9_RATTACH :fprintf (llogfile,"RATTACH: (" );
@@ -429,9 +423,7 @@ void pprint_pdu(V9fsPDU *pdu)case P9_RERROR :fprintf (llogfile,"RERROR: (" );pprint_str (pdu,1 , &offset,"ename" ); -if (dotu) { -pprint_int32 (pdu,1 , &offset,", ecode" ); - } +pprint_int32 (pdu,1 , &offset,", ecode" );break ;case P9_TFLUSH :fprintf (llogfile,"TFLUSH: (" );
@@ -466,9 +458,7 @@ void pprint_pdu(V9fsPDU *pdu)pprint_str (pdu,0 , &offset,", name" );pprint_int32 (pdu,0 , &offset,", perm" );pprint_int8 (pdu,0 , &offset,", mode" ); -if (dotu) { -pprint_str (pdu,0 , &offset,", extension" ); - } +pprint_str (pdu,0 , &offset,", extension" );break ;case P9_RCREATE :fprintf (llogfile,"RCREATE: (" );
hw/virtio-9p-debug.h +0 -1
@@ -1,7 +1,6 @@#ifndef _QEMU_VIRTIO_9P_DEBUG_H#define _QEMU_VIRTIO_9P_DEBUG_H -extern int dotu;void pprint_pdu (V9fsPDU *pdu);#endif
hw/virtio-9p.c +54 -63
155 lines not on this page · raw message
Signature · 1 line
1.6.5.2
PATCH v5 27/28 This patch implements TLERROR/RLERROR on the qemu 9P server.
In reply to Venkateswararao Jujjuri (JV)From: Arun R Bharadwaj <[email protected]>
--- hw/virtio-9p.c | 19 +++++++++++++------ hw/virtio-9p.h | 2 ++ 2 files changed, 15 insertions(+), 6 deletions(-)
hw/virtio-9p.c +13 -6
@@ -844,17 +844,24 @@ static void complete_pdu(V9fsState *s, V9fsPDU *pdu, ssize_t len)int8_t id = pdu->id +1 ;/* Response */ if (len <0 ) { -V9fsString str;int err = -len; + len =7 ; - str.data =strerror (err); - str.size =strlen (str.data); +if (s->proto_version !=V9FS_PROTO_2000L ) { +V9fsString str; + + str.data =strerror (err); + str.size =strlen (str.data); + + len +=pdu_marshal (pdu, len,"s" , &str); + id =P9_RERROR ; + } - len =7 ; - len +=pdu_marshal (pdu, len,"s" , &str); len +=pdu_marshal (pdu, len,"d" , err); - id =P9_RERROR ; +if (s->proto_version ==V9FS_PROTO_2000L ) { + id =P9_RLERROR ; + } }/* fill out the header */
hw/virtio-9p.h +2 -0
@@ -13,6 +13,8 @@#define VIRTIO_9P_MOUNT_TAG 0enum { +P9_TLERROR =6 , +P9_RLERROR ,P9_TSTATFS =8 ,P9_RSTATFS ,P9_TLOPEN =12 ,
Signature · 1 line
1.6.5.2
PATCH v5 28/28 virtio-9p: Change handling of flags in open() path for 9P2000.L
In reply to Venkateswararao Jujjuri (JV)From: Sripathi Kodi <[email protected]>
This patch applies on top of 9P2000.L patches that we have on the list. I took a look at how 9P server is handling open() flags in 9P2000.L path. I think we can do away with the valid_flags() function and simplify the code. The reasoning is as follows:
O_NOCTTY: (If the file is a terminal, don't make it the controlling terminal of the process even though the process does not have a controlling terminal) By the time the control reaches 9P client it is clear that what we have is not a terminal device. Hence it does not matter what we do with this flag. In any case 9P server can filter this flag out before making the syscall.
O_NONBLOCK: (Don't block if i) Can't read/write to the file ii) Can't get locks) This has an impact on FIFOs, but also on file locks. Hence we can pass it down to the system call.
O_ASYNC: From the manpage:
O_ASYNC
Enable signal-driven I/O: generate a signal (SIGIO by default, but this can be changed via fcntl(2)) when input or output becomes pos- sible on this file descriptor. This feature is only available for terminals, pseudo-terminals, sockets, and (since Linux 2.6) pipes and FIFOs. See fcntl(2) for further details.
Again, this does not make any impact on regular files handled by 9P. Also, we don't want 9P server to receive SIGIO. Hence I think 9P server can filter this flag out before making the syscall.
O_CLOEXEC: This flag makes sense only on the client. If guest user space sets this flag the guest VFS will take care of calling close() on the fd if an exec() happens. Hence 9P client need not be bothered with this flag. Also I think QEMU will not do an exec, but if it does, it makes sense to close these fds. Hence we can pass this flag down to the syscall.
O_CREAT: Since we are in open() path it means we have confirmed that the file exists. Hence there is no need to pass O_CREAT flag down to the system. In fact on some versions of glibc this causes problems, because we pass O_CREAT flag, but don't have permission bits. Hence we can just mask this flag out.
So in summary:
Mask out:O_NOCTTYO_ASYNCO_CREAT
Pass-through:O_NONBLOCKO_CLOEXEC
--- hw/virtio-9p.c | 14 +------------- 1 files changed, 1 insertions(+), 13 deletions(-)
hw/virtio-9p.c +1 -13
@@ -1684,15 +1684,6 @@ out:qemu_free (vs); } -static inline int valid_flags (int flag) -{ -if (flag &O_NOCTTY || flag &O_NONBLOCK || flag &O_ASYNC || - flag &O_CLOEXEC ) -return 0 ; -else -return 1 ; -} -static void v9fs_open_post_lstat (V9fsState *s,V9fsOpenState *vs,int err) {int flags;
@@ -1709,11 +1700,8 @@ static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)v9fs_open_post_opendir (s, vs, err); }else {if (s->proto_version ==V9FS_PROTO_2000L ) { -if (!valid_flags (vs->mode)) { - err = -EINVAL ; - goto out; - } flags = vs->mode; + flags &= ~(O_NOCTTY |O_ASYNC |O_CREAT ); }else { flags =omode_to_uflags (vs->mode); }
Signature · 1 line
1.6.5.2