Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1307085ybc; Tue, 19 Nov 2019 18:27:07 -0800 (PST) X-Google-Smtp-Source: APXvYqywhZWjVtfHBfcxb09ztjsK6XmvoeJsVNr/MR1mjkPwJtHF0lrE18kT4AqD7giWStQRLVTn X-Received: by 2002:a17:906:1c07:: with SMTP id k7mr1502230ejg.229.1574216827349; Tue, 19 Nov 2019 18:27:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574216827; cv=none; d=google.com; s=arc-20160816; b=Gikaai9Lfv44yj7rz+hNK4JB8Ngd0NbiCBuyyhkp/2flaMc6l0vNVDnB9Fy/ZAZ23m In6+FHbc6IX6joo+X247s7yLhUvLBmT8oHV3E5tEoxyQ0qRAPkqT9HwN+OVfAwK5E2l2 qOzypppwRtYkW5HM16YUtnUIW/2hge0+yo3mlwpXUSTDxvQlmAjK0+XuyjiQJShk5kvM xLbxJakwxuXE1sEPIYZ/tN8Kog93nmN2soSZhlNIim3ORalDcWjSTPXHay0kNoqaPEsW pqEpbV5syyyItIhK1SDKIGkiNMaEw/CwbQeLrZoBbhrTA/G9GUfLUfgCUdGcHg2L3WjX ik7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=G6s/zscyWj8h/m2pMQYpt10yiZ1ZtNfx047wBMtS7fs=; b=pFKOQLwPl6WMvpjNAtHbwp/IiRxoJkqxRaKy474nLyRuID04PIUhjLbz0NMmp1wRyN +RXKsFSIumSDlfKR6Nejz0UpaAaqQJmQDuJ03mRF3daSmwo/mnvRachr4xwGkCOPjZ7q X5NWe+F9XxD+xTyYk+jBd/XCiQEsphLI0u+jIhS7VVuBqtB8zMhPF1NGipJVH/JFo3pP rDPAq29cSGLufDxeA2Ac3ci5xc02WTS54zUthHT6oWfSBv5cZST2RTHIEUr8/lpC848W 3wF6jKPOrNXTEEquMQBuLlB8+RzgDKO6yh21HFntZaVsJjGwg3EkEqnr8tR0PEHm7cRg px3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=J8CX4S19; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5si13143254edq.27.2019.11.19.18.26.42; Tue, 19 Nov 2019 18:27:07 -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=@oracle.com header.s=corp-2019-08-05 header.b=J8CX4S19; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727343AbfKTCZr (ORCPT + 99 others); Tue, 19 Nov 2019 21:25:47 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:53660 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727082AbfKTCZr (ORCPT ); Tue, 19 Nov 2019 21:25:47 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xAK2OiYm169531; Wed, 20 Nov 2019 02:25:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2019-08-05; bh=G6s/zscyWj8h/m2pMQYpt10yiZ1ZtNfx047wBMtS7fs=; b=J8CX4S19nk9vTn8+LEmWm1JRy9LGGdQM/fSTysl6K+AMKx06sLE2Z0zFN9bm0UcU+qUq DFkfACwfLGqqY/MeQJYzhrK51p3U9JjqyJcvnyf1F0d4v4lwmUGkeh1tlemVg3VRB6wh JjkxmRyOQHBxRaAArlaTdcmXqH7KWI05A7CpmdEvWPp/VZdjdDDML/Nifyfus/jSUOGm mIVcbc5ZGO1/cWQiOKnDPEfdyDZGvKZV57odChCB4PQXT/TpuDs3CrwjW9TwPTKX1tvF IW7P0zpFCmauZVtCHzC86JIVOLky0tziyFgxrrR5lqw4rY8VU0oiPuc3XvgdduCKRFLq NA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2wa9rqjmty-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Nov 2019 02:25:27 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xAK2NxY0087921; Wed, 20 Nov 2019 02:25:27 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2wc0ahe56c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Nov 2019 02:25:26 +0000 Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id xAK2PIh5013857; Wed, 20 Nov 2019 02:25:19 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 19 Nov 2019 18:25:18 -0800 Date: Tue, 19 Nov 2019 18:25:18 -0800 From: "Darrick J. Wong" To: Evan Green Cc: Jens Axboe , Martin K Petersen , Gwendal Grignou , Christoph Hellwig , Ming Lei , Alexis Savery , Douglas Anderson , Bart Van Assche , Chaitanya Kulkarni , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 2/2] loop: Better discard support for block devices Message-ID: <20191120022518.GU6235@magnolia> References: <20191114235008.185111-1-evgreen@chromium.org> <20191114154903.v7.2.I4d476bddbf41a61422ad51502f4361e237d60ad4@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191114154903.v7.2.I4d476bddbf41a61422ad51502f4361e237d60ad4@changeid> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9446 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1911200020 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9446 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1911200020 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? --D > + > + blk_queue_max_write_zeroes_sectors(q, > + backingq->limits.max_write_zeroes_sectors); > > /* > * We use punch hole to reclaim the free space used by the > @@ -869,22 +885,24 @@ static void loop_config_discard(struct loop_device *lo) > * encryption is enabled, because it may give an attacker > * useful information. > */ > - if ((!file->f_op->fallocate) || > - lo->lo_encrypt_key_size) { > + } else if ((!file->f_op->fallocate) || lo->lo_encrypt_key_size) { > q->limits.discard_granularity = 0; > q->limits.discard_alignment = 0; > blk_queue_max_discard_sectors(q, 0); > blk_queue_max_write_zeroes_sectors(q, 0); > - blk_queue_flag_clear(QUEUE_FLAG_DISCARD, q); > - return; > - } > > - q->limits.discard_granularity = inode->i_sb->s_blocksize; > - q->limits.discard_alignment = 0; > + } else { > + q->limits.discard_granularity = inode->i_sb->s_blocksize; > + q->limits.discard_alignment = 0; > > - blk_queue_max_discard_sectors(q, UINT_MAX >> 9); > - blk_queue_max_write_zeroes_sectors(q, UINT_MAX >> 9); > - blk_queue_flag_set(QUEUE_FLAG_DISCARD, q); > + blk_queue_max_discard_sectors(q, UINT_MAX >> 9); > + blk_queue_max_write_zeroes_sectors(q, UINT_MAX >> 9); > + } > + > + if (q->limits.max_write_zeroes_sectors) > + blk_queue_flag_set(QUEUE_FLAG_DISCARD, q); > + else > + blk_queue_flag_clear(QUEUE_FLAG_DISCARD, q); > } > > static void loop_unprepare_queue(struct loop_device *lo) > -- > 2.21.0 >