From patchwork Tue Apr 21 13:51:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 11501463 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2DE41913 for ; Tue, 21 Apr 2020 13:52:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15B53206D5 for ; Tue, 21 Apr 2020 13:52:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HfUMLZrT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729119AbgDUNws (ORCPT ); Tue, 21 Apr 2020 09:52:48 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:53147 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726018AbgDUNwr (ORCPT ); Tue, 21 Apr 2020 09:52:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587477166; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ctzOqm9dtwbhRf44FvKp72RdNODJeokpu4mABLVWWLc=; b=HfUMLZrTsjJZ5MTWakU6Ip/201mGT2WMl9QcFjlTe7A6HddnNMDK6nP8DbQiHilQZFLO7H MSr0IMDYxDVsPl6FsG8MICACavx314Be1Z0M4Z4mTVXsAQOSCIbIvuQqXqCqpDp+m0khtM MNs339MOGa196tWdeqdCnYlgi6Q5iow= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-411-cxI5wA78NOecVC8zStXncg-1; Tue, 21 Apr 2020 09:52:43 -0400 X-MC-Unique: cxI5wA78NOecVC8zStXncg-1 Received: by mail-wm1-f72.google.com with SMTP id b203so1392314wmd.6 for ; Tue, 21 Apr 2020 06:52:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ctzOqm9dtwbhRf44FvKp72RdNODJeokpu4mABLVWWLc=; b=HN35cKR7mvp9R60ir5cRj329xIi/H/mBOqsoYgdSrKe/hyU0jQm9vyD1tn3+EQ7l1u nAxW+5WuDckwnZXFZ/sVV+5dpcYFc9KNG7/mv8SUgkz/pY4TAf1ckxHakGeEwArMKE3f F1z/q3oJoIB3YGSWsCohnT9LJgLE38+vMZtx8DDiNshIGrdNZiKKvWfu9Kz8g1lKt1la X+ukSiGqQqDBUgmn6WkXxxKLU/6MKIMHaRyOlCcFVy+qRjKPkhA2+ndHDPtm9FxSpyXt fFU4ejx2FFfFkrokEgAuzs7o4a2IoHDS3m43z9Zy39ib4ms2klJeuWUZhkF+u18kntZZ 0gyQ== X-Gm-Message-State: AGi0PubS3oVYw7gCZP15XZ4bJg16c4Z+LLeEA7UZO6XaUS1zzM9Iktlb tr8Il2iC0vtBCg6YrKnm9H88+iDAoVkewqKJ0hOk0N7AdHIwS+Hes9pTba8/jK63OQf6t8uhW+Z YTBuuJPVDEHRz6FD3F1Xijg== X-Received: by 2002:adf:fd0a:: with SMTP id e10mr23759627wrr.160.1587477102566; Tue, 21 Apr 2020 06:51:42 -0700 (PDT) X-Google-Smtp-Source: APiQypKYYb14rVpuN5IdJGjcztA4u7H/3dUDNtMGXdL7LsdIhh9n0qcoiv0NvYygrC3tIbBHwPH97A== X-Received: by 2002:adf:fd0a:: with SMTP id e10mr23759618wrr.160.1587477102414; Tue, 21 Apr 2020 06:51:42 -0700 (PDT) Received: from localhost.localdomain.com ([194.230.155.194]) by smtp.gmail.com with ESMTPSA id a187sm3565830wmh.40.2020.04.21.06.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 06:51:41 -0700 (PDT) From: Emanuele Giuseppe Esposito To: linux-fsdevel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , "Manoj N. Kumar" , "Matthew R. Ochs" , Uma Krishnan , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Joel Becker , Christoph Hellwig , "Rafael J. Wysocki" , John Johansen , James Morris , "Serge E. Hallyn" , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-scsi@vger.kernel.org, linux-security-module@vger.kernel.org, Paolo Bonzini , Emanuele Giuseppe Esposito Subject: [PATCH v2 1/7] apparmor: just use vfs_kern_mount to make .null Date: Tue, 21 Apr 2020 15:51:13 +0200 Message-Id: <20200421135119.30007-2-eesposit@redhat.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200421135119.30007-1-eesposit@redhat.com> References: <20200421135119.30007-1-eesposit@redhat.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org aa_mk_null_file is using simple_pin_fs/simple_release_fs with local variables as arguments, for what would amount to a simple vfs_kern_mount/mntput pair if everything was inlined. Just use the normal filesystem API since the reference counting is not needed here (it is a local variable and always 0 on entry and on exit). There is no functional change intended. Signed-off-by: Emanuele Giuseppe Esposito --- security/apparmor/apparmorfs.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 280741fc0f5f..36f848734902 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -2525,14 +2525,15 @@ struct path aa_null; static int aa_mk_null_file(struct dentry *parent) { - struct vfsmount *mount = NULL; + struct file_system_type *type = parent->d_sb->s_type; + struct vfsmount *mount; struct dentry *dentry; struct inode *inode; - int count = 0; - int error = simple_pin_fs(parent->d_sb->s_type, &mount, &count); + int error; - if (error) - return error; + mount = vfs_kern_mount(type, SB_KERNMOUNT, type->name, NULL); + if (IS_ERR(mount)) + return PTR_ERR(mount); inode_lock(d_inode(parent)); dentry = lookup_one_len(NULL_FILE_NAME, parent, strlen(NULL_FILE_NAME)); @@ -2561,7 +2562,7 @@ static int aa_mk_null_file(struct dentry *parent) dput(dentry); out: inode_unlock(d_inode(parent)); - simple_release_fs(&mount, &count); + mntput(mount); return error; } From patchwork Tue Apr 21 13:51:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 11501455 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F378B159A for ; Tue, 21 Apr 2020 13:51:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6FFF20672 for ; Tue, 21 Apr 2020 13:51:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cFlf1wk3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729013AbgDUNvx (ORCPT ); Tue, 21 Apr 2020 09:51:53 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:25625 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728960AbgDUNvv (ORCPT ); Tue, 21 Apr 2020 09:51:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587477108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uEO79FtubqXMahKIwTgMnvnxLKfl/MCXROyTj0OBoJ0=; b=cFlf1wk3mHxGIK9aPltEPgx+iSvPWLzyyikPicwZd265BNTphrRRU7JTBqtVuBsMjFtmH5 tZ3BYpNr4zV9DqhSmbBty9YjvUxO3h8cEEGKKZS/vIQglFsHzNlg+LCO+XVRv56wNKeY+Z P8DCbtykkLvGpvDOEMR3IS6IquS22fY= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-261-bmuOdxY0M4SWn4WsAGMo1w-1; Tue, 21 Apr 2020 09:51:46 -0400 X-MC-Unique: bmuOdxY0M4SWn4WsAGMo1w-1 Received: by mail-wm1-f70.google.com with SMTP id l21so1483683wmh.2 for ; Tue, 21 Apr 2020 06:51:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uEO79FtubqXMahKIwTgMnvnxLKfl/MCXROyTj0OBoJ0=; b=gKzrVdMzqKKVrEL/wcs2ZfjYqkpM05F8NpGaqKCaOjXmPLiPeSDh2tjzgEJolED9un OV5PG6+WPkJpRfIJqS6WWr4Oi+mLOZfc6+RR1NlPp0V/hfMSxt5xwyVBohY0eqBOBHtE DD2uuOXjSI3BOQ8ZbDhrG+AvuJK/Sc/pQ2EijF9i6Gnzd5FlmpCaLMYRjtqZDvSP4XbA hX04J+W02xobVoDYSuHEpXPWJJEZxiExDmTLVcKAekPnfJfkHqoyuShgpFHuD7Jsccct i6xFyzITSFLdneNY89YonCZ/yt3/TndXfkL/DE/hCZHqplxju7gEIJVvMXlBrdawTySn dntQ== X-Gm-Message-State: AGi0PubTNT4jZhZ7yhhFUwZAWMm9dZHCDDRpk/b6gW9fgkfAnFjsuZ+x 1w6XqWWttaJEPVlstdBQByJF43npmr8CnnBUVNyt8nO2n9ZEUe0tWxSOt+SEKz3FV7poP1pimkD CSOEAa2y1KPmYWKy3jTaJrQ== X-Received: by 2002:a05:6000:114b:: with SMTP id d11mr11202369wrx.138.1587477104838; Tue, 21 Apr 2020 06:51:44 -0700 (PDT) X-Google-Smtp-Source: APiQypJsZggx2G3tX02r+CIpkhG0GKbStWvZ8dzSX+QBPAQPkgkEDhh7nt3yzU3c0QsyRLr3LyQW5w== X-Received: by 2002:a05:6000:114b:: with SMTP id d11mr11202330wrx.138.1587477104368; Tue, 21 Apr 2020 06:51:44 -0700 (PDT) Received: from localhost.localdomain.com ([194.230.155.194]) by smtp.gmail.com with ESMTPSA id a187sm3565830wmh.40.2020.04.21.06.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 06:51:43 -0700 (PDT) From: Emanuele Giuseppe Esposito To: linux-fsdevel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , "Manoj N. Kumar" , "Matthew R. Ochs" , Uma Krishnan , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Joel Becker , Christoph Hellwig , "Rafael J. Wysocki" , John Johansen , James Morris , "Serge E. Hallyn" , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-scsi@vger.kernel.org, linux-security-module@vger.kernel.org, Paolo Bonzini , Emanuele Giuseppe Esposito Subject: [PATCH v2 2/7] libfs: wrap simple_pin_fs/simple_release_fs arguments in a struct Date: Tue, 21 Apr 2020 15:51:14 +0200 Message-Id: <20200421135119.30007-3-eesposit@redhat.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200421135119.30007-1-eesposit@redhat.com> References: <20200421135119.30007-1-eesposit@redhat.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Simplify passing the count and mount to simple_pin_fs and simple_release_fs by wrapping them in the simple_fs struct, in preparation for adding more high level operations to fs/libfs.c There is no functional change intended. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: James Morris --- drivers/gpu/drm/drm_drv.c | 11 ++++---- drivers/misc/cxl/api.c | 13 +++++----- drivers/scsi/cxlflash/ocxl_hw.c | 14 +++++----- fs/binfmt_misc.c | 9 +++---- fs/configfs/mount.c | 10 +++----- fs/debugfs/inode.c | 22 ++++++++-------- fs/libfs.c | 45 +++++++++++++++++++++++++-------- fs/tracefs/inode.c | 18 ++++++------- include/linux/fs.h | 10 ++++++-- security/apparmor/apparmorfs.c | 25 +++++++++--------- security/inode.c | 11 ++++---- 11 files changed, 103 insertions(+), 85 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 7b1a628d1f6e..e29424d64874 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -514,8 +514,7 @@ EXPORT_SYMBOL(drm_dev_unplug); * iput(), but this way you'd end up with a new vfsmount for each inode. */ -static int drm_fs_cnt; -static struct vfsmount *drm_fs_mnt; +static struct simple_fs drm_fs; static int drm_fs_init_fs_context(struct fs_context *fc) { @@ -534,15 +533,15 @@ static struct inode *drm_fs_inode_new(void) struct inode *inode; int r; - r = simple_pin_fs(&drm_fs_type, &drm_fs_mnt, &drm_fs_cnt); + r = simple_pin_fs(&drm_fs, &drm_fs_type); if (r < 0) { DRM_ERROR("Cannot mount pseudo fs: %d\n", r); return ERR_PTR(r); } - inode = alloc_anon_inode(drm_fs_mnt->mnt_sb); + inode = alloc_anon_inode(drm_fs.mount->mnt_sb); if (IS_ERR(inode)) - simple_release_fs(&drm_fs_mnt, &drm_fs_cnt); + simple_release_fs(&drm_fs); return inode; } @@ -551,7 +550,7 @@ static void drm_fs_inode_free(struct inode *inode) { if (inode) { iput(inode); - simple_release_fs(&drm_fs_mnt, &drm_fs_cnt); + simple_release_fs(&drm_fs); } } diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c index b493de962153..67e4808bce49 100644 --- a/drivers/misc/cxl/api.c +++ b/drivers/misc/cxl/api.c @@ -31,8 +31,7 @@ #define CXL_PSEUDO_FS_MAGIC 0x1697697f -static int cxl_fs_cnt; -static struct vfsmount *cxl_vfs_mount; +static struct simple_fs cxl_fs; static int cxl_fs_init_fs_context(struct fs_context *fc) { @@ -50,7 +49,7 @@ static struct file_system_type cxl_fs_type = { void cxl_release_mapping(struct cxl_context *ctx) { if (ctx->kernelapi && ctx->mapping) - simple_release_fs(&cxl_vfs_mount, &cxl_fs_cnt); + simple_release_fs(&cxl_fs); } static struct file *cxl_getfile(const char *name, @@ -66,20 +65,20 @@ static struct file *cxl_getfile(const char *name, if (fops->owner && !try_module_get(fops->owner)) return ERR_PTR(-ENOENT); - rc = simple_pin_fs(&cxl_fs_type, &cxl_vfs_mount, &cxl_fs_cnt); + rc = simple_pin_fs(&cxl_fs, &cxl_fs_type); if (rc < 0) { pr_err("Cannot mount cxl pseudo filesystem: %d\n", rc); file = ERR_PTR(rc); goto err_module; } - inode = alloc_anon_inode(cxl_vfs_mount->mnt_sb); + inode = alloc_anon_inode(cxl_fs.mount->mnt_sb); if (IS_ERR(inode)) { file = ERR_CAST(inode); goto err_fs; } - file = alloc_file_pseudo(inode, cxl_vfs_mount, name, + file = alloc_file_pseudo(inode, cxl_fs.mount, name, flags & (O_ACCMODE | O_NONBLOCK), fops); if (IS_ERR(file)) goto err_inode; @@ -91,7 +90,7 @@ static struct file *cxl_getfile(const char *name, err_inode: iput(inode); err_fs: - simple_release_fs(&cxl_vfs_mount, &cxl_fs_cnt); + simple_release_fs(&cxl_fs); err_module: module_put(fops->owner); return file; diff --git a/drivers/scsi/cxlflash/ocxl_hw.c b/drivers/scsi/cxlflash/ocxl_hw.c index 7018cd802569..7fa98dd4fa28 100644 --- a/drivers/scsi/cxlflash/ocxl_hw.c +++ b/drivers/scsi/cxlflash/ocxl_hw.c @@ -29,8 +29,7 @@ #define OCXLFLASH_FS_MAGIC 0x1697698f -static int ocxlflash_fs_cnt; -static struct vfsmount *ocxlflash_vfs_mount; +static struct simple_fs ocxlflash_fs; static int ocxlflash_fs_init_fs_context(struct fs_context *fc) { @@ -51,7 +50,7 @@ static struct file_system_type ocxlflash_fs_type = { static void ocxlflash_release_mapping(struct ocxlflash_context *ctx) { if (ctx->mapping) - simple_release_fs(&ocxlflash_vfs_mount, &ocxlflash_fs_cnt); + simple_release_fs(&ocxlflash_fs); ctx->mapping = NULL; } @@ -79,15 +78,14 @@ static struct file *ocxlflash_getfile(struct device *dev, const char *name, goto err1; } - rc = simple_pin_fs(&ocxlflash_fs_type, &ocxlflash_vfs_mount, - &ocxlflash_fs_cnt); + rc = simple_pin_fs(&ocxlflash_fs, &ocxlflash_fs_type); if (unlikely(rc < 0)) { dev_err(dev, "%s: Cannot mount ocxlflash pseudofs rc=%d\n", __func__, rc); goto err2; } - inode = alloc_anon_inode(ocxlflash_vfs_mount->mnt_sb); + inode = alloc_anon_inode(ocxlflash_fs.mount->mnt_sb); if (IS_ERR(inode)) { rc = PTR_ERR(inode); dev_err(dev, "%s: alloc_anon_inode failed rc=%d\n", @@ -95,7 +93,7 @@ static struct file *ocxlflash_getfile(struct device *dev, const char *name, goto err3; } - file = alloc_file_pseudo(inode, ocxlflash_vfs_mount, name, + file = alloc_file_pseudo(inode, ocxlflash_fs.mount, name, flags & (O_ACCMODE | O_NONBLOCK), fops); if (IS_ERR(file)) { rc = PTR_ERR(file); @@ -110,7 +108,7 @@ static struct file *ocxlflash_getfile(struct device *dev, const char *name, err4: iput(inode); err3: - simple_release_fs(&ocxlflash_vfs_mount, &ocxlflash_fs_cnt); + simple_release_fs(&ocxlflash_fs); err2: module_put(fops->owner); err1: diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c index cdb45829354d..3cff446f222b 100644 --- a/fs/binfmt_misc.c +++ b/fs/binfmt_misc.c @@ -64,8 +64,7 @@ typedef struct { static DEFINE_RWLOCK(entries_lock); static struct file_system_type bm_fs_type; -static struct vfsmount *bm_mnt; -static int entry_count; +static struct simple_fs bm_fs; /* * Max length of the register string. Determined by: @@ -623,7 +622,7 @@ static void kill_node(Node *e) drop_nlink(d_inode(dentry)); d_drop(dentry); dput(dentry); - simple_release_fs(&bm_mnt, &entry_count); + simple_release_fs(&bm_fs); } /* / */ @@ -718,7 +717,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer, if (!inode) goto out2; - err = simple_pin_fs(&bm_fs_type, &bm_mnt, &entry_count); + err = simple_pin_fs(&bm_fs, &bm_fs_type); if (err) { iput(inode); inode = NULL; @@ -732,7 +731,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer, if (IS_ERR(f)) { err = PTR_ERR(f); pr_notice("register: failed to install interpreter file %s\n", e->interpreter); - simple_release_fs(&bm_mnt, &entry_count); + simple_release_fs(&bm_fs); iput(inode); inode = NULL; goto out2; diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c index 0c6e8cf61953..9fb2791e5eed 100644 --- a/fs/configfs/mount.c +++ b/fs/configfs/mount.c @@ -24,9 +24,8 @@ /* Random magic number */ #define CONFIGFS_MAGIC 0x62656570 -static struct vfsmount *configfs_mount = NULL; +static struct simple_fs configfs_fs; struct kmem_cache *configfs_dir_cachep; -static int configfs_mnt_count = 0; static void configfs_free_inode(struct inode *inode) @@ -123,14 +122,13 @@ MODULE_ALIAS_FS("configfs"); struct dentry *configfs_pin_fs(void) { - int err = simple_pin_fs(&configfs_fs_type, &configfs_mount, - &configfs_mnt_count); - return err ? ERR_PTR(err) : configfs_mount->mnt_root; + int err = simple_pin_fs(&configfs_fs, &configfs_fs_type); + return err ? ERR_PTR(err) : configfs_fs.mount->mnt_root; } void configfs_release_fs(void) { - simple_release_fs(&configfs_mount, &configfs_mnt_count); + simple_release_fs(&configfs_fs); } diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index b7f2e971ecbc..5dbb74a23e7c 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -32,8 +32,7 @@ #define DEBUGFS_DEFAULT_MODE 0700 -static struct vfsmount *debugfs_mount; -static int debugfs_mount_count; +static struct simple_fs debugfs; static bool debugfs_registered; /* @@ -297,7 +296,7 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent) return NULL; if (!parent) - parent = debugfs_mount->mnt_root; + parent = debugfs.mount->mnt_root; dentry = lookup_positive_unlocked(name, parent, strlen(name)); if (IS_ERR(dentry)) @@ -316,8 +315,7 @@ static struct dentry *start_creating(const char *name, struct dentry *parent) if (IS_ERR(parent)) return parent; - error = simple_pin_fs(&debug_fs_type, &debugfs_mount, - &debugfs_mount_count); + error = simple_pin_fs(&debugfs, &debug_fs_type); if (error) { pr_err("Unable to pin filesystem for file '%s'\n", name); return ERR_PTR(error); @@ -329,7 +327,7 @@ static struct dentry *start_creating(const char *name, struct dentry *parent) * have around. */ if (!parent) - parent = debugfs_mount->mnt_root; + parent = debugfs.mount->mnt_root; inode_lock(d_inode(parent)); if (unlikely(IS_DEADDIR(d_inode(parent)))) @@ -349,7 +347,7 @@ static struct dentry *start_creating(const char *name, struct dentry *parent) if (IS_ERR(dentry)) { inode_unlock(d_inode(parent)); - simple_release_fs(&debugfs_mount, &debugfs_mount_count); + simple_release_fs(&debugfs); } return dentry; @@ -359,7 +357,7 @@ static struct dentry *failed_creating(struct dentry *dentry) { inode_unlock(d_inode(dentry->d_parent)); dput(dentry); - simple_release_fs(&debugfs_mount, &debugfs_mount_count); + simple_release_fs(&debugfs); return ERR_PTR(-ENOMEM); } @@ -676,9 +674,9 @@ static void __debugfs_file_removed(struct dentry *dentry) static void remove_one(struct dentry *victim) { - if (d_is_reg(victim)) + if (d_is_reg(victim)) __debugfs_file_removed(victim); - simple_release_fs(&debugfs_mount, &debugfs_mount_count); + simple_release_fs(&debugfs); } /** @@ -699,9 +697,9 @@ void debugfs_remove(struct dentry *dentry) if (IS_ERR_OR_NULL(dentry)) return; - simple_pin_fs(&debug_fs_type, &debugfs_mount, &debugfs_mount_count); + simple_pin_fs(&debugfs, &debug_fs_type); simple_recursive_removal(dentry, remove_one); - simple_release_fs(&debugfs_mount, &debugfs_mount_count); + simple_release_fs(&debugfs); } EXPORT_SYMBOL_GPL(debugfs_remove); diff --git a/fs/libfs.c b/fs/libfs.c index 3759fbacf522..54e07ae986ca 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -665,39 +665,64 @@ EXPORT_SYMBOL(simple_fill_super); static DEFINE_SPINLOCK(pin_fs_lock); -int simple_pin_fs(struct file_system_type *type, struct vfsmount **mount, int *count) +/** + * simple_pin_fs - generic function to pin (mount if needed, + * otherwise add a reference to the mount) a filesystem + * @fs: a pointer to a the simple_fs struct containing a struct vfs_mount + * pointer (that can be NULL) and a counter. + * @type: a pointer to the file system type used by vfs_kern_mount. + * + * This function sets fs->mount if NULL, by calling vfs_kern_mount + * on @type. + * It also takes care of incrementing the reference counter. + * + * This function will return 0 in case of success, and PTR_ERR(-ERROR) + * if vfs_kern_mount fails. + **/ +int simple_pin_fs(struct simple_fs *fs, struct file_system_type *type) { struct vfsmount *mnt = NULL; spin_lock(&pin_fs_lock); - if (unlikely(!*mount)) { + if (unlikely(!fs->mount)) { spin_unlock(&pin_fs_lock); mnt = vfs_kern_mount(type, SB_KERNMOUNT, type->name, NULL); if (IS_ERR(mnt)) return PTR_ERR(mnt); spin_lock(&pin_fs_lock); - if (!*mount) - *mount = mnt; + if (!fs->mount) + fs->mount = mnt; } - mntget(*mount); - ++*count; + mntget(fs->mount); + ++fs->count; spin_unlock(&pin_fs_lock); mntput(mnt); return 0; } EXPORT_SYMBOL(simple_pin_fs); -void simple_release_fs(struct vfsmount **mount, int *count) +/** + * simple_release_fs - decrements the reference counter and unmounts the + * file system. + * @fs: a pointer to a struct simple_fs containing the reference counter + * and vfs_mount pointer + * + * This function decrements the refcount of the given file system and + * if 0 sets the mount pointer to NULL. + **/ +void simple_release_fs(struct simple_fs *fs) { struct vfsmount *mnt; spin_lock(&pin_fs_lock); - mnt = *mount; - if (!--*count) - *mount = NULL; + mnt = fs->mount; + if (!--fs->count) + fs->mount = NULL; spin_unlock(&pin_fs_lock); mntput(mnt); } EXPORT_SYMBOL(simple_release_fs); + + /** * simple_read_from_buffer - copy data from the buffer to user space * @to: the user space buffer to read to diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 0ee8c6dfb036..370eb38ff1ad 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -24,8 +24,7 @@ #define TRACEFS_DEFAULT_MODE 0700 -static struct vfsmount *tracefs_mount; -static int tracefs_mount_count; +static struct simple_fs tracefs; static bool tracefs_registered; static ssize_t default_read_file(struct file *file, char __user *buf, @@ -316,8 +315,7 @@ static struct dentry *start_creating(const char *name, struct dentry *parent) pr_debug("tracefs: creating file '%s'\n",name); - error = simple_pin_fs(&trace_fs_type, &tracefs_mount, - &tracefs_mount_count); + error = simple_pin_fs(&tracefs, &trace_fs_type); if (error) return ERR_PTR(error); @@ -327,7 +325,7 @@ static struct dentry *start_creating(const char *name, struct dentry *parent) * have around. */ if (!parent) - parent = tracefs_mount->mnt_root; + parent = tracefs.mount->mnt_root; inode_lock(parent->d_inode); if (unlikely(IS_DEADDIR(parent->d_inode))) @@ -341,7 +339,7 @@ static struct dentry *start_creating(const char *name, struct dentry *parent) if (IS_ERR(dentry)) { inode_unlock(parent->d_inode); - simple_release_fs(&tracefs_mount, &tracefs_mount_count); + simple_release_fs(&tracefs); } return dentry; @@ -351,7 +349,7 @@ static struct dentry *failed_creating(struct dentry *dentry) { inode_unlock(dentry->d_parent->d_inode); dput(dentry); - simple_release_fs(&tracefs_mount, &tracefs_mount_count); + simple_release_fs(&tracefs); return NULL; } @@ -504,7 +502,7 @@ __init struct dentry *tracefs_create_instance_dir(const char *name, static void remove_one(struct dentry *victim) { - simple_release_fs(&tracefs_mount, &tracefs_mount_count); + simple_release_fs(&tracefs); } /** @@ -520,9 +518,9 @@ void tracefs_remove(struct dentry *dentry) if (IS_ERR_OR_NULL(dentry)) return; - simple_pin_fs(&trace_fs_type, &tracefs_mount, &tracefs_mount_count); + simple_pin_fs(&tracefs, &trace_fs_type); simple_recursive_removal(dentry, remove_one); - simple_release_fs(&tracefs_mount, &tracefs_mount_count); + simple_release_fs(&tracefs); } /** diff --git a/include/linux/fs.h b/include/linux/fs.h index 4f6f59b4f22a..a3691c132b3a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3363,8 +3363,14 @@ struct tree_descr { const char *name; const struct file_operations *ops; int mod struct dentry *d_alloc_name(struct dentry *, const char *); extern int simple_fill_super(struct super_block *, unsigned long, const struct tree_descr *); -extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count); -extern void simple_release_fs(struct vfsmount **mount, int *count); + +struct simple_fs { + struct vfsmount *mount; + int count; +}; + +extern int simple_pin_fs(struct simple_fs *, struct file_system_type *); +extern void simple_release_fs(struct simple_fs *); extern ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos, const void *from, size_t available); diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 36f848734902..00f0158fb1e1 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -140,8 +140,7 @@ static int mangle_name(const char *name, char *target) */ #define AAFS_NAME "apparmorfs" -static struct vfsmount *aafs_mnt; -static int aafs_count; +static struct simple_fs aafs; static int aafs_show_path(struct seq_file *seq, struct dentry *dentry) @@ -273,7 +272,7 @@ static struct dentry *aafs_create(const char *name, umode_t mode, if (!(mode & S_IFMT)) mode = (mode & S_IALLUGO) | S_IFREG; - error = simple_pin_fs(&aafs_ops, &aafs_mnt, &aafs_count); + error = simple_pin_fs(&aafs, &aafs_ops); if (error) return ERR_PTR(error); @@ -303,7 +302,7 @@ static struct dentry *aafs_create(const char *name, umode_t mode, fail_lock: inode_unlock(dir); - simple_release_fs(&aafs_mnt, &aafs_count); + simple_release_fs(&aafs); return ERR_PTR(error); } @@ -395,7 +394,7 @@ static void aafs_remove(struct dentry *dentry) dput(dentry); } inode_unlock(dir); - simple_release_fs(&aafs_mnt, &aafs_count); + simple_release_fs(&aafs); } @@ -1824,7 +1823,7 @@ static int ns_mkdir_op(struct inode *dir, struct dentry *dentry, umode_t mode) * for pin_fs */ inode_unlock(dir); - error = simple_pin_fs(&aafs_ops, &aafs_mnt, &aafs_count); + error = simple_pin_fs(&aafs, &aafs_ops); mutex_lock_nested(&parent->lock, parent->level); inode_lock_nested(dir, I_MUTEX_PARENT); if (error) @@ -1845,7 +1844,7 @@ static int ns_mkdir_op(struct inode *dir, struct dentry *dentry, umode_t mode) aa_put_ns(ns); /* list ref remains */ out_pin: if (error) - simple_release_fs(&aafs_mnt, &aafs_count); + simple_release_fs(&aafs); out: mutex_unlock(&parent->lock); aa_put_ns(parent); @@ -2580,7 +2579,7 @@ static const char *policy_get_link(struct dentry *dentry, return ERR_PTR(-ECHILD); ns = aa_get_current_ns(); - path.mnt = mntget(aafs_mnt); + path.mnt = mntget(aafs.mount); path.dentry = dget(ns_dir(ns)); error = nd_jump_link(&path); aa_put_ns(ns); @@ -2631,10 +2630,10 @@ static int __init aa_create_aafs(void) } /* setup apparmorfs used to virtualize policy/ */ - aafs_mnt = kern_mount(&aafs_ops); - if (IS_ERR(aafs_mnt)) + aafs.mount = kern_mount(&aafs_ops); + if (IS_ERR(aafs.mount)) panic("can't set apparmorfs up\n"); - aafs_mnt->mnt_sb->s_flags &= ~SB_NOUSER; + aafs.mount->mnt_sb->s_flags &= ~SB_NOUSER; /* Populate fs tree. */ error = entry_create_dir(&aa_sfs_entry, NULL); @@ -2667,8 +2666,8 @@ static int __init aa_create_aafs(void) /* policy tree referenced by magic policy symlink */ mutex_lock_nested(&root_ns->lock, root_ns->level); - error = __aafs_ns_mkdir(root_ns, aafs_mnt->mnt_root, ".policy", - aafs_mnt->mnt_root); + error = __aafs_ns_mkdir(root_ns, aafs.mount->mnt_root, ".policy", + aafs.mount->mnt_root); mutex_unlock(&root_ns->lock); if (error) goto error; diff --git a/security/inode.c b/security/inode.c index 6c326939750d..8a1bee35470a 100644 --- a/security/inode.c +++ b/security/inode.c @@ -22,8 +22,7 @@ #include #include -static struct vfsmount *mount; -static int mount_count; +static struct simple_fs securityfs; static void securityfs_free_inode(struct inode *inode) { @@ -118,12 +117,12 @@ static struct dentry *securityfs_create_dentry(const char *name, umode_t mode, pr_debug("securityfs: creating file '%s'\n",name); - error = simple_pin_fs(&fs_type, &mount, &mount_count); + error = simple_pin_fs(&securityfs, &fs_type); if (error) return ERR_PTR(error); if (!parent) - parent = mount->mnt_root; + parent = securityfs.mount->mnt_root; dir = d_inode(parent); @@ -168,7 +167,7 @@ static struct dentry *securityfs_create_dentry(const char *name, umode_t mode, dentry = ERR_PTR(error); out: inode_unlock(dir); - simple_release_fs(&mount, &mount_count); + simple_release_fs(&securityfs); return dentry; } @@ -309,7 +308,7 @@ void securityfs_remove(struct dentry *dentry) dput(dentry); } inode_unlock(dir); - simple_release_fs(&mount, &mount_count); + simple_release_fs(&securityfs); } EXPORT_SYMBOL_GPL(securityfs_remove); From patchwork Tue Apr 21 13:57:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 11501527 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D93EB1575 for ; Tue, 21 Apr 2020 13:58:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1D3220738 for ; Tue, 21 Apr 2020 13:58:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Nu3trMDK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728874AbgDUN5w (ORCPT ); Tue, 21 Apr 2020 09:57:52 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:59441 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728823AbgDUN5v (ORCPT ); Tue, 21 Apr 2020 09:57:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587477469; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2wRD9FPTWKMzxCyWJGhqpm27rg8NjVNjjKx55UL7gOU=; b=Nu3trMDKQtUIanQbH665T2r5W69cir4BYnqL/P1xC+skrm/gffIT4BhTOS6jPkTl5objGj BHNhlR18NZV0trlNkBy9l6qhtEKxmvOFYCua/P+dXcGMiqOQ3PTfuhO0Has91F7QzXDDI+ 14pV7PDCkEi+3gT39hdQsaQLePqKXnc= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-58-TXVtS4iwPdOdb58yGQtRTA-1; Tue, 21 Apr 2020 09:57:47 -0400 X-MC-Unique: TXVtS4iwPdOdb58yGQtRTA-1 Received: by mail-wr1-f70.google.com with SMTP id r17so7531594wrg.19 for ; Tue, 21 Apr 2020 06:57:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2wRD9FPTWKMzxCyWJGhqpm27rg8NjVNjjKx55UL7gOU=; b=TNHc7JhTUb74gQJ+Si3Us11Tk38cAA5yyRuFfAosdMDewOLEBQLABn/b2+W73yGufR hiP/xDJabN0irkIWcFtVCv22HHPv3YQmTb4e6IiDbFMiT0OyyLGfhL3bTFnmzmvBNtKT MlhCuK0/JVWS9i9lCUjpAgz6pVV9V2IyrloDaPD1gvaScy8cai02MGuyyqpuSn6jrasi jNip0qPZ6fXD5WyGjsJ62ZdiUsfAV6kAvDuhYX3nwdhOiAGSyG6yjrmZQUrcbsM9kh5+ DHbEJLYa3fQFK2TLZHg2pkhmZNjJGJt5WqpNiFz24GhAhXXw2VUhzgVcFmOhFXTcYURe AS4w== X-Gm-Message-State: AGi0PuZgtfTrJzO4WPQDm/5m/bA09ktT9obsuEmEcaXHnPeL7iD1HKYb RTxXljmvxyaSXIgHy15DcOCEtGmbApEzOwa0tZ1/AN0gBdeG1kSyeDRsZEeG7uvhvQLVCGHSw62 J83ltzDAZ57IAt7mm+XRqvA== X-Received: by 2002:a7b:cb17:: with SMTP id u23mr4993987wmj.130.1587477466575; Tue, 21 Apr 2020 06:57:46 -0700 (PDT) X-Google-Smtp-Source: APiQypIdMbj9yLvuLA4LwwjCRX8ejEQ6n8RjZ/wI7HQOlXPSbSe/l8j+NErdfsIjBeaz5nCZl4whdg== X-Received: by 2002:a7b:cb17:: with SMTP id u23mr4993944wmj.130.1587477466378; Tue, 21 Apr 2020 06:57:46 -0700 (PDT) Received: from localhost.localdomain.com ([194.230.155.194]) by smtp.gmail.com with ESMTPSA id f23sm3562989wml.4.2020.04.21.06.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 06:57:45 -0700 (PDT) From: Emanuele Giuseppe Esposito To: linux-fsdevel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , "Manoj N. Kumar" , "Matthew R. Ochs" , Uma Krishnan , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Joel Becker , Christoph Hellwig , "Rafael J. Wysocki" , John Johansen , James Morris , "Serge E. Hallyn" , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-scsi@vger.kernel.org, linux-security-module@vger.kernel.org, Paolo Bonzini , Emanuele Giuseppe Esposito Subject: [PATCH v2 3/7] libfs: introduce new_inode_current_time Date: Tue, 21 Apr 2020 15:57:37 +0200 Message-Id: <20200421135741.30657-1-eesposit@redhat.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200421135119.30007-1-eesposit@redhat.com> References: <20200421135119.30007-1-eesposit@redhat.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org It is a common special case for new_inode to initialize the time to the current time and the inode to get_next_ino(). Introduce a core function that does it. Signed-off-by: Emanuele Giuseppe Esposito --- fs/libfs.c | 20 ++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 21 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 54e07ae986ca..3fa0cd27ab06 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -594,6 +594,26 @@ int simple_write_end(struct file *file, struct address_space *mapping, } EXPORT_SYMBOL(simple_write_end); +/** + * new_inode_current_time - create new inode by initializing the + * time to the current time and the inode to get_next_ino() + * @sb: pointer to super block of the file system + * + * Returns an inode pointer on success, NULL on failure. + */ +struct inode *new_inode_current_time(struct super_block *sb) +{ + struct inode *inode = new_inode(sb); + + if (inode) { + inode->i_ino = get_next_ino(); + inode->i_atime = inode->i_mtime = + inode->i_ctime = current_time(inode); + } + return inode; +} +EXPORT_SYMBOL(new_inode_current_time); + /* * the inodes created here are not hashed. If you use iunique to generate * unique inode values later for this filesystem, then you must take care diff --git a/include/linux/fs.h b/include/linux/fs.h index a3691c132b3a..de2577df30ae 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3088,6 +3088,7 @@ extern void clear_inode(struct inode *); extern void __destroy_inode(struct inode *); extern struct inode *new_inode_pseudo(struct super_block *sb); extern struct inode *new_inode(struct super_block *sb); +extern struct inode *new_inode_current_time(struct super_block *sb); extern void free_inode_nonrcu(struct inode *inode); extern int should_remove_suid(struct dentry *); extern int file_remove_privs(struct file *); From patchwork Tue Apr 21 13:57:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 11501519 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8AD36159A for ; Tue, 21 Apr 2020 13:58:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6EF3520738 for ; Tue, 21 Apr 2020 13:58:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PHB69R7o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729164AbgDUN6d (ORCPT ); Tue, 21 Apr 2020 09:58:33 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:21503 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728856AbgDUN5x (ORCPT ); Tue, 21 Apr 2020 09:57:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587477471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5GipQquvXdS60T0xD4t06gmL9kKohzWhQBgW2pGftGs=; b=PHB69R7o2UCiOfbBuu6Q6vcQ8xOPXNr4q/fYz6yrM+vvdF9JDDv47kZAKUBFrYm+rNzqrX lNeAhIakLVW/DXhxZsNanVNGHjId8aNKRbGM7DQLqCZo5PVnNADig8PotLoAgplV2T6C+g jvUevzVoASftwSWkQX9cjw3InM9MOMU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-aGvnX9dCN5SHGGdZ5OE0TQ-1; Tue, 21 Apr 2020 09:57:49 -0400 X-MC-Unique: aGvnX9dCN5SHGGdZ5OE0TQ-1 Received: by mail-wm1-f72.google.com with SMTP id j5so1483090wmi.4 for ; Tue, 21 Apr 2020 06:57:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5GipQquvXdS60T0xD4t06gmL9kKohzWhQBgW2pGftGs=; b=ShwJI+TJ0BIonUcW+HTDwPbjR0PVxJI96lrl8ScWSi1r6Y5IkU/qQiNSjV/5QIXmuU EkJqcR+PgebFD14yWs6DEUaLY1g46lJVyUllF79PvV8+eznUCrFcYSxam5bo6tID6T5C QsYRaeTzN/d7tJV6za4Yo18Jq+TJuKQVdoBXUGpsAqjx3MGub0PLKXYQ+/FxyxyBdQmz 449DkTbgSWLw/J+zHvCNvzhfJHzJYkTIKeq4ybFnmUFafHy/ZT6yMlIOWGIFvJjR4rv1 ZC9nYcp4uEWT5xOLtQJX4DqVTWc+HU5toBABETVw6gnOyqeLAkFGbtf+SKtfSalO63Fp qOeA== X-Gm-Message-State: AGi0PuYyLyZ+p2EVNStfxahCq9ST2TA4y3OLQdi8j8/p5n08daeWu8O3 GheidbljNrLyP3Tje291K4CymTaZfhnRSJ7W8at6DUDeiapcPL0FobbzdSH/ot3CSfO3bFbJW5e tuYG1fn0BbsqRD1OgB5xy4g== X-Received: by 2002:a05:6000:10c4:: with SMTP id b4mr3548544wrx.203.1587477468497; Tue, 21 Apr 2020 06:57:48 -0700 (PDT) X-Google-Smtp-Source: APiQypIF3TEMFKgVlkqjV5D8Ac9x2gOX23CIH+SaywYNkeLA37qXXTG9GqXHBVuGZrEE7VAAb2MwEw== X-Received: by 2002:a05:6000:10c4:: with SMTP id b4mr3548522wrx.203.1587477468324; Tue, 21 Apr 2020 06:57:48 -0700 (PDT) Received: from localhost.localdomain.com ([194.230.155.194]) by smtp.gmail.com with ESMTPSA id f23sm3562989wml.4.2020.04.21.06.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 06:57:47 -0700 (PDT) From: Emanuele Giuseppe Esposito To: linux-fsdevel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , "Manoj N. Kumar" , "Matthew R. Ochs" , Uma Krishnan , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Joel Becker , Christoph Hellwig , "Rafael J. Wysocki" , John Johansen , James Morris , "Serge E. Hallyn" , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-scsi@vger.kernel.org, linux-security-module@vger.kernel.org, Paolo Bonzini , Emanuele Giuseppe Esposito Subject: [PATCH v2 4/7] libfs: add alloc_anon_inode wrapper Date: Tue, 21 Apr 2020 15:57:38 +0200 Message-Id: <20200421135741.30657-2-eesposit@redhat.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200421135119.30007-1-eesposit@redhat.com> References: <20200421135119.30007-1-eesposit@redhat.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org libfs.c has many functions that are useful to implement dentry and inode operations, but not many at the filesystem level. Start adding file creation wrappers, the simplest returns an anonymous inode. There is no functional change intended. Signed-off-by: Emanuele Giuseppe Esposito --- drivers/gpu/drm/drm_drv.c | 2 +- drivers/misc/cxl/api.c | 2 +- drivers/scsi/cxlflash/ocxl_hw.c | 2 +- fs/libfs.c | 10 +++++++++- include/linux/fs.h | 2 ++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index e29424d64874..1854f760ad39 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -539,7 +539,7 @@ static struct inode *drm_fs_inode_new(void) return ERR_PTR(r); } - inode = alloc_anon_inode(drm_fs.mount->mnt_sb); + inode = simple_alloc_anon_inode(&drm_fs); if (IS_ERR(inode)) simple_release_fs(&drm_fs); diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c index 67e4808bce49..57672abb6223 100644 --- a/drivers/misc/cxl/api.c +++ b/drivers/misc/cxl/api.c @@ -72,7 +72,7 @@ static struct file *cxl_getfile(const char *name, goto err_module; } - inode = alloc_anon_inode(cxl_fs.mount->mnt_sb); + inode = simple_alloc_anon_inode(&cxl_fs); if (IS_ERR(inode)) { file = ERR_CAST(inode); goto err_fs; diff --git a/drivers/scsi/cxlflash/ocxl_hw.c b/drivers/scsi/cxlflash/ocxl_hw.c index 7fa98dd4fa28..0e9f2ae7eebf 100644 --- a/drivers/scsi/cxlflash/ocxl_hw.c +++ b/drivers/scsi/cxlflash/ocxl_hw.c @@ -85,7 +85,7 @@ static struct file *ocxlflash_getfile(struct device *dev, const char *name, goto err2; } - inode = alloc_anon_inode(ocxlflash_fs.mount->mnt_sb); + inode = simple_alloc_anon_inode(&ocxlflash_fs); if (IS_ERR(inode)) { rc = PTR_ERR(inode); dev_err(dev, "%s: alloc_anon_inode failed rc=%d\n", diff --git a/fs/libfs.c b/fs/libfs.c index 3fa0cd27ab06..5c76e4c648dc 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -741,7 +741,15 @@ void simple_release_fs(struct simple_fs *fs) } EXPORT_SYMBOL(simple_release_fs); - +/** + * simple_alloc_anon_inode - wrapper for alloc_anon_inode + * @fs: a pointer to a struct simple_fs containing a valid vfs_mount pointer + **/ +struct inode *simple_alloc_anon_inode(struct simple_fs *fs) +{ + return alloc_anon_inode(fs->mount->mnt_sb); +} +EXPORT_SYMBOL(simple_alloc_anon_inode); /** * simple_read_from_buffer - copy data from the buffer to user space diff --git a/include/linux/fs.h b/include/linux/fs.h index de2577df30ae..5e93de72118b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3373,6 +3373,8 @@ struct simple_fs { extern int simple_pin_fs(struct simple_fs *, struct file_system_type *); extern void simple_release_fs(struct simple_fs *); +extern struct inode *simple_alloc_anon_inode(struct simple_fs *fs); + extern ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos, const void *from, size_t available); extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, From patchwork Tue Apr 21 13:57:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 11501531 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E1DF913 for ; Tue, 21 Apr 2020 13:59:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D52CC206D9 for ; Tue, 21 Apr 2020 13:59:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SwaRhyKH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728874AbgDUN7C (ORCPT ); Tue, 21 Apr 2020 09:59:02 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:25809 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728963AbgDUN7C (ORCPT ); Tue, 21 Apr 2020 09:59:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587477533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7IIEigFH4euYLZFcVPE/gY3sCMVw531UeBsz7uQYoxI=; b=SwaRhyKHg4eKoMZt58jxKBbz9jBcAfpAA6hlL5UgNoeHncNpklb9G2d276RESUPm/DeZYh 5vxj6rdO64dLaSG5TQzpXNcY4iI21WB/2M3tYrxI+iFVNAgpceXgqfdPMbheNgXY51WVNg 3RUOU09U5glPAP/Nly1FXOSYmfueGdQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-345-Q-XvYfdxOI2SQMTV-H_kbg-1; Tue, 21 Apr 2020 09:58:51 -0400 X-MC-Unique: Q-XvYfdxOI2SQMTV-H_kbg-1 Received: by mail-wm1-f71.google.com with SMTP id u11so1399795wmc.7 for ; Tue, 21 Apr 2020 06:58:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7IIEigFH4euYLZFcVPE/gY3sCMVw531UeBsz7uQYoxI=; b=KpTMMgPCNmjFEWoIW/yWP4MwtK0eExE1Y6GVoQEo4q/FZiV7F+JI1ANbRDqUOrXnnA GfxyQmhfat9SJNgZ5vuvbJNi1TtkUBZ3Iea78tnQyJf6NKllAMyVlj6xrvQ3+gKwGwmf BXGznlbMKVaSG/8Wv8vsbQVm2TSCof+1UldrW58KEbsYLq6yFp2k4f32jdD7ZeXOPdP6 QlkcgPmd94mVbyYCDCkcb2okhDObCu+WRi4Hz8FrOeEScavZwk/8IUt4z9CxakUHZ0A3 7rpapu3CXHSZ/K2hPdPUjBnQvnMo5DWLZTupqOfUekH4CW+1BPMNj9ntBw/bo1P7hqxy qnJg== X-Gm-Message-State: AGi0PuaE7jzPl0zuGSXfV7BVYlN/wPffZ+m0IdC5vPvO0Ens4pVvunZY rtdpOSY9JbUnN4rT9jj7oKKxqdVOW91vcO0Lf9gKrLja+t5oi96XzvxOye1UKkPAp1cl+EG32FR RTZGT0r+4o/pGjpOw2BFaCQ== X-Received: by 2002:a5d:4381:: with SMTP id i1mr23602728wrq.194.1587477470578; Tue, 21 Apr 2020 06:57:50 -0700 (PDT) X-Google-Smtp-Source: APiQypLt+rusb9oWs62pfY+dvFUY9ArCxclByAUD1+dJnv6mqI25nq4oBzy1Rmpsj/zgn97n7WVQFg== X-Received: by 2002:a5d:4381:: with SMTP id i1mr23602701wrq.194.1587477470222; Tue, 21 Apr 2020 06:57:50 -0700 (PDT) Received: from localhost.localdomain.com ([194.230.155.194]) by smtp.gmail.com with ESMTPSA id f23sm3562989wml.4.2020.04.21.06.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 06:57:49 -0700 (PDT) From: Emanuele Giuseppe Esposito To: linux-fsdevel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , "Manoj N. Kumar" , "Matthew R. Ochs" , Uma Krishnan , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Joel Becker , Christoph Hellwig , "Rafael J. Wysocki" , John Johansen , James Morris , "Serge E. Hallyn" , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-scsi@vger.kernel.org, linux-security-module@vger.kernel.org, Paolo Bonzini , Emanuele Giuseppe Esposito Subject: [PATCH v2 5/7] libfs: add file creation functions Date: Tue, 21 Apr 2020 15:57:39 +0200 Message-Id: <20200421135741.30657-3-eesposit@redhat.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200421135119.30007-1-eesposit@redhat.com> References: <20200421135119.30007-1-eesposit@redhat.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org A bunch of code is duplicated between debugfs and tracefs, unify it to the libfs library. The code is very similar, except that dentry and inode creation are unified into a single function (unlike start_creating in debugfs and tracefs, which only takes care of dentries). This adds an output parameter to the creation functions, but pushes all error recovery into fs/libfs.c. Signed-off-by: Emanuele Giuseppe Esposito --- fs/libfs.c | 226 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 18 ++++ 2 files changed, 244 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 5c76e4c648dc..90b0c221d9a2 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -751,6 +751,232 @@ struct inode *simple_alloc_anon_inode(struct simple_fs *fs) } EXPORT_SYMBOL(simple_alloc_anon_inode); +static struct dentry *failed_creating(struct simple_fs *fs, struct dentry *dentry) +{ + inode_unlock(d_inode(dentry->d_parent)); + dput(dentry); + simple_release_fs(fs); + return ERR_PTR(-ENOMEM); +} + +/** + * simplefs_create_dentry - creates a new dentry and inode + * @fs: a pointer to a struct simple_fs containing the reference counter + * and vfs_mount pointer + * @type: the fs type + * @name: dentry name + * @parent: parent dentry. If this parameter is NULL, + * then the dentry will be created in the root of the + * filesystem. + * @inode: pointer that will contain a newly created inode + * + * This function returns a new dentry, or NULL on error. On success, a + * new inode is created and stored into @inode. Also note that the inode + * for the parent directory is locked by simplefs_create_dentry(), + * and will be unlocked by simple_finish_dentry(). + **/ +struct dentry *simplefs_create_dentry(struct simple_fs *fs, struct file_system_type *type, + const char *name, struct dentry *parent, + struct inode **inode) +{ + struct dentry *dentry; + int error; + + pr_debug("creating file '%s'\n", name); + + if (IS_ERR(parent)) + return parent; + + error = simple_pin_fs(fs, type); + if (error) { + pr_err("Unable to pin filesystem for file '%s'\n", name); + return ERR_PTR(error); + } + + /* If the parent is not specified, we create it in the root. + * We need the root dentry to do this, which is in the super + * block. A pointer to that is in the struct vfsmount that we + * have around. + */ + if (!parent) + parent = fs->mount->mnt_root; + + inode_lock(d_inode(parent)); + dentry = lookup_one_len(name, parent, strlen(name)); + if (!IS_ERR(dentry) && d_really_is_positive(dentry)) { + if (d_is_dir(dentry)) + pr_err("Directory '%s' with parent '%s' already present!\n", + name, parent->d_name.name); + else + pr_err("File '%s' in directory '%s' already present!\n", + name, parent->d_name.name); + dput(dentry); + dentry = ERR_PTR(-EEXIST); + } + + if (IS_ERR(dentry)) { + inode_unlock(d_inode(parent)); + simple_release_fs(fs); + } + + + if (IS_ERR(dentry)) + return dentry; + + *inode = new_inode_current_time(fs->mount->mnt_sb); + if (unlikely(!(*inode))) { + pr_err("out of free inodes, can not create file '%s'\n", + name); + return failed_creating(fs, dentry); + } + + return dentry; +} +EXPORT_SYMBOL(simplefs_create_dentry); + +/** + * simplefs_create_file - creates a new file dentry and inode + * @fs: a pointer to a struct simple_fs containing the reference counter + * and vfs_mount pointer + * @type: the fs type + * @name: file name + * @mode: file mode + * @parent: parent dentry. If this parameter is NULL, + * then the file will be created in the root of the + * filesystem. + * @data: what will the file contain + * @inode: pointer that will contain a newly created inode + * + * This function returns a new dentry, or NULL on error. On success, a + * new inode is created and stored into @inode. Also note that the inode + * for the parent directory is locked by simplefs_create_dentry(), + * and will be unlocked by simple_finish_dentry(). + **/ +struct dentry *simplefs_create_file(struct simple_fs *fs, struct file_system_type *type, + const char *name, umode_t mode, + struct dentry *parent, void *data, + struct inode **inode) +{ + struct dentry *dentry; + + WARN_ON((mode & S_IFMT) && !S_ISREG(mode)); + mode |= S_IFREG; + + dentry = simplefs_create_dentry(fs, type, name, parent, inode); + + if (IS_ERR(dentry)) + return dentry; + + (*inode)->i_mode = mode; + (*inode)->i_private = data; + + return dentry; +} +EXPORT_SYMBOL(simplefs_create_file); + + +/** + * simplefs_finish_dentry- complete creation of a new dentry + * @dentry: the dentry being created + * @inode: the inode associated to the dentry + * + * This function completes the creation of a dentry. + * This includes associating @inode with the dentry, ensuring the link + * counts are consistent and informing fsnotify. + **/ +struct dentry *simplefs_finish_dentry(struct dentry *dentry, struct inode *inode) +{ + d_instantiate(dentry, inode); + if (S_ISDIR(inode->i_mode)) { + inc_nlink(d_inode(dentry->d_parent)); + fsnotify_mkdir(d_inode(dentry->d_parent), dentry); + } else { + fsnotify_create(d_inode(dentry->d_parent), dentry); + } + inode_unlock(d_inode(dentry->d_parent)); + return dentry; +} +EXPORT_SYMBOL(simplefs_finish_dentry); + +/** + * simplefs_create_dir - creates a new directory dentry and inode + * @fs: a pointer to a struct simple_fs containing the reference counter + * and vfs_mount pointer + * @type: the fs type + * @name: dir name + * @mode: dir mode + * @parent: parent dentry. If this parameter is NULL, + * then the directory will be created in the root of the + * filesystem. + * @inode: pointer that will contain a newly created inode + * + * This function returns a new dentry, or NULL on error. On success, a + * new inode is created and stored into @inode. Also note that the inode + * for the parent directory is locked by simplefs_create_dentry(), + * and will be unlocked by simple_finish_dentry(). + **/ +struct dentry *simplefs_create_dir(struct simple_fs *fs, struct file_system_type *type, + const char *name, umode_t mode, struct dentry *parent, + struct inode **inode) +{ + struct dentry *dentry; + + WARN_ON((mode & S_IFMT) && !S_ISDIR(mode)); + mode |= S_IFDIR; + + dentry = simplefs_create_dentry(fs, type, name, parent, inode); + if (IS_ERR(dentry)) + return dentry; + + (*inode)->i_mode = mode; + (*inode)->i_op = &simple_dir_inode_operations; + (*inode)->i_fop = &simple_dir_operations; + + /* directory inodes start off with i_nlink == 2 (for "." entry) */ + inc_nlink(*inode); + return dentry; +} +EXPORT_SYMBOL(simplefs_create_dir); + +/** + * simplefs_create_symlink - creates a new symlink dentry and inode + * @fs: a pointer to a struct simple_fs containing the reference counter + * and vfs_mount pointer + * @type: the fs type + * @name: symlink name + * @parent: parent dentry. If this parameter is NULL, + * then the symbolic link will be created in the root of the + * filesystem. + * @inode: pointer that will contain a newly created inode + * + * This function returns a new dentry, or NULL on error. On success, a + * new inode is created and stored into @inode. Also note that the inode + * for the parent directory is locked by simplefs_create_dentry(), + * and will be unlocked by simple_finish_dentry(). + **/ +struct dentry *simplefs_create_symlink(struct simple_fs *fs, struct file_system_type *type, + const char *name, struct dentry *parent, + const char *target, struct inode **inode) +{ + struct dentry *dentry; + char *link = kstrdup(target, GFP_KERNEL); + + if (!link) + return ERR_PTR(-ENOMEM); + + dentry = simplefs_create_dentry(fs, type, name, parent, inode); + if (IS_ERR(dentry)) { + kfree_link(link); + return dentry; + } + + (*inode)->i_mode = S_IFLNK | S_IRWXUGO; + (*inode)->i_link = link; + (*inode)->i_op = &simple_symlink_inode_operations; + return dentry; +} +EXPORT_SYMBOL(simplefs_create_symlink); + /** * simple_read_from_buffer - copy data from the buffer to user space * @to: the user space buffer to read to diff --git a/include/linux/fs.h b/include/linux/fs.h index 5e93de72118b..0569540fbe61 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3375,6 +3375,24 @@ extern void simple_release_fs(struct simple_fs *); extern struct inode *simple_alloc_anon_inode(struct simple_fs *fs); +extern struct dentry *simplefs_create_dentry(struct simple_fs *fs, + struct file_system_type *type, + const char *name, struct dentry *parent, + struct inode **inode); +struct dentry *simplefs_finish_dentry(struct dentry *dentry, struct inode *inode); + +extern struct dentry *simplefs_create_file(struct simple_fs *fs, + struct file_system_type *type, + const char *name, umode_t mode, + struct dentry *parent, void *data, + struct inode **inode); +extern struct dentry *simplefs_create_dir(struct simple_fs *fs, struct file_system_type *type, + const char *name, umode_t mode, struct dentry *parent, + struct inode **inode); +extern struct dentry *simplefs_create_symlink(struct simple_fs *fs, struct file_system_type *type, + const char *name, struct dentry *parent, + const char *target, struct inode **inode); + extern ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos, const void *from, size_t available); extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, From patchwork Tue Apr 21 13:57:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 11501495 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C08121575 for ; Tue, 21 Apr 2020 13:58:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F6F42070B for ; Tue, 21 Apr 2020 13:58:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cSn8rXNK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728963AbgDUN57 (ORCPT ); Tue, 21 Apr 2020 09:57:59 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:51790 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728960AbgDUN56 (ORCPT ); Tue, 21 Apr 2020 09:57:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587477475; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xjaOnzI5gdueJ0y4sy2VdCpkInG/pM8xAJAe7M5MwVA=; b=cSn8rXNKfSu/EzJdKFw0lgCwpBv4T8foRdmKsY5Nu/b8V7b/1fuYH8rlaqofq0qJpvTrzK 7OXHNXgriitN355roYl+Y0TK4FYepmMb/e7Kqo0qIQRsLIamGZYBFWX3i81FjjDMyNhHyZ IoH27m6RxSpQfxWVIg3XeAb4mEtXuZw= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-286-mxC6DqmSPdWBBdvTCwJnig-1; Tue, 21 Apr 2020 09:57:53 -0400 X-MC-Unique: mxC6DqmSPdWBBdvTCwJnig-1 Received: by mail-wr1-f70.google.com with SMTP id i10so7508948wrq.8 for ; Tue, 21 Apr 2020 06:57:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xjaOnzI5gdueJ0y4sy2VdCpkInG/pM8xAJAe7M5MwVA=; b=aGkdEqnTN+NBwpMgJBV7we9cDBjelzpx62C9q9mNCyNq3i3aTzQnCvV9AI+6Y5H/eA EXqyCKGWHB9JYwx3Bhr3b7RBekaP8R2XRO7JGUI1/LzYlGUC665/bhKjPWXjC095JySM eSYaS5hez6xWSNT7txrj2e4jzjIYyEFkQWldnZdZhlRthKDoUfuADHtZbAG/5deK1R+j ZfP66yNVVZ+1GOCy8/Y5ABtt8Btr26lIvhzHq6pGIXuvSLzSDC4++ILhq5dkBSZvXVbf K7YhtYulFiDkU3bIWNhRSdsPBdCFU9tWmwkaETfqF/2vVEGBwu/0U9xvNK+O0tOhOHWX 4LHg== X-Gm-Message-State: AGi0PuZ8MzNyRNmAkjbZFmjtJSZPL1CYCSHGHUKDBeEdpRdfuD8AYLgJ +iJiY80nQKLh5VE90dRyT2tsct0vz1xeo5ym3mTj4ynw1BpmpHwrAu9fwNCJ9oezJE2aULIyXkp Qyb0KER7oAXRb40H4VUmDLw== X-Received: by 2002:a1c:9c0a:: with SMTP id f10mr5022049wme.139.1587477472393; Tue, 21 Apr 2020 06:57:52 -0700 (PDT) X-Google-Smtp-Source: APiQypIlG2viM+l0EuPG6wic3zBlhrKU/He9H0puv0ur4Y4UIWdpPnCyTzA3FMh8mbZkb38/fp+4ZQ== X-Received: by 2002:a1c:9c0a:: with SMTP id f10mr5022031wme.139.1587477472153; Tue, 21 Apr 2020 06:57:52 -0700 (PDT) Received: from localhost.localdomain.com ([194.230.155.194]) by smtp.gmail.com with ESMTPSA id f23sm3562989wml.4.2020.04.21.06.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 06:57:51 -0700 (PDT) From: Emanuele Giuseppe Esposito To: linux-fsdevel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , "Manoj N. Kumar" , "Matthew R. Ochs" , Uma Krishnan , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Joel Becker , Christoph Hellwig , "Rafael J. Wysocki" , John Johansen , James Morris , "Serge E. Hallyn" , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-scsi@vger.kernel.org, linux-security-module@vger.kernel.org, Paolo Bonzini , Emanuele Giuseppe Esposito Subject: [PATCH v2 6/7] debugfs: switch to simplefs inode creation API Date: Tue, 21 Apr 2020 15:57:40 +0200 Message-Id: <20200421135741.30657-4-eesposit@redhat.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200421135119.30007-1-eesposit@redhat.com> References: <20200421135119.30007-1-eesposit@redhat.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The only difference, compared to the pre-existing code, is that symlink creation now triggers fsnotify_create. This was a bug in the debugfs code, since for example vfs_symlink does call fsnotify_create. Signed-off-by: Emanuele Giuseppe Esposito --- fs/debugfs/inode.c | 144 +++++---------------------------------------- 1 file changed, 15 insertions(+), 129 deletions(-) diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index 5dbb74a23e7c..ccbeea9e5f6c 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -305,68 +305,6 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent) } EXPORT_SYMBOL_GPL(debugfs_lookup); -static struct dentry *start_creating(const char *name, struct dentry *parent) -{ - struct dentry *dentry; - int error; - - pr_debug("creating file '%s'\n", name); - - if (IS_ERR(parent)) - return parent; - - error = simple_pin_fs(&debugfs, &debug_fs_type); - if (error) { - pr_err("Unable to pin filesystem for file '%s'\n", name); - return ERR_PTR(error); - } - - /* If the parent is not specified, we create it in the root. - * We need the root dentry to do this, which is in the super - * block. A pointer to that is in the struct vfsmount that we - * have around. - */ - if (!parent) - parent = debugfs.mount->mnt_root; - - inode_lock(d_inode(parent)); - if (unlikely(IS_DEADDIR(d_inode(parent)))) - dentry = ERR_PTR(-ENOENT); - else - dentry = lookup_one_len(name, parent, strlen(name)); - if (!IS_ERR(dentry) && d_really_is_positive(dentry)) { - if (d_is_dir(dentry)) - pr_err("Directory '%s' with parent '%s' already present!\n", - name, parent->d_name.name); - else - pr_err("File '%s' in directory '%s' already present!\n", - name, parent->d_name.name); - dput(dentry); - dentry = ERR_PTR(-EEXIST); - } - - if (IS_ERR(dentry)) { - inode_unlock(d_inode(parent)); - simple_release_fs(&debugfs); - } - - return dentry; -} - -static struct dentry *failed_creating(struct dentry *dentry) -{ - inode_unlock(d_inode(dentry->d_parent)); - dput(dentry); - simple_release_fs(&debugfs); - return ERR_PTR(-ENOMEM); -} - -static struct dentry *end_creating(struct dentry *dentry) -{ - inode_unlock(d_inode(dentry->d_parent)); - return dentry; -} - static struct dentry *__debugfs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *proxy_fops, @@ -375,32 +313,17 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode, struct dentry *dentry; struct inode *inode; - if (!(mode & S_IFMT)) - mode |= S_IFREG; - BUG_ON(!S_ISREG(mode)); - dentry = start_creating(name, parent); - + dentry = simplefs_create_file(&debugfs, &debug_fs_type, + name, mode, parent, data, &inode); if (IS_ERR(dentry)) return dentry; - inode = debugfs_get_inode(dentry->d_sb); - if (unlikely(!inode)) { - pr_err("out of free dentries, can not create file '%s'\n", - name); - return failed_creating(dentry); - } - - inode->i_mode = mode; - inode->i_private = data; - inode->i_op = &debugfs_file_inode_operations; inode->i_fop = proxy_fops; dentry->d_fsdata = (void *)((unsigned long)real_fops | DEBUGFS_FSDATA_IS_REAL_FOPS_BIT); - d_instantiate(dentry, inode); - fsnotify_create(d_inode(dentry->d_parent), dentry); - return end_creating(dentry); + return simplefs_finish_dentry(dentry, inode); } /** @@ -533,29 +456,16 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_size); */ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) { - struct dentry *dentry = start_creating(name, parent); + struct dentry *dentry; struct inode *inode; + dentry = simplefs_create_dir(&debugfs, &debug_fs_type, + name, 0755, parent, &inode); if (IS_ERR(dentry)) return dentry; - inode = debugfs_get_inode(dentry->d_sb); - if (unlikely(!inode)) { - pr_err("out of free dentries, can not create directory '%s'\n", - name); - return failed_creating(dentry); - } - - inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; inode->i_op = &debugfs_dir_inode_operations; - inode->i_fop = &simple_dir_operations; - - /* directory inodes start off with i_nlink == 2 (for "." entry) */ - inc_nlink(inode); - d_instantiate(dentry, inode); - inc_nlink(d_inode(dentry->d_parent)); - fsnotify_mkdir(d_inode(dentry->d_parent), dentry); - return end_creating(dentry); + return simplefs_finish_dentry(dentry, inode); } EXPORT_SYMBOL_GPL(debugfs_create_dir); @@ -575,29 +485,19 @@ struct dentry *debugfs_create_automount(const char *name, debugfs_automount_t f, void *data) { - struct dentry *dentry = start_creating(name, parent); + struct dentry *dentry; struct inode *inode; + dentry = simplefs_create_dentry(&debugfs, &debug_fs_type, name, parent, + &inode); if (IS_ERR(dentry)) return dentry; - inode = debugfs_get_inode(dentry->d_sb); - if (unlikely(!inode)) { - pr_err("out of free dentries, can not create automount '%s'\n", - name); - return failed_creating(dentry); - } - make_empty_dir_inode(inode); inode->i_flags |= S_AUTOMOUNT; inode->i_private = data; dentry->d_fsdata = (void *)f; - /* directory inodes start off with i_nlink == 2 (for "." entry) */ - inc_nlink(inode); - d_instantiate(dentry, inode); - inc_nlink(d_inode(dentry->d_parent)); - fsnotify_mkdir(d_inode(dentry->d_parent), dentry); - return end_creating(dentry); + return simplefs_finish_dentry(dentry, inode); } EXPORT_SYMBOL(debugfs_create_automount); @@ -629,28 +529,14 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent, { struct dentry *dentry; struct inode *inode; - char *link = kstrdup(target, GFP_KERNEL); - if (!link) - return ERR_PTR(-ENOMEM); - dentry = start_creating(name, parent); - if (IS_ERR(dentry)) { - kfree(link); + dentry = simplefs_create_symlink(&debugfs, &debug_fs_type, + name, parent, target, &inode); + if (IS_ERR(dentry)) return dentry; - } - inode = debugfs_get_inode(dentry->d_sb); - if (unlikely(!inode)) { - pr_err("out of free dentries, can not create symlink '%s'\n", - name); - kfree(link); - return failed_creating(dentry); - } - inode->i_mode = S_IFLNK | S_IRWXUGO; inode->i_op = &debugfs_symlink_inode_operations; - inode->i_link = link; - d_instantiate(dentry, inode); - return end_creating(dentry); + return simplefs_finish_dentry(dentry, inode); } EXPORT_SYMBOL_GPL(debugfs_create_symlink); From patchwork Tue Apr 21 13:57:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 11501493 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A769913 for ; Tue, 21 Apr 2020 13:58:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B1D520644 for ; Tue, 21 Apr 2020 13:58:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="flnIJNRY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729053AbgDUN6B (ORCPT ); Tue, 21 Apr 2020 09:58:01 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:50788 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729009AbgDUN57 (ORCPT ); Tue, 21 Apr 2020 09:57:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587477477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jPnP4qV6sDaGZ2bSbejYPzydlvKfgMg0o/pB9q3go8E=; b=flnIJNRYhz6k5uf28deeJaZr1AZzKWUshWdx0GvoCS61yZzs24C5VrhHB8WOUUBPY+mIC/ ucoMZCWcKvmgMb7d4sOPunzkenploPDxFxQq4/tItR/HSAWZjkVkB7CjFrtNHCg0vFwC9P cxEChLSAZCCrPhqp+bIqXGFQgzU4bV8= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-362-vBATI1D5OEi3ZsziDpo1CA-1; Tue, 21 Apr 2020 09:57:55 -0400 X-MC-Unique: vBATI1D5OEi3ZsziDpo1CA-1 Received: by mail-wr1-f69.google.com with SMTP id p16so7523011wro.16 for ; Tue, 21 Apr 2020 06:57:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jPnP4qV6sDaGZ2bSbejYPzydlvKfgMg0o/pB9q3go8E=; b=anC0u2Bx0w+LcQNPZUvU+HO5lvcfPTQFXH7rssX3+h74Ygo2uRWrBMEjWdXTl0lDuj 9aF8O0i5ElxjSepsff/aDfMWbn8VWrQ/3CbWcwGVIn3hGBxtwIE1dAVBP40dzzHsDHVk jxtgmlz21QRBab1f/1PuH1JKQ4CcuT9haAxCkIHbKBZ8ZaN1+LObSJhJEPkGJXZ+aLn0 gUz4oa3Ulq3/+gXh7OhxbduL4de3fBHKXUIyxk0Yixm+hm4ULk+y6cLWHlmwDhHD4XFZ cN83SY+K7QxDO1HVIIzBqUekPFit30BfZarjiJkyn1t+jsGE3lHyZ4+xEjLyxiEd6iu9 i9NQ== X-Gm-Message-State: AGi0PuZSlMhgNuZrGXm1QNI7nbekxttMikwNx4+NevU2CSpGkJxupXs+ YVBUQBnRROWEwL8YIrdw6WpBG8zqSbiMmfrdYoNm8j6LhlAW5bht2PlSv0mXm+Vtf+jeconoSv2 b2AlJodLkfSy7gfSDYO597A== X-Received: by 2002:a05:600c:da:: with SMTP id u26mr5188178wmm.48.1587477474539; Tue, 21 Apr 2020 06:57:54 -0700 (PDT) X-Google-Smtp-Source: APiQypImms4WydeI5+8l3z5lWKRrEMa+0XfWFGcGeKI2hzBQZu8YXbxqfuv1YC/rok2n8KUUpE7+Vg== X-Received: by 2002:a05:600c:da:: with SMTP id u26mr5188144wmm.48.1587477474268; Tue, 21 Apr 2020 06:57:54 -0700 (PDT) Received: from localhost.localdomain.com ([194.230.155.194]) by smtp.gmail.com with ESMTPSA id f23sm3562989wml.4.2020.04.21.06.57.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 06:57:53 -0700 (PDT) From: Emanuele Giuseppe Esposito To: linux-fsdevel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , "Manoj N. Kumar" , "Matthew R. Ochs" , Uma Krishnan , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Joel Becker , Christoph Hellwig , "Rafael J. Wysocki" , John Johansen , James Morris , "Serge E. Hallyn" , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-scsi@vger.kernel.org, linux-security-module@vger.kernel.org, Paolo Bonzini , Emanuele Giuseppe Esposito Subject: [PATCH v2 7/7] tracefs: switch to simplefs inode creation API Date: Tue, 21 Apr 2020 15:57:41 +0200 Message-Id: <20200421135741.30657-5-eesposit@redhat.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200421135119.30007-1-eesposit@redhat.com> References: <20200421135119.30007-1-eesposit@redhat.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org There is no semantic change intended; the code in the libfs.c functions in fact was derived from debugfs and tracefs code. Signed-off-by: Emanuele Giuseppe Esposito --- fs/tracefs/inode.c | 86 ++++------------------------------------------ 1 file changed, 7 insertions(+), 79 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 370eb38ff1ad..bceaa4f45da2 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -308,57 +308,6 @@ static struct file_system_type trace_fs_type = { }; MODULE_ALIAS_FS("tracefs"); -static struct dentry *start_creating(const char *name, struct dentry *parent) -{ - struct dentry *dentry; - int error; - - pr_debug("tracefs: creating file '%s'\n",name); - - error = simple_pin_fs(&tracefs, &trace_fs_type); - if (error) - return ERR_PTR(error); - - /* If the parent is not specified, we create it in the root. - * We need the root dentry to do this, which is in the super - * block. A pointer to that is in the struct vfsmount that we - * have around. - */ - if (!parent) - parent = tracefs.mount->mnt_root; - - inode_lock(parent->d_inode); - if (unlikely(IS_DEADDIR(parent->d_inode))) - dentry = ERR_PTR(-ENOENT); - else - dentry = lookup_one_len(name, parent, strlen(name)); - if (!IS_ERR(dentry) && dentry->d_inode) { - dput(dentry); - dentry = ERR_PTR(-EEXIST); - } - - if (IS_ERR(dentry)) { - inode_unlock(parent->d_inode); - simple_release_fs(&tracefs); - } - - return dentry; -} - -static struct dentry *failed_creating(struct dentry *dentry) -{ - inode_unlock(dentry->d_parent->d_inode); - dput(dentry); - simple_release_fs(&tracefs); - return NULL; -} - -static struct dentry *end_creating(struct dentry *dentry) -{ - inode_unlock(dentry->d_parent->d_inode); - return dentry; -} - /** * tracefs_create_file - create a file in the tracefs filesystem * @name: a pointer to a string containing the name of the file to create. @@ -395,49 +344,28 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, if (security_locked_down(LOCKDOWN_TRACEFS)) return NULL; - if (!(mode & S_IFMT)) - mode |= S_IFREG; - BUG_ON(!S_ISREG(mode)); - dentry = start_creating(name, parent); - + dentry = simplefs_create_file(&tracefs, &trace_fs_type, + name, mode, parent, data, &inode); if (IS_ERR(dentry)) return NULL; - inode = tracefs_get_inode(dentry->d_sb); - if (unlikely(!inode)) - return failed_creating(dentry); - - inode->i_mode = mode; inode->i_fop = fops ? fops : &tracefs_file_operations; - inode->i_private = data; - d_instantiate(dentry, inode); - fsnotify_create(dentry->d_parent->d_inode, dentry); - return end_creating(dentry); + return simplefs_finish_dentry(dentry, inode); } static struct dentry *__create_dir(const char *name, struct dentry *parent, const struct inode_operations *ops) { - struct dentry *dentry = start_creating(name, parent); + struct dentry *dentry; struct inode *inode; + dentry = simplefs_create_dir(&tracefs, &trace_fs_type, + name, 0755, parent, &inode); if (IS_ERR(dentry)) return NULL; - inode = tracefs_get_inode(dentry->d_sb); - if (unlikely(!inode)) - return failed_creating(dentry); - - inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; inode->i_op = ops; - inode->i_fop = &simple_dir_operations; - - /* directory inodes start off with i_nlink == 2 (for "." entry) */ - inc_nlink(inode); - d_instantiate(dentry, inode); - inc_nlink(dentry->d_parent->d_inode); - fsnotify_mkdir(dentry->d_parent->d_inode, dentry); - return end_creating(dentry); + return simplefs_finish_dentry(dentry, inode); } /**