diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-07-12 21:57:26 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2018-07-16 03:46:14 -0400 |
commit | c337e6cd3314ecfb5222dc75c788a4a74efcdf85 (patch) | |
tree | 8a5c7182c43297ac35b5c7c3b6382d5a48ddac48 | |
parent | aaf424e24d6e96750317000db50e8bef4f7f6aba (diff) |
bcachefs: create lost+found when initializing fs
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r-- | fs/bcachefs/recovery.c | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c index 58aee7aeef82..f7c138d274e0 100644 --- a/fs/bcachefs/recovery.c +++ b/fs/bcachefs/recovery.c @@ -5,6 +5,7 @@ #include "btree_update.h" #include "btree_update_interior.h" #include "btree_io.h" +#include "dirent.h" #include "error.h" #include "fsck.h" #include "journal_io.h" @@ -14,6 +15,8 @@ #include <linux/stat.h> +#define QSTR(n) { { { .len = strlen(n) } }, .name = n } + struct bkey_i *btree_root_find(struct bch_fs *c, struct bch_sb_field_clean *clean, struct jset *j, @@ -233,7 +236,8 @@ int bch2_fs_recovery(struct bch_fs *c) bch2_fs_journal_start(&c->journal); err = "error starting allocator"; - if (bch2_fs_allocator_start(c)) + ret = bch2_fs_allocator_start(c); + if (ret) goto err; bch_verbose(c, "starting journal replay:"); @@ -273,8 +277,10 @@ fsck_err: int bch2_fs_initialize(struct bch_fs *c) { - struct bch_inode_unpacked inode; + struct bch_inode_unpacked root_inode, lostfound_inode; struct bkey_inode_buf packed_inode; + struct bch_hash_info root_hash_info; + struct qstr lostfound = QSTR("lost+found"); const char *err = "cannot allocate memory"; struct bch_dev *ca; LIST_HEAD(journal); @@ -307,21 +313,46 @@ int bch2_fs_initialize(struct bch_fs *c) bch2_journal_set_replay_done(&c->journal); err = "error starting allocator"; - if (bch2_fs_allocator_start(c)) + ret = bch2_fs_allocator_start(c); + if (ret) goto err; - bch2_inode_init(c, &inode, 0, 0, + bch2_inode_init(c, &root_inode, 0, 0, S_IFDIR|S_IRWXU|S_IRUGO|S_IXUGO, 0, NULL); - inode.bi_inum = BCACHEFS_ROOT_INO; - - bch2_inode_pack(&packed_inode, &inode); + root_inode.bi_inum = BCACHEFS_ROOT_INO; + root_inode.bi_nlink++; /* lost+found */ + bch2_inode_pack(&packed_inode, &root_inode); err = "error creating root directory"; - if (bch2_btree_insert(c, BTREE_ID_INODES, - &packed_inode.inode.k_i, - NULL, NULL, NULL, 0)) + ret = bch2_btree_insert(c, BTREE_ID_INODES, + &packed_inode.inode.k_i, + NULL, NULL, NULL, 0); + if (ret) goto err; + bch2_inode_init(c, &lostfound_inode, 0, 0, + S_IFDIR|S_IRWXU|S_IRUGO|S_IXUGO, 0, + &root_inode); + lostfound_inode.bi_inum = BCACHEFS_ROOT_INO + 1; + bch2_inode_pack(&packed_inode, &lostfound_inode); + + err = "error creating lost+found"; + ret = bch2_btree_insert(c, BTREE_ID_INODES, + &packed_inode.inode.k_i, + NULL, NULL, NULL, 0); + if (ret) + goto err; + + root_hash_info = bch2_hash_info_init(c, &root_inode); + + ret = bch2_dirent_create(c, BCACHEFS_ROOT_INO, &root_hash_info, DT_DIR, + &lostfound, lostfound_inode.bi_inum, NULL, + BTREE_INSERT_NOFAIL); + if (ret) + goto err; + + atomic_long_set(&c->nr_inodes, 2); + if (enabled_qtypes(c)) { ret = bch2_fs_quota_read(c); if (ret) @@ -329,7 +360,8 @@ int bch2_fs_initialize(struct bch_fs *c) } err = "error writing first journal entry"; - if (bch2_journal_meta(&c->journal)) + ret = bch2_journal_meta(&c->journal); + if (ret) goto err; mutex_lock(&c->sb_lock); |