From patchwork Fri Jan 24 23:54:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950023 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 24355C02181 for ; Fri, 24 Jan 2025 23:55:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FC4A2800A8; Fri, 24 Jan 2025 18:55:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0ABA32800AE; Fri, 24 Jan 2025 18:55:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB5792800A8; Fri, 24 Jan 2025 18:55:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BF1B12800AE for ; Fri, 24 Jan 2025 18:55:34 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 67C06121961 for ; Fri, 24 Jan 2025 23:55:34 +0000 (UTC) X-FDA: 83044004988.06.4806661 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf19.hostedemail.com (Postfix) with ESMTP id 488621A0006 for ; Fri, 24 Jan 2025 23:55:32 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=afhvDSIm; spf=pass (imf19.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=1737762932; 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=nqagYyeBhaL2RlbKKTLc6lxU3rvGauZsyUuzovUQ98I=; b=t5ixm01GC2TCaEMgxZYbaqpz/GQo6Byp/55n7qwMZQXtQzaktADfbb6lp+tjr0c5cxFROu SNT75/HAznDFMspM+s0zhpMFDMWVtK0PJO4s2QaaLNBV36dK6MTSUeNAMvqx94r6IIwmsF d2KUGCUoHFvjRFH8G4BEX7H3Mkf8RWI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737762932; a=rsa-sha256; cv=none; b=bZidU5HZlpJSVmdtvd2qfHGWZvjjoOQvmRz5IQ6EalzFe4ex1tg4a0f+Hf3h9m/tjvCCo7 X1U7p8ulnud1A+y4xwVjMKRpQL3N54pIXUymOPP2/0YzVh8RBhrU4af6C+mRzgeTPiG4iu cIWn2ioYOPu/vp6H0q45AQEfolM9I0Y= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=afhvDSIm; spf=pass (imf19.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 Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50OIRdZF000609; Fri, 24 Jan 2025 23:55:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2023-11-20; bh=nqagY yeBhaL2RlbKKTLc6lxU3rvGauZsyUuzovUQ98I=; b=afhvDSImLqAMVCsYQmNcG ariAxBqtOlnnMHGzw4+P9TuWi+BLYUBCKMY/F/pj5x5FO7305VUzzvylCnuwmP4B hhYHZynes5p/hwSoIKvX5ccNh78E9B6di+gQeN+eIe16U3Df3EiBZIxNruSiHRU1 SJ50wwpE0RCkh3J6hYADyKFwjnQbcBOZwctnm2XyerXnxLsMg1bRN4OGjrNW+imS 2mYM2mcM+4MR+bLIYKhWG2LvVwU9fbAiSjcoxgT8/1PTvpcKSwoyu2z+mjgfJzs6 mVUJ4aXylk0CMjxwTAbeXUPl4y5yw2BzkPNJ2p8eCfMQMM1C7R1iqiPhQIjQHyEG w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44b06j5j3u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:14 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OLP7ek036648; Fri, 24 Jan 2025 23:55:14 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4a6c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:14 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxPm018051; Fri, 24 Jan 2025 23:55:13 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-4; Fri, 24 Jan 2025 23:55:12 +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, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, 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: [PATCH 03/20] mm/mshare: make msharefs writable and support directories Date: Fri, 24 Jan 2025 15:54:37 -0800 Message-ID: <20250124235454.84587-4-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=781 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: q87c7Eu1K_1GSRczZ328BcrLzGhppaPX X-Proofpoint-GUID: q87c7Eu1K_1GSRczZ328BcrLzGhppaPX X-Stat-Signature: ingqy84bs8ajippf7qawfjax7xpo9yan X-Rspam-User: X-Rspamd-Queue-Id: 488621A0006 X-Rspamd-Server: rspam03 X-HE-Tag: 1737762932-947245 X-HE-Meta: U2FsdGVkX18/2toI/gbM7WtemuspGUBJYGMshq0g/TOw4p1EMaDVFb0XVykMHTQSPdVcbwtGwW8vSxDCMwK2OcyH4wN9pHVV+wK8zFQnzvs1C47l5VidcDqKX5ECvUj5iZt809gcr2IrRkdTuKxt2fk4ILFRQRDV22c2djj8Kr2huuJb0KOSU/8sFQN52OwbdIDs+SVtYMG3MQiZ3e7heLpYFREW1OcxAByRKw495btJ64Z98C35hpIH8cz0SeAUKF14vcJK2aC7nkm/vOuJZtdeTdWpOOrPANKQsVipBaNq9/Ki1WCs/a2382SfAUE2HsGDmrwKmH8T301R/7OOpRc2V+6MDFwdBRAJ0q1XcExqRZdLRUF5iCCMoYBbK8ZCHwSUtFh0jGyWTnEKknHp4PPMFFbCKI22NhtsPjzKHqR4zHPrEp+yu9jirRAfGhZuzlfhkNTzDkJrzXtQX7NOVDnVKEK72Lkgy9vAx06QfsX4aZB83RuTgHILY57DfDi+Kg8lb2YRv/eGZvyNcna+g+ZCy1kMnLdo7Ebr13R0KEoGBnIVGNG7KIvueMKFpN/eqANlX1TLwzoq1e67QKYU37O0s2cgQ2r6DJu/fHOrVqQe/R5Lflb66vbCrVVx1WP27R0CYsN7t0BcqMBYqWP4YwEfepOF0bJrIQ98UHmnoOcmBQOm6DBD/D4Jy0mOEOh5fsawC+jZk0k9EiN3fuyyCrHNi2QPBK6lENufwrlD7XK9hw8cW6TYCj02h7gQk9KyAvTry1wasISXtVuMAjA1TEgzLihQVs6ryGEAA7CLBtZikAz+VqNqt22yqDiroyaE4fTpdxxuoA3DB/CHLBghRCVgSjhz5SAlbOscnjZ5gzQn4FJF9SubVp3z9wmqAptMVM5mnh+6lK3v2dX5qXPKoljaJQk1wiK2fWU/2zbqbzO/29cjon1EiDkfTLDBI00erIi+y7Z5/41dC8AG2Ku iz2Q/kui tWbryqTKFiMOTR3tRu2cl2s8DjVy+P2mEu1bboEsihBwMbJ/KTV2etGwfkvj17Jf+RA9AVYcoQvGnKQ+Itn8yndsUckn6Vw8R3IkoTCJEX/q+4xChSfbkIgmZ6BkIUvXMz3UaE8Sj9/db4+KzKaU/z5NEqtE/3wg3AGkcpG2VAMc6xBQ9W2XFKziVrfpiCEgpi7Nql1hMHYWhSNhzzvZinJLWQFtgho4T9ZoppeOCjtVaKWbYjMGdicAv8oqxFPbBmhWT 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 6d3760d1af8e..b755346da827 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -19,14 +19,129 @@ const unsigned long mshare_align = P4D_SIZE; +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, }; +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; +} + struct msharefs_info { struct dentry *info_dentry; }; +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) @@ -105,7 +220,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);