]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Update bcachefs sources to 61ebcb532a bcachefs: Fix for allocating before backpointer...
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 24 Oct 2022 15:34:07 +0000 (11:34 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 24 Oct 2022 15:34:07 +0000 (11:34 -0400)
.bcachefs_revision
libbcachefs/alloc_foreground.c
libbcachefs/btree_iter.c
libbcachefs/btree_iter.h
libbcachefs/fs-io.c
libbcachefs/io.c

index 206b9d4d94ab0203a763319ff6b2af4799ef51a6..3a147c61d07d322a44659e225edba0adf817a286 100644 (file)
@@ -1 +1 @@
-70fa0c1ff48feba041a8243b1a52ee57cffe1e0e
+61ebcb532a1266e5e36f354858b552e2a4fb9925
index a9e0c7397292fcab2e6dbcac08b7dd335c6c0147..186c2ed4c810d258ace640e655a5176fe211ae43 100644 (file)
@@ -14,6 +14,7 @@
 #include "bcachefs.h"
 #include "alloc_background.h"
 #include "alloc_foreground.h"
+#include "backpointers.h"
 #include "btree_iter.h"
 #include "btree_update.h"
 #include "btree_gc.h"
@@ -333,6 +334,28 @@ static struct open_bucket *try_alloc_bucket(struct btree_trans *trans, struct bc
                goto err;
        }
 
+       if (!test_bit(BCH_FS_CHECK_BACKPOINTERS_DONE, &c->flags)) {
+               struct bch_backpointer bp;
+               u64 bp_offset = 0;
+
+               ret = bch2_get_next_backpointer(trans, POS(ca->dev_idx, b), -1,
+                                               &bp_offset, &bp, 0);
+               if (ret) {
+                       ob = ERR_PTR(ret);
+                       goto err;
+               }
+
+               if (bp_offset != U64_MAX) {
+                       /*
+                        * Bucket may have data in it - we don't call
+                        * bc2h_trans_inconnsistent() because fsck hasn't
+                        * finished yet
+                        */
+                       ob = NULL;
+                       goto err;
+               }
+       }
+
        ob = __try_alloc_bucket(c, ca, b, reserve, &a,
                                skipped_open,
                                skipped_need_journal_commit,
index da116153aa47686aec3218316ece721194cc5c7f..99a92a897d721b77a131dcbe02dfcb74df9d721d 100644 (file)
@@ -1222,19 +1222,15 @@ struct btree_path *__bch2_btree_path_make_mut(struct btree_trans *trans,
 }
 
 struct btree_path * __must_check
-bch2_btree_path_set_pos(struct btree_trans *trans,
+__bch2_btree_path_set_pos(struct btree_trans *trans,
                   struct btree_path *path, struct bpos new_pos,
-                  bool intent, unsigned long ip)
+                  bool intent, unsigned long ip, int cmp)
 {
-       int cmp = bpos_cmp(new_pos, path->pos);
        unsigned l = path->level;
 
        EBUG_ON(trans->restarted);
        EBUG_ON(!path->ref);
 
-       if (!cmp)
-               return path;
-
        path = bch2_btree_path_make_mut(trans, path, intent, ip);
 
        path->pos = new_pos;
index 0775cfa2be9a37a0a042bd56f52217fc3e5d0ffc..8c35d7d45d8e93af0c8ffcf257663061f43e8b3f 100644 (file)
@@ -146,8 +146,21 @@ bch2_btree_path_make_mut(struct btree_trans *trans,
 }
 
 struct btree_path * __must_check
-bch2_btree_path_set_pos(struct btree_trans *, struct btree_path *,
-                       struct bpos, bool, unsigned long);
+__bch2_btree_path_set_pos(struct btree_trans *, struct btree_path *,
+                       struct bpos, bool, unsigned long, int);
+
+static inline struct btree_path * __must_check
+bch2_btree_path_set_pos(struct btree_trans *trans,
+                  struct btree_path *path, struct bpos new_pos,
+                  bool intent, unsigned long ip)
+{
+       int cmp = bpos_cmp(new_pos, path->pos);
+
+       return cmp
+               ? __bch2_btree_path_set_pos(trans, path, new_pos, intent, ip, cmp)
+               : path;
+}
+
 int __must_check bch2_btree_path_traverse(struct btree_trans *,
                                          struct btree_path *, unsigned);
 struct btree_path *bch2_path_get(struct btree_trans *, enum btree_id, struct bpos,
index 706180b97a7711138bfb9af59952c748fad6c7a3..3900995d2277c54bc56c2f3a3eaf9d43f8194820 100644 (file)
@@ -1666,10 +1666,21 @@ static int __bch2_buffered_write(struct bch_inode_info *inode,
                                goto out;
                }
 
+               /*
+                * XXX: per POSIX and fstests generic/275, on -ENOSPC we're
+                * supposed to write as much as we have disk space for.
+                *
+                * On failure here we should still write out a partial page if
+                * we aren't completely out of disk space - we don't do that
+                * yet:
+                */
                ret = bch2_page_reservation_get(c, inode, page, &res,
                                                pg_offset, pg_len);
-               if (ret)
-                       goto out;
+               if (unlikely(ret)) {
+                       if (!reserved)
+                               goto out;
+                       break;
+               }
 
                reserved += pg_len;
        }
@@ -1678,10 +1689,10 @@ static int __bch2_buffered_write(struct bch_inode_info *inode,
                for (i = 0; i < nr_pages; i++)
                        flush_dcache_page(pages[i]);
 
-       while (copied < len) {
+       while (copied < reserved) {
                struct page *page = pages[(offset + copied) >> PAGE_SHIFT];
                unsigned pg_offset = (offset + copied) & (PAGE_SIZE - 1);
-               unsigned pg_len = min_t(unsigned, len - copied,
+               unsigned pg_len = min_t(unsigned, reserved - copied,
                                        PAGE_SIZE - pg_offset);
                unsigned pg_copied = copy_page_from_iter_atomic(page,
                                                pg_offset, pg_len, iter);
index 5971569e31336043ce4bd69dda9b8028b703b6df..60a14fa1931d23053549608512266a9405bcc07c 100644 (file)
@@ -325,6 +325,9 @@ int bch2_extent_update(struct btree_trans *trans,
                        new_inode->v.bi_size = cpu_to_le64(new_i_size);
 
                le64_add_cpu(&new_inode->v.bi_sectors, i_sectors_delta);
+
+               new_inode->k.p.snapshot = iter->snapshot;
+
                ret = bch2_trans_update(trans, &inode_iter, &new_inode->k_i, 0);
                if (unlikely(ret))
                        goto err;