Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3562530pxb; Mon, 1 Mar 2021 13:26:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxebcNFjbgZGWSGHKnULKIqXgMf7VhEZyvNUYfRp3zt8r7tyFejPVXE4jDGnnjVZl/iEgzM X-Received: by 2002:a05:6402:95b:: with SMTP id h27mr3624949edz.93.1614633980132; Mon, 01 Mar 2021 13:26:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614633980; cv=none; d=google.com; s=arc-20160816; b=nlkDwmp/c/Fu8OeOd50Mf9zjSXjbStq1W47Z4P+kr+0v0SVGGmx/mJC/1mPB4MxgV2 Auopdm6KFSte4V5kBnrUqqMdfiH32FZs5Waz/m/Sx/XTNy1+j7wNau75gWXPeo8prtGZ MeTtShhqejhzQjQgKDuVPP9E8OmWDatppK/Vq/oipcimcRg9XyaGE75RP35Bfje94Cug lAXGrGHkAP0qESvlcCyeXjwQJUy6iB03uIAHz7d0EMKlS2TUM4Qm5/pth8B5ta8vrgtC LTqohChcjVQ56iCHAh+V/1pVrQnEUS0tyzvpDW8goyA8R8tGYlqKVlhV1O3yUvCx0Yr4 WB4Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CoWsy9Gam7iv8Ul/9FXtPh12+yJxZgYaDClMi9AfhGs=; b=owCvaDafKTyAd6kWY4tJOt9R9tic/KBC8wIDqTKNceN9dSBXdp7hvZYlAbyMZ7AG/r qT4r03BcvjACCVcXbRW+LR3ibbh2/k9aHuudGl75Zfw8GyAnkVVdfSh1BRYX7T6ExX/P 3PiuLoZk3zkmGTj0rDpXxf9gPr32q62GVucoArLQeezTKon9UwQszRIGcsU9/C5KGxGh AG1I3XT47TlBMRWugnxZnrAU8G8qAgEhFugmuXloo0fSk31qDQn+5E94umLm76MV9r7C DNJRHxNxGGla9amuwAMtDZYi19s8FR4KnvAuZkNFj6g3jLPp1olaODm7IlmGytpkwApw jzLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ohZwuOHP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h23si11700822ejt.655.2021.03.01.13.25.57; Mon, 01 Mar 2021 13:26:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ohZwuOHP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244002AbhCAVXT (ORCPT + 99 others); Mon, 1 Mar 2021 16:23:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:50436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232265AbhCARQE (ORCPT ); Mon, 1 Mar 2021 12:16:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C528A65050; Mon, 1 Mar 2021 16:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617185; bh=0KBqfaLlD1LOkMSE99nIANNFPHTpm6MgxtAapTpg6Do=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ohZwuOHP0axmmG5K0DEXAelJgG05PAJtkKqVtslFra9nz6rFHDFtCqJZ5I6ZjL0L1 WExHaL1KL2pzyaRsCJ/lDkUsNcdE4uZTXRIIGNngfQ8jxCwpaE2uyDtaViy0Dr0MCN s3kb+JEwzw8hmkDk8OV//ev0nTbyf4UI+jOMMVTQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikos Tsironis , Mike Snitzer Subject: [PATCH 4.19 233/247] dm era: Recover committed writeset after crash Date: Mon, 1 Mar 2021 17:14:13 +0100 Message-Id: <20210301161043.104059624@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nikos Tsironis commit de89afc1e40fdfa5f8b666e5d07c43d21a1d3be0 upstream. Following a system crash, dm-era fails to recover the committed writeset for the current era, leading to lost writes. That is, we lose the information about what blocks were written during the affected era. dm-era assumes that the writeset of the current era is archived when the device is suspended. So, when resuming the device, it just moves on to the next era, ignoring the committed writeset. This assumption holds when the device is properly shut down. But, when the system crashes, the code that suspends the target never runs, so the writeset for the current era is not archived. There are three issues that cause the committed writeset to get lost: 1. dm-era doesn't load the committed writeset when opening the metadata 2. The code that resizes the metadata wipes the information about the committed writeset (assuming it was loaded at step 1) 3. era_preresume() starts a new era, without taking into account that the current era might not have been archived, due to a system crash. To fix this: 1. Load the committed writeset when opening the metadata 2. Fix the code that resizes the metadata to make sure it doesn't wipe the loaded writeset 3. Fix era_preresume() to check for a loaded writeset and archive it, before starting a new era. Fixes: eec40579d84873 ("dm: add era target") Cc: stable@vger.kernel.org # v3.15+ Signed-off-by: Nikos Tsironis Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-era-target.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) --- a/drivers/md/dm-era-target.c +++ b/drivers/md/dm-era-target.c @@ -70,8 +70,6 @@ static size_t bitset_size(unsigned nr_bi */ static int writeset_alloc(struct writeset *ws, dm_block_t nr_blocks) { - ws->md.nr_bits = nr_blocks; - ws->md.root = INVALID_WRITESET_ROOT; ws->bits = vzalloc(bitset_size(nr_blocks)); if (!ws->bits) { DMERR("%s: couldn't allocate in memory bitset", __func__); @@ -84,12 +82,14 @@ static int writeset_alloc(struct writese /* * Wipes the in-core bitset, and creates a new on disk bitset. */ -static int writeset_init(struct dm_disk_bitset *info, struct writeset *ws) +static int writeset_init(struct dm_disk_bitset *info, struct writeset *ws, + dm_block_t nr_blocks) { int r; - memset(ws->bits, 0, bitset_size(ws->md.nr_bits)); + memset(ws->bits, 0, bitset_size(nr_blocks)); + ws->md.nr_bits = nr_blocks; r = setup_on_disk_bitset(info, ws->md.nr_bits, &ws->md.root); if (r) { DMERR("%s: setup_on_disk_bitset failed", __func__); @@ -578,6 +578,7 @@ static int open_metadata(struct era_meta md->nr_blocks = le32_to_cpu(disk->nr_blocks); md->current_era = le32_to_cpu(disk->current_era); + ws_unpack(&disk->current_writeset, &md->current_writeset->md); md->writeset_tree_root = le64_to_cpu(disk->writeset_tree_root); md->era_array_root = le64_to_cpu(disk->era_array_root); md->metadata_snap = le64_to_cpu(disk->metadata_snap); @@ -869,7 +870,6 @@ static int metadata_era_archive(struct e } ws_pack(&md->current_writeset->md, &value); - md->current_writeset->md.root = INVALID_WRITESET_ROOT; keys[0] = md->current_era; __dm_bless_for_disk(&value); @@ -881,6 +881,7 @@ static int metadata_era_archive(struct e return r; } + md->current_writeset->md.root = INVALID_WRITESET_ROOT; md->archived_writesets = true; return 0; @@ -897,7 +898,7 @@ static int metadata_new_era(struct era_m int r; struct writeset *new_writeset = next_writeset(md); - r = writeset_init(&md->bitset_info, new_writeset); + r = writeset_init(&md->bitset_info, new_writeset, md->nr_blocks); if (r) { DMERR("%s: writeset_init failed", __func__); return r; @@ -950,7 +951,7 @@ static int metadata_commit(struct era_me int r; struct dm_block *sblock; - if (md->current_writeset->md.root != SUPERBLOCK_LOCATION) { + if (md->current_writeset->md.root != INVALID_WRITESET_ROOT) { r = dm_bitset_flush(&md->bitset_info, md->current_writeset->md.root, &md->current_writeset->md.root); if (r) { @@ -1579,7 +1580,7 @@ static int era_preresume(struct dm_targe start_worker(era); - r = in_worker0(era, metadata_new_era); + r = in_worker0(era, metadata_era_rollover); if (r) { DMERR("%s: metadata_era_rollover failed", __func__); return r;