diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-02-09 14:06:44 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2018-05-22 00:44:18 -0400 |
commit | bb80cdf33ce21e02778ec97acdca73150b9c73e5 (patch) | |
tree | 08b0ade1350820d015ebca2451ae3410bdf9fe33 | |
parent | 10188409ef0f0c2f5b0618f8a41104c395713bf8 (diff) |
bcachefs: -o verbose_init, more error messages
for tracing problems with mount
-rw-r--r-- | fs/bcachefs/bcachefs.h | 6 | ||||
-rw-r--r-- | fs/bcachefs/btree_cache.c | 29 | ||||
-rw-r--r-- | fs/bcachefs/checksum.c | 44 | ||||
-rw-r--r-- | fs/bcachefs/compress.c | 38 | ||||
-rw-r--r-- | fs/bcachefs/fs-io.c | 9 | ||||
-rw-r--r-- | fs/bcachefs/journal.c | 15 | ||||
-rw-r--r-- | fs/bcachefs/opts.h | 3 | ||||
-rw-r--r-- | fs/bcachefs/super-io.c | 16 | ||||
-rw-r--r-- | fs/bcachefs/super.c | 52 |
9 files changed, 148 insertions, 64 deletions
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index cb9906c5bd22..cce11723d6ba 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -231,6 +231,12 @@ do { \ bch_info(c, fmt, ##__VA_ARGS__); \ } while (0) +#define pr_verbose_init(opts, fmt, ...) \ +do { \ + if (opt_get(opts, verbose_init)) \ + pr_info(fmt, ##__VA_ARGS__); \ +} while (0) + /* Parameters that are useful for debugging, but should always be compiled in: */ #define BCH_DEBUG_PARAMS_ALWAYS() \ BCH_DEBUG_PARAM(key_merging_disabled, \ diff --git a/fs/bcachefs/btree_cache.c b/fs/bcachefs/btree_cache.c index 0bde449ec745..7eae4d20a951 100644 --- a/fs/bcachefs/btree_cache.c +++ b/fs/bcachefs/btree_cache.c @@ -373,19 +373,23 @@ int bch2_fs_btree_cache_init(struct bch_fs *c) { struct btree_cache *bc = &c->btree_cache; unsigned i; - int ret; + int ret = 0; + + pr_verbose_init(c->opts, ""); ret = rhashtable_init(&bc->table, &bch_btree_cache_params); if (ret) - return ret; + goto out; bc->table_init_done = true; bch2_recalc_btree_reserve(c); for (i = 0; i < bc->reserve; i++) - if (!btree_node_mem_alloc(c, GFP_KERNEL)) - return -ENOMEM; + if (!btree_node_mem_alloc(c, GFP_KERNEL)) { + ret = -ENOMEM; + goto out; + } list_splice_init(&bc->live, &bc->freeable); @@ -393,12 +397,16 @@ int bch2_fs_btree_cache_init(struct bch_fs *c) mutex_init(&c->verify_lock); c->verify_ondisk = kvpmalloc(btree_bytes(c), GFP_KERNEL); - if (!c->verify_ondisk) - return -ENOMEM; + if (!c->verify_ondisk) { + ret = -ENOMEM; + goto out; + } c->verify_data = btree_node_mem_alloc(c, GFP_KERNEL); - if (!c->verify_data) - return -ENOMEM; + if (!c->verify_data) { + ret = -ENOMEM; + goto out; + } list_del_init(&c->verify_data->list); #endif @@ -408,8 +416,9 @@ int bch2_fs_btree_cache_init(struct bch_fs *c) bc->shrink.seeks = 4; bc->shrink.batch = btree_pages(c) * 2; register_shrinker(&bc->shrink); - - return 0; +out: + pr_verbose_init(c->opts, "ret %i", ret); + return ret; } void bch2_fs_btree_cache_init_early(struct btree_cache *bc) diff --git a/fs/bcachefs/checksum.c b/fs/bcachefs/checksum.c index 087558538835..56bd99fd8b71 100644 --- a/fs/bcachefs/checksum.c +++ b/fs/bcachefs/checksum.c @@ -219,12 +219,16 @@ int bch2_chacha_encrypt_key(struct bch_key *key, struct nonce nonce, crypto_alloc_skcipher("chacha20", 0, 0); int ret; - if (!chacha20) + if (!chacha20) { + pr_err("error requesting chacha20 module: %li", PTR_ERR(chacha20)); return PTR_ERR(chacha20); + } ret = crypto_skcipher_setkey(chacha20, (void *) key, sizeof(*key)); - if (ret) + if (ret) { + pr_err("crypto_skcipher_setkey() error: %i", ret); goto err; + } do_encrypt(chacha20, nonce, buf, len); err: @@ -567,7 +571,7 @@ int bch2_decrypt_sb_key(struct bch_fs *c, ret = bch2_request_key(c->disk_sb, &user_key); if (ret) { - bch_err(c, "error requesting encryption key"); + bch_err(c, "error requesting encryption key: %i", ret); goto err; } @@ -594,13 +598,19 @@ static int bch2_alloc_ciphers(struct bch_fs *c) { if (!c->chacha20) c->chacha20 = crypto_alloc_skcipher("chacha20", 0, 0); - if (IS_ERR(c->chacha20)) + if (IS_ERR(c->chacha20)) { + bch_err(c, "error requesting chacha20 module: %li", + PTR_ERR(c->chacha20)); return PTR_ERR(c->chacha20); + } if (!c->poly1305) c->poly1305 = crypto_alloc_shash("poly1305", 0, 0); - if (IS_ERR(c->poly1305)) + if (IS_ERR(c->poly1305)) { + bch_err(c, "error requesting poly1305 module: %li", + PTR_ERR(c->poly1305)); return PTR_ERR(c->poly1305); + } return 0; } @@ -660,7 +670,7 @@ int bch2_enable_encryption(struct bch_fs *c, bool keyed) if (keyed) { ret = bch2_request_key(c->disk_sb, &user_key); if (ret) { - bch_err(c, "error requesting encryption key"); + bch_err(c, "error requesting encryption key: %i", ret); goto err; } @@ -707,27 +717,35 @@ int bch2_fs_encryption_init(struct bch_fs *c) { struct bch_sb_field_crypt *crypt; struct bch_key key; - int ret; + int ret = 0; + + pr_verbose_init(c->opts, ""); c->sha256 = crypto_alloc_shash("sha256", 0, 0); - if (IS_ERR(c->sha256)) - return PTR_ERR(c->sha256); + if (IS_ERR(c->sha256)) { + bch_err(c, "error requesting sha256 module"); + ret = PTR_ERR(c->sha256); + goto out; + } crypt = bch2_sb_get_crypt(c->disk_sb); if (!crypt) - return 0; + goto out; ret = bch2_alloc_ciphers(c); if (ret) - return ret; + goto out; ret = bch2_decrypt_sb_key(c, crypt, &key); if (ret) - goto err; + goto out; ret = crypto_skcipher_setkey(c->chacha20, (void *) &key.key, sizeof(key.key)); -err: + if (ret) + goto out; +out: memzero_explicit(&key, sizeof(key)); + pr_verbose_init(c->opts, "ret %i", ret); return ret; } diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c index 64079981d357..26fd453268b4 100644 --- a/fs/bcachefs/compress.c +++ b/fs/bcachefs/compress.c @@ -441,18 +441,22 @@ unsigned bch2_bio_compress(struct bch_fs *c, int bch2_check_set_has_compressed_data(struct bch_fs *c, unsigned compression_type) { + int ret = 0; + + pr_verbose_init(c->opts, ""); + switch (compression_type) { case BCH_COMPRESSION_OPT_NONE: - return 0; + goto out; case BCH_COMPRESSION_OPT_LZ4: if (bch2_sb_test_feature(c->disk_sb, BCH_FEATURE_LZ4)) - return 0; + goto out; bch2_sb_set_feature(c->disk_sb, BCH_FEATURE_LZ4); break; case BCH_COMPRESSION_OPT_GZIP: if (bch2_sb_test_feature(c->disk_sb, BCH_FEATURE_GZIP)) - return 0; + goto out; bch2_sb_set_feature(c->disk_sb, BCH_FEATURE_GZIP); break; @@ -460,7 +464,10 @@ int bch2_check_set_has_compressed_data(struct bch_fs *c, BUG(); } - return bch2_fs_compress_init(c); + ret = bch2_fs_compress_init(c); +out: + pr_verbose_init(c->opts, "ret %i", ret); + return ret; } void bch2_fs_compress_exit(struct bch_fs *c) @@ -478,24 +485,26 @@ void bch2_fs_compress_exit(struct bch_fs *c) int bch2_fs_compress_init(struct bch_fs *c) { unsigned order = get_order(c->sb.encoded_extent_max << 9); - int ret; + int ret = 0; + + pr_verbose_init(c->opts, ""); if (!bch2_sb_test_feature(c->disk_sb, BCH_FEATURE_LZ4) && !bch2_sb_test_feature(c->disk_sb, BCH_FEATURE_GZIP)) - return 0; + goto out; if (!mempool_initialized(&c->compression_bounce[READ])) { ret = mempool_init_page_pool(&c->compression_bounce[READ], 1, order); if (ret) - return ret; + goto out; } if (!mempool_initialized(&c->compression_bounce[WRITE])) { ret = mempool_init_page_pool(&c->compression_bounce[WRITE], 1, order); if (ret) - return ret; + goto out; } if (!mempool_initialized(&c->lz4_workspace_pool) && @@ -503,15 +512,18 @@ int bch2_fs_compress_init(struct bch_fs *c) ret = mempool_init_kmalloc_pool(&c->lz4_workspace_pool, 1, LZ4_MEM_COMPRESS); if (ret) - return ret; + goto out; } if (!c->zlib_workspace && bch2_sb_test_feature(c->disk_sb, BCH_FEATURE_GZIP)) { c->zlib_workspace = vmalloc(COMPRESSION_WORKSPACE_SIZE); - if (!c->zlib_workspace) - return -ENOMEM; + if (!c->zlib_workspace) { + ret = -ENOMEM; + goto out; + } } - - return 0; +out: + pr_verbose_init(c->opts, "ret %i", ret); + return ret; } diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c index af215f5b5a53..d84e2d76c15f 100644 --- a/fs/bcachefs/fs-io.c +++ b/fs/bcachefs/fs-io.c @@ -2691,6 +2691,10 @@ void bch2_fs_fsio_exit(struct bch_fs *c) int bch2_fs_fsio_init(struct bch_fs *c) { + int ret = 0; + + pr_verbose_init(c->opts, ""); + if (bioset_init(&c->writepage_bioset, 4, offsetof(struct bch_writepage_io, op.op.wbio.bio), BIOSET_NEED_BVECS) || @@ -2700,9 +2704,10 @@ int bch2_fs_fsio_init(struct bch_fs *c) bioset_init(&c->dio_write_bioset, 4, offsetof(struct dio_write, iop.op.wbio.bio), BIOSET_NEED_BVECS)) - return -ENOMEM; + ret = -ENOMEM; - return 0; + pr_verbose_init(c->opts, "ret %i", ret); + return ret; } #endif /* NO_BCACHEFS_FS */ diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c index 03506217041b..7dc0663201da 100644 --- a/fs/bcachefs/journal.c +++ b/fs/bcachefs/journal.c @@ -2948,7 +2948,11 @@ void bch2_fs_journal_exit(struct journal *j) int bch2_fs_journal_init(struct journal *j) { + struct bch_fs *c = container_of(j, struct bch_fs, journal); static struct lock_class_key res_key; + int ret = 0; + + pr_verbose_init(c->opts, ""); spin_lock_init(&j->lock); spin_lock_init(&j->err_lock); @@ -2974,12 +2978,15 @@ int bch2_fs_journal_init(struct journal *j) if (!(init_fifo(&j->pin, JOURNAL_PIN, GFP_KERNEL)) || !(j->buf[0].data = kvpmalloc(j->buf[0].size, GFP_KERNEL)) || - !(j->buf[1].data = kvpmalloc(j->buf[1].size, GFP_KERNEL))) - return -ENOMEM; + !(j->buf[1].data = kvpmalloc(j->buf[1].size, GFP_KERNEL))) { + ret = -ENOMEM; + goto out; + } j->pin.front = j->pin.back = 1; - - return 0; +out: + pr_verbose_init(c->opts, "ret %i", ret); + return ret; } /* debug: */ diff --git a/fs/bcachefs/opts.h b/fs/bcachefs/opts.h index 5d42dd5f570d..e722d1af388c 100644 --- a/fs/bcachefs/opts.h +++ b/fs/bcachefs/opts.h @@ -127,6 +127,9 @@ enum opt_type { BCH_OPT(verbose_recovery, u8, OPT_MOUNT, \ OPT_BOOL(), \ NO_SB_OPT, false) \ + BCH_OPT(verbose_init, u8, OPT_MOUNT, \ + OPT_BOOL(), \ + NO_SB_OPT, false) \ BCH_OPT(journal_flush_disabled, u8, OPT_RUNTIME, \ OPT_BOOL(), \ NO_SB_OPT, false) \ diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c index 445ac9a8dd3b..c747391707b3 100644 --- a/fs/bcachefs/super-io.c +++ b/fs/bcachefs/super-io.c @@ -546,6 +546,8 @@ int bch2_read_super(const char *path, struct bch_opts *opts, __le64 *i; int ret; + pr_verbose_init(*opts, ""); + memset(sb, 0, sizeof(*sb)); sb->mode = FMODE_READ; @@ -566,8 +568,10 @@ int bch2_read_super(const char *path, struct bch_opts *opts, opt_set(*opts, nochanges, true); } - if (IS_ERR(sb->bdev)) - return PTR_ERR(sb->bdev); + if (IS_ERR(sb->bdev)) { + ret = PTR_ERR(sb->bdev); + goto out; + } err = "cannot allocate memory"; ret = __bch2_super_realloc(sb, 0); @@ -638,12 +642,14 @@ got_super: if (sb->mode & FMODE_WRITE) bdev_get_queue(sb->bdev)->backing_dev_info->capabilities |= BDI_CAP_STABLE_WRITES; - - return 0; + ret = 0; +out: + pr_verbose_init(*opts, "ret %i", ret); + return ret; err: bch2_free_super(sb); pr_err("error reading superblock: %s", err); - return ret; + goto out; } /* write superblock: */ diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 2b0542284982..d450bc48b5b1 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -507,9 +507,11 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) struct bch_fs *c; unsigned i, iter_size; + pr_verbose_init(opts, ""); + c = kvpmalloc(sizeof(struct bch_fs), GFP_KERNEL|__GFP_ZERO); if (!c) - return NULL; + goto out; __module_get(THIS_MODULE); @@ -646,10 +648,13 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) kobject_init(&c->internal, &bch2_fs_internal_ktype); kobject_init(&c->opts_dir, &bch2_fs_opts_dir_ktype); kobject_init(&c->time_stats, &bch2_fs_time_stats_ktype); +out: + pr_verbose_init(opts, "ret %i", c ? 0 : -ENOMEM); return c; err: bch2_fs_free(c); - return NULL; + c = NULL; + goto out; } static const char *__bch2_fs_online(struct bch_fs *c) @@ -1084,14 +1089,17 @@ static int bch2_dev_sysfs_online(struct bch_fs *c, struct bch_dev *ca) static int bch2_dev_alloc(struct bch_fs *c, unsigned dev_idx) { struct bch_member *member; - struct bch_dev *ca; + struct bch_dev *ca = NULL; + int ret = 0; + + pr_verbose_init(c->opts, ""); if (bch2_fs_init_fault("dev_alloc")) - return -ENOMEM; + goto err; ca = kzalloc(sizeof(*ca), GFP_KERNEL); if (!ca) - return -ENOMEM; + goto err; kobject_init(&ca->kobj, &bch2_dev_ktype); init_completion(&ca->ref_completion); @@ -1133,11 +1141,14 @@ static int bch2_dev_alloc(struct bch_fs *c, unsigned dev_idx) if (bch2_dev_sysfs_online(c, ca)) pr_warn("error creating sysfs objects"); - - return 0; +out: + pr_verbose_init(c->opts, "ret %i", ret); + return ret; err: - bch2_dev_free(ca); - return -ENOMEM; + if (ca) + bch2_dev_free(ca); + ret = -ENOMEM; + goto out; } static int __bch2_dev_online(struct bch_fs *c, struct bch_sb_handle *sb) @@ -1701,11 +1712,17 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices, const char *err; int ret = -ENOMEM; - if (!nr_devices) - return ERR_PTR(-EINVAL); + pr_verbose_init(opts, ""); + + if (!nr_devices) { + c = ERR_PTR(-EINVAL); + goto out2; + } - if (!try_module_get(THIS_MODULE)) - return ERR_PTR(-ENODEV); + if (!try_module_get(THIS_MODULE)) { + c = ERR_PTR(-ENODEV); + goto out2; + } sb = kcalloc(nr_devices, sizeof(*sb), GFP_KERNEL); if (!sb) @@ -1760,8 +1777,11 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices, if (err) goto err_print; +out: kfree(sb); module_put(THIS_MODULE); +out2: + pr_verbose_init(opts, "ret %i", PTR_ERR_OR_ZERO(c)); return c; err_print: pr_err("bch_fs_open err opening %s: %s", @@ -1770,12 +1790,10 @@ err_print: err: if (c) bch2_fs_stop(c); - for (i = 0; i < nr_devices; i++) bch2_free_super(&sb[i]); - kfree(sb); - module_put(THIS_MODULE); - return ERR_PTR(ret); + c = ERR_PTR(ret); + goto out; } static const char *__bch2_fs_open_incremental(struct bch_sb_handle *sb, |