From patchwork Tue Dec 10 11:48:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pavel Reichl X-Patchwork-Id: 11282035 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7899714E3 for ; Tue, 10 Dec 2019 11:48:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 56CBF207FF for ; Tue, 10 Dec 2019 11:48:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Yb+nFItr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727426AbfLJLs0 (ORCPT ); Tue, 10 Dec 2019 06:48:26 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:22455 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727693AbfLJLs0 (ORCPT ); Tue, 10 Dec 2019 06:48:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575978505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RBaDerO5m1QBPWzoq0igJSlGppQzcNjGlqrOv8f6/iw=; b=Yb+nFItrOfWsiR1HPiTSPzlONwOwyvmAS+jd9pnrHyhtWFa3PcY2kQoV8Z3gIHkAESgyVm Ro5s5cJqjO76VqYxRHAoqNE4fs6Tpf9+1OGCpRKbo2+z7wkQk4kt4XweJgTKAZUDKm41Dx mmNE3UGXboUKMbWviffUhOLyPkD3ABo= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-298-2XlxopTOPdCy1sQQF6aqAA-1; Tue, 10 Dec 2019 06:48:19 -0500 Received: by mail-wm1-f72.google.com with SMTP id l13so899587wmj.8 for ; Tue, 10 Dec 2019 03:48:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BGf1nl8mK8BLFMrPnS/NtXMadtN9Ny4M+NfXyxu1AHA=; b=B9MCSoG/TlcaW3AkXH4L9S8QsiIGLxyvQzxdGNptKrQBBNsibX4GpX3GBIBnRTGTqf GBZAusDkgtkRqldphSTjMQEF+Qz9FTmXavZrbydt5eaMtPSH/Y6HUdwhKu2CI9T4oYNK i8RqBNNI2WgWU6RQyXYNVQg9zPQfGooaxSwYSroZgWuVHhjQa8270LNc9+h0pV5abcxG ahJzsarXVXuPfD6v3KILNpNxTvHZSC4dfHsy6ckKwZei3rVnInXte2e2F0RsJBK/az4T jKvp2gel7jAdqvsqK96L8gtbRKnYtdRV1FPUvSbGy+fZy2F2dYizTPnSUsgFLT9Pe9RH S61w== X-Gm-Message-State: APjAAAXVAhrDK6N+Kuid0Yh5L2G5FDKw/qD6xgqNTyAevdaVCPLO5bqi H4SndXclwtYbyaCYsTEeHFGj3T6nUIopfqCA2XjDvWV4LRdZtDCO5dCbk6kE+sJGfJrmCg5X8wA IVphSWAvbFZ8a9AcaXemw X-Received: by 2002:a5d:4a8c:: with SMTP id o12mr2777831wrq.43.1575978497954; Tue, 10 Dec 2019 03:48:17 -0800 (PST) X-Google-Smtp-Source: APXvYqwTKr7+fq2DhHzxKGQjb9hnay1Pkr58RNSv+F1GPFidwKvOxaISPugjFfqtrwAE8usjEAk0Kg== X-Received: by 2002:a5d:4a8c:: with SMTP id o12mr2777803wrq.43.1575978497630; Tue, 10 Dec 2019 03:48:17 -0800 (PST) Received: from preichl.redhat.com (243.206.broadband12.iol.cz. [90.179.206.243]) by smtp.gmail.com with ESMTPSA id b10sm3017434wrt.90.2019.12.10.03.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 03:48:17 -0800 (PST) From: Pavel Reichl To: linux-xfs@vger.kernel.org Cc: Pavel Reichl Subject: [PATCH v4] mkfs: Break block discard into chunks of 2 GB Date: Tue, 10 Dec 2019 12:48:07 +0100 Message-Id: <20191210114807.161927-1-preichl@redhat.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-MC-Unique: 2XlxopTOPdCy1sQQF6aqAA-1 X-Mimecast-Spam-Score: 0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Some users are not happy about the BLKDISCARD taking too long and at the same time not being informed about that - so they think that the command actually hung. This commit changes code so that progress reporting is possible and also typing the ^C will cancel the ongoing BLKDISCARD. Signed-off-by: Pavel Reichl Reviewed-by: Darrick J. Wong Reviewed-by: Dave Chinner --- Changelog: V4: Limit the reporting about discarding to a single line mkfs/xfs_mkfs.c | 50 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 18338a61..4bfdebf6 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -1240,17 +1240,40 @@ done: } static void -discard_blocks(dev_t dev, uint64_t nsectors) +discard_blocks(dev_t dev, uint64_t nsectors, int quiet) { - int fd; + int fd; + uint64_t offset = 0; + /* Discard the device 2G at a time */ + const uint64_t step = 2ULL << 30; + const uint64_t count = BBTOB(nsectors); - /* - * We intentionally ignore errors from the discard ioctl. It is - * not necessary for the mkfs functionality but just an optimization. - */ fd = libxfs_device_to_fd(dev); - if (fd > 0) - platform_discard_blocks(fd, 0, nsectors << 9); + if (fd <= 0) + return; + if (!quiet) { + printf("Discarding blocks..."); + fflush(stdout); + } + + /* The block discarding happens in smaller batches so it can be + * interrupted prematurely + */ + while (offset < count) { + uint64_t tmp_step = min(step, count - offset); + + /* + * We intentionally ignore errors from the discard ioctl. It is + * not necessary for the mkfs functionality but just an + * optimization. However we should stop on error. + */ + if (platform_discard_blocks(fd, offset, tmp_step)) + return; + + offset += tmp_step; + } + if (!quiet) + printf("Done.\n"); } static __attribute__((noreturn)) void @@ -2507,18 +2530,19 @@ open_devices( static void discard_devices( - struct libxfs_xinit *xi) + struct libxfs_xinit *xi, + int quiet) { /* * This function has to be called after libxfs has been initialized. */ if (!xi->disfile) - discard_blocks(xi->ddev, xi->dsize); + discard_blocks(xi->ddev, xi->dsize, quiet); if (xi->rtdev && !xi->risfile) - discard_blocks(xi->rtdev, xi->rtsize); + discard_blocks(xi->rtdev, xi->rtsize, quiet); if (xi->logdev && xi->logdev != xi->ddev && !xi->lisfile) - discard_blocks(xi->logdev, xi->logBBsize); + discard_blocks(xi->logdev, xi->logBBsize, quiet); } static void @@ -3749,7 +3773,7 @@ main( * All values have been validated, discard the old device layout. */ if (discard && !dry_run) - discard_devices(&xi); + discard_devices(&xi, quiet); /* * we need the libxfs buffer cache from here on in.