Skip to contentSkip to conversation

locks: remove LOCK_MAND flock lock support

PATCH In review Jeff Layton 3 participants 4 messages Sep 10, 2021

Subsystems (6)
lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

PATCH 1/1 locks: remove LOCK_MAND flock lock support

As best I can tell, the logic for these has been broken for a long time (at least before the move to git), such that they never conflict with anything. Also, nothing checks for these flags and prevented opens or read/write behavior on the files. They don't seem to do anything.

Given that, we can rip these symbols out of the kernel, and just make flock(2) return 0 when LOCK_MAND is set in order to preserve existing behavior.

Cc Matthew Wilcox <[email protected]>
Cc Stephen Rothwell <[email protected]>
---
 fs/ceph/locks.c                  |  3 ---
 fs/gfs2/file.c                   |  2 --
 fs/locks.c                       | 46 +++++++++++++++-----------------
 fs/nfs/file.c                    |  9 -------
 include/uapi/asm-generic/fcntl.h |  4 +++
 5 files changed, 25 insertions(+), 39 deletions(-)

Note that I do see some occurrences of LOCK_MAND in samba codebase, but I think it's probably best that those are removed.

fs/ceph/locks.c +0 -3
index bdeb271f47d9..d8c31069fbf2 100644
@@ -302,9 +302,6 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
 
 	if (!(fl->fl_flags & FL_FLOCK))
 		return -ENOLCK;
-	/* No mandatory locks */
-	if (fl->fl_type & LOCK_MAND)
-		return -EOPNOTSUPP;
 
 	dout("ceph_flock, fl_file: %p\n", fl->fl_file);
 
