Skip to contentSkip to conversation

virtiofsd, vhost-user-fs: Add support for notification queue

RFC PATCH Applied Vivek Goyal 2 participants 8 messages Dec 4, 2019 – Dec 6, 2019 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

v2 cover virtiofsd, vhost-user-fs: Add support for notification queue

Hi,

Here is V2 of RFC patches for adding a notification queue to vhost-user-fs device to send notifications from host to guest. It also has patches to support remote posix locks which make use of this newly introduced notification queue.

I have taken care of most of the comments from last iteration. Still one major TODO item is to be able to interrupt/stop blocked thrads for locks when guest reboots.

Patches are also available here.

https://github.com/rhvgoyal/qemu/commits/blocking-locks-v2

Associated kernel changes are available here.

https://github.com/rhvgoyal/linux/commits/blocking-locks-v2

Thanks
Vivek

Vivek Goyal (5):
virtiofsd: Get rid of unused fields in fv_QueueInfo
virtiofsd: Release file locks using F_UNLCK
virtiofd: Create a notification queue
virtiofsd: Specify size of notification buffer using config space
virtiofsd: Implement blocking posix locks

 contrib/virtiofsd/fuse_i.h                 |   1 +
 contrib/virtiofsd/fuse_kernel.h            |   7 +
 contrib/virtiofsd/fuse_lowlevel.c          |  23 ++-
 contrib/virtiofsd/fuse_lowlevel.h          |  25 +++
 contrib/virtiofsd/fuse_virtio.c            | 208 +++++++++++++++++----
 contrib/virtiofsd/passthrough_ll.c         |  80 ++++++--
 hw/virtio/vhost-user-fs-pci.c              |   2 +-
 hw/virtio/vhost-user-fs.c                  |  63 ++++++-
 include/hw/virtio/vhost-user-fs.h          |   3 +
 include/standard-headers/linux/virtio_fs.h |   5 +
 10 files changed, 354 insertions(+), 63 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/5 virtiofsd: Get rid of unused fields in fv_QueueInfo

There are some unused fields in "struct fv_QueueInfo". Get rid of these fields.

---
 contrib/virtiofsd/fuse_virtio.c | 6 ------
 1 file changed, 6 deletions(-)
contrib/virtiofsd/fuse_virtio.c +0 -6
index 31c8542b6c..2a9cd60a01 100644
@@ -50,12 +50,6 @@ struct fv_QueueInfo {
     int qidx;
     int kick_fd;
     int kill_fd; /* For killing the thread */
-
-    /* The element for the command currently being processed */
-    VuVirtqElement *qe;
-    /* If any of the qe vec elements (towards vmm) are unmappable */
-    unsigned int elem_bad_in;
-    bool reply_sent;
 };
 
 /* A FUSE request */
Signature · 1 line
2.20.1
Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] virtiofsd: Get rid of unused fields in fv_QueueInfo

Quoted 12 lines · * Vivek Goyal ([email protected]) wrote:

There are some unused fields in "struct fv_QueueInfo". Get rid of these fields.

---
 contrib/virtiofsd/fuse_virtio.c | 6 ------
 1 file changed, 6 deletions(-)
contrib/virtiofsd/fuse_virtio.c +0 -0
index 31c8542b6c..2a9cd60a01 100644

