Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2242271ybc; Wed, 20 Nov 2019 11:01:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzhp7vKqWlYDkQjb8HToDsZ2Ka633UDgGxmj+H9EvS/6jK8drn4KenMxqoeZi4QK6jjPfGT X-Received: by 2002:a7b:c24b:: with SMTP id b11mr5339783wmj.125.1574276483262; Wed, 20 Nov 2019 11:01:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574276483; cv=none; d=google.com; s=arc-20160816; b=Zuh8JXVNwDuDWPLndq3ntHYmxd39AD0CPL2YFOqF7xYDQkCG3n1cjjuk7/+83Ac6Ax hsDyYnMP9zJPLH4SxP1vW+NqvHDXahHvVoZGsDgGJgwpUiCg/zSvx/7IPzGPCQ8Atj8k Yb2WhfAKklmOhqb00EEerW2w7m2UodCA/ekvhwRuaoGZpmLRZaR2rFx0LtVOWIX5FLK5 nrAfjtKQ/lKGsyg4Kt0hC4/ri8uTfViStJJ0W633+iXKExZ9dNmXWBjcXBx+Zkex9KeY RiL7BiTvsUGyd8DN14VNfFi6SUvDdUuBAHKDTWzErJIlR/XtaDeE3HjNGNYsJO65BwMA fTiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jOSs8GWh4nvdHvITwvOT+7DGX4JWzvhey5FOjHknUSw=; b=DdLqn2fjCknhrDAqHmWRIRO9gfVYRCSx0+BkrMTze33hmhjgMezGIoYoGIJ2D6SdMM rNfgrAG2tZYI9/CXtHnPt6mjcUJ3WQK252RruU+QIW2CIFs4+si+Y11NQrvoXPkZLjTh eFlPd4vNlPJ+m/iYIaS+9N3etrsFO0wnHICC9vqE1eECI/5XC8//bPU+hCpmJfs4d+OS AGKCH3Xh6DhspYrpEg4Z1jBmu7n3hccvWsCTxVDUG7dQ3XiVjgFTSRzv+u7CIo3rqqNW 1Ypr91RqpkpRT/XqZ+ogq2eIORVTOrR/ZGwqE/p89gaPeJyn0n1vy+6ikTLcc4rOvd+E DFzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cFv2Z33Q; 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 q44si209590eda.242.2019.11.20.11.00.58; Wed, 20 Nov 2019 11:01:23 -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=cFv2Z33Q; 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 S1727560AbfKTS5L (ORCPT + 99 others); Wed, 20 Nov 2019 13:57:11 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:40865 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727188AbfKTS5L (ORCPT ); Wed, 20 Nov 2019 13:57:11 -0500 Received: by mail-lj1-f196.google.com with SMTP id q2so312560ljg.7 for ; Wed, 20 Nov 2019 10:57:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jOSs8GWh4nvdHvITwvOT+7DGX4JWzvhey5FOjHknUSw=; b=cFv2Z33QNS8FpfuHutXCBQyQhPSIGwX+LfOwGlTR9vLXVSoIDDnfRthMyiahTGOfjw chxSXEuCrJqyhTSt7qt57KAxvGZjWprcx5G5hWWzVEXyEoSM3S7xUECA5GQrbjqImzbS 1z/i9s/QZ4KTGxDmOI5d8yt2FH4zlKyIs6KYs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jOSs8GWh4nvdHvITwvOT+7DGX4JWzvhey5FOjHknUSw=; b=cQleTkIpOSJYDHAlkR5T/MbF04PTw6DCMDJouc8VoVOYG/w/1ATR/2ewEzcVfyfJqH xKIGUdQ4ygNoG3a7lSaw99wk55ARmFsnIYQzQBPzQ+uxLqmNpubuQnHiT+jdN2eTfYV8 erYwUD4LN5VzouTisGWOloZ8cqA8hEYz8Q4LqlGjoRXkyU0n6oX25fZzz7c5i1ElhEYU +l52CxWMYAhxK6PiUpAavgYiZnrdkNYcLW6WxOP/NeDAdqur42S4Xn+irmoSG1rWHcZd 1gHbZyDyZ0X/H1+9/mbtTlbNs7+JoOAe2JeBmHixctY3JaXTklrZJZfhYyHwkCRvpdDT CRiQ== X-Gm-Message-State: APjAAAWkmOX8wPVhLjA8h5JgzhEHgEc4kmDoSf1lgn1n2KU4R1gg0UoZ d4U/Tv4DtNNlk3SL+fedh+/hhYcikNM= X-Received: by 2002:a2e:7607:: with SMTP id r7mr4229245ljc.37.1574276228108; Wed, 20 Nov 2019 10:57:08 -0800 (PST) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com. [209.85.167.48]) by smtp.gmail.com with ESMTPSA id 28sm13232182lfy.38.2019.11.20.10.57.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Nov 2019 10:57:07 -0800 (PST) Received: by mail-lf1-f48.google.com with SMTP id b20so421369lfp.4 for ; Wed, 20 Nov 2019 10:57:06 -0800 (PST) X-Received: by 2002:ac2:5597:: with SMTP id v23mr1072977lfg.79.1574276226377; Wed, 20 Nov 2019 10:57:06 -0800 (PST) MIME-Version: 1.0 References: <20191114235008.185111-1-evgreen@chromium.org> <20191114154903.v7.2.I4d476bddbf41a61422ad51502f4361e237d60ad4@changeid> <20191120022518.GU6235@magnolia> In-Reply-To: <20191120022518.GU6235@magnolia> From: Evan Green Date: Wed, 20 Nov 2019 10:56:30 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 2/2] loop: Better discard support for block devices To: "Darrick J. Wong" Cc: Jens Axboe , Martin K Petersen , Gwendal Grignou , Christoph Hellwig , Ming Lei , Alexis Savery , Douglas Anderson , Bart Van Assche , Chaitanya Kulkarni , linux-block , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 19, 2019 at 6:25 PM Darrick J. Wong wrote: > > On Thu, Nov 14, 2019 at 03:50:08PM -0800, Evan Green wrote: > > If the backing device for a loop device is itself a block device, > > then mirror the "write zeroes" capabilities of the underlying > > block device into the loop device. Copy this capability into both > > max_write_zeroes_sectors and max_discard_sectors of the loop device. > > > > The reason for this is that REQ_OP_DISCARD on a loop device translates > > into blkdev_issue_zeroout(), rather than blkdev_issue_discard(). This > > presents a consistent interface for loop devices (that discarded data > > is zeroed), regardless of the backing device type of the loop device. > > There should be no behavior change for loop devices backed by regular > > files. > > > > This change fixes blktest block/003, and removes an extraneous > > error print in block/013 when testing on a loop device backed > > by a block device that does not support discard. > > > > Signed-off-by: Evan Green > > Reviewed-by: Gwendal Grignou > > Reviewed-by: Chaitanya Kulkarni > > --- > > > > Changes in v7: > > - Rebase on top of Darrick's patch > > - Tweak opening line of commit description (Darrick) > > > > Changes in v6: None > > Changes in v5: > > - Don't mirror discard if lo_encrypt_key_size is non-zero (Gwendal) > > > > Changes in v4: > > - Mirror blkdev's write_zeroes into loopdev's discard_sectors. > > > > Changes in v3: > > - Updated commit description > > > > Changes in v2: None > > > > drivers/block/loop.c | 40 +++++++++++++++++++++++++++++----------- > > 1 file changed, 29 insertions(+), 11 deletions(-) > > > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > > index 6a9fe1f9fe84..e8f23e4b78f7 100644 > > --- a/drivers/block/loop.c > > +++ b/drivers/block/loop.c > > @@ -427,11 +427,12 @@ static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos, > > * information. > > */ > > struct file *file = lo->lo_backing_file; > > + struct request_queue *q = lo->lo_queue; > > int ret; > > > > mode |= FALLOC_FL_KEEP_SIZE; > > > > - if ((!file->f_op->fallocate) || lo->lo_encrypt_key_size) { > > + if (!blk_queue_discard(q)) { > > ret = -EOPNOTSUPP; > > goto out; > > } > > @@ -862,6 +863,21 @@ static void loop_config_discard(struct loop_device *lo) > > struct file *file = lo->lo_backing_file; > > struct inode *inode = file->f_mapping->host; > > struct request_queue *q = lo->lo_queue; > > + struct request_queue *backingq; > > + > > + /* > > + * If the backing device is a block device, mirror its zeroing > > + * capability. REQ_OP_DISCARD translates to a zero-out even when backed > > + * by block devices to keep consistent behavior with file-backed loop > > + * devices. > > + */ > > + if (S_ISBLK(inode->i_mode) && !lo->lo_encrypt_key_size) { > > + backingq = bdev_get_queue(inode->i_bdev); > > + blk_queue_max_discard_sectors(q, > > + backingq->limits.max_write_zeroes_sectors); > > max_discard_sectors? I didn't plumb max_discard_sectors because for my scenario it never ends up hitting the block device that way. The loop device either uses FL_ZERO_RANGE or FL_PUNCH_HOLE. When backed by a block device, that ends up in blkdev_fallocate(), which always translates both of those into blkdev_issue_zeroout(), not blkdev_issue_discard(). So it's really the zeroing capabilities of the block device that matters, even for loop discard operations. It seems weird, but I think this is the right thing because it presents a consistent interface to loop device users whether backed by a file system file, or directly by a block device. That is, a previously discarded range will read back as zeroes. -Evan