From: Max Reitz <mreitz@redhat.com> To: qemu-devel@nongnu.org, virtio-fs@redhat.com Cc: Stefan Hajnoczi <stefanha@redhat.com>, "Dr . David Alan Gilbert" <dgilbert@redhat.com>, Vivek Goyal <vgoyal@redhat.com>, Max Reitz <mreitz@redhat.com> Subject: [PATCH v3 05/10] virtiofsd: Let lo_fd() return a TempFd Date: Fri, 30 Jul 2021 17:01:29 +0200 [thread overview] Message-ID: <20210730150134.216126-6-mreitz@redhat.com> (raw) In-Reply-To: <20210730150134.216126-1-mreitz@redhat.com> Accessing lo_inode.fd must generally happen through lo_inode_fd(), and lo_fd() is no exception; and then it must pass on the TempFd it has received from lo_inode_fd(). (Note that all lo_fd() calls now use proper error handling, where all of them were in-line before; i.e. they were used in place of the fd argument of some function call. This only worked because the only error that could occur was that lo_inode() failed to find the inode ID: Then -1 would be passed as the fd, which would result in an EBADF error, which is precisely what we would want to return to the guest for an invalid inode ID. Now, though, lo_inode_fd() might potentially invoke open_by_handle_at(), which can return many different errors, and they should be properly handled and returned to the guest. So we can no longer allow lo_fd() to be used in-line, and instead need to do proper error handling for it.) Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Connor Kuehl <ckuehl@redhat.com> --- tools/virtiofsd/passthrough_ll.c | 55 +++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c index 86b901cf19..9e1bc37af8 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -650,18 +650,19 @@ static int lo_inode_fd(const struct lo_inode *inode, TempFd *tfd) * they are done with the fd. This will be done in a later patch to make * review easier. */ -static int lo_fd(fuse_req_t req, fuse_ino_t ino) +static int lo_fd(fuse_req_t req, fuse_ino_t ino, TempFd *tfd) { struct lo_inode *inode = lo_inode(req, ino); - int fd; + int res; if (!inode) { - return -1; + return -EBADF; } - fd = inode->fd; + res = lo_inode_fd(inode, tfd); + lo_inode_put(lo_data(req), &inode); - return fd; + return res; } /* @@ -798,14 +799,19 @@ static void lo_init(void *userdata, struct fuse_conn_info *conn) static void lo_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) { + g_auto(TempFd) ino_fd = TEMP_FD_INIT; int res; struct stat buf; struct lo_data *lo = lo_data(req); (void)fi; - res = - fstatat(lo_fd(req, ino), "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW); + res = lo_fd(req, ino, &ino_fd); + if (res < 0) { + return (void)fuse_reply_err(req, -res); + } + + res = fstatat(ino_fd.fd, "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW); if (res == -1) { return (void)fuse_reply_err(req, errno); } @@ -1529,6 +1535,7 @@ out: static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name) { + g_auto(TempFd) parent_fd = TEMP_FD_INIT; int res; struct lo_inode *inode; struct lo_data *lo = lo_data(req); @@ -1543,13 +1550,19 @@ static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name) return; } + res = lo_fd(req, parent, &parent_fd); + if (res < 0) { + fuse_reply_err(req, -res); + return; + } + inode = lookup_name(req, parent, name); if (!inode) { fuse_reply_err(req, EIO); return; } - res = unlinkat(lo_fd(req, parent), name, AT_REMOVEDIR); + res = unlinkat(parent_fd.fd, name, AT_REMOVEDIR); fuse_reply_err(req, res == -1 ? errno : 0); unref_inode_lolocked(lo, inode, 1); @@ -1635,6 +1648,7 @@ out: static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name) { + g_auto(TempFd) parent_fd = TEMP_FD_INIT; int res; struct lo_inode *inode; struct lo_data *lo = lo_data(req); @@ -1649,13 +1663,19 @@ static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name) return; } + res = lo_fd(req, parent, &parent_fd); + if (res < 0) { + fuse_reply_err(req, -res); + return; + } + inode = lookup_name(req, parent, name); if (!inode) { fuse_reply_err(req, EIO); return; } - res = unlinkat(lo_fd(req, parent), name, 0); + res = unlinkat(parent_fd.fd, name, 0); fuse_reply_err(req, res == -1 ? errno : 0); unref_inode_lolocked(lo, inode, 1); @@ -1735,10 +1755,16 @@ static void lo_forget_multi(fuse_req_t req, size_t count, static void lo_readlink(fuse_req_t req, fuse_ino_t ino) { + g_auto(TempFd) ino_fd = TEMP_FD_INIT; char buf[PATH_MAX + 1]; int res; - res = readlinkat(lo_fd(req, ino), "", buf, sizeof(buf)); + res = lo_fd(req, ino, &ino_fd); + if (res < 0) { + return (void)fuse_reply_err(req, -res); + } + + res = readlinkat(ino_fd.fd, "", buf, sizeof(buf)); if (res == -1) { return (void)fuse_reply_err(req, errno); } @@ -2535,10 +2561,17 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, static void lo_statfs(fuse_req_t req, fuse_ino_t ino) { + g_auto(TempFd) ino_fd = TEMP_FD_INIT; int res; struct statvfs stbuf; - res = fstatvfs(lo_fd(req, ino), &stbuf); + res = lo_fd(req, ino, &ino_fd); + if (res < 0) { + fuse_reply_err(req, -res); + return; + } + + res = fstatvfs(ino_fd.fd, &stbuf); if (res == -1) { fuse_reply_err(req, errno); } else { -- 2.31.1
WARNING: multiple messages have this Message-ID (diff)
From: Max Reitz <mreitz@redhat.com> To: qemu-devel@nongnu.org, virtio-fs@redhat.com Cc: Vivek Goyal <vgoyal@redhat.com>, Max Reitz <mreitz@redhat.com> Subject: [Virtio-fs] [PATCH v3 05/10] virtiofsd: Let lo_fd() return a TempFd Date: Fri, 30 Jul 2021 17:01:29 +0200 [thread overview] Message-ID: <20210730150134.216126-6-mreitz@redhat.com> (raw) In-Reply-To: <20210730150134.216126-1-mreitz@redhat.com> Accessing lo_inode.fd must generally happen through lo_inode_fd(), and lo_fd() is no exception; and then it must pass on the TempFd it has received from lo_inode_fd(). (Note that all lo_fd() calls now use proper error handling, where all of them were in-line before; i.e. they were used in place of the fd argument of some function call. This only worked because the only error that could occur was that lo_inode() failed to find the inode ID: Then -1 would be passed as the fd, which would result in an EBADF error, which is precisely what we would want to return to the guest for an invalid inode ID. Now, though, lo_inode_fd() might potentially invoke open_by_handle_at(), which can return many different errors, and they should be properly handled and returned to the guest. So we can no longer allow lo_fd() to be used in-line, and instead need to do proper error handling for it.) Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Connor Kuehl <ckuehl@redhat.com> --- tools/virtiofsd/passthrough_ll.c | 55 +++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c index 86b901cf19..9e1bc37af8 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -650,18 +650,19 @@ static int lo_inode_fd(const struct lo_inode *inode, TempFd *tfd) * they are done with the fd. This will be done in a later patch to make * review easier. */ -static int lo_fd(fuse_req_t req, fuse_ino_t ino) +static int lo_fd(fuse_req_t req, fuse_ino_t ino, TempFd *tfd) { struct lo_inode *inode = lo_inode(req, ino); - int fd; + int res; if (!inode) { - return -1; + return -EBADF; } - fd = inode->fd; + res = lo_inode_fd(inode, tfd); + lo_inode_put(lo_data(req), &inode); - return fd; + return res; } /* @@ -798,14 +799,19 @@ static void lo_init(void *userdata, struct fuse_conn_info *conn) static void lo_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) { + g_auto(TempFd) ino_fd = TEMP_FD_INIT; int res; struct stat buf; struct lo_data *lo = lo_data(req); (void)fi; - res = - fstatat(lo_fd(req, ino), "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW); + res = lo_fd(req, ino, &ino_fd); + if (res < 0) { + return (void)fuse_reply_err(req, -res); + } + + res = fstatat(ino_fd.fd, "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW); if (res == -1) { return (void)fuse_reply_err(req, errno); } @@ -1529,6 +1535,7 @@ out: static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name) { + g_auto(TempFd) parent_fd = TEMP_FD_INIT; int res; struct lo_inode *inode; struct lo_data *lo = lo_data(req); @@ -1543,13 +1550,19 @@ static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name) return; } + res = lo_fd(req, parent, &parent_fd); + if (res < 0) { + fuse_reply_err(req, -res); + return; + } + inode = lookup_name(req, parent, name); if (!inode) { fuse_reply_err(req, EIO); return; } - res = unlinkat(lo_fd(req, parent), name, AT_REMOVEDIR); + res = unlinkat(parent_fd.fd, name, AT_REMOVEDIR); fuse_reply_err(req, res == -1 ? errno : 0); unref_inode_lolocked(lo, inode, 1); @@ -1635,6 +1648,7 @@ out: static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name) { + g_auto(TempFd) parent_fd = TEMP_FD_INIT; int res; struct lo_inode *inode; struct lo_data *lo = lo_data(req); @@ -1649,13 +1663,19 @@ static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name) return; } + res = lo_fd(req, parent, &parent_fd); + if (res < 0) { + fuse_reply_err(req, -res); + return; + } + inode = lookup_name(req, parent, name); if (!inode) { fuse_reply_err(req, EIO); return; } - res = unlinkat(lo_fd(req, parent), name, 0); + res = unlinkat(parent_fd.fd, name, 0); fuse_reply_err(req, res == -1 ? errno : 0); unref_inode_lolocked(lo, inode, 1); @@ -1735,10 +1755,16 @@ static void lo_forget_multi(fuse_req_t req, size_t count, static void lo_readlink(fuse_req_t req, fuse_ino_t ino) { + g_auto(TempFd) ino_fd = TEMP_FD_INIT; char buf[PATH_MAX + 1]; int res; - res = readlinkat(lo_fd(req, ino), "", buf, sizeof(buf)); + res = lo_fd(req, ino, &ino_fd); + if (res < 0) { + return (void)fuse_reply_err(req, -res); + } + + res = readlinkat(ino_fd.fd, "", buf, sizeof(buf)); if (res == -1) { return (void)fuse_reply_err(req, errno); } @@ -2535,10 +2561,17 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, static void lo_statfs(fuse_req_t req, fuse_ino_t ino) { + g_auto(TempFd) ino_fd = TEMP_FD_INIT; int res; struct statvfs stbuf; - res = fstatvfs(lo_fd(req, ino), &stbuf); + res = lo_fd(req, ino, &ino_fd); + if (res < 0) { + fuse_reply_err(req, -res); + return; + } + + res = fstatvfs(ino_fd.fd, &stbuf); if (res == -1) { fuse_reply_err(req, errno); } else { -- 2.31.1
next prev parent reply other threads:[~2021-07-30 15:04 UTC|newest] Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-30 15:01 [PATCH v3 00/10] virtiofsd: Allow using file handles instead of O_PATH FDs Max Reitz 2021-07-30 15:01 ` [Virtio-fs] " Max Reitz 2021-07-30 15:01 ` [PATCH v3 01/10] virtiofsd: Limit setxattr()'s creds-dropped region Max Reitz 2021-07-30 15:01 ` [Virtio-fs] " Max Reitz 2021-08-06 14:16 ` Vivek Goyal 2021-08-06 14:16 ` [Virtio-fs] " Vivek Goyal 2021-08-09 10:30 ` Max Reitz 2021-08-09 10:30 ` [Virtio-fs] " Max Reitz 2021-07-30 15:01 ` [PATCH v3 02/10] virtiofsd: Add TempFd structure Max Reitz 2021-07-30 15:01 ` [Virtio-fs] " Max Reitz 2021-08-06 14:41 ` Vivek Goyal 2021-08-06 14:41 ` [Virtio-fs] " Vivek Goyal 2021-08-09 10:44 ` Max Reitz 2021-08-09 10:44 ` [Virtio-fs] " Max Reitz 2021-07-30 15:01 ` [PATCH v3 03/10] virtiofsd: Use lo_inode_open() instead of openat() Max Reitz 2021-07-30 15:01 ` [Virtio-fs] " Max Reitz 2021-08-06 15:42 ` Vivek Goyal 2021-08-06 15:42 ` [Virtio-fs] " Vivek Goyal 2021-07-30 15:01 ` [PATCH v3 04/10] virtiofsd: Add lo_inode_fd() helper Max Reitz 2021-07-30 15:01 ` [Virtio-fs] " Max Reitz 2021-08-06 18:25 ` Vivek Goyal 2021-08-06 18:25 ` [Virtio-fs] " Vivek Goyal 2021-08-09 10:48 ` Max Reitz 2021-08-09 10:48 ` [Virtio-fs] " Max Reitz 2021-07-30 15:01 ` Max Reitz [this message] 2021-07-30 15:01 ` [Virtio-fs] [PATCH v3 05/10] virtiofsd: Let lo_fd() return a TempFd Max Reitz 2021-07-30 15:01 ` [PATCH v3 06/10] virtiofsd: Let lo_inode_open() " Max Reitz 2021-07-30 15:01 ` [Virtio-fs] " Max Reitz 2021-08-06 19:55 ` Vivek Goyal 2021-08-06 19:55 ` [Virtio-fs] " Vivek Goyal 2021-08-09 13:40 ` Max Reitz 2021-08-09 13:40 ` [Virtio-fs] " Max Reitz 2021-07-30 15:01 ` [PATCH v3 07/10] virtiofsd: Add lo_inode.fhandle Max Reitz 2021-07-30 15:01 ` [Virtio-fs] " Max Reitz 2021-08-09 15:21 ` Vivek Goyal 2021-08-09 15:21 ` [Virtio-fs] " Vivek Goyal 2021-08-09 16:41 ` Hanna Reitz 2021-08-09 16:41 ` [Virtio-fs] " Hanna Reitz 2021-07-30 15:01 ` [PATCH v3 08/10] virtiofsd: Add inodes_by_handle hash table Max Reitz 2021-07-30 15:01 ` [Virtio-fs] " Max Reitz 2021-08-09 16:10 ` Vivek Goyal 2021-08-09 16:10 ` [Virtio-fs] " Vivek Goyal 2021-08-09 16:47 ` Hanna Reitz 2021-08-09 16:47 ` [Virtio-fs] " Hanna Reitz 2021-08-10 14:07 ` Vivek Goyal 2021-08-10 14:07 ` [Virtio-fs] " Vivek Goyal 2021-08-10 14:13 ` Hanna Reitz 2021-08-10 14:13 ` [Virtio-fs] " Hanna Reitz 2021-08-10 17:51 ` Vivek Goyal 2021-08-10 17:51 ` [Virtio-fs] " Vivek Goyal 2021-07-30 15:01 ` [PATCH v3 09/10] virtiofsd: Optionally fill lo_inode.fhandle Max Reitz 2021-07-30 15:01 ` [Virtio-fs] " Max Reitz 2021-08-09 18:41 ` Vivek Goyal 2021-08-09 18:41 ` [Virtio-fs] " Vivek Goyal 2021-08-10 8:32 ` Hanna Reitz 2021-08-10 8:32 ` [Virtio-fs] " Hanna Reitz 2021-08-10 15:23 ` Vivek Goyal 2021-08-10 15:23 ` [Virtio-fs] " Vivek Goyal 2021-08-10 15:26 ` Hanna Reitz 2021-08-10 15:26 ` [Virtio-fs] " Hanna Reitz 2021-08-10 15:57 ` Vivek Goyal 2021-08-10 15:57 ` [Virtio-fs] " Vivek Goyal 2021-08-11 6:41 ` Hanna Reitz 2021-08-11 6:41 ` [Virtio-fs] " Hanna Reitz 2021-08-16 19:44 ` Vivek Goyal 2021-08-16 19:44 ` [Virtio-fs] " Vivek Goyal 2021-08-17 8:27 ` Hanna Reitz 2021-08-17 8:27 ` [Virtio-fs] " Hanna Reitz 2021-08-17 19:45 ` Vivek Goyal 2021-08-17 19:45 ` [Virtio-fs] " Vivek Goyal 2021-08-18 0:14 ` Vivek Goyal 2021-08-18 0:14 ` [Virtio-fs] " Vivek Goyal 2021-08-18 13:32 ` Vivek Goyal 2021-08-18 13:32 ` [Virtio-fs] " Vivek Goyal 2021-08-18 13:48 ` Hanna Reitz 2021-08-18 13:48 ` [Virtio-fs] " Hanna Reitz 2021-08-19 16:38 ` Dr. David Alan Gilbert 2021-08-19 16:38 ` [Virtio-fs] " Dr. David Alan Gilbert 2021-07-30 15:01 ` [PATCH v3 10/10] virtiofsd: Add lazy lo_do_find() Max Reitz 2021-07-30 15:01 ` [Virtio-fs] " Max Reitz 2021-08-09 19:08 ` Vivek Goyal 2021-08-09 19:08 ` [Virtio-fs] " Vivek Goyal 2021-08-10 8:38 ` Hanna Reitz 2021-08-10 8:38 ` [Virtio-fs] " Hanna Reitz 2021-08-10 14:12 ` Vivek Goyal 2021-08-10 14:12 ` [Virtio-fs] " Vivek Goyal 2021-08-10 14:17 ` Hanna Reitz 2021-08-10 14:17 ` [Virtio-fs] " Hanna Reitz
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210730150134.216126-6-mreitz@redhat.com \ --to=mreitz@redhat.com \ --cc=dgilbert@redhat.com \ --cc=qemu-devel@nongnu.org \ --cc=stefanha@redhat.com \ --cc=vgoyal@redhat.com \ --cc=virtio-fs@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.