]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Update bcachefs sources to bba7493dda bcachefs: Fix error path in bch2_snapshot_set_e...
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 28 Mar 2022 20:32:53 +0000 (16:32 -0400)
committerKent Overstreet <kent.overstreet@gmail.com>
Mon, 28 Mar 2022 20:32:53 +0000 (16:32 -0400)
.bcachefs_revision
libbcachefs/btree_io.c
libbcachefs/darray.h [deleted file]
libbcachefs/io.c
libbcachefs/journal.c
libbcachefs/journal_reclaim.c
libbcachefs/journal_sb.c
libbcachefs/subvolume.c
libbcachefs/super-io.c
libbcachefs/util.h

index 9f55ecef644c900d15df1faea5ad6eaff87ecd01..901b02da77d69c5a21ac719582beec168953bdd4 100644 (file)
@@ -1 +1 @@
-367a8fad45924ce9fbe808964d1783c391a11bea
+bba7493dda9d1a0a9741fff88aff2228af3f4fc0
index a8014003c2b0b539a6bfe68d9ae0db94ef23f99e..4b880ea59cad8448e30f3e9fbf9a19b50eef74c7 100644 (file)
@@ -1074,7 +1074,7 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
 
                        bch2_bkey_val_to_text(&buf, c, u.s_c);
                        btree_err(BTREE_ERR_FIXABLE, c, NULL, b, i,
-                                 "invalid bkey %s: %s", buf, invalid);
+                                 "invalid bkey %s: %s", buf.buf, invalid);
                        printbuf_exit(&buf);
 
                        btree_keys_account_key_drop(&b->nr, 0, k);