contrib/virtiofsd/fuse_virtio.c struct fv_QueueInfo { · line 58

Quoted 9 lines
contrib/virtiofsd/fuse_virtio.c +0 -6
@@ -50,12 +50,6 @@ struct fv_QueueInfo {
     int qidx;
     int kick_fd;
     int kill_fd; /* For killing the thread */
-
-    /* The element for the command currently being processed */
-    VuVirtqElement *qe;
-    /* If any of the qe vec elements (towards vmm) are unmappable */
-    unsigned int elem_bad_in;
-    bool reply_sent;

Yep, those last two got moved into FVRequest as part of the thread pool stuff.

Quoted 6 lines
contrib/virtiofsd/fuse_virtio.c +0 -0
 };
 
 /* A FUSE request */
Signature · 1 line
2.20.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw

Re: [Virtio-fs] [PATCH v2 1/5] virtiofsd: Get rid of unused fields in fv_QueueInfo

Quoted 27 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 12 lines · * Vivek Goyal ([email protected]) wrote:

There are some unused fields in "struct fv_QueueInfo". Get rid of these fields.

---
 contrib/virtiofsd/fuse_virtio.c | 6 ------
 1 file changed, 6 deletions(-)
contrib/virtiofsd/fuse_virtio.c +0 -0
index 31c8542b6c..2a9cd60a01 100644

contrib/virtiofsd/fuse_virtio.c struct fv_QueueInfo { · line 58

Quoted 9 lines
contrib/virtiofsd/fuse_virtio.c +0 -6
@@ -50,12 +50,6 @@ struct fv_QueueInfo {
     int qidx;
     int kick_fd;
     int kill_fd; /* For killing the thread */
-
-    /* The element for the command currently being processed */
-    VuVirtqElement *qe;
-    /* If any of the qe vec elements (towards vmm) are unmappable */
-    unsigned int elem_bad_in;
-    bool reply_sent;

Yep, those last two got moved into FVRequest as part of the thread pool stuff.

Quoted 1 line

I've merged that 1/5 into my world.

Quoted 6 lines
Quoted 6 lines
contrib/virtiofsd/fuse_virtio.c +0 -0
 };
 
 /* A FUSE request */
Signature · 1 line
2.20.1
Quoted 7 lines

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#4 lore raw

PATCH v2 2/5 virtiofsd: Release file locks using F_UNLCK

In reply to Vivek Goyal

We are emulating posix locks for guest using open file description locks in virtiofsd. When any of the fd is closed in guest, we find associated OFD lock fd (if there is one) and close it to release all the locks.

Assumption here is that there is no other thread using lo_inode_plock structure or plock->fd, hence it is safe to do so.

But now we are about to introduce blocking variant of locks (SETLKW), and that means we might be waiting to a lock to be available and using plock->fd. And that means there are still users of plock structure.

So release locks using fcntl(SETLK, F_UNLCK) instead and plock will be freed later.

---
 contrib/virtiofsd/passthrough_ll.c | 31 ++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)
contrib/virtiofsd/passthrough_ll.c +21 -10
index bc214df0c7..6aa56882e8 100644
@@ -936,6 +936,14 @@ static void put_shared(struct lo_data *lo, struct lo_inode *inode)
 	}
 }
 
+static void posix_locks_value_destroy(gpointer data)
+{
+	struct lo_inode_plock *plock = data;
+
+	close(plock->fd);
+	free(plock);
+}
+
 /* Increments nlookup and caller must release refcount using
  * lo_inode_put(&parent).
  */
@@ -994,7 +1002,9 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
 		inode->key.ino = e->attr.st_ino;
 		inode->key.dev = e->attr.st_dev;
 		pthread_mutex_init(&inode->plock_mutex, NULL);
-		inode->posix_locks = g_hash_table_new(g_direct_hash, g_direct_equal);
+		inode->posix_locks = g_hash_table_new_full(g_direct_hash,
+					g_direct_equal, NULL,
+					posix_locks_value_destroy);
 
 		get_shared(lo, inode);
 
