From: Wang Shilong <wangshilong1991@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Subject: [PATCH v2] Btrfs-progs: avoid using btrfs internal subvolume path to send
Date: Sat, 30 Nov 2013 00:37:25 +0800 [thread overview]
Message-ID: <1385743045-2969-1-git-send-email-wangshilong1991@gmail.com> (raw)
From: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Steps to reproduce:
# mkfs.btrfs -f /dev/sda
# mount /dev/sda /mnt
# btrfs subvolume create /mnt/foo
# umount /mnt
# mount -o subvol=foo /dev/sda /mnt
# btrfs sub snapshot -r /mnt /mnt/snap
# btrfs send /mnt/snap > /dev/null
We will fail to send '/mnt/snap',this is because btrfs send try to
open '/mnt/snap' by btrfs internal subvolume path 'foo/snap' rather
than relative path based on mounted point, this will return us 'no
such file or directory',this is not right, fix it.
Reported-by: Thomas Scheiblauer <tom@sharkbay.at>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
v1->v2:
code cleanups(thanks to Stefan)
---
cmds-send.c | 34 ++++++----------------------------
1 file changed, 6 insertions(+), 28 deletions(-)
diff --git a/cmds-send.c b/cmds-send.c
index 53e9a53..6fdfd7f 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -282,31 +282,21 @@ out:
return ERR_PTR(ret);
}
-static int do_send(struct btrfs_send *send, u64 root_id, u64 parent_root_id,
- int is_first_subvol, int is_last_subvol)
+static int do_send(struct btrfs_send *send, u64 parent_root_id,
+ int is_first_subvol, int is_last_subvol, char *subvol)
{
int ret;
pthread_t t_read;
pthread_attr_t t_attr;
struct btrfs_ioctl_send_args io_send;
- struct subvol_info *si;
void *t_err = NULL;
int subvol_fd = -1;
int pipefd[2] = {-1, -1};
- si = subvol_uuid_search(&send->sus, root_id, NULL, 0, NULL,
- subvol_search_by_root_id);
- if (!si) {
- ret = -ENOENT;
- fprintf(stderr, "ERROR: could not find subvol info for %llu",
- root_id);
- goto out;
- }
-
- subvol_fd = openat(send->mnt_fd, si->path, O_RDONLY | O_NOATIME);
+ subvol_fd = openat(send->mnt_fd, subvol, O_RDONLY | O_NOATIME);
if (subvol_fd < 0) {
ret = -errno;
- fprintf(stderr, "ERROR: open %s failed. %s\n", si->path,
+ fprintf(stderr, "ERROR: open %s failed. %s\n", subvol,
strerror(-ret));
goto out;
}
@@ -385,10 +375,6 @@ out:
close(pipefd[0]);
if (pipefd[1] != -1)
close(pipefd[1]);
- if (si) {
- free(si->path);
- free(si);
- }
return ret;
}
@@ -664,14 +650,6 @@ int cmd_send(int argc, char **argv)
goto out;
}
- ret = get_root_id(&send, get_subvol_name(send.root_path, subvol),
- &root_id);
- if (ret < 0) {
- fprintf(stderr, "ERROR: could not resolve root_id "
- "for %s\n", subvol);
- goto out;
- }
-
if (!full_send && !parent_root_id) {
ret = find_good_parent(&send, root_id, &parent_root_id);
if (ret < 0) {
@@ -700,8 +678,8 @@ int cmd_send(int argc, char **argv)
is_first_subvol = 1;
is_last_subvol = 1;
}
- ret = do_send(&send, root_id, parent_root_id,
- is_first_subvol, is_last_subvol);
+ ret = do_send(&send, parent_root_id, is_first_subvol,
+ is_last_subvol, subvol);
if (ret < 0)
goto out;
--
1.8.4
next reply other threads:[~2013-11-29 16:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-29 16:37 Wang Shilong [this message]
2013-11-30 11:43 ` [PATCH v2] Btrfs-progs: avoid using btrfs internal subvolume path to send Miguel Negrão
[not found] ` <CAP9B-QksjFo_G70QjThw-LRt=J8PxeRe-UuMgrhtub_R+b_+BQ@mail.gmail.com>
2013-12-01 1:34 ` Fwd: " Shilong Wang
2014-01-11 22:35 ` Alex Lyakas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1385743045-2969-1-git-send-email-wangshilong1991@gmail.com \
--to=wangshilong1991@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wangsl.fnst@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).