All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com,
	misono.tomohiro@jp.fujitsu.com
Cc: virtio-fs@redhat.com, vgoyal@Redhat.com
Subject: [PULL 13/16] virtiofsd: Store every lo_inode's parent_dev
Date: Mon, 26 Oct 2020 18:43:28 +0000	[thread overview]
Message-ID: <20201026184331.272953-14-dgilbert@redhat.com> (raw)
In-Reply-To: <20201026184331.272953-1-dgilbert@redhat.com>

From: Max Reitz <mreitz@redhat.com>

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>
Message-Id: <20200909184028.262297-6-mreitz@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@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 a0beb986f3..4188bf3ad2 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -125,6 +125,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 {
@@ -847,6 +855,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);
@@ -1073,6 +1082,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.28.0



WARNING: multiple messages have this Message-ID (diff)
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com,
	misono.tomohiro@jp.fujitsu.com
Cc: virtio-fs@redhat.com, vgoyal@redhat.com
Subject: [Virtio-fs] [PULL 13/16] virtiofsd: Store every lo_inode's parent_dev
Date: Mon, 26 Oct 2020 18:43:28 +0000	[thread overview]
Message-ID: <20201026184331.272953-14-dgilbert@redhat.com> (raw)
In-Reply-To: <20201026184331.272953-1-dgilbert@redhat.com>

From: Max Reitz <mreitz@redhat.com>

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>
Message-Id: <20200909184028.262297-6-mreitz@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@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 a0beb986f3..4188bf3ad2 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -125,6 +125,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 {
@@ -847,6 +855,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);
@@ -1073,6 +1082,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.28.0


  parent reply	other threads:[~2020-10-26 18:55 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 18:43 [PULL 00/16] virtiofs queue Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 01/16] configure: add option for virtiofsd Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 02/16] virtiofsd: passthrough_ll: set FUSE_LOG_INFO as default log_level Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 03/16] virtiofsd: add container-friendly -o sandbox=chroot option Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 04/16] tools/virtiofsd: xattr name mappings: Add option Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 05/16] tools/virtiofsd: xattr name mappings: Map client xattr names Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 06/16] tools/virtiofsd: xattr name mappings: Map server " Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 07/16] tools/virtiofsd: xattr name mapping examples Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 08/16] tools/virtiofsd: xattr name mappings: Simple 'map' Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 09/16] linux/fuse.h: Pull in from Linux Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 10/16] virtiofsd: Announce FUSE_ATTR_FLAGS Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 11/16] virtiofsd: Add attr_flags to fuse_entry_param Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 12/16] virtiofsd: Add fuse_reply_attr_with_flags() Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` Dr. David Alan Gilbert (git) [this message]
2020-10-26 18:43   ` [Virtio-fs] [PULL 13/16] virtiofsd: Store every lo_inode's parent_dev Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 14/16] virtiofsd: Announce sub-mount points Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 15/16] tests/acceptance/boot_linux: Accept SSH pubkey Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-26 18:43 ` [PULL 16/16] tests/acceptance: Add virtiofs_submounts.py Dr. David Alan Gilbert (git)
2020-10-26 18:43   ` [Virtio-fs] " Dr. David Alan Gilbert (git)
2020-10-27 16:58 ` [PULL 00/16] virtiofs queue Peter Maydell
2020-10-27 16:58   ` [Virtio-fs] " Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201026184331.272953-14-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=misono.tomohiro@jp.fujitsu.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vgoyal@Redhat.com \
    --cc=virtio-fs@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.