From mboxrd@z Thu Jan 1 00:00:00 1970 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 E44F4CCA47B for ; Thu, 30 Jun 2022 23:10:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 565AF8E0002; Thu, 30 Jun 2022 19:10:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EEB18E0001; Thu, 30 Jun 2022 19:10:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38F248E0002; Thu, 30 Jun 2022 19:10:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2444D8E0001 for ; Thu, 30 Jun 2022 19:10:37 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EC33721554 for ; Thu, 30 Jun 2022 23:10:36 +0000 (UTC) X-FDA: 79636448472.12.3F7B7B0 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) by imf04.hostedemail.com (Postfix) with ESMTP id 8991C40045 for ; Thu, 30 Jun 2022 23:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=PLnX+GdiFq0h5m7XxJGkEoRQcXwyc8nFGHPUn3RIA68=; b=DONAnasQ0yvPgsBJkOz9zo+fop 6HB95NCmxtbegAsvEMNEF/V90e76fDOkTxUK9lwlhAMa395kOpj33EYQqt3LVUiMdgebzjU8V3IfT kZD469AenC21vxxaaes2+2vhbayHa2Fq6Yuh3V1rS6GO0QdOvYc/SsGHHrDMsfxsTEScwXTDD3Epj rAL8mIesWjBOzYo5IF6JzwznaT4wqiNo0lRD3qYwYzrwUMiKLcOoc51vkCmo4sD2hteg7k9rqa3XI l3V8DefBid9ZOHUMLCllhBcb7pAycMYEXUOb+Ll5xs1q1AoMwx5VXgoO9AO+wHNaBKZU42Y7BmQYT dkdQB6rQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1o73I3-006iv9-RN; Thu, 30 Jun 2022 23:09:40 +0000 Date: Fri, 1 Jul 2022 00:09:39 +0100 From: Al Viro To: Khalid Aziz Cc: akpm@linux-foundation.org, willy@infradead.org, aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: Re: [PATCH v2 3/9] mm/mshare: make msharefs writable and support directories Message-ID: References: <397ad80630444b90877625a1e94dd81392fc678e.1656531090.git.khalid.aziz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <397ad80630444b90877625a1e94dd81392fc678e.1656531090.git.khalid.aziz@oracle.com> ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.org.uk header.s=zeniv-20220401 header.b=DONAnasQ; dmarc=pass (policy=none) header.from=zeniv.linux.org.uk; spf=none (imf04.hostedemail.com: domain of viro@ftp.linux.org.uk has no SPF policy when checking 62.89.141.173) smtp.mailfrom=viro@ftp.linux.org.uk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656630636; a=rsa-sha256; cv=none; b=Rx7CIW+dqyNYp6Ig0ijsoI3MrZwK/0lZJTQwyeqKZHwilIARXCmRAx36bVgRLY22WVC7r3 A3QD6HRL8JbMXVM3z7znRA0lMr9WFuWJcD/ujwWAERc1xQYFdJZZlP8LsxeUSqAGRKxMoV Iu3EWCg0UNI0TQ/T3cykH7CBNV5wUbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656630636; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PLnX+GdiFq0h5m7XxJGkEoRQcXwyc8nFGHPUn3RIA68=; b=Qhrfbuy4q2O+PL27p/gzDBKs9AFKMDdRz21dODktK6V3tTI7kHih+ndqWXq5iWe2Y7fZsC UXotHOAs2PR0zuLwoAyJre/Pty7HWmBbfe46ygrUYC1Q+zb2Jogksl35IXxBSBhGd0BWBP 2tJ+wYYulykt+ybYdhC+1s+D6R22DVA= X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.org.uk header.s=zeniv-20220401 header.b=DONAnasQ; dmarc=pass (policy=none) header.from=zeniv.linux.org.uk; spf=none (imf04.hostedemail.com: domain of viro@ftp.linux.org.uk has no SPF policy when checking 62.89.141.173) smtp.mailfrom=viro@ftp.linux.org.uk X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8991C40045 X-Stat-Signature: 5xts7cfirf6uyneaf8fdh74h5mo9othd X-HE-Tag: 1656630636-380650 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: On Wed, Jun 29, 2022 at 04:53:54PM -0600, Khalid Aziz wrote: > +static int > +msharefs_open(struct inode *inode, struct file *file) > +{ > + return simple_open(inode, file); > +} Again, whatever for? > +static struct dentry > +*msharefs_alloc_dentry(struct dentry *parent, const char *name) > +{ > + struct dentry *d; > + struct qstr q; > + int err; > + > + q.name = name; > + q.len = strlen(name); > + > + err = msharefs_d_hash(parent, &q); > + if (err) > + return ERR_PTR(err); > + > + d = d_alloc(parent, &q); > + if (d) > + return d; > + > + return ERR_PTR(-ENOMEM); > +} And it's different from d_alloc_name() how, exactly? > + case S_IFLNK: > + inode->i_op = &page_symlink_inode_operations; > + break; Really? You've got symlinks here? > + default: > + discard_new_inode(inode); > + inode = NULL; That's an odd way to spell BUG()... > +static int > +msharefs_mknod(struct user_namespace *mnt_userns, struct inode *dir, > + struct dentry *dentry, umode_t mode, dev_t dev) > +{ > + struct inode *inode; > + int err = 0; > + > + inode = msharefs_get_inode(dir->i_sb, dir, mode); > + if (IS_ERR(inode)) > + return PTR_ERR(inode); > + > + d_instantiate(dentry, inode); > + dget(dentry); > + dir->i_mtime = dir->i_ctime = current_time(dir); > + > + return err; > +} BTW, what's the point of having device nodes on that thing? > +static int > +msharefs_create(struct user_namespace *mnt_userns, struct inode *dir, > + struct dentry *dentry, umode_t mode, bool excl) > +{ > + return msharefs_mknod(&init_user_ns, dir, dentry, mode | S_IFREG, 0); > +} > + > +static int > +msharefs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, > + struct dentry *dentry, umode_t mode) > +{ > + int ret = msharefs_mknod(&init_user_ns, dir, dentry, mode | S_IFDIR, 0); > + > + if (!ret) > + inc_nlink(dir); > + return ret; > +} > + > +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 = simple_unlink, > + .mkdir = msharefs_mkdir, > + .rmdir = simple_rmdir, > + .mknod = msharefs_mknod, > + .rename = simple_rename, > +}; > + > static void > mshare_evict_inode(struct inode *inode) > { > @@ -58,7 +175,7 @@ mshare_info_read(struct file *file, char __user *buf, size_t nbytes, > { > char s[80]; > > - sprintf(s, "%ld", PGDIR_SIZE); > + sprintf(s, "%ld\n", PGDIR_SIZE); > return simple_read_from_buffer(buf, nbytes, ppos, s, strlen(s)); > } > > @@ -72,6 +189,38 @@ static const struct super_operations mshare_s_ops = { > .evict_inode = mshare_evict_inode, > }; > > +static int > +prepopulate_files(struct super_block *s, struct inode *dir, > + struct dentry *root, const struct tree_descr *files) > +{ > + int i; > + struct inode *inode; > + struct dentry *dentry; > + > + for (i = 0; !files->name || files->name[0]; i++, files++) { > + if (!files->name) > + continue; > + > + dentry = msharefs_alloc_dentry(root, files->name); > + if (!dentry) > + return -ENOMEM; > + > + inode = msharefs_get_inode(s, dir, S_IFREG | files->mode); > + if (!inode) { > + dput(dentry); > + return -ENOMEM; > + } > + inode->i_mode = S_IFREG | files->mode; > + inode->i_atime = inode->i_mtime = inode->i_ctime > + = current_time(inode); > + inode->i_fop = files->ops; > + inode->i_ino = i; > + d_add(dentry, inode); > + } > + > + return 0; > +} Looks remarkably similar to something I've seen somewhere... fs/libfs.c, if I'm not mistaken... Sarcasm aside, what's wrong with using simple_fill_super()?