Skip to contentSkip to conversation

btrfs-progs: receive: cannot find clone source subvol when receiving in reverse direction

PATCH Superseded Arsenii Skvortsov 2 participants 2 messages Aug 26, 2023 – Aug 28, 2023 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: receive: cannot find clone source subvol when receiving in reverse direction

process_clone, unlike process_snapshot, only searched a subvolume matching by received uuid. However, when earlier "receiver" side sends, it mentions received uuid, which is for earlier "send" side (now "receiver" side) is just uuid.

---
 cmds/receive.c                               | 28 +++--- tests/misc-tests/058-reverse-receive/test.sh | 98 ++++++++++++++++++++

 2 files changed, 115 insertions(+), 11 deletions(-)

 create mode 100755 tests/misc-tests/058-reverse-receive/test.sh

cmds/receive.c +0 -0
index d16dc0a..bdd4dee 100644
@@ -222,6 +222,19 @@ out:

        return ret;
 }

+static struct subvol_info *search_source_subvol(struct subvol_uuid_search *s,
+                                                                               const u8 *subvol_uuid, u64 transid) +{
+       struct subvol_info *found;
+       found = subvol_uuid_search(s, 0, subvol_uuid, transid, NULL,
+                                  subvol_search_by_received_uuid);
+       if (IS_ERR_OR_NULL(found)) {
+               found = subvol_uuid_search(s, 0, subvol_uuid, transid, NULL,
+                                          subvol_search_by_uuid);
+       }
+       return found;
+}
+
 static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
                            const u8 *parent_uuid, u64 parent_ctransid,
                            void *user)
@@ -284,14 +297,8 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid, memset(&args_v2, 0, sizeof(args_v2));
        strncpy_null(args_v2.name, path);

-       parent_subvol = subvol_uuid_search(rctx->mnt_fd, 0, parent_uuid,
-                                          parent_ctransid, NULL,
-                                          subvol_search_by_received_uuid);
-       if (IS_ERR_OR_NULL(parent_subvol)) {
-               parent_subvol = subvol_uuid_search(rctx->mnt_fd, 0, parent_uuid,
-                                                  parent_ctransid, NULL,
-                                                  subvol_search_by_uuid);
-       }
+       parent_subvol = search_source_subvol(rctx->mnt_fd, parent_uuid,
+                                            parent_ctransid);
        if (IS_ERR_OR_NULL(parent_subvol)) {
                if (!parent_subvol)
                        ret = -ENOENT;
@@ -746,9 +753,8 @@ static int process_clone(const char *path, u64 offset, u64 len, BTRFS_UUID_SIZE) == 0) {
                subvol_path = rctx->cur_subvol_path;
        } else {
-               si = subvol_uuid_search(rctx->mnt_fd, 0, clone_uuid, clone_ctransid,
-                                       NULL,
-                                       subvol_search_by_received_uuid);
+               si = search_source_subvol(rctx->mnt_fd, clone_uuid,
+                                         clone_ctransid);
                if (IS_ERR_OR_NULL(si)) {
                        char uuid_str[BTRFS_UUID_UNPARSED_SIZE];

tests/misc-tests/058-reverse-receive/test.sh new file +98 -0

98 lines not on this page · raw message

Signature · 1 line
2.41.0
#1 lore raw
Quoted 5 lines · Arsenii Skvortsov

process_clone, unlike process_snapshot, only searched a subvolume matching by received uuid. However, when earlier "receiver" side sends, it mentions received uuid, which is for earlier "send" side (now "receiver" side) is just uuid.

The changelog is too terse for what you're describing, it took me a while to figure out what exactly the problem was and what you were trying to accomplish.

Something more like

process_clone only searches the received_uuid, but could exist in an earlier uuid that isn't the received_uuid. Mirror what process_snapshot does and search both the received_uuid and if that fails look up by normal uuid.

Or something like that.

Quoted 16 lines

---
 cmds/receive.c                               | 28 +++--- tests/misc-tests/058-reverse-receive/test.sh | 98 ++++++++++++++++++++

 2 files changed, 115 insertions(+), 11 deletions(-)

 create mode 100755 tests/misc-tests/058-reverse-receive/test.sh

cmds/receive.c +0 -0
index d16dc0a..bdd4dee 100644
@@ -222,6 +222,19 @@ out:
         return ret;
  }
Quoted 3 lines


+static struct subvol_info *search_source_subvol(struct subvol_uuid_search *s,
+                                                                               const u8 *subvol_uuid, u64 transid)

The formatting is off right here, and in the whole patch, you need to use tabs not spaces for indention. The code and the test are great, just fixup your editor to use tabs. If you're using VIM let me know and I can give you a .vimrc that will do the right thing. Thanks,

Josef