[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/8] virtiofsd: Store every lo_inode's parent_dev
From: |
Max Reitz |
Subject: |
[PATCH 5/8] virtiofsd: Store every lo_inode's parent_dev |
Date: |
Wed, 9 Sep 2020 20:40:25 +0200 |
We want to detect mount points in the shared tree. We report them to
the guest by setting the FUSE_ATTR_SUBMOUNT flag in fuse_attr.flags, but
because the FUSE client will create a submount for every directory that
has this flag set, we must do this only for the actual mount points.
We can detect mount points by comparing a directory's st_dev with its
parent's st_dev. To be able to do so, we need to store the parent's
st_dev in the lo_inode object.
Note that mount points need not necessarily be directories; a single
file can be a mount point as well. However, for the sake of simplicity
let us ignore any non-directory mount points for now.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
tools/virtiofsd/passthrough_ll.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 784330e0e4..2c48c03b4c 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -124,6 +124,14 @@ struct lo_inode {
GHashTable *posix_locks; /* protected by lo_inode->plock_mutex */
mode_t filetype;
+
+ /*
+ * So we can detect crossmount roots
+ * (As such, this only needs to be valid for directories. Note
+ * that files can have multiple parents due to hard links, and so
+ * their parent_dev may fluctuate.)
+ */
+ dev_t parent_dev;
};
struct lo_cred {
@@ -821,6 +829,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent,
const char *name,
g_hash_table_insert(lo->inodes, &inode->key, inode);
pthread_mutex_unlock(&lo->mutex);
}
+ inode->parent_dev = dir->key.dev;
e->ino = inode->fuse_ino;
lo_inode_put(lo, &inode);
lo_inode_put(lo, &dir);
@@ -1047,6 +1056,14 @@ static void lo_link(fuse_req_t req, fuse_ino_t ino,
fuse_ino_t parent,
fuse_log(FUSE_LOG_DEBUG, " %lli/%s -> %lli\n", (unsigned long long)parent,
name, (unsigned long long)e.ino);
+ /*
+ * No need to update inode->parent_dev, because
+ * (1) We cannot, the inode now has more than one parent,
+ * (2) Directories cannot have more than one parent, so link()
+ * does not work for them; but parent_dev only needs to be
+ * valid for directories.
+ */
+
fuse_reply_entry(req, &e);
lo_inode_put(lo, &parent_inode);
lo_inode_put(lo, &inode);
--
2.26.2
- [PATCH 0/8] virtiofsd: Announce submounts to the guest, Max Reitz, 2020/09/09
- [PATCH 1/8] linux/fuse.h: Pull in from Linux, Max Reitz, 2020/09/09
- [PATCH 2/8] virtiofsd: Announce FUSE_ATTR_FLAGS, Max Reitz, 2020/09/09
- [PATCH 3/8] virtiofsd: Add attr_flags to fuse_entry_param, Max Reitz, 2020/09/09
- [PATCH 4/8] virtiofsd: Add fuse_reply_attr_with_flags(), Max Reitz, 2020/09/09
- [PATCH 5/8] virtiofsd: Store every lo_inode's parent_dev,
Max Reitz <=
- [PATCH 7/8] tests/acceptance/boot_linux: Accept SSH pubkey, Max Reitz, 2020/09/09
- [PATCH 6/8] virtiofsd: Announce sub-mount points, Max Reitz, 2020/09/09
- [PATCH 8/8] tests/acceptance: Add virtiofs_submounts.py, Max Reitz, 2020/09/09
- Re: [PATCH 0/8] virtiofsd: Announce submounts to the guest, Stefan Hajnoczi, 2020/09/11