Skip to content

Commit

Permalink
btrfs-progs: cmds: replace perror with error_msg
Browse files Browse the repository at this point in the history
Use our error message helper with predefined common templates.

Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
kdave committed Mar 14, 2024
1 parent 6d46c8b commit 0d8c8aa
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmds/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ static int cmd_device_ready(const struct cmd_struct *cmd, int argc, char **argv)

fd = open("/dev/btrfs-control", O_RDWR);
if (fd < 0) {
perror("failed to open /dev/btrfs-control");
error("failed to open /dev/btrfs-control: %m");
return 1;
}

Expand Down
14 changes: 7 additions & 7 deletions cmds/inspect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1259,9 +1259,9 @@ static int read_chunk_tree(int fd, struct chunk **chunks, size_t *num_chunks)
if (items_pos >= sk->nr_items) {
sk->nr_items = 4096;
ret = btrfs_tree_search_ioctl(fd, &args);
if (ret == -1) {
perror("BTRFS_IOC_TREE_SEARCH");
return -1;
if (ret < 0) {
error_msg(ERROR_MSG_TREE_SEARCH, "%m");
return -errno;
}
items_pos = 0;
buf_off = 0;
Expand All @@ -1286,8 +1286,8 @@ static int read_chunk_tree(int fd, struct chunk **chunks, size_t *num_chunks)
capacity *= 2;
tmp = realloc(*chunks, capacity * sizeof(**chunks));
if (!tmp) {
perror("realloc");
return -1;
error_msg(ERROR_MSG_MEMORY, NULL);
return -ENOMEM;
}
*chunks = tmp;
}
Expand All @@ -1302,8 +1302,8 @@ static int read_chunk_tree(int fd, struct chunk **chunks, size_t *num_chunks)
chunk->stripes = calloc(chunk->num_stripes,
sizeof(*chunk->stripes));
if (!chunk->stripes) {
perror("calloc");
return -1;
error_msg(ERROR_MSG_MEMORY, NULL);
return -ENOMEM;
}
(*num_chunks)++;

Expand Down
2 changes: 1 addition & 1 deletion cmds/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void dev_replace_sigint_handler(int signal)
args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL;
ret = ioctl(dev_replace_cancel_fd, BTRFS_IOC_DEV_REPLACE, &args);
if (ret < 0)
perror("Device replace cancel failed");
error("device replace cancel failed: %m");
}

static int dev_replace_handle_sigint(int fd)
Expand Down
2 changes: 1 addition & 1 deletion cmds/scrub.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ static void scrub_sigint_record_progress(int signal)

ret = ioctl(cancel_fd, BTRFS_IOC_SCRUB_CANCEL, NULL);
if (ret < 0)
perror("Scrub cancel failed");
error("scrub cancel failed: %m");
}

static int scrub_handle_sigint_parent(void)
Expand Down
2 changes: 1 addition & 1 deletion cmds/subvolume-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ static int lookup_ino_path(int fd, struct root_info *ri)
/* we're at the root of ref_tree */
ri->path = strdup(ri->name);
if (!ri->path) {
perror("strdup failed");
error_msg(ERROR_MSG_MEMORY, NULL);
exit(1);
}
}
Expand Down
1 change: 1 addition & 0 deletions common/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static const char *common_error_string[] = {
[ERROR_MSG_MEMORY] = "not enough memory",
[ERROR_MSG_START_TRANS] = "failed to start transaction",
[ERROR_MSG_COMMIT_TRANS] = "failed to commit transaction",
[ERROR_MSG_TREE_SEARCH] = "TREE_SEARCH ioctl failed",
};

__attribute__ ((format (printf, 1, 2)))
Expand Down
1 change: 1 addition & 0 deletions common/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ enum common_error {
ERROR_MSG_MEMORY,
ERROR_MSG_START_TRANS,
ERROR_MSG_COMMIT_TRANS,
ERROR_MSG_TREE_SEARCH,
};

__attribute__ ((format (printf, 2, 3)))
Expand Down

0 comments on commit 0d8c8aa

Please sign in to comment.