From patchwork Tue Apr 20 04:58:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 12213333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79826C433B4 for ; Tue, 20 Apr 2021 04:58:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31C61613AE for ; Tue, 20 Apr 2021 04:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229553AbhDTE7L (ORCPT ); Tue, 20 Apr 2021 00:59:11 -0400 Received: from eu-shark2.inbox.eu ([195.216.236.82]:54276 "EHLO eu-shark2.inbox.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbhDTE7L (ORCPT ); Tue, 20 Apr 2021 00:59:11 -0400 Received: from eu-shark2.inbox.eu (localhost [127.0.0.1]) by eu-shark2-out.inbox.eu (Postfix) with ESMTP id AA5F8471D54; Tue, 20 Apr 2021 07:58:38 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=inbox.eu; s=20140211; t=1618894718; bh=Zztl01tReI0XCvZgAFF1lESc19Tfa0DkZfzxZ+KCRsk=; h=From:To:Cc:Subject:Date:Reply-To; b=BjPIm4F+JtgGABQRTwQrhh4UVCd6/x3qLLAdUXBgchLFsC5WpMqNwXhGtXP9MS2pZ lGTFF+sq/j0IpKG+EsAHA74z3ZNUKy8Nwh/HS3sT5yfgPmSuK53MaT086FLIcKjY7o qVbVsWsz4ghlxQUlZbeILFFbPVk4j1KhkoKTr6Vs= Received: from localhost (localhost [127.0.0.1]) by eu-shark2-in.inbox.eu (Postfix) with ESMTP id 99251471D52; Tue, 20 Apr 2021 07:58:38 +0300 (EEST) Received: from eu-shark2.inbox.eu ([127.0.0.1]) by localhost (eu-shark2.inbox.eu [127.0.0.1]) (spamfilter, port 35) with ESMTP id mKEWnUjhULD7; Tue, 20 Apr 2021 07:58:38 +0300 (EEST) Received: from mail.inbox.eu (eu-pop1 [127.0.0.1]) by eu-shark2-in.inbox.eu (Postfix) with ESMTP id 3CF7C471D57; Tue, 20 Apr 2021 07:58:38 +0300 (EEST) Received: from localhost.localdomain (unknown [45.87.95.33]) (Authenticated sender: l@damenly.su) by mail.inbox.eu (Postfix) with ESMTPA id D422B1BE00BD; Tue, 20 Apr 2021 07:58:35 +0300 (EEST) From: Su Yue To: linux-btrfs@vger.kernel.org Cc: l@damenly.su, boris@bur.io, Chris Murphy Subject: [PATCH v3] btrfs-progs: fi resize: fix false 0.00B sized output Date: Tue, 20 Apr 2021 12:58:27 +0800 Message-Id: <20210420045827.150881-1-l@damenly.su> X-Mailer: git-send-email 2.30.1 Reply-To: 20210419124541.148269-1-l@damenly.su MIME-Version: 1.0 X-Virus-Scanned: OK X-ESPOL: 6NpmlYxOGzysiV+lRWetdgtNzzYrL+Dh55TE3V0G3GeDUSOAe1YFVw6+mHJ1TmA= Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Resize to nums without sign prefix makes false output: btrfs fi resize 1:150g /srv/extra Resize device id 1 (/dev/sdb1) from 298.09GiB to 0.00B The resize operation would take effect though. check_resize_args() does not handle the mod 0 case and new_size is 0. Simply assigning @diff to @new_size to fix this. Issue: #307 Reported-by: Chris Murphy Signed-off-by: Su Yue Reviewed-by: Boris Burkov --- Changelog: v3: Just assign @diff to @new_size. (Boris Burkov) v2: Calculate u64 diff using max() and min(). Calculate mod by comparing new and old size. --- cmds/filesystem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmds/filesystem.c b/cmds/filesystem.c index 9e3cce687d6e..b4c09768235c 100644 --- a/cmds/filesystem.c +++ b/cmds/filesystem.c @@ -1158,7 +1158,10 @@ static int check_resize_args(const char *amount, const char *path) { } old_size = di_args[dev_idx].total_bytes; - if (mod < 0) { + /* For target sizes without '+'/'-' sign prefix(e.g. 1:150g) */ + if (mod == 0) { + new_size = diff; + } else if (mod < 0) { if (diff > old_size) { error("current size is %s which is smaller than %s", pretty_size_mode(old_size, UNITS_DEFAULT),