[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 07/13] virtiofsd: Release file locks using F_UNLCK
From: |
Vivek Goyal |
Subject: |
[PATCH 07/13] virtiofsd: Release file locks using F_UNLCK |
Date: |
Thu, 30 Sep 2021 11:30:31 -0400 |
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 of closing fd
and plock will be freed later when lo_inode is being freed.
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Ioannis Angelakopoulos <iangelak@redhat.com>
---
tools/virtiofsd/passthrough_ll.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 38b2af8599..6928662e22 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -1557,9 +1557,6 @@ static void unref_inode(struct lo_data *lo, struct
lo_inode *inode, uint64_t n)
lo_map_remove(&lo->ino_map, inode->fuse_ino);
g_hash_table_remove(lo->inodes, &inode->key);
if (lo->posix_lock) {
- 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);
}
@@ -2266,6 +2263,8 @@ 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_data *lo = lo_data(req);
+ struct lo_inode_plock *plock;
+ struct flock flock;
inode = lo_inode(req, ino);
if (!inode) {
@@ -2282,8 +2281,22 @@ static void lo_flush(fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi)
/* An fd is going away. Cleanup associated posix locks */
if (lo->posix_lock) {
pthread_mutex_lock(&inode->plock_mutex);
- g_hash_table_remove(inode->posix_locks,
+ plock = g_hash_table_lookup(inode->posix_locks,
GUINT_TO_POINTER(fi->lock_owner));
+
+ if (plock) {
+ /*
+ * An fd is being closed. For posix locks, this means
+ * drop all the associated locks.
+ */
+ 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);
}
res = close(dup(lo_fi_fd(req, fi)));
--
2.31.1
- [PATCH 01/13] virtio_fs.h: Add notification queue feature bit, (continued)
- [PATCH 01/13] virtio_fs.h: Add notification queue feature bit, Vivek Goyal, 2021/09/30
- [PATCH 13/13] virtiofsd, seccomp: Add clock_nanosleep() to allow list, Vivek Goyal, 2021/09/30
- [PATCH 05/13] virtiofsd: Add a helper to stop all queues, Vivek Goyal, 2021/09/30
- [PATCH 03/13] virtiofsd: Remove unused virtio_fs_config definition, Vivek Goyal, 2021/09/30
- [PATCH 08/13] virtiofsd: Create a notification queue, Vivek Goyal, 2021/09/30
- [PATCH 11/13] virtiofsd: Shutdown notification queue in the end, Vivek Goyal, 2021/09/30
- [PATCH 10/13] virtiofsd: Custom threadpool for remote blocking posix locks requests, Vivek Goyal, 2021/09/30
- [PATCH 02/13] virtiofsd: fuse.h header file changes for lock notification, Vivek Goyal, 2021/09/30
- [PATCH 04/13] virtiofsd: Add a helper to send element on virtqueue, Vivek Goyal, 2021/09/30
- [PATCH 06/13] vhost-user-fs: Use helpers to create/cleanup virtqueue, Vivek Goyal, 2021/09/30
- [PATCH 07/13] virtiofsd: Release file locks using F_UNLCK,
Vivek Goyal <=
- [PATCH 09/13] virtiofsd: Specify size of notification buffer using config space, Vivek Goyal, 2021/09/30
- [PATCH 12/13] virtiofsd: Implement blocking posix locks, Vivek Goyal, 2021/09/30