]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/bkey.c
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / libbcachefs / bkey.c
index d6960e259c804897137220f3f26ad734a087b35f..76e79a15ba08fb23ed9d0560dcd5966fe68ce92a 100644 (file)
@@ -33,7 +33,7 @@ void bch2_bkey_packed_to_binary_text(struct printbuf *out,
                        next_key_bits -= 64;
                }
 
-               bch2_prt_u64_binary(out, v, min(word_bits, nr_key_bits));
+               bch2_prt_u64_base2_nbits(out, v, min(word_bits, nr_key_bits));
 
                if (!next_key_bits)
                        break;
@@ -127,7 +127,7 @@ static void pack_state_finish(struct pack_state *state,
                              struct bkey_packed *k)
 {
        EBUG_ON(state->p <  k->_data);
-       EBUG_ON(state->p >= k->_data + state->format->key_u64s);
+       EBUG_ON(state->p >= (u64 *) k->_data + state->format->key_u64s);
 
        *state->p = state->w;
 }
@@ -308,9 +308,14 @@ struct bpos __bkey_unpack_pos(const struct bkey_format *format,
 
 /**
  * bch2_bkey_pack_key -- pack just the key, not the value
+ * @out:       packed result
+ * @in:                key to pack
+ * @format:    format of packed result
+ *
+ * Returns: true on success, false on failure
  */
 bool bch2_bkey_pack_key(struct bkey_packed *out, const struct bkey *in,
-                  const struct bkey_format *format)
+                       const struct bkey_format *format)
 {
        struct pack_state state = pack_state_init(format, out);
        u64 *w = out->_data;
@@ -336,9 +341,12 @@ bool bch2_bkey_pack_key(struct bkey_packed *out, const struct bkey *in,
 
 /**
  * bch2_bkey_unpack -- unpack the key and the value
+ * @b:         btree node of @src key (for packed format)
+ * @dst:       unpacked result
+ * @src:       packed input
  */
 void bch2_bkey_unpack(const struct btree *b, struct bkey_i *dst,
-                const struct bkey_packed *src)
+                     const struct bkey_packed *src)
 {
        __bkey_unpack_key(b, &dst->k, src);
 
@@ -349,19 +357,24 @@ void bch2_bkey_unpack(const struct btree *b, struct bkey_i *dst,
 
 /**
  * bch2_bkey_pack -- pack the key and the value
+ * @dst:       packed result
+ * @src:       unpacked input
+ * @format:    format of packed result
+ *
+ * Returns: true on success, false on failure
  */
-bool bch2_bkey_pack(struct bkey_packed *out, const struct bkey_i *in,
-              const struct bkey_format *format)
+bool bch2_bkey_pack(struct bkey_packed *dst, const struct bkey_i *src,
+                   const struct bkey_format *format)
 {
        struct bkey_packed tmp;
 
-       if (!bch2_bkey_pack_key(&tmp, &in->k, format))
+       if (!bch2_bkey_pack_key(&tmp, &src->k, format))
                return false;
 
-       memmove_u64s((u64 *) out + format->key_u64s,
-                    &in->v,
-                    bkey_val_u64s(&in->k));
-       memcpy_u64s_small(out, &tmp, format->key_u64s);
+       memmove_u64s((u64 *) dst + format->key_u64s,
+                    &src->v,
+                    bkey_val_u64s(&src->k));
+       memcpy_u64s_small(dst, &tmp, format->key_u64s);
 
        return true;
 }
@@ -591,8 +604,10 @@ struct bkey_format bch2_bkey_format_done(struct bkey_format_state *s)
 
        /* allow for extent merging: */
        if (ret.bits_per_field[BKEY_FIELD_SIZE]) {
-               ret.bits_per_field[BKEY_FIELD_SIZE] += 4;
-               bits += 4;
+               unsigned b = min(4U, 32U - ret.bits_per_field[BKEY_FIELD_SIZE]);
+
+               ret.bits_per_field[BKEY_FIELD_SIZE] += b;
+               bits += b;
        }
 
        ret.key_u64s = DIV_ROUND_UP(bits, 64);