bcachefs: Kill bch_scnmemcpy()

bch_scnmemcpy was for printing length-limited strings that might not
have a terminating null - turns out sprintf & pr_buf can do this with
%.*s.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2022-02-20 04:52:44 -05:00 committed by Kent Overstreet
parent 3117db99f3
commit d4b691522c
6 changed files with 13 additions and 29 deletions

View File

@ -122,9 +122,9 @@ void bch2_dirent_to_text(struct printbuf *out, struct bch_fs *c,
{
struct bkey_s_c_dirent d = bkey_s_c_to_dirent(k);
bch_scnmemcpy(out, d.v->d_name,
bch2_dirent_name_bytes(d));
pr_buf(out, " -> %llu type %s",
pr_buf(out, "%.*s -> %llu type %s",
bch2_dirent_name_bytes(d),
d.v->d_name,
d.v->d_type != DT_SUBVOL
? le64_to_cpu(d.v->d_inum)
: le32_to_cpu(d.v->d_child_subvol),

View File

@ -76,8 +76,9 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb,
for (g = sorted; g + 1 < sorted + nr_groups; g++)
if (!BCH_GROUP_DELETED(g) &&
!group_cmp(&g[0], &g[1])) {
pr_buf(err, "duplicate label %llu.", BCH_GROUP_PARENT(g));
bch_scnmemcpy(err, g->label, strnlen(g->label, sizeof(g->label)));
pr_buf(err, "duplicate label %llu.%.*s",
BCH_GROUP_PARENT(g),
(int) sizeof(g->label), g->label);
goto err;
}
@ -376,9 +377,7 @@ void bch2_disk_path_to_text(struct printbuf *out,
v = path[--nr];
g = groups->entries + v;
bch_scnmemcpy(out, g->label,
strnlen(g->label, sizeof(g->label)));
pr_buf(out, "%.*s", (int) sizeof(g->label), g->label);
if (nr)
pr_buf(out, ".");
}

View File

@ -595,7 +595,7 @@ static void journal_entry_log_to_text(struct printbuf *out, struct bch_fs *c,
struct jset_entry_log *l = container_of(entry, struct jset_entry_log, entry);
unsigned bytes = vstruct_bytes(entry) - offsetof(struct jset_entry_log, d);
bch_scnmemcpy(out, l->d, strnlen(l->d, bytes));
pr_buf(out, "%.*s", bytes, l->d);
}
struct jset_entry_ops {

View File

@ -581,19 +581,6 @@ void memcpy_from_bio(void *dst, struct bio *src, struct bvec_iter src_iter)
}
}
void bch_scnmemcpy(struct printbuf *out,
const char *src, size_t len)
{
size_t n = printbuf_remaining(out);
if (n) {
n = min(n - 1, len);
memcpy(out->pos, src, n);
out->pos += n;
*out->pos = '\0';
}
}
#include "eytzinger.h"
static int alignment_ok(const void *base, size_t align)

View File

@ -281,8 +281,6 @@ static inline void printbuf_newline(struct printbuf *buf)
pr_buf(buf, " ");
}
void bch_scnmemcpy(struct printbuf *, const char *, size_t);
int bch2_strtoint_h(const char *, int *);
int bch2_strtouint_h(const char *, unsigned int *);
int bch2_strtoll_h(const char *, long long *);

View File

@ -111,11 +111,11 @@ void bch2_xattr_to_text(struct printbuf *out, struct bch_fs *c,
else
pr_buf(out, "(unknown type %u)", xattr.v->x_type);
bch_scnmemcpy(out, xattr.v->x_name,
xattr.v->x_name_len);
pr_buf(out, ":");
bch_scnmemcpy(out, xattr_val(xattr.v),
le16_to_cpu(xattr.v->x_val_len));
pr_buf(out, "%.*s:%.*s",
xattr.v->x_name_len,
xattr.v->x_name,
le16_to_cpu(xattr.v->x_val_len),
(char *) xattr_val(xattr.v));
}
static int bch2_xattr_get_trans(struct btree_trans *trans, struct bch_inode_info *inode,