Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp731395rdb; Fri, 6 Oct 2023 18:28:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkgzQiGYrYG3MtjXtyXgZwRP7Z7dHFa4EfjnMFPeDzU+TMaFe36alFt5b/YXiXE1AVZFyQ X-Received: by 2002:a17:903:2309:b0:1c6:2acc:62d7 with SMTP id d9-20020a170903230900b001c62acc62d7mr11384981plh.15.1696642131482; Fri, 06 Oct 2023 18:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696642131; cv=none; d=google.com; s=arc-20160816; b=xUkJ5atdw8r/y09Gf90CBP/wHJT75BdAZkX/b9zyOy+QZEBxzDcra/jhAhTZ6MB2Tg 6nPuKLg1ERu6jY4MNu8ci9C3KBnkvI6+aB7pP4yFA5KiZdwNpRmb4YfHUZs4Ey6HGASy 1bdhrZnsRgAc85Gi0zFEAci6Esi5gwR1bRhCzup7qcROUavZhotcGorJm0dp5fvH386B inbybGg8lFdPinS1+iKtu87jysH0ZDlzylIED8zXqx8DPJlky0fpQ1NtB7NJSgfJUQUC PE8Z3dApf9rpYnw9JbwP+L+kImaagVSarWv4HE6RTn8O/sX9tiTrGQVEb2nruoOXCzvS oFWQ== 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=qwbLxQP2MlVOvPJLqOZgvAlqQEss4gZRIzs/TWsm4fw=; fh=LP/ElqP5atwyI2q2hCf+Eqqm/1Qm/oXEwaFb5LVgt4U=; b=UoolHzUxn80fQvvD2B2XlfD2e4kR0fpm4esS9FYjl8pQ9JX6IFjPERTIP/cPbVwMks PF+ametN4YEBpLY46prtQjx5dD790tzzyOTOXjBGw478LCMhD0c/9tuHx3H/FTI3Ivr9 rTPon3yS2E44sOLzWNNpb9QmEO3bcA0pe0TT14T91pXfFRhApjGMR7+o4STlgvi+xk1Q BAst1MzvHdBg3pVbW5fLy+8wsbguGutyz6M54pDTywnDb5WRqrgI8ESFTjX2zKGYb1mB 0B9GMXv2XCVyDxrLQDP0dbV7y2Ol05QQmIWH2AEGIl47ZDO79lEiNy6kjkNAgeb52cIK 4xkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JAL7Y5nM; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id o10-20020a170902d4ca00b001c7347e993esi4954607plg.17.2023.10.06.18.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 18:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JAL7Y5nM; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A3ADB8137680; Fri, 6 Oct 2023 18:28:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234085AbjJGB2l (ORCPT + 99 others); Fri, 6 Oct 2023 21:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234059AbjJGB2j (ORCPT ); Fri, 6 Oct 2023 21:28:39 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 559BCDE for ; Fri, 6 Oct 2023 18:28:31 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-54290603887so1949654a12.1 for ; Fri, 06 Oct 2023 18:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696642111; x=1697246911; darn=vger.kernel.org; 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=qwbLxQP2MlVOvPJLqOZgvAlqQEss4gZRIzs/TWsm4fw=; b=JAL7Y5nMIPObXpQQ1/i/luoEBZrnL4/t4Q5U2s0jqk7ZARrhlf/wgFNRl3gN/s18Oq TLlvu68mEPALzJV21SWzNOKZhNaOgVYcL5dTwj95XQYRUluEPgVRwLpe9ciZAAcEBFwe gIyWbQzOqqXF8EQIKN6gSw68aDfOvlaXJpLWU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696642111; x=1697246911; 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=qwbLxQP2MlVOvPJLqOZgvAlqQEss4gZRIzs/TWsm4fw=; b=lufUth2sYwBxEu3tDIleRb9340rHt1t4bnLE+VwSx1IL1l8ydJk5OoW2DBMld/6VRO bBUxJIO3KB8nbvU5RpbIvH6X6Rnbq1atCUvErWDQIl3axThaHLzfkIiyKus6zLQoKFmK LyGyu9uU/X9TZOnSPTiBsQei/IsNHpQOjnNvHUELM6sM1rmx8eehmKaGuULmg+Oqk0M6 13mKR8bN+ZWm031p8KzvwNFpBswoTViWTz0R7hjzNI4TAkjG7nUDGIN3MrsLA4LNQfIJ uXf3WJ03QqdejzJI8M1mwZjfKshcHjHBvZ/jHG3yc1oqbgCYULFEC+okXePxb0IT8KkJ fllQ== X-Gm-Message-State: AOJu0YzZNXLbzOQX4n2xwhykCttQtaaATA7q/No5yqd0Yp1NxwfaIged xxhvAus+axdQjoutwM14qL1uYA== X-Received: by 2002:a17:903:25c3:b0:1c5:76b6:d4f7 with SMTP id jc3-20020a17090325c300b001c576b6d4f7mr8553824plb.36.1696642110765; Fri, 06 Oct 2023 18:28:30 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:138c:8976:eb4a:a91c]) by smtp.gmail.com with UTF8SMTPSA id o18-20020a170902d4d200b001c73fb506aesm4524873plg.128.2023.10.06.18.28.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Oct 2023 18:28:30 -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 , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , "Darrick J. Wong" , Dave Chinner , Sarthak Kukreti Subject: [PATCH v8 3/5] loop: Add support for provision requests Date: Fri, 6 Oct 2023 18:28:15 -0700 Message-ID: <20231007012817.3052558-4-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog In-Reply-To: <20231007012817.3052558-1-sarthakkukreti@chromium.org> References: <20231007012817.3052558-1-sarthakkukreti@chromium.org> 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 06 Oct 2023 18:28:49 -0700 (PDT) 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 Signed-off-by: Mike Snitzer --- 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 9f2d412fc560..abb4dddbd4fd 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, blk_mode_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); @@ -1857,6 +1884,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.42.0.609.gbb76f46606-goog