hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/locks.c
....@@ -1339,6 +1339,7 @@
13391339 out:
13401340 spin_unlock(&ctx->flc_lock);
13411341 percpu_up_read(&file_rwsem);
1342
+ trace_posix_lock_inode(inode, request, error);
13421343 /*
13431344 * Free any unused locks.
13441345 */
....@@ -1347,7 +1348,6 @@
13471348 if (new_fl2)
13481349 locks_free_lock(new_fl2);
13491350 locks_dispose_list(&dispose);
1350
- trace_posix_lock_inode(inode, request, error);
13511351
13521352 return error;
13531353 }
....@@ -2813,6 +2813,29 @@
28132813 }
28142814 EXPORT_SYMBOL_GPL(vfs_cancel_lock);
28152815
2816
+/**
2817
+ * vfs_inode_has_locks - are any file locks held on @inode?
2818
+ * @inode: inode to check for locks
2819
+ *
2820
+ * Return true if there are any FL_POSIX or FL_FLOCK locks currently
2821
+ * set on @inode.
2822
+ */
2823
+bool vfs_inode_has_locks(struct inode *inode)
2824
+{
2825
+ struct file_lock_context *ctx;
2826
+ bool ret;
2827
+
2828
+ ctx = smp_load_acquire(&inode->i_flctx);
2829
+ if (!ctx)
2830
+ return false;
2831
+
2832
+ spin_lock(&ctx->flc_lock);
2833
+ ret = !list_empty(&ctx->flc_posix) || !list_empty(&ctx->flc_flock);
2834
+ spin_unlock(&ctx->flc_lock);
2835
+ return ret;
2836
+}
2837
+EXPORT_SYMBOL_GPL(vfs_inode_has_locks);
2838
+
28162839 #ifdef CONFIG_PROC_FS
28172840 #include <linux/proc_fs.h>
28182841 #include <linux/seq_file.h>