[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a4f03e42-14a3-8e1b-387e-6f18b57f1eb@google.com>
Date: Fri, 30 Jul 2021 00:57:56 -0700 (PDT)
From: Hugh Dickins <hughd@...gle.com>
To: Andrew Morton <akpm@...ux-foundation.org>
cc: Hugh Dickins <hughd@...gle.com>,
Shakeel Butt <shakeelb@...gle.com>,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Yang Shi <shy828301@...il.com>,
Miaohe Lin <linmiaohe@...wei.com>,
Mike Kravetz <mike.kravetz@...cle.com>,
Michal Hocko <mhocko@...e.com>,
Rik van Riel <riel@...riel.com>,
Christoph Hellwig <hch@...radead.org>,
Matthew Wilcox <willy@...radead.org>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Alexey Gladkov <legion@...nel.org>,
Chris Wilson <chris@...is-wilson.co.uk>,
Matthew Auld <matthew.auld@...el.com>,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-api@...r.kernel.org, linux-mm@...ck.org
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@...gle.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
Powered by blists - more mailing lists