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 X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A618BC54FC9 for ; Tue, 21 Apr 2020 13:58:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8356120644 for ; Tue, 21 Apr 2020 13:58:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="apsS1Fm0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729035AbgDUN57 (ORCPT ); Tue, 21 Apr 2020 09:57:59 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:55272 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728963AbgDUN56 (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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xjaOnzI5gdueJ0y4sy2VdCpkInG/pM8xAJAe7M5MwVA=; b=apsS1Fm0qtV6O0VidnFF2wOKPSvn/99MeZShrhxZtnNwSBqdtCDBoJJrzYHvPiwagMghOQ LydCVkk+/L+zARF6pCT79i7HgGqQ/iDDpzQIJOF67ncrSVPORpaJ3U15p/IKw4I02yOQ4g Tdk2mjIwKXWDiJ6yIjvahFA3olN9xdc= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-186-ynLx0rIJOg6l0x-Q1vNEZQ-1; Tue, 21 Apr 2020 09:57:53 -0400 X-MC-Unique: ynLx0rIJOg6l0x-Q1vNEZQ-1 Received: by mail-wr1-f71.google.com with SMTP id f2so7535963wrm.9 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=Im0XwMELgWDmfzOQGpQhbAGfHu4C6BmqunkXHpQPfnb3GBNOUEyPhu2PWw/7eKEywG SXeJ0fboU8DPtmTSVBCuhoZvZqqX8z/TfgLpEp69U+vjK0fNqgHh56sd3NYqBM+hE8Fs Oc3d5GeZ33Z7lBCz0weGhufMvJeptGFYaqIhPbz/jp5w0ij+pzx4gPWOLyxi+J8Fwvq8 DxEQJDd83yRGFitUSxI8XKKgPaHa7nTJ8TE3DF76gDkxnY6rOf88J1x8v4NccNAqSgoF R8SwLtVPio3M1I/niHbdSROmZA0auxa9LeCgxO0pIbdyyWBxO6RcYA+jlJnpogaIwwqj Euhg== X-Gm-Message-State: AGi0PuZwZ+m7Xk6B2kEKisDt3rHY9R95Kpx4eBQsjcldXyMZU+qVfaZm B01aadyUFZ43/hYZITpx7mXsb/I+v5RXalJqgVpDAyT1ILOqHW8gkYQ6Lo9D3bu01ISecT9Upga /KpMOi9ciFNREIm4y1LvI5Y9wjkABt8Y860qA X-Received: by 2002:a1c:9c0a:: with SMTP id f10mr5022063wme.139.1587477472394; 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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); -- 2.25.2 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 X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 293C3C54FCC for ; Tue, 21 Apr 2020 14:36:17 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D120A20656 for ; Tue, 21 Apr 2020 14:36:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WQqmQp1H"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WQqmQp1H" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D120A20656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4965jB0NfFzDqGG for ; Wed, 22 Apr 2020 00:36:14 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=207.211.31.120; helo=us-smtp-1.mimecast.com; envelope-from=eesposit@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WQqmQp1H; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WQqmQp1H; dkim-atps=neutral Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4964s40k59zDqVn for ; Tue, 21 Apr 2020 23:57:59 +1000 (AEST) 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kmtwUC7V+MJ1MUJkO+8igv9Zdipw2p7Im+OneAOOFXw=; b=WQqmQp1HtBxxtrpHlZafYguVF2X3bkbYJ5sjzzwfdJzk3FgLp8EDvj1Bic0jP1L80tVdVy YiAmRaz4+8cQZrqKjtRfeu5Maet7VWRqdSiUVZtJkLP33Vlcfg3ZsOVtY9CBw8ytIMYe5L GC12v2O8jCf+IrgqFGBOrS5KI12A9y8= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kmtwUC7V+MJ1MUJkO+8igv9Zdipw2p7Im+OneAOOFXw=; b=WQqmQp1HtBxxtrpHlZafYguVF2X3bkbYJ5sjzzwfdJzk3FgLp8EDvj1Bic0jP1L80tVdVy YiAmRaz4+8cQZrqKjtRfeu5Maet7VWRqdSiUVZtJkLP33Vlcfg3ZsOVtY9CBw8ytIMYe5L GC12v2O8jCf+IrgqFGBOrS5KI12A9y8= 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-183-oLr1DmOcPxitSBTT78H4ZQ-1; Tue, 21 Apr 2020 09:57:53 -0400 X-MC-Unique: oLr1DmOcPxitSBTT78H4ZQ-1 Received: by mail-wr1-f70.google.com with SMTP id g7so6631768wrw.18 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=IJaZYZO4W6p56B/ApTjwr3BmBqzFLOgOPWduG+iZx2zKixSSMeK8GrhpbcD6htJFzu kinQGhC4cFFlUZRYk2HFWVi/w47WzXH/ogIHxElZODjhPiVQ8T+EXjAHb5BawFQQfzP6 2e7DvliUyWEJYAkwzVOXsDTm1iHVVYC2bO/of2j8MHbwkkqWmVony2tEXp0yyxAvhKCw hDtEpimwad3vUDvkw3PuDkezbWqNuStts54FSBNKm7rIrsi+psTA/y3+j/p8raULOWAN yvgWxLptNoS8oNK7WABQLKZrE+W04BrQxxXdf7Es0NkMiAXygM8abYuHjaxP++DDb8rj 0YrQ== X-Gm-Message-State: AGi0PuaOX1+uBdG6JmgMSiF5//8I29bCbe9pV5vkz2xLSHGVc2JbByWc XPUhgd/Jqe0k4Gq/kacj1s6Tv02rJib+VkfSnz27DLB7VZzYDYOYkR0bJdNPKrDQuoeJpB09sop NQK5BrR3hGrR2tyr61G9nfY1WRA== X-Received: by 2002:a1c:9c0a:: with SMTP id f10mr5022050wme.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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Rafael J. Wysocki" , David Airlie , dri-devel@lists.freedesktop.org, Christoph Hellwig , Andrew Donnellan , Emanuele Giuseppe Esposito , linux-scsi@vger.kernel.org, James Morris , "Serge E. Hallyn" , Daniel Vetter , Arnd Bergmann , "James E.J. Bottomley" , Maarten Lankhorst , Maxime Ripard , "Manoj N. Kumar" , Alexander Viro , "Matthew R. Ochs" , Uma Krishnan , John Johansen , "Martin K. Petersen" , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Thomas Zimmermann , Frederic Barrat , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org, Joel Becker Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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); =20 -static struct dentry *start_creating(const char *name, struct dentry *pare= nt) -{ -=09struct dentry *dentry; -=09int error; - -=09pr_debug("creating file '%s'\n", name); - -=09if (IS_ERR(parent)) -=09=09return parent; - -=09error =3D simple_pin_fs(&debugfs, &debug_fs_type); -=09if (error) { -=09=09pr_err("Unable to pin filesystem for file '%s'\n", name); -=09=09return ERR_PTR(error); -=09} - -=09/* If the parent is not specified, we create it in the root. -=09 * We need the root dentry to do this, which is in the super -=09 * block. A pointer to that is in the struct vfsmount that we -=09 * have around. -=09 */ -=09if (!parent) -=09=09parent =3D debugfs.mount->mnt_root; - -=09inode_lock(d_inode(parent)); -=09if (unlikely(IS_DEADDIR(d_inode(parent)))) -=09=09dentry =3D ERR_PTR(-ENOENT); -=09else -=09=09dentry =3D lookup_one_len(name, parent, strlen(name)); -=09if (!IS_ERR(dentry) && d_really_is_positive(dentry)) { -=09=09if (d_is_dir(dentry)) -=09=09=09pr_err("Directory '%s' with parent '%s' already present!\n", -=09=09=09 name, parent->d_name.name); -=09=09else -=09=09=09pr_err("File '%s' in directory '%s' already present!\n", -=09=09=09 name, parent->d_name.name); -=09=09dput(dentry); -=09=09dentry =3D ERR_PTR(-EEXIST); -=09} - -=09if (IS_ERR(dentry)) { -=09=09inode_unlock(d_inode(parent)); -=09=09simple_release_fs(&debugfs); -=09} - -=09return dentry; -} - -static struct dentry *failed_creating(struct dentry *dentry) -{ -=09inode_unlock(d_inode(dentry->d_parent)); -=09dput(dentry); -=09simple_release_fs(&debugfs); -=09return ERR_PTR(-ENOMEM); -} - -static struct dentry *end_creating(struct dentry *dentry) -{ -=09inode_unlock(d_inode(dentry->d_parent)); -=09return dentry; -} - static struct dentry *__debugfs_create_file(const char *name, umode_t mode= , =09=09=09=09struct dentry *parent, void *data, =09=09=09=09const struct file_operations *proxy_fops, @@ -375,32 +313,17 @@ static struct dentry *__debugfs_create_file(const cha= r *name, umode_t mode, =09struct dentry *dentry; =09struct inode *inode; =20 -=09if (!(mode & S_IFMT)) -=09=09mode |=3D S_IFREG; -=09BUG_ON(!S_ISREG(mode)); -=09dentry =3D start_creating(name, parent); - +=09dentry =3D simplefs_create_file(&debugfs, &debug_fs_type, +=09=09=09=09 name, mode, parent, data, &inode); =09if (IS_ERR(dentry)) =09=09return dentry; =20 -=09inode =3D debugfs_get_inode(dentry->d_sb); -=09if (unlikely(!inode)) { -=09=09pr_err("out of free dentries, can not create file '%s'\n", -=09=09 name); -=09=09return failed_creating(dentry); -=09} - -=09inode->i_mode =3D mode; -=09inode->i_private =3D data; - =09inode->i_op =3D &debugfs_file_inode_operations; =09inode->i_fop =3D proxy_fops; =09dentry->d_fsdata =3D (void *)((unsigned long)real_fops | =09=09=09=09DEBUGFS_FSDATA_IS_REAL_FOPS_BIT); =20 -=09d_instantiate(dentry, inode); -=09fsnotify_create(d_inode(dentry->d_parent), dentry); -=09return end_creating(dentry); +=09return simplefs_finish_dentry(dentry, inode); } =20 /** @@ -533,29 +456,16 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_size); */ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) { -=09struct dentry *dentry =3D start_creating(name, parent); +=09struct dentry *dentry; =09struct inode *inode; =20 +=09dentry =3D simplefs_create_dir(&debugfs, &debug_fs_type, +=09=09=09=09 name, 0755, parent, &inode); =09if (IS_ERR(dentry)) =09=09return dentry; =20 -=09inode =3D debugfs_get_inode(dentry->d_sb); -=09if (unlikely(!inode)) { -=09=09pr_err("out of free dentries, can not create directory '%s'\n", -=09=09 name); -=09=09return failed_creating(dentry); -=09} - -=09inode->i_mode =3D S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; =09inode->i_op =3D &debugfs_dir_inode_operations; -=09inode->i_fop =3D &simple_dir_operations; - -=09/* directory inodes start off with i_nlink =3D=3D 2 (for "." entry) */ -=09inc_nlink(inode); -=09d_instantiate(dentry, inode); -=09inc_nlink(d_inode(dentry->d_parent)); -=09fsnotify_mkdir(d_inode(dentry->d_parent), dentry); -=09return end_creating(dentry); +=09return simplefs_finish_dentry(dentry, inode); } EXPORT_SYMBOL_GPL(debugfs_create_dir); =20 @@ -575,29 +485,19 @@ struct dentry *debugfs_create_automount(const char *n= ame, =09=09=09=09=09debugfs_automount_t f, =09=09=09=09=09void *data) { -=09struct dentry *dentry =3D start_creating(name, parent); +=09struct dentry *dentry; =09struct inode *inode; =20 +=09dentry =3D simplefs_create_dentry(&debugfs, &debug_fs_type, name, paren= t, +=09=09=09=09=09&inode); =09if (IS_ERR(dentry)) =09=09return dentry; =20 -=09inode =3D debugfs_get_inode(dentry->d_sb); -=09if (unlikely(!inode)) { -=09=09pr_err("out of free dentries, can not create automount '%s'\n", -=09=09 name); -=09=09return failed_creating(dentry); -=09} - =09make_empty_dir_inode(inode); =09inode->i_flags |=3D S_AUTOMOUNT; =09inode->i_private =3D data; =09dentry->d_fsdata =3D (void *)f; -=09/* directory inodes start off with i_nlink =3D=3D 2 (for "." entry) */ -=09inc_nlink(inode); -=09d_instantiate(dentry, inode); -=09inc_nlink(d_inode(dentry->d_parent)); -=09fsnotify_mkdir(d_inode(dentry->d_parent), dentry); -=09return end_creating(dentry); +=09return simplefs_finish_dentry(dentry, inode); } EXPORT_SYMBOL(debugfs_create_automount); =20 @@ -629,28 +529,14 @@ struct dentry *debugfs_create_symlink(const char *nam= e, struct dentry *parent, { =09struct dentry *dentry; =09struct inode *inode; -=09char *link =3D kstrdup(target, GFP_KERNEL); -=09if (!link) -=09=09return ERR_PTR(-ENOMEM); =20 -=09dentry =3D start_creating(name, parent); -=09if (IS_ERR(dentry)) { -=09=09kfree(link); +=09dentry =3D simplefs_create_symlink(&debugfs, &debug_fs_type, +=09=09=09=09=09 name, parent, target, &inode); +=09if (IS_ERR(dentry)) =09=09return dentry; -=09} =20 -=09inode =3D debugfs_get_inode(dentry->d_sb); -=09if (unlikely(!inode)) { -=09=09pr_err("out of free dentries, can not create symlink '%s'\n", -=09=09 name); -=09=09kfree(link); -=09=09return failed_creating(dentry); -=09} -=09inode->i_mode =3D S_IFLNK | S_IRWXUGO; =09inode->i_op =3D &debugfs_symlink_inode_operations; -=09inode->i_link =3D link; -=09d_instantiate(dentry, inode); -=09return end_creating(dentry); +=09return simplefs_finish_dentry(dentry, inode); } EXPORT_SYMBOL_GPL(debugfs_create_symlink); =20 --=20 2.25.2 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 X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A332C55184 for ; Tue, 21 Apr 2020 13:57:59 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D4B752071C for ; Tue, 21 Apr 2020 13:57:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YULjPD5L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D4B752071C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 483806E988; Tue, 21 Apr 2020 13:57:58 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 71C426E988 for ; Tue, 21 Apr 2020 13:57:56 +0000 (UTC) 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kmtwUC7V+MJ1MUJkO+8igv9Zdipw2p7Im+OneAOOFXw=; b=YULjPD5L0DUJ+PU6Ww7TacsSdTNysH+YmMAtVcf5cCpG8bIzAoUG0jmFtje29ZwIyrk6Lc iPhR56RuarA/qhCYN1BO8D9vDAxbRDeCUNBLWKFQlO4A7bTIlqmFuEXb4v1SALIsZ87n6j hPqbVbjeapLRXpFguQWGlmGyrReLFIQ= 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-482-9D2OHxO_OOOsicP3pBkjhQ-1; Tue, 21 Apr 2020 09:57:53 -0400 X-MC-Unique: 9D2OHxO_OOOsicP3pBkjhQ-1 Received: by mail-wm1-f70.google.com with SMTP id u11so1399829wmc.7 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=XmJa9Tucd4diSzUGuMpiTZoKxfH4H83iwh39YnhSmz/HZ4D2mIUFI/Ss7fwrlyzft5 hJNu5yXfNZjKuEMFPlW4meQlbfgHqPLVt1s4AO1iliqO9UvR1gnbUYjpoHDrfRhUQqUH oPFL+GYrZEkgFRYOgtUNwHbfVtyAvUyEu/515ADKBsZYNJNvodEtfjzWNuAEi/xIGf8f Fxp4FJo1DJV4e5ooielH7VDec1AAIl/V1p0mMQG/us3x9xgdTwZ6M8w5zVZx52jNONTg 6tVZDoqiDLSaHo5anbkyBEVYjGPOWnfRiAVs1wqp4LB3gSi8kPxDcD0fGrV7RiE9Y9ZI ch8A== X-Gm-Message-State: AGi0PuYiJ4LOMCnvQG5v+LuKi7MjjJPUjRBHvR+NXuZLcMZtlIt8I8AQ gpCOeuHDBEvGpuFYSMJlVsdnKnl4wGglsE1OmHvnHXfzjHknUcAmQrgip/tH+yF3zbySSRS5U1l DpP0UHhyVyKKcjpc70lT9aRG0jCVx X-Received: by 2002:a1c:9c0a:: with SMTP id f10mr5022060wme.139.1587477472394; 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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Rafael J. Wysocki" , David Airlie , dri-devel@lists.freedesktop.org, Christoph Hellwig , Andrew Donnellan , Emanuele Giuseppe Esposito , linux-scsi@vger.kernel.org, James Morris , "Serge E. Hallyn" , Arnd Bergmann , "James E.J. Bottomley" , "Manoj N. Kumar" , Alexander Viro , "Matthew R. Ochs" , Uma Krishnan , John Johansen , "Martin K. Petersen" , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Thomas Zimmermann , Frederic Barrat , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org, Joel Becker Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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); -- 2.25.2 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel