From patchwork Fri Jun 18 11:51:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristian Klausen X-Patchwork-Id: 12331171 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=-23.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 81924C48BDF for ; Fri, 18 Jun 2021 11:52:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63B2B613E2 for ; Fri, 18 Jun 2021 11:52:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233378AbhFRLyf (ORCPT ); Fri, 18 Jun 2021 07:54:35 -0400 Received: from mail.klausen.dk ([157.90.24.29]:44588 "EHLO mail.klausen.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234342AbhFRLye (ORCPT ); Fri, 18 Jun 2021 07:54:34 -0400 From: Kristian Klausen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=klausen.dk; s=dkim; t=1624017142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=fNVRnRf8542INKe/gU6+30e9FBmzmdw4HOsCG1SESDg=; b=PylWqcdWYA5ulggA5WAFN4wVUb53dyb2SbV3C39KTPdkmlbic6heUukQs9O0fr/FqSJsBx SBoOBTrTcq1w1rUnUx9d75/rh8sRMLqLMLqzM/Uwd6L013Zs0QB39ECNGT6sdVarMuCFj/ EmaVwN2RufE2h+rDHJi8GF/Iuab2knk= To: linux-block@vger.kernel.org Cc: Kristian Klausen , stable@vger.kernel.org, Jens Axboe , Martijn Coenen , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] loop: Fix missing discard support when using LOOP_CONFIGURE Date: Fri, 18 Jun 2021 13:51:57 +0200 Message-Id: <20210618115157.31452-1-kristian@klausen.dk> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Without calling loop_config_discard() the discard flag and parameters aren't set/updated for the loop device and worst-case they could indicate discard support when it isn't the case (ex: if the LOOP_SET_STATUS ioctl was used with a different file prior to LOOP_CONFIGURE). Cc: # 5.8.x- Fixes: 3448914e8cc5 ("loop: Add LOOP_CONFIGURE ioctl") Signed-off-by: Kristian Klausen --- v1 of the patch was tested like so (without the patch): losetup 2.37<= uses LOOP_CONFIGURE instead of LOOP_SET_STATUS64[1] # fallocate -l100M disk.img # rmmod loop # losetup --version losetup from util-linux 2.36.2 # losetup --find --show disk.img /dev/loop0 # grep '' /sys/devices/virtual/block/loop0/queue/*discard* /sys/devices/virtual/block/loop0/queue/discard_granularity:4096 /sys/devices/virtual/block/loop0/queue/discard_max_bytes:4294966784 /sys/devices/virtual/block/loop0/queue/discard_max_hw_bytes:4294966784 /sys/devices/virtual/block/loop0/queue/discard_zeroes_data:0 /sys/devices/virtual/block/loop0/queue/max_discard_segments:1 # losetup -d /dev/loop0 # [update util-linux] # losetup --version losetup from util-linux 2.37 # rmmod loop # losetup --find --show disk.img /dev/loop0 # grep '' /sys/devices/virtual/block/loop0/queue/*discard* /sys/devices/virtual/block/loop0/queue/discard_granularity:0 /sys/devices/virtual/block/loop0/queue/discard_max_bytes:0 /sys/devices/virtual/block/loop0/queue/discard_max_hw_bytes:0 /sys/devices/virtual/block/loop0/queue/discard_zeroes_data:0 /sys/devices/virtual/block/loop0/queue/max_discard_segments:1 With the patch applied: # losetup --version losetup from util-linux 2.37 # rmmod loop # losetup --find --show disk.img /dev/loop0 # grep '' /sys/devices/virtual/block/loop0/queue/*discard* /sys/devices/virtual/block/loop0/queue/discard_granularity:4096 /sys/devices/virtual/block/loop0/queue/discard_max_bytes:4294966784 /sys/devices/virtual/block/loop0/queue/discard_max_hw_bytes:4294966784 /sys/devices/virtual/block/loop0/queue/discard_zeroes_data:0 /sys/devices/virtual/block/loop0/queue/max_discard_segments:1 [1] https://github.com/karelzak/util-linux/pull/1152 v2: Add commit message Move loop_config_discard() before loop_update_rotational() drivers/block/loop.c | 1 + 1 file changed, 1 insertion(+) base-commit: 70585216fe7730d9fb5453d3e2804e149d0fe201 diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 76e12f3482a9..8271df125153 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1154,6 +1154,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, blk_queue_physical_block_size(lo->lo_queue, bsize); blk_queue_io_min(lo->lo_queue, bsize); + loop_config_discard(lo); loop_update_rotational(lo); loop_update_dio(lo); loop_sysfs_init(lo);