diff --git a/libbcachefs/darray.h b/libbcachefs/darray.h
deleted file mode 100644 (file)
index daf872f..0000000
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Copyright (C) 2011 Joseph Adams <joeyadams3.14159@gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef CCAN_DARRAY_H
-#define CCAN_DARRAY_H
-
-#include <stdlib.h>
-#include <string.h>
-#include "config.h"
-
-/*
- * SYNOPSIS
- *
- * Life cycle of a darray (dynamically-allocated array):
- *
- *     darray(int) a = darray_new();
- *     darray_free(a);
- *
- *     struct {darray(int) a;} foo;
- *     darray_init(foo.a);
- *     darray_free(foo.a);
- *
- * Typedefs for darrays of common types:
- *
- *     darray_char, darray_schar, darray_uchar
- *     darray_short, darray_int, darray_long
- *     darray_ushort, darray_uint, darray_ulong
- *
- * Access:
- *
- *     T      darray_item(darray(T) arr, size_t index);
- *     size_t darray_size(darray(T) arr);
- *     size_t darray_alloc(darray(T) arr);
- *     bool   darray_empty(darray(T) arr);
- *
- * Insertion (single item):
- *
- *     void   darray_append(darray(T) arr, T item);
- *     void   darray_prepend(darray(T) arr, T item);
- *     void   darray_push(darray(T) arr, T item); // same as darray_append
- *
- * Insertion (multiple items):
- *
- *     void   darray_append_items(darray(T) arr, T *items, size_t count);
- *     void   darray_prepend_items(darray(T) arr, T *items, size_t count);
- *
- *     void   darray_appends(darray(T) arr, [T item, [...]]);
- *     void   darray_prepends(darray(T) arr, [T item, [...]]);
- *
- *     // Same functionality as above, but does not require typeof.
- *     void   darray_appends_t(darray(T) arr, #T, [T item, [...]]);
- *     void   darray_prepends_t(darray(T) arr, #T, [T item, [...]]);
- *
- * Removal:
- *
- *     T      darray_pop(darray(T) arr | darray_size(arr) != 0);
- *     T*     darray_pop_check(darray(T*) arr);
- *     void   darray_remove(darray(T) arr, size_t index);
- *
- * Replacement:
- *
- *     void   darray_from_items(darray(T) arr, T *items, size_t count);
- *     void   darray_from_c(darray(T) arr, T c_array[N]);
- *
- * String buffer:
- *
- *     void   darray_append_string(darray(char) arr, const char *str);
- *     void   darray_append_lit(darray(char) arr, char stringLiteral[N+1]);
- *
- *     void   darray_prepend_string(darray(char) arr, const char *str);
- *     void   darray_prepend_lit(darray(char) arr, char stringLiteral[N+1]);
- *
- *     void   darray_from_string(darray(T) arr, const char *str);
- *     void   darray_from_lit(darray(char) arr, char stringLiteral[N+1]);
- *
- * Size management:
- *
- *     void   darray_resize(darray(T) arr, size_t newSize);
- *     void   darray_resize0(darray(T) arr, size_t newSize);
- *
- *     void   darray_realloc(darray(T) arr, size_t newAlloc);
- *     void   darray_growalloc(darray(T) arr, size_t newAlloc);
- *
- *     void   darray_make_room(darray(T) arr, size_t room);
- *
- * Traversal:
- *
- *     darray_foreach(T *&i, darray(T) arr) {...}
- *     darray_foreach_reverse(T *&i, darray(T) arr) {...}
- *
- * Except for darray_foreach, darray_foreach_reverse, and darray_remove,
- * all macros evaluate their non-darray arguments only once.
- */
-
-/*** Life cycle ***/
-
-#define darray(type) struct {type *item; size_t size; size_t alloc;}
-
-#define darray_new() {0,0,0}
-#define darray_init(arr) do {(arr).item=0; (arr).size=0; (arr).alloc=0;} while(0)
-#define darray_free(arr) do {kfree((arr).item);} while(0)
-
-
-
-/*** Access ***/
-
-#define darray_item(arr, i) ((arr).item[i])
-#define darray_size(arr)    ((arr).size)
-#define darray_alloc(arr)   ((arr).alloc)
-#define darray_empty(arr)   ((arr).size == 0)
-
-
-/*** Insertion (single item) ***/
-
-#define darray_append(arr, ...) do { \
-               darray_resize(arr, (arr).size+1); \
-               (arr).item[(arr).size-1] = (__VA_ARGS__); \
-       } while(0)
-#define darray_prepend(arr, ...) do { \
-               darray_resize(arr, (arr).size+1); \
-               memmove((arr).item+1, (arr).item, ((arr).size-1)*sizeof(*(arr).item)); \
-               (arr).item[0] = (__VA_ARGS__); \
-       } while(0)
-#define darray_push(arr, ...) darray_append(arr, __VA_ARGS__)
-
-
-/*** Insertion (multiple items) ***/
-
-#define darray_append_items(arr, items, count) do { \
-               size_t __count = (count), __oldSize = (arr).size; \
-               darray_resize(arr, __oldSize + __count); \
-               memcpy((arr).item + __oldSize, items, __count * sizeof(*(arr).item)); \
-       } while(0)
-
-#define darray_prepend_items(arr, items, count) do { \
-               size_t __count = (count), __oldSize = (arr).size; \
-               darray_resize(arr, __count + __oldSize); \
-               memmove((arr).item + __count, (arr).item, __oldSize * sizeof(*(arr).item)); \
-               memcpy((arr).item, items, __count * sizeof(*(arr).item)); \
-       } while(0)
-
-#if HAVE_TYPEOF
-#define darray_appends(arr, ...) darray_appends_t(arr, typeof((*(arr).item)), __VA_ARGS__)
-#define darray_prepends(arr, ...) darray_prepends_t(arr, typeof((*(arr).item)), __VA_ARGS__)
-#endif
-
-#define darray_appends_t(arr, type, ...) do { \
-               type __src[] = {__VA_ARGS__}; \
-               darray_append_items(arr, __src, sizeof(__src)/sizeof(*__src)); \
-       } while(0)
-#define darray_prepends_t(arr, type, ...) do { \
-               type __src[] = {__VA_ARGS__}; \
-               darray_prepend_items(arr, __src, sizeof(__src)/sizeof(*__src)); \
-       } while(0)
-
-
-/*** Removal ***/
-
-/* Warning: Do not call darray_pop on an empty darray. */
-#define darray_pop(arr) ((arr).item[--(arr).size])
-#define darray_pop_check(arr) ((arr).size ? darray_pop(arr) : NULL)
-/* Warning, slow: Requires copying all elements after removed item. */
-#define darray_remove(arr, index) do { \
-       if (index < arr.size-1)    \
-               memmove(&(arr).item[index], &(arr).item[index+1], ((arr).size-1-i)*sizeof(*(arr).item)); \
-       (arr).size--;  \
-       } while(0)
-
-
-/*** Replacement ***/
-
-#define darray_from_items(arr, items, count) do {size_t __count = (count); darray_resize(arr, __count); memcpy((arr).item, items, __count*sizeof(*(arr).item));} while(0)
-#define darray_from_c(arr, c_array) darray_from_items(arr, c_array, sizeof(c_array)/sizeof(*(c_array)))
-
-
-/*** Size management ***/
-
-#define darray_resize(arr, newSize) darray_growalloc(arr, (arr).size = (newSize))
-#define darray_resize0(arr, newSize) do { \
-               size_t __oldSize = (arr).size, __newSize = (newSize); \
-               (arr).size = __newSize; \
-               if (__newSize > __oldSize) { \
-                       darray_growalloc(arr, __newSize); \
-                       memset(&(arr).item[__oldSize], 0, (__newSize - __oldSize) * sizeof(*(arr).item)); \
-               } \
-       } while(0)
-
-#define darray_realloc(arr, newAlloc) do { \
-               (arr).item = realloc((arr).item, ((arr).alloc = (newAlloc)) * sizeof(*(arr).item)); \
-       } while(0)
-#define darray_growalloc(arr, need) do { \
-               size_t __need = (need); \
-               if (__need > (arr).alloc) \
-                       darray_realloc(arr, darray_next_alloc((arr).alloc, __need)); \
-       } while(0)
-
-#if HAVE_STATEMENT_EXPR==1
-#define darray_make_room(arr, room) ({size_t newAlloc = (arr).size+(room); if ((arr).alloc<newAlloc) darray_realloc(arr, newAlloc); (arr).item+(arr).size; })
-#endif
-
-static inline size_t darray_next_alloc(size_t alloc, size_t need)
-{
-       return roundup_pow_of_two(alloc + need);
-}
-
-
-/*** Traversal ***/
-
-/*
- * darray_foreach(T *&i, darray(T) arr) {...}
- *
- * Traverse a darray.  `i` must be declared in advance as a pointer to an item.
- */
-#define darray_foreach(i, arr) \
-       for ((i) = &(arr).item[0]; (i) < &(arr).item[(arr).size]; (i)++)
-
-/*
- * darray_foreach_reverse(T *&i, darray(T) arr) {...}
- *
- * Like darray_foreach, but traverse in reverse order.
- */
-#define darray_foreach_reverse(i, arr) \
-       for ((i) = &(arr).item[(arr).size]; (i)-- > &(arr).item[0]; )
-
-
-#endif /* CCAN_DARRAY_H */
-
-/*
-
-darray_growalloc(arr, newAlloc) sees if the darray can currently hold newAlloc items;
-       if not, it increases the alloc to satisfy this requirement, allocating slack
-       space to avoid having to reallocate for every size increment.
-
-darray_from_string(arr, str) copies a string to an darray_char.
-
-darray_push(arr, item) pushes an item to the end of the darray.
-darray_pop(arr) pops it back out.  Be sure there is at least one item in the darray before calling.
-darray_pop_check(arr) does the same as darray_pop, but returns NULL if there are no more items left in the darray.
-
-darray_make_room(arr, room) ensures there's 'room' elements of space after the end of the darray, and it returns a pointer to this space.
-Currently requires HAVE_STATEMENT_EXPR, but I plan to remove this dependency by creating an inline function.
-
-The following require HAVE_TYPEOF==1 :
-
-darray_appends(arr, item0, item1...) appends a collection of comma-delimited items to the darray.
-darray_prepends(arr, item0, item1...) prepends a collection of comma-delimited items to the darray.\
-
-
-Examples:
-
-       darray(int)  arr;
-       int        *i;
-       
-       darray_appends(arr, 0,1,2,3,4);
-       darray_appends(arr, -5,-4,-3,-2,-1);
-       darray_foreach(i, arr)
-               printf("%d ", *i);
-       printf("\n");
-       
-       darray_free(arr);
-       
-
-       typedef struct {int n,d;} Fraction;
-       darray(Fraction) fractions;
-       Fraction        *i;
-       
-       darray_appends(fractions, {3,4}, {3,5}, {2,1});
-       darray_foreach(i, fractions)
-               printf("%d/%d\n", i->n, i->d);
-       
-       darray_free(fractions);
-*/
index cf97594b7c6fc1f7edc0bc5a662cab1a76503590..36929451af2ca30701291bd8914c4bd48e1cb714 100644 (file)
@@ -1059,7 +1059,7 @@ static void __bch2_write(struct closure *cl)
        struct bch_write_op *op = container_of(cl, struct bch_write_op, cl);
        struct bch_fs *c = op->c;
        struct write_point *wp;