@@ -1436,9 +1446,6 @@ static void unref_inode(struct lo_data *lo, struct lo_inode *inode, uint64_t n)
 	if (!inode->nlookup) {
 		lo_map_remove(&lo->ino_map, inode->fuse_ino);
                 g_hash_table_remove(lo->inodes, &inode->key);
-		if (g_hash_table_size(inode->posix_locks)) {
-			fuse_log(FUSE_LOG_WARNING, "Hash table is not empty\n");
-		}
 		g_hash_table_destroy(inode->posix_locks);
 		pthread_mutex_destroy(&inode->plock_mutex);
 
@@ -1868,6 +1875,7 @@ static struct lo_inode_plock *lookup_create_plock_ctx(struct lo_data *lo,
 	plock->fd = fd;
 	g_hash_table_insert(inode->posix_locks,
 			    GUINT_TO_POINTER(plock->lock_owner), plock);
+	fuse_log(FUSE_LOG_DEBUG, "lookup_create_plock_ctx(): Inserted element in posix_locks hash table with value pointer %p\n", plock);
 	return plock;
 }
 
@@ -2046,6 +2054,7 @@ static void lo_flush(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
 	(void) ino;
 	struct lo_inode *inode;
 	struct lo_inode_plock *plock;
+	struct flock flock;
 
 	inode = lo_inode(req, ino);
 	if (!inode) {
@@ -2058,14 +2067,16 @@ static void lo_flush(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
 	plock = g_hash_table_lookup(inode->posix_locks,
 				    GUINT_TO_POINTER(fi->lock_owner));
 	if (plock) {
-		g_hash_table_remove(inode->posix_locks,
-				    GUINT_TO_POINTER(fi->lock_owner));
 		/*
-		 * We had used open() for locks and had only one fd. So
-		 * closing this fd should release all OFD locks.
+		 * An fd is being closed. For posix locks, this means
+		 * drop all the associated locks.
 		 */
-		close(plock->fd);
-		free(plock);
+		memset(&flock, 0, sizeof(struct flock));
+		flock.l_type = F_UNLCK;
+		flock.l_whence = SEEK_SET;
+		/* Unlock whole file */
+		flock.l_start = flock.l_len = 0;
+		fcntl(plock->fd, F_OFD_SETLK, &flock);
 	}
 	pthread_mutex_unlock(&inode->plock_mutex);
 
Signature · 1 line
2.20.1
#5 lore raw

PATCH v2 3/5 virtiofd: Create a notification queue

In reply to Vivek Goyal

Add a notification queue which will be used to send async notifications for file lock availability.

---
 contrib/virtiofsd/fuse_i.h                 |  1 +
 contrib/virtiofsd/fuse_virtio.c            | 74 +++++++++++++++-------
 hw/virtio/vhost-user-fs-pci.c              |  2 +-
 hw/virtio/vhost-user-fs.c                  | 37 +++++++++--
 include/hw/virtio/vhost-user-fs.h          |  1 +
 include/standard-headers/linux/virtio_fs.h |  3 +
 6 files changed, 87 insertions(+), 31 deletions(-)
contrib/virtiofsd/fuse_i.h +1 -0
index 966b1a3baa..4eeae0bfeb 100644
@@ -74,6 +74,7 @@ struct fuse_session {
 	char *vu_socket_lock;
 	struct fv_VuDev *virtio_dev;
 	int thread_pool_size;
+	bool notify_enabled;
 };
 
 struct fuse_chan {
contrib/virtiofsd/fuse_virtio.c +51 -23

133 lines not on this page · raw message

hw/virtio/vhost-user-fs-pci.c +1 -1
index 0f3c3c8711..95f9fe5c5c 100644
@@ -44,7 +44,7 @@ static void vhost_user_fs_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     uint64_t totalsize;
 
     if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
-        vpci_dev->nvectors = dev->vdev.conf.num_request_queues + 1;
+        vpci_dev->nvectors = dev->vdev.conf.num_request_queues + 2;
     }
 
     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
hw/virtio/vhost-user-fs.c +30 -7
index 455e97beea..5555fe9dbe 100644
@@ -24,6 +24,10 @@
 #include "exec/address-spaces.h"
 #include "trace.h"
 
+static const int user_feature_bits[] = {
+    VIRTIO_FS_F_NOTIFICATION,
+};
+
 uint64_t vhost_user_fs_slave_map(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm,
                                  int fd)
 {
@@ -378,12 +382,23 @@ static void vuf_set_status(VirtIODevice *vdev, uint8_t status)
     }
 }
 
-static uint64_t vuf_get_features(VirtIODevice *vdev,
-                                      uint64_t requested_features,
-                                      Error **errp)
+static uint64_t vuf_get_features(VirtIODevice *vdev, uint64_t features,
+                                 Error **errp)
 {
-    /* No feature bits used yet */
-    return requested_features;
+    VHostUserFS *fs = VHOST_USER_FS(vdev);
+
+    virtio_add_feature(&features, VIRTIO_FS_F_NOTIFICATION);
+
+    return vhost_get_features(&fs->vhost_dev, user_feature_bits, features);
+}
+
+static void vuf_set_features(VirtIODevice *vdev, uint64_t features)
+{
+    VHostUserFS *fs = VHOST_USER_FS(vdev);
+
+    if (virtio_has_feature(features, VIRTIO_FS_F_NOTIFICATION)) {
+        fs->notify_enabled = true;
+    }
 }
 
 static void vuf_handle_output(VirtIODevice *vdev, VirtQueue *vq)
@@ -515,13 +530,20 @@ static void vuf_device_realize(DeviceState *dev, Error **errp)
     /* Hiprio queue */
     virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output);
 
+    /* Notification queue. Feature negotiation happens later. So at this
+     * point of time we don't know if driver will use notification queue
+     * or not.
+     */
+    virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output);
+
     /* Request queues */
     for (i = 0; i < fs->conf.num_request_queues; i++) {
         virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output);
     }
 
