|
|
ddf19c |
From e01a6e68d799ed2af0ca3b04d75818ba62b18682 Mon Sep 17 00:00:00 2001
|
|
|
ddf19c |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
ddf19c |
Date: Mon, 27 Jan 2020 19:02:08 +0100
|
|
|
ddf19c |
Subject: [PATCH 097/116] virtiofsd: rename inode->refcount to inode->nlookup
|
|
|
ddf19c |
MIME-Version: 1.0
|
|
|
ddf19c |
Content-Type: text/plain; charset=UTF-8
|
|
|
ddf19c |
Content-Transfer-Encoding: 8bit
|
|
|
ddf19c |
|
|
|
ddf19c |
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ddf19c |
Message-id: <20200127190227.40942-94-dgilbert@redhat.com>
|
|
|
ddf19c |
Patchwork-id: 93547
|
|
|
ddf19c |
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 093/112] virtiofsd: rename inode->refcount to inode->nlookup
|
|
|
ddf19c |
Bugzilla: 1694164
|
|
|
ddf19c |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
ddf19c |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ddf19c |
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
|
|
|
ddf19c |
|
|
|
ddf19c |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ddf19c |
|
|
|
ddf19c |
This reference counter plays a specific role in the FUSE protocol. It's
|
|
|
ddf19c |
not a generic object reference counter and the FUSE kernel code calls it
|
|
|
ddf19c |
"nlookup".
|
|
|
ddf19c |
|
|
|
ddf19c |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ddf19c |
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
ddf19c |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ddf19c |
(cherry picked from commit 1222f015558fc34cea02aa3a5a92de608c82cec8)
|
|
|
ddf19c |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
ddf19c |
---
|
|
|
ddf19c |
tools/virtiofsd/passthrough_ll.c | 37 +++++++++++++++++++++++++------------
|
|
|
ddf19c |
1 file changed, 25 insertions(+), 12 deletions(-)
|
|
|
ddf19c |
|
|
|
ddf19c |
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
|
|
|
ddf19c |
index 2d703b5..c819b5f 100644
|
|
|
ddf19c |
--- a/tools/virtiofsd/passthrough_ll.c
|
|
|
ddf19c |
+++ b/tools/virtiofsd/passthrough_ll.c
|
|
|
ddf19c |
@@ -99,7 +99,20 @@ struct lo_inode {
|
|
|
ddf19c |
int fd;
|
|
|
ddf19c |
bool is_symlink;
|
|
|
ddf19c |
struct lo_key key;
|
|
|
ddf19c |
- uint64_t refcount; /* protected by lo->mutex */
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /*
|
|
|
ddf19c |
+ * This counter keeps the inode alive during the FUSE session.
|
|
|
ddf19c |
+ * Incremented when the FUSE inode number is sent in a reply
|
|
|
ddf19c |
+ * (FUSE_LOOKUP, FUSE_READDIRPLUS, etc). Decremented when an inode is
|
|
|
ddf19c |
+ * released by requests like FUSE_FORGET, FUSE_RMDIR, FUSE_RENAME, etc.
|
|
|
ddf19c |
+ *
|
|
|
ddf19c |
+ * Note that this value is untrusted because the client can manipulate
|
|
|
ddf19c |
+ * it arbitrarily using FUSE_FORGET requests.
|
|
|
ddf19c |
+ *
|
|
|
ddf19c |
+ * Protected by lo->mutex.
|
|
|
ddf19c |
+ */
|
|
|
ddf19c |
+ uint64_t nlookup;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
fuse_ino_t fuse_ino;
|
|
|
ddf19c |
pthread_mutex_t plock_mutex;
|
|
|
ddf19c |
GHashTable *posix_locks; /* protected by lo_inode->plock_mutex */
|
|
|
ddf19c |
@@ -568,7 +581,7 @@ retry:
|
|
|
ddf19c |
if (last == path) {
|
|
|
ddf19c |
p = &lo->root;
|
|
|
ddf19c |
pthread_mutex_lock(&lo->mutex);
|
|
|
ddf19c |
- p->refcount++;
|
|
|
ddf19c |
+ p->nlookup++;
|
|
|
ddf19c |
pthread_mutex_unlock(&lo->mutex);
|
|
|
ddf19c |
} else {
|
|
|
ddf19c |
*last = '\0';
|
|
|
ddf19c |
@@ -786,8 +799,8 @@ static struct lo_inode *lo_find(struct lo_data *lo, struct stat *st)
|
|
|
ddf19c |
pthread_mutex_lock(&lo->mutex);
|
|
|
ddf19c |
p = g_hash_table_lookup(lo->inodes, &key);
|
|
|
ddf19c |
if (p) {
|
|
|
ddf19c |
- assert(p->refcount > 0);
|
|
|
ddf19c |
- p->refcount++;
|
|
|
ddf19c |
+ assert(p->nlookup > 0);
|
|
|
ddf19c |
+ p->nlookup++;
|
|
|
ddf19c |
}
|
|
|
ddf19c |
pthread_mutex_unlock(&lo->mutex);
|
|
|
ddf19c |
|
|
|
ddf19c |
@@ -855,7 +868,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
inode->is_symlink = S_ISLNK(e->attr.st_mode);
|
|
|
ddf19c |
- inode->refcount = 1;
|
|
|
ddf19c |
+ inode->nlookup = 1;
|
|
|
ddf19c |
inode->fd = newfd;
|
|
|
ddf19c |
newfd = -1;
|
|
|
ddf19c |
inode->key.ino = e->attr.st_ino;
|
|
|
ddf19c |
@@ -1112,7 +1125,7 @@ static void lo_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t parent,
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
pthread_mutex_lock(&lo->mutex);
|
|
|
ddf19c |
- inode->refcount++;
|
|
|
ddf19c |
+ inode->nlookup++;
|
|
|
ddf19c |
pthread_mutex_unlock(&lo->mutex);
|
|
|
ddf19c |
e.ino = inode->fuse_ino;
|
|
|
ddf19c |
|
|
|
ddf19c |
@@ -1193,9 +1206,9 @@ static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
pthread_mutex_lock(&lo->mutex);
|
|
|
ddf19c |
- assert(inode->refcount >= n);
|
|
|
ddf19c |
- inode->refcount -= n;
|
|
|
ddf19c |
- if (!inode->refcount) {
|
|
|
ddf19c |
+ assert(inode->nlookup >= n);
|
|
|
ddf19c |
+ inode->nlookup -= n;
|
|
|
ddf19c |
+ if (!inode->nlookup) {
|
|
|
ddf19c |
lo_map_remove(&lo->ino_map, inode->fuse_ino);
|
|
|
ddf19c |
g_hash_table_remove(lo->inodes, &inode->key);
|
|
|
ddf19c |
if (g_hash_table_size(inode->posix_locks)) {
|
|
|
ddf19c |
@@ -1216,7 +1229,7 @@ static int unref_all_inodes_cb(gpointer key, gpointer value, gpointer user_data)
|
|
|
ddf19c |
struct lo_inode *inode = value;
|
|
|
ddf19c |
struct lo_data *lo = user_data;
|
|
|
ddf19c |
|
|
|
ddf19c |
- inode->refcount = 0;
|
|
|
ddf19c |
+ inode->nlookup = 0;
|
|
|
ddf19c |
lo_map_remove(&lo->ino_map, inode->fuse_ino);
|
|
|
ddf19c |
close(inode->fd);
|
|
|
ddf19c |
|
|
|
ddf19c |
@@ -1241,7 +1254,7 @@ static void lo_forget_one(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup)
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
fuse_log(FUSE_LOG_DEBUG, " forget %lli %lli -%lli\n",
|
|
|
ddf19c |
- (unsigned long long)ino, (unsigned long long)inode->refcount,
|
|
|
ddf19c |
+ (unsigned long long)ino, (unsigned long long)inode->nlookup,
|
|
|
ddf19c |
(unsigned long long)nlookup);
|
|
|
ddf19c |
|
|
|
ddf19c |
unref_inode_lolocked(lo, inode, nlookup);
|
|
|
ddf19c |
@@ -2609,7 +2622,7 @@ static void setup_root(struct lo_data *lo, struct lo_inode *root)
|
|
|
ddf19c |
root->fd = fd;
|
|
|
ddf19c |
root->key.ino = stat.st_ino;
|
|
|
ddf19c |
root->key.dev = stat.st_dev;
|
|
|
ddf19c |
- root->refcount = 2;
|
|
|
ddf19c |
+ root->nlookup = 2;
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
static guint lo_key_hash(gconstpointer key)
|
|
|
ddf19c |
--
|
|
|
ddf19c |
1.8.3.1
|
|
|
ddf19c |
|