All of lore.kernel.org
 help / color / mirror / Atom feed
From: 石祤 <linxiulei@gmail.com>
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	[thread overview]
Message-ID: <20170531035423.70970-2-leilei.lin@alibaba-inc.com> (raw)
In-Reply-To: <20170531035423.70970-1-leilei.lin@alibaba-inc.com>

From: "leilei.lin" <leilei.lin@alibaba-inc.com>

locklessly and integrally copy dentry name. It will be used later for
bugfix

Signed-off-by: leilei.lin <leilei.lin@alibaba-inc.com>
---
 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.. */
 
 /**
-- 
2.8.4.31.g9ed660f

  reply	other threads:[~2017-05-31  3:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31  3:54 [PATCH 0/2] fsnotify: fix mem overwritten 石祤
2017-05-31  3:54 ` 石祤 [this message]
2017-05-31  3:54 ` [PATCH 2/2] fsnotify: use method copy_dname copying filename 石祤
2017-08-04  3:58   ` 林守磊
2017-08-04  3:58     ` 林守磊
2017-08-04  5:18     ` Al Viro
2017-08-04  5:18       ` Al Viro
2017-08-04  5:18       ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170531035423.70970-2-leilei.lin@alibaba-inc.com \
    --to=linxiulei@gmail.com \
    --cc=leilei.lin@alibaba-inc.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zhiche.yy@alibaba-inc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.