From patchwork Wed Sep 19 12:56:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Tulak X-Patchwork-Id: 10605833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 175435A4 for ; Wed, 19 Sep 2018 12:56:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 095742B29C for ; Wed, 19 Sep 2018 12:56:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1CAB2B2C1; Wed, 19 Sep 2018 12:56:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B3702B29C for ; Wed, 19 Sep 2018 12:56:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731591AbeISSeT (ORCPT ); Wed, 19 Sep 2018 14:34:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56332 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731419AbeISSeT (ORCPT ); Wed, 19 Sep 2018 14:34:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0D1486678; Wed, 19 Sep 2018 12:56:29 +0000 (UTC) Received: from honza-mbp.redhat.com (unknown [10.40.205.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD94A7B02C; Wed, 19 Sep 2018 12:56:28 +0000 (UTC) From: Jan Tulak To: linux-xfs@vger.kernel.org Cc: sandeen@sandeen.net, Jan Tulak Subject: [PATCH 2/2] mkfs: move 'mounted' check before 'existing fs' check Date: Wed, 19 Sep 2018 14:56:17 +0200 Message-Id: <20180919125617.28048-2-jtulak@redhat.com> In-Reply-To: <20180919125617.28048-1-jtulak@redhat.com> References: <20180919125617.28048-1-jtulak@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 19 Sep 2018 12:56:29 +0000 (UTC) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check if a device is mounted (and issue an error about that) before asking for -f flag. Example of the old behaviour I'm changing: $ mkfs.xfs /dev/sda1 mkfs.xfs: /dev/sda1 appears to contain an existing filesystem (xfs). mkfs.xfs: Use the -f option to force overwrite. $ mkfs.xfs -f /dev/sda1 mkfs.xfs: /dev/sda1 contains a mounted filesystem Signed-off-by: Jan Tulak Reviewed-by: Darrick J. Wong --- mkfs/xfs_mkfs.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) -- 2.18.0 diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 81d9859a..97e78647 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -1012,7 +1012,6 @@ check_device_type( bool no_size, bool no_name, int *create, - bool force_overwrite, const char *optname) { struct stat statbuf; @@ -1043,13 +1042,6 @@ check_device_type( return; } - if (!force_overwrite && check_overwrite(name)) { - fprintf(stderr, - _("%s: Use the -f option to force overwrite.\n"), - progname); - exit(1); - } - /* * We only want to completely truncate and recreate an existing file if * we were specifically told it was a file. Set the create flag only in @@ -1079,6 +1071,20 @@ check_device_type( usage(); } +static void +validate_overwrite( + const char *name, + bool force_overwrite) +{ + if (!force_overwrite && check_overwrite(name)) { + fprintf(stderr, + _("%s: Use the -f option to force overwrite.\n"), + progname); + exit(1); + } + +} + static void validate_ag_geometry( int blocklog, @@ -1731,18 +1737,15 @@ validate_sectorsize( * files or block devices and set the control parameters correctly. */ check_device_type(dfile, &cli->xi->disfile, !cli->dsize, !dfile, - dry_run ? NULL : &cli->xi->dcreat, - force_overwrite, "d"); + dry_run ? NULL : &cli->xi->dcreat, "d"); if (!cli->loginternal) check_device_type(cli->xi->logname, &cli->xi->lisfile, !cli->logsize, !cli->xi->logname, - dry_run ? NULL : &cli->xi->lcreat, - force_overwrite, "l"); + dry_run ? NULL : &cli->xi->lcreat, "l"); if (cli->xi->rtname) check_device_type(cli->xi->rtname, &cli->xi->risfile, !cli->rtsize, !cli->xi->rtname, - dry_run ? NULL : &cli->xi->rcreat, - force_overwrite, "r"); + dry_run ? NULL : &cli->xi->rcreat, "r"); /* * Explicitly disable direct IO for image files so we don't error out on @@ -3909,6 +3912,7 @@ main( * Open and validate the device configurations */ open_devices(&cfg, &xi); + validate_overwrite(dfile, force_overwrite); validate_datadev(&cfg, &cli); validate_logdev(&cfg, &cli, &logfile); validate_rtdev(&cfg, &cli, &rtfile);