-    /* 1 high prio queue, plus the number configured */
-    fs->vhost_dev.nvqs = 1 + fs->conf.num_request_queues;
+    /* 1 high prio queue, 1 notification queue plus the number configured */
+    fs->vhost_dev.nvqs = 2 + fs->conf.num_request_queues;
+
     fs->vhost_dev.vqs = g_new0(struct vhost_virtqueue, fs->vhost_dev.nvqs);
     ret = vhost_dev_init(&fs->vhost_dev, &fs->vhost_user,
                          VHOST_BACKEND_TYPE_USER, 0);
@@ -584,6 +606,7 @@ static void vuf_class_init(ObjectClass *klass, void *data)
     vdc->realize = vuf_device_realize;
     vdc->unrealize = vuf_device_unrealize;
     vdc->get_features = vuf_get_features;
+    vdc->set_features = vuf_set_features;
     vdc->get_config = vuf_get_config;
     vdc->set_status = vuf_set_status;
     vdc->guest_notifier_mask = vuf_guest_notifier_mask;
include/hw/virtio/vhost-user-fs.h +1 -0
index 4e7be1f312..bd47e0da98 100644
@@ -64,6 +64,7 @@ typedef struct {
     /* Metadata version table */
     size_t mdvt_size;
     MemoryRegion mdvt;
+    bool notify_enabled;
 } VHostUserFS;
 
 /* Callbacks from the vhost-user code for slave commands */
include/standard-headers/linux/virtio_fs.h +3 -0
index 310210b7b6..9ee95f584f 100644
@@ -8,6 +8,9 @@
 #include "standard-headers/linux/virtio_config.h"
 #include "standard-headers/linux/virtio_types.h"
 
+/* Feature bits */
+#define VIRTIO_FS_F_NOTIFICATION	0	/* Notification queue supported */
+
 struct virtio_fs_config {
 	/* Filesystem name (UTF-8, not NUL-terminated, padded with NULs) */
 	uint8_t tag[36];
Signature · 1 line
2.20.1
#6 lore raw

PATCH v2 4/5 virtiofsd: Specify size of notification buffer using config space

In reply to Vivek Goyal

Daemon specifies size of notification buffer needed and that should be done using config space.

Only ->notify_buf_size value of config space comes from daemon. Rest of it is filled by qemu device emulation code.

---
 contrib/virtiofsd/fuse_virtio.c            | 31 ++++++++++++++++++++++
 hw/virtio/vhost-user-fs.c                  | 26 ++++++++++++++++++
 include/hw/virtio/vhost-user-fs.h          |  2 ++
 include/standard-headers/linux/virtio_fs.h |  2 ++
 4 files changed, 61 insertions(+)
contrib/virtiofsd/fuse_virtio.c +31 -0
index b1eebcf054..94cf9b3791 100644
@@ -869,6 +869,35 @@ static bool fv_queue_order(VuDev *dev, int qidx)
     return false;
 }
 
