[Devel,vz7,46/46] fuse: ioctl() to bind fuse device to input queue

Submitted by Maxim Patlasov on March 25, 2017, 2:30 a.m.

Details

Message ID 149040905088.25341.9715217119164050001.stgit@maxim-thinkpad
State New
Series "fuse: add multi-threading support"
Headers show

Commit Message

Maxim Patlasov March 25, 2017, 2:30 a.m.
By default all fuse devices refer to the main input queue: fc->main_iq.
Userspace may change the mapping by:

ioctl(fd, FUSE_DEV_IOC_SETAFF, i);

where "fd" is clone file descriptor for "/dev/fuse" and "i" is
an integer from zero to num_online_cpus-1.

Signed-off-by: Maxim Patlasov <mpatlasov@virtuozzo.com>
---
 fs/fuse/dev.c             |   16 ++++++++++++++++
 include/uapi/linux/fuse.h |    1 +
 2 files changed, 17 insertions(+)

Patch hide | download patch | download mbox

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 08c825e..8dd5154 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2272,6 +2272,22 @@  static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
 				fput(old);
 			}
 		}
+	} else if (cmd == FUSE_DEV_IOC_SETAFF) {
+		if (arg >= num_online_cpus()) {
+			err = -EINVAL;
+		} else {
+			struct fuse_dev *fud = fuse_get_dev(file);
+			spin_lock(&fud->fc->lock);
+
+			fud->fiq->handled_by_fud--;
+			BUG_ON(fud->fiq->handled_by_fud < 0);
+
+			fud->fiq = per_cpu_ptr(fud->fc->iqs, arg);
+
+			fud->fiq->handled_by_fud++;
+			spin_unlock(&fud->fc->lock);
+			err = 0;
+		}
 	}
 	return err;
 }
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 3262980..c2c1ac9 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -751,5 +751,6 @@  struct fuse_notify_inval_files_out {
 
 /* Device ioctls: */
 #define FUSE_DEV_IOC_CLONE	_IOR(229, 0, uint32_t)
+#define FUSE_DEV_IOC_SETAFF	_IOR(229, 1, uint32_t)
 
 #endif /* _LINUX_FUSE_H */