virtiofsd: do fallocate for setupmapping requests with write flag
PATCH 1/1 virtiofsd: do fallocate for setupmapping requests with write flag
We'll have to make sure filesystem has allocated space for the dax mapping, otherwise, guest writes from virtiofs may hang since write page fault is not able to be resolved if host fs is full (->page_mkwrite() return -ENOSPC).
--- contrib/virtiofsd/passthrough_ll.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
contrib/virtiofsd/passthrough_ll.c +16 -0
@@ -1897,12 +1897,28 @@ static void lo_setupmapping(fuse_req_t req, fuse_ino_t ino, uint64_t foffset, } +if (flags &O_WRONLY ) { +/* this may allocate more space than we need. */ + ret =fallocate (fd,FALLOC_FL_KEEP_SIZE , foffset, len); +if (ret <0 ) { + ret = errno; +fprintf (stderr,"%s: fallocate fail (ino=%" PRId64"fd=%d foffset=0x%" PRIx64")\n" , + __func__, ino, fi ? (int )fi->fh :lo_fd (req, ino), foffset); + goto err; + } + +if (lo_debug (req)) +fprintf (stderr,"fallocate (foffset=%" PRIx64"moffset=%" PRIx64")\n" , + foffset, moffset); + } +if (fuse_virtio_map (req, &msg, fd)) {fprintf (stderr,"%s: map over virtio failed (ino=%" PRId64"fd=%d moffset=0x%" PRIx64")\n" , __func__, ino, fi ? (int )fi->fh :lo_fd (req, ino), moffset); ret =EINVAL ; } +err:if (!fi)close (fd);fuse_reply_err (req, ret);
Signature · 1 line
1.8.3.1
Quoted 7 lines · Liu Bo
We'll have to make sure filesystem has allocated space for the dax mapping, otherwise, guest writes from virtiofs may hang since write page fault is not able to be resolved if host fs is full (->page_mkwrite() return
-ENOSPC).Signed-off-by Liu Bo <[email protected]>
Quoted 44 lines
--- contrib/virtiofsd/passthrough_ll.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)contrib/virtiofsd/passthrough_ll.c +16
-1@@ -1897,12 +1897,28 @@ static void lo_setupmapping(fuse_req_t req, fuse_ino_t ino, uint64_t foffset, } +if (flags &O_WRONLY ) { +/* this may allocate more space than we need. */ + ret =fallocate (fd,FALLOC_FL_KEEP_SIZE , foffset, len); +if (ret <0 ) { + ret = errno; +fprintf (stderr,"%s: fallocate fail (ino=%" PRId64"fd=%d foffset=0x%" PRIx64")\n" , + __func__, ino, fi ? (int )fi->fh :lo_fd (req, ino), foffset); + goto err; + } + +if (lo_debug (req)) +fprintf (stderr,"fallocate (foffset=%" PRIx64"moffset=%" PRIx64")\n" , + foffset, moffset); + } +if (fuse_virtio_map (req, &msg, fd)) {fprintf (stderr,"%s: map over virtio failed (ino=%" PRId64"fd=%d moffset=0x%" PRIx64")\n" , __func__, ino, fi ? (int )fi->fh :lo_fd (req, ino), moffset); ret =EINVAL ; } +err:if (!fi)close (fd);fuse_reply_err (req, ret); --1.8.3.1
_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs
Signature · 1 line
[email protected]
Quoted 4 lines · Liu Bo
We'll have to make sure filesystem has allocated space for the dax mapping, otherwise, guest writes from virtiofs may hang since write page fault is not able to be resolved if host fs is full (->page_mkwrite() return
-ENOSPC).
The issues I see with fallocate are:
1. Space is now reserved for anything that is mapped with the write bit, even pages that are never written. This defeats sparseness, which is often relied on by applications and users to minimize space usage.
2. The setupmapping performance suffers from the fallocate overhead.
I tend to think that KVM's fault handling should be fixed to check return values so that the infinite loop is avoided. The root cause is in kvm.ko, not in virtiofsd, and fallocate is a workaround rather than a full fix.
Vivek: Do you have code that stops the async pagefault infinite loop in kvm.ko?
Quoted 45 lines
Signed-off-by Liu Bo <[email protected]>--- contrib/virtiofsd/passthrough_ll.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)contrib/virtiofsd/passthrough_ll.c +16
-0@@ -1897,12 +1897,28 @@ static void lo_setupmapping(fuse_req_t req, fuse_ino_t ino, uint64_t foffset, } +if (flags &O_WRONLY ) { +/* this may allocate more space than we need. */ + ret =fallocate (fd,FALLOC_FL_KEEP_SIZE , foffset, len); +if (ret <0 ) { + ret = errno; +fprintf (stderr,"%s: fallocate fail (ino=%" PRId64"fd=%d foffset=0x%" PRIx64")\n" , + __func__, ino, fi ? (int )fi->fh :lo_fd (req, ino), foffset); + goto err; + } + +if (lo_debug (req)) +fprintf (stderr,"fallocate (foffset=%" PRIx64"moffset=%" PRIx64")\n" , + foffset, moffset); + } +if (fuse_virtio_map (req, &msg, fd)) {fprintf (stderr,"%s: map over virtio failed (ino=%" PRId64"fd=%d moffset=0x%" PRIx64")\n" , __func__, ino, fi ? (int )fi->fh :lo_fd (req, ino), moffset); ret =EINVAL ; } +err:if (!fi)close (fd);fuse_reply_err (req, ret);Signature · 6 lines
1.8.3.1 _______________________________________________ Virtio-fs mailing list [email protected] https://www.redhat.com/mailman/listinfo/virtio-fs