+static uint64_t fv_get_protocol_features(VuDev *dev)
+{
+	return 1ull << VHOST_USER_PROTOCOL_F_CONFIG;
+}
+
+static int fv_get_config(VuDev *dev, uint8_t *config, uint32_t len)
+{
+	struct virtio_fs_config fscfg = {};
+	unsigned notify_size, roundto = 64;
+	union fuse_notify_union {
+		struct fuse_notify_poll_wakeup_out	wakeup_out;
+		struct fuse_notify_inval_inode_out	inode_out;
+		struct fuse_notify_inval_entry_out	entry_out;
+		struct fuse_notify_delete_out		delete_out;
+		struct fuse_notify_store_out		store_out;
+		struct fuse_notify_retrieve_out		retrieve_out;
+	};
+
+	notify_size = sizeof(struct fuse_out_header) +
+		      sizeof(union fuse_notify_union);
+	notify_size = ((notify_size + roundto)/roundto) * roundto;
+
+	fscfg.notify_buf_size = notify_size;
+	memcpy(config, &fscfg, len);
+	fuse_log(FUSE_LOG_DEBUG, "%s:Setting notify_buf_size=%d\n", __func__,
+                 fscfg.notify_buf_size);
+	return 0;
+}
+
 static const VuDevIface fv_iface = {
     .get_features = fv_get_features,
     .set_features = fv_set_features,
@@ -877,6 +906,8 @@ static const VuDevIface fv_iface = {
     .queue_set_started = fv_queue_set_started,
 
     .queue_is_processed_in_order = fv_queue_order,
+    .get_protocol_features = fv_get_protocol_features,
+    .get_config = fv_get_config,
 };
 
 /*
hw/virtio/vhost-user-fs.c +26 -0
index 5555fe9dbe..5a6d244b98 100644
@@ -277,16 +277,40 @@ uint64_t vhost_user_fs_slave_io(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm,
     return (uint64_t)done;
 }
 
+static int vhost_user_fs_handle_config_change(struct vhost_dev *dev)
+{
+    return 0;
+}
+
+const VhostDevConfigOps fs_ops = {
+    .vhost_dev_config_notifier = vhost_user_fs_handle_config_change,
+};
 
 static void vuf_get_config(VirtIODevice *vdev, uint8_t *config)
 {
     VHostUserFS *fs = VHOST_USER_FS(vdev);
     struct virtio_fs_config fscfg = {};
+    int ret;
+
+    /*
+     * As of now we only get notification buffer size from device. And that's
+     * needed only if notification queue is enabled.
+     */
+    if (fs->notify_enabled) {
+        ret = vhost_dev_get_config(&fs->vhost_dev, (uint8_t *)&fs->fscfg,
+                                   sizeof(struct virtio_fs_config));
+        if (ret < 0) {
+            error_report("vhost-user-fs: get device config space failed."
+                         " ret=%d\n", ret);
+            return;
+        }
+    }
 
     memcpy((char *)fscfg.tag, fs->conf.tag,
            MIN(strlen(fs->conf.tag) + 1, sizeof(fscfg.tag)));
 
     virtio_stl_p(vdev, &fscfg.num_request_queues, fs->conf.num_request_queues);
+    virtio_stl_p(vdev, &fscfg.notify_buf_size, fs->fscfg.notify_buf_size);
 
     memcpy(config, &fscfg, sizeof(fscfg));
 }
@@ -545,6 +569,8 @@ static void vuf_device_realize(DeviceState *dev, Error **errp)
     fs->vhost_dev.nvqs = 2 + fs->conf.num_request_queues;
 
     fs->vhost_dev.vqs = g_new0(struct vhost_virtqueue, fs->vhost_dev.nvqs);
