From patchwork Sat May 6 06:29: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: 90678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp886761vqo; Fri, 5 May 2023 23:30:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ758Y6suNcntuHTzJX6/VTCRO3MhqryHpyJPAR+29X5tXjyRQcwuPYU7pTa1pSmnB1KmEcS X-Received: by 2002:a17:90a:c908:b0:24e:b0f:8f57 with SMTP id v8-20020a17090ac90800b0024e0b0f8f57mr3394823pjt.48.1683354658964; Fri, 05 May 2023 23:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683354658; cv=none; d=google.com; s=arc-20160816; b=Ew+EKzb0wPBZWtCEEo9L9MQHtLLKiGjz4Q7Mrcqi9OyB3l5EYh4LA2y53/MpEOkrL3 w2KqrkvB/gi6RxvDwEwLjBtsFT2VF9p+sPIO/4WH4apDoSiUVOLXMFQ9SKUN+lwN6sqI 0J5jjPl7irqmiLofmBRZptdFgWt34pccgn6QTMZxZ8mSnRX1ttF1V/6zIDF6Bpoeg4xQ vumLwu1b3dWaBI8HPgCZeho53HfKkHJoxMzPK3fO3Cne+bEnsWUTiZJtv/KAROPKgQep F0I6pGL2q0/irwciAwPvQxyHoYLHxeWZ7nc3m5X3yAlW9fhsmzk5BfdIW7J3JUaH24vj JpuQ== 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=zQ9yrjmUAqVySk8MuY1pMhr1iKygu//Q+LJoJEaObAo=; b=NSPj6QmkZOQJ0F1j7HVqf626A1SJmk74GkvBwh5uspV1sbo2PEPJNLlZ+EYZ0nGOyu Kk7tvrSHZ8CA0Gpk37Mhx5oWmXTD+SOAZQB2PdC0M/qLqD1v0C8wh1me+jjGnMi/8X/+ vUIv3imcfqKj1mT56kodg0V0Z56R35Q3nFnZDM/n/Dsa1ckJKnF4QQcodF4x58XhcW/G HfTWQDACCInOAQEHCWlgE6kRbzL7kcW67HjtX8EAgtyY/FauZ+i7FMeaWseiTnMN77fx 5owqsYawe2x2GhqAQf75bbm+M04H3a+QXlAFSSrEj05ISjJgmD0BBHA6tc8fwsYVfvai cITw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=X+RDL9WC; 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 y192-20020a638ac9000000b004a68aefb7b0si3900477pgd.173.2023.05.05.23.30.44; Fri, 05 May 2023 23:30:58 -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=X+RDL9WC; 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 S229812AbjEFG3j (ORCPT + 99 others); Sat, 6 May 2023 02:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbjEFG32 (ORCPT ); Sat, 6 May 2023 02:29:28 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D988900D for ; Fri, 5 May 2023 23:29:25 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1aaf21bb427so18394125ad.1 for ; Fri, 05 May 2023 23:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1683354564; x=1685946564; 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=zQ9yrjmUAqVySk8MuY1pMhr1iKygu//Q+LJoJEaObAo=; b=X+RDL9WCUMRLr97XlGQgcE6QkLnPJNNc9YXk6bqR+1nSI3HydlRJUHC7Gy/8LQiKVg /OPSdXCjKFy+86w2JWVcGc0qHEyNbA8axX6uZnhOHHKbvvR+QghU3ysubs9Zb0Si1lvj 3adOFHiOSmRVyJUDY7+XaZiLFFkxtLB6Kelo0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683354564; x=1685946564; 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=zQ9yrjmUAqVySk8MuY1pMhr1iKygu//Q+LJoJEaObAo=; b=j6mhSnS5Pk02p6r0Dy/adu9NR4ZP8TnvL3AJ2qks1smrKrvCqZy3zHXflMU8l0Tw7M f2bTN5fI9Z0IScrUBl3OE+U6O6fpfFPHVu0F1czdfN2rvNGaw36n0LCcUzDGB4tSqFXz myjvUVJ9vHWLPr/x5+rfzDNlYdzWbH7PqwEbN6cAihAZ+jQRt0EWNnMDRyOQGI6LBMgG Gh60rAd5MwpYBQiX3q1XAA4RMB4n/k2lYM/dU33phYtKxAbPLQBUTULcYFPj+E4u+K99 9hnsTDS0MXZvzTkol6PZPq+PNReMyGvt1Ng9qOEV6oCXyyPiGqX/6KALh4yMLLpmDwtG 20JA== X-Gm-Message-State: AC+VfDw0P9JNEhFNMVRb/Bbsc0L8xYm1FMEKRAIN0CEOwJqt9ItVAuVc mvWq5Rr81dEavcUdPEXuQ6yNIg== X-Received: by 2002:a17:903:228c:b0:19e:6e00:4676 with SMTP id b12-20020a170903228c00b0019e6e004676mr4943558plh.61.1683354564473; Fri, 05 May 2023 23:29:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 23:29:24 -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 3/5] dm: Add block provisioning support Date: Fri, 5 May 2023 23:29:07 -0700 Message-ID: <20230506062909.74601-4-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 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=ham 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?1763554120825813569?= X-GMAIL-MSGID: =?utf-8?q?1765125295031076161?= Add block provisioning support for device-mapper targets. dm-crypt, dm-snap and dm-linear will, by default, passthrough REQ_OP_PROVISION requests to the underlying device, if supported. Signed-off-by: Sarthak Kukreti Reviewed-by: Mike Snitzer --- drivers/md/dm-crypt.c | 4 +++- drivers/md/dm-linear.c | 1 + drivers/md/dm-snap.c | 7 +++++++ drivers/md/dm-table.c | 23 +++++++++++++++++++++++ drivers/md/dm.c | 6 ++++++ include/linux/device-mapper.h | 17 +++++++++++++++++ 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 8b47b913ee83..5a7c475ce6fc 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -3336,6 +3336,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) { @@ -3390,7 +3392,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-snap.c b/drivers/md/dm-snap.c index 9c49f53760d0..0dfda50ac4e0 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -1358,6 +1358,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) if (s->discard_zeroes_cow) ti->num_discard_bios = (s->discard_passdown_origin ? 2 : 1); ti->per_io_data_size = sizeof(struct dm_snap_tracked_chunk); + ti->num_provision_bios = 1; /* Add snapshot to the list of snapshots for this origin */ /* Exceptions aren't triggered till snapshot_resume() is called */ @@ -2003,6 +2004,11 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio) /* If the block is already remapped - use that, else remap it */ e = dm_lookup_exception(&s->complete, chunk); if (e) { + if (unlikely(bio_op(bio) == REQ_OP_PROVISION)) { + bio_endio(bio); + r = DM_MAPIO_SUBMITTED; + goto out_unlock; + } remap_exception(s, e, bio, chunk); if (unlikely(bio_op(bio) == REQ_OP_DISCARD) && io_overlaps_chunk(s, bio)) { @@ -2413,6 +2419,7 @@ static void snapshot_io_hints(struct dm_target *ti, struct queue_limits *limits) /* All discards are split on chunk_size boundary */ limits->discard_granularity = snap->store->chunk_size; limits->max_discard_sectors = snap->store->chunk_size; + limits->max_provision_sectors = snap->store->chunk_size; up_read(&_origins_lock); } diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 119db5e01080..282c530b0685 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1854,6 +1854,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) { @@ -1987,6 +2007,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 3b694ba3a106..9b94121b8d38 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1609,6 +1609,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; @@ -1641,6 +1642,11 @@ static blk_status_t __process_abnormal_io(struct clone_info *ci, if (ti->max_write_zeroes_granularity) max_granularity = limits->max_write_zeroes_sectors; break; + case REQ_OP_PROVISION: + num_bios = ti->num_provision_bios; + if (ti->max_provision_granularity) + max_granularity = limits->max_provision_sectors; + break; default: break; } diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index a52d2b9a6846..9981378457d2 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -334,6 +334,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. @@ -358,6 +364,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. @@ -376,6 +387,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. */