@@ -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:
@@ -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.
@@ -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;
}
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(+)