bcachefs: New bch_extent_rebalance fields
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 20 Oct 2024 01:41:20 +0000 (21:41 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:16 +0000 (01:36 -0500)
- Add more io path options to bch_extent_rebalance
- For each option, track whether it came from the filesystem or the
  inode

This will be used for improved rebalance support for reflinked data.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/extents.c
fs/bcachefs/extents_format.h
fs/bcachefs/opts.h

index a134aa5a76bb1b430139b815228a359c050a4e42..467ffed0809e0f84630f7d9f35bcc01c726a8b98 100644 (file)
@@ -1121,6 +1121,57 @@ void bch2_extent_crc_unpacked_to_text(struct printbuf *out, struct bch_extent_cr
        bch2_prt_compression_type(out, crc->compression_type);
 }
 
+static void bch2_extent_rebalance_to_text(struct printbuf *out, struct bch_fs *c,
+                                         const struct bch_extent_rebalance *r)
+{
+       prt_str(out, "rebalance:");
+
+       prt_printf(out, " replicas=%u", r->data_replicas);
+       if (r->data_replicas_from_inode)
+               prt_str(out, " (inode)");
+
+       prt_str(out, " checksum=");
+       bch2_prt_csum_opt(out, r->data_checksum);
+       if (r->data_checksum_from_inode)
+               prt_str(out, " (inode)");
+
+       if (r->background_compression || r->background_compression_from_inode) {
+               prt_str(out, " background_compression=");
+               bch2_compression_opt_to_text(out, r->background_compression);
+
+               if (r->background_compression_from_inode)
+                       prt_str(out, " (inode)");
+       }
+
+       if (r->background_target || r->background_target_from_inode) {
+               prt_str(out, " background_target=");
+               if (c)
+                       bch2_target_to_text(out, c, r->background_target);
+               else
+                       prt_printf(out, "%u", r->background_target);
+
+               if (r->background_target_from_inode)
+                       prt_str(out, " (inode)");
+       }
+
+       if (r->promote_target || r->promote_target_from_inode) {
+               prt_str(out, " promote_target=");
+               if (c)
+                       bch2_target_to_text(out, c, r->promote_target);
+               else
+                       prt_printf(out, "%u", r->promote_target);
+
+               if (r->promote_target_from_inode)
+                       prt_str(out, " (inode)");
+       }
+
+       if (r->erasure_code || r->erasure_code_from_inode) {
+               prt_printf(out, " ec=%u", r->erasure_code);
+               if (r->erasure_code_from_inode)
+                       prt_str(out, " (inode)");
+       }
+}
+
 void bch2_bkey_ptrs_to_text(struct printbuf *out, struct bch_fs *c,
                            struct bkey_s_c k)
 {
@@ -1156,18 +1207,10 @@ void bch2_bkey_ptrs_to_text(struct printbuf *out, struct bch_fs *c,
                               (u64) ec->idx, ec->block);
                        break;
                }
-               case BCH_EXTENT_ENTRY_rebalance: {
-                       const struct bch_extent_rebalance *r = &entry->rebalance;
-
-                       prt_str(out, "rebalance: target ");
-                       if (c)
-                               bch2_target_to_text(out, c, r->background_target);
-                       else
-                               prt_printf(out, "%u", r->background_target);
-                       prt_str(out, " compression ");
-                       bch2_compression_opt_to_text(out, r->background_compression);
+               case BCH_EXTENT_ENTRY_rebalance:
+                       bch2_extent_rebalance_to_text(out, c, &entry->rebalance);
                        break;
-               }
+
                default:
                        prt_printf(out, "(invalid extent entry %.16llx)", *((u64 *) entry));
                        return;
index 520697f236c03db8f66e428069d03bf2785e96bd..222eed6b46d86152ef38ec392556cedb566b6a05 100644 (file)
@@ -204,21 +204,49 @@ struct bch_extent_stripe_ptr {
 struct bch_extent_rebalance {
 #if defined(__LITTLE_ENDIAN_BITFIELD)
        __u64                   type:6,
-                               unused:34,
+                               unused:3,
+
+                               promote_target_from_inode:1,
+                               erasure_code_from_inode:1,
+                               data_checksum_from_inode:1,
+                               background_compression_from_inode:1,
+                               data_replicas_from_inode:1,
+                               background_target_from_inode:1,
+
+                               promote_target:16,
+                               erasure_code:1,
+                               data_checksum:4,
+                               data_replicas:4,
                                background_compression:8, /* enum bch_compression_opt */
                                background_target:16;
 #elif defined (__BIG_ENDIAN_BITFIELD)
        __u64                   background_target:16,
                                background_compression:8,
-                               unused:34,
+                               data_replicas:4,
+                               data_checksum:4,
+                               erasure_code:1,
+                               promote_target:16,
+
+                               background_target_from_inode:1,
+                               data_replicas_from_inode:1,
+                               background_compression_from_inode:1,
+                               data_checksum_from_inode:1,
+                               erasure_code_from_inode:1,
+                               promote_target_from_inode:1,
+
+                               unused:3,
                                type:6;
 #endif
 };
 
 /* subset of BCH_INODE_OPTS */
 #define BCH_REBALANCE_OPTS()                   \
+       x(data_checksum)                        \
        x(background_compression)               \
-       x(background_target)
+       x(data_replicas)                        \
+       x(promote_target)                       \
+       x(background_target)                    \
+       x(erasure_code)
 
 union bch_extent_entry {
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ||  __BITS_PER_LONG == 64
index f6dc0628b025704c305197885b045ebbb20eb3ef..39cdc185fa733b57c2e668aa21fb211db2380da5 100644 (file)
@@ -665,7 +665,8 @@ static inline struct bch_extent_rebalance io_opts_to_rebalance_opts(struct bch_i
        return (struct bch_extent_rebalance) {
                .type = BIT(BCH_EXTENT_ENTRY_rebalance),
 #define x(_name)                                                       \
-               ._name = opts->_name,
+               ._name = opts->_name,                                   \
+               ._name##_from_inode = opts->_name##_from_inode,
                BCH_REBALANCE_OPTS()
 #undef x
        };