[RFC PATCH 9/9] fuse: add fuse device ioctl(FUSE_DEV_IOC_BM_REVAL)

From: Alexander Mikhalitsyn
Date: Mon Feb 20 2023 - 14:39:24 EST


This ioctl allows to revalidate all the existing fuse bindmounts
by performing relookup of all root dentries and resetting them.

Useful if it's needed to make fuse bindmounts work without
remounting them after fuse connection reinitialization.

Cc: Miklos Szeredi <mszeredi@xxxxxxxxxx>
Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
Cc: Amir Goldstein <amir73il@xxxxxxxxx>
Cc: Stéphane Graber <stgraber@xxxxxxxxxx>
Cc: Seth Forshee <sforshee@xxxxxxxxxx>
Cc: Christian Brauner <brauner@xxxxxxxxxx>
Cc: Andrei Vagin <avagin@xxxxxxxxx>
Cc: Pavel Tikhomirov <ptikhomirov@xxxxxxxxxxxxx>
Cc: linux-fsdevel@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: criu@xxxxxxxxxx
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@xxxxxxxxxxxxx>
---
fs/fuse/dev.c | 29 ++++++++++++++++++++++++++++-
include/uapi/linux/fuse.h | 1 +
2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 0f53ffd63957..ae301cb8486b 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -13,6 +13,7 @@
#include <linux/poll.h>
#include <linux/sched/signal.h>
#include <linux/uio.h>
+#include <linux/mnt_namespace.h>
#include <linux/miscdevice.h>
#include <linux/pagemap.h>
#include <linux/file.h>
@@ -2293,6 +2294,27 @@ static int fuse_reinit_conn(struct fuse_conn *fc)
return 0;
}

+static ssize_t fuse_revalidate_bindmounts(struct fuse_conn *fc)
+{
+ int ret = 0;
+
+ down_read(&fc->killsb);
+ if (!list_empty(&fc->mounts)) {
+ struct fuse_mount *fm;
+
+ fm = list_first_entry(&fc->mounts, struct fuse_mount, fc_entry);
+ if (!fm->sb) {
+ up_read(&fc->killsb);
+ return -EINVAL;
+ }
+
+ ret = sb_revalidate_bindmounts(fm->sb);
+ }
+ up_read(&fc->killsb);
+
+ return ret;
+}
+
void fuse_wait_aborted(struct fuse_conn *fc)
{
/* matches implicit memory barrier in fuse_drop_waiting() */
@@ -2389,6 +2411,7 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
}
break;
case FUSE_DEV_IOC_REINIT:
+ case FUSE_DEV_IOC_BM_REVAL:
struct fuse_conn *fc;

if (!checkpoint_restore_ns_capable(file->f_cred->user_ns))
@@ -2409,7 +2432,11 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
mutex_unlock(&fuse_mutex);

if (fc) {
- res = fuse_reinit_conn(fc);
+ if (cmd == FUSE_DEV_IOC_REINIT)
+ res = fuse_reinit_conn(fc);
+ else if (cmd == FUSE_DEV_IOC_BM_REVAL)
+ res = fuse_revalidate_bindmounts(fc);
+
fuse_conn_put(fc);
}
}
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 3dac67b25eae..14f7fe4a99cf 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -990,6 +990,7 @@ struct fuse_notify_retrieve_in {
#define FUSE_DEV_IOC_MAGIC 229
#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
#define FUSE_DEV_IOC_REINIT _IO(FUSE_DEV_IOC_MAGIC, 0)
+#define FUSE_DEV_IOC_BM_REVAL _IO(FUSE_DEV_IOC_MAGIC, 1)

struct fuse_lseek_in {
uint64_t fh;
--
2.34.1