Commit c2951f32 authored by Jeff Mahoney's avatar Jeff Mahoney Committed by David Sterba

btrfs: remove old tree_root dirent processing in btrfs_real_readdir()

Commit 3de4586c (Btrfs: Allow subvolumes and snapshots anywhere
in the directory tree) introduced the current system of placing
snapshots in the directory tree.  It also introduced the behavior of
creating the snapshot and then creating the directory entries for it.

We've kept this code around for compatibility reasons, but it turns
out that no file systems with the old tree_root based snapshots can
be mounted on newer (>= 2009) kernels anyway.  About a month after the
above commit, commit 2a7108ad (Btrfs: rev the disk format for the
inode compat and csum selection changes) landed, changing the superblock
magic number.

As a result, we know that we'll never encounter tree_root-based dirents
or have to deal with skipping our own snapshot dirents.  Since that
also means that we're now only iterating over DIR_INDEX items, which only
contain one directory entry per leaf item, we don't need to loop over
the leaf item contents anymore either.
Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent d1111a75
...@@ -5804,20 +5804,13 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) ...@@ -5804,20 +5804,13 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
int slot; int slot;
unsigned char d_type; unsigned char d_type;
int over = 0; int over = 0;
u32 di_cur;
u32 di_total;
u32 di_len;
int key_type = BTRFS_DIR_INDEX_KEY;
char tmp_name[32]; char tmp_name[32];
char *name_ptr; char *name_ptr;
int name_len; int name_len;
int is_curr = 0; /* ctx->pos points to the current index? */ int is_curr = 0; /* ctx->pos points to the current index? */
bool emitted; bool emitted;
bool put = false; bool put = false;
struct btrfs_key location;
/* FIXME, use a real flag for deciding about the key type */
if (root->fs_info->tree_root == root)
key_type = BTRFS_DIR_ITEM_KEY;
if (!dir_emit_dots(file, ctx)) if (!dir_emit_dots(file, ctx))
return 0; return 0;
...@@ -5828,14 +5821,11 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) ...@@ -5828,14 +5821,11 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
path->reada = READA_FORWARD; path->reada = READA_FORWARD;
if (key_type == BTRFS_DIR_INDEX_KEY) { INIT_LIST_HEAD(&ins_list);
INIT_LIST_HEAD(&ins_list); INIT_LIST_HEAD(&del_list);
INIT_LIST_HEAD(&del_list); put = btrfs_readdir_get_delayed_items(inode, &ins_list, &del_list);
put = btrfs_readdir_get_delayed_items(inode, &ins_list,
&del_list);
}
key.type = key_type; key.type = BTRFS_DIR_INDEX_KEY;
key.offset = ctx->pos; key.offset = ctx->pos;
key.objectid = btrfs_ino(inode); key.objectid = btrfs_ino(inode);
...@@ -5861,85 +5851,54 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) ...@@ -5861,85 +5851,54 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
if (found_key.objectid != key.objectid) if (found_key.objectid != key.objectid)
break; break;
if (found_key.type != key_type) if (found_key.type != BTRFS_DIR_INDEX_KEY)
break; break;
if (found_key.offset < ctx->pos) if (found_key.offset < ctx->pos)
goto next; goto next;
if (key_type == BTRFS_DIR_INDEX_KEY && if (btrfs_should_delete_dir_index(&del_list, found_key.offset))
btrfs_should_delete_dir_index(&del_list,
found_key.offset))
goto next; goto next;
ctx->pos = found_key.offset; ctx->pos = found_key.offset;
is_curr = 1; is_curr = 1;
di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item); di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
di_cur = 0; if (verify_dir_item(root, leaf, di))
di_total = btrfs_item_size(leaf, item); goto next;
while (di_cur < di_total) {
struct btrfs_key location;
if (verify_dir_item(root, leaf, di))
break;
name_len = btrfs_dir_name_len(leaf, di); name_len = btrfs_dir_name_len(leaf, di);
if (name_len <= sizeof(tmp_name)) { if (name_len <= sizeof(tmp_name)) {
name_ptr = tmp_name; name_ptr = tmp_name;
} else { } else {
name_ptr = kmalloc(name_len, GFP_KERNEL); name_ptr = kmalloc(name_len, GFP_KERNEL);
if (!name_ptr) { if (!name_ptr) {
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err;
}
} }
read_extent_buffer(leaf, name_ptr, }
(unsigned long)(di + 1), name_len); read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1),
name_len);
d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)];
btrfs_dir_item_key_to_cpu(leaf, di, &location);
d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)];
btrfs_dir_item_key_to_cpu(leaf, di, &location);
/* is this a reference to our own snapshot? If so over = !dir_emit(ctx, name_ptr, name_len, location.objectid,
* skip it. d_type);
*
* In contrast to old kernels, we insert the snapshot's
* dir item and dir index after it has been created, so
* we won't find a reference to our own snapshot. We
* still keep the following code for backward
* compatibility.
*/
if (location.type == BTRFS_ROOT_ITEM_KEY &&
location.objectid == root->root_key.objectid) {
over = 0;
goto skip;
}
over = !dir_emit(ctx, name_ptr, name_len,
location.objectid, d_type);
skip: if (name_ptr != tmp_name)
if (name_ptr != tmp_name) kfree(name_ptr);
kfree(name_ptr);
if (over)
goto nopos;
emitted = true; emitted = true;
di_len = btrfs_dir_name_len(leaf, di) + if (over)
btrfs_dir_data_len(leaf, di) + sizeof(*di); goto nopos;
di_cur += di_len;
di = (struct btrfs_dir_item *)((char *)di + di_len);
}
next: next:
path->slots[0]++; path->slots[0]++;
} }
if (key_type == BTRFS_DIR_INDEX_KEY) { if (is_curr)
if (is_curr) ctx->pos++;
ctx->pos++; ret = btrfs_readdir_delayed_dir_index(ctx, &ins_list, &emitted);
ret = btrfs_readdir_delayed_dir_index(ctx, &ins_list, &emitted); if (ret)
if (ret) goto nopos;
goto nopos;
}
/* /*
* If we haven't emitted any dir entry, we must not touch ctx->pos as * If we haven't emitted any dir entry, we must not touch ctx->pos as
...@@ -5970,12 +5929,10 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) ...@@ -5970,12 +5929,10 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
* last entry requires it because doing so has broken 32bit apps * last entry requires it because doing so has broken 32bit apps
* in the past. * in the past.
*/ */
if (key_type == BTRFS_DIR_INDEX_KEY) { if (ctx->pos >= INT_MAX)
if (ctx->pos >= INT_MAX) ctx->pos = LLONG_MAX;
ctx->pos = LLONG_MAX; else
else ctx->pos = INT_MAX;
ctx->pos = INT_MAX;
}
nopos: nopos:
ret = 0; ret = 0;
err: err:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment