From patchwork Thu May 18 22:33:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Kukreti X-Patchwork-Id: 96080 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp842843vqo; Thu, 18 May 2023 15:39:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7R8MWeK9KG6M+YIaUFKu5ItABjZyPqYCYyVRcUD34KXG/nRsG1FYwkkcikqjcubyo2wZRP X-Received: by 2002:a05:6a21:30c1:b0:106:999f:64e5 with SMTP id yf1-20020a056a2130c100b00106999f64e5mr1219397pzb.60.1684449571249; Thu, 18 May 2023 15:39:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684449571; cv=none; d=google.com; s=arc-20160816; b=EkRqFsOZ/wLFvCYSBCS+DCkYdnVMjBdDifNzLQAyhNmuwC4MHTQpxebqklv+91EYTo bIXaWN8waVKcCOJFc9m9ScDp8lYCIsUHqAjTcAciNrb1sTmOMLJO00dmKIk+XwXDv1Pd aKCCXskzViJG19U6q1bPcDtv9L69mV7qgfqpAl6P/i6NpHl3g4aHaMTO7XY2GcIYBpkX 2WaNWPmfDo3ia9+N88M/tKUQvezVN+A9ziu8djrtN87wYezW9tJ5w6zY1Z0HsTuhby5B J5O75rgzk7MnMsYVOsrgGrjnA5HzkHOe2t3pIn1J976e2pFp1tQiw3hhUspGMkTlF+RU WHZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=D1nBFbl2kNhqRXHkgIUn6lQxv3BWL5XvL+95Aso43MI=; b=d7dQ+lm+ymtXrc2O2bD5LWbuV4H21WWcSSDjaQDMvuvE5nicTdiufT8B3Blba+6F+j lNTgbObeRzCjjVGTCA++zbUAghhrnarXNr+Ue+juiiem8gg/DXAIkPDMVo+tMth2EUxL cjm+jR0TmtA0kFqPOXrrG83evbte7MRmOkAyxaAoU7ZUiBXgn2wdpkSrzQi8RopXOI4H aUwzJ/xpDoUaiAJGW/EYOexrYGhpUIHj2LF4/2vovJOmkKChR2M5DshxrrVavPnbxWKA ZDWeHdn5x1UhRYjrwbhJwt/A6IprTLiovV7XoILqbg4NnjALnKlj7v9MPuIC41JzLvef NJLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JnT3Nm6b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020aa79509000000b0063d6708d1c9si2744156pfp.105.2023.05.18.15.39.16; Thu, 18 May 2023 15:39:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JnT3Nm6b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230002AbjERWed (ORCPT + 99 others); Thu, 18 May 2023 18:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbjERWeI (ORCPT ); Thu, 18 May 2023 18:34:08 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01EE710D0 for ; Thu, 18 May 2023 15:33:59 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1ae4c5e12edso20706365ad.3 for ; Thu, 18 May 2023 15:33:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1684449239; x=1687041239; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D1nBFbl2kNhqRXHkgIUn6lQxv3BWL5XvL+95Aso43MI=; b=JnT3Nm6byGtDawfZcACo1v8lokc0XTySqmTYShweWMVp8qL45gp07eq/6jgdwoVlR0 nZXUqAFvVJd7nS83y/ZXaFd7TsKRuQjPPI8JmvPWUHujsZkS7P4hHgSkTkmF2pkjGl9K DSB916FWMBFpvSJ5MLATv/gve4uyaJyVrwk+M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684449239; x=1687041239; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D1nBFbl2kNhqRXHkgIUn6lQxv3BWL5XvL+95Aso43MI=; b=E7upsUrw+HFGFB4xgjDpyZjlgZlbj2Qd5qsupy4Ar544iAaaJQ+9P/D+cpAPlSyc9W GIW8TB2agltnPrei6uEeArdl54EBRnKgT5NT6luKqawXwIOO3yofvfEOjgGD/NIoSKtx dttBMjPSDhht52UP6/Amlt54tw8Wzz9N9Z7Npx4qSYatU0QmAr50I1rnymSgADY9Frx4 TxK4gAJJvkDGG88mX0UuxwfiDjbwWue//HxD9TR7D6Pso9wLUDKxLiX8hR4kCKzhFeKl FDs6IWp6gsyMTTommjfzmGWT6NPrYYnkfZc228xFMYEFmCKssvtjFkoy1own8Yo15UyY nqvw== X-Gm-Message-State: AC+VfDwfijbpsAgwH3+smjqJYoubiWcsY54vFdFGDetyYnJK/YYzMr60 ++UZP9QCzrqrsTMt/bJpPi3u3Q== X-Received: by 2002:a17:903:2689:b0:1ac:8837:df8 with SMTP id jf9-20020a170903268900b001ac88370df8mr699263plb.6.1684449239382; Thu, 18 May 2023 15:33:59 -0700 (PDT) Received: from sarthakkukreti-glaptop.corp.google.com ([100.107.238.113]) by smtp.gmail.com with ESMTPSA id q4-20020a170902b10400b001aafb802efbsm1996502plr.12.2023.05.18.15.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 15:33:59 -0700 (PDT) From: Sarthak Kukreti To: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Jens Axboe , "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , "Darrick J. Wong" Subject: [PATCH v7 5/5] loop: Add support for provision requests Date: Thu, 18 May 2023 15:33:26 -0700 Message-ID: <20230518223326.18744-6-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog In-Reply-To: <20230518223326.18744-1-sarthakkukreti@chromium.org> References: <20230518223326.18744-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766273393238629493?= X-GMAIL-MSGID: =?utf-8?q?1766273393238629493?= Add support for provision requests to loopback devices. Loop devices will configure provision support based on whether the underlying block device/file can support the provision request and upon receiving a provision bio, will map it to the backing device/storage. For loop devices over files, a REQ_OP_PROVISION request will translate to an fallocate mode 0 call on the backing file. Signed-off-by: Sarthak Kukreti --- drivers/block/loop.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index bc31bb7072a2..7fe1a6629754 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -311,16 +311,20 @@ static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos, { /* * We use fallocate to manipulate the space mappings used by the image - * a.k.a. discard/zerorange. + * a.k.a. discard/provision/zerorange. */ struct file *file = lo->lo_backing_file; int ret; - mode |= FALLOC_FL_KEEP_SIZE; + if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE) && + !bdev_max_discard_sectors(lo->lo_device)) + return -EOPNOTSUPP; - if (!bdev_max_discard_sectors(lo->lo_device)) + if (mode == 0 && !bdev_max_provision_sectors(lo->lo_device)) return -EOPNOTSUPP; + mode |= FALLOC_FL_KEEP_SIZE; + ret = file->f_op->fallocate(file, mode, pos, blk_rq_bytes(rq)); if (unlikely(ret && ret != -EINVAL && ret != -EOPNOTSUPP)) return -EIO; @@ -488,6 +492,8 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq) FALLOC_FL_PUNCH_HOLE); case REQ_OP_DISCARD: return lo_fallocate(lo, rq, pos, FALLOC_FL_PUNCH_HOLE); + case REQ_OP_PROVISION: + return lo_fallocate(lo, rq, pos, 0); case REQ_OP_WRITE: if (cmd->use_aio) return lo_rw_aio(lo, cmd, pos, ITER_SOURCE); @@ -754,6 +760,25 @@ static void loop_sysfs_exit(struct loop_device *lo) &loop_attribute_group); } +static void loop_config_provision(struct loop_device *lo) +{ + struct file *file = lo->lo_backing_file; + struct inode *inode = file->f_mapping->host; + + /* + * If the backing device is a block device, mirror its provisioning + * capability. + */ + if (S_ISBLK(inode->i_mode)) { + blk_queue_max_provision_sectors(lo->lo_queue, + bdev_max_provision_sectors(I_BDEV(inode))); + } else if (file->f_op->fallocate) { + blk_queue_max_provision_sectors(lo->lo_queue, UINT_MAX >> 9); + } else { + blk_queue_max_provision_sectors(lo->lo_queue, 0); + } +} + static void loop_config_discard(struct loop_device *lo) { struct file *file = lo->lo_backing_file; @@ -1092,6 +1117,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, blk_queue_io_min(lo->lo_queue, bsize); loop_config_discard(lo); + loop_config_provision(lo); loop_update_rotational(lo); loop_update_dio(lo); loop_sysfs_init(lo); @@ -1304,6 +1330,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) } loop_config_discard(lo); + loop_config_provision(lo); /* update dio if lo_offset or transfer is changed */ __loop_update_dio(lo, lo->use_dio); @@ -1830,6 +1857,7 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx, case REQ_OP_FLUSH: case REQ_OP_DISCARD: case REQ_OP_WRITE_ZEROES: + case REQ_OP_PROVISION: cmd->use_aio = false; break; default: