From: Al Viro <viro@ZenIV.linux.org.uk>
To: Waiman Long <waiman.long@hp.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
"Chandramouleeswaran, Aswin" <aswin@hp.com>,
"Norton, Scott J" <scott.norton@hp.com>,
George Spelvin <linux@horizon.com>,
John Stoffel <john@stoffel.org>
Subject: Re: [PATCH v2 1/1] dcache: Translating dentry into pathname without taking rename_lock
Date: Thu, 5 Sep 2013 21:46:09 +0100 [thread overview]
Message-ID: <20130905204609.GV13318@ZenIV.linux.org.uk> (raw)
In-Reply-To: <5228E992.5050901@hp.com>
On Thu, Sep 05, 2013 at 04:29:06PM -0400, Waiman Long wrote:
> It is not as simple as doing a strncpy(). The pathname was built
> from the leaf up to the root, and from the end of buffer toward the
> beginning. As it goes through the while loop, the buffer will look
> like:
>
> " /c"
> " /b/c"
> "/a/b/c"
>
> If the content of the string is unreliable, I have to do at least 2 passes:
> 1) Locate the end of the string and determine the actual length
> 2) Copy the whole string or byte-by-byte backward
No, you do not need anything of that kind. All you need is
a) don't step out of the array (which will contain NUL at the end
at all times, no matter what) and
b) generate correct output *IF* no d_move() happens while you
do that.
Nothing else matters at all. You trust the length to be correct in absense
of d_move(). You can not trust it to match the size of ->d_name.name when
d_move() is happening, but you can trust everything up to ->d_name.len *or*
the first NUL, whichever happens first, to be safe to access.
Again, the contents copied into the buffer needs to be valid only if d_move()
hasn't happened; if it has, we don't give a fuck - read_seqretry() will take
care of that. All you need to care about in that case is not oopsing the
damn thing.
static int prepend_name(char **buffer, int *buflen, struct qstr *name)
{
const char *s = ACCESS_ONCE(name->name);
unsigned len = ACCESS_ONCE(name->len);
char *p;
*buflen -= len;
if (*buflen < 0)
return -ENAMETOOLONG;
p = *buffer -= len;
while (len--) {
c = *s++;
if (!c)
break;
*p++ = c;
}
return 0;
}
And that's *all* - just call that under rcu_read_lock() and within
seq = read_seqbegin(&rename_lock)/read_seqretry(&rename_lock, seq)
loop over the whole prepend_path/path_with_deleted/__dentry_path
thing.
next prev parent reply other threads:[~2013-09-05 20:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-05 18:55 [PATCH v2 0/1] dcache: Translating dentry into pathname without taking rename_lock Waiman Long
2013-09-05 18:55 ` [PATCH v2 1/1] " Waiman Long
2013-09-05 19:35 ` Linus Torvalds
2013-09-05 20:29 ` Waiman Long
2013-09-05 20:42 ` Linus Torvalds
2013-09-06 2:01 ` Waiman Long
2013-09-06 4:54 ` Linus Torvalds
2013-09-05 20:46 ` Al Viro [this message]
2013-09-05 21:27 ` Linus Torvalds
2013-09-05 20:04 ` Al Viro
2013-09-05 20:43 ` Waiman Long
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=20130905204609.GV13318@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=aswin@hp.com \
--cc=john@stoffel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@horizon.com \
--cc=scott.norton@hp.com \
--cc=torvalds@linux-foundation.org \
--cc=waiman.long@hp.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).