From patchwork Thu Sep 20 09:20:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Tulak X-Patchwork-Id: 10607217 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 8CB2114DA for ; Thu, 20 Sep 2018 09:20:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 724E82B9BA for ; Thu, 20 Sep 2018 09:20:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6465A2CB2E; Thu, 20 Sep 2018 09:20:37 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI 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 ED1452C9FB for ; Thu, 20 Sep 2018 09:20:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727986AbeITPCg (ORCPT ); Thu, 20 Sep 2018 11:02:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59836 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727633AbeITPCg (ORCPT ); Thu, 20 Sep 2018 11:02:36 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BAC566B for ; Thu, 20 Sep 2018 09:20:05 +0000 (UTC) Received: from honza-mbp.redhat.com (ovpn-204-142.brq.redhat.com [10.40.204.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED9B810694C9; Thu, 20 Sep 2018 09:20:04 +0000 (UTC) From: Jan Tulak To: linux-xfs@vger.kernel.org Cc: Jan Tulak Subject: [PATCH 1/2 v2] mkfs: discard only after all validations Date: Thu, 20 Sep 2018 11:20:06 +0200 Message-Id: <20180920092006.37596-1-jtulak@redhat.com> In-Reply-To: <20180919125617.28048-1-jtulak@redhat.com> References: <20180919125617.28048-1-jtulak@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 20 Sep 2018 09:20:05 +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 Reviewed-by: Darrick J. Wong --- CHANGES: v2 * discard_data -> discard_devices * move the discard condition outside of the function --- mkfs/xfs_mkfs.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 2e53c1e8..c97c69e8 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,10 +2418,15 @@ open_devices( xi->dsize &= sector_mask; xi->rtsize &= sector_mask; xi->logBBsize &= (uint64_t)-1 << (max(cfg->lsectorlog, 10) - BBSHIFT); +} - - if (!discard) - return; +static void +discard_devices( + struct libxfs_xinit *xi) +{ + /* + * This function has to be called after libxfs has been initialized. + */ if (!xi->disfile) discard_blocks(xi->ddev, xi->dsize); @@ -3901,7 +3905,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 +3956,12 @@ main( exit(0); } + /* + * All values have been validated, discard the old device layout. + */ + if (discard && !dry_run) + discard_devices(&xi); + /* * we need the libxfs buffer cache from here on in. */