From patchwork Tue Jun 28 09:47:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9202423 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 E61AE60757 for ; Tue, 28 Jun 2016 09:48:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5C19285D0 for ; Tue, 28 Jun 2016 09:48:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA768285F9; Tue, 28 Jun 2016 09:48:02 +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 78F70285D0 for ; Tue, 28 Jun 2016 09:48:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752116AbcF1Jri (ORCPT ); Tue, 28 Jun 2016 05:47:38 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:37719 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752023AbcF1Jrg (ORCPT ); Tue, 28 Jun 2016 05:47:36 -0400 Received: by mail-wm0-f45.google.com with SMTP id a66so19126988wme.0 for ; Tue, 28 Jun 2016 02:47:36 -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; bh=vElB5NOTghD8a7D5KHD7YJMciAqn39msJ+vMgPOxy7g=; b=AIcXKRVsKGTFqIgm80NkI/fuv7fLYk1Af7HDfcse8rQttFj2z+A6cBRHM7ZRqWsJhX iuFQkMaIdC7/JkbHqOEYjX6Gmf48fbSjB8OvvxwvqakbAQSegY/0MhaNmsmFcc1AEGnj 89EAGES4SwSdJEMN29lDILP5C0s47tUYAaawXIJgx2Pj6BAFslNbzFVGwSBm+Loe12kq xetmoD8Syd5r+Qu6JjTvQUHWTmdGdUE4U/rbpIy8TBPt2pdctvyZ2oHlLXXGKDdzbw3K Ms2INTFmn59FEiP7MOBdA+BdgKpywu8P3JQoW2kHX87tbLE99EY/8uKbHRSoYV0vSup5 TUCA== X-Gm-Message-State: ALyK8tKb5PmI84YCX+nKk3GNA/cXm0pewfaYTLH1dPWgljo1pnCfufIatXfLfqNN4mIxFEIO X-Received: by 10.194.223.98 with SMTP id qt2mr289361wjc.89.1467107255401; Tue, 28 Jun 2016 02:47:35 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (563B8CE9.dsl.pool.telekom.hu. [86.59.140.233]) by smtp.gmail.com with ESMTPSA id h8sm5936686wjg.9.2016.06.28.02.47.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jun 2016 02:47:34 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH for 4.8] vfs: new d_init method Date: Tue, 28 Jun 2016 11:47:32 +0200 Message-Id: <1467107252-21165-1-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 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 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..fbae98e01606 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_init)(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_init: 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..bf816aba2288 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_init)(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_init: called when a dentry is 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..9bba3e3d7c94 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_init) { + err = dentry->d_op->d_init(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..5e523c7f0d8a 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_init)(struct dentry *); void (*d_release)(struct dentry *); void (*d_prune)(struct dentry *); void (*d_iput)(struct dentry *, struct inode *);