Merge pull request #13 from modelrockettier/target-printing

Nicer group and target show-super output
This commit is contained in:
koverstreet 2018-11-06 22:42:00 -05:00 committed by GitHub
commit 11a3c461ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 22 deletions

View File

@ -87,7 +87,7 @@ static void usage(void)
" --replicas=# Sets both data and metadata replicas\n"
" --encrypted Enable whole filesystem encryption (chacha20/poly1305)\n"
" --no_passphrase Don't encrypt master encryption key\n"
" --error_action=(continue|remount-ro|panic)\n"
" -e, --error_action=(continue|remount-ro|panic)\n"
" Action to take on filesystem error\n"
" -L, --label=label\n"
" -U, --uuid=uuid\n"
@ -153,7 +153,7 @@ int cmd_format(int argc, char *argv[])
darray_init(devices);
while ((opt = getopt_long(argc, argv,
"-b:e:L:U:ft:qh",
"-b:e:g:L:U:fqh",
format_opts,
NULL)) != -1)
switch (opt) {
@ -208,13 +208,13 @@ int cmd_format(int argc, char *argv[])
opts.meta_replicas = opts.data_replicas;
break;
case O_foreground_target:
opts.foreground_target = strdup(optarg);
opts.foreground_target = optarg;
break;
case O_background_target:
opts.background_target = strdup(optarg);
opts.background_target = optarg;
break;
case O_promote_target:
opts.promote_target = strdup(optarg);
opts.promote_target = optarg;
break;
case O_encrypted:
opts.encrypted = true;
@ -230,7 +230,7 @@ int cmd_format(int argc, char *argv[])
break;
case O_label:
case 'L':
opts.label = strdup(optarg);
opts.label = optarg;
break;
case O_uuid:
case 'U':
@ -253,7 +253,7 @@ int cmd_format(int argc, char *argv[])
break;
case O_group:
case 'g':
dev_opts.group = strdup(optarg);
dev_opts.group = optarg;
break;
case O_discard:
dev_opts.discard = true;
@ -269,7 +269,7 @@ int cmd_format(int argc, char *argv[])
die("invalid durability");
break;
case O_no_opt:
dev_opts.path = strdup(optarg);
dev_opts.path = optarg;
darray_append(devices, dev_opts);
dev_opts.size = 0;
break;
@ -284,7 +284,7 @@ int cmd_format(int argc, char *argv[])
break;
}
if (!darray_size(devices))
if (darray_empty(devices))
die("Please supply a device");
if (opts.encrypted && !no_passphrase)
@ -305,6 +305,8 @@ int cmd_format(int argc, char *argv[])
free(opts.passphrase);
}
darray_free(devices);
return 0;
}

View File

