Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1060686rwn; Thu, 15 Sep 2022 09:51:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4NQdBARQpX5vIfANE3jAceUc5gJHdvW0mpzDuzCPEm+725Xor9Mj3C94h3FjIFiPayanKc X-Received: by 2002:a17:906:6086:b0:731:3970:48d0 with SMTP id t6-20020a170906608600b00731397048d0mr613533ejj.16.1663260697291; Thu, 15 Sep 2022 09:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663260697; cv=none; d=google.com; s=arc-20160816; b=QNWojSUtz9dN7Jdfe2XFLl5A8ZIy+zdaDnwSZGhAPD7brOOeVA8S6SpfzowyA3SNoZ 9eXSCSEevzMcdaIVagunfvprK4BioiuiSCF3gPd7Hf9rD7NzgroKhF8Su+gw4VUJrmi4 MmAbsRh7aM6fjRyx4J0mHnpRxNewRtTf5Y0gYcpPeXzPvODV63qXhU4Q7GWHYePw8rAN DJp+ZShobdwe5WgJmb+QdgYP4qC3kaA7NhjdiJvzoDUbkLZ1yOqDbkiTCymPILPnPXOP gQLCb/jrLDIhKMMmOtlN6o0upKAL1PxJHs6Btm0SZ5w6gSuONo9Zd/RDe/5G0+4unNwY W7gA== 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=Ez356cXmd+P7nHsJjjr+e0UneH5b2Is7vVwjmIs0dPs=; b=XulkEfJXV5wsiA0dNHQ2ccc+ykZsNiASGHlPPCdnZtQcg/Is8NUWmpm64HnupQiT+3 eDaFB7GPdnOVISbKEXd7W3+TW5TqeZ4NskqPjx4xGeBLF0O0McJjzIm6DgIed7S+LuwU VCKXTrNltSqwTTJRyZDf8bcZCYWdQJkuK6NxCRlvDcvb+mqrE+B19onGSYiZ75jqR0ZA VhJqE3V/6lcNPnao7MxhfKd/5v2HbIWVjK3Ypp5N+YML5L8MoLf0+UMYF0CqUba+oduV KsVSW/BVxPNEtV2aAS3BuY84mr//UEPG+bkh7MdsbcyFby2ntinMx5QPc+UQkA1sVHdj a7tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hf5bm+zk; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s25-20020aa7d799000000b0044f0a023da0si12816938edq.118.2022.09.15.09.51.12; Thu, 15 Sep 2022 09:51:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=hf5bm+zk; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 S229715AbiIOQt0 (ORCPT + 99 others); Thu, 15 Sep 2022 12:49:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbiIOQs7 (ORCPT ); Thu, 15 Sep 2022 12:48:59 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D4CC72FD7 for ; Thu, 15 Sep 2022 09:48:51 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id d64-20020a17090a6f4600b00202ce056566so13512529pjk.4 for ; Thu, 15 Sep 2022 09:48:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Ez356cXmd+P7nHsJjjr+e0UneH5b2Is7vVwjmIs0dPs=; b=hf5bm+zkYxj81k0yr271q/Vk7dx9PD258+F9SK/a1tGt7tNa+NuehKD3IiLyt97euU FtXSg24Apya78hp1GXFu5BbK+vkKNo1ymR0Rwg7K+y3rnIb3ONI2XzkuntNb07Nm+r9L GJij3Ake6waJf54qKgjqFZkAvVur99qaXQO6Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=Ez356cXmd+P7nHsJjjr+e0UneH5b2Is7vVwjmIs0dPs=; b=16R1Y/Nk0LscDFXo1XpzsBjTSRodxqRrEv8clyl8kt5b05Z4/ILkIBNpaeKhD90DIn dRRY34X9Tf9tjCe3X9oBnh/gYfvAs4DnN3NYa9fDp2v7uyrhPIY+crm9Ugl65Xs1gPo5 JJMfAIprayPvjnvjCIGrbFkASFiUqL7l1sf9e7fUpWrJgwl5JNOd1beCMb79UHA5Pyoq 8QnrrAeM30LiJOvEHutJ5xnHcljNZ4eZT3YMFJtG4ubwbUgogSoWaZHDqvBIQng159NX mLZh6ObFRmB5vte14xNv03hG92kHHs57u7jmLQW3DgfnY7ux1knBIIW3hO7llvL+P8Ur dyUw== X-Gm-Message-State: ACrzQf0y5l6q8Fh3pU6vN8lnglH5WckwKpu04k1WQgiANg9NS30zN30d iK6MtDXl90JRNN+KqILVgeNwKw== X-Received: by 2002:a17:902:c106:b0:178:8cb:2762 with SMTP id 6-20020a170902c10600b0017808cb2762mr482863pli.58.1663260530537; Thu, 15 Sep 2022 09:48:50 -0700 (PDT) Received: from sarthakkukreti-glaptop.hsd1.ca.comcast.net ([2601:647:4200:b5b0:3af2:34b2:a98a:a652]) by smtp.gmail.com with ESMTPSA id o4-20020a170902bcc400b00177ee563b6dsm13174970pls.33.2022.09.15.09.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 09:48:49 -0700 (PDT) From: Sarthak Kukreti X-Google-Original-From: Sarthak Kukreti To: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: Jens Axboe , "Michael S . Tsirkin" , Jason Wang , Paolo Bonzini , Stefan Hajnoczi , Alasdair Kergon , Mike Snitzer , Theodore Ts'o , Andreas Dilger , Bart Van Assche , Daniil Lunev , Evan Green , Gwendal Grignou , Sarthak Kukreti Subject: [PATCH RFC 5/8] loop: Add support for provision requests Date: Thu, 15 Sep 2022 09:48:23 -0700 Message-Id: <20220915164826.1396245-6-sarthakkukreti@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220915164826.1396245-1-sarthakkukreti@google.com> References: <20220915164826.1396245-1-sarthakkukreti@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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-ext4@vger.kernel.org From: Sarthak Kukreti 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. Signed-off-by: Sarthak Kukreti --- drivers/block/loop.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index ad92192c7d61..83f486b9bceb 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -327,6 +327,24 @@ static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos, return ret; } +static int lo_req_provision(struct loop_device *lo, struct request *rq, loff_t pos) +{ + struct file *file = lo->lo_backing_file; + struct request_queue *q = lo->lo_queue; + int ret; + + if (!q->limits.max_provision_sectors) { + ret = -EOPNOTSUPP; + goto out; + } + + ret = file->f_op->fallocate(file, FALLOC_FL_PROVISION, pos, blk_rq_bytes(rq)); + if (unlikely(ret && ret != -EINVAL && ret != -EOPNOTSUPP)) + ret = -EIO; + out: + return ret; +} + static int lo_req_flush(struct loop_device *lo, struct request *rq) { int ret = vfs_fsync(lo->lo_backing_file, 0); @@ -488,6 +506,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_req_provision(lo, rq, pos); case REQ_OP_WRITE: if (cmd->use_aio) return lo_rw_aio(lo, cmd, pos, WRITE); @@ -754,6 +774,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 +1131,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 +1344,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); @@ -1815,6 +1856,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: -- 2.31.0