[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250820010415.699353-6-anthony.yznaga@oracle.com>
Date: Tue, 19 Aug 2025 18:03:58 -0700
From: Anthony Yznaga <anthony.yznaga@...cle.com>
To: linux-mm@...ck.org
Cc: akpm@...ux-foundation.org, andreyknvl@...il.com, arnd@...db.de,
bp@...en8.de, brauner@...nel.org, bsegall@...gle.com, corbet@....net,
dave.hansen@...ux.intel.com, david@...hat.com,
dietmar.eggemann@....com, ebiederm@...ssion.com, hpa@...or.com,
jakub.wartak@...lbox.org, jannh@...gle.com, juri.lelli@...hat.com,
khalid@...nel.org, liam.howlett@...cle.com, linyongting@...edance.com,
lorenzo.stoakes@...cle.com, luto@...nel.org, markhemm@...glemail.com,
maz@...nel.org, mhiramat@...nel.org, mgorman@...e.de, mhocko@...e.com,
mingo@...hat.com, muchun.song@...ux.dev, neilb@...e.de,
osalvador@...e.de, pcc@...gle.com, peterz@...radead.org,
pfalcato@...e.de, rostedt@...dmis.org, rppt@...nel.org,
shakeel.butt@...ux.dev, surenb@...gle.com, tglx@...utronix.de,
vasily.averin@...ux.dev, vbabka@...e.cz, vincent.guittot@...aro.org,
viro@...iv.linux.org.uk, vschneid@...hat.com, willy@...radead.org,
x86@...nel.org, xhao@...ux.alibaba.com, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-arch@...r.kernel.org
Subject: [PATCH v3 05/22] mm/mshare: add ways to set the size of an mshare region
Add file and inode operations to allow the size of an mshare region
to be set fallocate() or ftruncate().
Signed-off-by: Anthony Yznaga <anthony.yznaga@...cle.com>
---
mm/mshare.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 86 insertions(+), 1 deletion(-)
diff --git a/mm/mshare.c b/mm/mshare.c
index 400f198c0791..bf859b176e09 100644
--- a/mm/mshare.c
+++ b/mm/mshare.c
@@ -16,19 +16,78 @@
#include <linux/fs.h>
#include <linux/fs_context.h>
#include <uapi/linux/magic.h>
+#include <linux/falloc.h>
const unsigned long mshare_align = P4D_SIZE;
+#define MSHARE_INITIALIZED 0x1
+
struct mshare_data {
struct mm_struct *mm;
refcount_t ref;
+ unsigned long size;
+ unsigned long flags;
};
+static inline bool mshare_is_initialized(struct mshare_data *m_data)
+{
+ return test_bit(MSHARE_INITIALIZED, &m_data->flags);
+}
+
+static int msharefs_set_size(struct mshare_data *m_data, unsigned long size)
+{
+ int error = -EINVAL;
+
+ if (mshare_is_initialized(m_data))
+ goto out;
+
+ if (m_data->size || (size & (mshare_align - 1)))
+ goto out;
+
+ m_data->mm->task_size = m_data->size = size;
+
+ set_bit(MSHARE_INITIALIZED, &m_data->flags);
+ error = 0;
+out:
+ return error;
+}
+
+static long msharefs_fallocate(struct file *file, int mode, loff_t offset,
+ loff_t len)
+{
+ struct inode *inode = file_inode(file);
+ struct mshare_data *m_data = inode->i_private;
+ int error;
+
+ if (mode != FALLOC_FL_ALLOCATE_RANGE)
+ return -EOPNOTSUPP;
+
+ if (offset)
+ return -EINVAL;
+
+ inode_lock(inode);
+
+ error = inode_newsize_ok(inode, len);
+ if (error)
+ goto out;
+
+ error = msharefs_set_size(m_data, len);
+ if (error)
+ goto out;
+
+ i_size_write(inode, len);
+out:
+ inode_unlock(inode);
+
+ return error;
+}
+
static const struct inode_operations msharefs_dir_inode_ops;
static const struct inode_operations msharefs_file_inode_ops;
static const struct file_operations msharefs_file_operations = {
.open = simple_open,
+ .fallocate = msharefs_fallocate,
};
static int
@@ -128,6 +187,32 @@ msharefs_mknod(struct mnt_idmap *idmap, struct inode *dir,
return 0;
}
+static int msharefs_setattr(struct mnt_idmap *idmap,
+ struct dentry *dentry, struct iattr *attr)
+{
+ struct inode *inode = d_inode(dentry);
+ struct mshare_data *m_data = inode->i_private;
+ unsigned int ia_valid = attr->ia_valid;
+ int error;
+
+ error = setattr_prepare(idmap, dentry, attr);
+ if (error)
+ return error;
+
+ if (ia_valid & ATTR_SIZE) {
+ loff_t newsize = attr->ia_size;
+
+ error = msharefs_set_size(m_data, newsize);
+ if (error)
+ return error;
+
+ i_size_write(inode, newsize);
+ }
+
+ setattr_copy(idmap, inode, attr);
+ return 0;
+}
+
static int
msharefs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
@@ -182,7 +267,7 @@ msharefs_unlink(struct inode *dir, struct dentry *dentry)
}
static const struct inode_operations msharefs_file_inode_ops = {
- .setattr = simple_setattr,
+ .setattr = msharefs_setattr,
};
static const struct inode_operations msharefs_dir_inode_ops = {
--
2.47.1
Powered by blists - more mailing lists