From patchwork Thu Aug 20 05:24:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 7040751 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 EAEE79F373 for ; Thu, 20 Aug 2015 05:24:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1A84B2051C for ; Thu, 20 Aug 2015 05:24:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 234032051A for ; Thu, 20 Aug 2015 05:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751887AbbHTFY2 (ORCPT ); Thu, 20 Aug 2015 01:24:28 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:36455 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751286AbbHTFY1 (ORCPT ); Thu, 20 Aug 2015 01:24:27 -0400 Received: by wicja10 with SMTP id ja10so135571524wic.1 for ; Wed, 19 Aug 2015 22:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=tyDUO23MGYmO1L5vosOVMS+GFXYFg2x1/NmFNSbO4wA=; b=LeaAebYNcsWPau62bMOgdeeNEaKj7EiwCqrBUHbq7U6oAhNI6BRIoMFnDBcCaZ66Av lQYwf+7I6/Y8pMDw1EycaNMt5+MgyVX6BXNc+wS3jw1TAKnvWzCCRkSt7ztxbl/gMh15 m7aWCHD0h1xkPd6GxwdH6EG4PbwcEnqYkjvk8PjpZMiGlqoNXUiDoLrY9FLS8KD4WzOb Cg4NEZGV2ZITomFItZ7lxC4WfT8bIZHN1SrMuoUBCIBuFhgCjQGQOUhDs1ksPGtmSBjJ QricX/Zta7lalFokWdOAMZP4RkT1IIzrMi6qwXO+wZlliPIb+CUvMRRMAp8MP4SIbjEj m/DA== X-Received: by 10.194.190.79 with SMTP id go15mr2408680wjc.80.1440048265758; Wed, 19 Aug 2015 22:24:25 -0700 (PDT) Received: from venice.bhome (ppp-229-183.25-151.libero.it. [151.25.183.229]) by smtp.gmail.com with ESMTPSA id ho10sm3810984wjb.39.2015.08.19.22.24.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Aug 2015 22:24:25 -0700 (PDT) From: Goffredo Baroncelli X-Google-Original-From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Cc: Goffredo Baroncelli Subject: [PATCH] btrfs-progs: Add further checks to btrfs replace start command Date: Thu, 20 Aug 2015 07:24:23 +0200 Message-Id: <1440048263-6089-1-git-send-email-kreijack@inwind.it> X-Mailer: git-send-email 2.5.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=-7.3 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 Add further checks to btrfs replace start command. The following tests where added in user space before calling the ioctl(): 1) check if the new disk is greather or equal to the old one 2) check if the source device is or a block device or a numerical dev-id These checks are already performed in kernel space; however when "btrfs replace start" is ran in background is not possible to show any error returned by the ioctl(), so in case of fail the user had to check dmesg to understand the what happened. Signed-off-by: Goffredo Baroncelli --- cmds-replace.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmds-replace.c b/cmds-replace.c index 85365e3..45fe060 100644 --- a/cmds-replace.c +++ b/cmds-replace.c @@ -142,6 +142,8 @@ static int cmd_start_replace(int argc, char **argv) int do_not_background = 0; int mixed = 0; DIR *dirstream = NULL; + u64 srcdev_size; + u64 dstdev_size; while ((c = getopt(argc, argv, "Brf")) != -1) { switch (c) { @@ -249,16 +251,28 @@ static int cmd_start_replace(int argc, char **argv) srcdev, path); goto leave_with_error; } - } else if (is_block_device(srcdev)) { + srcdev_size = di_args[i].total_bytes; + } else if (is_block_device(srcdev) > 0) { strncpy((char *)start_args.start.srcdev_name, srcdev, BTRFS_DEVICE_PATH_NAME_MAX); start_args.start.srcdevid = 0; + srcdev_size = get_partition_size(srcdev); + } else { + fprintf(stderr, "ERROR: source device must be a block device or a devid\n"); + goto leave_with_error; } ret = test_dev_for_mkfs(dstdev, force_using_targetdev); if (ret) goto leave_with_error; + dstdev_size = get_partition_size(dstdev); + if (srcdev_size > dstdev_size) { + fprintf(stderr, "ERROR: target device smaller than source device (required %llu bytes)\n", + srcdev_size); + goto leave_with_error; + } + fddstdev = open(dstdev, O_RDWR); if (fddstdev < 0) { fprintf(stderr, "Unable to open %s\n", dstdev);