Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752741AbbKKV3n (ORCPT ); Wed, 11 Nov 2015 16:29:43 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:47542 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751522AbbKKV3l (ORCPT ); Wed, 11 Nov 2015 16:29:41 -0500 Subject: Re: [PATCH] loop: properly observe rotational flag of underlying device To: =?UTF-8?Q?Holger_Hoffst=c3=a4tte?= , LKML References: <56435D0F.80006@googlemail.com> From: Jens Axboe Message-ID: <5643B341.9010600@fb.com> Date: Wed, 11 Nov 2015 14:29:37 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <56435D0F.80006@googlemail.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2015-11-11_16:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2195 Lines: 58 On 11/11/2015 08:21 AM, Holger Hoffstätte wrote: > > 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. > > Signed-off-by: Holger Hoffstätte > --- > drivers/block/loop.c | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > index 423f4ca..2984aca 100644 > --- a/drivers/block/loop.c > +++ b/drivers/block/loop.c > @@ -843,6 +843,24 @@ static void loop_config_discard(struct loop_device *lo) > queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q); > } > > +static void loop_update_rotational(struct loop_device *lo) > +{ > + struct file *file = lo->lo_backing_file; > + struct inode *file_inode = file->f_mapping->host; > + struct block_device *file_bdev = file_inode->i_sb->s_bdev; > + struct request_queue *q = lo->lo_queue; > + bool nonrot = true; > + > + /* not all filesystems (e.g. tmpfs) have a sb->s_bdev */ > + if (file_bdev) > + nonrot = blk_queue_nonrot(bdev_get_queue(file_bdev)); > + > + if (nonrot) > + queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q); > + else > + queue_flag_clear_unlocked(QUEUE_FLAG_NONROT, q); > +} Are we sure we want to change the default from rot to nonrot? Apart from that, looks good. -- Jens Axboe -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/