+
+    vhost_dev_set_config_notifier(&fs->vhost_dev, &fs_ops);
     ret = vhost_dev_init(&fs->vhost_dev, &fs->vhost_user,
                          VHOST_BACKEND_TYPE_USER, 0);
     if (ret < 0) {
include/hw/virtio/vhost-user-fs.h +2 -0
index bd47e0da98..f667cc4b5a 100644
@@ -14,6 +14,7 @@
 #ifndef _QEMU_VHOST_USER_FS_H
 #define _QEMU_VHOST_USER_FS_H
 
+#include "standard-headers/linux/virtio_fs.h"
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/vhost.h"
 #include "hw/virtio/vhost-user.h"
@@ -58,6 +59,7 @@ typedef struct {
     struct vhost_virtqueue *vhost_vqs;
     struct vhost_dev vhost_dev;
     VhostUserState vhost_user;
+    struct virtio_fs_config fscfg;
 
     /*< public >*/
     MemoryRegion cache;
include/standard-headers/linux/virtio_fs.h +2 -0
index 9ee95f584f..719216a262 100644
@@ -17,6 +17,8 @@ struct virtio_fs_config {
 
 	/* Number of request queues */
 	uint32_t num_request_queues;
+	/* Size of notification buffer */
+	uint32_t notify_buf_size;
 } QEMU_PACKED;
 
 #define VIRTIO_FS_PCI_CACHE_BAR 2
Signature · 1 line
2.20.1
#7 lore raw

PATCH v2 5/5 virtiofsd: Implement blocking posix locks

In reply to Vivek Goyal

As of now we don't support fcntl(F_SETLKW) and if we see one, we return -EOPNOTSUPP.

Change that by accepting these requests and returning a reply immediately asking caller to wait. Once lock is available, send a notification to the waiter indicating lock is available.

---
 contrib/virtiofsd/fuse_kernel.h    |  7 +++
 contrib/virtiofsd/fuse_lowlevel.c  | 23 ++++++-
 contrib/virtiofsd/fuse_lowlevel.h  | 25 ++++++++
 contrib/virtiofsd/fuse_virtio.c    | 97 ++++++++++++++++++++++++++++--
 contrib/virtiofsd/passthrough_ll.c | 49 ++++++++++++---
 5 files changed, 185 insertions(+), 16 deletions(-)
contrib/virtiofsd/fuse_kernel.h +7 -0
index 2bdc8b1c88..432eb14d14 100644
@@ -444,6 +444,7 @@ enum fuse_notify_code {
 	FUSE_NOTIFY_STORE = 4,
 	FUSE_NOTIFY_RETRIEVE = 5,
 	FUSE_NOTIFY_DELETE = 6,
+	FUSE_NOTIFY_LOCK = 7,
 	FUSE_NOTIFY_CODE_MAX,
 };
 
@@ -836,6 +837,12 @@ struct fuse_notify_retrieve_in {
 	uint64_t	dummy4;
 };
 
+struct fuse_notify_lock_out {
+	uint64_t	unique;
+	int32_t		error;
+	int32_t		padding;
+};
+
 /* Device ioctls: */
 #define FUSE_DEV_IOC_CLONE	_IOR(229, 0, uint32_t)
 
contrib/virtiofsd/fuse_lowlevel.c +22 -1
index d4a42d9804..3d9c289510 100644
@@ -183,7 +183,8 @@ int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
 {
 	struct fuse_out_header out;
 
-	if (error <= -1000 || error > 0) {
+	/* error = 1 has been used to signal client to wait for notificaiton */
+	if (error <= -1000 || error > 1) {
 		fuse_log(FUSE_LOG_ERR, "fuse: bad error value: %i\n",	error);
 		error = -ERANGE;
 	}
@@ -291,6 +292,12 @@ int fuse_reply_err(fuse_req_t req, int err)
 	return send_reply(req, -err, NULL, 0);
 }
 
+int fuse_reply_wait(fuse_req_t req)
+{
+	/* TODO: This is a hack. Fix it */
+	return send_reply(req, 1, NULL, 0);
+}
+
 void fuse_reply_none(fuse_req_t req)
 {
 	fuse_free_req(req);
@@ -2207,6 +2214,20 @@ static int send_notify_iov(struct fuse_session *se, int notify_code,
 	return fuse_send_msg(se, NULL, iov, count);
 }
 
+int fuse_lowlevel_notify_lock(struct fuse_session *se, uint64_t unique,
+			      int32_t error)
+{
+	struct fuse_notify_lock_out outarg = {0};
+	struct iovec iov[2];
+
+	outarg.unique = unique;
+	outarg.error = -error;
+
+	iov[1].iov_base = &outarg;
+	iov[1].iov_len = sizeof(outarg);
+	return send_notify_iov(se, FUSE_NOTIFY_LOCK, iov, 2);
+}
+
 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph)
 {
 	if (ph != NULL) {
contrib/virtiofsd/fuse_lowlevel.h +25 -0
index e664d2d12d..4126b4f967 100644
@@ -1251,6 +1251,22 @@ struct fuse_lowlevel_ops {
  */
 int fuse_reply_err(fuse_req_t req, int err);
 
+/**
+ * Ask caller to wait for lock.
+ *
+ * Possible requests:
+ *   setlkw
+ *
+ * If caller sends a blocking lock request (setlkw), then reply to caller
+ * that wait for lock to be available. Once lock is available caller will
+ * receive a notification with request's unique id. Notification will
+ * carry info whether lock was successfully obtained or not.
+ *
+ * @param req request handle
+ * @return zero for success, -errno for failure to send reply
+ */
+int fuse_reply_wait(fuse_req_t req);
+
 /**
  * Don't send reply
  *
@@ -1704,6 +1720,15 @@ int fuse_lowlevel_notify_delete(struct fuse_session *se,
 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
 			       off_t offset, struct fuse_bufvec *bufv,
 			       enum fuse_buf_copy_flags flags);
+/**
+ * Notify event related to previous lock request
+ *
+ * @param se the session object
+ * @param unique the unique id of the request which requested setlkw
+ * @param error zero for success, -errno for the failure
+ */
+int fuse_lowlevel_notify_lock(struct fuse_session *se, uint64_t unique,
+			      int32_t error);
 
 /* ----------------------------------------------------------- *
  * Utility functions					       *
contrib/virtiofsd/fuse_virtio.c +91 -6

122 lines not on this page · raw message

contrib/virtiofsd/passthrough_ll.c +40 -9

79 lines not on this page · raw message

Signature · 1 line
2.20.1