lkml.org 
[lkml]   [2018]   [Jun]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [CFT][PATCH] kernfs: Correct kernfs directory seeks.
"Hatayama, Daisuke" <d.hatayama@jp.fujitsu.com> writes:

>> >> +
>> >> + /* Is the saved position usable? */
>> >> + if (saved) {
>> >> + /* Proper parent and hash? */
>> >> + if ((parent != saved->parent) || (saved->hash != hash)) {
>> >> + saved = NULL;
>> >
>> > name is uninitialized in this path.
>>
>> It is. name is initialized to "" see above.
>>
>
> Or when either of the conditions is true, it has resulted in some inconsistent state, right?
> So, why not terminating this session of readdir() immediately by
> returning NULL just as when off is turned out to be invalid?

What I have above is not the clearest, and in fact the logic could be
better.

The fundamental challenge is because hash collisions are possible a file
offset does not hold complete position information in a directory.

So the kernfs node that is to be read/displayed next is saved in the
struct file. The it is tested if the saved kernfs node is usable
for finding the location in the directory. Several things may have
gone wrong.

- Someone may have called seekdir.
- The saved kernfs node may have been renamed.
- The saved kernfs node may have been moved to a different directory in
kernfs.
- the saved kernfs node may have been deleted.

If any of those are true the code needs to do the rbtree lookup.

If the kernfs node has been deleted or moved to a different directory we
can safely use it's name while performing the rbtree lookup. Which in
the event of a hash collision will be more accurate in finding our old
location, and preventing the same directory entry being returned
multiple times.

Which is completely different than if the directory offset is an invalid
value that will never point to any directory entries.

Eric




\
 
 \ /
  Last update: 2018-06-05 17:33    [W:0.053 / U:3.524 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site