Messages in this thread Patch in this message | | | Date | Fri, 30 Jul 2021 00:57:56 -0700 (PDT) | From | Hugh Dickins <> | Subject | [PATCH 11/16] tmpfs: fcntl(fd, F_MEM_LOCKED) to test if memlocked |
| |
Though we have not yet found a compelling need to make the locked status of a tmpfs file visible, and offer no tool to show it, the kernel ought to be able to support such a tool: add the F_MEM_LOCKED fcntl, returning -1 on failure (not tmpfs), 0 when not F_MEM_LOCKED, 1 when F_MEM_LOCKED.
Signed-off-by: Hugh Dickins <hughd@google.com> --- fs/fcntl.c | 1 + include/uapi/linux/fcntl.h | 1 + mm/shmem.c | 4 ++++ 3 files changed, 6 insertions(+)
diff --git a/fs/fcntl.c b/fs/fcntl.c index a3534764b50e..0d8dc723732d 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -439,6 +439,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, case F_NOHUGEPAGE: case F_MEM_LOCK: case F_MEM_UNLOCK: + case F_MEM_LOCKED: err = shmem_fcntl(filp, cmd, arg); break; default: diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h index 21dc969df0fd..012585e8c9ab 100644 --- a/include/uapi/linux/fcntl.h +++ b/include/uapi/linux/fcntl.h @@ -88,6 +88,7 @@ */ #define F_MEM_LOCK (F_LINUX_SPECIFIC_BASE + 17) #define F_MEM_UNLOCK (F_LINUX_SPECIFIC_BASE + 18) +#define F_MEM_LOCKED (F_LINUX_SPECIFIC_BASE + 19) /* * Types of directory notifications that may be requested. diff --git a/mm/shmem.c b/mm/shmem.c index ba9b9900287b..6e53dabe658b 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2299,6 +2299,9 @@ static int shmem_memlock_fcntl(struct file *file, unsigned int cmd) bool cleanup_mapping = false; int retval = 0; + if (cmd == F_MEM_LOCKED) + return !!info->mlock_ucounts; + inode_lock(inode); if (cmd == F_MEM_LOCK) { if (!info->mlock_ucounts) { @@ -2762,6 +2765,7 @@ long shmem_fcntl(struct file *file, unsigned int cmd, unsigned long arg) break; case F_MEM_LOCK: case F_MEM_UNLOCK: + case F_MEM_LOCKED: error = shmem_memlock_fcntl(file, cmd); break; } -- 2.26.2
| |