[PATCH 09/13] filelock: lift the ban on directory leases in generic_setlease

Jeff Layton posted 13 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH 09/13] filelock: lift the ban on directory leases in generic_setlease
Posted by Jeff Layton 2 months, 1 week ago
With the addition of the try_break_lease calls in directory changing
operations, allow generic_setlease to hand them out.

Note that this also makes directory leases available to userland via
fcntl().

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/locks.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/locks.c b/fs/locks.c
index 9e366b13674538dbf482ffdeee92fc717733ee20..ee85a38a7d42fb9545887a4879746c82779ace90 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1934,14 +1934,19 @@ static int generic_delete_lease(struct file *filp, void *owner)
 int generic_setlease(struct file *filp, int arg, struct file_lease **flp,
 			void **priv)
 {
-	if (!S_ISREG(file_inode(filp)->i_mode))
+	struct inode *inode = file_inode(filp);
+
+	if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
 		return -EINVAL;
 
 	switch (arg) {
 	case F_UNLCK:
 		return generic_delete_lease(filp, *priv);
-	case F_RDLCK:
 	case F_WRLCK:
+		if (S_ISDIR(inode->i_mode))
+			return -EINVAL;
+		fallthrough;
+	case F_RDLCK:
 		if (!(*flp)->fl_lmops->lm_break) {
 			WARN_ON_ONCE(1);
 			return -ENOLCK;

-- 
2.51.0