Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1847799rwr; Fri, 5 May 2023 23:31:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7bHepLKA6NmucYaQwjsHzoERUOkL9y97iwwbLiW4atZozS7b71B8DTfpZPz7cG4Qo++wEt X-Received: by 2002:a17:902:dacf:b0:1a6:e6b6:7d79 with SMTP id q15-20020a170902dacf00b001a6e6b67d79mr4783919plx.49.1683354682365; Fri, 05 May 2023 23:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683354682; cv=none; d=google.com; s=arc-20160816; b=a5ZMtN7trO7P5sYghkJkykFypqecLQdBROpMOGaqRUuuFFXoU2Dji4UfFLgjd7jxp1 +lF2F8yEuONk8vtDK2nrOAvzu1nJN6077VoTTZjjCDENQ8nd+Q4QoKlxEhZ1E7HDsN5x dCv5axswq7Zvz6RzimwOGEVI/UtNKJtcFwzKH1uuEXlliTKPeTB1o2JgixYc7g1zYJKR cW6fgOL/Mm7v1Erre5FDKaRfOFcqxUWf7mMhLguJk+8pa+2MEKlMqliX0DB9vXPQ3L70 tEpnQdZkGTG+/aQSg0cBd/x3FITUUCpPNDio4LxJrWni/CoJHrkbBJjpF9cj1v1OD96r xf4w== 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=GA9/r1+W52jO7n2EjPCELUtEsZGxSnkL540gJUY9gpA=; b=X4455ududRahEUL/uNSIBHCP6siaf8Z0JFTkJBfd48DPaeqKage+4VtEQK/HZawK4H WW1ziS1OrCFFpsr5YS6eV7ePmUD1Vhpn3+ctcDaZhf44VycfBuRkGIurpjcnCF31LXsa +YAnTdxJ60Av3VdnhePEDIkYnxRR2RtzDSoSHEsmB+CkuoOttNEJc54QT/h8S4B6Oa03 MeRC8KPo6D2swln/b1qsND1ICguryVeEDqFIvkybD9rptg4iNd850A4cMULJ+zRvrxul XA+HLlGIZIbqfrq4a/QkY29Z3KVXSwWSfVFJjHDMFNI91rtwBK9S1wJ47/RH2d2R4gN4 KCEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GB0N8axl; 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 g1-20020a170902740100b001ab0216d6b3si3191899pll.652.2023.05.05.23.31.08; Fri, 05 May 2023 23:31:22 -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=GB0N8axl; 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 S230237AbjEFGaC (ORCPT + 99 others); Sat, 6 May 2023 02:30:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230039AbjEFG3d (ORCPT ); Sat, 6 May 2023 02:29:33 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D68A9001 for ; Fri, 5 May 2023 23:29:26 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1ab05018381so24248035ad.2 for ; Fri, 05 May 2023 23:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1683354566; x=1685946566; 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=GA9/r1+W52jO7n2EjPCELUtEsZGxSnkL540gJUY9gpA=; b=GB0N8axleFFpirH/WmF1g9f99okHbh8g8gp06TveEZqIkmQ30yB/pH6wQ/umVZP/Lc Fm3Qm8Q3WbjHGo1s+YH5daC9mP8AvHv55CLeeA9Yy1dXwq+XOKGlqxKS7Q4lkR6ertny HaWE0Hi1ovT0B6xj/3GwtgGPui4EIVsa1/Kug= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683354566; x=1685946566; 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=GA9/r1+W52jO7n2EjPCELUtEsZGxSnkL540gJUY9gpA=; b=NasaXOckZ67YM4Aolk+wlsP4+Rh9owJ4x+yJIe7iG/AQX8bXhLMG4CLdOaZRFYZGNd wHyJLYUVqO2gfhp468I2JZv+bfNlVakIC4kcDY+WaFP5Ft5DpZGb93jwRF8ZQHxIm+so sCVhy6SQRBsq9QSblQmdiX3P4uMnRcPRffSXZaeiyoMhNR0Li9pqRdIFYp5beqX7PMQO jfhdrgw0MWDlOsc53HBm3yH3bV9OQeE7m2RQkiPq0HFt0/igCkLDW/QZJcU+ZP3xXykG d6eRgbbrY0A4WCzoZCNagEgNxLn1n0ELTVpmVYgBpIo0sMU/9eBx+uHLOYUn1xRyO3PH S1TA== X-Gm-Message-State: AC+VfDw2/DBJ+hByzIpKCCB7ZrelmouDpnCFkDAeTwlICK4QveA0/Zdd KOIeDeRgRuMDI525n3wrBn7A2g== X-Received: by 2002:a17:902:8691:b0:19a:9890:eac6 with SMTP id g17-20020a170902869100b0019a9890eac6mr3683354plo.24.1683354565876; Fri, 05 May 2023 23:29:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 23:29:25 -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 4/5] dm-thin: Add REQ_OP_PROVISION support Date: Fri, 5 May 2023 23:29:08 -0700 Message-ID: <20230506062909.74601-5-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 dm-thinpool uses the provision request to provision blocks for a dm-thin device. dm-thinpool currently does not pass through REQ_OP_PROVISION to underlying devices. For shared blocks, provision requests will break sharing and copy the contents of the entire block. Additionally, if 'skip_block_zeroing' is not set, dm-thin will opt to zero out the entire range as a part of provisioning. Signed-off-by: Sarthak Kukreti --- drivers/md/dm-thin.c | 70 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index 2b13c949bd72..3f94f53ac956 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c @@ -274,6 +274,7 @@ struct pool { process_bio_fn process_bio; process_bio_fn process_discard; + process_bio_fn process_provision; process_cell_fn process_cell; process_cell_fn process_discard_cell; @@ -913,7 +914,8 @@ static void __inc_remap_and_issue_cell(void *context, struct bio *bio; while ((bio = bio_list_pop(&cell->bios))) { - if (op_is_flush(bio->bi_opf) || bio_op(bio) == REQ_OP_DISCARD) + if (op_is_flush(bio->bi_opf) || bio_op(bio) == REQ_OP_DISCARD || + bio_op(bio) == REQ_OP_PROVISION) bio_list_add(&info->defer_bios, bio); else { inc_all_io_entry(info->tc->pool, bio); @@ -1245,8 +1247,8 @@ static int io_overlaps_block(struct pool *pool, struct bio *bio) static int io_overwrites_block(struct pool *pool, struct bio *bio) { - return (bio_data_dir(bio) == WRITE) && - io_overlaps_block(pool, bio); + return (bio_data_dir(bio) == WRITE) && io_overlaps_block(pool, bio) && + bio_op(bio) != REQ_OP_PROVISION; } static void save_and_set_endio(struct bio *bio, bio_end_io_t **save, @@ -1953,6 +1955,51 @@ static void provision_block(struct thin_c *tc, struct bio *bio, dm_block_t block } } +static void process_provision_bio(struct thin_c *tc, struct bio *bio) +{ + int r; + struct pool *pool = tc->pool; + dm_block_t block = get_bio_block(tc, bio); + struct dm_bio_prison_cell *cell; + struct dm_cell_key key; + struct dm_thin_lookup_result lookup_result; + + /* + * If cell is already occupied, then the block is already + * being provisioned so we have nothing further to do here. + */ + build_virtual_key(tc->td, block, &key); + if (bio_detain(pool, &key, bio, &cell)) + return; + + if (tc->requeue_mode) { + cell_requeue(pool, cell); + return; + } + + r = dm_thin_find_block(tc->td, block, 1, &lookup_result); + switch (r) { + case 0: + if (lookup_result.shared) { + process_shared_bio(tc, bio, block, &lookup_result, cell); + } else { + bio_endio(bio); + cell_defer_no_holder(tc, cell); + } + break; + case -ENODATA: + provision_block(tc, bio, block, cell); + break; + + default: + DMERR_LIMIT("%s: dm_thin_find_block() failed: error = %d", + __func__, r); + cell_defer_no_holder(tc, cell); + bio_io_error(bio); + break; + } +} + static void process_cell(struct thin_c *tc, struct dm_bio_prison_cell *cell) { int r; @@ -2228,6 +2275,8 @@ static void process_thin_deferred_bios(struct thin_c *tc) if (bio_op(bio) == REQ_OP_DISCARD) pool->process_discard(tc, bio); + else if (bio_op(bio) == REQ_OP_PROVISION) + pool->process_provision(tc, bio); else pool->process_bio(tc, bio); @@ -2579,6 +2628,7 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode) dm_pool_metadata_read_only(pool->pmd); pool->process_bio = process_bio_fail; pool->process_discard = process_bio_fail; + pool->process_provision = process_bio_fail; pool->process_cell = process_cell_fail; pool->process_discard_cell = process_cell_fail; pool->process_prepared_mapping = process_prepared_mapping_fail; @@ -2592,6 +2642,7 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode) dm_pool_metadata_read_only(pool->pmd); pool->process_bio = process_bio_read_only; pool->process_discard = process_bio_success; + pool->process_provision = process_bio_fail; pool->process_cell = process_cell_read_only; pool->process_discard_cell = process_cell_success; pool->process_prepared_mapping = process_prepared_mapping_fail; @@ -2612,6 +2663,7 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode) pool->out_of_data_space = true; pool->process_bio = process_bio_read_only; pool->process_discard = process_discard_bio; + pool->process_provision = process_bio_fail; pool->process_cell = process_cell_read_only; pool->process_prepared_mapping = process_prepared_mapping; set_discard_callbacks(pool); @@ -2628,6 +2680,7 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode) dm_pool_metadata_read_write(pool->pmd); pool->process_bio = process_bio; pool->process_discard = process_discard_bio; + pool->process_provision = process_provision_bio; pool->process_cell = process_cell; pool->process_prepared_mapping = process_prepared_mapping; set_discard_callbacks(pool); @@ -2749,7 +2802,8 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio) return DM_MAPIO_SUBMITTED; } - if (op_is_flush(bio->bi_opf) || bio_op(bio) == REQ_OP_DISCARD) { + if (op_is_flush(bio->bi_opf) || bio_op(bio) == REQ_OP_DISCARD || + bio_op(bio) == REQ_OP_PROVISION) { thin_defer_bio_with_throttle(tc, bio); return DM_MAPIO_SUBMITTED; } @@ -3396,6 +3450,9 @@ static int pool_ctr(struct dm_target *ti, unsigned int argc, char **argv) pt->adjusted_pf = pt->requested_pf = pf; ti->num_flush_bios = 1; ti->limit_swap_bios = true; + ti->num_provision_bios = 1; + ti->provision_supported = true; + ti->max_provision_granularity = true; /* * Only need to enable discards if the pool should pass @@ -4114,6 +4171,8 @@ static void pool_io_hints(struct dm_target *ti, struct queue_limits *limits) * The pool uses the same discard limits as the underlying data * device. DM core has already set this up. */ + + limits->max_provision_sectors = pool->sectors_per_block; } static struct target_type pool_target = { @@ -4288,6 +4347,9 @@ static int thin_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->max_discard_granularity = true; } + ti->num_provision_bios = 1; + ti->provision_supported = true; + mutex_unlock(&dm_thin_pool_table.mutex); spin_lock_irq(&tc->pool->lock); -- 2.40.1.521.gf1e218fcd8-goog