-       struct bio *bio;
+       struct bio *bio = NULL;
        bool skip_put = true;
        unsigned nofs_flags;
        int ret;
index 6d91a2c8f6b5373dae2d80883ef068174193e31f..505e8367b5f2c867a7e2eb94ff74a39ca8457f4e 100644 (file)
@@ -1246,7 +1246,7 @@ void __bch2_journal_debug_to_text(struct printbuf *out, struct journal *j)
        pr_buf(out, "last_seq_ondisk:\t%llu\n",         j->last_seq_ondisk);
        pr_buf(out, "flushed_seq_ondisk:\t%llu\n",      j->flushed_seq_ondisk);
        pr_buf(out, "prereserved:\t\t%u/%u\n",          j->prereserved.reserved, j->prereserved.remaining);
-       pr_buf(out, "watermark:\t\t%u\n",               bch2_journal_watermarks[j->watermark]);
+       pr_buf(out, "watermark:\t\t%s\n",               bch2_journal_watermarks[j->watermark]);
        pr_buf(out, "each entry reserved:\t%u\n",       j->entry_u64s_reserved);
        pr_buf(out, "nr flush writes:\t%llu\n",         j->nr_flush_writes);
        pr_buf(out, "nr noflush writes:\t%llu\n",       j->nr_noflush_writes);
