From patchwork Wed May 31 03:54:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?UTF-8?q?=E7=9F=B3=E7=A5=A4?= X-Patchwork-Id: 9755753 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 C8629602F0 for ; Wed, 31 May 2017 03:55:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B609926785 for ; Wed, 31 May 2017 03:55:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA49D28485; Wed, 31 May 2017 03:55:14 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 686EA26785 for ; Wed, 31 May 2017 03:55:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750902AbdEaDyz (ORCPT ); Tue, 30 May 2017 23:54:55 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:36042 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751009AbdEaDyw (ORCPT ); Tue, 30 May 2017 23:54:52 -0400 Received: by mail-io0-f195.google.com with SMTP id f102so1205558ioi.3; Tue, 30 May 2017 20:54:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=8UpGZNXYyVSfkF+3qjM+3B0vSvo3WCUSCx0XFku4Wsk=; b=mwfCFWg7OFYfOJnDsDmFEWruARFX4Tako530rLABOqBf2vihbdWw/dMID4sPEXr8nW TAA+8wL9p3R1V5ZPemu/pFyIebJf3mvbWaRC8WO7vlbYmnG0Kc93P+bNgmg1G8G6Qzje PbtugYj7Tp0SnH421rmT/kXwbT5uP2DtirjLWpax/ZGxWYNm5Id9qZDXuBXzALFLUnBl 2s6AiDeI3LUApzoxNe0TlUF2lBF0BG70D75k7XihrvUCxXh6SlYijGEbStveEef34t+P Z8IvT710KslWfh0lyiAz4unmHtZELjPf0pyLZ1fC+bQNU1o8i6fvDYABAjobyL3zz1od itZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=8UpGZNXYyVSfkF+3qjM+3B0vSvo3WCUSCx0XFku4Wsk=; b=pBlydvNkRk8Zx9QyQAbF3FhU/dCsmC9ERnta4LwzjD+mCh/pPDo+I9aYkucmEzGRtS 4CWwV2sLICHk5ieX+His/e/N9u77PwqDVhk3jJ6Bd/my0fWVrKOIeMO/rgyQ/3/0wXnJ j/dYAVM/eRePbJ2UV3NGcZr/CE7husvu5ehyp0suzl2btQ7iKc2o+AFCU3jorgG8ekcO 5c1GytDI3CmwI52LDxe4cXx1mdWSEm9R+55f5BEdZmojkUBjwogpOrSNlHIiWCej7wyL 1hYAWsYewLVM3N7HKx6YczwEWITg+hK6ZyEXlQzTbr6WT4g5lE85UrW4U3jrUZTg8Z1c pPaw== X-Gm-Message-State: AODbwcCBIPMjIlYnZz6v7HEGSa/YnioUcmCt51jZ/iWNteM86E+bvyeO +/BR/m+vWXervQ== X-Received: by 10.157.22.164 with SMTP id c33mr10312114ote.247.1496202891889; Tue, 30 May 2017 20:54:51 -0700 (PDT) Received: from localhost.localdomain ([205.204.117.25]) by smtp.gmail.com with ESMTPSA id p3sm6691122oia.24.2017.05.30.20.54.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 May 2017 20:54:51 -0700 (PDT) From: "=?UTF-8?q?=E7=9F=B3=E7=A5=A4?=" X-Google-Original-From: =?UTF-8?q?=E7=9F=B3=E7=A5=A4?= To: leilei.lin@alibaba-inc.com, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, zhiche.yy@alibaba-inc.com Subject: [PATCH 1/2] fs/dcache.c: New copy_dname method Date: Wed, 31 May 2017 11:54:22 +0800 Message-Id: <20170531035423.70970-2-leilei.lin@alibaba-inc.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531035423.70970-1-leilei.lin@alibaba-inc.com> References: <20170531035423.70970-1-leilei.lin@alibaba-inc.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 From: "leilei.lin" locklessly and integrally copy dentry name. It will be used later for bugfix Signed-off-by: leilei.lin --- fs/dcache.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/dcache.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/fs/dcache.c b/fs/dcache.c index 95d71ed..056249b 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -3536,6 +3536,44 @@ void d_tmpfile(struct dentry *dentry, struct inode *inode) } EXPORT_SYMBOL(d_tmpfile); +int copy_dname(struct dentry *dentry, char **name) +{ + unsigned int seq; + const char *dname; + + /* in case that dentry was being free */ + rcu_read_lock(); + + dname = dentry->d_name.name; + + if (unlikely(!dname)) { + rcu_read_unlock(); + return 0; + } + + if (unlikely(dname != dentry->d_iname)) { + *name = kstrdup(dname, GFP_ATOMIC); + rcu_read_unlock(); + if (unlikely(!*name)) + return -ENOMEM; + + return 0; + } + + rcu_read_unlock(); + *name = kmalloc(DNAME_INLINE_LEN, GFP_KERNEL); + if (unlikely(!*name)) + return -ENOMEM; + + do { + seq = read_seqcount_begin(&dentry->d_seq); + strcpy(*name, dname); + } while (read_seqcount_retry(&dentry->d_seq, seq)); + + return 0; +} +EXPORT_SYMBOL(copy_dname); + static __initdata unsigned long dhash_entries; static int __init set_dhash_entries(char *str) { diff --git a/include/linux/dcache.h b/include/linux/dcache.h index d2e38dc..a1b2aeb 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -296,6 +296,8 @@ extern char *d_path(const struct path *, char *, int); extern char *dentry_path_raw(struct dentry *, char *, int); extern char *dentry_path(struct dentry *, char *, int); +extern int copy_dname(struct dentry *dentry, char **name); + /* Allocation counts.. */ /**