From 088f5d7244de8d4ad0418c2ae7167fd9fe8efd31 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Mon, 29 Dec 2003 05:41:34 -0800 Subject: [PATCH] [PATCH] add steal_locks helper From: Chris Wright Add steal_locks helper for use in conjunction with unshare_files to make sure POSIX file lock semantics aren't broken due to unshare_files. --- fs/locks.c | 18 ++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 19 insertions(+) diff --git a/fs/locks.c b/fs/locks.c index 6ba8af8a7f386..e7bd3ffda64a9 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1983,6 +1983,24 @@ int lock_may_write(struct inode *inode, loff_t start, unsigned long len) EXPORT_SYMBOL(lock_may_write); +void steal_locks(fl_owner_t from) +{ + struct list_head *tmp; + + if (from == current->files) + return; + + lock_kernel(); + list_for_each(tmp, &file_lock_list) { + struct file_lock *fl = list_entry(tmp, struct file_lock, fl_link); + if (fl->fl_owner == from) + fl->fl_owner = current->files; + } + unlock_kernel(); +} + +EXPORT_SYMBOL(steal_locks); + static int __init filelock_init(void) { filelock_cache = kmem_cache_create("file_lock_cache", diff --git a/include/linux/fs.h b/include/linux/fs.h index dbe66b2858701..ab962f0b00c24 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -630,6 +630,7 @@ extern int __break_lease(struct inode *inode, unsigned int flags); extern void lease_get_mtime(struct inode *, struct timespec *time); extern int lock_may_read(struct inode *, loff_t start, unsigned long count); extern int lock_may_write(struct inode *, loff_t start, unsigned long count); +extern void steal_locks(fl_owner_t from); struct fasync_struct { int magic; -- 2.53.0