@ -351,6 +351,52 @@ static unsigned get_dev_has_data(struct bch_sb *sb, unsigned dev)
return data_has;
}
static int bch2_sb_get_target(struct bch_sb *sb, char *buf, size_t len, u64 v)
{
struct target t = target_decode(v);
int ret;
switch (t.type) {
case TARGET_NULL:
return scnprintf(buf, len, "none");
case TARGET_DEV: {
struct bch_sb_field_members *mi = bch2_sb_get_members(sb);
struct bch_member *m = mi->members + t.dev;
if (bch2_dev_exists(sb, mi, t.dev)) {
char uuid_str[40];
uuid_unparse(m->uuid.b, uuid_str);
ret = scnprintf(buf, len, "Device %u (%s)", t.dev,
uuid_str);
} else {
ret = scnprintf(buf, len, "Bad device %u", t.dev);
}
break;
}
case TARGET_GROUP: {
struct bch_sb_field_disk_groups *gi;
gi = bch2_sb_get_disk_groups(sb);
struct bch_disk_group *g = gi->entries + t.group;
if (t.group < disk_groups_nr(gi) && !BCH_GROUP_DELETED(g)) {
ret = scnprintf(buf, len, "Group %u (%.*s)", t.group,
BCH_SB_LABEL_SIZE, g->label);
} else {
ret = scnprintf(buf, len, "Bad group %u", t.group);
}
break;
}
default:
BUG();
}
return ret;
}
/* superblock printing: */
static void bch2_sb_print_layout(struct bch_sb *sb, enum units units)
@ -402,7 +448,7 @@ static void bch2_sb_print_members(struct bch_sb *sb, struct bch_sb_field *f,
char member_uuid_str[40];
char data_allowed_str[100];
char data_has_str[100];
char group[64];
char group[BCH_SB_LABEL_SIZE+10];
char time_str[64];
if (!bch2_member_exists(m))
@ -414,12 +460,14 @@ static void bch2_sb_print_members(struct bch_sb *sb, struct bch_sb_field *f,
unsigned idx = BCH_MEMBER_GROUP(m) - 1;
if (idx < disk_groups_nr(gi)) {
memcpy(group, gi->entries[idx].label,
BCH_SB_LABEL_SIZE);
group[BCH_SB_LABEL_SIZE] = '\0';
snprintf(group, sizeof(group), "%.*s (%u)",
BCH_SB_LABEL_SIZE,
gi->entries[idx].label, idx);
} else {
strcpy(group, "(bad disk groups section");
strcpy(group, "(bad disk groups section)");
}
} else {
strcpy(group, "(none)");
}
bch2_scnprint_flag_list(data_allowed_str,
@ -569,13 +617,17 @@ void bch2_sb_print(struct bch_sb *sb, bool print_layout,
char fields_have_str[200];
char label[BCH_SB_LABEL_SIZE + 1];
char time_str[64];
char foreground_str[64];
char background_str[64];
char promote_str[64];
struct bch_sb_field *f;
u64 fields_have = 0;
unsigned nr_devices = 0;
time_t time_base = le64_to_cpu(sb->time_base_lo) / NSEC_PER_SEC;
memset(label, 0, sizeof(label));
memcpy(label, sb->label, sizeof(sb->label));
memcpy(label, sb->label, BCH_SB_LABEL_SIZE);
label[BCH_SB_LABEL_SIZE] = '\0';
uuid_unparse(sb->user_uuid.b, user_uuid_str);
uuid_unparse(sb->uuid.b, internal_uuid_str);
@ -598,6 +650,15 @@ void bch2_sb_print(struct bch_sb *sb, bool print_layout,
nr_devices += bch2_member_exists(m);
}
bch2_sb_get_target(sb, foreground_str, sizeof(foreground_str),
BCH_SB_FOREGROUND_TARGET(sb));
bch2_sb_get_target(sb, background_str, sizeof(background_str),
BCH_SB_BACKGROUND_TARGET(sb));
bch2_sb_get_target(sb, promote_str, sizeof(promote_str),
BCH_SB_PROMOTE_TARGET(sb));
vstruct_for_each(sb, f)
fields_have |= 1 << le32_to_cpu(f->type);
bch2_scnprint_flag_list(fields_have_str, sizeof(fields_have_str),
@ -620,9 +681,9 @@ void bch2_sb_print(struct bch_sb *sb, bool print_layout,
"Data checksum type: %s (%llu)\n"
"Compression type: %s (%llu)\n"
"Foreground write target: %llu\n"
"Background write target: %llu\n"
"Promote target: %llu\n"
"Foreground write target: %s\n"
"Background write target: %s\n"
"Promote target: %s\n"
"String hash type: %s (%llu)\n"
"32 bit inodes: %llu\n"
@ -664,9 +725,9 @@ void bch2_sb_print(struct bch_sb *sb, bool print_layout,
: "unknown",
BCH_SB_COMPRESSION_TYPE(sb),
BCH_SB_FOREGROUND_TARGET(sb),
BCH_SB_BACKGROUND_TARGET(sb),
BCH_SB_PROMOTE_TARGET(sb),
foreground_str,
background_str,
promote_str,
BCH_SB_STR_HASH_TYPE(sb) < BCH_STR_HASH_NR
? bch2_str_hash_types[BCH_SB_STR_HASH_TYPE(sb)]