virtiofsd: Reset O_DIRECT flag during file open
PATCH v2 1/1 virtiofsd: Reset O_DIRECT flag during file open
If an application wants to do direct IO and opens a file with O_DIRECT in guest, that does not necessarily mean that we need to bypass page cache on host as well. So reset this flag on host.
If somebody needs to bypass page cache on host as well (and it is safe to do so), we can add a knob in daemon later to control this behavior.
I check virtio-9p and they do reset O_DIRECT flag.
--- contrib/virtiofsd/passthrough_ll.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
contrib/virtiofsd/passthrough_ll.c +14 -0
@@ -1752,6 +1752,13 @@ static void lo_create(fuse_req_t req, fuif (err) goto out; +/* +* O_DIRECT in guest should not necessarily mean bypassing page +* cache on host as well. If somebody needs that behavior, it +* probably should be a configuration knob in daemon. +*/ + fi->flags &= ~O_DIRECT ; + fd =openat (parent_inode->fd, name, (fi->flags |O_CREAT ) & ~O_NOFOLLOW , mode); err = fd ==-1 ? errno :0 ;
@@ -1967,6 +1974,13 @@ static void lo_open(fuse_req_t req, fuseif (lo->writeback && (fi->flags &O_APPEND )) fi->flags &= ~O_APPEND ; +/* +* O_DIRECT in guest should not necessarily mean bypassing page +* cache on host as well. If somebody needs that behavior, it +* probably should be a configuration knob in daemon. +*/ + fi->flags &= ~O_DIRECT ; +sprintf (buf,"%i" ,lo_fd (req, ino)); fd =openat (lo->proc_self_fd, buf, fi->flags & ~O_NOFOLLOW );if (fd ==-1 )
Quoted 7 lines · Vivek Goyal
If an application wants to do direct IO and opens a file with
O_DIRECTin guest, that does not necessarily mean that we need to bypass page cache on host as well. So reset this flag on host.If somebody needs to bypass page cache on host as well (and it is safe to do so), we can add a knob in daemon later to control this behavior.
Quoted 6 lines
I check virtio-9p and they do reset
O_DIRECTflag.Signed-off-by Vivek Goyal <[email protected]>--- contrib/virtiofsd/passthrough_ll.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
virtio-fs should work even if the host file system doesn't support O_DIRECT:
Quoted 10 lines · * Vivek Goyal ([email protected]) wrote:
If an application wants to do direct IO and opens a file with
O_DIRECTin guest, that does not necessarily mean that we need to bypass page cache on host as well. So reset this flag on host.If somebody needs to bypass page cache on host as well (and it is safe to do so), we can add a knob in daemon later to control this behavior.
I check virtio-9p and they do reset
O_DIRECTflag.Signed-off-by Vivek Goyal <[email protected]>
Merged; thanks
Quoted 26 lines
--- contrib/virtiofsd/passthrough_ll.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)Index:
qemu/contrib/virtiofsd/passthrough_ll.c
===================================================================contrib/virtiofsd/passthrough_ll.c +7
-0@@ -1752,6 +1752,13 @@ static void lo_create(fuse_req_t req, fuif (err) goto out; +/* +* O_DIRECT in guest should not necessarily mean bypassing page +* cache on host as well. If somebody needs that behavior, it +* probably should be a configuration knob in daemon. +*/ + fi->flags &= ~O_DIRECT ; + fd =openat (parent_inode->fd, name, (fi->flags |O_CREAT ) & ~O_NOFOLLOW , mode); err = fd ==-1 ? errno :0 ;@@ -1967,6 +1974,13 @@ static void lo_open(fuse_req_t req, fuseif (lo->writeback && (fi->flags &O_APPEND )) fi->flags &= ~O_APPEND ;
contrib/virtiofsd/passthrough_ll.c static void lo_open(fuse_req_t req, fuse · line 1986
Quoted 10 lines
contrib/virtiofsd/passthrough_ll.c +7
-0+/* +* O_DIRECT in guest should not necessarily mean bypassing page +* cache on host as well. If somebody needs that behavior, it +* probably should be a configuration knob in daemon. +*/ + fi->flags &= ~O_DIRECT ; +sprintf (buf,"%i" ,lo_fd (req, ino)); fd =openat (lo->proc_self_fd, buf, fi->flags & ~O_NOFOLLOW );if (fd ==-1 )
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK