virtiofsd: During setup mapping, open file O_RDWR only if needed
PATCH 1/1 virtiofsd: During setup mapping, open file O_RDWR only if needed
As of now we always open file O_RDWR (even if writable mappings are not required). This leads to copy up of file if file is backed by overlayfs and hence nullying advantages of overlayfs.
So open file O_RDONLY if writable mappings are not required. Open O_RDWR if writable mappings are needed.
--- contrib/virtiofsd/passthrough_ll.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
contrib/virtiofsd/passthrough_ll.c +6 -3
@@ -2197,15 +2197,15 @@ static void lo_setupmapping(fuse_req_t rVhostUserFSSlaveMsg msg = {0 };uint64_t vhu_flags;char *buf; +bool writable = flags &FUSE_SETUPMAPPING_FLAG_WRITE ;if (lo_debug (req))fuse_debug ("lo_setupmapping(ino=%" PRIu64", fi=0x%p)\n" , ino, (void *)fi); vhu_flags =VHOST_USER_FS_FLAG_MAP_R ; -if (flags &O_WRONLY ) { +if (writable) vhu_flags |=VHOST_USER_FS_FLAG_MAP_W ; - } msg.fd_offset[0 ] = foffset; msg.len[0 ] = len;
@@ -2223,7 +2223,10 @@ static void lo_setupmapping(fuse_req_t r* TODO: O_RDWR might not be allowed if file is read only or * write only. Fix it. */ - fd =openat (lo->proc_self_fd, buf,O_RDWR ); +if (writable) + fd =openat (lo->proc_self_fd, buf,O_RDWR ); +else + fd =openat (lo->proc_self_fd, buf,O_RDONLY );free (buf);if (fd ==-1 )return (void )fuse_reply_err (req, errno);
Quoted 17 lines · Vivek Goyal
As of now we always open file
O_RDWR(even if writable mappings are not required). This leads to copy up of file if file is backed by overlayfs and hence nullying advantages of overlayfs.So open file
O_RDONLYif writable mappings are not required. OpenO_RDWRif writable mappings are needed.Signed-off-by Vivek Goyal <[email protected]>--- contrib/virtiofsd/passthrough_ll.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)Index:
qemu/contrib/virtiofsd/passthrough_ll.c
===================================================================
contrib/virtiofsd/passthrough_ll.c static void lo_setupmapping(fuse_req_t r · line 2200
Quoted 4 lines
contrib/virtiofsd/passthrough_ll.c +1
-0@@ -2197,15 +2197,15 @@ static void lo_setupmapping(fuse_req_t rVhostUserFSSlaveMsg msg = {0 };uint64_t vhu_flags;char *buf; +bool writable = flags &FUSE_SETUPMAPPING_FLAG_WRITE ;
typo? flags is set to O_WRONLY or 0 in do_lookup, although this may work as same.
thanks,
-liubo
Quoted 25 lines
contrib/virtiofsd/passthrough_ll.c +5
-3if (lo_debug (req))fuse_debug ("lo_setupmapping(ino=%" PRIu64", fi=0x%p)\n" , ino, (void *)fi); vhu_flags =VHOST_USER_FS_FLAG_MAP_R ; -if (flags &O_WRONLY ) { +if (writable) vhu_flags |=VHOST_USER_FS_FLAG_MAP_W ; - } msg.fd_offset[0 ] = foffset; msg.len[0 ] = len;@@ -2223,7 +2223,10 @@ static void lo_setupmapping(fuse_req_t r* TODO: O_RDWR might not be allowed if file is read only or * write only. Fix it. */ - fd =openat (lo->proc_self_fd, buf,O_RDWR ); +if (writable) + fd =openat (lo->proc_self_fd, buf,O_RDWR ); +else + fd =openat (lo->proc_self_fd, buf,O_RDONLY );free (buf);if (fd ==-1 )return (void )fuse_reply_err (req, errno);
Quoted 13 lines · * Liu Bo ([email protected]) wrote:
Quoted 12 lines · Vivek Goyal
As of now we always open file
O_RDWR(even if writable mappings are not required). This leads to copy up of file if file is backed by overlayfs and hence nullying advantages of overlayfs.So open file
O_RDONLYif writable mappings are not required. OpenO_RDWRif writable mappings are needed.Signed-off-by Vivek Goyal <[email protected]>--- contrib/virtiofsd/passthrough_ll.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Quoted 11 lines
contrib/virtiofsd/passthrough_ll.c static void lo_setupmapping(fuse_req_t r · line 2200
Quoted 9 lines
Index:
qemu/contrib/virtiofsd/passthrough_ll.c
===================================================================contrib/virtiofsd/passthrough_ll.c +1
-0@@ -2197,15 +2197,15 @@ static void lo_setupmapping(fuse_req_t rVhostUserFSSlaveMsg msg = {0 };uint64_t vhu_flags;char *buf; +bool writable = flags &FUSE_SETUPMAPPING_FLAG_WRITE ;typo? flags is set to
O_WRONLYor 0 indo_lookup, although this may work as same.
Right; that should be O_WRONLY;do_setupmapping does:
genflags = 0;
genflags |= (arg->flags & FUSE_SETUPMAPPING_FLAG_WRITE) ? O_WRONLY : 0;to convert from the fuse definition on the wire to the O_ notation before calling the filesstem code.
Dave
Quoted 13 lines
thanks,
-liuboQuoted 11 lines
contrib/virtiofsd/passthrough_ll.c +1
-2if (lo_debug (req))fuse_debug ("lo_setupmapping(ino=%" PRIu64", fi=0x%p)\n" , ino, (void *)fi); vhu_flags =VHOST_USER_FS_FLAG_MAP_R ; -if (flags &O_WRONLY ) { +if (writable) vhu_flags |=VHOST_USER_FS_FLAG_MAP_W ; - }
Quoted 14 lines
Quoted 4 lines
contrib/virtiofsd/passthrough_ll.c +0
-0msg.fd_offset[0 ] = foffset; msg.len[0 ] = len;@@ -2223,7 +2223,10 @@ static void lo_setupmapping(fuse_req_t r* TODO: O_RDWR might not be allowed if file is read only or contrib/virtiofsd/passthrough_ll.c static void lo_setupmapping(fuse_req_t r · line 2232
Quoted 10 lines
contrib/virtiofsd/passthrough_ll.c +4
-1* write only. Fix it. */ - fd =openat (lo->proc_self_fd, buf,O_RDWR ); +if (writable) + fd =openat (lo->proc_self_fd, buf,O_RDWR ); +else + fd =openat (lo->proc_self_fd, buf,O_RDONLY );free (buf);if (fd ==-1 )return (void )fuse_reply_err (req, errno);
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 26 lines · Dr. David Alan Gilbert
Quoted 13 lines · * Liu Bo ([email protected]) wrote:
Quoted 12 lines · Vivek Goyal
As of now we always open file
O_RDWR(even if writable mappings are not required). This leads to copy up of file if file is backed by overlayfs and hence nullying advantages of overlayfs.So open file
O_RDONLYif writable mappings are not required. OpenO_RDWRif writable mappings are needed.Signed-off-by Vivek Goyal <[email protected]>--- contrib/virtiofsd/passthrough_ll.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)Quoted 11 lines
contrib/virtiofsd/passthrough_ll.c static void lo_setupmapping(fuse_req_t r · line 2200
Quoted 9 lines
Index:
qemu/contrib/virtiofsd/passthrough_ll.c
===================================================================contrib/virtiofsd/passthrough_ll.c +1
-0@@ -2197,15 +2197,15 @@ static void lo_setupmapping(fuse_req_t rVhostUserFSSlaveMsg msg = {0 };uint64_t vhu_flags;char *buf; +bool writable = flags &FUSE_SETUPMAPPING_FLAG_WRITE ;typo? flags is set to
O_WRONLYor 0 indo_lookup, although this may work as same.
Quoted 8 lines
Right; that should be
O_WRONLY;do_setupmappingdoes:genflags = 0; genflags |= (arg->flags & FUSE_SETUPMAPPING_FLAG_WRITE) ? O_WRONLY : 0;to convert from the fuse definition on the wire to the O_ notation before calling the filesstem code.
So I have two questions.
- O_WRONLY does not sound like correct mapping. FUSE_SETUPMAPPING_FLAG_WRITE only says that write behavior is required. It does not say *write only*.
- Is it must that we need to translate fuse message specific flag to O_* notation. How about let filesystem code parse it?
Thanks
Vivek
Quoted 33 lines · * Vivek Goyal ([email protected]) wrote:
Quoted 32 lines · Dr. David Alan Gilbert
Quoted 13 lines · * Liu Bo ([email protected]) wrote:
Quoted 12 lines · Vivek Goyal
As of now we always open file
O_RDWR(even if writable mappings are not required). This leads to copy up of file if file is backed by overlayfs and hence nullying advantages of overlayfs.So open file
O_RDONLYif writable mappings are not required. OpenO_RDWRif writable mappings are needed.Signed-off-by Vivek Goyal <[email protected]>--- contrib/virtiofsd/passthrough_ll.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)Quoted 11 lines
contrib/virtiofsd/passthrough_ll.c static void lo_setupmapping(fuse_req_t r · line 2200
Quoted 9 lines
Index:
qemu/contrib/virtiofsd/passthrough_ll.c
===================================================================contrib/virtiofsd/passthrough_ll.c +1
-0@@ -2197,15 +2197,15 @@ static void lo_setupmapping(fuse_req_t rVhostUserFSSlaveMsg msg = {0 };uint64_t vhu_flags;char *buf; +bool writable = flags &FUSE_SETUPMAPPING_FLAG_WRITE ;typo? flags is set to
O_WRONLYor 0 indo_lookup, although this may work as same.Right; that should be
O_WRONLY;do_setupmappingdoes:genflags = 0; genflags |= (arg->flags & FUSE_SETUPMAPPING_FLAG_WRITE) ? O_WRONLY : 0;
Quoted 7 lines
Quoted 2 lines
to convert from the fuse definition on the wire to the O_ notation before calling the filesstem code.
So I have two questions.
-
O_WRONLYdoes not sound like correct mapping.FUSE_SETUPMAPPING_FLAG_WRITEonly says that write behavior is required. It does not say *write only*.
True, we should make it end up as O_RDONLY or O_RDWR.
Quoted 2 lines
- Is it must that we need to translate fuse message specific flag to O_* notation. How about let filesystem code parse it?
I think all of the decoding of wire protocol is done in fuse_lowlevel, it tries not to pass protocol down.
Dave
Quoted 2 lines
Thanks
Vivek
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK