From patchwork Fri Nov 29 16:37:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 3258971 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 41AF5BEEAD for ; Fri, 29 Nov 2013 16:37:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3F1F920685 for ; Fri, 29 Nov 2013 16:37:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 469C8205F2 for ; Fri, 29 Nov 2013 16:37:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755352Ab3K2Qhg (ORCPT ); Fri, 29 Nov 2013 11:37:36 -0500 Received: from mail-pb0-f54.google.com ([209.85.160.54]:32880 "EHLO mail-pb0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752749Ab3K2Qhg (ORCPT ); Fri, 29 Nov 2013 11:37:36 -0500 Received: by mail-pb0-f54.google.com with SMTP id un15so14783772pbc.13 for ; Fri, 29 Nov 2013 08:37:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=LW6dibptFputgVlZIEsorYd1Mn6wlwFTSYDopKitDbo=; b=Iph47+ufGfheTHi6Dmr0tLGoeq2ralFRzWz81o2mz5G6A2Hhxr8gne+CXL5Gx+Cq6v 0aCqMgeAJQFGwIE72euhOuzUQi0aFef7ObuWD4ir1nYGG+gMOtsxzgqAGaaTzT9wk5ui hiqenGOg1N6dRdDXiVk4S/5lZY/k6nnFh50YXbwnQBE7VE75Ui5ImWp0vk1eJ7uDQ0Rn rfTisedG95q5094P2+P4LXoCYoc+oYzH+09XsEELLWIatv/UQAUx7taTOk8CHqv1QV7/ H6WlVN7re9KbkHpwH3rju4iVGEjr78ZeqEEd24Wmy/5sdes570QiWTc7YVMCuEpwTILx FuAA== X-Received: by 10.68.106.69 with SMTP id gs5mr6583585pbb.87.1385743055433; Fri, 29 Nov 2013 08:37:35 -0800 (PST) Received: from linux-b0ol.localdomain ([223.65.140.195]) by mx.google.com with ESMTPSA id gf5sm103197390pbc.22.2013.11.29.08.37.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Nov 2013 08:37:34 -0800 (PST) From: Wang Shilong To: linux-btrfs@vger.kernel.org Cc: Wang Shilong Subject: [PATCH v2] Btrfs-progs: avoid using btrfs internal subvolume path to send Date: Sat, 30 Nov 2013 00:37:25 +0800 Message-Id: <1385743045-2969-1-git-send-email-wangshilong1991@gmail.com> X-Mailer: git-send-email 1.8.4 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wang Shilong 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 Signed-off-by: Wang Shilong --- 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;