History

ovl: discard independent cursor in readdir()

Since the ovl_dir_cache is stable during a directory reading, the cursor of struct ovl_dir_file don't need to be an independent entry in the list of a merged directory. This patch changes *cursor* to a pointer which points to the entry in the ovl_dir_cache. After this, we don't need to check *is_cursor* either.

hujianyang committed 11 years ago

Commit 43303971 parent 6d900f51 file · +14 −24Browse files

Unified · Split

fs/overlayfs/readdir.c+14−24
@@ -24,7 +24,6 @@ struct ovl_cache_entry { · 23 unmodified lines
2424 struct list_head l_node;
2525 struct rb_node node;
2626 bool is_whiteout;
27− bool is_cursor;
2827 char name[];
2928 };
3029
@@ -49,7 +48,7 @@ struct ovl_dir_file { · 18 unmodified lines
4948 bool is_real;
5049 bool is_upper;
5150 struct ovl_dir_cache *cache;
52− struct ovl_cache_entry cursor;
51+ struct list_head *cursor;
5352 struct file *realfile;
5453 struct file *upperfile;
5554 };
@@ -97,7 +96,6 @@ static struct ovl_cache_entry *ovl_cache_entry_new(struct dentry *dir, · 41 unmodified lines
9796 p->type = d_type;
9897 p->ino = ino;
9998 p->is_whiteout = false;
100− p->is_cursor = false;
10199
102100 if (d_type == DT_CHR) {
103101 struct dentry *dentry;
@@ -196,7 +194,6 @@ static void ovl_cache_put(struct ovl_dir_file *od, struct dentry *dentry) · 92 unmodified lines
196194 {
197195 struct ovl_dir_cache *cache = od->cache;
198196
199− list_del_init(&od->cursor.l_node);
200197 WARN_ON(cache->refcount <= 0);
201198 cache->refcount--;
202199 if (!cache->refcount) {
@@ -254,6 +251,7 @@ static void ovl_dir_reset(struct file *file) · 51 unmodified lines
254251 if (cache && ovl_dentry_version_get(dentry) != cache->version) {
255252 ovl_cache_put(od, dentry);
256253 od->cache = NULL;
254+ od->cursor = NULL;
257255 }
258256 WARN_ON(!od->is_real && !OVL_TYPE_MERGE(type));
259257 if (od->is_real && OVL_TYPE_MERGE(type))
@@ -295,17 +293,16 @@ static int ovl_dir_read_merged(struct dentry *dentry, struct list_head *list) · 35 unmodified lines
295293
296294 static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos)
297295 {
298− struct ovl_cache_entry *p;
296+ struct list_head *p;
299297 loff_t off = 0;
300298
301− list_for_each_entry(p, &od->cache->entries, l_node) {
302− if (p->is_cursor)
303− continue;
299+ list_for_each(p, &od->cache->entries) {
304300 if (off >= pos)
305301 break;
306302 off++;
307303 }
308− list_move_tail(&od->cursor.l_node, &p->l_node);
304+ /* Cursor is safe since the cache is stable */
305+ od->cursor = p;
309306 }
310307
311308 static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)
@@ -344,6 +341,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx) · 32 unmodified lines
344341 {
345342 struct ovl_dir_file *od = file->private_data;
346343 struct dentry *dentry = file->f_path.dentry;
344+ struct ovl_cache_entry *p;
347345
348346 if (!ctx->pos)
349347 ovl_dir_reset(file);
@@ -362,19 +360,13 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx) · 12 unmodified lines
362360 ovl_seek_cursor(od, ctx->pos);
363361 }
364362
365− while (od->cursor.l_node.next != &od->cache->entries) {
366− struct ovl_cache_entry *p;
367−
368− p = list_entry(od->cursor.l_node.next, struct ovl_cache_entry, l_node);
369− /* Skip cursors */
370− if (!p->is_cursor) {
371− if (!p->is_whiteout) {
372− if (!dir_emit(ctx, p->name, p->len, p->ino, p->type))
373− break;
374− }
375− ctx->pos++;
376− }
377− list_move(&od->cursor.l_node, &p->l_node);
363+ while (od->cursor != &od->cache->entries) {
364+ p = list_entry(od->cursor, struct ovl_cache_entry, l_node);
365+ if (!p->is_whiteout)
366+ if (!dir_emit(ctx, p->name, p->len, p->ino, p->type))
367+ break;
368+ od->cursor = p->l_node.next;
369+ ctx->pos++;
378370 }
379371 return 0;
380372 }
@@ -493,11 +485,9 @@ static int ovl_dir_open(struct inode *inode, struct file *file) · 112 unmodified lines
493485 kfree(od);
494486 return PTR_ERR(realfile);
495487 }
496− INIT_LIST_HEAD(&od->cursor.l_node);
497488 od->realfile = realfile;
498489 od->is_real = !OVL_TYPE_MERGE(type);
499490 od->is_upper = OVL_TYPE_UPPER(type);
500− od->cursor.is_cursor = true;
501491 file->private_data = od;
502492
503493 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t