index 6f1bad522949dbb365ffb12bd80ca6c4493b9c9f..a9f7d5a7feb2a8811a406d42974c47305c479721 100644 (file)
@@ -216,7 +216,14 @@ void bch2_journal_space_available(struct journal *j)
                bch_err(c, "journal stuck\n%s", buf.buf);
                printbuf_exit(&buf);
 
+               /*
+                * Hack: bch2_fatal_error() calls bch2_journal_halt() which
+                * takes journal lock:
+                */
+               spin_unlock(&j->lock);
                bch2_fatal_error(c);
+               spin_lock(&j->lock);
+
                ret = JOURNAL_ERR_journal_stuck;
        } else if (!j->space[journal_space_discarded].next_entry)
                ret = JOURNAL_ERR_journal_full;
index 0a8a0077b6f1aaff4a65be13e454be7cfbc6c29a..8efe7b7e3dcbdb575dcbc91120318eedf5bb743a 100644 (file)
@@ -131,13 +131,13 @@ static int bch2_sb_journal_v2_validate(struct bch_sb *sb,
 
        if (b[0].start < le16_to_cpu(m->first_bucket)) {
                pr_buf(err, "journal bucket %llu before first bucket %u",
-                      b[0], le16_to_cpu(m->first_bucket));
+                      b[0].start, le16_to_cpu(m->first_bucket));
                goto err;
        }
 
        if (b[nr - 1].end > le64_to_cpu(m->nbuckets)) {
                pr_buf(err, "journal bucket %llu past end of device (nbuckets %llu)",
-                      b[nr - 1], le64_to_cpu(m->nbuckets));
+                      b[nr - 1].end - 1, le64_to_cpu(m->nbuckets));
                goto err;
        }
 
