Skip to content

Commit bae45de

Browse files
chrismason-xxDavid Woodhouse
authored andcommitted
Btrfs: add dir inode index
Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent b1a4d96 commit bae45de

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

‎fs/btrfs/ctree.h‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,41 +282,42 @@ struct btrfs_root {
282282
* for every name in a directory.
283283
*/
284284
#define BTRFS_DIR_ITEM_KEY 2
285+
#define BTRFS_DIR_INDEX_KEY 3
285286
/*
286287
* inline data is file data that fits in the btree.
287288
*/
288-
#define BTRFS_INLINE_DATA_KEY 3
289+
#define BTRFS_INLINE_DATA_KEY 4
289290
/*
290291
* extent data is for data that can't fit in the btree. It points to
291292
* a (hopefully) huge chunk of disk
292293
*/
293-
#define BTRFS_EXTENT_DATA_KEY 4
294+
#define BTRFS_EXTENT_DATA_KEY 5
294295
/*
295296
* csum items have the checksums for data in the extents
296297
*/
297-
#define BTRFS_CSUM_ITEM_KEY 5
298+
#define BTRFS_CSUM_ITEM_KEY 6
298299

299300
/*
300301
* root items point to tree roots. There are typically in the root
301302
* tree used by the super block to find all the other trees
302303
*/
303-
#define BTRFS_ROOT_ITEM_KEY 6
304+
#define BTRFS_ROOT_ITEM_KEY 7
304305
/*
305306
* extent items are in the extent map tree. These record which blocks
306307
* are used, and how many references there are to each block
307308
*/
308-
#define BTRFS_EXTENT_ITEM_KEY 7
309+
#define BTRFS_EXTENT_ITEM_KEY 8
309310

310311
/*
311312
* the inode map records which inode numbers are in use and where
312313
* they actually live on disk
313314
*/
314-
#define BTRFS_INODE_MAP_ITEM_KEY 8
315+
#define BTRFS_INODE_MAP_ITEM_KEY 9
315316
/*
316317
* string items are for debugging. They just store a short string of
317318
* data in the FS
318319
*/
319-
#define BTRFS_STRING_ITEM_KEY 9
320+
#define BTRFS_STRING_ITEM_KEY 10
320321

321322
static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
322323
{

‎fs/btrfs/dir-item.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
3737
name_ptr = (char *)(dir_item + 1);
3838
btrfs_memcpy(root, path->nodes[0]->b_data, name_ptr, name, name_len);
3939
btrfs_mark_buffer_dirty(path->nodes[0]);
40+
btrfs_release_path(root, path);
41+
42+
btrfs_set_key_type(&key, BTRFS_DIR_INDEX_KEY);
43+
key.offset = objectid;
44+
ret = btrfs_insert_empty_item(trans, root, path, &key, data_size);
45+
// FIXME clear the dirindex bit
46+
if (ret)
47+
goto out;
48+
49+
dir_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
50+
path->slots[0],
51+
struct btrfs_dir_item);
52+
btrfs_set_dir_objectid(dir_item, objectid);
53+
btrfs_set_dir_type(dir_item, type);
54+
btrfs_set_dir_flags(dir_item, 0);
55+
btrfs_set_dir_name_len(dir_item, name_len);
56+
name_ptr = (char *)(dir_item + 1);
57+
btrfs_memcpy(root, path->nodes[0]->b_data, name_ptr, name, name_len);
58+
btrfs_mark_buffer_dirty(path->nodes[0]);
4059
out:
4160
btrfs_release_path(root, path);
4261
btrfs_free_path(path);

‎fs/btrfs/super.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
447447
mutex_lock(&root->fs_info->fs_mutex);
448448
key.objectid = inode->i_ino;
449449
key.flags = 0;
450-
btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
450+
btrfs_set_key_type(&key, BTRFS_DIR_INDEX_KEY);
451451
key.offset = filp->f_pos;
452452
path = btrfs_alloc_path();
453453
btrfs_init_path(path);
@@ -477,7 +477,7 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
477477
item = leaf->items + slot;
478478
if (btrfs_disk_key_objectid(&item->key) != key.objectid)
479479
break;
480-
if (btrfs_disk_key_type(&item->key) != BTRFS_DIR_ITEM_KEY)
480+
if (btrfs_disk_key_type(&item->key) != BTRFS_DIR_INDEX_KEY)
481481
continue;
482482
if (btrfs_disk_key_offset(&item->key) < filp->f_pos)
483483
continue;

‎fs/btrfs/sysfs.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <linux/module.h>
2+
#include "ctree.h"
3+
#include "disk-io.h"
4+
#include "transaction.h"

0 commit comments

Comments
 (0)