From patchwork Wed Sep 19 12:56:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Tulak X-Patchwork-Id: 10605831 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 75AE815E8 for ; Wed, 19 Sep 2018 12:56:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A6682B2AF for ; Wed, 19 Sep 2018 12:56:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B3012B29C; Wed, 19 Sep 2018 12:56:28 +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 ECFA82B29C for ; Wed, 19 Sep 2018 12:56:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731576AbeISSeQ (ORCPT ); Wed, 19 Sep 2018 14:34:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35724 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731419AbeISSeQ (ORCPT ); Wed, 19 Sep 2018 14:34:16 -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 229B33082261; Wed, 19 Sep 2018 12:56:27 +0000 (UTC) Received: from honza-mbp.redhat.com (unknown [10.40.205.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1D857B02A; Wed, 19 Sep 2018 12:56:25 +0000 (UTC) From: Jan Tulak To: linux-xfs@vger.kernel.org Cc: sandeen@sandeen.net, Jan Tulak Subject: [PATCH 1/2] mkfs: discard only after all validations Date: Wed, 19 Sep 2018 14:56:16 +0200 Message-Id: <20180919125617.28048-1-jtulak@redhat.com> MIME-Version: 1.0 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.45]); Wed, 19 Sep 2018 12:56:27 +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 Discard should happen only when everything has been validated, just before we start writing to the device. If it happens earlier, it is possible that mkfs will abort, but managed to already wipe data. This patch moves the discard to the latest possible moment. Signed-off-by: Jan Tulak --- mkfs/xfs_mkfs.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 2e53c1e8..81d9859a 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -2389,8 +2389,7 @@ _("log stripe unit (%d bytes) is too large (maximum is 256KiB)\n" static void open_devices( struct mkfs_params *cfg, - struct libxfs_xinit *xi, - bool discard) + struct libxfs_xinit *xi) { uint64_t sector_mask; @@ -2419,8 +2418,16 @@ open_devices( xi->dsize &= sector_mask; xi->rtsize &= sector_mask; xi->logBBsize &= (uint64_t)-1 << (max(cfg->lsectorlog, 10) - BBSHIFT); +} - +static void +discard_data( + struct libxfs_xinit *xi, + bool discard) +{ + /* + * This function has to be called after libxfs has been initialized. + */ if (!discard) return; @@ -3901,7 +3908,7 @@ main( /* * Open and validate the device configurations */ - open_devices(&cfg, &xi, (discard && !dry_run)); + open_devices(&cfg, &xi); validate_datadev(&cfg, &cli); validate_logdev(&cfg, &cli, &logfile); validate_rtdev(&cfg, &cli, &rtfile); @@ -3952,6 +3959,11 @@ main( exit(0); } + /* + * All values have been validated, discard the old device layout. + */ + discard_data(&xi, (discard && !dry_run)); + /* * we need the libxfs buffer cache from here on in. */