From patchwork Tue Apr 18 22:12:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Kukreti X-Patchwork-Id: 85099 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3160568vqo; Tue, 18 Apr 2023 15:17:28 -0700 (PDT) X-Google-Smtp-Source: AKy350ZFUnCKO8LXY7xYepheRl9/Xg7/9WIPggEPRmZgzZj9eO/u3fdLJEPK+8HGvTYdwOJK3zV+ X-Received: by 2002:a05:6a20:1a86:b0:f0:f2a:ff4f with SMTP id ci6-20020a056a201a8600b000f00f2aff4fmr1071621pzb.8.1681856248361; Tue, 18 Apr 2023 15:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681856248; cv=none; d=google.com; s=arc-20160816; b=yuPKIP/2e12BhXwrX7aCqARlbv1d4Hs3vZ9QV4vYKgLcsLHOgN1WzYPWu1vUSIPboa 1c6iLAcJGpTY7ofCga5CdaX7afhhelRmxG7uum9xGk5lp1kSD5qfHWsiSxU7AoCRzG3+ VVLSWPNRTG8WG857nY1gPSuQKfHHFDI750gKRbdb6qq9aucfNHqFmcHMVdj11ratDRgV 7XJEtXRinPr62MavcvBguDfdU5ojgougQ2cXvQj5phgWp+SnyDblgWehH9BHe1ke5CtN wLDvWaOJpW/gWK+nD6sIlegi0Rj9hhn9Ofukb7me94QNTXCS9nukG6j6YPV0g2kQaW3T afvQ== 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=DJ+yGPB/3GoY7peOyZ+CblNlWIiKQ+IujQrkD9HaThI=; b=OuT8EvUVxuDqOimvEDVgnYHHReGcSZO0z0Kl+VZpti9pSinoryqDxt3os4qF8EplLd fcRrO+h1f0Rq9a1ryjsOQmhrjYwjMqR4Cov4lt5sAFn+BMa72Nl7KPSDMGEFa4wB+VM2 zcwwbUWiOLWg2egomgjGg4bIAPYCMkspYLMIhfkOKSPIWApji+zXWSM9QkIJN4p0IIR/ CcRugWY7xrOvn7ibrYW3EI1xp07MNyCzw1o5gBdNOoyRuChg4+BPKZaezLP/Y3jM84fX Gx47htqNJI1vm9h7wMCIoNygp8W8MgT67mqQFeN2Z6BpHYf4fAmvXb7H8zQnxBkxt+Ap aPJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="JCDbU/1B"; 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 c130-20020a621c88000000b0063354a65327si14168163pfc.395.2023.04.18.15.17.13; Tue, 18 Apr 2023 15:17:28 -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="JCDbU/1B"; 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 S233213AbjDRWNF (ORCPT + 99 others); Tue, 18 Apr 2023 18:13:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233199AbjDRWMm (ORCPT ); Tue, 18 Apr 2023 18:12:42 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83AE06EA5 for ; Tue, 18 Apr 2023 15:12:35 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1a66b9bd893so22336025ad.1 for ; Tue, 18 Apr 2023 15:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681855955; x=1684447955; 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=DJ+yGPB/3GoY7peOyZ+CblNlWIiKQ+IujQrkD9HaThI=; b=JCDbU/1Bhcl2YTj6lbZ8vWIJJgUX2ZBx7G1LvK9zy76LTAJd32O6W7BwyOtGTnXIPY 4fTpOYl3vnOuO33PE9j8K486WzNAqN1s15u5FrvCJvsazYo2SrKcYSyD9AF0Yn+alco0 ukXRsiqT0/g2OCfSlkCDQQe7njZVTqrULBWrs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681855955; x=1684447955; 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=DJ+yGPB/3GoY7peOyZ+CblNlWIiKQ+IujQrkD9HaThI=; b=P7tjizlHk2lthcOvz28AJ6UU0DV8CVuEw9yCm9XTZcOmnr6A1O3nCtYfrC2g01QBkq Fms32j/w4/RcRNIAW+qiXyptHIZVk0feGE1ZBGy1c6WwFyU8cLPE3iQjOJaLHyrpSr32 kcXX19bKQMJ+Umu9WSYYhajcvG1GVFTv3hAh2gyjecZr2X8XQFLs9hHdkw8D0uwMu2Be 5EYkjqW/+7Px7Fn1qnkhpijEva2Y/CMhH+Za4unJL+51wJIOiqR56NGEjSFmNk2CwHef liB2yQUqEAhq52+afuvHCS3xax2XbuX5srDWTqn2b9Jb6MSP1U5Ptz/lOJVBJwt2thJ3 6Y2Q== X-Gm-Message-State: AAQBX9ekI3bv3pCCS+45NAuodbqAR8wkcbtCCOJnWRm82yPut9HSmAvB 2INnVJp4xgFh651nyVEv/BOp9w== X-Received: by 2002:a17:903:11cc:b0:1a6:4541:73c with SMTP id q12-20020a17090311cc00b001a64541073cmr3738421plh.33.1681855955208; Tue, 18 Apr 2023 15:12:35 -0700 (PDT) Received: from sarthakkukreti-glaptop.corp.google.com ([2620:15c:9d:200:e38b:ca5e:3203:48d3]) by smtp.gmail.com with ESMTPSA id x1-20020a1709029a4100b001a687c505e9sm9911892plv.237.2023.04.18.15.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 15:12:34 -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 , Daniil Lunev , "Darrick J. Wong" Subject: [PATCH v4 4/4] loop: Add support for provision requests Date: Tue, 18 Apr 2023 15:12:07 -0700 Message-ID: <20230418221207.244685-5-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog In-Reply-To: <20230418221207.244685-1-sarthakkukreti@chromium.org> References: <20230414000219.92640-1-sarthakkukreti@chromium.org> <20230418221207.244685-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,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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763108347101598542?= X-GMAIL-MSGID: =?utf-8?q?1763554097858743808?= 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: