]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Temporary import of valgrind fixes for bcachefs branch.
authorJustin Husted <sigstop@gmail.com>
Fri, 1 Nov 2019 02:10:19 +0000 (19:10 -0700)
committerKent Overstreet <kent.overstreet@gmail.com>
Mon, 4 Nov 2019 04:17:43 +0000 (23:17 -0500)
libbcachefs/alloc_background.c
libbcachefs/btree_cache.c
libbcachefs/inode.c
libbcachefs/super-io.c
libbcachefs/util.h

index 990701a680b1e5b9abd52db20d50860ff58d6d1e..e252a039dc2b781e97f41d093221202a3fd4ad6e 100644 (file)
@@ -152,6 +152,7 @@ void bch2_alloc_pack(struct bkey_i_alloc *dst,
 {
        unsigned idx = 0;
        void *d = dst->v.data;
+       unsigned bytes;
 
        dst->v.fields   = 0;
        dst->v.gen      = src.gen;
@@ -160,7 +161,9 @@ void bch2_alloc_pack(struct bkey_i_alloc *dst,
        BCH_ALLOC_FIELDS()
 #undef  x
 
-       set_bkey_val_bytes(&dst->k, (void *) d - (void *) &dst->v);
+       bytes = (void *) d - (void *) &dst->v;
+       set_bkey_val_bytes(&dst->k, bytes);
+       memset_u64s_tail(&dst->v, 0, bytes);
 }
 
 static unsigned bch_alloc_val_u64s(const struct bch_alloc *a)
index 416949512057cf8467ee73b63e6fb3fda5757926..2d8f63793180e7293d69bb4dfb185dd7b37bca63 100644 (file)
@@ -83,6 +83,9 @@ static void btree_node_data_alloc(struct bch_fs *c, struct btree *b, gfp_t gfp)
        if (bch2_btree_keys_alloc(b, btree_page_order(c), gfp))
                goto err;
 
+       memset(&b->data->csum, 0, sizeof b->data->csum);
+       b->data->flags = 0;
+
        bc->used++;
        list_move(&b->list, &bc->freeable);
        return;
index e953b78f7d9a76c6d7740a3003f30391b0266ba2..59653b978212ee7ddd39bea7303b04d748512898 100644 (file)
@@ -95,6 +95,7 @@ void bch2_inode_pack(struct bkey_inode_buf *packed,
        u8 *end = (void *) &packed[1];
        u8 *last_nonzero_field = out;
        unsigned nr_fields = 0, last_nonzero_fieldnr = 0;
+       unsigned bytes;
 
        bkey_inode_init(&packed->inode.k_i);
        packed->inode.k.p.inode         = inode->bi_inum;
@@ -117,10 +118,9 @@ void bch2_inode_pack(struct bkey_inode_buf *packed,
        out = last_nonzero_field;
        nr_fields = last_nonzero_fieldnr;
 
-       set_bkey_val_bytes(&packed->inode.k, out - (u8 *) &packed->inode.v);
-       memset(out, 0,
-              (u8 *) &packed->inode.v +
-              bkey_val_bytes(&packed->inode.k) - out);
+       bytes = out - (u8 *) &packed->inode.v;
+       set_bkey_val_bytes(&packed->inode.k, bytes);
+       memset_u64s_tail(&packed->inode.v, 0, bytes);
 
        SET_INODE_NR_FIELDS(&packed->inode.v, nr_fields);
 
index 550a140df2a192875b30e90d6508ae9241697adc..b36cfdf0b41c4a8ac4f6275563f36133d522603d 100644 (file)
@@ -949,6 +949,25 @@ int bch2_fs_mark_dirty(struct bch_fs *c)
        return ret;
 }
 
+static void
+entry_init_u64s(struct jset_entry *entry, unsigned u64s)
+{
+       memset(entry, 0, u64s * sizeof(u64));
+
+       /*
+        * The u64s field counts from the start of data, ignoring the shared
+        * fields.
+        */
+       entry->u64s = u64s - 1;
+}
+
+static void
+entry_init_size(struct jset_entry *entry, size_t size)
+{
+       unsigned u64s = DIV_ROUND_UP(size, sizeof(u64));
+       entry_init_u64s(entry, u64s);
+}
+
 struct jset_entry *
 bch2_journal_super_entries_add_common(struct bch_fs *c,
                                      struct jset_entry *entry,
@@ -963,7 +982,7 @@ bch2_journal_super_entries_add_common(struct bch_fs *c,
             r < c->btree_roots + BTREE_ID_NR;
             r++)
                if (r->alive) {
-                       entry->u64s     = r->key.u64s;
+                       entry_init_u64s(entry, r->key.u64s + 1);
                        entry->btree_id = r - c->btree_roots;
                        entry->level    = r->level;
                        entry->type     = BCH_JSET_ENTRY_btree_root;
@@ -988,8 +1007,7 @@ bch2_journal_super_entries_add_common(struct bch_fs *c,
                struct jset_entry_usage *u =
                        container_of(entry, struct jset_entry_usage, entry);
 
-               memset(u, 0, sizeof(*u));
-               u->entry.u64s   = DIV_ROUND_UP(sizeof(*u), sizeof(u64)) - 1;
+               entry_init_size(entry, sizeof(*u));
                u->entry.type   = BCH_JSET_ENTRY_usage;
                u->entry.btree_id = FS_USAGE_INODES;
                u->v            = cpu_to_le64(c->usage_base->nr_inodes);
@@ -1001,8 +1019,7 @@ bch2_journal_super_entries_add_common(struct bch_fs *c,
                struct jset_entry_usage *u =
                        container_of(entry, struct jset_entry_usage, entry);
 
-               memset(u, 0, sizeof(*u));
-               u->entry.u64s   = DIV_ROUND_UP(sizeof(*u), sizeof(u64)) - 1;
+               entry_init_size(entry, sizeof(*u));
                u->entry.type   = BCH_JSET_ENTRY_usage;
                u->entry.btree_id = FS_USAGE_KEY_VERSION;
                u->v            = cpu_to_le64(atomic64_read(&c->key_version));
@@ -1014,8 +1031,7 @@ bch2_journal_super_entries_add_common(struct bch_fs *c,
                struct jset_entry_usage *u =
                        container_of(entry, struct jset_entry_usage, entry);
 
-               memset(u, 0, sizeof(*u));
-               u->entry.u64s   = DIV_ROUND_UP(sizeof(*u), sizeof(u64)) - 1;
+               entry_init_size(entry, sizeof(*u));
                u->entry.type   = BCH_JSET_ENTRY_usage;
                u->entry.btree_id = FS_USAGE_RESERVED;
                u->entry.level  = i;
@@ -1030,10 +1046,7 @@ bch2_journal_super_entries_add_common(struct bch_fs *c,
                struct jset_entry_data_usage *u =
                        container_of(entry, struct jset_entry_data_usage, entry);
 
-               int u64s = DIV_ROUND_UP(sizeof(*u) + e->nr_devs,
-                                       sizeof(u64)) - 1;
-               memset(u, 0, u64s * sizeof(u64));
-               u->entry.u64s   = u64s;
+               entry_init_size(entry, sizeof(*u) + e->nr_devs);
                u->entry.type   = BCH_JSET_ENTRY_data_usage;
                u->v            = cpu_to_le64(c->usage_base->replicas[i]);
                memcpy(&u->r, e, replicas_entry_bytes(e));
index fa3a991453e91109a8a4865073b557a9a7bbee41..050277618a28b531ba7168444cf383b58e682ecc 100644 (file)
@@ -628,6 +628,14 @@ static inline void memmove_u64s(void *dst, const void *src,
                __memmove_u64s_up(dst, src, u64s);
 }
 
+/* Set the last few bytes up to a u64 boundary given an offset into a buffer. */
+static inline void memset_u64s_tail(void *s, int c, unsigned bytes)
+{
+       unsigned rem = round_up(bytes, sizeof(u64)) - bytes;
+
+       memset(s + bytes, c, rem);
+}
+
 void sort_cmp_size(void *base, size_t num, size_t size,
          int (*cmp_func)(const void *, const void *, size_t),
          void (*swap_func)(void *, void *, size_t));