index 69603327d93df6587f4e8713d249c240c8bc1fde..666f1c88a3b618a1fa810f34c13f0dfa2356ed05 100644 (file)
@@ -139,7 +139,7 @@ static int bch2_snapshots_set_equiv(struct btree_trans *trans)
        for_each_btree_key(trans, iter, BTREE_ID_snapshots,
                           POS_MIN, 0, k, ret) {
                u32 id = k.k->p.offset, child[2];
-               unsigned nr_live = 0, live_idx;
+               unsigned nr_live = 0, live_idx = 0;
 
                if (k.k->type != KEY_TYPE_snapshot)
                        continue;
@@ -151,7 +151,7 @@ static int bch2_snapshots_set_equiv(struct btree_trans *trans)
                for (i = 0; i < 2; i++) {
                        ret = snapshot_live(trans, child[i]);
                        if (ret < 0)
-                               break;
+                               goto err;
 
                        if (ret)
                                live_idx = i;
@@ -162,6 +162,7 @@ static int bch2_snapshots_set_equiv(struct btree_trans *trans)
                        ? snapshot_t(c, child[live_idx])->equiv
                        : id;
        }
+err:
        bch2_trans_iter_exit(trans, &iter);
 
        if (ret)
index be61c20b06f350cc6aa7d76c6a2b362a1a08913b..71abf87114dfc41a20fb408a049ce27bd77fdfe4 100644 (file)
@@ -1510,7 +1510,7 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
 
        pr_buf(out, "Oldest version on disk:");
        pr_tab(out);
-       pr_buf(out, "%u", bch2_metadata_versions[le16_to_cpu(sb->version_min)]);
+       pr_buf(out, "%s", bch2_metadata_versions[le16_to_cpu(sb->version_min)]);
        pr_newline(out);
 
        pr_buf(out, "Created:");
index d6d7f1bc16b8a927c3e3e269f2ad792796589ad8..888693703c75b10ecc034713290f383a46859350 100644 (file)
@@ -210,9 +210,11 @@ do {                                                                       \
                                                                        \
        BUG_ON(_i >= (h)->used);                                        \
        (h)->used--;                                                    \
-       heap_swap(h, _i, (h)->used, set_backpointer);                   \
-       heap_sift_up(h, _i, cmp, set_backpointer);                      \
-       heap_sift_down(h, _i, cmp, set_backpointer);                    \
+       if ((_i) < (h)->used) {                                         \
+               heap_swap(h, _i, (h)->used, set_backpointer);           \
+               heap_sift_up(h, _i, cmp, set_backpointer);              \
+               heap_sift_down(h, _i, cmp, set_backpointer);            \
+       }                                                               \
 } while (0)
 
 #define heap_pop(h, d, cmp, set_backpointer)                           \
@@ -282,7 +284,8 @@ static inline size_t printbuf_linelen(struct printbuf *buf)
        return buf->pos - buf->last_newline;
 }
 
-void bch2_pr_buf(struct printbuf *out, const char *fmt, ...);
+void bch2_pr_buf(struct printbuf *out, const char *fmt, ...)
+       __attribute__ ((format (printf, 2, 3)));
 
 #define pr_buf(_out, ...) bch2_pr_buf(_out, __VA_ARGS__)