Commit 03ea3962 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Log & error message improvements

 - Add a shim uuid_unparse_lower() in the kernel, since %pU doesn't work
   in userspace

 - We don't need to print the bcachefs: or the filesystem name prefix in
   userspace

 - Improve a few error messages
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 57cfdd8b
...@@ -223,8 +223,8 @@ ...@@ -223,8 +223,8 @@
#define bch2_fmt(_c, fmt) "bcachefs (%s): " fmt "\n", ((_c)->name) #define bch2_fmt(_c, fmt) "bcachefs (%s): " fmt "\n", ((_c)->name)
#define bch2_fmt_inum(_c, _inum, fmt) "bcachefs (%s inum %llu): " fmt "\n", ((_c)->name), (_inum) #define bch2_fmt_inum(_c, _inum, fmt) "bcachefs (%s inum %llu): " fmt "\n", ((_c)->name), (_inum)
#else #else
#define bch2_fmt(_c, fmt) "%s: " fmt "\n", ((_c)->name) #define bch2_fmt(_c, fmt) fmt "\n"
#define bch2_fmt_inum(_c, _inum, fmt) "%s inum %llu: " fmt "\n", ((_c)->name), (_inum) #define bch2_fmt_inum(_c, _inum, fmt) "inum %llu: " fmt "\n", (_inum)
#endif #endif
#define bch_info(c, fmt, ...) \ #define bch_info(c, fmt, ...) \
......
...@@ -967,19 +967,23 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca, ...@@ -967,19 +967,23 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
SET_BSET_BIG_ENDIAN(i, CPU_BIG_ENDIAN); SET_BSET_BIG_ENDIAN(i, CPU_BIG_ENDIAN);
b->written += sectors;
blacklisted = bch2_journal_seq_is_blacklisted(c, blacklisted = bch2_journal_seq_is_blacklisted(c,
le64_to_cpu(i->journal_seq), le64_to_cpu(i->journal_seq),
true); true);
btree_err_on(blacklisted && first, btree_err_on(blacklisted && first,
BTREE_ERR_FIXABLE, c, ca, b, i, BTREE_ERR_FIXABLE, c, ca, b, i,
"first btree node bset has blacklisted journal seq"); "first btree node bset has blacklisted journal seq (%llu)",
le64_to_cpu(i->journal_seq));
btree_err_on(blacklisted && ptr_written, btree_err_on(blacklisted && ptr_written,
BTREE_ERR_FIXABLE, c, ca, b, i, BTREE_ERR_FIXABLE, c, ca, b, i,
"found blacklisted bset in btree node with sectors_written"); "found blacklisted bset (journal seq %llu) in btree node at offset %u-%u/%u",
le64_to_cpu(i->journal_seq),
b->written, b->written + sectors, ptr_written);
b->written += sectors;
if (blacklisted && !first) if (blacklisted && !first)
continue; continue;
......
...@@ -209,7 +209,6 @@ static int btree_key_cache_fill(struct btree_trans *trans, ...@@ -209,7 +209,6 @@ static int btree_key_cache_fill(struct btree_trans *trans,
struct btree_path *ck_path, struct btree_path *ck_path,
struct bkey_cached *ck) struct bkey_cached *ck)
{ {
struct bch_fs *c = trans->c;
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
unsigned new_u64s = 0; unsigned new_u64s = 0;
...@@ -239,7 +238,7 @@ static int btree_key_cache_fill(struct btree_trans *trans, ...@@ -239,7 +238,7 @@ static int btree_key_cache_fill(struct btree_trans *trans,
new_u64s = roundup_pow_of_two(new_u64s); new_u64s = roundup_pow_of_two(new_u64s);
new_k = kmalloc(new_u64s * sizeof(u64), GFP_NOFS); new_k = kmalloc(new_u64s * sizeof(u64), GFP_NOFS);
if (!new_k) { if (!new_k) {
bch_err(c, "error allocating memory for key cache key, btree %s u64s %u", bch_err(trans->c, "error allocating memory for key cache key, btree %s u64s %u",
bch2_btree_ids[ck->key.btree_id], new_u64s); bch2_btree_ids[ck->key.btree_id], new_u64s);
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err;
......
...@@ -407,16 +407,12 @@ int bch2_rechecksum_bio(struct bch_fs *c, struct bio *bio, ...@@ -407,16 +407,12 @@ int bch2_rechecksum_bio(struct bch_fs *c, struct bio *bio,
} }
#ifdef __KERNEL__ #ifdef __KERNEL__
int bch2_request_key(struct bch_sb *sb, struct bch_key *key) static int __bch2_request_key(char *key_description, struct bch_key *key)
{ {
char key_description[60];
struct key *keyring_key; struct key *keyring_key;
const struct user_key_payload *ukp; const struct user_key_payload *ukp;
int ret; int ret;
snprintf(key_description, sizeof(key_description),
"bcachefs:%pUb", &sb->user_uuid);
keyring_key = request_key(&key_type_logon, key_description, NULL); keyring_key = request_key(&key_type_logon, key_description, NULL);
if (IS_ERR(keyring_key)) if (IS_ERR(keyring_key))
return PTR_ERR(keyring_key); return PTR_ERR(keyring_key);
...@@ -436,16 +432,10 @@ int bch2_request_key(struct bch_sb *sb, struct bch_key *key) ...@@ -436,16 +432,10 @@ int bch2_request_key(struct bch_sb *sb, struct bch_key *key)
} }
#else #else
#include <keyutils.h> #include <keyutils.h>
#include <uuid/uuid.h>
int bch2_request_key(struct bch_sb *sb, struct bch_key *key) static int __bch2_request_key(char *key_description, struct bch_key *key)
{ {
key_serial_t key_id; key_serial_t key_id;
char key_description[60];
char uuid[40];
uuid_unparse_lower(sb->user_uuid.b, uuid);
sprintf(key_description, "bcachefs:%s", uuid);
key_id = request_key("user", key_description, NULL, key_id = request_key("user", key_description, NULL,
KEY_SPEC_USER_KEYRING); KEY_SPEC_USER_KEYRING);
...@@ -459,6 +449,17 @@ int bch2_request_key(struct bch_sb *sb, struct bch_key *key) ...@@ -459,6 +449,17 @@ int bch2_request_key(struct bch_sb *sb, struct bch_key *key)
} }
#endif #endif
int bch2_request_key(struct bch_sb *sb, struct bch_key *key)
{
char key_description[60];
char uuid[40];
uuid_unparse_lower(sb->user_uuid.b, uuid);
sprintf(key_description, "bcachefs:%s", uuid);
return __bch2_request_key(key_description, key);
}
int bch2_decrypt_sb_key(struct bch_fs *c, int bch2_decrypt_sb_key(struct bch_fs *c,
struct bch_sb_field_crypt *crypt, struct bch_sb_field_crypt *crypt,
struct bch_key *key) struct bch_key *key)
......
...@@ -530,10 +530,8 @@ static int bch2_journal_replay(struct bch_fs *c) ...@@ -530,10 +530,8 @@ static int bch2_journal_replay(struct bch_fs *c)
sizeof(keys_sorted[0]), sizeof(keys_sorted[0]),
journal_sort_seq_cmp, NULL); journal_sort_seq_cmp, NULL);
if (keys->nr) { if (keys->nr)
bch_verbose(c, "starting journal replay, %zu keys", keys->nr);
replay_now_at(j, keys->journal_seq_base); replay_now_at(j, keys->journal_seq_base);
}
for (i = 0; i < keys->nr; i++) { for (i = 0; i < keys->nr; i++) {
k = keys_sorted[i]; k = keys_sorted[i];
...@@ -901,7 +899,6 @@ static int bch2_fs_initialize_subvolumes(struct bch_fs *c) ...@@ -901,7 +899,6 @@ static int bch2_fs_initialize_subvolumes(struct bch_fs *c)
static int bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans) static int bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans)
{ {
struct bch_fs *c = trans->c;
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bch_inode_unpacked inode; struct bch_inode_unpacked inode;
...@@ -915,7 +912,7 @@ static int bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans) ...@@ -915,7 +912,7 @@ static int bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans)
goto err; goto err;
if (!bkey_is_inode(k.k)) { if (!bkey_is_inode(k.k)) {
bch_err(c, "root inode not found"); bch_err(trans->c, "root inode not found");
ret = -ENOENT; ret = -ENOENT;
goto err; goto err;
} }
...@@ -1138,7 +1135,7 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1138,7 +1135,7 @@ int bch2_fs_recovery(struct bch_fs *c)
if (c->opts.norecovery) if (c->opts.norecovery)
goto out; goto out;
bch_verbose(c, "starting journal replay"); bch_verbose(c, "starting journal replay, %zu keys", c->journal_keys.nr);
err = "journal replay failed"; err = "journal replay failed";
ret = bch2_journal_replay(c); ret = bch2_journal_replay(c);
if (ret) if (ret)
......
...@@ -745,7 +745,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) ...@@ -745,7 +745,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
if (ret) if (ret)
goto err; goto err;
scnprintf(c->name, sizeof(c->name), "%pU", &c->sb.user_uuid); uuid_unparse_lower(c->sb.user_uuid.b, c->name);
/* Compat: */ /* Compat: */
if (sb->version <= bcachefs_metadata_version_inode_v2 && if (sb->version <= bcachefs_metadata_version_inode_v2 &&
......
...@@ -764,4 +764,13 @@ static inline int u8_cmp(u8 l, u8 r) ...@@ -764,4 +764,13 @@ static inline int u8_cmp(u8 l, u8 r)
return cmp_int(l, r); return cmp_int(l, r);
} }
#ifdef __KERNEL__
static inline void uuid_unparse_lower(u8 *uuid, char *out)
{
sprintf(out, "%plU", uuid);
}
#else
#include <uuid/uuid.h>
#endif
#endif /* _BCACHEFS_UTIL_H */ #endif /* _BCACHEFS_UTIL_H */
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