Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1848047rwr; Fri, 5 May 2023 23:31:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5OYpiNi4vY+RIfmwVq5kvfvHI4/xroCBtuDVeIGTObpyIoEH9K0GNVZ7mDEH+hwSo19bSl X-Received: by 2002:a05:6a00:1504:b0:643:9c72:17f with SMTP id q4-20020a056a00150400b006439c72017fmr5178312pfu.26.1683354700115; Fri, 05 May 2023 23:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683354700; cv=none; d=google.com; s=arc-20160816; b=IWZsn4dVjZGnOmPgnrFsOXy7AQ79Bxhm8eVIKJJRTuSi/ICNPwXB//j95EHW5sc3lS TPPRIGkHWarQtXN3q5ZGlbL28JmrbcqUnkoD8OdtaaJ7gNB2Ss/ZWpM+pkhfdMgtG+YH y0P1gCXWRfZIaA+KIktUw3mLOEUQHRraO6phXAmC85/mTkLSEg7vgWDi8u2/2mWl4CCF GUPpd3TQBVnCaXC1w3pLHDMY+LCjWyo0Tnnki9r3LH5dfP6I/sB0tpcPOBdLHvdekklC K7mhN1wXsPExTp3jQkEgjrIkLq2sJpDxaf/VuD9nmi0PewKWlm5w6e+poRbzTgqK0PAU L2Kw== 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=InFdLedk8W4w07J7XoL1tPvroN7gbQ5/0z95FVsjtiY=; b=bTT5j9JwgItJ3hbWiESVMQJVO4ANU4C2NeWaYTQPbyiAnJYqOqFJDxm7j4neRlNqt6 1xVyhCI9l60iSJF1ShuDi49T+p0q+79hcwohMtUlPc7jYjZ26jVv61L9C7UB1P7rKQ2C ZNNqAytyBtv76sfes5SsFSNe4xuLuRU88Udqs7rHAz/EhxACeCdRcWZe4FGa82DcP5eA JFtarf0Tov4gx51CGUP33JB+KldcqyfEO9IPmhpmqP5h75vtZAHL8iNqEtzqHxDDRkxs XrK8+N7mlcJ0NqPL1z6S+aA9qcw7mbOFYwGb2ojyt2UBq3O0ZjQ2MNNlwRmpUkLnM7ER wJ9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CmHRUMR9; 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 g14-20020aa79f0e000000b006281ec442absi3818734pfr.309.2023.05.05.23.31.27; Fri, 05 May 2023 23:31:40 -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=CmHRUMR9; 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 S230319AbjEFGaS (ORCPT + 99 others); Sat, 6 May 2023 02:30:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230083AbjEFG3d (ORCPT ); Sat, 6 May 2023 02:29:33 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7463902A for ; Fri, 5 May 2023 23:29:27 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1a516fb6523so23896005ad.3 for ; Fri, 05 May 2023 23:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1683354567; x=1685946567; 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=InFdLedk8W4w07J7XoL1tPvroN7gbQ5/0z95FVsjtiY=; b=CmHRUMR9jW4AOK1NZCBjH29qdLqf2INWs14uPajBR8COJj9RWplsSylSWW7VPXUeW8 FaVWvmdKDnJeKht84+2xka4eso8ygRjZwbxCC8KPA7rD7LNC+WcGDZCWprG9AQODUY62 WebIIxvlpLumt8V8TyqTmbh8SZ57o7f0ftVBs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683354567; x=1685946567; 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=InFdLedk8W4w07J7XoL1tPvroN7gbQ5/0z95FVsjtiY=; b=SU4KvzkXMuoagJa9CAIu/wL68X93f6kWY9SCYid5hfckx+kLHqpIaHcqAc8vOZIyYt pMqfizq4r/FySlewdKfZgCcKEDtkKpmxW2UjZNhhdIoFwFMTAajGGhzVbeKf9soWspZP nt4L9yrzvOkztfjq79FXPJOtzLiUDieJjiVQlV2Sl4GUbZzMEbA8LzT4qzciKmZ/Atv9 ea5ScjPMfjb394RxJ+oo5kuB2CbMS/k+r1XSUnlTZehQ2yXues5mg6hQ+y9endtRKbzr EmV9Cx4lZkHhSZ0ISDsNKNlznPZsDIShX1G/exoUsZYP8Xr8ZRd/fuVViFy/H6oeMesw nrqg== X-Gm-Message-State: AC+VfDzDhst8U6swEhdMxTzI9GT23TOYM6kI7s+/YO7f/fy+ETZ8O1lu ZsPYLOZ0GwGNBlzfLwHeW3EjTQ== X-Received: by 2002:a17:902:e549:b0:1a6:9f9b:1327 with SMTP id n9-20020a170902e54900b001a69f9b1327mr4551842plf.45.1683354567162; Fri, 05 May 2023 23:29:27 -0700 (PDT) Received: from sarthakkukreti-glaptop.hsd1.ca.comcast.net ([2601:647:4200:b5b0:f19c:a713:5517:ed4]) by smtp.gmail.com with ESMTPSA id q16-20020a170902dad000b001ac381f1ce9sm2793598plx.185.2023.05.05.23.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 23:29:26 -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 v6 5/5] loop: Add support for provision requests Date: Fri, 5 May 2023 23:29:09 -0700 Message-ID: <20230506062909.74601-6-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog In-Reply-To: <20230506062909.74601-1-sarthakkukreti@chromium.org> References: <20230420004850.297045-1-sarthakkukreti@chromium.org> <20230506062909.74601-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 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,URIBL_BLOCKED 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 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 | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index bc31bb7072a2..13c4b4f8b9c1 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, 0, 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, ITER_SOURCE); @@ -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); @@ -1830,6 +1871,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.40.1.521.gf1e218fcd8-goog