render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

Blame 0101-virtiofsd-passthrough_ll-fix-refcounting-on-remove-r.patch

1d442b
From: Miklos Szeredi <mszeredi@redhat.com>
1d442b
Date: Mon, 27 Jan 2020 19:02:10 +0000
1d442b
Subject: [PATCH] virtiofsd: passthrough_ll: fix refcounting on remove/rename
1d442b
1d442b
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1d442b
Reviewed-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
(cherry picked from commit 9257e514d861afa759c36704e1904d43ca3fec88)
1d442b
---
1d442b
 tools/virtiofsd/passthrough_ll.c | 50 +++++++++++++++++++++++++++++++-
1d442b
 1 file changed, 49 insertions(+), 1 deletion(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
1d442b
index c819b5f782..e3a6d6b611 100644
1d442b
--- a/tools/virtiofsd/passthrough_ll.c
1d442b
+++ b/tools/virtiofsd/passthrough_ll.c
1d442b
@@ -1140,17 +1140,42 @@ out_err:
1d442b
     fuse_reply_err(req, saverr);
1d442b
 }
1d442b
 
1d442b
+static struct lo_inode *lookup_name(fuse_req_t req, fuse_ino_t parent,
1d442b
+                                    const char *name)
1d442b
+{
1d442b
+    int res;
1d442b
+    struct stat attr;
1d442b
+
1d442b
+    res = fstatat(lo_fd(req, parent), name, &attr,
1d442b
+                  AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
1d442b
+    if (res == -1) {
1d442b
+        return NULL;
1d442b
+    }
1d442b
+
1d442b
+    return lo_find(lo_data(req), &attr);
1d442b
+}
1d442b
+
1d442b
 static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name)
1d442b
 {
1d442b
     int res;
1d442b
+    struct lo_inode *inode;
1d442b
+    struct lo_data *lo = lo_data(req);
1d442b
+
1d442b
     if (!is_safe_path_component(name)) {
1d442b
         fuse_reply_err(req, EINVAL);
1d442b
         return;
1d442b
     }
1d442b
 
1d442b
+    inode = lookup_name(req, parent, name);
1d442b
+    if (!inode) {
1d442b
+        fuse_reply_err(req, EIO);
1d442b
+        return;
1d442b
+    }
1d442b
+
1d442b
     res = unlinkat(lo_fd(req, parent), name, AT_REMOVEDIR);
1d442b
 
1d442b
     fuse_reply_err(req, res == -1 ? errno : 0);
1d442b
+    unref_inode_lolocked(lo, inode, 1);
1d442b
 }
1d442b
 
1d442b
 static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
1d442b
@@ -1158,12 +1183,23 @@ static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
1d442b
                       unsigned int flags)
1d442b
 {
1d442b
     int res;
1d442b
+    struct lo_inode *oldinode;
1d442b
+    struct lo_inode *newinode;
1d442b
+    struct lo_data *lo = lo_data(req);
1d442b
 
1d442b
     if (!is_safe_path_component(name) || !is_safe_path_component(newname)) {
1d442b
         fuse_reply_err(req, EINVAL);
1d442b
         return;
1d442b
     }
1d442b
 
1d442b
+    oldinode = lookup_name(req, parent, name);
1d442b
+    newinode = lookup_name(req, newparent, newname);
1d442b
+
1d442b
+    if (!oldinode) {
1d442b
+        fuse_reply_err(req, EIO);
1d442b
+        goto out;
1d442b
+    }
1d442b
+
1d442b
     if (flags) {
1d442b
 #ifndef SYS_renameat2
1d442b
         fuse_reply_err(req, EINVAL);
1d442b
@@ -1176,26 +1212,38 @@ static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
1d442b
             fuse_reply_err(req, res == -1 ? errno : 0);
1d442b
         }
1d442b
 #endif
1d442b
-        return;
1d442b
+        goto out;
1d442b
     }
1d442b
 
1d442b
     res = renameat(lo_fd(req, parent), name, lo_fd(req, newparent), newname);
1d442b
 
1d442b
     fuse_reply_err(req, res == -1 ? errno : 0);
1d442b
+out:
1d442b
+    unref_inode_lolocked(lo, oldinode, 1);
1d442b
+    unref_inode_lolocked(lo, newinode, 1);
1d442b
 }
1d442b
 
1d442b
 static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name)
1d442b
 {
1d442b
     int res;
1d442b
+    struct lo_inode *inode;
1d442b
+    struct lo_data *lo = lo_data(req);
1d442b
 
1d442b
     if (!is_safe_path_component(name)) {
1d442b
         fuse_reply_err(req, EINVAL);
1d442b
         return;
1d442b
     }
1d442b
 
1d442b
+    inode = lookup_name(req, parent, name);
1d442b
+    if (!inode) {
1d442b
+        fuse_reply_err(req, EIO);
1d442b
+        return;
1d442b
+    }
1d442b
+
1d442b
     res = unlinkat(lo_fd(req, parent), name, 0);
1d442b
 
1d442b
     fuse_reply_err(req, res == -1 ? errno : 0);
1d442b
+    unref_inode_lolocked(lo, inode, 1);
1d442b
 }
1d442b
 
1d442b
 static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,