Proxy FS driver for VirtFS
PATCH v5 12/14 hw/9pfs: Documentation changes related to proxy fs
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
--- qemu-options.hx | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-)
qemu-options.hx +16 -9
@@ -538,19 +538,19 @@ DEFHEADING() DEFHEADING(File system options:) DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, - "-fsdev fsdriver,id=id,path=path,[security_model={mapped|passthrough|none}]\n" - " [,writeout=immediate][,readonly]\n", + "-fsdev fsdriver,id=id[,path=path,][security_model={mapped|passthrough|none}]\n" + " [,writeout=immediate][,readonly][,sock_fd=sock_fd]\n", QEMU_ARCH_ALL) STEXI -@item -fsdev @var{fsdriver},id=@var{id},path=@var{path},[security_model=@var{security_model}][,writeout=@var{writeout}][,readonly] +@item -fsdev @var{fsdriver},id=@var{id},path=@var{path},[security_model=@var{security_model}][,writeout=@var{writeout}][,readonly][,sock_fd=@var{sock_fd}] @findex -fsdev Define a new file system device. Valid options are: @table @option @item @var{fsdriver} This option specifies the fs driver backend to use. -Currently "local" and "handle" file system drivers are supported. +Currently "local", "handle" and "proxy" file system drivers are supported. @item id=@var{id} Specifies identifier for this device @item path=@var{path}
@@ -567,7 +567,7 @@ file attributes. Directories exported by this security model cannot interact with other unix tools. "none" security model is same as passthrough except the sever won't report failures if it fails to set file attributes like ownership. Security model is mandatory -only for local fsdriver. Other fsdrivers (like handle) don't take +only for local fsdriver. Other fsdrivers (like handle, proxy) don't take security model as a parameter. @item writeout=@var{writeout} This is an optional argument. The only supported value is "immediate".
@@ -577,6 +577,10 @@ reported as written by the storage subsystem. @item readonly Enables exporting 9p share as a readonly mount for guests. By default read-write access is given. +@item sock_fd=@var{sock_fd} +Enables proxy filesystem driver to use passed socket descriptor for +communicating with virtfs-proxy-helper. Usually a helper like libvirt +will create socketpair and pass one of the fds as sock_fd @end table -fsdev option is used along with -device driver "virtio-9p-pci".
@@ -597,19 +601,19 @@ 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|none]\n" - " [,writeout=immediate][,readonly]\n", + " [,writeout=immediate][,readonly][,sock_fd=sock_fd]\n", QEMU_ARCH_ALL) STEXI -@item -virtfs @var{fsdriver},path=@var{path},mount_tag=@var{mount_tag},security_model=@var{security_model}[,writeout=@var{writeout}][,readonly] +@item -virtfs @var{fsdriver}[,path=@var{path}],mount_tag=@var{mount_tag}[,security_model=@var{security_model}][,writeout=@var{writeout}][,readonly][,sock_fd=@var{sock_fd}] @findex -virtfs The general form of a Virtual File system pass-through options are: @table @option @item @var{fsdriver} This option specifies the fs driver backend to use. -Currently "local" and "handle" file system drivers are supported. +Currently "local", "handle" and "proxy" file system drivers are supported. @item id=@var{id} Specifies identifier for this device @item path=@var{path}
@@ -626,7 +630,7 @@ file attributes. Directories exported by this security model cannot interact with other unix tools. "none" security model is same as passthrough except the sever won't report failures if it fails to set file attributes like ownership. Security model is mandatory only -for local fsdriver. Other fsdrivers (like handle) don't take security +for local fsdriver. Other fsdrivers (like handle, proxy) don't take security model as a parameter. @item writeout=@var{writeout} This is an optional argument. The only supported value is "immediate".
@@ -636,6 +640,9 @@ reported as written by the storage subsystem. @item readonly Enables exporting 9p share as a readonly mount for guests. By default read-write access is given. +@item sock_fd +Enables proxy filesystem driver to use passed 'sock_fd' as the socket +descriptor for interfacing with virtfs-proxy-helper @end table ETEXI
Signature · 1 line
1.7.6
PATCH v5 2/14 hw/9pfs: Move pdu_marshal/unmarshal code to a seperate file
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Move p9 marshaling/unmarshaling code to a separate file so that proxy filesytem driver can use these calls. Also made marshaling code generic to accept "struct iovec" instead of V9fsPDU.
--- Makefile.objs | 2 +- fsdev/virtio-9p-marshal.c | 338 +++++++++++++++++++++++++++++++++++++++++++++ fsdev/virtio-9p-marshal.h | 87 ++++++++++++ hw/9pfs/virtio-9p.c | 297 +--------------------------------------- hw/9pfs/virtio-9p.h | 83 +---------- 5 files changed, 438 insertions(+), 369 deletions(-) create mode 100644 fsdev/virtio-9p-marshal.c create mode 100644 fsdev/virtio-9p-marshal.h
Makefile.objs +1 -1
@@ -61,7 +61,7 @@ ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy) # Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add. # only pull in the actual virtio-9p device if we also enabled virtio. CONFIG_REALLY_VIRTFS=y -fsdev-nested-y = qemu-fsdev.o +fsdev-nested-y = qemu-fsdev.o virtio-9p-marshal.o else fsdev-nested-y = qemu-fsdev-dummy.o endif
fsdev/virtio-9p-marshal.c new file +338 -0
338 lines not on this page · raw message
fsdev/virtio-9p-marshal.h new file +87 -0
87 lines not on this page · raw message
hw/9pfs/virtio-9p.c +4 -293
321 lines not on this page · raw message
hw/9pfs/virtio-9p.h +8 -75
119 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH v5 5/14 hw/9pfs: File system helper process for qemu 9p proxy FS
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Provide root privilege access to QEMU 9p proxy filesystem using socket communication.
Proxy helper is started by root user as:
~ # virtfs-proxy-helper -f|--fd <socket descriptor> -p|--path <path-to-share>
--- Makefile | 3 + configure | 19 +++ fsdev/virtfs-proxy-helper.c | 300 +++++++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p-proxy.h | 9 ++ 4 files changed, 331 insertions(+), 0 deletions(-) create mode 100644 fsdev/virtfs-proxy-helper.c
Makefile +3 -0
@@ -154,6 +154,9 @@ qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) $(block-obj-y) qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) $(block-obj-y) qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y) +fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o +fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap + qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $@")
configure +19 -0
@@ -1939,6 +1939,22 @@ else fi ########################################## +# libcap probe + +if test "$cap" != "no" ; then + cat > $TMPC <<EOF +#include <stdio.h> +#include <sys/capability.h> +int main(void) { cap_t caps; caps = cap_init(); } +EOF + if compile_prog "" "-lcap" ; then + cap=yes + else + cap=no + fi +fi + +########################################## # pthread probe PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2"
@@ -2736,6 +2752,9 @@ confdir=$sysconfdir$confsuffix tools= if test "$softmmu" = yes ; then tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools" + if [ "$cap" = "yes" -a "$linux" = "yes" ] ; then + tools="$tools fsdev/virtfs-proxy-helper\$(EXESUF)" + fi if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then tools="qemu-nbd\$(EXESUF) $tools" if [ "$guest_agent" = "yes" ]; then
fsdev/virtfs-proxy-helper.c new file +300 -0
300 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.h +9 -0
@@ -14,6 +14,15 @@#define PROXY_MAX_IO_SZ (64 * 1024) +/* +* proxy iovec only support one element and +* marsha/unmarshal doesn't do little endian conversion. +*/ +#define proxy_unmarshal(in_sg, offset, fmt, args...) \ + v9fs_unmarshal(in_sg, 1, offset, 0, fmt, ##args) +#define proxy_marshal(out_sg, offset, fmt, args...) \ + v9fs_marshal(out_sg, 1, offset, 0, fmt, ##args) + typedef struct { uint32_t type; uint32_t size;
Signature · 1 line
1.7.6
PATCH v5 1/14 hw/9pfs: Move opt validation to FsDriver callback
In reply to M. Mohan KumarFrom: "Aneesh Kumar K.V" <[email protected]>
This remove all conditional code from common code path and make opt validation a FSDriver callback.
--- fsdev/file-op-9p.h | 15 +++++++++++++-- fsdev/qemu-fsdev.c | 44 ++++++-------------------------------------- fsdev/qemu-fsdev.h | 10 ---------- hw/9pfs/virtio-9p-device.c | 13 ++++++++----- hw/9pfs/virtio-9p-handle.c | 20 ++++++++++++++++++++ hw/9pfs/virtio-9p-local.c | 34 ++++++++++++++++++++++++++++++++++ vl.c | 8 ++------ 7 files changed, 83 insertions(+), 61 deletions(-)
fsdev/file-op-9p.h +13 -2
@@ -61,6 +61,16 @@ typedef struct extended_ops {#define V9FS_SEC_MASK 0x0000001C +typedef struct FileOperations FileOperations ; +/* +* Structure to store the various fsdev's passed through command line. +*/ +typedef struct FsDriverEntry { +char *fsdev_id; +char *path; +int export_flags; +FileOperations *ops; +}FsDriverEntry ; typedef struct FsContext {
@@ -82,8 +92,9 @@ typedef union V9fsFidOpenState V9fsFidOpenState;void cred_init (FsCred *); -typedef struct FileOperations +struct FileOperations { +int (*parse_opts)(QemuOpts *,struct FsDriverEntry *);int (*init)(struct FsContext *);int (*lstat)(FsContext *,V9fsPath *,struct stat *);ssize_t (*readlink)(FsContext *,V9fsPath *,char *,size_t );
@@ -128,6 +139,6 @@ typedef struct FileOperations V9fsPath *newdir, const char *new_name);int (*unlinkat)(FsContext *ctx,V9fsPath *dir,const char *name,int flags); void *opaque; -} FileOperations; +};#endif
fsdev/qemu-fsdev.c +6 -38
69 lines not on this page · raw message
fsdev/qemu-fsdev.h +0 -10
@@ -34,16 +34,6 @@ typedef struct FsDriverTable {FileOperations *ops; } FsDriverTable; -/* -* Structure to store the various fsdev's passed through command line. -*/ -typedef struct FsDriverEntry { -char *fsdev_id; -char *path; -int export_flags; -FileOperations *ops; -}FsDriverEntry ; - typedef struct FsDriverListEntry { FsDriverEntry fse; QTAILQ_ENTRY(FsDriverListEntry) next;
hw/9pfs/virtio-9p-device.c +8 -5
@@ -77,16 +77,19 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)exit (1 ); } -if (!fse->path || !conf->tag) { -/* we haven't specified a mount_tag or the path */ -fprintf (stderr,"fsdev with id %s needs path " -"and Virtio-9p device needs mount_tag arguments\n" , +if (!conf->tag) { +/* we haven't specified a mount_tag */ +fprintf (stderr,"fsdev with id %s needs mount_tag arguments\n" , conf->fsdev_id);exit (1 ); } s->ctx.export_flags = fse->export_flags; - s->ctx.fs_root =g_strdup (fse->path); +if (fse->path) { + s->ctx.fs_root =g_strdup (fse->path); + }else { + s->ctx.fs_root =NULL ; + } s->ctx.exops.get_st_gen =NULL ;if (fse->export_flags &V9FS_SM_PASSTHROUGH ) {
hw/9pfs/virtio-9p-handle.c +20 -0
@@ -641,7 +641,27 @@ out:return ret; } +static int handle_parse_opts (QemuOpts *opts,struct FsDriverEntry *fse) +{ +const char *sec_model =qemu_opt_get (opts,"security_model" ); +const char *path =qemu_opt_get (opts,"path" ); + +if (sec_model) { +fprintf (stderr,"Invalid argument security_model specified with handle fsdriver\n" ); +return -1 ; + } + +if (!path) { +fprintf (stderr,"fsdev: No path specified.\n" ); +return -1 ; + } + fse->path =g_strdup (path); +return 0 ; + +} +FileOperations handle_ops = { + .parse_opts = handle_parse_opts, .init = handle_init, .lstat = handle_lstat, .readlink = handle_readlink,
hw/9pfs/virtio-9p-local.c +34 -0
@@ -756,7 +756,41 @@ static int local_init(FsContext *ctx)return err; } +static int local_parse_opts (QemuOpts *opts,struct FsDriverEntry *fse) +{ +const char *sec_model =qemu_opt_get (opts,"security_model" ); +const char *path =qemu_opt_get (opts,"path" ); + +if (!sec_model) { +fprintf (stderr,"security model not specified, " +"local fs needs security model\nvalid options are:" +"\tsecurity_model=[passthrough|mapped|none]\n" ); +return -1 ; + } + +if (!strcmp (sec_model,"passthrough" )) { + fse->export_flags |=V9FS_SM_PASSTHROUGH ; + }else if (!strcmp (sec_model,"mapped" )) { + fse->export_flags |=V9FS_SM_MAPPED ; + }else if (!strcmp (sec_model,"none" )) { + fse->export_flags |=V9FS_SM_NONE ; + }else { +fprintf (stderr,"Invalid security model %s specified, valid options are" +"\n\t [passthrough|mapped|none]\n" , sec_model); +return -1 ; + } + +if (!path) { +fprintf (stderr,"fsdev: No path specified.\n" ); +return -1 ; + } + fse->path =g_strdup (path); + +return 0 ; +} +FileOperations local_ops = { + .parse_opts = local_parse_opts, .init = local_init, .lstat = local_lstat, .readlink = local_readlink,
vl.c +2 -6
@@ -2683,11 +2683,8 @@ int main(int argc, char **argv, char **envp) }if (qemu_opt_get (opts,"fsdriver" ) ==NULL || -qemu_opt_get (opts,"mount_tag" ) ==NULL || -qemu_opt_get (opts,"path" ) ==NULL ) { -fprintf (stderr,"Usage: -virtfs fsdriver,path=/share_path/," -"[security_model={mapped|passthrough|none}]," -"mount_tag=tag.\n" ); +qemu_opt_get (opts,"mount_tag" ) ==NULL ) { +fprintf (stderr,"Usage: -virtfs fsdriver,mount_tag=tag.\n" );exit (1 ); } fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
@@ -2733,7 +2730,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); }qemu_opt_set (fsdev,"fsdriver" ,"synth" ); -qemu_opt_set (fsdev,"path" ,"/" );/* ignored */ device =qemu_opts_create (qemu_find_opts ("device" ),NULL ,0 );qemu_opt_set (device,"driver" ,"virtio-9p-pci" );
Signature · 1 line
1.7.6
v5 cover Proxy FS driver for VirtFS
From: "M. Mohan Kumar" <[email protected]>
Pass-through security model in QEMU 9p server needs root privilege to do few file operations (like chown, chmod to any mode/uid:gid). There are two issues in pass-through security model
1) TOCTTOU vulnerability: Following symbolic links in the server could provide access to files beyond 9p export path.
2) Running QEMU with root privilege could be a security issue.
To overcome above issues, following approach is used: A new filesytem type 'proxy' is introduced. Proxy FS uses chroot + socket combination for securing the vulnerability known with following symbolic links. Intention of adding a new filesystem type is to allow qemu to run in non-root mode, but doing privileged operations using socket IO.
Proxy helper(a stand alone binary part of qemu) is invoked with root privileges. Proxy helper chroots into 9p export path and creates a socket pair or a named socket based on the command line parameter. Qemu and proxy helper communicate using this socket. QEMU proxy fs driver sends filesystem request to proxy helper and receives the response from it.
Proxy helper is designed so that it can drop the root privilege but retaining capbilities that are needed for doing filesystem operations (like CAP_DAC_OVERRIDE, CAP_FOWNER etc)
Changes from previous version V4:
* Handle the case request message > PROXY_MAX_IO_SZ as fatal, instead of recovering.
* Changed size data type to unsigned for both ProxyHeader and V9fsString
* Added chdir("/") before doing chroot()
* Code changes due to changing ProxyHeader size type to unsigned
Changes from previous version V3:
* Lots of code change involving
* Improve error handling in marshaling/unmarshaling code
* Return ENOBUFS when request/response size exceeds maximum buffer size
Changes from previous version V2:
* Added check to handle failures in marshaling/unmarshaling code. Also make sure that request/response will not exceed maximum buffer size (BUFF_SZ)
* Addressed Stefan's review comments
Changes from previous version:
*) Communication between qemu and helper process is similar to 9p way of packing elements (pdu marshaling).
Aneesh Kumar K.V (1):
hw/9pfs: Move opt validation to FsDriver callback
M. Mohan Kumar (13):
hw/9pfs: Move pdu_marshal/unmarshal code to a seperate file hw/9pfs: Add validation to {un}marshal code hw/9pfs: Add new proxy filesystem driver
hw/9pfs: File system helper process for qemu 9p proxy FS hw/9pfs: Open and create files
hw/9pfs: Create other filesystem objects
hw/9pfs: Add stat/readlink/statfs for proxy FS hw/9pfs: File ownership and others
hw/9pfs: xattr interfaces in proxy filesystem driver hw/9pfs: Proxy getversion
hw/9pfs: Documentation changes related to proxy fs hw/9pfs: man page for proxy helper
hw/9pfs: Add support to use named socket for proxy FS
Makefile | 15 +- Makefile.objs | 3 +- configure | 19 + fsdev/file-op-9p.h | 17 +- fsdev/qemu-fsdev.c | 45 +-- fsdev/qemu-fsdev.h | 11 +- fsdev/virtfs-proxy-helper.c | 1113 ++++++++++++++++++++++++++++++++++++ fsdev/virtfs-proxy-helper.texi | 63 +++ fsdev/virtio-9p-marshal.c | 360 ++++++++++++ fsdev/virtio-9p-marshal.h | 90 +++ hw/9pfs/virtio-9p-device.c | 13 +- hw/9pfs/virtio-9p-handle.c | 20 + hw/9pfs/virtio-9p-local.c | 34 ++ hw/9pfs/virtio-9p-proxy.c | 1210 ++++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p-proxy.h | 95 ++++ hw/9pfs/virtio-9p.c | 756 ++++++++++++-------------- hw/9pfs/virtio-9p.h | 83 +--- qemu-config.c | 13 + qemu-options.hx | 32 +- vl.c | 18 +- 20 files changed, 3448 insertions(+), 562 deletions(-) create mode 100644 fsdev/virtfs-proxy-helper.c create mode 100644 fsdev/virtfs-proxy-helper.texi create mode 100644 fsdev/virtio-9p-marshal.c create mode 100644 fsdev/virtio-9p-marshal.h create mode 100644 hw/9pfs/virtio-9p-proxy.c create mode 100644 hw/9pfs/virtio-9p-proxy.h
Signature · 1 line
1.7.6
PATCH v5 7/14 hw/9pfs: Create other filesystem objects
From: "M. Mohan Kumar" <[email protected]>
Add interfaces to create filesystem objects like directory, device nodes, symbolic links, links for proxy filesytem driver
--- fsdev/virtfs-proxy-helper.c | 129 ++++++++++++++++++++++++++-- hw/9pfs/virtio-9p-proxy.c | 199 +++++++++++++++++++++++++++++++++++++++---- hw/9pfs/virtio-9p-proxy.h | 8 ++- 3 files changed, 313 insertions(+), 23 deletions(-)
fsdev/virtfs-proxy-helper.c +123 -6
@@ -231,6 +231,30 @@ static int send_fd(int sockfd, int fd)return 0 ; } +static int send_status (int sockfd,struct iovec *iovec,int status) +{ +ProxyHeader header; +int retval, msg_size;; + +if (status <0 ) { + header.type =T_ERROR ; + }else { + header.type =T_SUCCESS ; + } + header.size =sizeof (status); +/* +* marshal the return status. We don't check error. +* because we are sure we have enough space for the status +*/ + msg_size =proxy_marshal (iovec,0 ,"ddd" , header.type, + header.size, status); + retval =socket_write (sockfd, iovec->iov_base, msg_size); +if (retval <0 ) { +return retval; + } +return 0 ; +} +/* * from man 7 capabilities, section * Effect of User ID Changes on Capabilities:
@@ -262,6 +286,67 @@ static int setfsugid(int uid, int gid) }/* +* create other filesystem objects and send 0 on success +* return -errno on error +*/ +static int do_create_others (int type,struct iovec *iovec) +{ +dev_t rdev; +int retval =0 ; +int offset =PROXY_HDR_SZ ; +V9fsString oldpath, path; +int mode, uid, gid, cur_uid, cur_gid; + +v9fs_string_init (&path); +v9fs_string_init (&oldpath); + cur_uid =geteuid (); + cur_gid =getegid (); + + retval =proxy_unmarshal (iovec, offset,"dd" , &uid, &gid); +if (retval <0 ) { +return retval; + } + offset += retval; + retval =setfsugid (uid, gid); +if (retval <0 ) { + retval = -errno; + goto err_out; + } +switch (type) { +case T_MKNOD : + retval =proxy_unmarshal (iovec, offset,"sdq" , &path, &mode, &rdev); +if (retval <0 ) { + goto err_out; + } + retval =mknod (path.data, mode, rdev); +break ; +case T_MKDIR : + retval =proxy_unmarshal (iovec, offset,"sd" , &path, &mode); +if (retval <0 ) { + goto err_out; + } + retval =mkdir (path.data, mode); +break ; +case T_SYMLINK : + retval =proxy_unmarshal (iovec, offset,"ss" , &oldpath, &path); +if (retval <0 ) { + goto err_out; + } + retval =symlink (oldpath.data, path.data); +break ; + } +if (retval <0 ) { + retval = -errno; + } + +err_out: +v9fs_string_free (&path); +v9fs_string_free (&oldpath); +setfsugid (cur_uid, cur_gid); +return retval; +} + +/* * create a file and send fd on success * return -errno on error */
@@ -331,7 +416,8 @@ static void usage(char *prog) basename(prog)); } -static int process_reply (int sock,int type,int retval) +static int process_reply (int sock,int type, +struct iovec *out_iovec,int retval) {switch (type) {case T_OPEN :
@@ -340,6 +426,14 @@ static int process_reply(int sock, int type, int retval)return -1 ; }break ; +case T_MKNOD : +case T_MKDIR : +case T_SYMLINK : +case T_LINK : +if (send_status (sock, out_iovec, retval) <0 ) { +return -1 ; + } +break ;default :return -1 ;break ;
@@ -351,10 +445,14 @@ static int process_requests(int sock) {int retval =0 ;ProxyHeader header; -struct iovec in_iovec; +V9fsString oldpath, path; +struct iovec in_iovec, out_iovec; + + in_iovec.iov_base =g_malloc (PROXY_MAX_IO_SZ +PROXY_HDR_SZ ); + in_iovec.iov_len =PROXY_MAX_IO_SZ +PROXY_HDR_SZ ; + out_iovec.iov_base =g_malloc (PROXY_MAX_IO_SZ +PROXY_HDR_SZ ); + out_iovec.iov_len =PROXY_MAX_IO_SZ +PROXY_HDR_SZ ; - in_iovec.iov_base =g_malloc (PROXY_MAX_IO_SZ +PROXY_HDR_SZ ); - in_iovec.iov_len =PROXY_MAX_IO_SZ +PROXY_HDR_SZ ;while (1 ) {/* * initialize the header type, so that we send
@@ -373,18 +471,37 @@ static int process_requests(int sock)case T_CREATE : retval =do_create (&in_iovec);break ; +case T_MKNOD : +case T_MKDIR : +case T_SYMLINK : + retval =do_create_others (header.type, &in_iovec); +break ; +case T_LINK : +v9fs_string_init (&path); +v9fs_string_init (&oldpath); + retval =proxy_unmarshal (&in_iovec,PROXY_HDR_SZ , +"ss" , &oldpath, &path); +if (retval >0 ) { + retval =link (oldpath.data, path.data); +if (retval <0 ) { + retval = -errno; + } + } +v9fs_string_free (&oldpath); +v9fs_string_free (&path); +break ;default : goto err_out;break ; } -if (process_reply (sock, header.type, retval) <0 ) { +if (process_reply (sock, header.type, &out_iovec, retval) <0 ) { goto err_out; } } - (void )socket_write; err_out:g_free (in_iovec.iov_base); +g_free (out_iovec.iov_base);return -1 ; }
hw/9pfs/virtio-9p-proxy.c +183 -16
270 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.h +7 -1
@@ -37,8 +37,14 @@ typedef struct {#define PROXY_HDR_SZ (sizeof(ProxyHeader))enum { -T_OPEN =1 , +T_SUCCESS =0 , +T_ERROR , +T_OPEN ,T_CREATE , +T_MKNOD , +T_MKDIR , +T_SYMLINK , +T_LINK , };#endif
Signature · 1 line
1.7.6
PATCH v5 9/14 hw/9pfs: File ownership and others
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add file ownership interfaces like chmod/chown, utime update, rename, remove and truncating files for proxy FS
--- Makefile | 2 +- fsdev/virtfs-proxy-helper.c | 83 ++++++++++++++++++++++++++ hw/9pfs/virtio-9p-proxy.c | 136 +++++++++++++++++++++++++++++++++++++++---- hw/9pfs/virtio-9p-proxy.h | 6 ++ 4 files changed, 214 insertions(+), 13 deletions(-)
Makefile +1 -1
@@ -154,7 +154,7 @@ qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) $(block-obj-y) qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) $(block-obj-y) qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y) -fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o +fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o oslib-posix.o $(trace-obj-y) fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
fsdev/virtfs-proxy-helper.c +83 -0
102 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.c +124 -12
185 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.h +6 -0
@@ -48,6 +48,12 @@ enum {T_LSTAT ,T_READLINK ,T_STATFS , +T_CHMOD , +T_CHOWN , +T_TRUNCATE , +T_UTIME , +T_RENAME , + T_REMOVE, }; typedef struct {
Signature · 1 line
1.7.6
PATCH v5 4/14 hw/9pfs: Add new proxy filesystem driver
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add new proxy filesystem driver to add root privilege to qemu process. It needs a helper process to be started by root user.
Following command line can be used to utilize proxy filesystem driver -virtfs proxy,id=<id>,mount_tag=<tag>,socket_fd=<socket-fd>
--- Makefile.objs | 1 + fsdev/qemu-fsdev.c | 1 + fsdev/qemu-fsdev.h | 1 + hw/9pfs/virtio-9p-proxy.c | 388 +++++++++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p-proxy.h | 24 +++ qemu-config.c | 6 + vl.c | 6 +- 7 files changed, 426 insertions(+), 1 deletions(-) create mode 100644 hw/9pfs/virtio-9p-proxy.c create mode 100644 hw/9pfs/virtio-9p-proxy.h
Makefile.objs +1 -0
@@ -312,6 +312,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y) 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o 9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o virtio-9p-synth.o 9pfs-nested-$(CONFIG_OPEN_BY_HANDLE) += virtio-9p-handle.o +9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-proxy.o hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y)) $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
fsdev/qemu-fsdev.c +1 -0
@@ -27,6 +27,7 @@ static FsDriverTable FsDrivers[] = { { .name = "handle", .ops = &handle_ops}, #endif { .name = "synth", .ops = &synth_ops}, + { .name = "proxy", .ops = &proxy_ops}, }; int qemu_fsdev_add(QemuOpts *opts)
fsdev/qemu-fsdev.h +1 -0
@@ -44,4 +44,5 @@ FsDriverEntry *get_fsdev_fsentry(char *id);extern FileOperations local_ops;extern FileOperations handle_ops;extern FileOperations synth_ops; +extern FileOperations proxy_ops;#endif
hw/9pfs/virtio-9p-proxy.c new file +388 -0
388 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Virtio 9p Proxy callback +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* M. Mohan Kumar <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/ +#ifndef _QEMU_VIRTIO_9P_PROXY_H +#define _QEMU_VIRTIO_9P_PROXY_H + +#define PROXY_MAX_IO_SZ (64 * 1024) + +typedef struct { +uint32_t type; +uint32_t size; +}ProxyHeader ; + +#define PROXY_HDR_SZ (sizeof(ProxyHeader)) + +#endif
qemu-config.c +6 -0
@@ -211,6 +211,9 @@ QemuOptsList qemu_fsdev_opts = { }, { .name = "readonly", .type = QEMU_OPT_BOOL, + }, { + .name = "sock_fd", + .type = QEMU_OPT_NUMBER, }, { /*End of list */ }
@@ -240,6 +243,9 @@ QemuOptsList qemu_virtfs_opts = { }, { .name = "readonly", .type = QEMU_OPT_BOOL, + }, { + .name = "sock_fd", + .type = QEMU_OPT_NUMBER, }, { /*End of list */ }
vl.c +5 -1
@@ -2669,7 +2669,7 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_virtfs: {QemuOpts *fsdev;QemuOpts *device; -const char *writeout; +const char *writeout, *sock_fd; olist =qemu_find_opts ("virtfs" );if (!olist) {
@@ -2709,6 +2709,10 @@ int main(int argc, char **argv, char **envp)qemu_opt_set (fsdev,"path" ,qemu_opt_get (opts,"path" ));qemu_opt_set (fsdev,"security_model" ,qemu_opt_get (opts,"security_model" )); + sock_fd =qemu_opt_get (opts,"sock_fd" ); +if (sock_fd) { +qemu_opt_set (fsdev,"sock_fd" , sock_fd); + }qemu_opt_set_bool (fsdev,"readonly" ,qemu_opt_get_bool (opts,"readonly" ,0 ));
Signature · 1 line
1.7.6
PATCH v5 10/14 hw/9pfs: xattr interfaces in proxy filesystem driver
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add xattr support for proxy FS
--- fsdev/virtfs-proxy-helper.c | 99 ++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p-proxy.c | 124 ++++++++++++++++++++++++++++++++++++++++--- hw/9pfs/virtio-9p-proxy.h | 4 ++ 3 files changed, 219 insertions(+), 8 deletions(-)
fsdev/virtfs-proxy-helper.c +99 -0
@@ -27,6 +27,7 @@#include <stdbool.h> #include <sys/vfs.h> #include <sys/stat.h> +#include <attr/xattr.h> #include "qemu-common.h" #include "virtio-9p-marshal.h" #include "hw/9pfs/virtio-9p-proxy.h"
@@ -329,6 +330,62 @@ static int send_response(int sock, struct iovec *iovec, int size)return 0 ; } +static int do_getxattr (int type,struct iovec *iovec,struct iovec *out_iovec) +{ +int size =0 , offset, retval; +V9fsString path, name, xattr; + +v9fs_string_init (&xattr); +v9fs_string_init (&path); + retval =proxy_unmarshal (iovec,PROXY_HDR_SZ ,"ds" , &size, &path); +if (retval <0 ) { +return retval; + } + offset =PROXY_HDR_SZ + retval; + +if (size) { + xattr.data =g_malloc (size); + xattr.size = size; + } +switch (type) { +case T_LGETXATTR : +v9fs_string_init (&name); + retval =proxy_unmarshal (iovec, offset,"s" , &name); +if (retval >0 ) { + retval =lgetxattr (path.data, name.data, xattr.data, size); +if (retval <0 ) { + retval = -errno; + }else { + xattr.size = retval; + } + } +v9fs_string_free (&name); +break ; +case T_LLISTXATTR : + retval =llistxattr (path.data, xattr.data, size); +if (retval <0 ) { + retval = -errno; + }else { + xattr.size = retval; + } +break ; + } +if (retval <0 ) { + goto err_out; + } + +if (!size) { +proxy_marshal (out_iovec,PROXY_HDR_SZ ,"d" , retval); + retval =sizeof (retval); + }else { + retval =proxy_marshal (out_iovec,PROXY_HDR_SZ ,"s" , &xattr); + } +err_out: +v9fs_string_free (&xattr); +v9fs_string_free (&path); +return retval; +} +static void stat_to_prstat (ProxyStat *pr_stat,struct stat *stat) {memset (pr_stat,0 ,sizeof (*pr_stat));
@@ -604,6 +661,8 @@ static int process_reply(int sock, int type,case T_UTIME :case T_RENAME :case T_REMOVE : +case T_LSETXATTR : +case T_LREMOVEXATTR :if (send_status (sock, out_iovec, retval) <0 ) {return -1 ; }
@@ -611,6 +670,8 @@ static int process_reply(int sock, int type,case T_LSTAT :case T_STATFS :case T_READLINK : +case T_LGETXATTR : +case T_LLISTXATTR :if (send_response (sock, out_iovec, retval) <0 ) {return -1 ; }
@@ -624,10 +685,13 @@ static int process_reply(int sock, int type,static int process_requests (int sock) { +int flags; +int size =0 ;int retval =0 ;uint64_t offset;ProxyHeader header;int mode, uid, gid; +V9fsString name, value;struct timespec spec[2 ];V9fsString oldpath, path;struct iovec in_iovec, out_iovec;
@@ -755,6 +819,41 @@ static int process_requests(int sock) }v9fs_string_free (&path);break ; +case T_LGETXATTR : +case T_LLISTXATTR : + retval =do_getxattr (header.type, &in_iovec, &out_iovec); +break ; +case T_LSETXATTR : +v9fs_string_init (&path); +v9fs_string_init (&name); +v9fs_string_init (&value); + retval =proxy_unmarshal (&in_iovec,PROXY_HDR_SZ ,"sssdd" , &path, + &name, &value, &size, &flags); +if (retval >0 ) { + retval =lsetxattr (path.data, + name.data, value.data, size, flags); +if (retval <0 ) { + retval = -errno; + } + } +v9fs_string_free (&path); +v9fs_string_free (&name); +v9fs_string_free (&value); +break ; +case T_LREMOVEXATTR : +v9fs_string_init (&path); +v9fs_string_init (&name); + retval =proxy_unmarshal (&in_iovec, +PROXY_HDR_SZ ,"ss" , &path, &name); +if (retval >0 ) { + retval =lremovexattr (path.data, name.data); +if (retval <0 ) { + retval = -errno; + } + } +v9fs_string_free (&path); +v9fs_string_free (&name); +break ;default : goto err_out;break ;
hw/9pfs/virtio-9p-proxy.c +116 -8
175 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.h +4 -0
@@ -54,6 +54,10 @@ enum {T_UTIME ,T_RENAME ,T_REMOVE , +T_LGETXATTR , +T_LLISTXATTR , +T_LSETXATTR , + T_LREMOVEXATTR, }; typedef struct {
Signature · 1 line
1.7.6
PATCH v5 8/14 hw/9pfs: Add stat/readlink/statfs for proxy FS
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
--- fsdev/virtfs-proxy-helper.c | 182 ++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p-proxy.c | 206 +++++++++++++++++++++++++++++++++++++++++-- hw/9pfs/virtio-9p-proxy.h | 34 +++++++ 3 files changed, 414 insertions(+), 8 deletions(-)
fsdev/virtfs-proxy-helper.c +182 -0
@@ -25,6 +25,8 @@#include <sys/fsuid.h> #include <stdarg.h> #include <stdbool.h> +#include <sys/vfs.h> +#include <sys/stat.h> #include "qemu-common.h" #include "virtio-9p-marshal.h" #include "hw/9pfs/virtio-9p-proxy.h"
@@ -286,6 +288,172 @@ static int setfsugid(int uid, int gid) }/* +* send response in two parts +* 1) ProxyHeader +* 2) Response or error status +* This function should be called with marshaled response +* send_response constructs header part and error part only. +* send response sends {ProxyHeader,Response} if the request was success +* otherwise sends {ProxyHeader,error status} +*/ +static int send_response (int sock,struct iovec *iovec,int size) +{ +int retval; +ProxyHeader header; + +/* +* If response size exceeds available iovec->iov_len, +* we return ENOBUFS +*/ +if (size >PROXY_MAX_IO_SZ ) { + size = -ENOBUFS ; + } + +if (size <0 ) { +/* +* In case of error we would not have got the error encoded +* already so encode the error here. +*/ + header.type =T_ERROR ; + header.size =sizeof (size); +proxy_marshal (iovec,PROXY_HDR_SZ ,"d" , size); + }else { + header.type =T_SUCCESS ; + header.size = size; + } +proxy_marshal (iovec,0 ,"dd" , header.type, header.size); + retval =socket_write (sock, iovec->iov_base, header.size +PROXY_HDR_SZ ); +if (retval <0 ) { +return retval;; + } +return 0 ; +} + +static void stat_to_prstat (ProxyStat *pr_stat,struct stat *stat) +{ +memset (pr_stat,0 ,sizeof (*pr_stat)); + pr_stat->st_dev = stat->st_dev; + pr_stat->st_ino = stat->st_ino; + pr_stat->st_nlink = stat->st_nlink; + pr_stat->st_mode = stat->st_mode; + pr_stat->st_uid = stat->st_uid; + pr_stat->st_gid = stat->st_gid; + pr_stat->st_rdev = stat->st_rdev; + pr_stat->st_size = stat->st_size; + pr_stat->st_blksize = stat->st_blksize; + pr_stat->st_blocks = stat->st_blocks; + pr_stat->st_atim_sec = stat->st_atim.tv_sec; + pr_stat->st_atim_nsec = stat->st_atim.tv_nsec; + pr_stat->st_mtim_sec = stat->st_mtim.tv_sec; + pr_stat->st_mtim_nsec = stat->st_mtim.tv_nsec; + pr_stat->st_ctim_sec = stat->st_ctim.tv_sec; + pr_stat->st_ctim_nsec = stat->st_ctim.tv_nsec; +} + +static void statfs_to_prstatfs (ProxyStatFS *pr_stfs,struct statfs *stfs) +{ +memset (pr_stfs,0 ,sizeof (*pr_stfs)); + pr_stfs->f_type = stfs->f_type; + pr_stfs->f_bsize = stfs->f_bsize; + pr_stfs->f_blocks = stfs->f_blocks; + pr_stfs->f_bfree = stfs->f_bfree; + pr_stfs->f_bavail = stfs->f_bavail; + pr_stfs->f_files = stfs->f_files; + pr_stfs->f_ffree = stfs->f_ffree; + pr_stfs->f_fsid[0 ] = stfs->f_fsid.__val[0 ]; + pr_stfs->f_fsid[1 ] = stfs->f_fsid.__val[1 ]; + pr_stfs->f_namelen = stfs->f_namelen; + pr_stfs->f_frsize = stfs->f_frsize; +} + +/* +* Gets stat/statfs information and packs in out_iovec structure +* on success returns number of bytes packed in out_iovec struture +* otherwise returns -errno +*/ +static int do_stat (int type,struct iovec *iovec,struct iovec *out_iovec) +{ +int retval; +V9fsString path; +ProxyStat pr_stat; +ProxyStatFS pr_stfs; +struct stat st_buf; +struct statfs stfs_buf; + +v9fs_string_init (&path); + retval =proxy_unmarshal (iovec,PROXY_HDR_SZ ,"s" , &path); +if (retval <0 ) { +return retval; + } + +switch (type) { +case T_LSTAT : + retval =lstat (path.data, &st_buf); +if (retval <0 ) { + retval = -errno; + }else { +stat_to_prstat (&pr_stat, &st_buf); + retval =proxy_marshal (out_iovec,PROXY_HDR_SZ , +"qqqdddqqqqqqqqqq" , pr_stat.st_dev, + pr_stat.st_ino, pr_stat.st_nlink, + pr_stat.st_mode, pr_stat.st_uid, + pr_stat.st_gid, pr_stat.st_rdev, + pr_stat.st_size, pr_stat.st_blksize, + pr_stat.st_blocks, + pr_stat.st_atim_sec, pr_stat.st_atim_nsec, + pr_stat.st_mtim_sec, pr_stat.st_mtim_nsec, + pr_stat.st_ctim_sec, pr_stat.st_ctim_nsec); + } +break ; +case T_STATFS : + retval =statfs (path.data, &stfs_buf); +if (retval <0 ) { + retval = -errno; + }else { +statfs_to_prstatfs (&pr_stfs, &stfs_buf); + retval =proxy_marshal (out_iovec,PROXY_HDR_SZ , +"qqqqqqqqqqq" , pr_stfs.f_type, + pr_stfs.f_bsize, pr_stfs.f_blocks, + pr_stfs.f_bfree, pr_stfs.f_bavail, + pr_stfs.f_files, pr_stfs.f_ffree, + pr_stfs.f_fsid[0 ], pr_stfs.f_fsid[1 ], + pr_stfs.f_namelen, pr_stfs.f_frsize); + } +break ; + } +v9fs_string_free (&path); +return retval; +} + +static int do_readlink (struct iovec *iovec,struct iovec *out_iovec) +{ +char *buffer; +int size, retval; +V9fsString target, path; + +v9fs_string_init (&path); + retval =proxy_unmarshal (iovec,PROXY_HDR_SZ ,"sd" , &path, &size); +if (retval <0 ) { +v9fs_string_free (&path); +return retval; + } + buffer =g_malloc (size); +v9fs_string_init (&target); + retval =readlink (path.data, buffer, size); +if (retval >0 ) { + buffer[retval] ='\0' ; +v9fs_string_sprintf (&target,"%s" , buffer); + retval =proxy_marshal (out_iovec,PROXY_HDR_SZ ,"s" , &target); + }else { + retval = -errno; + } +g_free (buffer); +v9fs_string_free (&target); +v9fs_string_free (&path); +return retval; +} + +/* * create other filesystem objects and send 0 on success * return -errno on error */
@@ -434,6 +602,13 @@ static int process_reply(int sock, int type,return -1 ; }break ; +case T_LSTAT : +case T_STATFS : +case T_READLINK : +if (send_response (sock, out_iovec, retval) <0 ) { +return -1 ; + } +break ;default :return -1 ;break ;
@@ -490,6 +665,13 @@ static int process_requests(int sock)v9fs_string_free (&oldpath);v9fs_string_free (&path);break ; +case T_LSTAT : +case T_STATFS : + retval =do_stat (header.type, &in_iovec, &out_iovec); +break ; +case T_READLINK : + retval =do_readlink (&in_iovec, &out_iovec); +break ;default : goto err_out;break ;
hw/9pfs/virtio-9p-proxy.c +198 -8
253 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.h +34 -0
@@ -45,6 +45,40 @@ enum {T_MKDIR ,T_SYMLINK ,T_LINK , +T_LSTAT , +T_READLINK , + T_STATFS, }; +typedef struct { +uint64_t st_dev; +uint64_t st_ino; +uint64_t st_nlink; +uint32_t st_mode; +uint32_t st_uid; +uint32_t st_gid; +uint64_t st_rdev; +uint64_t st_size; +uint64_t st_blksize; +uint64_t st_blocks; +uint64_t st_atim_sec; +uint64_t st_atim_nsec; +uint64_t st_mtim_sec; +uint64_t st_mtim_nsec; +uint64_t st_ctim_sec; +uint64_t st_ctim_nsec; +}ProxyStat ; + +typedef struct { +uint64_t f_type; +uint64_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 f_fsid[2 ]; +uint64_t f_namelen; +uint64_t f_frsize; +}ProxyStatFS ;#endif
Signature · 1 line
1.7.6
PATCH v5 3/14 hw/9pfs: Add validation to {un}marshal code
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
--- fsdev/virtio-9p-marshal.c | 148 ++++++++------ fsdev/virtio-9p-marshal.h | 19 +- hw/9pfs/virtio-9p.c | 467 +++++++++++++++++++++++++++++++++------------ 3 files changed, 438 insertions(+), 196 deletions(-)
fsdev/virtio-9p-marshal.c +85 -63
@@ -20,17 +20,12 @@#include <sys/uio.h> #include <string.h> #include <stdint.h> +#include <errno.h> #include "compiler.h" #include "virtio-9p-marshal.h" #include "bswap.h" -void v9fs_string_init (V9fsString *str) -{ - str->data =NULL ; - str->size =0 ; -} -void v9fs_string_free (V9fsString *str) {g_free (str->data);
@@ -62,11 +57,13 @@ void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs) } -static size_t v9fs_packunpack (void *addr,struct iovec *sg,int sg_count, -size_t offset,size_t size,int pack) +static ssize_t v9fs_packunpack (void *addr,struct iovec *sg,int sg_count, +size_t offset,size_t size,int pack) {int i =0 ;size_t copied =0 ; +size_t req_size = size; +for (i =0 ; size && i < sg_count; i++) {size_t len;
@@ -90,18 +87,23 @@ static size_t v9fs_packunpack(void *addr, struct iovec *sg, int sg_count, } } } - +if (copied < req_size) { +/* +* We copied less that requested size. error out +*/ +return -ENOBUFS ; + }return copied; } -static size_t v9fs_unpack (void *dst,struct iovec *out_sg,int out_num, -size_t offset,size_t size) +static ssize_t v9fs_unpack (void *dst,struct iovec *out_sg,int out_num, +size_t offset,size_t size) {return v9fs_packunpack (dst, out_sg, out_num, offset, size,0 ); } -size_t v9fs_pack (struct iovec *in_sg,int in_num,size_t offset, -const void *src,size_t size) +ssize_t v9fs_pack (struct iovec *in_sg,int in_num,size_t offset, +const void *src,size_t size) {return v9fs_packunpack ((void *)src, in_sg, in_num, offset, size,1 ); }
@@ -131,11 +133,12 @@ static int v9fs_copy_sg(struct iovec *src_sg, unsigned int num,return j; } -size_t v9fs_unmarshal (struct iovec *out_sg,int out_num,size_t offset, -int bswap,const char *fmt, ...) +ssize_t v9fs_unmarshal (struct iovec *out_sg,int out_num,size_t offset, +int bswap,const char *fmt, ...) {int i;va_list ap; +ssize_t copied;size_t old_offset = offset;va_start (ap, fmt);
@@ -143,13 +146,13 @@ size_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,switch (fmt[i]) {case 'b' : { uint8_t *valp = va_arg(ap, uint8_t *); - offset +=v9fs_unpack (valp, out_sg, out_num, offset,sizeof (*valp)); + copied =v9fs_unpack (valp, out_sg, out_num, offset,sizeof (*valp));break ; }case 'w' : {uint16_t val, *valp; valp = va_arg(ap, uint16_t *); - offset +=v9fs_unpack (&val, out_sg, out_num, offset,sizeof (val)); + copied =v9fs_unpack (&val, out_sg, out_num, offset,sizeof (val));if (bswap) { *valp =le16_to_cpu (val); }else {
@@ -160,7 +163,7 @@ size_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,case 'd' : {uint32_t val, *valp; valp = va_arg(ap, uint32_t *); - offset +=v9fs_unpack (&val, out_sg, out_num, offset,sizeof (val)); + copied =v9fs_unpack (&val, out_sg, out_num, offset,sizeof (val));if (bswap) { *valp =le32_to_cpu (val); }else {
@@ -171,7 +174,7 @@ size_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,case 'q' : {uint64_t val, *valp; valp = va_arg(ap, uint64_t *); - offset +=v9fs_unpack (&val, out_sg, out_num, offset,sizeof (val)); + copied =v9fs_unpack (&val, out_sg, out_num, offset,sizeof (val));if (bswap) { *valp =le64_to_cpu (val); }else {
@@ -187,59 +190,70 @@ size_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset, }case 's' : { V9fsString *str = va_arg(ap, V9fsString *); - offset +=v9fs_unmarshal (out_sg, out_num, offset, bswap, -"w" , &str->size); -/* FIXME: sanity check str->size */ - str->data =g_malloc (str->size +1 ); - offset +=v9fs_unpack (str->data, out_sg, out_num, offset, - str->size); - str->data[str->size] =0 ; + copied =v9fs_unmarshal (out_sg, out_num, offset, bswap, +"w" , &str->size); +if (copied >0 ) { + offset += copied; + str->data =g_malloc (str->size +1 ); + copied =v9fs_unpack (str->data, out_sg, out_num, offset, + str->size); +if (copied >0 ) { + str->data[str->size] =0 ; + }else { +v9fs_string_free (str); + } + }break ; }case 'Q' : { V9fsQID *qidp = va_arg(ap, V9fsQID *); - offset +=v9fs_unmarshal (out_sg, out_num, offset, bswap,"bdq" , - &qidp->type, &qidp->version, &qidp->path); + copied =v9fs_unmarshal (out_sg, out_num, offset, bswap,"bdq" , + &qidp->type, &qidp->version, &qidp->path);break ; }case 'S' : { V9fsStat *statp = va_arg(ap, V9fsStat *); - offset +=v9fs_unmarshal (out_sg, out_num, offset, bswap, + copied =v9fs_unmarshal (out_sg, out_num, offset, bswap,"wwdQdddqsssssddd" , - &statp->size, &statp->type, &statp->dev, - &statp->qid, &statp->mode, &statp->atime, - &statp->mtime, &statp->length, - &statp->name, &statp->uid, &statp->gid, - &statp->muid, &statp->extension, - &statp->n_uid, &statp->n_gid, - &statp->n_muid); + &statp->size, &statp->type, &statp->dev, + &statp->qid, &statp->mode, &statp->atime, + &statp->mtime, &statp->length, + &statp->name, &statp->uid, &statp->gid, + &statp->muid, &statp->extension, + &statp->n_uid, &statp->n_gid, + &statp->n_muid);break ; }case 'I' : { V9fsIattr *iattr = va_arg(ap, V9fsIattr *); - offset +=v9fs_unmarshal (out_sg, out_num, offset, bswap, -"ddddqqqqq" , - &iattr->valid, &iattr->mode, - &iattr->uid, &iattr->gid, &iattr->size, - &iattr->atime_sec, &iattr->atime_nsec, - &iattr->mtime_sec, &iattr->mtime_nsec); + copied =v9fs_unmarshal (out_sg, out_num, offset, bswap, +"ddddqqqqq" , + &iattr->valid, &iattr->mode, + &iattr->uid, &iattr->gid, &iattr->size, + &iattr->atime_sec, &iattr->atime_nsec, + &iattr->mtime_sec, &iattr->mtime_nsec);break ; }default :break ; } +if (copied <0 ) { +va_end (ap); +return copied; + } + offset += copied; } -va_end (ap);return offset - old_offset; } -size_t v9fs_marshal (struct iovec *in_sg,int in_num,size_t offset, -int bswap,const char *fmt, ...) +ssize_t v9fs_marshal (struct iovec *in_sg,int in_num,size_t offset, +int bswap,const char *fmt, ...) {int i;va_list ap; +ssize_t copied;size_t old_offset = offset;va_start (ap, fmt);
@@ -247,7 +261,7 @@ size_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,switch (fmt[i]) {case 'b' : {uint8_t val =va_arg (ap, int); - offset +=v9fs_pack (in_sg, in_num, offset, &val,sizeof (val)); + copied =v9fs_pack (in_sg, in_num, offset, &val,sizeof (val));break ; }case 'w' : {
@@ -257,7 +271,7 @@ size_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset, }else { val =va_arg (ap, int); } - offset +=v9fs_pack (in_sg, in_num, offset, &val,sizeof (val)); + copied =v9fs_pack (in_sg, in_num, offset, &val,sizeof (val));break ; }case 'd' : {
@@ -267,7 +281,7 @@ size_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset, }else { val =va_arg (ap, uint32_t); } - offset +=v9fs_pack (in_sg, in_num, offset, &val,sizeof (val)); + copied =v9fs_pack (in_sg, in_num, offset, &val,sizeof (val));break ; }case 'q' : {
@@ -277,7 +291,7 @@ size_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset, }else { val =va_arg (ap, uint64_t); } - offset +=v9fs_pack (in_sg, in_num, offset, &val,sizeof (val)); + copied =v9fs_pack (in_sg, in_num, offset, &val,sizeof (val));break ; }case 'v' : {
@@ -288,32 +302,35 @@ size_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset, }case 's' : { V9fsString *str = va_arg(ap, V9fsString *); - offset +=v9fs_marshal (in_sg, in_num, offset, bswap, -"w" , str->size); - offset +=v9fs_pack (in_sg, in_num, offset, str->data, str->size); + copied =v9fs_marshal (in_sg, in_num, offset, bswap, +"w" , str->size); +if (copied >0 ) { + offset += copied; + copied =v9fs_pack (in_sg, in_num, offset, str->data, str->size); + }break ; }case 'Q' : { V9fsQID *qidp = va_arg(ap, V9fsQID *); - offset +=v9fs_marshal (in_sg, in_num, offset, bswap,"bdq" , - qidp->type, qidp->version, qidp->path); + copied =v9fs_marshal (in_sg, in_num, offset, bswap,"bdq" , + qidp->type, qidp->version, qidp->path);break ; }case 'S' : { V9fsStat *statp = va_arg(ap, V9fsStat *); - offset +=v9fs_marshal (in_sg, in_num, offset, bswap, -"wwdQdddqsssssddd" , - statp->size, statp->type, statp->dev, - &statp->qid, statp->mode, statp->atime, - statp->mtime, statp->length, &statp->name, - &statp->uid, &statp->gid, &statp->muid, - &statp->extension, statp->n_uid, - statp->n_gid, statp->n_muid); + copied =v9fs_marshal (in_sg, in_num, offset, bswap, +"wwdQdddqsssssddd" , + statp->size, statp->type, statp->dev, + &statp->qid, statp->mode, statp->atime, + statp->mtime, statp->length, &statp->name, + &statp->uid, &statp->gid, &statp->muid, + &statp->extension, statp->n_uid, + statp->n_gid, statp->n_muid);break ; }case 'A' : { V9fsStatDotl *statp = va_arg(ap, V9fsStatDotl *); - offset += v9fs_marshal(in_sg, in_num, offset, bswap, + copied = v9fs_marshal(in_sg, in_num, offset, bswap, "qQdddqqqqqqqqqqqqqqq", statp->st_result_mask, &statp->qid, statp->st_mode,
@@ -331,6 +348,11 @@ size_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,default :break ; } +if (copied <0 ) { +va_end (ap); +return copied; + } + offset += copied; }va_end (ap);
fsdev/virtio-9p-marshal.h +11 -8
@@ -71,17 +71,20 @@ typedef struct V9fsStatDotl {uint64_t st_data_version; } V9fsStatDotl; -extern void v9fs_string_init (V9fsString *str); +static inline void v9fs_string_init (V9fsString *str) +{ + str->data =NULL ; + str->size =0 ; +}extern void v9fs_string_free (V9fsString *str);extern void v9fs_string_null (V9fsString *str);extern void v9fs_string_sprintf (V9fsString *str,const char *fmt, ...);extern void v9fs_string_copy (V9fsString *lhs,V9fsString *rhs); -size_t v9fs_pack (struct iovec *in_sg,int in_num,size_t offset, -const void *src,size_t size); -size_t v9fs_unmarshal (struct iovec *out_sg,int out_num,size_t offset, -int bswap,const char *fmt, ...); -size_t v9fs_marshal (struct iovec *in_sg,int in_num,size_t offset, -int bswap,const char *fmt, ...); - +ssize_t v9fs_pack (struct iovec *in_sg,int in_num,size_t offset, +const void *src,size_t size); +ssize_t v9fs_unmarshal (struct iovec *out_sg,int out_num,size_t offset, +int bswap,const char *fmt, ...); +ssize_t v9fs_marshal (struct iovec *in_sg,int in_num,size_t offset, +int bswap,const char *fmt, ...);#endif
hw/9pfs/virtio-9p.c +342 -125
881 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH v5 6/14 hw/9pfs: Open and create files
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add interfaces to open and create files for proxy file system driver.
--- fsdev/virtfs-proxy-helper.c | 178 ++++++++++++++++++++++++++++++++++++++++- hw/9pfs/virtio-9p-proxy.c | 187 +++++++++++++++++++++++++++++++++++++++++-- hw/9pfs/virtio-9p-proxy.h | 11 +++ 3 files changed, 367 insertions(+), 9 deletions(-)
fsdev/virtfs-proxy-helper.c +175 -3
@@ -9,6 +9,7 @@* the COPYING file in the top-level directory. */ #include <stdio.h> +#include <sys/socket.h> #include <string.h> #include <sys/un.h> #include <limits.h>
@@ -27,6 +28,7 @@#include "qemu-common.h" #include "virtio-9p-marshal.h" #include "hw/9pfs/virtio-9p-proxy.h" +#include "fsdev/virtio-9p-marshal.h" #define PROGNAME "virtfs-proxy-helper"
@@ -187,6 +189,139 @@ static int read_request(int sockfd, struct iovec *iovec, ProxyHeader *header)return 0 ; } +static int send_fd (int sockfd,int fd) +{ +struct msghdr msg; +struct iovec iov; +int retval, data; +struct cmsghdr *cmsg; +union MsgControl msg_control; + + iov.iov_base = &data; + iov.iov_len =sizeof (data); + +memset (&msg,0 ,sizeof (msg)); + msg.msg_iov = &iov; + msg.msg_iovlen =1 ; +/* No ancillary data on error */ +if (fd <0 ) { +/* fd is really negative errno if the request failed */ + data = fd; + }else { + data =V9FS_FD_VALID ; + msg.msg_control = &msg_control; + msg.msg_controllen =sizeof (msg_control); + + cmsg = &msg_control.cmsg; + cmsg->cmsg_len =CMSG_LEN (sizeof (fd)); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; +memcpy (CMSG_DATA (cmsg), &fd,sizeof (fd)); + } + +do { + retval =sendmsg (sockfd, &msg,0 ); + }while (retval <0 && errno ==EINTR ); +if (fd >=0 ) { +close (fd); + } +if (retval <0 ) { +return retval; + } +return 0 ; +} + +/* +* from man 7 capabilities, section +* Effect of User ID Changes on Capabilities: +* 4. If the file system user ID is changed from 0 to nonzero (see setfsuid(2)) +* then the following capabilities are cleared from the effective set: +* CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_DAC_READ_SEARCH, CAP_FOWNER, CAP_FSETID, +* CAP_LINUX_IMMUTABLE (since Linux 2.2.30), CAP_MAC_OVERRIDE, and CAP_MKNOD +* (since Linux 2.2.30). If the file system UID is changed from nonzero to 0, +* then any of these capabilities that are enabled in the permitted set +* are enabled in the effective set. +*/ +static int setfsugid (int uid,int gid) +{ +/* +* We still need DAC_OVERRIDE because we don't change +* supplementary group ids, and hence may be subjected DAC rules +*/ +cap_value_t cap_list[] = { +CAP_DAC_OVERRIDE , + }; + +setfsgid (gid); +setfsuid (uid); + +if (uid !=0 || gid !=0 ) { +return do_cap_set (cap_list,ARRAY_SIZE (cap_list),0 ); + } +return 0 ; +} + +/* +* create a file and send fd on success +* return -errno on error +*/ +static int do_create (struct iovec *iovec) +{ +int ret; +V9fsString path; +int flags, mode, uid, gid, cur_uid, cur_gid; + +v9fs_string_init (&path); + ret =proxy_unmarshal (iovec,PROXY_HDR_SZ ,"sdddd" , + &path, &flags, &mode, &uid, &gid); +if (ret <0 ) { + goto err_out; + } + cur_uid =geteuid (); + cur_gid =getegid (); + ret =setfsugid (uid, gid); +if (ret <0 ) { +/* +* On failure reset back to the +* old uid/gid +*/ + ret = -errno; + goto err_out; + } + ret =open (path.data, flags, mode); +if (ret <0 ) { + ret = -errno; + } + +err_out: +setfsugid (cur_uid, cur_gid); +v9fs_string_free (&path); +return ret; +} + +/* +* open a file and send fd on success +* return -errno on error +*/ +static int do_open (struct iovec *iovec) +{ +int flags, ret; +V9fsString path; + +v9fs_string_init (&path); + ret =proxy_unmarshal (iovec,PROXY_HDR_SZ ,"sd" , &path, &flags); +if (ret <0 ) { + goto err_out; + } + ret =open (path.data, flags); +if (ret <0 ) { + ret = -errno; + } +err_out: +v9fs_string_free (&path); +return ret; +} +static void usage (char *prog) { fprintf(stderr, "usage: %s\n"
@@ -196,22 +331,59 @@ static void usage(char *prog) basename(prog)); } +static int process_reply (int sock,int type,int retval) +{ +switch (type) { +case T_OPEN : +case T_CREATE : +if (send_fd (sock, retval) <0 ) { +return -1 ; + } +break ; +default : +return -1 ; +break ; + } +return 0 ; +} +static int process_requests (int sock) { -int retval; +int retval =0 ;ProxyHeader header;struct iovec in_iovec; in_iovec.iov_base =g_malloc (PROXY_MAX_IO_SZ +PROXY_HDR_SZ ); in_iovec.iov_len =PROXY_MAX_IO_SZ +PROXY_HDR_SZ ;while (1 ) { +/* +* initialize the header type, so that we send +* response to proper request type. +*/ + header.type =0 ; retval =read_request (sock, &in_iovec, &header);if (retval <0 ) { - goto error; + goto err_out; + } + +switch (header.type) { +case T_OPEN : + retval =do_open (&in_iovec); +break ; +case T_CREATE : + retval =do_create (&in_iovec); +break ; +default : + goto err_out; +break ; + } + +if (process_reply (sock, header.type, retval) <0 ) { + goto err_out; } } (void )socket_write; -error: +err_out:g_free (in_iovec.iov_base);return -1 ; }
hw/9pfs/virtio-9p-proxy.c +181 -6
212 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.h +11 -0
@@ -13,6 +13,7 @@#define _QEMU_VIRTIO_9P_PROXY_H#define PROXY_MAX_IO_SZ (64 * 1024) +#define V9FS_FD_VALID INT_MAX/* * proxy iovec only support one element and
@@ -23,6 +24,11 @@ #define proxy_marshal(out_sg, offset, fmt, args...) \ v9fs_marshal(out_sg, 1, offset, 0, fmt, ##args) +union MsgControl { +struct cmsghdr cmsg; +char control[CMSG_SPACE (sizeof (int ))]; +}; + typedef struct { uint32_t type; uint32_t size;
@@ -30,4 +36,9 @@ typedef struct {#define PROXY_HDR_SZ (sizeof(ProxyHeader)) +enum { +T_OPEN =1 , +T_CREATE , +}; +#endif
Signature · 1 line
1.7.6
PATCH v5 14/14 hw/9pfs: Add support to use named socket for proxy FS
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add option to use named socket for communicating between proxy helper and qemu proxy FS. Access to socket can be given by using command line options -u and -g. We can achive the same using a shell script over qemu and virtfs-proxy-helper using exec fd<><socket-path>, and then passing that fd as argument to qemu and virtfs-proxy-helper. Also having a server like virtfs-proxy-helper listening on a pathname without any authentication is little bit scary. So we have to decide whether this patch is really needed.
--- fsdev/file-op-9p.h | 2 + fsdev/virtfs-proxy-helper.c | 86 ++++++++++++++++++++++++++++++++++++++- fsdev/virtfs-proxy-helper.texi | 4 ++ hw/9pfs/virtio-9p-proxy.c | 52 +++++++++++++++++++++--- qemu-config.c | 7 +++ qemu-options.hx | 15 +++++-- vl.c | 6 ++- 7 files changed, 157 insertions(+), 15 deletions(-)
fsdev/file-op-9p.h +2 -0
@@ -57,6 +57,8 @@ typedef struct extended_ops {*/ #define V9FS_SM_NONE 0x00000010#define V9FS_RDONLY 0x00000020 +#define V9FS_PROXY_SOCK_FD 0x00000040 +#define V9FS_PROXY_SOCK_NAME 0x00000080#define V9FS_SEC_MASK 0x0000001C
fsdev/virtfs-proxy-helper.c +83 -3
136 lines not on this page · raw message
fsdev/virtfs-proxy-helper.texi +4 -0
@@ -46,6 +46,10 @@ Path to export for proxy filesystem driver Use given file descriptor as socket descriptor for communicating with qemu proxy fs drier. Usually a helper like libvirt will create socketpair and pass one of the fds as parameter to -f|--fd +@item -s|--socket socket-file +Creates named socket file for communicating with qemu proxy fs driver +@item -u|--uid uid -g|--gid gid +uid:gid combination to give access to named socket file @item -n|--nodaemon Run as a normal program. By default program will run in daemon mode @end table
hw/9pfs/virtio-9p-proxy.c +45 -7
70 lines not on this page · raw message
qemu-config.c +7 -0
@@ -211,6 +211,10 @@ QemuOptsList qemu_fsdev_opts = { }, { .name = "readonly", .type = QEMU_OPT_BOOL, + + }, { + .name = "socket", + .type = QEMU_OPT_STRING, }, { .name = "sock_fd", .type = QEMU_OPT_NUMBER,
@@ -244,6 +248,9 @@ QemuOptsList qemu_virtfs_opts = { .name = "readonly", .type = QEMU_OPT_BOOL, }, { + .name = "socket", + .type = QEMU_OPT_STRING, + }, { .name = "sock_fd", .type = QEMU_OPT_NUMBER, },
qemu-options.hx +11 -4
@@ -539,12 +539,12 @@ DEFHEADING(File system options:) DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, "-fsdev fsdriver,id=id[,path=path,][security_model={mapped|passthrough|none}]\n" - " [,writeout=immediate][,readonly][,sock_fd=sock_fd]\n", + " [,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd]\n", QEMU_ARCH_ALL) STEXI -@item -fsdev @var{fsdriver},id=@var{id},path=@var{path},[security_model=@var{security_model}][,writeout=@var{writeout}][,readonly][,sock_fd=@var{sock_fd}] +@item -fsdev @var{fsdriver},id=@var{id},path=@var{path},[security_model=@var{security_model}][,writeout=@var{writeout}][,readonly][,socket=@var{socket}|sock_fd=@var{sock_fd}] @findex -fsdev Define a new file system device. Valid options are: @table @option
@@ -577,6 +577,9 @@ reported as written by the storage subsystem. @item readonly Enables exporting 9p share as a readonly mount for guests. By default read-write access is given. +@item socket=@var{socket} +Enables proxy filesystem driver to use passed socket file for communicating +with virtfs-proxy-helper @item sock_fd=@var{sock_fd} Enables proxy filesystem driver to use passed socket descriptor for communicating with virtfs-proxy-helper. Usually a helper like libvirt
@@ -601,12 +604,12 @@ 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|none]\n" - " [,writeout=immediate][,readonly][,sock_fd=sock_fd]\n", + " [,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd]\n", QEMU_ARCH_ALL) STEXI -@item -virtfs @var{fsdriver}[,path=@var{path}],mount_tag=@var{mount_tag}[,security_model=@var{security_model}][,writeout=@var{writeout}][,readonly][,sock_fd=@var{sock_fd}] +@item -virtfs @var{fsdriver}[,path=@var{path}],mount_tag=@var{mount_tag}[,security_model=@var{security_model}][,writeout=@var{writeout}][,readonly][,socket=@var{socket}|sock_fd=@var{sock_fd}] @findex -virtfs The general form of a Virtual File system pass-through options are:
@@ -640,6 +643,10 @@ reported as written by the storage subsystem. @item readonly Enables exporting 9p share as a readonly mount for guests. By default read-write access is given. +@item socket=@var{socket} +Enables proxy filesystem driver to use passed socket file for +communicating with virtfs-proxy-helper. Usually a helper like libvirt +will create socketpair and pass one of the fds as sock_fd @item sock_fd Enables proxy filesystem driver to use passed 'sock_fd' as the socket descriptor for interfacing with virtfs-proxy-helper
vl.c +5 -1
@@ -2669,7 +2669,7 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_virtfs: {QemuOpts *fsdev;QemuOpts *device; -const char *writeout, *sock_fd; +const char *writeout, *sock_fd, *socket; olist =qemu_find_opts ("virtfs" );if (!olist) {
@@ -2709,6 +2709,10 @@ int main(int argc, char **argv, char **envp)qemu_opt_set (fsdev,"path" ,qemu_opt_get (opts,"path" ));qemu_opt_set (fsdev,"security_model" ,qemu_opt_get (opts,"security_model" )); + socket =qemu_opt_get (opts,"socket" ); +if (socket) { +qemu_opt_set (fsdev,"socket" , socket); + } sock_fd =qemu_opt_get (opts,"sock_fd" );if (sock_fd) {qemu_opt_set (fsdev,"sock_fd" , sock_fd);
Signature · 1 line
1.7.6
PATCH v5 13/14 hw/9pfs: man page for proxy helper
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
--- Makefile | 12 +++++++- fsdev/virtfs-proxy-helper.texi | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletions(-) create mode 100644 fsdev/virtfs-proxy-helper.texi
Makefile +11 -1
@@ -38,6 +38,7 @@ LIBS+=-lz $(LIBS_TOOLS) ifdef BUILD_DOCS DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8 QMP/qmp-commands.txt +DOCS+=fsdev/virtfs-proxy-helper.1 else DOCS= endif
@@ -283,7 +284,10 @@ ifdef CONFIG_POSIX $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8" $(INSTALL_DATA) qemu-nbd.8 "$(DESTDIR)$(mandir)/man8" endif - +ifdef CONFIG_VIRTFS + $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" + $(INSTALL_DATA) fsdev/virtfs-proxy-helper.1 "$(DESTDIR)$(mandir)/man1" +endif install-sysconfig: $(INSTALL_DIR) "$(DESTDIR)$(sysconfdir)/qemu" $(INSTALL_DATA) $(SRC_PATH)/sysconfigs/target/target-x86_64.conf "$(DESTDIR)$(sysconfdir)/qemu"
@@ -367,6 +371,12 @@ qemu-img.1: qemu-img.texi qemu-img-cmds.texi pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@, \ " GEN $@") +fsdev/virtfs-proxy-helper.1: fsdev/virtfs-proxy-helper.texi + $(call quiet-command, \ + perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< fsdev/virtfs-proxy-helper.pod && \ + pod2man --section=1 --center=" " --release=" " fsdev/virtfs-proxy-helper.pod > $@, \ + " GEN $@") + qemu-nbd.8: qemu-nbd.texi $(call quiet-command, \ perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-nbd.pod && \
fsdev/virtfs-proxy-helper.texi new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH v5 11/14 hw/9pfs: Proxy getversion
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add proxy getversion to get generation number
--- fsdev/virtfs-proxy-helper.c | 80 +++++++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p-proxy.c | 32 +++++++++++++++++ hw/9pfs/virtio-9p-proxy.h | 1 + 3 files changed, 113 insertions(+), 0 deletions(-)
fsdev/virtfs-proxy-helper.c +80 -0
@@ -28,6 +28,11 @@#include <sys/vfs.h> #include <sys/stat.h> #include <attr/xattr.h> +#include <sys/ioctl.h> +#include <linux/fs.h> +#ifdef CONFIG_LINUX_MAGIC_H +#include <linux/magic.h> +#endif #include "qemu-common.h" #include "virtio-9p-marshal.h" #include "hw/9pfs/virtio-9p-proxy.h"
@@ -35,6 +40,19 @@#define PROGNAME "virtfs-proxy-helper" +#ifndef XFS_SUPER_MAGIC +#define XFS_SUPER_MAGIC 0x58465342 +#endif +#ifndef EXT2_SUPER_MAGIC +#define EXT2_SUPER_MAGIC 0xEF53 +#endif +#ifndef REISERFS_SUPER_MAGIC +#define REISERFS_SUPER_MAGIC 0x52654973 +#endif +#ifndef BTRFS_SUPER_MAGIC +#define BTRFS_SUPER_MAGIC 0x9123683E +#endif +static struct option helper_opts[] = { {"fd" , required_argument,NULL ,'f' }, {"path" , required_argument,NULL ,'p' },
@@ -42,6 +60,7 @@ static struct option helper_opts[] = { };static bool is_daemon; +static bool get_version;/* IOC getversion IOCTL supported */ static void do_log (int loglevel,const char *format, ...) {
@@ -330,6 +349,45 @@ static int send_response(int sock, struct iovec *iovec, int size)return 0 ; } +/* +* gets generation number +* returns -errno on failure and sizeof(generation number) on success +*/ +static int do_getversion (struct iovec *iovec,struct iovec *out_iovec) +{ +V9fsString path; +uint64_t version; +int fd, retval = -ENOTTY ; + +/* no need to issue ioctl */ +if (!get_version) { + version =0 ; + retval =proxy_marshal (out_iovec,PROXY_HDR_SZ ,"q" , version); +return retval; + } +#ifdef FS_IOC_GETVERSION + retval =proxy_unmarshal (iovec,PROXY_HDR_SZ ,"s" , &path); +if (retval <0 ) { +return retval; + } + + fd =open (path.data,O_RDONLY ); +if (fd <0 ) { + retval = -errno; + goto err_out; + } +if (ioctl (fd,FS_IOC_GETVERSION , &version) <0 ) { + retval = -errno; + }else { + retval =proxy_marshal (out_iovec,PROXY_HDR_SZ ,"q" , version); + } +close (fd); +err_out: +v9fs_string_free (&path); +#endif +return retval; +} +static int do_getxattr (int type,struct iovec *iovec,struct iovec *out_iovec) {int size =0 , offset, retval;
@@ -672,6 +730,7 @@ static int process_reply(int sock, int type,case T_READLINK :case T_LGETXATTR :case T_LLISTXATTR : +case T_GETVERSION :if (send_response (sock, out_iovec, retval) <0 ) {return -1 ; }
@@ -854,6 +913,9 @@ static int process_requests(int sock)v9fs_string_free (&path);v9fs_string_free (&name);break ; +case T_GETVERSION : + retval =do_getversion (&in_iovec, &out_iovec); +break ;default : goto err_out;break ;
@@ -875,6 +937,8 @@ int main(int argc, char **argv)char *rpath =NULL ;struct stat stbuf;int c, option_index; +int retval; +struct statfs st_fs; is_daemon = true; sock =-1 ;
@@ -931,6 +995,22 @@ int main(int argc, char **argv)do_log (LOG_INFO ,"Started\n" ); + get_version = false; +#ifdef FS_IOC_GETVERSION +/* check whether underlying FS support IOC_GETVERSION */ + retval =statfs (rpath, &st_fs); +if (!retval) { +switch (st_fs.f_type) { +case EXT2_SUPER_MAGIC : +case BTRFS_SUPER_MAGIC : +case REISERFS_SUPER_MAGIC : +case XFS_SUPER_MAGIC : + get_version = true; +break ; + } + } +#endif +if (chdir ("/" ) <0 ) {do_perror ("chdir" ); goto error;
hw/9pfs/virtio-9p-proxy.c +32 -0
@@ -243,6 +243,9 @@ static int v9fs_receive_response(V9fsProxy *proxy, int type,v9fs_string_free (&xattr);break ; } +case T_GETVERSION : +proxy_unmarshal (reply,PROXY_HDR_SZ ,"q" , response); +break ;default :return -1 ; }
@@ -509,6 +512,14 @@ static int v9fs_request(V9fsProxy *proxy, int type, header.type =T_LREMOVEXATTR ; }break ; +case T_GETVERSION : + path = va_arg(ap, V9fsString *); + retval =proxy_marshal (iovec,PROXY_HDR_SZ ,"s" , path); +if (retval >0 ) { + header.size = retval; + header.type =T_GETVERSION ; + } +break ;default :error_report ("Invalid type %d\n" , type); retval = -EINVAL ;
@@ -559,6 +570,7 @@ static int v9fs_request(V9fsProxy *proxy, int type,case T_LSTAT :case T_READLINK :case T_STATFS : +case T_GETVERSION :if (v9fs_receive_response (proxy, type, &retval, response) <0 ) { goto close_error; }
@@ -1064,6 +1076,25 @@ static int proxy_unlinkat(FsContext *ctx, V9fsPath *dir,return ret; } +static int proxy_ioc_getversion (FsContext *fs_ctx,V9fsPath *path, +mode_t st_mode,uint64_t *st_gen) +{ +int err; + +/* Do not try to open special files like device nodes, fifos etc +* we can get fd for regular files and directories only +*/ +if (!S_ISREG (st_mode) && !S_ISDIR (st_mode)) { +return 0 ; + } + err =v9fs_request (fs_ctx->private,T_GETVERSION , st_gen,"s" , path); +if (err <0 ) { + errno = -err; + err =-1 ; + } +return err; +} +static int proxy_parse_opts (QemuOpts *opts,struct FsDriverEntry *fs) {const char *sock_fd =qemu_opt_get (opts,"sock_fd" );
@@ -1098,6 +1129,7 @@ static int proxy_init(FsContext *ctx)qemu_mutex_init (&proxy->mutex); ctx->export_flags |=V9FS_PATHNAME_FSCONTEXT ; + ctx->exops.get_st_gen = proxy_ioc_getversion;return 0 ; }
hw/9pfs/virtio-9p-proxy.h +1 -0
@@ -58,6 +58,7 @@ enum {T_LLISTXATTR ,T_LSETXATTR ,T_LREMOVEXATTR , + T_GETVERSION, }; typedef struct {
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH V5 06/14] hw/9pfs: Open and create files
In reply to M. Mohan KumarQuoted 14 lines · M. Mohan Kumar
From: "M. Mohan Kumar" <[email protected]>
Add interfaces to open and create files for proxy file system driver.
Signed-off-by M. Mohan Kumar <[email protected]>--- fsdev/virtfs-proxy-helper.c | 178 ++++++++++++++++++++++++++++++++++++++++- hw/9pfs/virtio-9p-proxy.c | 187 +++++++++++++++++++++++++++++++++++++++++-- hw/9pfs/virtio-9p-proxy.h | 11 +++ 3 files changed, 367 insertions(+), 9 deletions(-)fsdev/virtfs-proxy-helper.c +2
-0+static int setfsugid (int uid,int gid) +{
fsdev/virtfs-proxy-helper.c static int read_request(int sockfd, struct iovec *iovec, ProxyHeader *header) · line 256
Quoted 10 lines
fsdev/virtfs-proxy-helper.c +10
-0+/* +* We still need DAC_OVERRIDE because we don't change +* supplementary group ids, and hence may be subjected DAC rules +*/ +cap_value_t cap_list[] = { +CAP_DAC_OVERRIDE , + }; + +setfsgid (gid); +setfsuid (uid);
Fedora 17 now complains about this:
CC fsdev/virtfs-proxy-helper.ofsdev/virtfs-proxy-helper.c: In function ‘setfsugid’:fsdev/virtfs-proxy-helper.c:293:13: error: ignoring return value of ‘setfsgid’, declared with attribute warn_unused_result [-Werror=unused-result] fsdev/virtfs-proxy-helper.c:294:13: error: ignoring return value of ‘setfsuid’, declared with attribute warn_unused_result [-Werror=unused-result]
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org