]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/replicas.c
Update bcachefs sources to dab31ca168 bcachefs: Add some logging for btree node rewri...
[bcachefs-tools-debian] / libbcachefs / replicas.c
index c2771112d573d56370d283660062836ec79df339..482bedf4be8ba2cd696dd5afae09230281ae8aa0 100644 (file)
@@ -42,14 +42,14 @@ void bch2_replicas_entry_v0_to_text(struct printbuf *out,
        unsigned i;
 
        if (e->data_type < BCH_DATA_NR)
-               pr_buf(out, "%s", bch2_data_types[e->data_type]);
+               prt_printf(out, "%s", bch2_data_types[e->data_type]);
        else
-               pr_buf(out, "(invalid data type %u)", e->data_type);
+               prt_printf(out, "(invalid data type %u)", e->data_type);
 
-       pr_buf(out, ": %u [", e->nr_devs);
+       prt_printf(out, ": %u [", e->nr_devs);
        for (i = 0; i < e->nr_devs; i++)
-               pr_buf(out, i ? " %u" : "%u", e->devs[i]);
-       pr_buf(out, "]");
+               prt_printf(out, i ? " %u" : "%u", e->devs[i]);
+       prt_printf(out, "]");
 }
 
 void bch2_replicas_entry_to_text(struct printbuf *out,
@@ -58,14 +58,14 @@ void bch2_replicas_entry_to_text(struct printbuf *out,
        unsigned i;
 
        if (e->data_type < BCH_DATA_NR)
-               pr_buf(out, "%s", bch2_data_types[e->data_type]);
+               prt_printf(out, "%s", bch2_data_types[e->data_type]);
        else
-               pr_buf(out, "(invalid data type %u)", e->data_type);
+               prt_printf(out, "(invalid data type %u)", e->data_type);
 
-       pr_buf(out, ": %u/%u [", e->nr_required, e->nr_devs);
+       prt_printf(out, ": %u/%u [", e->nr_required, e->nr_devs);
        for (i = 0; i < e->nr_devs; i++)
-               pr_buf(out, i ? " %u" : "%u", e->devs[i]);
-       pr_buf(out, "]");
+               prt_printf(out, i ? " %u" : "%u", e->devs[i]);
+       prt_printf(out, "]");
 }
 
 void bch2_cpu_replicas_to_text(struct printbuf *out,
@@ -76,7 +76,7 @@ void bch2_cpu_replicas_to_text(struct printbuf *out,
 
        for_each_cpu_replicas_entry(r, e) {
                if (!first)
-                       pr_buf(out, " ");
+                       prt_printf(out, " ");
                first = false;
 
                bch2_replicas_entry_to_text(out, e);
@@ -299,6 +299,13 @@ static int replicas_table_update(struct bch_fs *c,
 
        memset(new_usage, 0, sizeof(new_usage));
 
+       for (i = 0; i < ARRAY_SIZE(new_usage); i++)
+               if (!(new_usage[i] = __alloc_percpu_gfp(bytes,
+                                       sizeof(u64), GFP_KERNEL)))
+                       goto err;
+
+       memset(new_usage, 0, sizeof(new_usage));
+
        for (i = 0; i < ARRAY_SIZE(new_usage); i++)
                if (!(new_usage[i] = __alloc_percpu_gfp(bytes,
                                        sizeof(u64), GFP_KERNEL)))
@@ -478,7 +485,7 @@ int bch2_replicas_gc_end(struct bch_fs *c, int ret)
                    bch2_fs_usage_read_one(c, &c->usage_base->replicas[i])) {
                        n = cpu_replicas_add_entry(&c->replicas_gc, e);
                        if (!n.entries) {
-                               ret = -ENOSPC;
+                               ret = -ENOMEM;
                                goto err;
                        }
 
@@ -487,10 +494,9 @@ int bch2_replicas_gc_end(struct bch_fs *c, int ret)
                }
        }
 
-       if (bch2_cpu_replicas_to_sb_replicas(c, &c->replicas_gc)) {
-               ret = -ENOSPC;
+       ret = bch2_cpu_replicas_to_sb_replicas(c, &c->replicas_gc);
+       if (ret)
                goto err;
-       }
 
        ret = replicas_table_update(c, &c->replicas_gc);
 err:
@@ -593,10 +599,9 @@ retry:
 
        bch2_cpu_replicas_sort(&new);
 
-       if (bch2_cpu_replicas_to_sb_replicas(c, &new)) {
-               ret = -ENOSPC;
+       ret = bch2_cpu_replicas_to_sb_replicas(c, &new);
+       if (ret)
                goto err;
-       }
 
        ret = replicas_table_update(c, &new);
 err:
@@ -751,7 +756,7 @@ static int bch2_cpu_replicas_to_sb_replicas_v0(struct bch_fs *c,
        sb_r = bch2_sb_resize_replicas_v0(&c->disk_sb,
                        DIV_ROUND_UP(bytes, sizeof(u64)));
        if (!sb_r)
-               return -ENOSPC;
+               return -BCH_ERR_ENOSPC_sb_replicas;
 
        bch2_sb_field_delete(&c->disk_sb, BCH_SB_FIELD_replicas);
        sb_r = bch2_sb_get_replicas_v0(c->disk_sb.sb);
@@ -796,7 +801,7 @@ static int bch2_cpu_replicas_to_sb_replicas(struct bch_fs *c,
        sb_r = bch2_sb_resize_replicas(&c->disk_sb,
                        DIV_ROUND_UP(bytes, sizeof(u64)));
        if (!sb_r)
-               return -ENOSPC;
+               return -BCH_ERR_ENOSPC_sb_replicas;
 
        bch2_sb_field_delete(&c->disk_sb, BCH_SB_FIELD_replicas_v0);
        sb_r = bch2_sb_get_replicas(c->disk_sb.sb);
@@ -834,29 +839,29 @@ static int bch2_cpu_replicas_validate(struct bch_replicas_cpu *cpu_r,
                        cpu_replicas_entry(cpu_r, i);
 
                if (e->data_type >= BCH_DATA_NR) {
-                       pr_buf(err, "invalid data type in entry ");
+                       prt_printf(err, "invalid data type in entry ");
                        bch2_replicas_entry_to_text(err, e);
-                       return -EINVAL;
+                       return -BCH_ERR_invalid_sb_replicas;
                }
 
                if (!e->nr_devs) {
-                       pr_buf(err, "no devices in entry ");
+                       prt_printf(err, "no devices in entry ");
                        bch2_replicas_entry_to_text(err, e);
-                       return -EINVAL;
+                       return -BCH_ERR_invalid_sb_replicas;
                }
 
                if (e->nr_required > 1 &&
                    e->nr_required >= e->nr_devs) {
-                       pr_buf(err, "bad nr_required in entry ");
+                       prt_printf(err, "bad nr_required in entry ");
                        bch2_replicas_entry_to_text(err, e);
-                       return -EINVAL;
+                       return -BCH_ERR_invalid_sb_replicas;
                }
 
                for (j = 0; j < e->nr_devs; j++)
                        if (!bch2_dev_exists(sb, mi, e->devs[j])) {
-                               pr_buf(err, "invalid device %u in entry ", e->devs[j]);
+                               prt_printf(err, "invalid device %u in entry ", e->devs[j]);
                                bch2_replicas_entry_to_text(err, e);
-                               return -EINVAL;
+                               return -BCH_ERR_invalid_sb_replicas;
                        }
 
                if (i + 1 < cpu_r->nr) {
@@ -866,9 +871,9 @@ static int bch2_cpu_replicas_validate(struct bch_replicas_cpu *cpu_r,
                        BUG_ON(memcmp(e, n, cpu_r->entry_size) > 0);
 
                        if (!memcmp(e, n, cpu_r->entry_size)) {
-                               pr_buf(err, "duplicate replicas entry ");
+                               prt_printf(err, "duplicate replicas entry ");
                                bch2_replicas_entry_to_text(err, e);
-                               return -EINVAL;
+                               return -BCH_ERR_invalid_sb_replicas;
                        }
                }
        }
@@ -901,12 +906,12 @@ static void bch2_sb_replicas_to_text(struct printbuf *out,
 
        for_each_replicas_entry(r, e) {
                if (!first)
-                       pr_buf(out, " ");
+                       prt_printf(out, " ");
                first = false;
 
                bch2_replicas_entry_to_text(out, e);
        }
-       pr_newline(out);
+       prt_newline(out);
 }
 
 const struct bch_sb_field_ops bch_sb_field_ops_replicas = {
@@ -939,12 +944,12 @@ static void bch2_sb_replicas_v0_to_text(struct printbuf *out,
 
        for_each_replicas_entry(sb_r, e) {
                if (!first)
-                       pr_buf(out, " ");
+                       prt_printf(out, " ");
                first = false;
 
                bch2_replicas_entry_v0_to_text(out, e);
        }
-       pr_newline(out);
+       prt_newline(out);
 }
 
 const struct bch_sb_field_ops bch_sb_field_ops_replicas_v0 = {