fs/gfs2/file.c +0 -2
index c559827cb6f9..078ef29e31bc 100644
@@ -1338,8 +1338,6 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
 {
 	if (!(fl->fl_flags & FL_FLOCK))
 		return -ENOLCK;
-	if (fl->fl_type & LOCK_MAND)
-		return -EOPNOTSUPP;
 
 	if (fl->fl_type == F_UNLCK) {
 		do_unflock(file, fl);
fs/locks.c +21 -25

85 lines not on this page · raw message

fs/nfs/file.c +0 -9
index aa353fd58240..24e7dccce355 100644
@@ -843,15 +843,6 @@ int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
 	if (!(fl->fl_flags & FL_FLOCK))
 		return -ENOLCK;
 
-	/*
-	 * The NFSv4 protocol doesn't support LOCK_MAND, which is not part of
-	 * any standard. In principle we might be able to support LOCK_MAND
-	 * on NFSv2/3 since NLMv3/4 support DOS share modes, but for now the
-	 * NFS code is not set up for it.
-	 */
-	if (fl->fl_type & LOCK_MAND)
-		return -EINVAL;
-
 	if (NFS_SERVER(inode)->flags & NFS_MOUNT_LOCAL_FLOCK)
 		is_local = 1;
 
include/uapi/asm-generic/fcntl.h +4 -0
index 9dc0bf0c5a6e..ecd0f5bdfc1d 100644
@@ -181,6 +181,10 @@ struct f_owner_ex {
 				   blocking */
 #define LOCK_UN		8	/* remove lock */
 
+/*
+ * LOCK_MAND support has been removed from the kernel. We leave the symbols
+ * here to not break legacy builds, but these should not be used in new code.
+ */
 #define LOCK_MAND	32	/* This is a mandatory flock ... */
 #define LOCK_READ	64	/* which allows concurrent read operations */
 #define LOCK_WRITE	128	/* which allows concurrent write operations */
Signature · 1 line
2.31.1
#1 lore raw
Quoted 3 lines · Jeff Layton

As best I can tell, the logic for these has been broken for a long time (at least before the move to git), such that they never conflict with anything.

I've wondered about that!

But a grep of the Samba code shows it actually uses LOCK_MAND, why? Looking closer now, I see that it sets LOCK_MAND in some cases but never checks for LOCK_MAND, so there's absolutely no point unless the kernel is doing something useful, which it isn't. Huh.

Looking back at the kernel... LOCK_MAND was introduced in Linux 2.4.0-test9pre6, and it was only checked in nfsd read and write code, and only only on exports that had an "msnfs" export option set.

So it was a mandatory lock that only worked against NFS readers and writers, and only if the admin knew to set this export option.

And, oh, look, I'd forgotten about this, but apparently in 2011 I noticed that the msnfs option was totally undocumented and ripped it out, in 9ce137eee4fe "nfsd: don't support msnfs export option".

I've heard no complaints since, so I guess that was an OK decision.

But I should have noticed at the same time that this also made LOCK_MAND a no-op.

OK, sorry for the novel, and thanks for cleaning this up!

(Are you sending Samba a patch too?)

--b.

Quoted 180 lines

Also, nothing checks for these flags and prevented opens or read/write behavior on the files. They don't seem to do anything.

Given that, we can rip these symbols out of the kernel, and just make flock(2) return 0 when LOCK_MAND is set in order to preserve existing behavior.

Cc Matthew Wilcox <[email protected]>
Cc Stephen Rothwell <[email protected]>
---
 fs/ceph/locks.c                  |  3 ---
 fs/gfs2/file.c                   |  2 --
 fs/locks.c                       | 46 +++++++++++++++-----------------
 fs/nfs/file.c                    |  9 -------
 include/uapi/asm-generic/fcntl.h |  4 +++
 5 files changed, 25 insertions(+), 39 deletions(-)

Note that I do see some occurrences of LOCK_MAND in samba codebase, but I think it's probably best that those are removed.

fs/ceph/locks.c +0 -3
index bdeb271f47d9..d8c31069fbf2 100644
@@ -302,9 +302,6 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
 
 	if (!(fl->fl_flags & FL_FLOCK))
 		return -ENOLCK;
-	/* No mandatory locks */
-	if (fl->fl_type & LOCK_MAND)
-		return -EOPNOTSUPP;
 
 	dout("ceph_flock, fl_file: %p\n", fl->fl_file);
 
fs/gfs2/file.c +0 -2
index c559827cb6f9..078ef29e31bc 100644
@@ -1338,8 +1338,6 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
 {
 	if (!(fl->fl_flags & FL_FLOCK))
 		return -ENOLCK;
-	if (fl->fl_type & LOCK_MAND)
-		return -EOPNOTSUPP;
 
 	if (fl->fl_type == F_UNLCK) {
 		do_unflock(file, fl);
fs/locks.c +21 -25
index 3d6fb4ae847b..0e1d8a637e9c 100644
@@ -461,8 +461,6 @@ static void locks_move_blocks(struct file_lock *new, struct file_lock *fl)
 }
 
 static inline int flock_translate_cmd(int cmd) {
-	if (cmd & LOCK_MAND)
-		return cmd & (LOCK_MAND | LOCK_RW);
 	switch (cmd) {
 	case LOCK_SH:
 		return F_RDLCK;
@@ -942,8 +940,6 @@ static bool flock_locks_conflict(struct file_lock *caller_fl,
 	 */
 	if (caller_fl->fl_file == sys_fl->fl_file)
 		return false;
-	if ((caller_fl->fl_type & LOCK_MAND) || (sys_fl->fl_type & LOCK_MAND))
-		return false;
 
 	return locks_conflict(caller_fl, sys_fl);
 }
@@ -2116,11 +2112,9 @@ EXPORT_SYMBOL(locks_lock_inode_wait);
  *	- %LOCK_SH -- a shared lock.
  *	- %LOCK_EX -- an exclusive lock.
  *	- %LOCK_UN -- remove an existing lock.
- *	- %LOCK_MAND -- a 'mandatory' flock.
- *	  This exists to emulate Windows Share Modes.
+ *	- %LOCK_MAND -- a 'mandatory' flock. (DEPRECATED)
  *
- *	%LOCK_MAND can be combined with %LOCK_READ or %LOCK_WRITE to allow other
- *	processes read and write access respectively.
+ *	%LOCK_MAND support has been removed from the kernel.
  */
 SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
 {
@@ -2137,9 +2131,22 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
 	cmd &= ~LOCK_NB;
 	unlock = (cmd == LOCK_UN);
 
-	if (!unlock && !(cmd & LOCK_MAND) &&
-	    !(f.file->f_mode & (FMODE_READ|FMODE_WRITE)))
+	if (!unlock && !(f.file->f_mode & (FMODE_READ|FMODE_WRITE)))
+		goto out_putf;
+
+	/*
+	 * LOCK_MAND locks were broken for a long time in that they never
+	 * conflicted with one another and didn't prevent any sort of open,
+	 * read or write activity.
+	 *
+	 * Just ignore these requests now, to preserve legacy behavior, but
+	 * throw a warning to let people know that they don't actually work.
+	 */
+	if (cmd & LOCK_MAND) {
+		pr_warn_once("Attempt to set a LOCK_MAND lock via flock(2). This support has been removed and the request ignored.\n");
+		error = 0;
 		goto out_putf;
+	}
 
 	lock = flock_make_lock(f.file, cmd, NULL);
 	if (IS_ERR(lock)) {
@@ -2745,11 +2752,7 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
 		seq_printf(f, " %s ",
 			     (inode == NULL) ? "*NOINODE*" : "ADVISORY ");
 	} else if (IS_FLOCK(fl)) {
-		if (fl->fl_type & LOCK_MAND) {
-			seq_puts(f, "FLOCK  MSNFS     ");
-		} else {
-			seq_puts(f, "FLOCK  ADVISORY  ");
-		}
+		seq_puts(f, "FLOCK  ADVISORY  ");
 	} else if (IS_LEASE(fl)) {
 		if (fl->fl_flags & FL_DELEG)
 			seq_puts(f, "DELEG  ");
@@ -2765,17 +2768,10 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
 	} else {
 		seq_puts(f, "UNKNOWN UNKNOWN  ");
 	}
-	if (fl->fl_type & LOCK_MAND) {
-		seq_printf(f, "%s ",
-			       (fl->fl_type & LOCK_READ)
-			       ? (fl->fl_type & LOCK_WRITE) ? "RW   " : "READ "
-			       : (fl->fl_type & LOCK_WRITE) ? "WRITE" : "NONE ");
-	} else {
-		int type = IS_LEASE(fl) ? target_leasetype(fl) : fl->fl_type;
+	int type = IS_LEASE(fl) ? target_leasetype(fl) : fl->fl_type;
 
-		seq_printf(f, "%s ", (type == F_WRLCK) ? "WRITE" :
-				     (type == F_RDLCK) ? "READ" : "UNLCK");
-	}
+	seq_printf(f, "%s ", (type == F_WRLCK) ? "WRITE" :
+			     (type == F_RDLCK) ? "READ" : "UNLCK");
 	if (inode) {
 		/* userspace relies on this representation of dev_t */
 		seq_printf(f, "%d %02x:%02x:%lu ", fl_pid,
fs/nfs/file.c +0 -9
index aa353fd58240..24e7dccce355 100644
@@ -843,15 +843,6 @@ int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
 	if (!(fl->fl_flags & FL_FLOCK))
 		return -ENOLCK;
 
-	/*
-	 * The NFSv4 protocol doesn't support LOCK_MAND, which is not part of
-	 * any standard. In principle we might be able to support LOCK_MAND
-	 * on NFSv2/3 since NLMv3/4 support DOS share modes, but for now the
-	 * NFS code is not set up for it.
-	 */
-	if (fl->fl_type & LOCK_MAND)
-		return -EINVAL;
-
 	if (NFS_SERVER(inode)->flags & NFS_MOUNT_LOCAL_FLOCK)
 		is_local = 1;
 
include/uapi/asm-generic/fcntl.h +4 -0
index 9dc0bf0c5a6e..ecd0f5bdfc1d 100644
@@ -181,6 +181,10 @@ struct f_owner_ex {
 				   blocking */
 #define LOCK_UN		8	/* remove lock */
 
+/*
+ * LOCK_MAND support has been removed from the kernel. We leave the symbols
+ * here to not break legacy builds, but these should not be used in new code.
+ */
 #define LOCK_MAND	32	/* This is a mandatory flock ... */
 #define LOCK_READ	64	/* which allows concurrent read operations */
 #define LOCK_WRITE	128	/* which allows concurrent write operations */
Signature · 1 line
2.31.1
author maintainer
#2 lore raw
Quoted 25 lines · J. Bruce Fields
Quoted 3 lines · Jeff Layton

As best I can tell, the logic for these has been broken for a long time (at least before the move to git), such that they never conflict with anything.

I've wondered about that!

But a grep of the Samba code shows it actually uses LOCK_MAND, why? Looking closer now, I see that it sets LOCK_MAND in some cases but never checks for LOCK_MAND, so there's absolutely no point unless the kernel is doing something useful, which it isn't. Huh.

Looking back at the kernel... LOCK_MAND was introduced in Linux 2.4.0-test9pre6, and it was only checked in nfsd read and write code, and only only on exports that had an "msnfs" export option set.

So it was a mandatory lock that only worked against NFS readers and writers, and only if the admin knew to set this export option.

And, oh, look, I'd forgotten about this, but apparently in 2011 I noticed that the msnfs option was totally undocumented and ripped it out, in 9ce137eee4fe "nfsd: don't support msnfs export option".

I've heard no complaints since, so I guess that was an OK decision.

Quoted 9 lines

But I should have noticed at the same time that this also made LOCK_MAND a no-op.

OK, sorry for the novel, and thanks for cleaning this up!

(Are you sending Samba a patch too?)

--b.

Ahh, thanks for the archaeology! That makes sense. I took a look at Samba, but haven't cooked up a patch for it yet.

After taking a look, I sort of wonder whether there might be out of tree filesystems (GPFS?) that do support these flags properly. OTOH, I'm not inclined to worry about them too much. Maybe if they want to chime in we can work with them to ease the transition.

I'll probably do a patch for samba soon, just to kick off the discussion with those guys. I'll see what I can come up with.

Quoted 180 lines
Quoted 180 lines

Also, nothing checks for these flags and prevented opens or read/write behavior on the files. They don't seem to do anything.

Given that, we can rip these symbols out of the kernel, and just make flock(2) return 0 when LOCK_MAND is set in order to preserve existing behavior.

Cc Matthew Wilcox <[email protected]>
Cc Stephen Rothwell <[email protected]>
---
 fs/ceph/locks.c                  |  3 ---
 fs/gfs2/file.c                   |  2 --
 fs/locks.c                       | 46 +++++++++++++++-----------------
 fs/nfs/file.c                    |  9 -------
 include/uapi/asm-generic/fcntl.h |  4 +++
 5 files changed, 25 insertions(+), 39 deletions(-)

Note that I do see some occurrences of LOCK_MAND in samba codebase, but I think it's probably best that those are removed.

fs/ceph/locks.c +0 -3
index bdeb271f47d9..d8c31069fbf2 100644
@@ -302,9 +302,6 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
 
 	if (!(fl->fl_flags & FL_FLOCK))
 		return -ENOLCK;
-	/* No mandatory locks */
-	if (fl->fl_type & LOCK_MAND)
-		return -EOPNOTSUPP;
 
 	dout("ceph_flock, fl_file: %p\n", fl->fl_file);
 
fs/gfs2/file.c +0 -2
index c559827cb6f9..078ef29e31bc 100644
@@ -1338,8 +1338,6 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
 {
 	if (!(fl->fl_flags & FL_FLOCK))
 		return -ENOLCK;
-	if (fl->fl_type & LOCK_MAND)
-		return -EOPNOTSUPP;
 
 	if (fl->fl_type == F_UNLCK) {
 		do_unflock(file, fl);
fs/locks.c +21 -25
index 3d6fb4ae847b..0e1d8a637e9c 100644
@@ -461,8 +461,6 @@ static void locks_move_blocks(struct file_lock *new, struct file_lock *fl)
 }
 
 static inline int flock_translate_cmd(int cmd) {
-	if (cmd & LOCK_MAND)
-		return cmd & (LOCK_MAND | LOCK_RW);
 	switch (cmd) {
 	case LOCK_SH:
 		return F_RDLCK;
@@ -942,8 +940,6 @@ static bool flock_locks_conflict(struct file_lock *caller_fl,
 	 */
 	if (caller_fl->fl_file == sys_fl->fl_file)
 		return false;
-	if ((caller_fl->fl_type & LOCK_MAND) || (sys_fl->fl_type & LOCK_MAND))
-		return false;
 
 	return locks_conflict(caller_fl, sys_fl);
 }
@@ -2116,11 +2112,9 @@ EXPORT_SYMBOL(locks_lock_inode_wait);
  *	- %LOCK_SH -- a shared lock.
  *	- %LOCK_EX -- an exclusive lock.
  *	- %LOCK_UN -- remove an existing lock.
- *	- %LOCK_MAND -- a 'mandatory' flock.
- *	  This exists to emulate Windows Share Modes.
+ *	- %LOCK_MAND -- a 'mandatory' flock. (DEPRECATED)
  *
- *	%LOCK_MAND can be combined with %LOCK_READ or %LOCK_WRITE to allow other
- *	processes read and write access respectively.
+ *	%LOCK_MAND support has been removed from the kernel.
  */
 SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
 {
@@ -2137,9 +2131,22 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
 	cmd &= ~LOCK_NB;
 	unlock = (cmd == LOCK_UN);
 
-	if (!unlock && !(cmd & LOCK_MAND) &&
-	    !(f.file->f_mode & (FMODE_READ|FMODE_WRITE)))
+	if (!unlock && !(f.file->f_mode & (FMODE_READ|FMODE_WRITE)))
+		goto out_putf;
+
+	/*
+	 * LOCK_MAND locks were broken for a long time in that they never
+	 * conflicted with one another and didn't prevent any sort of open,
+	 * read or write activity.
+	 *
+	 * Just ignore these requests now, to preserve legacy behavior, but
+	 * throw a warning to let people know that they don't actually work.
+	 */
+	if (cmd & LOCK_MAND) {
+		pr_warn_once("Attempt to set a LOCK_MAND lock via flock(2). This support has been removed and the request ignored.\n");
+		error = 0;
 		goto out_putf;
+	}
 
 	lock = flock_make_lock(f.file, cmd, NULL);
 	if (IS_ERR(lock)) {
@@ -2745,11 +2752,7 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
 		seq_printf(f, " %s ",
 			     (inode == NULL) ? "*NOINODE*" : "ADVISORY ");
 	} else if (IS_FLOCK(fl)) {
-		if (fl->fl_type & LOCK_MAND) {
-			seq_puts(f, "FLOCK  MSNFS     ");
-		} else {
-			seq_puts(f, "FLOCK  ADVISORY  ");
-		}
+		seq_puts(f, "FLOCK  ADVISORY  ");
 	} else if (IS_LEASE(fl)) {
 		if (fl->fl_flags & FL_DELEG)
 			seq_puts(f, "DELEG  ");
@@ -2765,17 +2768,10 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
 	} else {
 		seq_puts(f, "UNKNOWN UNKNOWN  ");
 	}
-	if (fl->fl_type & LOCK_MAND) {
-		seq_printf(f, "%s ",
-			       (fl->fl_type & LOCK_READ)
-			       ? (fl->fl_type & LOCK_WRITE) ? "RW   " : "READ "
-			       : (fl->fl_type & LOCK_WRITE) ? "WRITE" : "NONE ");
-	} else {
-		int type = IS_LEASE(fl) ? target_leasetype(fl) : fl->fl_type;
+	int type = IS_LEASE(fl) ? target_leasetype(fl) : fl->fl_type;
 
-		seq_printf(f, "%s ", (type == F_WRLCK) ? "WRITE" :
-				     (type == F_RDLCK) ? "READ" : "UNLCK");
-	}
+	seq_printf(f, "%s ", (type == F_WRLCK) ? "WRITE" :
+			     (type == F_RDLCK) ? "READ" : "UNLCK");
 	if (inode) {
 		/* userspace relies on this representation of dev_t */
 		seq_printf(f, "%d %02x:%02x:%lu ", fl_pid,
fs/nfs/file.c +0 -9
index aa353fd58240..24e7dccce355 100644
@@ -843,15 +843,6 @@ int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
 	if (!(fl->fl_flags & FL_FLOCK))
 		return -ENOLCK;
 
-	/*
-	 * The NFSv4 protocol doesn't support LOCK_MAND, which is not part of
-	 * any standard. In principle we might be able to support LOCK_MAND
-	 * on NFSv2/3 since NLMv3/4 support DOS share modes, but for now the
-	 * NFS code is not set up for it.
-	 */
-	if (fl->fl_type & LOCK_MAND)
-		return -EINVAL;
-
 	if (NFS_SERVER(inode)->flags & NFS_MOUNT_LOCAL_FLOCK)
 		is_local = 1;
 
include/uapi/asm-generic/fcntl.h +4 -0
index 9dc0bf0c5a6e..ecd0f5bdfc1d 100644
@@ -181,6 +181,10 @@ struct f_owner_ex {
 				   blocking */
 #define LOCK_UN		8	/* remove lock */
 
+/*
+ * LOCK_MAND support has been removed from the kernel. We leave the symbols
+ * here to not break legacy builds, but these should not be used in new code.
+ */
 #define LOCK_MAND	32	/* This is a mandatory flock ... */
 #define LOCK_READ	64	/* which allows concurrent read operations */
 #define LOCK_WRITE	128	/* which allows concurrent write operations */
Signature · 1 line
2.31.1
Signature · 1 line
Jeff Layton <[email protected]>
#3 lore raw
In reply to Jeff Layton
I love your patch! Perhaps something to improve:

Hi Jeff,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on linux/master v5.14 next-20210910]
[cannot apply to ceph-client/for-linus gfs2/for-next nfs/linux-next asm-generic/master] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Jeff-Layton/locks-remove-LOCK_MAND-flock-lock-support/20210911-042031
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e99f23c5bf59219d0cd9b6e0d7d4c1b641a98704
config: nios2-buildonly-randconfig-r006-20210910 (attached as .config)
compiler: nios2-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/6ad4c7ee0637575ecc2f2acb3bf693d033259c83
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jeff-Layton/locks-remove-LOCK_MAND-flock-lock-support/20210911-042031 git checkout 6ad4c7ee0637575ecc2f2acb3bf693d033259c83
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=nios2

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

fs/locks.c: In function 'lock_get_status':

>> fs/locks.c:2771:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    2771 |         int type = IS_LEASE(fl) ? target_leasetype(fl) : fl->fl_type;
         |         ^~~

vim +2771 fs/locks.c

7012b02a2b2c42 Jeff Layton         2013-06-21  2721  
7f8ada98d9edd8 Pavel Emelyanov     2007-10-01  2722  static void lock_get_status(struct seq_file *f, struct file_lock *fl,
b8da9b10e26cee Luo Longjun         2021-02-25  2723  			    loff_t id, char *pfx, int repeat)
^1da177e4c3f41 Linus Torvalds      2005-04-16  2724  {
^1da177e4c3f41 Linus Torvalds      2005-04-16  2725  	struct inode *inode = NULL;
ab1f16116527e4 Vitaliy Gusev       2008-01-17  2726  	unsigned int fl_pid;
9d78edeaec759f Alexey Gladkov      2020-05-18  2727  	struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)->i_sb);
d67fd44f697dff Nikolay Borisov     2016-08-17  2728  
9d5b86ac13c573 Benjamin Coddington 2017-07-16  2729  	fl_pid = locks_translate_pid(fl, proc_pidns);
d67fd44f697dff Nikolay Borisov     2016-08-17  2730  	/*
1cf8e5de4055f8 Konstantin Khorenko 2018-06-08  2731  	 * If lock owner is dead (and pid is freed) or not visible in current
1cf8e5de4055f8 Konstantin Khorenko 2018-06-08  2732  	 * pidns, zero is shown as a pid value. Check lock info from
1cf8e5de4055f8 Konstantin Khorenko 2018-06-08  2733  	 * init_pid_ns to get saved lock pid value.
d67fd44f697dff Nikolay Borisov     2016-08-17  2734  	 */
^1da177e4c3f41 Linus Torvalds      2005-04-16  2735  
^1da177e4c3f41 Linus Torvalds      2005-04-16  2736  	if (fl->fl_file != NULL)
c568d68341be70 Miklos Szeredi      2016-09-16  2737  		inode = locks_inode(fl->fl_file);
^1da177e4c3f41 Linus Torvalds      2005-04-16  2738  
b8da9b10e26cee Luo Longjun         2021-02-25  2739  	seq_printf(f, "%lld: ", id);
b8da9b10e26cee Luo Longjun         2021-02-25  2740  
b8da9b10e26cee Luo Longjun         2021-02-25  2741  	if (repeat)
b8da9b10e26cee Luo Longjun         2021-02-25  2742  		seq_printf(f, "%*s", repeat - 1 + (int)strlen(pfx), pfx);
b8da9b10e26cee Luo Longjun         2021-02-25  2743  
^1da177e4c3f41 Linus Torvalds      2005-04-16  2744  	if (IS_POSIX(fl)) {
c918d42a27a9be Jeff Layton         2014-02-03  2745  		if (fl->fl_flags & FL_ACCESS)
5315c26a6c557f Fabian Frederick    2014-05-09  2746  			seq_puts(f, "ACCESS");
cff2fce58b2b0f Jeff Layton         2014-04-22  2747  		else if (IS_OFDLCK(fl))
5315c26a6c557f Fabian Frederick    2014-05-09  2748  			seq_puts(f, "OFDLCK");
c918d42a27a9be Jeff Layton         2014-02-03  2749  		else
5315c26a6c557f Fabian Frederick    2014-05-09  2750  			seq_puts(f, "POSIX ");
c918d42a27a9be Jeff Layton         2014-02-03  2751  
c918d42a27a9be Jeff Layton         2014-02-03  2752  		seq_printf(f, " %s ",
f7e33bdbd6d1bd Jeff Layton         2021-08-19  2753  			     (inode == NULL) ? "*NOINODE*" : "ADVISORY ");
^1da177e4c3f41 Linus Torvalds      2005-04-16  2754  	} else if (IS_FLOCK(fl)) {
5315c26a6c557f Fabian Frederick    2014-05-09  2755  		seq_puts(f, "FLOCK  ADVISORY  ");
^1da177e4c3f41 Linus Torvalds      2005-04-16  2756  	} else if (IS_LEASE(fl)) {
8144f1f69943f4 Jeff Layton         2014-08-11  2757  		if (fl->fl_flags & FL_DELEG)
8144f1f69943f4 Jeff Layton         2014-08-11  2758  			seq_puts(f, "DELEG  ");
8144f1f69943f4 Jeff Layton         2014-08-11  2759  		else
5315c26a6c557f Fabian Frederick    2014-05-09  2760  			seq_puts(f, "LEASE  ");
8144f1f69943f4 Jeff Layton         2014-08-11  2761  
ab83fa4b49a54e J. Bruce Fields     2011-07-26  2762  		if (lease_breaking(fl))
5315c26a6c557f Fabian Frederick    2014-05-09  2763  			seq_puts(f, "BREAKING  ");
^1da177e4c3f41 Linus Torvalds      2005-04-16  2764  		else if (fl->fl_file)
5315c26a6c557f Fabian Frederick    2014-05-09  2765  			seq_puts(f, "ACTIVE    ");
^1da177e4c3f41 Linus Torvalds      2005-04-16  2766  		else
5315c26a6c557f Fabian Frederick    2014-05-09  2767  			seq_puts(f, "BREAKER   ");
^1da177e4c3f41 Linus Torvalds      2005-04-16  2768  	} else {
5315c26a6c557f Fabian Frederick    2014-05-09  2769  		seq_puts(f, "UNKNOWN UNKNOWN  ");
^1da177e4c3f41 Linus Torvalds      2005-04-16  2770  	}
43e4cb942e88e7 Pavel Begunkov      2019-07-24 @2771  	int type = IS_LEASE(fl) ? target_leasetype(fl) : fl->fl_type;
43e4cb942e88e7 Pavel Begunkov      2019-07-24  2772  
43e4cb942e88e7 Pavel Begunkov      2019-07-24  2773  	seq_printf(f, "%s ", (type == F_WRLCK) ? "WRITE" :
43e4cb942e88e7 Pavel Begunkov      2019-07-24  2774  			     (type == F_RDLCK) ? "READ" : "UNLCK");
^1da177e4c3f41 Linus Torvalds      2005-04-16  2775  	if (inode) {
3648888e90bb7f Jeff Layton         2015-04-03  2776  		/* userspace relies on this representation of dev_t */
98ca480a8f22fd Amir Goldstein      2019-12-22  2777  		seq_printf(f, "%d %02x:%02x:%lu ", fl_pid,
^1da177e4c3f41 Linus Torvalds      2005-04-16  2778  				MAJOR(inode->i_sb->s_dev),
^1da177e4c3f41 Linus Torvalds      2005-04-16  2779  				MINOR(inode->i_sb->s_dev), inode->i_ino);
^1da177e4c3f41 Linus Torvalds      2005-04-16  2780  	} else {
ab1f16116527e4 Vitaliy Gusev       2008-01-17  2781  		seq_printf(f, "%d <none>:0 ", fl_pid);
^1da177e4c3f41 Linus Torvalds      2005-04-16  2782  	}
^1da177e4c3f41 Linus Torvalds      2005-04-16  2783  	if (IS_POSIX(fl)) {
^1da177e4c3f41 Linus Torvalds      2005-04-16  2784  		if (fl->fl_end == OFFSET_MAX)
7f8ada98d9edd8 Pavel Emelyanov     2007-10-01  2785  			seq_printf(f, "%Ld EOF\n", fl->fl_start);
^1da177e4c3f41 Linus Torvalds      2005-04-16  2786  		else
7f8ada98d9edd8 Pavel Emelyanov     2007-10-01  2787  			seq_printf(f, "%Ld %Ld\n", fl->fl_start, fl->fl_end);
^1da177e4c3f41 Linus Torvalds      2005-04-16  2788  	} else {
5315c26a6c557f Fabian Frederick    2014-05-09  2789  		seq_puts(f, "0 EOF\n");
^1da177e4c3f41 Linus Torvalds      2005-04-16  2790  	}
^1da177e4c3f41 Linus Torvalds      2005-04-16  2791  }
^1da177e4c3f41 Linus Torvalds      2005-04-16  2792  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org