From patchwork Wed Jun 22 14:35:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9193117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 97FA060890 for ; Wed, 22 Jun 2016 14:38:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88A0128408 for ; Wed, 22 Jun 2016 14:38:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C90C28358; Wed, 22 Jun 2016 14:38:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2815F28408 for ; Wed, 22 Jun 2016 14:38:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751537AbcFVOhk (ORCPT ); Wed, 22 Jun 2016 10:37:40 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:34921 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752102AbcFVOfR (ORCPT ); Wed, 22 Jun 2016 10:35:17 -0400 Received: by mail-wm0-f47.google.com with SMTP id v199so90223311wmv.0 for ; Wed, 22 Jun 2016 07:35:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LPnZndCp902PTZaZWQrM/j6C8q/ebPvz3tx2sU8myF8=; b=XMi3SZklVDo0QHify9UDpij/y0YslCWcWtrus6nYmLVK+5OkYhrEXQW1FGbkLjNCMd Ttl5AkG/Nw//AEeVPNsKVrg85v79Zt+L6tTcxL84Mr2C4QsKL2N1sHVaISfRYB7Du7zg fDxKG7sQ7umjA7b+edjwlc1hTpRBl4w6AzAuJNjy97tqlQrA1nvUaygqrufAzSXacB5N C+QO+xTNw0b+grCgExQjv0A5Q1HbUlyisejluyOU/wpuhHO0osxMnBdHbdxev3CRuU6+ tm9kUUPS+h1zPy6Djr+WD2tERP1PQvzfpUWHd5Cu2lead6FMKqbt6428klRwCIrkQx4l htfA== X-Gm-Message-State: ALyK8tIqpPb/vkjJOjni5nAWOElH0Ysw3L8CzJYr5tM0uS/oIEBTF1odF8LrWX3ZBWZ0DLYM X-Received: by 10.28.194.87 with SMTP id s84mr8562075wmf.59.1466606113836; Wed, 22 Jun 2016 07:35:13 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id u71sm930666wmu.13.2016.06.22.07.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jun 2016 07:35:12 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 1/8] vfs: new d_allocate method Date: Wed, 22 Jun 2016 16:35:03 +0200 Message-Id: <1466606110-24297-2-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1466606110-24297-1-git-send-email-mszeredi@redhat.com> References: <1466606110-24297-1-git-send-email-mszeredi@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow filesystem to initialize dentry (->d_fsdata to be explicit) at allocation time. Signed-off-by: Miklos Szeredi --- Documentation/filesystems/Locking | 2 ++ Documentation/filesystems/vfs.txt | 3 +++ fs/dcache.c | 11 +++++++++++ include/linux/dcache.h | 1 + 4 files changed, 17 insertions(+) diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index 75eea7ce3d7c..6da7d7363709 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking @@ -15,6 +15,7 @@ prototypes: int (*d_compare)(const struct dentry *, const struct dentry *, unsigned int, const char *, const struct qstr *); int (*d_delete)(struct dentry *); + int (*d_allocate)(struct dentry *); void (*d_release)(struct dentry *); void (*d_iput)(struct dentry *, struct inode *); char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen); @@ -28,6 +29,7 @@ d_weak_revalidate:no no yes no d_hash no no no maybe d_compare: yes no no maybe d_delete: no yes no no +d_allocate: no no yes no d_release: no no yes no d_prune: no yes no no d_iput: no no yes no diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index c61a223ef3ff..4d8f1a5d8936 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt @@ -933,6 +933,7 @@ struct dentry_operations { int (*d_compare)(const struct dentry *, const struct dentry *, unsigned int, const char *, const struct qstr *); int (*d_delete)(const struct dentry *); + int (*d_allocate)(struct dentry *); void (*d_release)(struct dentry *); void (*d_iput)(struct dentry *, struct inode *); char *(*d_dname)(struct dentry *, char *, int); @@ -1003,6 +1004,8 @@ struct dentry_operations { always cache a reachable dentry. d_delete must be constant and idempotent. + d_allocate: called when a dentry is really allocated + d_release: called when a dentry is really deallocated d_iput: called when a dentry loses its inode (just prior to its diff --git a/fs/dcache.c b/fs/dcache.c index 817c243c1ff1..dc573af50edc 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1559,6 +1559,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) { struct dentry *dentry; char *dname; + int err; dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); if (!dentry) @@ -1617,6 +1618,16 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) INIT_LIST_HEAD(&dentry->d_child); d_set_d_op(dentry, dentry->d_sb->s_d_op); + if (dentry->d_op && dentry->d_op->d_allocate) { + err = dentry->d_op->d_allocate(dentry); + if (err) { + if (dname_external(dentry)) + kfree(external_name(dentry)); + kmem_cache_free(dentry_cache, dentry); + return NULL; + } + } + this_cpu_inc(nr_dentry); return dentry; diff --git a/include/linux/dcache.h b/include/linux/dcache.h index f28100f6b556..a2f01284b277 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -133,6 +133,7 @@ struct dentry_operations { int (*d_compare)(const struct dentry *, const struct dentry *, unsigned int, const char *, const struct qstr *); int (*d_delete)(const struct dentry *); + int (*d_allocate)(struct dentry *); void (*d_release)(struct dentry *); void (*d_prune)(struct dentry *); void (*d_iput)(struct dentry *, struct inode *);