Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcachefs: Private error codes: ENOMEM

This adds private error codes for most (but not all) of our ENOMEM uses,
which makes it easier to track down assorted allocation failures.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

+259 -157
+9 -9
fs/bcachefs/btree_cache.c
··· 91 91 92 92 b->data = kvpmalloc(btree_bytes(c), gfp); 93 93 if (!b->data) 94 - return -ENOMEM; 94 + return -BCH_ERR_ENOMEM_btree_node_mem_alloc; 95 95 #ifdef __KERNEL__ 96 96 b->aux_data = kvmalloc(btree_aux_data_bytes(b), gfp); 97 97 #else ··· 104 104 if (!b->aux_data) { 105 105 kvpfree(b->data, btree_bytes(c)); 106 106 b->data = NULL; 107 - return -ENOMEM; 107 + return -BCH_ERR_ENOMEM_btree_node_mem_alloc; 108 108 } 109 109 110 110 return 0; ··· 207 207 (1U << BTREE_NODE_read_in_flight)| 208 208 (1U << BTREE_NODE_write_in_flight))) { 209 209 if (!flush) 210 - return -ENOMEM; 210 + return -BCH_ERR_ENOMEM_btree_node_reclaim; 211 211 212 212 /* XXX: waiting on IO with btree cache lock held */ 213 213 bch2_btree_node_wait_on_read(b); ··· 215 215 } 216 216 217 217 if (!six_trylock_intent(&b->c.lock)) 218 - return -ENOMEM; 218 + return -BCH_ERR_ENOMEM_btree_node_reclaim; 219 219 220 220 if (!six_trylock_write(&b->c.lock)) 221 221 goto out_unlock_intent; ··· 263 263 six_unlock_write(&b->c.lock); 264 264 out_unlock_intent: 265 265 six_unlock_intent(&b->c.lock); 266 - ret = -ENOMEM; 266 + ret = -BCH_ERR_ENOMEM_btree_node_reclaim; 267 267 goto out; 268 268 } 269 269 ··· 462 462 463 463 for (i = 0; i < bc->reserve; i++) 464 464 if (!__bch2_btree_node_mem_alloc(c)) { 465 - ret = -ENOMEM; 465 + ret = -BCH_ERR_ENOMEM_fs_btree_cache_init; 466 466 goto out; 467 467 } 468 468 ··· 516 516 517 517 if (!cl) { 518 518 trace_and_count(c, btree_cache_cannibalize_lock_fail, c); 519 - return -ENOMEM; 519 + return -BCH_ERR_ENOMEM_btree_cache_cannibalize_lock; 520 520 } 521 521 522 522 closure_wait(&bc->alloc_wait, cl); ··· 669 669 670 670 mutex_unlock(&bc->lock); 671 671 memalloc_nofs_restore(flags); 672 - return ERR_PTR(-ENOMEM); 672 + return ERR_PTR(-BCH_ERR_ENOMEM_btree_node_mem_alloc); 673 673 } 674 674 675 675 /* Slowpath, don't want it inlined into btree_iter_traverse() */ ··· 698 698 699 699 b = bch2_btree_node_mem_alloc(trans, level != 0); 700 700 701 - if (b == ERR_PTR(-ENOMEM)) { 701 + if (bch2_err_matches(PTR_ERR_OR_ZERO(b), ENOMEM)) { 702 702 trans->memory_allocation_failure = true; 703 703 trace_and_count(c, trans_restart_memory_allocation_failure, trans, _THIS_IP_, path); 704 704 return ERR_PTR(btree_trans_restart(trans, BCH_ERR_transaction_restart_fill_mem_alloc_fail));
+8 -8
fs/bcachefs/btree_gc.c
··· 201 201 202 202 new = kmalloc_array(BKEY_BTREE_PTR_U64s_MAX, sizeof(u64), GFP_KERNEL); 203 203 if (!new) 204 - return -ENOMEM; 204 + return -BCH_ERR_ENOMEM_gc_repair_key; 205 205 206 206 btree_ptr_to_v2(b, new); 207 207 b->data->min_key = new_min; ··· 230 230 231 231 new = kmalloc_array(BKEY_BTREE_PTR_U64s_MAX, sizeof(u64), GFP_KERNEL); 232 232 if (!new) 233 - return -ENOMEM; 233 + return -BCH_ERR_ENOMEM_gc_repair_key; 234 234 235 235 btree_ptr_to_v2(b, new); 236 236 b->data->max_key = new_max; ··· 686 686 new = kmalloc(bkey_bytes(k->k), GFP_KERNEL); 687 687 if (!new) { 688 688 bch_err(c, "%s: error allocating new key", __func__); 689 - ret = -ENOMEM; 689 + ret = -BCH_ERR_ENOMEM_gc_repair_key; 690 690 goto err; 691 691 } 692 692 ··· 1293 1293 sizeof(u64), GFP_KERNEL); 1294 1294 if (!c->usage_gc) { 1295 1295 bch_err(c, "error allocating c->usage_gc"); 1296 - return -ENOMEM; 1296 + return -BCH_ERR_ENOMEM_gc_start; 1297 1297 } 1298 1298 1299 1299 for_each_member_device(ca, c, i) { ··· 1303 1303 if (!ca->usage_gc) { 1304 1304 bch_err(c, "error allocating ca->usage_gc"); 1305 1305 percpu_ref_put(&ca->ref); 1306 - return -ENOMEM; 1306 + return -BCH_ERR_ENOMEM_gc_start; 1307 1307 } 1308 1308 1309 1309 this_cpu_write(ca->usage_gc->d[BCH_DATA_free].buckets, ··· 1495 1495 if (!buckets) { 1496 1496 percpu_ref_put(&ca->ref); 1497 1497 bch_err(c, "error allocating ca->buckets[gc]"); 1498 - return -ENOMEM; 1498 + return -BCH_ERR_ENOMEM_gc_alloc_start; 1499 1499 } 1500 1500 1501 1501 buckets->first_bucket = ca->mi.first_bucket; ··· 1656 1656 r = genradix_ptr_alloc(&c->reflink_gc_table, c->reflink_gc_nr++, 1657 1657 GFP_KERNEL); 1658 1658 if (!r) { 1659 - ret = -ENOMEM; 1659 + ret = -BCH_ERR_ENOMEM_gc_reflink_start; 1660 1660 break; 1661 1661 } 1662 1662 ··· 1977 1977 ca->oldest_gen = kvmalloc(ca->mi.nbuckets, GFP_KERNEL); 1978 1978 if (!ca->oldest_gen) { 1979 1979 percpu_ref_put(&ca->ref); 1980 - ret = -ENOMEM; 1980 + ret = -BCH_ERR_ENOMEM_gc_gens; 1981 1981 goto err; 1982 1982 } 1983 1983
+1 -1
fs/bcachefs/btree_io.c
··· 1483 1483 1484 1484 ra = kzalloc(sizeof(*ra), GFP_NOFS); 1485 1485 if (!ra) 1486 - return -ENOMEM; 1486 + return -BCH_ERR_ENOMEM_btree_node_read_all_replicas; 1487 1487 1488 1488 closure_init(&ra->cl, NULL); 1489 1489 ra->c = c;
+2 -2
fs/bcachefs/btree_iter.c
··· 1012 1012 __btree_path_put(path, false); 1013 1013 1014 1014 if (bch2_err_matches(ret, BCH_ERR_transaction_restart) || 1015 - ret == -ENOMEM) 1015 + bch2_err_matches(ret, ENOMEM)) 1016 1016 goto retry_all; 1017 1017 if (ret) 1018 1018 goto err; ··· 2809 2809 } 2810 2810 2811 2811 if (!new_mem) 2812 - return ERR_PTR(-ENOMEM); 2812 + return ERR_PTR(-BCH_ERR_ENOMEM_trans_kmalloc); 2813 2813 2814 2814 trans->mem = new_mem; 2815 2815 trans->mem_bytes = new_bytes;
+8 -8
fs/bcachefs/btree_key_cache.c
··· 336 336 if (unlikely(!ck)) { 337 337 bch_err(c, "error allocating memory for key cache item, btree %s", 338 338 bch2_btree_ids[path->btree_id]); 339 - return ERR_PTR(-ENOMEM); 339 + return ERR_PTR(-BCH_ERR_ENOMEM_btree_key_cache_create); 340 340 } 341 341 342 342 mark_btree_node_locked(trans, path, 0, SIX_LOCK_intent); ··· 423 423 if (!new_k) { 424 424 bch_err(trans->c, "error allocating memory for key cache key, btree %s u64s %u", 425 425 bch2_btree_ids[ck->key.btree_id], new_u64s); 426 - ret = -ENOMEM; 426 + ret = -BCH_ERR_ENOMEM_btree_key_cache_fill; 427 427 goto err; 428 428 } 429 429 ··· 1043 1043 int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc) 1044 1044 { 1045 1045 struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache); 1046 - int ret; 1047 1046 1048 1047 #ifdef __KERNEL__ 1049 1048 bc->pcpu_freed = alloc_percpu(struct btree_key_cache_freelist); 1050 1049 if (!bc->pcpu_freed) 1051 - return -ENOMEM; 1050 + return -BCH_ERR_ENOMEM_fs_btree_cache_init; 1052 1051 #endif 1053 1052 1054 - ret = rhashtable_init(&bc->table, &bch2_btree_key_cache_params); 1055 - if (ret) 1056 - return ret; 1053 + if (rhashtable_init(&bc->table, &bch2_btree_key_cache_params)) 1054 + return -BCH_ERR_ENOMEM_fs_btree_cache_init; 1057 1055 1058 1056 bc->table_init_done = true; 1059 1057 1060 1058 bc->shrink.seeks = 0; 1061 1059 bc->shrink.count_objects = bch2_btree_key_cache_count; 1062 1060 bc->shrink.scan_objects = bch2_btree_key_cache_scan; 1063 - return register_shrinker(&bc->shrink, "%s/btree_key_cache", c->name); 1061 + if (register_shrinker(&bc->shrink, "%s/btree_key_cache", c->name)) 1062 + return -BCH_ERR_ENOMEM_fs_btree_cache_init; 1063 + return 0; 1064 1064 } 1065 1065 1066 1066 void bch2_btree_key_cache_to_text(struct printbuf *out, struct btree_key_cache *c)
+6 -3
fs/bcachefs/btree_update_interior.c
··· 2475 2475 c->btree_interior_update_worker = 2476 2476 alloc_workqueue("btree_update", WQ_UNBOUND|WQ_MEM_RECLAIM, 1); 2477 2477 if (!c->btree_interior_update_worker) 2478 - return -ENOMEM; 2478 + return -BCH_ERR_ENOMEM_btree_interior_update_worker_init; 2479 2479 2480 - return mempool_init_kmalloc_pool(&c->btree_interior_update_pool, 1, 2481 - sizeof(struct btree_update)); 2480 + if (mempool_init_kmalloc_pool(&c->btree_interior_update_pool, 1, 2481 + sizeof(struct btree_update))) 2482 + return -BCH_ERR_ENOMEM_btree_interior_update_pool_init; 2483 + 2484 + return 0; 2482 2485 }
+2 -2
fs/bcachefs/btree_update_leaf.c
··· 401 401 if (!new_k) { 402 402 bch_err(c, "error allocating memory for key cache key, btree %s u64s %u", 403 403 bch2_btree_ids[path->btree_id], new_u64s); 404 - return -ENOMEM; 404 + return -BCH_ERR_ENOMEM_btree_key_cache_insert; 405 405 } 406 406 407 407 trans_for_each_update(trans, i) ··· 1891 1891 int ret; 1892 1892 1893 1893 prt_vprintf(&buf, fmt, args); 1894 - ret = buf.allocation_failure ? -ENOMEM : 0; 1894 + ret = buf.allocation_failure ? -BCH_ERR_ENOMEM_trans_log_msg : 0; 1895 1895 if (ret) 1896 1896 goto err; 1897 1897
+1 -1
fs/bcachefs/btree_write_buffer.c
··· 333 333 wb->keys[0] = kvmalloc_array(wb->size, sizeof(*wb->keys[0]), GFP_KERNEL); 334 334 wb->keys[1] = kvmalloc_array(wb->size, sizeof(*wb->keys[1]), GFP_KERNEL); 335 335 if (!wb->keys[0] || !wb->keys[1]) 336 - return -ENOMEM; 336 + return -BCH_ERR_ENOMEM_fs_btree_write_buffer_init; 337 337 338 338 return 0; 339 339 }
+14 -8
fs/bcachefs/buckets.c
··· 906 906 if (!m) { 907 907 bch_err(c, "error allocating memory for gc_stripes, idx %llu", 908 908 (u64) p.idx); 909 - return -ENOMEM; 909 + return -BCH_ERR_ENOMEM_mark_stripe_ptr; 910 910 } 911 911 912 912 mutex_lock(&c->ec_stripes_heap_lock); ··· 1075 1075 if (!m) { 1076 1076 bch_err(c, "error allocating memory for gc_stripes, idx %llu", 1077 1077 idx); 1078 - return -ENOMEM; 1078 + return -BCH_ERR_ENOMEM_mark_stripe; 1079 1079 } 1080 1080 /* 1081 1081 * This will be wrong when we bring back runtime gc: we should ··· 2045 2045 struct bucket_gens *bucket_gens = NULL, *old_bucket_gens = NULL; 2046 2046 unsigned long *buckets_nouse = NULL; 2047 2047 bool resize = ca->bucket_gens != NULL; 2048 - int ret = -ENOMEM; 2048 + int ret; 2049 2049 2050 2050 if (!(bucket_gens = kvpmalloc(sizeof(struct bucket_gens) + nbuckets, 2051 - GFP_KERNEL|__GFP_ZERO)) || 2052 - (c->opts.buckets_nouse && 2051 + GFP_KERNEL|__GFP_ZERO))) { 2052 + ret = -BCH_ERR_ENOMEM_bucket_gens; 2053 + goto err; 2054 + } 2055 + 2056 + if ((c->opts.buckets_nouse && 2053 2057 !(buckets_nouse = kvpmalloc(BITS_TO_LONGS(nbuckets) * 2054 2058 sizeof(unsigned long), 2055 - GFP_KERNEL|__GFP_ZERO)))) 2059 + GFP_KERNEL|__GFP_ZERO)))) { 2060 + ret = -BCH_ERR_ENOMEM_buckets_nouse; 2056 2061 goto err; 2062 + } 2057 2063 2058 2064 bucket_gens->first_bucket = ca->mi.first_bucket; 2059 2065 bucket_gens->nbuckets = nbuckets; ··· 2129 2123 2130 2124 ca->usage_base = kzalloc(sizeof(struct bch_dev_usage), GFP_KERNEL); 2131 2125 if (!ca->usage_base) 2132 - return -ENOMEM; 2126 + return -BCH_ERR_ENOMEM_usage_init; 2133 2127 2134 2128 for (i = 0; i < ARRAY_SIZE(ca->usage); i++) { 2135 2129 ca->usage[i] = alloc_percpu(struct bch_dev_usage); 2136 2130 if (!ca->usage[i]) 2137 - return -ENOMEM; 2131 + return -BCH_ERR_ENOMEM_usage_init; 2138 2132 } 2139 2133 2140 2134 return bch2_dev_buckets_resize(c, ca, ca->mi.nbuckets);
+2 -2
fs/bcachefs/buckets_waiting_for_journal.c
··· 110 110 111 111 n = kvmalloc(sizeof(*n) + (sizeof(n->d[0]) << new_bits), GFP_KERNEL); 112 112 if (!n) { 113 - ret = -ENOMEM; 113 + ret = -BCH_ERR_ENOMEM_buckets_waiting_for_journal_set; 114 114 goto out; 115 115 } 116 116 ··· 159 159 b->t = kvmalloc(sizeof(*b->t) + 160 160 (sizeof(b->t->d[0]) << INITIAL_TABLE_BITS), GFP_KERNEL); 161 161 if (!b->t) 162 - return -ENOMEM; 162 + return -BCH_ERR_ENOMEM_buckets_waiting_for_journal_init; 163 163 164 164 bucket_table_init(b->t, INITIAL_TABLE_BITS); 165 165 return 0;
+2 -2
fs/bcachefs/checksum.c
··· 133 133 134 134 sg = kmalloc_array(pages, sizeof(*sg), GFP_KERNEL); 135 135 if (!sg) 136 - return -ENOMEM; 136 + return -BCH_ERR_ENOMEM_do_encrypt; 137 137 138 138 sg_init_table(sg, pages); 139 139 ··· 648 648 649 649 crypt = bch2_sb_resize_crypt(&c->disk_sb, sizeof(*crypt) / sizeof(u64)); 650 650 if (!crypt) { 651 - ret = -ENOMEM; /* XXX this technically could be -ENOSPC */ 651 + ret = -BCH_ERR_ENOSPC_sb_crypt; 652 652 goto err; 653 653 } 654 654
+2 -2
fs/bcachefs/clock.c
··· 184 184 185 185 clock->pcpu_buf = alloc_percpu(*clock->pcpu_buf); 186 186 if (!clock->pcpu_buf) 187 - return -ENOMEM; 187 + return -BCH_ERR_ENOMEM_io_clock_init; 188 188 189 189 if (!init_heap(&clock->timers, NR_IO_TIMERS, GFP_KERNEL)) 190 - return -ENOMEM; 190 + return -BCH_ERR_ENOMEM_io_clock_init; 191 191 192 192 return 0; 193 193 }
+32 -33
fs/bcachefs/compress.c
··· 270 270 { 271 271 struct bbuf dst_data = { NULL }; 272 272 size_t dst_len = crc.uncompressed_size << 9; 273 - int ret = -ENOMEM; 273 + int ret; 274 274 275 275 if (crc.uncompressed_size << 9 > c->opts.encoded_extent_max || 276 276 crc.compressed_size << 9 > c->opts.encoded_extent_max) ··· 542 542 mempool_exit(&c->compression_bounce[READ]); 543 543 } 544 544 545 - static int __bch2_fs_compress_init(struct bch_fs *c, u64 features) 545 + static int _bch2_fs_compress_init(struct bch_fs *c, u64 features) 546 546 { 547 547 size_t decompress_workspace_size = 0; 548 548 bool decompress_workspace_needed; ··· 561 561 zstd_cctx_workspace_bound(&params.cParams), 562 562 zstd_dctx_workspace_bound() }, 563 563 }, *i; 564 - int ret = 0; 565 - 566 - pr_verbose_init(c->opts, ""); 564 + bool have_compressed = false; 567 565 568 566 c->zstd_params = params; 569 567 570 568 for (i = compression_types; 571 569 i < compression_types + ARRAY_SIZE(compression_types); 572 570 i++) 573 - if (features & (1 << i->feature)) 574 - goto have_compressed; 571 + have_compressed |= (features & (1 << i->feature)) != 0; 575 572 576 - goto out; 577 - have_compressed: 573 + if (!have_compressed) 574 + return 0; 578 575 579 - if (!mempool_initialized(&c->compression_bounce[READ])) { 580 - ret = mempool_init_kvpmalloc_pool(&c->compression_bounce[READ], 581 - 1, c->opts.encoded_extent_max); 582 - if (ret) 583 - goto out; 584 - } 576 + if (!mempool_initialized(&c->compression_bounce[READ]) && 577 + mempool_init_kvpmalloc_pool(&c->compression_bounce[READ], 578 + 1, c->opts.encoded_extent_max)) 579 + return -BCH_ERR_ENOMEM_compression_bounce_read_init; 585 580 586 - if (!mempool_initialized(&c->compression_bounce[WRITE])) { 587 - ret = mempool_init_kvpmalloc_pool(&c->compression_bounce[WRITE], 588 - 1, c->opts.encoded_extent_max); 589 - if (ret) 590 - goto out; 591 - } 581 + if (!mempool_initialized(&c->compression_bounce[WRITE]) && 582 + mempool_init_kvpmalloc_pool(&c->compression_bounce[WRITE], 583 + 1, c->opts.encoded_extent_max)) 584 + return -BCH_ERR_ENOMEM_compression_bounce_write_init; 592 585 593 586 for (i = compression_types; 594 587 i < compression_types + ARRAY_SIZE(compression_types); ··· 598 605 if (mempool_initialized(&c->compress_workspace[i->type])) 599 606 continue; 600 607 601 - ret = mempool_init_kvpmalloc_pool( 608 + if (mempool_init_kvpmalloc_pool( 602 609 &c->compress_workspace[i->type], 603 - 1, i->compress_workspace); 604 - if (ret) 605 - goto out; 610 + 1, i->compress_workspace)) 611 + return -BCH_ERR_ENOMEM_compression_workspace_init; 606 612 } 607 613 608 - if (!mempool_initialized(&c->decompress_workspace)) { 609 - ret = mempool_init_kvpmalloc_pool( 610 - &c->decompress_workspace, 611 - 1, decompress_workspace_size); 612 - if (ret) 613 - goto out; 614 - } 615 - out: 614 + if (!mempool_initialized(&c->decompress_workspace) && 615 + mempool_init_kvpmalloc_pool(&c->decompress_workspace, 616 + 1, decompress_workspace_size)) 617 + return -BCH_ERR_ENOMEM_decompression_workspace_init; 618 + 619 + return 0; 620 + } 621 + 622 + static int __bch2_fs_compress_init(struct bch_fs *c, u64 features) 623 + { 624 + int ret; 625 + 626 + pr_verbose_init(c->opts, ""); 627 + ret = _bch2_fs_compress_init(c, features); 616 628 pr_verbose_init(c->opts, "ret %i", ret); 629 + 617 630 return ret; 618 631 } 619 632
+1 -1
fs/bcachefs/counters.c
··· 96 96 { 97 97 c->counters = __alloc_percpu(sizeof(u64) * BCH_COUNTER_NR, sizeof(u64)); 98 98 if (!c->counters) 99 - return -ENOMEM; 99 + return -BCH_ERR_ENOMEM_fs_counters_init; 100 100 101 101 return bch2_sb_counters_to_cpu(c); 102 102 }
+2 -2
fs/bcachefs/disk_groups.c
··· 68 68 69 69 sorted = kmalloc_array(nr_groups, sizeof(*sorted), GFP_KERNEL); 70 70 if (!sorted) 71 - return -ENOMEM; 71 + return -BCH_ERR_ENOMEM_disk_groups_validate; 72 72 73 73 memcpy(sorted, groups->entries, nr_groups * sizeof(*sorted)); 74 74 sort(sorted, nr_groups, sizeof(*sorted), group_cmp, NULL); ··· 134 134 cpu_g = kzalloc(sizeof(*cpu_g) + 135 135 sizeof(cpu_g->entries[0]) * nr_groups, GFP_KERNEL); 136 136 if (!cpu_g) 137 - return -ENOMEM; 137 + return -BCH_ERR_ENOMEM_disk_groups_to_cpu; 138 138 139 139 cpu_g->nr = nr_groups; 140 140
+7 -7
fs/bcachefs/ec.c
··· 494 494 495 495 buf = kzalloc(sizeof(*buf), GFP_NOIO); 496 496 if (!buf) 497 - return -ENOMEM; 497 + return -BCH_ERR_ENOMEM_ec_read_extent; 498 498 499 499 ret = get_stripe_key(c, rbio->pick.ec.idx, buf); 500 500 if (ret) { ··· 559 559 560 560 if (idx >= h->size) { 561 561 if (!init_heap(&n, max(1024UL, roundup_pow_of_two(idx + 1)), gfp)) 562 - return -ENOMEM; 562 + return -BCH_ERR_ENOMEM_ec_stripe_mem_alloc; 563 563 564 564 mutex_lock(&c->ec_stripes_heap_lock); 565 565 if (n.size > h->size) { ··· 573 573 } 574 574 575 575 if (!genradix_ptr_alloc(&c->stripes, idx, gfp)) 576 - return -ENOMEM; 576 + return -BCH_ERR_ENOMEM_ec_stripe_mem_alloc; 577 577 578 578 if (c->gc_pos.phase != GC_PHASE_NOT_RUNNING && 579 579 !genradix_ptr_alloc(&c->gc_stripes, idx, gfp)) 580 - return -ENOMEM; 580 + return -BCH_ERR_ENOMEM_ec_stripe_mem_alloc; 581 581 582 582 return 0; 583 583 } ··· 1323 1323 1324 1324 s = kzalloc(sizeof(*s), GFP_KERNEL); 1325 1325 if (!s) 1326 - return -ENOMEM; 1326 + return -BCH_ERR_ENOMEM_ec_new_stripe_alloc; 1327 1327 1328 1328 mutex_init(&s->lock); 1329 1329 closure_init(&s->iodone, NULL); ··· 1680 1680 return h; 1681 1681 1682 1682 if (!h->s) { 1683 - if (ec_new_stripe_alloc(c, h)) { 1684 - ret = -ENOMEM; 1683 + ret = ec_new_stripe_alloc(c, h); 1684 + if (ret) { 1685 1685 bch_err(c, "failed to allocate new stripe"); 1686 1686 goto err; 1687 1687 }
+75
fs/bcachefs/errcode.h
··· 4 4 5 5 #define BCH_ERRCODES() \ 6 6 x(ENOMEM, ENOMEM_stripe_buf) \ 7 + x(ENOMEM, ENOMEM_replicas_table) \ 8 + x(ENOMEM, ENOMEM_cpu_replicas) \ 9 + x(ENOMEM, ENOMEM_replicas_gc) \ 10 + x(ENOMEM, ENOMEM_disk_groups_validate) \ 11 + x(ENOMEM, ENOMEM_disk_groups_to_cpu) \ 12 + x(ENOMEM, ENOMEM_mark_snapshot) \ 13 + x(ENOMEM, ENOMEM_mark_stripe) \ 14 + x(ENOMEM, ENOMEM_mark_stripe_ptr) \ 15 + x(ENOMEM, ENOMEM_btree_key_cache_create) \ 16 + x(ENOMEM, ENOMEM_btree_key_cache_fill) \ 17 + x(ENOMEM, ENOMEM_btree_key_cache_insert) \ 18 + x(ENOMEM, ENOMEM_trans_kmalloc) \ 19 + x(ENOMEM, ENOMEM_trans_log_msg) \ 20 + x(ENOMEM, ENOMEM_do_encrypt) \ 21 + x(ENOMEM, ENOMEM_ec_read_extent) \ 22 + x(ENOMEM, ENOMEM_ec_stripe_mem_alloc) \ 23 + x(ENOMEM, ENOMEM_ec_new_stripe_alloc) \ 24 + x(ENOMEM, ENOMEM_fs_btree_cache_init) \ 25 + x(ENOMEM, ENOMEM_fs_btree_key_cache_init) \ 26 + x(ENOMEM, ENOMEM_fs_counters_init) \ 27 + x(ENOMEM, ENOMEM_fs_btree_write_buffer_init) \ 28 + x(ENOMEM, ENOMEM_io_clock_init) \ 29 + x(ENOMEM, ENOMEM_blacklist_table_init) \ 30 + x(ENOMEM, ENOMEM_sb_realloc_injected) \ 31 + x(ENOMEM, ENOMEM_sb_bio_realloc) \ 32 + x(ENOMEM, ENOMEM_sb_buf_realloc) \ 33 + x(ENOMEM, ENOMEM_sb_journal_validate) \ 34 + x(ENOMEM, ENOMEM_sb_journal_v2_validate) \ 35 + x(ENOMEM, ENOMEM_journal_entry_add) \ 36 + x(ENOMEM, ENOMEM_journal_read_buf_realloc) \ 37 + x(ENOMEM, ENOMEM_btree_interior_update_worker_init)\ 38 + x(ENOMEM, ENOMEM_btree_interior_update_pool_init) \ 39 + x(ENOMEM, ENOMEM_bio_read_init) \ 40 + x(ENOMEM, ENOMEM_bio_read_split_init) \ 41 + x(ENOMEM, ENOMEM_bio_write_init) \ 42 + x(ENOMEM, ENOMEM_bio_bounce_pages_init) \ 43 + x(ENOMEM, ENOMEM_writepage_bioset_init) \ 44 + x(ENOMEM, ENOMEM_dio_read_bioset_init) \ 45 + x(ENOMEM, ENOMEM_dio_write_bioset_init) \ 46 + x(ENOMEM, ENOMEM_nocow_flush_bioset_init) \ 47 + x(ENOMEM, ENOMEM_promote_table_init) \ 48 + x(ENOMEM, ENOMEM_compression_bounce_read_init) \ 49 + x(ENOMEM, ENOMEM_compression_bounce_write_init) \ 50 + x(ENOMEM, ENOMEM_compression_workspace_init) \ 51 + x(ENOMEM, ENOMEM_decompression_workspace_init) \ 52 + x(ENOMEM, ENOMEM_bucket_gens) \ 53 + x(ENOMEM, ENOMEM_buckets_nouse) \ 54 + x(ENOMEM, ENOMEM_usage_init) \ 55 + x(ENOMEM, ENOMEM_btree_node_read_all_replicas) \ 56 + x(ENOMEM, ENOMEM_btree_node_reclaim) \ 57 + x(ENOMEM, ENOMEM_btree_node_mem_alloc) \ 58 + x(ENOMEM, ENOMEM_btree_cache_cannibalize_lock) \ 59 + x(ENOMEM, ENOMEM_buckets_waiting_for_journal_init)\ 60 + x(ENOMEM, ENOMEM_buckets_waiting_for_journal_set) \ 61 + x(ENOMEM, ENOMEM_set_nr_journal_buckets) \ 62 + x(ENOMEM, ENOMEM_dev_journal_init) \ 63 + x(ENOMEM, ENOMEM_journal_pin_fifo) \ 64 + x(ENOMEM, ENOMEM_journal_buf) \ 65 + x(ENOMEM, ENOMEM_gc_start) \ 66 + x(ENOMEM, ENOMEM_gc_alloc_start) \ 67 + x(ENOMEM, ENOMEM_gc_reflink_start) \ 68 + x(ENOMEM, ENOMEM_gc_gens) \ 69 + x(ENOMEM, ENOMEM_gc_repair_key) \ 70 + x(ENOMEM, ENOMEM_fsck_extent_ends_at) \ 71 + x(ENOMEM, ENOMEM_fsck_add_nlink) \ 72 + x(ENOMEM, ENOMEM_journal_key_insert) \ 73 + x(ENOMEM, ENOMEM_journal_keys_sort) \ 74 + x(ENOMEM, ENOMEM_journal_replay) \ 75 + x(ENOMEM, ENOMEM_read_superblock_clean) \ 76 + x(ENOMEM, ENOMEM_fs_alloc) \ 77 + x(ENOMEM, ENOMEM_fs_name_alloc) \ 78 + x(ENOMEM, ENOMEM_fs_other_alloc) \ 79 + x(ENOMEM, ENOMEM_dev_alloc) \ 7 80 x(ENOSPC, ENOSPC_disk_reservation) \ 8 81 x(ENOSPC, ENOSPC_bucket_alloc) \ 9 82 x(ENOSPC, ENOSPC_disk_label_add) \ ··· 87 14 x(ENOSPC, ENOSPC_subvolume_create) \ 88 15 x(ENOSPC, ENOSPC_sb) \ 89 16 x(ENOSPC, ENOSPC_sb_journal) \ 17 + x(ENOSPC, ENOSPC_sb_journal_seq_blacklist) \ 90 18 x(ENOSPC, ENOSPC_sb_quota) \ 91 19 x(ENOSPC, ENOSPC_sb_replicas) \ 92 20 x(ENOSPC, ENOSPC_sb_members) \ 21 + x(ENOSPC, ENOSPC_sb_crypt) \ 93 22 x(0, open_buckets_empty) \ 94 23 x(0, freelist_empty) \ 95 24 x(BCH_ERR_freelist_empty, no_buckets_found) \
+13 -7
fs/bcachefs/fs-io.c
··· 3713 3713 3714 3714 if (bioset_init(&c->writepage_bioset, 3715 3715 4, offsetof(struct bch_writepage_io, op.wbio.bio), 3716 - BIOSET_NEED_BVECS) || 3717 - bioset_init(&c->dio_read_bioset, 3716 + BIOSET_NEED_BVECS)) 3717 + return -BCH_ERR_ENOMEM_writepage_bioset_init; 3718 + 3719 + if (bioset_init(&c->dio_read_bioset, 3718 3720 4, offsetof(struct dio_read, rbio.bio), 3719 - BIOSET_NEED_BVECS) || 3720 - bioset_init(&c->dio_write_bioset, 3721 + BIOSET_NEED_BVECS)) 3722 + return -BCH_ERR_ENOMEM_dio_read_bioset_init; 3723 + 3724 + if (bioset_init(&c->dio_write_bioset, 3721 3725 4, offsetof(struct dio_write, op.wbio.bio), 3722 - BIOSET_NEED_BVECS) || 3723 - bioset_init(&c->nocow_flush_bioset, 3726 + BIOSET_NEED_BVECS)) 3727 + return -BCH_ERR_ENOMEM_dio_write_bioset_init; 3728 + 3729 + if (bioset_init(&c->nocow_flush_bioset, 3724 3730 1, offsetof(struct nocow_flush, bio), 0)) 3725 - ret = -ENOMEM; 3731 + return -BCH_ERR_ENOMEM_nocow_flush_bioset_init; 3726 3732 3727 3733 pr_verbose_init(c->opts, "ret %i", ret); 3728 3734 return ret;
+2 -2
fs/bcachefs/fsck.c
··· 1237 1237 sizeof(seen->ids.data[0]) * seen->ids.size, 1238 1238 GFP_KERNEL); 1239 1239 if (!n.seen.ids.data) 1240 - return -ENOMEM; 1240 + return -BCH_ERR_ENOMEM_fsck_extent_ends_at; 1241 1241 1242 1242 darray_for_each(*extent_ends, i) { 1243 1243 if (i->snapshot == k.k->p.snapshot) { ··· 2141 2141 if (!d) { 2142 2142 bch_err(c, "fsck: error allocating memory for nlink_table, size %zu", 2143 2143 new_size); 2144 - return -ENOMEM; 2144 + return -BCH_ERR_ENOMEM_fsck_add_nlink; 2145 2145 } 2146 2146 2147 2147 if (t->d)
+17 -9
fs/bcachefs/io.c
··· 2995 2995 int bch2_fs_io_init(struct bch_fs *c) 2996 2996 { 2997 2997 if (bioset_init(&c->bio_read, 1, offsetof(struct bch_read_bio, bio), 2998 - BIOSET_NEED_BVECS) || 2999 - bioset_init(&c->bio_read_split, 1, offsetof(struct bch_read_bio, bio), 3000 - BIOSET_NEED_BVECS) || 3001 - bioset_init(&c->bio_write, 1, offsetof(struct bch_write_bio, bio), 3002 - BIOSET_NEED_BVECS) || 3003 - mempool_init_page_pool(&c->bio_bounce_pages, 2998 + BIOSET_NEED_BVECS)) 2999 + return -BCH_ERR_ENOMEM_bio_read_init; 3000 + 3001 + if (bioset_init(&c->bio_read_split, 1, offsetof(struct bch_read_bio, bio), 3002 + BIOSET_NEED_BVECS)) 3003 + return -BCH_ERR_ENOMEM_bio_read_split_init; 3004 + 3005 + if (bioset_init(&c->bio_write, 1, offsetof(struct bch_write_bio, bio), 3006 + BIOSET_NEED_BVECS)) 3007 + return -BCH_ERR_ENOMEM_bio_write_init; 3008 + 3009 + if (mempool_init_page_pool(&c->bio_bounce_pages, 3004 3010 max_t(unsigned, 3005 3011 c->opts.btree_node_size, 3006 3012 c->opts.encoded_extent_max) / 3007 - PAGE_SIZE, 0) || 3008 - rhashtable_init(&c->promote_table, &bch_promote_params)) 3009 - return -ENOMEM; 3013 + PAGE_SIZE, 0)) 3014 + return -BCH_ERR_ENOMEM_bio_bounce_pages_init; 3015 + 3016 + if (rhashtable_init(&c->promote_table, &bch_promote_params)) 3017 + return -BCH_ERR_ENOMEM_promote_table_init; 3010 3018 3011 3019 return 0; 3012 3020 }
+8 -8
fs/bcachefs/journal.c
··· 768 768 new_buckets = kcalloc(nr, sizeof(u64), GFP_KERNEL); 769 769 new_bucket_seq = kcalloc(nr, sizeof(u64), GFP_KERNEL); 770 770 if (!bu || !ob || !new_buckets || !new_bucket_seq) { 771 - ret = -ENOMEM; 771 + ret = -BCH_ERR_ENOMEM_set_nr_journal_buckets; 772 772 goto err_free; 773 773 } 774 774 ··· 941 941 unsigned nr; 942 942 943 943 if (dynamic_fault("bcachefs:add:journal_alloc")) 944 - return -ENOMEM; 944 + return -BCH_ERR_ENOMEM_set_nr_journal_buckets; 945 945 946 946 /* 1/128th of the device by default: */ 947 947 nr = ca->mi.nbuckets >> 7; ··· 1033 1033 init_fifo(&j->pin, roundup_pow_of_two(nr + 1), GFP_KERNEL); 1034 1034 if (!j->pin.data) { 1035 1035 bch_err(c, "error reallocating journal fifo (%llu open entries)", nr); 1036 - return -ENOMEM; 1036 + return -BCH_ERR_ENOMEM_journal_pin_fifo; 1037 1037 } 1038 1038 } 1039 1039 ··· 1127 1127 1128 1128 ja->bucket_seq = kcalloc(ja->nr, sizeof(u64), GFP_KERNEL); 1129 1129 if (!ja->bucket_seq) 1130 - return -ENOMEM; 1130 + return -BCH_ERR_ENOMEM_dev_journal_init; 1131 1131 1132 1132 nr_bvecs = DIV_ROUND_UP(JOURNAL_ENTRY_SIZE_MAX, PAGE_SIZE); 1133 1133 1134 1134 ca->journal.bio = bio_kmalloc(nr_bvecs, GFP_KERNEL); 1135 1135 if (!ca->journal.bio) 1136 - return -ENOMEM; 1136 + return -BCH_ERR_ENOMEM_dev_journal_init; 1137 1137 1138 1138 bio_init(ca->journal.bio, NULL, ca->journal.bio->bi_inline_vecs, nr_bvecs, 0); 1139 1139 1140 1140 ja->buckets = kcalloc(ja->nr, sizeof(u64), GFP_KERNEL); 1141 1141 if (!ja->buckets) 1142 - return -ENOMEM; 1142 + return -BCH_ERR_ENOMEM_dev_journal_init; 1143 1143 1144 1144 if (journal_buckets_v2) { 1145 1145 unsigned nr = bch2_sb_field_journal_v2_nr_entries(journal_buckets_v2); ··· 1193 1193 { .cur_entry_offset = JOURNAL_ENTRY_CLOSED_VAL }).v); 1194 1194 1195 1195 if (!(init_fifo(&j->pin, JOURNAL_PIN, GFP_KERNEL))) { 1196 - ret = -ENOMEM; 1196 + ret = -BCH_ERR_ENOMEM_journal_pin_fifo; 1197 1197 goto out; 1198 1198 } 1199 1199 ··· 1201 1201 j->buf[i].buf_size = JOURNAL_ENTRY_SIZE_MIN; 1202 1202 j->buf[i].data = kvpmalloc(j->buf[i].buf_size, GFP_KERNEL); 1203 1203 if (!j->buf[i].data) { 1204 - ret = -ENOMEM; 1204 + ret = -BCH_ERR_ENOMEM_journal_buf; 1205 1205 goto out; 1206 1206 } 1207 1207 }
+4 -4
fs/bcachefs/journal_io.c
··· 118 118 journal_entry_radix_idx(c, le64_to_cpu(j->seq)), 119 119 GFP_KERNEL); 120 120 if (!_i) 121 - return -ENOMEM; 121 + return -BCH_ERR_ENOMEM_journal_entry_add; 122 122 123 123 /* 124 124 * Duplicate journal entries? If so we want the one that didn't have a ··· 148 148 replace: 149 149 i = kvpmalloc(offsetof(struct journal_replay, j) + bytes, GFP_KERNEL); 150 150 if (!i) 151 - return -ENOMEM; 151 + return -BCH_ERR_ENOMEM_journal_entry_add; 152 152 153 153 i->nr_ptrs = 0; 154 154 i->csum_good = entry_ptr.csum_good; ··· 835 835 836 836 /* the bios are sized for this many pages, max: */ 837 837 if (new_size > JOURNAL_ENTRY_SIZE_MAX) 838 - return -ENOMEM; 838 + return -BCH_ERR_ENOMEM_journal_read_buf_realloc; 839 839 840 840 new_size = roundup_pow_of_two(new_size); 841 841 n = kvpmalloc(new_size, GFP_KERNEL); 842 842 if (!n) 843 - return -ENOMEM; 843 + return -BCH_ERR_ENOMEM_journal_read_buf_realloc; 844 844 845 845 kvpfree(b->data, b->size); 846 846 b->data = n;
+2 -2
fs/bcachefs/journal_sb.c
··· 33 33 34 34 b = kmalloc_array(nr, sizeof(u64), GFP_KERNEL); 35 35 if (!b) 36 - return -ENOMEM; 36 + return -BCH_ERR_ENOMEM_sb_journal_validate; 37 37 38 38 for (i = 0; i < nr; i++) 39 39 b[i] = le64_to_cpu(journal->buckets[i]); ··· 116 116 117 117 b = kmalloc_array(nr, sizeof(*b), GFP_KERNEL); 118 118 if (!b) 119 - return -ENOMEM; 119 + return -BCH_ERR_ENOMEM_sb_journal_v2_validate; 120 120 121 121 for (i = 0; i < nr; i++) { 122 122 b[i].start = le64_to_cpu(journal->d[i].start);
+2 -2
fs/bcachefs/journal_seq_blacklist.c
··· 103 103 bl = bch2_sb_resize_journal_seq_blacklist(&c->disk_sb, 104 104 sb_blacklist_u64s(nr + 1)); 105 105 if (!bl) { 106 - ret = -ENOMEM; 106 + ret = -BCH_ERR_ENOSPC_sb_journal_seq_blacklist; 107 107 goto out; 108 108 } 109 109 ··· 168 168 t = kzalloc(sizeof(*t) + sizeof(t->entries[0]) * nr, 169 169 GFP_KERNEL); 170 170 if (!t) 171 - return -ENOMEM; 171 + return -BCH_ERR_ENOMEM_blacklist_table_init; 172 172 173 173 t->nr = nr; 174 174
+5 -5
fs/bcachefs/recovery.c
··· 228 228 if (!new_keys.d) { 229 229 bch_err(c, "%s: error allocating new key array (size %zu)", 230 230 __func__, new_keys.size); 231 - return -ENOMEM; 231 + return -BCH_ERR_ENOMEM_journal_key_insert; 232 232 } 233 233 234 234 /* Since @keys was full, there was no gap: */ ··· 266 266 267 267 n = kmalloc(bkey_bytes(&k->k), GFP_KERNEL); 268 268 if (!n) 269 - return -ENOMEM; 269 + return -BCH_ERR_ENOMEM_journal_key_insert; 270 270 271 271 bkey_copy(n, k); 272 272 ret = bch2_journal_key_insert_take(c, id, level, n); ··· 503 503 504 504 keys->d = kvmalloc_array(keys->size, sizeof(keys->d[0]), GFP_KERNEL); 505 505 if (!keys->d) 506 - return -ENOMEM; 506 + return -BCH_ERR_ENOMEM_journal_keys_sort; 507 507 508 508 genradix_for_each(&c->journal_entries, iter, _i) { 509 509 i = *_i; ··· 601 601 602 602 keys_sorted = kvmalloc_array(sizeof(*keys_sorted), keys->nr, GFP_KERNEL); 603 603 if (!keys_sorted) 604 - return -ENOMEM; 604 + return -BCH_ERR_ENOMEM_journal_replay; 605 605 606 606 for (i = 0; i < keys->nr; i++) 607 607 keys_sorted[i] = &keys->d[i]; ··· 905 905 GFP_KERNEL); 906 906 if (!clean) { 907 907 mutex_unlock(&c->sb_lock); 908 - return ERR_PTR(-ENOMEM); 908 + return ERR_PTR(-BCH_ERR_ENOMEM_read_superblock_clean); 909 909 } 910 910 911 911 ret = bch2_sb_clean_validate_late(c, clean, READ);
+21 -17
fs/bcachefs/replicas.c
··· 336 336 return ret; 337 337 err: 338 338 bch_err(c, "error updating replicas table: memory allocation failure"); 339 - ret = -ENOMEM; 339 + ret = -BCH_ERR_ENOMEM_replicas_table; 340 340 goto out; 341 341 } 342 342 ··· 383 383 if (c->replicas_gc.entries && 384 384 !__replicas_has_entry(&c->replicas_gc, new_entry)) { 385 385 new_gc = cpu_replicas_add_entry(&c->replicas_gc, new_entry); 386 - if (!new_gc.entries) 386 + if (!new_gc.entries) { 387 + ret = -BCH_ERR_ENOMEM_cpu_replicas; 387 388 goto err; 389 + } 388 390 } 389 391 390 392 if (!__replicas_has_entry(&c->replicas, new_entry)) { 391 393 new_r = cpu_replicas_add_entry(&c->replicas, new_entry); 392 - if (!new_r.entries) 394 + if (!new_r.entries) { 395 + ret = -BCH_ERR_ENOMEM_cpu_replicas; 393 396 goto err; 397 + } 394 398 395 399 ret = bch2_cpu_replicas_to_sb_replicas(c, &new_r); 396 400 if (ret) ··· 429 425 430 426 return ret; 431 427 err: 432 - bch_err(c, "error adding replicas entry: memory allocation failure"); 433 - ret = -ENOMEM; 428 + bch_err(c, "error adding replicas entry: %s", bch2_err_str(ret)); 434 429 goto out; 435 430 } 436 431 ··· 481 478 bch2_fs_usage_read_one(c, &c->usage_base->replicas[i])) { 482 479 n = cpu_replicas_add_entry(&c->replicas_gc, e); 483 480 if (!n.entries) { 484 - ret = -ENOMEM; 481 + ret = -BCH_ERR_ENOMEM_cpu_replicas; 485 482 goto err; 486 483 } 487 484 ··· 536 533 if (!c->replicas_gc.entries) { 537 534 mutex_unlock(&c->sb_lock); 538 535 bch_err(c, "error allocating c->replicas_gc"); 539 - return -ENOMEM; 536 + return -BCH_ERR_ENOMEM_replicas_gc; 540 537 } 541 538 542 539 for_each_cpu_replicas_entry(&c->replicas, e) ··· 565 562 new.entries = kcalloc(nr, new.entry_size, GFP_KERNEL); 566 563 if (!new.entries) { 567 564 bch_err(c, "error allocating c->replicas_gc"); 568 - return -ENOMEM; 565 + return -BCH_ERR_ENOMEM_replicas_gc; 569 566 } 570 567 571 568 mutex_lock(&c->sb_lock); ··· 624 621 625 622 n = cpu_replicas_add_entry(&c->replicas, r); 626 623 if (!n.entries) 627 - return -ENOMEM; 624 + return -BCH_ERR_ENOMEM_cpu_replicas; 628 625 629 626 ret = replicas_table_update(c, &n); 630 627 if (ret) ··· 658 655 659 656 cpu_r->entries = kcalloc(nr, entry_size, GFP_KERNEL); 660 657 if (!cpu_r->entries) 661 - return -ENOMEM; 658 + return -BCH_ERR_ENOMEM_cpu_replicas; 662 659 663 660 cpu_r->nr = nr; 664 661 cpu_r->entry_size = entry_size; ··· 690 687 691 688 cpu_r->entries = kcalloc(nr, entry_size, GFP_KERNEL); 692 689 if (!cpu_r->entries) 693 - return -ENOMEM; 690 + return -BCH_ERR_ENOMEM_cpu_replicas; 694 691 695 692 cpu_r->nr = nr; 696 693 cpu_r->entry_size = entry_size; ··· 720 717 ret = __bch2_sb_replicas_to_cpu_replicas(sb_v1, &new_r); 721 718 else if ((sb_v0 = bch2_sb_get_replicas_v0(c->disk_sb.sb))) 722 719 ret = __bch2_sb_replicas_v0_to_cpu_replicas(sb_v0, &new_r); 723 - 724 720 if (ret) 725 - return -ENOMEM; 721 + return ret; 726 722 727 723 bch2_cpu_replicas_sort(&new_r); 728 724 ··· 883 881 struct bch_replicas_cpu cpu_r; 884 882 int ret; 885 883 886 - if (__bch2_sb_replicas_to_cpu_replicas(sb_r, &cpu_r)) 887 - return -ENOMEM; 884 + ret = __bch2_sb_replicas_to_cpu_replicas(sb_r, &cpu_r); 885 + if (ret) 886 + return ret; 888 887 889 888 ret = bch2_cpu_replicas_validate(&cpu_r, sb, err); 890 889 kfree(cpu_r.entries); ··· 922 919 struct bch_replicas_cpu cpu_r; 923 920 int ret; 924 921 925 - if (__bch2_sb_replicas_v0_to_cpu_replicas(sb_r, &cpu_r)) 926 - return -ENOMEM; 922 + ret = __bch2_sb_replicas_v0_to_cpu_replicas(sb_r, &cpu_r); 923 + if (ret) 924 + return ret; 927 925 928 926 ret = bch2_cpu_replicas_validate(&cpu_r, sb, err); 929 927 kfree(cpu_r.entries);
+1 -1
fs/bcachefs/subvolume.c
··· 87 87 U32_MAX - new.k->p.offset, 88 88 GFP_KERNEL); 89 89 if (!t) 90 - return -ENOMEM; 90 + return -BCH_ERR_ENOMEM_mark_snapshot; 91 91 92 92 if (new.k->type == KEY_TYPE_snapshot) { 93 93 struct bkey_s_c_snapshot s = bkey_s_c_to_snapshot(new);
+6 -5
fs/bcachefs/super-io.c
··· 139 139 return 0; 140 140 141 141 if (dynamic_fault("bcachefs:add:super_realloc")) 142 - return -ENOMEM; 142 + return -BCH_ERR_ENOMEM_sb_realloc_injected; 143 143 144 144 if (sb->have_bio) { 145 145 unsigned nr_bvecs = DIV_ROUND_UP(new_buffer_size, PAGE_SIZE); 146 146 147 147 bio = bio_kmalloc(nr_bvecs, GFP_KERNEL); 148 148 if (!bio) 149 - return -ENOMEM; 149 + return -BCH_ERR_ENOMEM_sb_bio_realloc; 150 150 151 151 bio_init(bio, NULL, bio->bi_inline_vecs, nr_bvecs, 0); 152 152 ··· 156 156 157 157 new_sb = krealloc(sb->sb, new_buffer_size, GFP_NOFS|__GFP_ZERO); 158 158 if (!new_sb) 159 - return -ENOMEM; 159 + return -BCH_ERR_ENOMEM_sb_buf_realloc; 160 160 161 161 sb->sb = new_sb; 162 162 sb->buffer_size = new_buffer_size; ··· 562 562 } 563 563 564 564 if (bytes > sb->buffer_size) { 565 - if (bch2_sb_realloc(sb, le32_to_cpu(sb->sb->u64s))) 566 - return -ENOMEM; 565 + ret = bch2_sb_realloc(sb, le32_to_cpu(sb->sb->u64s)); 566 + if (ret) 567 + return ret; 567 568 goto reread; 568 569 } 569 570
+4 -4
fs/bcachefs/super.c
··· 644 644 645 645 c = kvpmalloc(sizeof(struct bch_fs), GFP_KERNEL|__GFP_ZERO); 646 646 if (!c) { 647 - c = ERR_PTR(-ENOMEM); 647 + c = ERR_PTR(-BCH_ERR_ENOMEM_fs_alloc); 648 648 goto out; 649 649 } 650 650 ··· 744 744 strscpy(c->name, name.buf, sizeof(c->name)); 745 745 printbuf_exit(&name); 746 746 747 - ret = name.allocation_failure ? -ENOMEM : 0; 747 + ret = name.allocation_failure ? -BCH_ERR_ENOMEM_fs_name_alloc : 0; 748 748 if (ret) 749 749 goto err; 750 750 ··· 808 808 mempool_init_kmalloc_pool(&c->large_bkey_pool, 1, 2048) || 809 809 !(c->unused_inode_hints = kcalloc(1U << c->inode_shard_bits, 810 810 sizeof(u64), GFP_KERNEL))) { 811 - ret = -ENOMEM; 811 + ret = -BCH_ERR_ENOMEM_fs_other_alloc; 812 812 goto err; 813 813 } 814 814 ··· 1189 1189 err: 1190 1190 if (ca) 1191 1191 bch2_dev_free(ca); 1192 - ret = -ENOMEM; 1192 + ret = -BCH_ERR_ENOMEM_dev_alloc; 1193 1193 goto out; 1194 1194 } 1195 1195