From patchwork Wed May 27 17:51:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 6492041 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A88D49F1CC for ; Wed, 27 May 2015 17:51:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BED3820642 for ; Wed, 27 May 2015 17:51:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9279720640 for ; Wed, 27 May 2015 17:51:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751836AbbE0Rvn (ORCPT ); Wed, 27 May 2015 13:51:43 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:50125 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751488AbbE0Rvn (ORCPT ); Wed, 27 May 2015 13:51:43 -0400 Received: from pps.filterd (m0004077 [127.0.0.1]) by mx0b-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id t4RHm9R2026630 for ; Wed, 27 May 2015 10:51:32 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : subject : date : message-id : mime-version : content-type; s=facebook; bh=ODDNAVv2HxH0/Qosyom4mBZij+kCAQIrVgtfI+JE+s0=; b=kysUiU7gR1vZ8+HWoCJgRgSxpet1m9BPTVKzfukWqg5uI6DNzVUlBrlVOWYCLZOvBr9H tl7YYdVtwV9M1BTUTBSb9BXxWui8cM6PZq7zuhvMsO95RXwzLPSoMHu5mDQLS5B/ENjL D+0xJ+wHloUQi6Yh7U2/kYO+XUDaXfljp9w= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 1ungdj0h18-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT) for ; Wed, 27 May 2015 10:51:32 -0700 Received: from localhost (192.168.54.13) by mail.thefacebook.com (192.168.16.13) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 27 May 2015 10:51:30 -0700 From: Josef Bacik To: Subject: [PATCH] btrfs-progs: specify mountpoint for recieve Date: Wed, 27 May 2015 13:51:29 -0400 Message-ID: <1432749089-14663-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.14.151, 1.0.33, 0.0.0000 definitions=2015-05-27_07:2015-05-26, 2015-05-27, 1970-01-01 signatures=0 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_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,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 In a chroot environment we may not have /proc mounted, which makes btrfs receive freak out since it wants to know the base directory where are are mounted for things like clone and such. Give an option to specify where the mountpoint is in these cases so you can still do a btrfs receive in a chroot. Thanks, Signed-off-by: Josef Bacik --- cmds-receive.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/cmds-receive.c b/cmds-receive.c index b7cf3f9..28ae8e9 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -813,8 +813,8 @@ static struct btrfs_send_ops send_ops = { .utimes = process_utimes, }; -static int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd, - u64 max_errors) +static int do_receive(struct btrfs_receive *r, const char *tomnt, + char *realmnt, int r_fd, u64 max_errors) { int ret; char *dest_dir_full_path; @@ -836,20 +836,24 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd, goto out; } - ret = find_mount_root(dest_dir_full_path, &r->root_path); - if (ret < 0) { - fprintf(stderr, - "ERROR: failed to determine mount point for %s: %s\n", - dest_dir_full_path, strerror(-ret)); - ret = -EINVAL; - goto out; - } - if (ret > 0) { - fprintf(stderr, + if (realmnt) { + r->root_path = realmnt; + } else { + ret = find_mount_root(dest_dir_full_path, &r->root_path); + if (ret < 0) { + fprintf(stderr, + "ERROR: failed to determine mount point for %s: %s\n", + dest_dir_full_path, strerror(-ret)); + ret = -EINVAL; + goto out; + } + if (ret > 0) { + fprintf(stderr, "ERROR: %s doesn't belong to btrfs mount point\n", dest_dir_full_path); - ret = -EINVAL; - goto out; + ret = -EINVAL; + goto out; + } } r->mnt_fd = open(r->root_path, O_RDONLY | O_NOATIME); if (r->mnt_fd < 0) { @@ -943,6 +947,7 @@ int cmd_receive(int argc, char **argv) { char *tomnt = NULL; char *fromfile = NULL; + char *realmnt = NULL; struct btrfs_receive r; int receive_fd = fileno(stdin); u64 max_errors = 1; @@ -962,7 +967,7 @@ int cmd_receive(int argc, char **argv) { NULL, 0, NULL, 0 } }; - c = getopt_long(argc, argv, "Cevf:", long_opts, NULL); + c = getopt_long(argc, argv, "Cevf:m:", long_opts, NULL); if (c < 0) break; @@ -982,6 +987,13 @@ int cmd_receive(int argc, char **argv) case 'E': max_errors = arg_strtou64(optarg); break; + case 'm': + realmnt = strdup(optarg); + if (!realmnt) { + fprintf(stderr, "ERROR: couldn't allocate realmnt.\n"); + return 1; + } + break; case '?': default: fprintf(stderr, "ERROR: receive args invalid.\n"); @@ -1002,7 +1014,7 @@ int cmd_receive(int argc, char **argv) } } - ret = do_receive(&r, tomnt, receive_fd, max_errors); + ret = do_receive(&r, tomnt, realmnt, receive_fd, max_errors); return !!ret; } @@ -1032,5 +1044,8 @@ const char * const cmd_receive_usage[] = { "--max-errors Terminate as soon as N errors happened while", " processing commands from the send stream.", " Default value is 1. A value of 0 means no limit.", + "-m The root mount point of the destination fs.", + " If you do not have /proc use this to tell us where ", + " this file system is mounted.", NULL };