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