From patchwork Tue Sep 3 23:22:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E268CD37B1 for ; Tue, 3 Sep 2024 23:23:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92F4E8D01F1; Tue, 3 Sep 2024 19:23:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DFE58D01E4; Tue, 3 Sep 2024 19:23:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 730FF8D01F1; Tue, 3 Sep 2024 19:23:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4AAA58D01E4 for ; Tue, 3 Sep 2024 19:23:43 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9E008A9230 for ; Tue, 3 Sep 2024 23:23:42 +0000 (UTC) X-FDA: 82525006284.06.1ECFF6A Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf02.hostedemail.com (Postfix) with ESMTP id 7D0E08000E for ; Tue, 3 Sep 2024 23:23:40 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=JWnQoH6O; spf=pass (imf02.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725405745; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6B0tKbUVx2G5pw+r7fZGx9eSPo2EK+YI2lXoEXcda9U=; b=bKY/4DZW3tgiv0L8gAHpisZbUc4wpW7j8qZZrFY27M7ef722bJNrIqmw7snlFqfxIBMJEM G2XOKUKEqlyXZdlyp4xK3a1G7MZN5QVTrWVyanKlMp4ovTVn2Actkx6eb7jma2c+x06iJt dJOAoZB/iIpGwtOVVCsFhiEyRoSqq9Q= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=JWnQoH6O; spf=pass (imf02.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725405745; a=rsa-sha256; cv=none; b=Bf86jvqUBfwMY9DWa33uoz/WNdHcv+EtsiHreoWds01fXQTFwaFObjB3rFJqmu7NDTdo5D oE4YNkzjGBJRn5eUxRRz/mGsiLqDwod8RnDfa064tvD0hYgt2n5NGy1dSoDlzuMKPiazmP SRpZtivKC3U53uAFgs4N3pCv1nehG5E= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 483LBX5G019218; Tue, 3 Sep 2024 23:23:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=6 B0tKbUVx2G5pw+r7fZGx9eSPo2EK+YI2lXoEXcda9U=; b=JWnQoH6OkoRsK/s6Y pYOu63ObV4XAiFYZHrkfMbGHjP4QhBQGg+TwphKXfWvY2Z8qDsMyd9a1Jprv7IMu 8QdGSPdH6BPbLRBQNRorn7egiix4VMt88WdNf5uTfdDWdJ+T0orhKeqIPV/Ef8vk rcl9DsghKzUObYBJFv6YMrba7G1L6Vz67A1sPXps7pQ0F4WOZuPk53C4RWkyQi9S iPLGth4Q49ly5FIicWwRDuldjaT9lkRygrHyUOBa9HybefSgesYdwsVrDWN7GC6F VcaJ8Mhtr9wkZZl6NIWrp3cKvjLHANz5oEbA9ClYXCKd+Sj3lYTcAGdTITuF+F5u 8d5oQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dw51t434-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:25 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483NAKBu001869; Tue, 3 Sep 2024 23:23:24 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmnad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:24 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfC040456; Tue, 3 Sep 2024 23:23:23 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-4; Tue, 03 Sep 2024 23:23:23 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 03/10] mm/mshare: make msharefs writable and support directories Date: Tue, 3 Sep 2024 16:22:34 -0700 Message-ID: <20240903232241.43995-4-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=670 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-ORIG-GUID: dkXLeEH9FYZojdDG1RlpfQIloPnwy2Wb X-Proofpoint-GUID: dkXLeEH9FYZojdDG1RlpfQIloPnwy2Wb X-Stat-Signature: h7o5o73dfrxh51r3einnija97bdo71am X-Rspam-User: X-Rspamd-Queue-Id: 7D0E08000E X-Rspamd-Server: rspam02 X-HE-Tag: 1725405820-121058 X-HE-Meta: U2FsdGVkX1/xo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myzIdhkOjVgvUuhrhsxcTjDyiVyUlB7H3b0hAvQP+lDiELeu5tD6WfVayJ7PgVmNUtSn7axLEAEQ64NtgE5298BkHUks6aLARcxEsooDgbNm4TJM9OCVYjeKfksXeOS3eq3o413xs/JvEGvKRAx+OyR8UWuSHui5vdAe47fwY9dzGcUTSFHVQ0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Khalid Aziz Make msharefs filesystem writable and allow creating directories to support better access control to mshare'd regions defined in msharefs. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/mm/mshare.c b/mm/mshare.c index 6562000545e1..f718b8934cdf 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -21,11 +21,126 @@ struct msharefs_info { struct dentry *info_dentry; }; +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, .llseek = no_llseek, }; +static struct inode +*msharefs_get_inode(struct mnt_idmap *idmap, struct super_block *sb, + const struct inode *dir, umode_t mode) +{ + struct inode *inode = new_inode(sb); + + if (!inode) + return ERR_PTR(-ENOMEM); + + inode->i_ino = get_next_ino(); + inode_init_owner(&nop_mnt_idmap, inode, dir, mode); + simple_inode_init_ts(inode); + + switch (mode & S_IFMT) { + case S_IFREG: + inode->i_op = &msharefs_file_inode_ops; + inode->i_fop = &msharefs_file_operations; + break; + case S_IFDIR: + inode->i_op = &msharefs_dir_inode_ops; + inode->i_fop = &simple_dir_operations; + inc_nlink(inode); + break; + default: + discard_new_inode(inode); + return ERR_PTR(-EINVAL); + } + + return inode; +} + +static int +msharefs_mknod(struct mnt_idmap *idmap, struct inode *dir, + struct dentry *dentry, umode_t mode) +{ + struct inode *inode; + + inode = msharefs_get_inode(idmap, dir->i_sb, dir, mode); + if (IS_ERR(inode)) + return PTR_ERR(inode); + + d_instantiate(dentry, inode); + dget(dentry); + inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); + + return 0; +} + +static int +msharefs_create(struct mnt_idmap *idmap, struct inode *dir, + struct dentry *dentry, umode_t mode, bool excl) +{ + return msharefs_mknod(idmap, dir, dentry, mode | S_IFREG); +} + +static int +msharefs_mkdir(struct mnt_idmap *idmap, struct inode *dir, + struct dentry *dentry, umode_t mode) +{ + int ret = msharefs_mknod(idmap, dir, dentry, mode | S_IFDIR); + + if (!ret) + inc_nlink(dir); + return ret; +} + +static inline bool +is_msharefs_info_file(const struct dentry *dentry) +{ + struct msharefs_info *info = dentry->d_sb->s_fs_info; + + return info->info_dentry == dentry; +} + +static int +msharefs_rename(struct mnt_idmap *idmap, + struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) +{ + if (is_msharefs_info_file(old_dentry) || + is_msharefs_info_file(new_dentry)) + return -EPERM; + + return simple_rename(idmap, old_dir, old_dentry, new_dir, + new_dentry, flags); +} + +static int +msharefs_unlink(struct inode *dir, struct dentry *dentry) +{ + if (is_msharefs_info_file(dentry)) + return -EPERM; + + return simple_unlink(dir, dentry); +} + +static const struct inode_operations msharefs_file_inode_ops = { + .setattr = simple_setattr, + .getattr = simple_getattr, +}; + +static const struct inode_operations msharefs_dir_inode_ops = { + .create = msharefs_create, + .lookup = simple_lookup, + .link = simple_link, + .unlink = msharefs_unlink, + .mkdir = msharefs_mkdir, + .rmdir = simple_rmdir, + .rename = msharefs_rename, +}; + static ssize_t mshare_info_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) @@ -104,7 +219,7 @@ msharefs_fill_super(struct super_block *sb, struct fs_context *fc) inode->i_ino = 1; inode->i_mode = S_IFDIR | 0777; simple_inode_init_ts(inode); - inode->i_op = &simple_dir_inode_operations; + inode->i_op = &msharefs_dir_inode_ops; inode->i_fop = &simple_dir_operations; set_nlink(inode, 2);