[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 072/104] virtiofsd: passthrough_ll: fix refcounting on remove/ren
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PATCH 072/104] virtiofsd: passthrough_ll: fix refcounting on remove/rename |
Date: |
Thu, 12 Dec 2019 16:38:32 +0000 |
From: Miklos Szeredi <address@hidden>
Signed-off-by: Miklos Szeredi <address@hidden>
---
tools/virtiofsd/passthrough_ll.c | 50 +++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 0f33c3c5e9..1b84d4f313 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -1077,17 +1077,42 @@ out_err:
fuse_reply_err(req, saverr);
}
+static struct lo_inode *lookup_name(fuse_req_t req, fuse_ino_t parent,
+ const char *name)
+{
+ int res;
+ struct stat attr;
+
+ res = fstatat(lo_fd(req, parent), name, &attr,
+ AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+ if (res == -1) {
+ return NULL;
+ }
+
+ return lo_find(lo_data(req), &attr);
+}
+
static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name)
{
int res;
+ struct lo_inode *inode;
+ struct lo_data *lo = lo_data(req);
+
if (!is_safe_path_component(name)) {
fuse_reply_err(req, EINVAL);
return;
}
+ inode = lookup_name(req, parent, name);
+ if (!inode) {
+ fuse_reply_err(req, EIO);
+ return;
+ }
+
res = unlinkat(lo_fd(req, parent), name, AT_REMOVEDIR);
fuse_reply_err(req, res == -1 ? errno : 0);
+ unref_inode_lolocked(lo, inode, 1);
}
static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
@@ -1095,12 +1120,23 @@ static void lo_rename(fuse_req_t req, fuse_ino_t
parent, const char *name,
unsigned int flags)
{
int res;
+ struct lo_inode *oldinode;
+ struct lo_inode *newinode;
+ struct lo_data *lo = lo_data(req);
if (!is_safe_path_component(name) || !is_safe_path_component(newname)) {
fuse_reply_err(req, EINVAL);
return;
}
+ oldinode = lookup_name(req, parent, name);
+ newinode = lookup_name(req, newparent, newname);
+
+ if (!oldinode) {
+ fuse_reply_err(req, EIO);
+ goto out;
+ }
+
if (flags) {
#ifndef SYS_renameat2
fuse_reply_err(req, EINVAL);
@@ -1113,26 +1149,38 @@ static void lo_rename(fuse_req_t req, fuse_ino_t
parent, const char *name,
fuse_reply_err(req, res == -1 ? errno : 0);
}
#endif
- return;
+ goto out;
}
res = renameat(lo_fd(req, parent), name, lo_fd(req, newparent), newname);
fuse_reply_err(req, res == -1 ? errno : 0);
+out:
+ unref_inode_lolocked(lo, oldinode, 1);
+ unref_inode_lolocked(lo, newinode, 1);
}
static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name)
{
int res;
+ struct lo_inode *inode;
+ struct lo_data *lo = lo_data(req);
if (!is_safe_path_component(name)) {
fuse_reply_err(req, EINVAL);
return;
}
+ inode = lookup_name(req, parent, name);
+ if (!inode) {
+ fuse_reply_err(req, EIO);
+ return;
+ }
+
res = unlinkat(lo_fd(req, parent), name, 0);
fuse_reply_err(req, res == -1 ? errno : 0);
+ unref_inode_lolocked(lo, inode, 1);
}
static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,
--
2.23.0
- [PATCH 061/104] virtiofsd: Handle reinit, (continued)
- [PATCH 061/104] virtiofsd: Handle reinit, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 062/104] virtiofsd: Handle hard reboot, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 063/104] virtiofsd: Kill threads when queues are stopped, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 064/104] vhost-user: Print unexpected slave message types, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 065/104] contrib/libvhost-user: Protect slave fd with mutex, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 066/104] virtiofsd: passthrough_ll: add renameat2 support, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 067/104] virtiofsd: passthrough_ll: disable readdirplus on cache=never, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 068/104] virtiofsd: passthrough_ll: control readdirplus, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 069/104] virtiofsd: rename unref_inode() to unref_inode_lolocked(), Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 070/104] virtiofsd: fail when parent inode isn't known in lo_do_lookup(), Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 072/104] virtiofsd: passthrough_ll: fix refcounting on remove/rename,
Dr. David Alan Gilbert (git) <=
- [PATCH 071/104] virtiofsd: extract root inode init into setup_root(), Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 073/104] virtiofsd: passthrough_ll: clean up cache related options, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 074/104] virtiofsd: passthrough_ll: use hashtable, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 075/104] virtiofsd: Clean up inodes on destroy, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 076/104] virtiofsd: support nanosecond resolution for file timestamp, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 077/104] virtiofsd: fix error handling in main(), Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 078/104] virtiofsd: cleanup allocated resource in se, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 079/104] virtiofsd: fix memory leak on lo.source, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 080/104] virtiofsd: add helper for lo_data cleanup, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 081/104] virtiofsd: Prevent multiply running with same vhost_user_socket, Dr. David Alan Gilbert (git), 2019/12/12