Skip to content

Commit c2be0e2

Browse files
committed
btrfs-progs: use template for out of memory error messages
Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 74eb8c6 commit c2be0e2

21 files changed

+77
-78
lines changed

btrfs-corrupt-block.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ int main(int argc, char **argv)
14711471
del = rand_range(3);
14721472
path = btrfs_alloc_path();
14731473
if (!path) {
1474-
error("path allocation failed");
1474+
error_msg(ERROR_MSG_MEMORY, NULL);
14751475
goto out_close;
14761476
}
14771477

@@ -1597,8 +1597,8 @@ int main(int argc, char **argv)
15971597
eb = btrfs_find_create_tree_block(root->fs_info,
15981598
logical);
15991599
if (!eb) {
1600-
error(
1601-
"not enough memory to allocate extent buffer for bytenr %llu",
1600+
error_msg(ERROR_MSG_MEMORY,
1601+
"allocating extent buffer for bytenr %llu",
16021602
logical);
16031603
ret = 1;
16041604
goto out_close;

check/main.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ static int add_mismatch_dir_hash(struct inode_record *dir_rec,
13871387

13881388
hash_record = malloc(sizeof(*hash_record) + namelen);
13891389
if (!hash_record) {
1390-
error("failed to allocate memory for mismatch dir hash rec");
1390+
error_msg(ERROR_MSG_MEMORY, "mismatch dir hash record");
13911391
return -ENOMEM;
13921392
}
13931393
memcpy(&hash_record->key, key, sizeof(*key));
@@ -5224,7 +5224,7 @@ struct chunk_record *btrfs_new_chunk_record(struct extent_buffer *leaf,
52245224

52255225
rec = calloc(1, btrfs_chunk_record_size(num_stripes));
52265226
if (!rec) {
5227-
fprintf(stderr, "memory allocation failed\n");
5227+
error_msg(ERROR_MSG_MEMORY, NULL);
52285228
exit(-1);
52295229
}
52305230

@@ -5311,7 +5311,7 @@ static int process_device_item(struct rb_root *dev_cache,
53115311

53125312
rec = malloc(sizeof(*rec));
53135313
if (!rec) {
5314-
fprintf(stderr, "memory allocation failed\n");
5314+
error_msg(ERROR_MSG_MEMORY, NULL);
53155315
return -ENOMEM;
53165316
}
53175317

@@ -5366,7 +5366,7 @@ btrfs_new_block_group_record(struct extent_buffer *leaf, struct btrfs_key *key,
53665366

53675367
rec = calloc(1, sizeof(*rec));
53685368
if (!rec) {
5369-
fprintf(stderr, "memory allocation failed\n");
5369+
error_msg(ERROR_MSG_MEMORY, NULL);
53705370
exit(-1);
53715371
}
53725372

@@ -5430,7 +5430,7 @@ btrfs_new_device_extent_record(struct extent_buffer *leaf,
54305430

54315431
rec = calloc(1, sizeof(*rec));
54325432
if (!rec) {
5433-
fprintf(stderr, "memory allocation failed\n");
5433+
error_msg(ERROR_MSG_MEMORY, NULL);
54345434
exit(-1);
54355435
}
54365436

@@ -8895,7 +8895,7 @@ static int check_chunks_and_extents(void)
88958895
bits_nr = 1024;
88968896
bits = malloc(bits_nr * sizeof(struct block_info));
88978897
if (!bits) {
8898-
perror("malloc");
8898+
error_msg(ERROR_MSG_MEMORY, NULL);
88998899
exit(1);
89008900
}
89018901

check/qgroup-verify.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static int account_all_refs(int do_qgroups, u64 search_subvol)
580580
ulist_free(roots);
581581
return 0;
582582
enomem:
583-
error("Out of memory while accounting refs for qgroups");
583+
error_msg(ERROR_MSG_MEMORY, "accounting for refs for qgroups");
584584
return -ENOMEM;
585585
}
586586

@@ -1006,7 +1006,7 @@ static int load_quota_info(struct btrfs_fs_info *info)
10061006
count = alloc_count(&disk_key, leaf, item);
10071007
if (!count) {
10081008
ret = ENOMEM;
1009-
error("out of memory");
1009+
error_msg(ERROR_MSG_MEMORY, NULL);
10101010
goto out;
10111011
}
10121012

@@ -1414,7 +1414,7 @@ int qgroup_verify_all(struct btrfs_fs_info *info)
14141414

14151415
tree_blocks = ulist_alloc(0);
14161416
if (!tree_blocks) {
1417-
error("out of memory while allocating ulist");
1417+
error_msg(ERROR_MSG_MEMORY, "allocate ulist");
14181418
return ENOMEM;
14191419
}
14201420

@@ -1521,7 +1521,7 @@ int print_extent_state(struct btrfs_fs_info *info, u64 subvol)
15211521

15221522
tree_blocks = ulist_alloc(0);
15231523
if (!tree_blocks) {
1524-
error("out of memory while allocating ulist");
1524+
error_msg(ERROR_MSG_MEMORY, "allocate ulist");
15251525
return ENOMEM;
15261526
}
15271527

cmds/device.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static int print_device_stat_string(struct format_ctx *fctx,
607607
canonical_path = malloc(32);
608608

609609
if (!canonical_path) {
610-
error("not enough memory for path buffer");
610+
error_msg(ERROR_MSG_MEMORY, "device path buffer");
611611
return -ENOMEM;
612612
}
613613

@@ -671,7 +671,7 @@ static int print_device_stat_tabular(struct string_table *table, int row,
671671
canonical_path = malloc(32);
672672

673673
if (!canonical_path) {
674-
error("not enough memory for path buffer");
674+
error_msg(ERROR_MSG_MEMORY, "device path buffer");
675675
return -ENOMEM;
676676
}
677677

@@ -775,7 +775,7 @@ static int cmd_device_stats(const struct cmd_struct *cmd, int argc, char **argv)
775775
*/
776776
table = table_create(7, fi_args.num_devices + 2);
777777
if (!table) {
778-
error("not enough memory");
778+
error_msg(ERROR_MSG_MEMORY, NULL);
779779
goto out;
780780
}
781781
free_table = true;

cmds/filesystem-usage.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static int add_info_to_list(struct chunk_info **chunkinfo_ret,
7777

7878
if (!res) {
7979
free(*chunkinfo_ret);
80-
error("not enough memory");
80+
error_msg(ERROR_MSG_MEMORY, NULL);
8181
return -ENOMEM;
8282
}
8383

@@ -240,7 +240,7 @@ static struct btrfs_ioctl_space_args *load_space_info(int fd, const char *path)
240240

241241
sargs_orig = sargs = calloc(1, sizeof(struct btrfs_ioctl_space_args));
242242
if (!sargs) {
243-
error("not enough memory");
243+
error_msg(ERROR_MSG_MEMORY, NULL);
244244
return NULL;
245245
}
246246

@@ -265,7 +265,7 @@ static struct btrfs_ioctl_space_args *load_space_info(int fd, const char *path)
265265
(count * sizeof(struct btrfs_ioctl_space_info)));
266266
if (!sargs) {
267267
free(sargs_orig);
268-
error("not enough memory");
268+
error_msg(ERROR_MSG_MEMORY, NULL);
269269
return NULL;
270270
}
271271

@@ -725,7 +725,7 @@ static int load_device_info(int fd, struct device_info **devinfo_ret,
725725

726726
info = calloc(fi_args.num_devices, sizeof(struct device_info));
727727
if (!info) {
728-
error("not enough memory");
728+
error_msg(ERROR_MSG_MEMORY, NULL);
729729
return 1;
730730
}
731731

@@ -873,7 +873,7 @@ static void _cmd_filesystem_usage_tabular(unsigned unit_mode,
873873

874874
matrix = table_create(ncols, nrows);
875875
if (!matrix) {
876-
error("not enough memory");
876+
error_msg(ERROR_MSG_MEMORY, NULL);
877877
return;
878878
}
879879

cmds/qgroup.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ static struct btrfs_qgroup_comparer_set *qgroup_alloc_comparer_set(void)
507507
sizeof(struct btrfs_qgroup_comparer);
508508
set = calloc(1, size);
509509
if (!set) {
510-
error("memory allocation failed");
510+
error_msg(ERROR_MSG_MEMORY, NULL);
511511
exit(1);
512512
}
513513

@@ -667,7 +667,7 @@ static struct btrfs_qgroup *get_or_add_qgroup(
667667

668668
bq = calloc(1, sizeof(*bq));
669669
if (!bq) {
670-
error("memory allocation failed");
670+
error_msg(ERROR_MSG_MEMORY, NULL);
671671
return ERR_PTR(-ENOMEM);
672672
}
673673

@@ -754,7 +754,7 @@ static int update_qgroup_relation(struct qgroup_lookup *qgroup_lookup,
754754

755755
list = malloc(sizeof(*list));
756756
if (!list) {
757-
error("memory allocation failed");
757+
error_msg(ERROR_MSG_MEMORY, NULL);
758758
return -ENOMEM;
759759
}
760760

@@ -888,7 +888,7 @@ static struct btrfs_qgroup_filter_set *qgroup_alloc_filter_set(void)
888888
sizeof(struct btrfs_qgroup_filter);
889889
set = calloc(1, size);
890890
if (!set) {
891-
error("memory allocation failed");
891+
error_msg(ERROR_MSG_MEMORY, NULL);
892892
exit(1);
893893
}
894894
set->total = BTRFS_QGROUP_NFILTERS_INCREASE;
@@ -915,7 +915,7 @@ static int qgroup_setup_filter(struct btrfs_qgroup_filter_set **filter_set,
915915
tmp = set;
916916
set = realloc(set, size);
917917
if (!set) {
918-
error("memory allocation failed");
918+
error_msg(ERROR_MSG_MEMORY, NULL);
919919
free(tmp);
920920
exit(1);
921921
}
@@ -1441,7 +1441,7 @@ static int qgroup_inherit_realloc(struct btrfs_qgroup_inherit **inherit, int n,
14411441

14421442
out = calloc(sizeof(*out) + sizeof(out->qgroups[0]) * (nitems + n), 1);
14431443
if (out == NULL) {
1444-
error("not enough memory");
1444+
error_msg(ERROR_MSG_MEMORY, NULL);
14451445
return -ENOMEM;
14461446
}
14471447

cmds/receive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ static int decompress_zlib(struct btrfs_receive *rctx, const char *encoded_data,
10091009
init = true;
10101010
rctx->zlib_stream = malloc(sizeof(z_stream));
10111011
if (!rctx->zlib_stream) {
1012-
error("failed to allocate zlib stream %m");
1012+
error_msg(ERROR_MSG_MEMORY, "zlib stream: %m");
10131013
return -ENOMEM;
10141014
}
10151015
}
@@ -1163,7 +1163,7 @@ static int decompress_and_write(struct btrfs_receive *rctx,
11631163

11641164
unencoded_data = calloc(unencoded_len, 1);
11651165
if (!unencoded_data) {
1166-
error("allocating space for unencoded data failed: %m");
1166+
error_msg(ERROR_MSG_MEMORY, "unencoded data: %m");
11671167
return -errno;
11681168
}
11691169

cmds/rescue-chunk-recover.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static struct extent_record *btrfs_new_extent_record(struct extent_buffer *eb)
8686

8787
rec = calloc(1, sizeof(*rec));
8888
if (!rec) {
89-
fprintf(stderr, "Fail to allocate memory for extent record.\n");
89+
error_msg(ERROR_MSG_MEMORY, "extent record");
9090
exit(1);
9191
}
9292

@@ -1437,7 +1437,7 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
14371437

14381438
fs_info = btrfs_new_fs_info(1, BTRFS_SUPER_INFO_OFFSET);
14391439
if (!fs_info) {
1440-
fprintf(stderr, "Failed to allocate memory for fs_info\n");
1440+
error_msg(ERROR_MSG_MEMORY, "fs_info");
14411441
return ERR_PTR(-ENOMEM);
14421442
}
14431443
fs_info->is_chunk_recover = 1;

cmds/restore.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static int copy_one_inline(struct btrfs_root *root, int fd,
327327
ram_size = btrfs_file_extent_ram_bytes(leaf, fi);
328328
outbuf = calloc(1, ram_size);
329329
if (!outbuf) {
330-
error("not enough memory");
330+
error_msg(ERROR_MSG_MEMORY, NULL);
331331
return -ENOMEM;
332332
}
333333

@@ -397,14 +397,14 @@ static int copy_one_extent(struct btrfs_root *root, int fd,
397397

398398
inbuf = malloc(size_left);
399399
if (!inbuf) {
400-
error("not enough memory");
400+
error_msg(ERROR_MSG_MEMORY, NULL);
401401
return -ENOMEM;
402402
}
403403

404404
if (compress != BTRFS_COMPRESS_NONE) {
405405
outbuf = calloc(1, ram_size);
406406
if (!outbuf) {
407-
error("not enough memory");
407+
error_msg(ERROR_MSG_MEMORY, NULL);
408408
free(inbuf);
409409
return -ENOMEM;
410410
}
@@ -1035,7 +1035,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
10351035
char *dir = strdup(fs_name);
10361036

10371037
if (!dir) {
1038-
error("ran out of memory");
1038+
error_msg(ERROR_MSG_MEMORY, NULL);
10391039
ret = -ENOMEM;
10401040
goto out;
10411041
}

cmds/subvolume-list.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
383383
tmp = set;
384384
set = realloc(set, size);
385385
if (!set) {
386-
fprintf(stderr, "memory allocation failed\n");
386+
error_msg(ERROR_MSG_MEMORY, NULL);
387387
free(tmp);
388388
exit(1);
389389
}
@@ -533,7 +533,7 @@ static int update_root(struct rb_root *root_lookup,
533533

534534
ri->name = malloc(name_len + 1);
535535
if (!ri->name) {
536-
fprintf(stderr, "memory allocation failed\n");
536+
error_msg(ERROR_MSG_MEMORY, NULL);
537537
exit(1);
538538
}
539539
strncpy(ri->name, name, name_len);
@@ -597,15 +597,15 @@ static int add_root(struct rb_root *root_lookup,
597597

598598
ri = calloc(1, sizeof(*ri));
599599
if (!ri) {
600-
printf("memory allocation failed\n");
600+
error_msg(ERROR_MSG_MEMORY, NULL);
601601
exit(1);
602602
}
603603
ri->root_id = root_id;
604604

605605
if (name && name_len > 0) {
606606
ri->name = malloc(name_len + 1);
607607
if (!ri->name) {
608-
fprintf(stderr, "memory allocation failed\n");
608+
error_msg(ERROR_MSG_MEMORY, NULL);
609609
exit(1);
610610
}
611611
strncpy(ri->name, name, name_len);
@@ -708,7 +708,7 @@ static int resolve_root(struct rb_root *rl, struct root_info *ri,
708708
/* room for / and for null */
709709
tmp = malloc(add_len + 2 + len);
710710
if (!tmp) {
711-
perror("malloc failed");
711+
error_msg(ERROR_MSG_MEMORY, NULL);
712712
exit(1);
713713
}
714714
memcpy(tmp + add_len + 1, full_path, len);
@@ -790,7 +790,7 @@ static int lookup_ino_path(int fd, struct root_info *ri)
790790
*/
791791
ri->path = malloc(strlen(ri->name) + strlen(args.name) + 1);
792792
if (!ri->path) {
793-
perror("malloc failed");
793+
error_msg(ERROR_MSG_MEMORY, NULL);
794794
exit(1);
795795
}
796796
strcpy(ri->path, args.name);
@@ -977,7 +977,7 @@ static int filter_full_path(struct root_info *ri, u64 data)
977977

978978
tmp = malloc(len + add_len + 2);
979979
if (!tmp) {
980-
fprintf(stderr, "memory allocation failed\n");
980+
error_msg(ERROR_MSG_MEMORY, NULL);
981981
exit(1);
982982
}
983983
memcpy(tmp + add_len + 1, ri->full_path, len);
@@ -1038,7 +1038,7 @@ static void btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
10381038
tmp = set;
10391039
set = realloc(set, size);
10401040
if (!set) {
1041-
fprintf(stderr, "memory allocation failed\n");
1041+
error_msg(ERROR_MSG_MEMORY, NULL);
10421042
free(tmp);
10431043
exit(1);
10441044
}
@@ -1457,7 +1457,7 @@ static struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
14571457
BTRFS_LIST_NFILTERS_INCREASE * sizeof(struct btrfs_list_filter);
14581458
set = calloc(1, size);
14591459
if (!set) {
1460-
fprintf(stderr, "memory allocation failed\n");
1460+
error_msg(ERROR_MSG_MEMORY, NULL);
14611461
exit(1);
14621462
}
14631463

@@ -1475,7 +1475,7 @@ static struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void)
14751475
BTRFS_LIST_NCOMPS_INCREASE * sizeof(struct btrfs_list_comparer);
14761476
set = calloc(1, size);
14771477
if (!set) {
1478-
fprintf(stderr, "memory allocation failed\n");
1478+
error_msg(ERROR_MSG_MEMORY, NULL);
14791479
exit(1);
14801480
}
14811481

0 commit comments

Comments
 (0)