Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp731467rdb; Fri, 6 Oct 2023 18:29:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaaNEbcYyhHjjFr5DfDoGuDTLLfslfymmmZCINfQcOYaujELsnlRCMEaUpqdLo9RQHbM9p X-Received: by 2002:a17:902:e886:b0:1c5:f7e2:c5e0 with SMTP id w6-20020a170902e88600b001c5f7e2c5e0mr10444843plg.51.1696642154290; Fri, 06 Oct 2023 18:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696642154; cv=none; d=google.com; s=arc-20160816; b=m+PHWYuUTaONWimp4MIxYsmqGf4Rb8uSQ1dbRe4vSQbJGRGG4UKmksOEZhy5p4yp6t izH2smms7TUob6LUnccZ2nmqFUrj0ew8oGsschx8iI7Vxy/XI5/rMkqYP0AFfMIJK7ki rgXcp/nngbHexpSRs4Eo6N6H2iAV7x5uN+/UY2zZEH/8YdjdvkdCdtHy4wuxX2Esa1Z4 qIDnIQnlbYLK/s5hUilWZ0SmaE15yysnpFjeyJDQZgB2tt59/kluNUYHkZlzcmI1TuwA UhDXI4hFMFb5pcT7RgL7smbEoMcPkwgRnQ9jz2e+qXJUgaiyJCtUSZ2GJQu5LyIioQCe r/iA== 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=FqB1hDPxuIIbyhAWdDDt1cqx20h+edShJFHuWVHb1Qc=; fh=LP/ElqP5atwyI2q2hCf+Eqqm/1Qm/oXEwaFb5LVgt4U=; b=WoD7KEmw6TD/gcxheRsQDug8nCs9zM2OAaycfuum2KXMaonbbs8WnAkWbIcT3bWUUp 5R4RkXwOEvX5kdsiuNG22ohAoLghyn/EuxrJdSlo3QSVyXp3dSDyg8PYe9Girku9V0nC 6V3Yra+ZYNP+v7EqJj3HoCH8ti5i8TBcJ2MG5L4m1mWH9hMdJ438PD9OpCd8OjwNB4Wx 7PRMLw5xC0n6KoR/SQ8v9aVwHnC2pI8G1UN69xhYW18XD8SzfKBsZ8GPk2Eudf4az6RB PUM3ol/VRPf1RCdsot/WvWMtDFqGJ3dRr4ZCPJX9WIjHyEDJiM3Ca1SZndJNepP8XI+Q HAcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aWgOmSUH; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id ks14-20020a170903084e00b001b801044467si4525601plb.3.2023.10.06.18.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 18:29:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aWgOmSUH; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 5758780A28FA; Fri, 6 Oct 2023 18:29:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234068AbjJGB3D (ORCPT + 99 others); Fri, 6 Oct 2023 21:29:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234080AbjJGB2k (ORCPT ); Fri, 6 Oct 2023 21:28:40 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 530A5FF for ; Fri, 6 Oct 2023 18:28:34 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-690f7bf73ddso2195657b3a.2 for ; Fri, 06 Oct 2023 18:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696642113; x=1697246913; 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=FqB1hDPxuIIbyhAWdDDt1cqx20h+edShJFHuWVHb1Qc=; b=aWgOmSUHwsmMvbEaaTkokkzio5kkq8dXlNqM0Nt2qbGhYfAhtQ3WJb4BaiBliM9EmC EQN730lOOGn22sCAAAfEMlGWtZDQMIfZSR5jNUUY6tFGGYtqoTEOoCqUU0ScxrcWTx/n 4iWRGReDP3MdEdZrnMy5VeiOo5WzN8kmm2dD4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696642113; x=1697246913; 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=FqB1hDPxuIIbyhAWdDDt1cqx20h+edShJFHuWVHb1Qc=; b=ct20Kbca8gvFB3QIcWJMDKco9MwcuD85lj6XqQ9/VF+ADJBdkonvY/4+U45kYoyR5p LZg3WjSOr/RwHmh/E3OjXs0dS2N2mrYBsNQK7EAbxvsw4m4FFAJ0SajwJ00b3JBgsPcH XlKQx8Df8HepQzjph3UTGKLHedaQCayVe5FIoRYkiI79Lwc7dghp9qj7VKJCyx/i0XOA t3mZXGBmd4hKYUnV3iCDog5tajDg5UUwfRnbh/Ew7xgjobASNJWU5e0+RHWQCWwvxmtJ hamUHUfxcgk1zf5cqeFnCDVDDPycFofik/6jZfZs727bsMVll7bOvo1LBZ/S+mm1/0xh /fAw== X-Gm-Message-State: AOJu0YyAOD3yMy2L34+kFMd4WO/mumFlnd9ShtgcfjlZ4jI4N6tEIGGF C6v8b/mLdx2veHlenUp0nHIzCg== X-Received: by 2002:a05:6a00:3a1f:b0:690:d620:7804 with SMTP id fj31-20020a056a003a1f00b00690d6207804mr10717726pfb.13.1696642113085; Fri, 06 Oct 2023 18:28:33 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:138c:8976:eb4a:a91c]) by smtp.gmail.com with UTF8SMTPSA id 20-20020aa79114000000b006969e8dac24sm2118332pfh.68.2023.10.06.18.28.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Oct 2023 18:28:32 -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 4/5] dm: Add block provisioning support Date: Fri, 6 Oct 2023 18:28:16 -0700 Message-ID: <20231007012817.3052558-5-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.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Fri, 06 Oct 2023 18:29:08 -0700 (PDT) X-Spam-Level: ** Add block provisioning support for device-mapper targets. dm-crypt and dm-linear will, by default, passthrough REQ_OP_PROVISION requests to the underlying device, if supported. Signed-off-by: Sarthak Kukreti Signed-off-by: Mike Snitzer --- drivers/md/dm-crypt.c | 4 +++- drivers/md/dm-linear.c | 1 + drivers/md/dm-table.c | 23 +++++++++++++++++++++++ drivers/md/dm.c | 7 +++++++ include/linux/device-mapper.h | 17 +++++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index f2662c21a6df..8f94d98e241b 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -3362,6 +3362,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) cc->tag_pool_max_sectors <<= cc->sector_shift; } + ti->num_provision_bios = 1; + ret = -ENOMEM; cc->io_queue = alloc_workqueue("kcryptd_io/%s", WQ_MEM_RECLAIM, 1, devname); if (!cc->io_queue) { @@ -3416,7 +3418,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio) * - for REQ_OP_DISCARD caller must use flush if IO ordering matters */ if (unlikely(bio->bi_opf & REQ_PREFLUSH || - bio_op(bio) == REQ_OP_DISCARD)) { + bio_op(bio) == REQ_OP_DISCARD || bio_op(bio) == REQ_OP_PROVISION)) { bio_set_dev(bio, cc->dev->bdev); if (bio_sectors(bio)) bio->bi_iter.bi_sector = cc->start + diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index f4448d520ee9..74ee27ca551a 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c @@ -62,6 +62,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->num_discard_bios = 1; ti->num_secure_erase_bios = 1; ti->num_write_zeroes_bios = 1; + ti->num_provision_bios = 1; ti->private = lc; return 0; diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 37b48f63ae6a..1839317d047e 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1856,6 +1856,26 @@ static bool dm_table_supports_write_zeroes(struct dm_table *t) return true; } +static int device_provision_capable(struct dm_target *ti, struct dm_dev *dev, + sector_t start, sector_t len, void *data) +{ + return bdev_max_provision_sectors(dev->bdev); +} + +static bool dm_table_supports_provision(struct dm_table *t) +{ + for (unsigned int i = 0; i < t->num_targets; i++) { + struct dm_target *ti = dm_table_get_target(t, i); + + if (ti->provision_supported || + (ti->type->iterate_devices && + ti->type->iterate_devices(ti, device_provision_capable, NULL))) + return true; + } + + return false; +} + static int device_not_nowait_capable(struct dm_target *ti, struct dm_dev *dev, sector_t start, sector_t len, void *data) { @@ -1989,6 +2009,9 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, if (!dm_table_supports_write_zeroes(t)) q->limits.max_write_zeroes_sectors = 0; + if (!dm_table_supports_provision(t)) + q->limits.max_provision_sectors = 0; + dm_table_verify_integrity(t); /* diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 64a1f306c96c..0e6cf1a5a414 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1598,6 +1598,7 @@ static bool is_abnormal_io(struct bio *bio) case REQ_OP_DISCARD: case REQ_OP_SECURE_ERASE: case REQ_OP_WRITE_ZEROES: + case REQ_OP_PROVISION: return true; default: break; @@ -1634,6 +1635,12 @@ static blk_status_t __process_abnormal_io(struct clone_info *ci, if (ti->max_write_zeroes_granularity) max_granularity = max_sectors; break; + case REQ_OP_PROVISION: + num_bios = ti->num_provision_bios; + max_sectors = limits->max_provision_sectors; + if (ti->max_provision_granularity) + max_granularity = max_sectors; + break; default: break; } diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 69d0435c7ebb..41fd4e456d1f 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -332,6 +332,12 @@ struct dm_target { */ unsigned int num_write_zeroes_bios; + /* + * The number of PROVISION bios that will be submitted to the target. + * The bio number can be accessed with dm_bio_get_target_bio_nr. + */ + unsigned int num_provision_bios; + /* * The minimum number of extra bytes allocated in each io for the * target to use. @@ -356,6 +362,11 @@ struct dm_target { */ bool discards_supported:1; + /* Set if this target needs to receive provision requests regardless of + * whether or not its underlying devices have support. + */ + bool provision_supported:1; + /* * Set if this target requires that discards be split on * 'max_discard_sectors' boundaries. @@ -374,6 +385,12 @@ struct dm_target { */ bool max_write_zeroes_granularity:1; + /* + * Set if this target requires that provisions be split on + * 'max_provision_sectors' boundaries. + */ + bool max_provision_granularity:1; + /* * Set if we need to limit the number of in-flight bios when swapping. */ -- 2.42.0.609.gbb76f46606-goog