Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2280526ybl; Thu, 19 Dec 2019 10:56:52 -0800 (PST) X-Google-Smtp-Source: APXvYqzAWHR/Bu6z9ZJursmV5wD4e7lDi/qmYEZuPaQyaX03SLdKLt2uznMxo4z6ADU/wMan8+1Z X-Received: by 2002:a9d:3e16:: with SMTP id a22mr8471432otd.259.1576781812674; Thu, 19 Dec 2019 10:56:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576781812; cv=none; d=google.com; s=arc-20160816; b=K+x6lrYzHM8KuuDgGNMxqsW9uXOoN7Dwu6JY7cpzjyelwsQ6+8zRiiVicRlrfG4D+K Ew0lkWfra2FblfEQuxr724b3DIK4yaoBhKRWSyyv1uuL5wgAw7y0NOSYPVS2QGXDs6nn iVUTOcnSCyRY0e3qZKcyWIQA4hTo5PEZ+tttOuWlNo6lRrsx3I0/+w6qL8/2epbBUpFI Uioj+DhF6eLceFv44MmoyzgXj1DgqhPHP8OWdjNz/m8XqOH3sTC6DQprdKIqNKpTOhRT ZndvUHDF0qufMFAZJP5RvlXJsir/1kpbEtwPwzmYi95folRC3sV3bNh1ZRYM2aRZShfx DdDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZAUKNc18OHrOSiZ66Vhe/BRBd2t1cdBcJDRvWJQ8dio=; b=UT41COdKVdBkfwa6d6jHzJX8o42MpFyrNX6Yq7sVVqCzeASRvovQCwuHLbzZDYXHXq zb5Fifiv432jeCVFtwA9IO2uPnWK0QKN5B2PEe8rZMZb2q+hzzaBAWlCztIEZnRuvnU/ I+kVV+wqPrczb45B+Ah4h1lC+MB/jiODJ/y1AmM3FZM8Kdni2oJIIF54g4qPs3GSaLnO eHRbsDma/KpCn8DeGFf/gDBcTaV4GGB1Y8NmwI2+arUwDh0HTgvGkjvgg1Mj4ITSR23H rOEr8C9JR8DykhJoMCIyvXFJzrykgsMqEdqkS7X23SF9AnAa9Kyyxvu8uSaIMh9TwXa1 E/LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gZ9s72sd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si3378382oir.132.2019.12.19.10.56.40; Thu, 19 Dec 2019 10:56:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gZ9s72sd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730673AbfLSSza (ORCPT + 99 others); Thu, 19 Dec 2019 13:55:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:51498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730671AbfLSSz3 (ORCPT ); Thu, 19 Dec 2019 13:55:29 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 13419222C2; Thu, 19 Dec 2019 18:55:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781728; bh=jHk6kFfOtSMEBZVCkTM11i7PAbqCtZUHn4B97YaqBsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gZ9s72sdwjJ4Jlwo8B15ElMX/SdNkFSso68N3fyNB/zvG000dUEi14VWf8kFFl5p6 VIo2Abl0YsnLr8697XT/wKjGtP/6z8DXm1Lmc29esqSfWh7Vxpfd0YV2gQWQl1xdZ7 IuYqnv9UP9INgQ8unNgLVMH8TRSdMVFVleFoqBpI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikos Tsironis , Joe Thornber , Mike Snitzer Subject: [PATCH 5.4 56/80] dm thin metadata: Add support for a pre-commit callback Date: Thu, 19 Dec 2019 19:34:48 +0100 Message-Id: <20191219183130.074267108@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183031.278083125@linuxfoundation.org> References: <20191219183031.278083125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nikos Tsironis commit ecda7c0280e6b3398459dc589b9a41c1adb45529 upstream. Add support for one pre-commit callback which is run right before the metadata are committed. This allows the thin provisioning target to run a callback before the metadata are committed and is required by the next commit. Cc: stable@vger.kernel.org Signed-off-by: Nikos Tsironis Acked-by: Joe Thornber Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-thin-metadata.c | 29 +++++++++++++++++++++++++++++ drivers/md/dm-thin-metadata.h | 7 +++++++ 2 files changed, 36 insertions(+) --- a/drivers/md/dm-thin-metadata.c +++ b/drivers/md/dm-thin-metadata.c @@ -189,6 +189,15 @@ struct dm_pool_metadata { sector_t data_block_size; /* + * Pre-commit callback. + * + * This allows the thin provisioning target to run a callback before + * the metadata are committed. + */ + dm_pool_pre_commit_fn pre_commit_fn; + void *pre_commit_context; + + /* * We reserve a section of the metadata for commit overhead. * All reported space does *not* include this. */ @@ -826,6 +835,14 @@ static int __commit_transaction(struct d if (unlikely(!pmd->in_service)) return 0; + if (pmd->pre_commit_fn) { + r = pmd->pre_commit_fn(pmd->pre_commit_context); + if (r < 0) { + DMERR("pre-commit callback failed"); + return r; + } + } + r = __write_changed_details(pmd); if (r < 0) return r; @@ -892,6 +909,8 @@ struct dm_pool_metadata *dm_pool_metadat pmd->in_service = false; pmd->bdev = bdev; pmd->data_block_size = data_block_size; + pmd->pre_commit_fn = NULL; + pmd->pre_commit_context = NULL; r = __create_persistent_data_objects(pmd, format_device); if (r) { @@ -2044,6 +2063,16 @@ int dm_pool_register_metadata_threshold( return r; } +void dm_pool_register_pre_commit_callback(struct dm_pool_metadata *pmd, + dm_pool_pre_commit_fn fn, + void *context) +{ + pmd_write_lock_in_core(pmd); + pmd->pre_commit_fn = fn; + pmd->pre_commit_context = context; + pmd_write_unlock(pmd); +} + int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd) { int r = -EINVAL; --- a/drivers/md/dm-thin-metadata.h +++ b/drivers/md/dm-thin-metadata.h @@ -230,6 +230,13 @@ bool dm_pool_metadata_needs_check(struct */ void dm_pool_issue_prefetches(struct dm_pool_metadata *pmd); +/* Pre-commit callback */ +typedef int (*dm_pool_pre_commit_fn)(void *context); + +void dm_pool_register_pre_commit_callback(struct dm_pool_metadata *pmd, + dm_pool_pre_commit_fn fn, + void *context); + /*----------------------------------------------------------------*/ #endif