Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2893784rdb; Wed, 4 Oct 2023 15:12:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHD7SatOpCgeww6Dfn6FXX/qxh7IG0Fk4poNeQhHgU1qw2a4XDQq4pinTTt2MHY55nseEOk X-Received: by 2002:a05:6a00:1ac6:b0:690:2818:a4ce with SMTP id f6-20020a056a001ac600b006902818a4cemr4198539pfv.7.1696457570846; Wed, 04 Oct 2023 15:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696457570; cv=none; d=google.com; s=arc-20160816; b=giKviV1iNw/8Zw0uOwg4n6zmBT2hZsHgCCVzMrkgrtzb+k3EKpbyc6n2bwDN8sCQhe zHoupDIeW/+Ug3rFyq+mEI8YyLuSzTas0FnoQaEZeaTlGWtztAnKkXvzRgpc8iVVaaV1 sWCnNoT6HFFI1Us2XSWz4ETr1K5u2+x9bCyknDk2GQdVAcT7phtqLoSb+VXZgUNtemc5 ky7Ebenci/MiNdMyWJrFsyqEvH7tRmz6daj7dfRQvPChv+ydp8YgTtig1VrPWLAsnb9s 292qFqMl+0LdMhsLmnxe1EBgPZqMfL0mgv6sPlqp8X6HgF8C1BYYGmC4QJ6aj2MU6bj+ w9fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature:dkim-filter; bh=eJS+kBKHSIzGbwwv49yX5DCUKZVKLPE/A7wfEDIcA9E=; fh=PhRfb9k/VCaD3nhvPFELAdaSNFsaoc654VPOTTQHJlA=; b=SH79KNgjyR3xXdaAwiBdeDcyoRnFPwG8Ll4qSaUOFdAbFwlWdxwHydIhq4Jea40XOP A5YRa+VM//p3Yl56/hfMQ1JB5kqSseA5hUsJxFxKjGiqQ2PVYlxxe75AN7pDlgni/gpW XnF+LK394tSPwIbB6uLPna9CkxK82l3i4A8+3OhHuQytMO7hZv86tYmrdPElWgmOz7G/ B0HmmRTIPcDEyLEi9WG4Xn2BjHMdjrDXUpTWjiWMNaRnj9KIeyYrxSWwXjK2Nnw2T799 mCmWfCxPChjT+pAaeXqkObsY3AWUqwf9UQNwjMu15+Dz4CpKgwMNw/TMsYLUp8SgX/5b WeUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=kivRmiQv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id ck13-20020a056a00328d00b0068a590d8043si24635pfb.375.2023.10.04.15.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 15:12:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=kivRmiQv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id D567781DF249; Wed, 4 Oct 2023 15:12:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239469AbjJDWLK (ORCPT + 99 others); Wed, 4 Oct 2023 18:11:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233563AbjJDWJ5 (ORCPT ); Wed, 4 Oct 2023 18:09:57 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 811D3E4; Wed, 4 Oct 2023 15:09:54 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1052) id D315F20B74D8; Wed, 4 Oct 2023 15:09:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D315F20B74D8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1696457390; bh=eJS+kBKHSIzGbwwv49yX5DCUKZVKLPE/A7wfEDIcA9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kivRmiQvs0LNuyzLsMCEEVEdqNtf6L5xl16co++lbJNojj2N7CnDAjy+8HfjVqa3s DI8XBOrh8ocu5/dAKmmJnSU0tv9SUOOLCgLQQKevgS84tyQYx8ciXVaHBv2Q7ijzXh hX5dxUtiY48KK7vGUG+7aj/jEn3ihq7B4AgdN2lw= From: Fan Wu To: corbet@lwn.net, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, tytso@mit.edu, ebiggers@kernel.org, axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org, eparis@redhat.com, paul@paul-moore.com Cc: linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@redhat.com, audit@vger.kernel.org, roberto.sassu@huawei.com, linux-kernel@vger.kernel.org, Fan Wu Subject: [RFC PATCH v11 12/19] dm: add finalize hook to target_type Date: Wed, 4 Oct 2023 15:09:39 -0700 Message-Id: <1696457386-3010-13-git-send-email-wufan@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1696457386-3010-1-git-send-email-wufan@linux.microsoft.com> References: <1696457386-3010-1-git-send-email-wufan@linux.microsoft.com> X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 04 Oct 2023 15:12:27 -0700 (PDT) This patch adds a target finalize hook. The hook is triggered just before activating an inactive table of a mapped device. If it returns an error the __bind get cancelled. The dm-verity target will use this hook to attach the dm-verity's roothash metadata to the block_device struct of the mapped device. Signed-off-by: Fan Wu --- v1-v10: + Not present --- drivers/md/dm.c | 12 ++++++++++++ include/linux/device-mapper.h | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 64a1f306c96c..3be9cc35306d 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2239,6 +2239,18 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, goto out; } + for (unsigned int i = 0; i < t->num_targets; i++) { + struct dm_target *ti = dm_table_get_target(t, i); + + if (ti->type->finalize) { + ret = ti->type->finalize(ti); + if (ret) { + old_map = ERR_PTR(ret); + goto out; + } + } + } + old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); rcu_assign_pointer(md->map, (void *)t); md->immutable_target_type = dm_table_get_immutable_target_type(t); diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 69d0435c7ebb..4040e84a8ec7 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -160,6 +160,12 @@ typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff, */ typedef size_t (*dm_dax_recovery_write_fn)(struct dm_target *ti, pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i); +/* + * Returns: + * < 0 : error + * = 0 : success + */ +typedef int (*dm_finalize_fn) (struct dm_target *target); void dm_error(const char *message); @@ -209,6 +215,7 @@ struct target_type { dm_dax_direct_access_fn direct_access; dm_dax_zero_page_range_fn dax_zero_page_range; dm_dax_recovery_write_fn dax_recovery_write; + dm_finalize_fn finalize; /* For internal device-mapper use. */ struct list_head list; -- 2.25.1