Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4511253imj; Tue, 12 Feb 2019 18:11:23 -0800 (PST) X-Google-Smtp-Source: AHgI3IblvMhe0Fq20hTLS3j/nuc1SN1gSwcXy/6SAp2EtGKXHcU5XRh6/M7roL0wqwi0FqmF0e0v X-Received: by 2002:a63:cd11:: with SMTP id i17mr6546130pgg.345.1550023882857; Tue, 12 Feb 2019 18:11:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550023882; cv=none; d=google.com; s=arc-20160816; b=lDJKgM3VtCX7/C0OZShEFvtprFdaVBQ7vGn4omPjOWYMournlpU/ozmV2JvGSvfpnw 1AG0q0owUkMNXfQSR+mBeUUZcretrOTTCu2oXOaeyxT5yt/Lh6FolNqEjHxMEZqfWgyc Q3C5JKCYsDL6gIKhlVf5DswrQupv65btZfsq6VUnhkkRWN1nRChr7ZS9MYyic//iwsyY 2D14I+bufZlsdQVW75cllkswIS9iSvN0i0xKecRp5cmn27n9jslkaySlLnpv85q8zD4/ yfhgcxE6XlcvPrnmfrtD3hamfe6IVh9MQyfr4lHmk1mByOCxxK57RftNv4DTkbhsztGt cHkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:from :subject:mime-version:message-id:date:dkim-signature; bh=KjNhG0POKcODcquT3yAek3QXMouSJzo7JdLuo1R8jCc=; b=CmtDRA1R8yaCZxkNe6WPccWcH6512eC601wxIZlzmhELrQuRvJqjZQDaaO923dobad SpSGEnXS6J+BHcn2X76Q1+qR0nLhz7KpSRIoc69MAQAYUfG1UVo2QTkNSh/Ds4NVJLXX lYkIUqV9PazCCCTMMi/6iJUDDKMH/4RJeSTd9PdkqAAi7LSh+1zOn6DIWh0TusMmXVZc M4YunWum2MKL5c3LuXvmkA9wwyqvVA0Cb+uLR9Z7u0Xkf3XFpf2oUOBEZidlZrsMA/t7 ucTzsELSYDVviLUPQYpun/36Xrogmgdv7zMVoFoDyWJeI4YRwmeSvGbay3oBk8rtkVMa 0Aiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=K3FBCroj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w18si632518plp.438.2019.02.12.18.11.06; Tue, 12 Feb 2019 18:11:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=K3FBCroj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730214AbfBLWzF (ORCPT + 99 others); Tue, 12 Feb 2019 17:55:05 -0500 Received: from mail-it1-f200.google.com ([209.85.166.200]:57936 "EHLO mail-it1-f200.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730128AbfBLWzF (ORCPT ); Tue, 12 Feb 2019 17:55:05 -0500 Received: by mail-it1-f200.google.com with SMTP id n124so668426itb.7 for ; Tue, 12 Feb 2019 14:55:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=KjNhG0POKcODcquT3yAek3QXMouSJzo7JdLuo1R8jCc=; b=K3FBCrojOBj+AULGeeagiyj2tWTLvWqC3Jw0oR6M26/d4060eYDWgzYRPOI4Frjpyo RPPJmzDMCXZwyN5K9Y6J1JcISAdd1vd0iKluguGMwkW6cvmpKzIH32CJbwMD1OK19Cp5 g+88UJyiX8qkXmztMCWT56GEfm+0CgsEkKWKQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=KjNhG0POKcODcquT3yAek3QXMouSJzo7JdLuo1R8jCc=; b=aLLg/cwJraXD8BfafFFEf3NeQ3BExnmWL5bMT6f4PY8RNDio9RLuHCCX474zphoY+P 6E4CxwBuyGFfjAgg27f2umLkyFzGdfEzjj+uG8w4Dv6azfZIsGhWSIiUXWGtQxl78lAS OFrGON0ornAMEE+a9TSayM9dOpP4MbWe/vRjgVwMiYD4s8STBvdED1FGlw1ApyBtoJ2o tRF7Q97UowsXVSdZ6T2frfjHb/HHHnZNEtOaFVnd23UDN7irJO7B3vk4xkAen0mKdkJC QfPrDpghXebceIn3n8mNki540QNEhtTAfmnSx+sn1nAqk1tj2fif5xUI7O1jB7eKyMod /32A== X-Gm-Message-State: AHQUAuaqF3A3lThHCo8rL2aRAQJRxNjZvy1cd0U8aB4zgL0hmrwXTxRK +ZKiUuscavz/UccDfsA87te+321nh/FgahCh X-Received: by 2002:a24:394f:: with SMTP id l76mr793867ita.23.1550012104207; Tue, 12 Feb 2019 14:55:04 -0800 (PST) Date: Tue, 12 Feb 2019 15:54:24 -0700 Message-Id: <20190212225424.139232-1-bmgordon@chromium.org> Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a-goog Subject: [PATCH] loop: properly observe rotational flag of underlying device From: Benjamin Gordon To: linux-kernel@vger.kernel.org Cc: "=?UTF-8?q?Holger=20Hoffst=C3=A4tte?=" , Jens Axboe , linux-block@vger.kernel.org, holger@applied-asynchrony.com, Gwendal Grignou , Benjamin Gordon , Guenter Roeck Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Holger Hoffst=C3=A4tte The loop driver always declares the rotational flag of its device as rotational, even when the device of the mapped file is nonrotational, as is the case with SSDs or on tmpfs. This can confuse filesystem tools which are SSD-aware; in my case I frequently forget to tell mkfs.btrfs that my loop device on tmpfs is nonrotational, and that I really don't need any automatic metadata redundancy. The attached patch fixes this by introspecting the rotational flag of the mapped file's underlying block device, if it exists. If the mapped file's filesystem has no associated block device - as is the case on e.g. tmpfs - we assume nonrotational storage. If there is a better way to identify such non-devices I'd love to hear them. Cc: Jens Axboe Cc: linux-block@vger.kernel.org Cc: holger@applied-asynchrony.com Signed-off-by: Holger Hoffst=C3=A4tte Signed-off-by: Gwendal Grignou Signed-off-by: Benjamin Gordon Reviewed-by: Guenter Roeck --- This is a resend of Holger's original patch from https://lkml.org/lkml/2015/11/11/288 with the _unlocked functions updated. We keep running into the same problem on Chrome OS that this originally solved; any chance it can go in? drivers/block/loop.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index cf5538942834..6c0fc0d49dc0 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -900,6 +900,24 @@ static int loop_prepare_queue(struct loop_device *lo) return 0; } =20 +static void loop_update_rotational(struct loop_device *lo) +{ + struct file *file =3D lo->lo_backing_file; + struct inode *file_inode =3D file->f_mapping->host; + struct block_device *file_bdev =3D file_inode->i_sb->s_bdev; + struct request_queue *q =3D lo->lo_queue; + bool nonrot =3D true; + + /* not all filesystems (e.g. tmpfs) have a sb->s_bdev */ + if (file_bdev) + nonrot =3D blk_queue_nonrot(bdev_get_queue(file_bdev)); + + if (nonrot) + blk_queue_flag_set(QUEUE_FLAG_NONROT, q); + else + blk_queue_flag_clear(QUEUE_FLAG_NONROT, q); +} + static int loop_set_fd(struct loop_device *lo, fmode_t mode, struct block_device *bdev, unsigned int arg) { @@ -963,6 +981,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t = mode, if (!(lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync) blk_queue_write_cache(lo->lo_queue, true, false); =20 + loop_update_rotational(lo); loop_update_dio(lo); set_capacity(lo->lo_disk, size); bd_set_size(bdev, size << 9); --=20 2.20.1.791.gb4d0f1c61a-goog