Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp487651pxb; Wed, 3 Mar 2021 08:06:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgEBDvvQa1COY5OwTy4MXDiXZKIbBmB70A/ojjYShQcyfldUn1HCWgv8hWPcqrW92Dzug2 X-Received: by 2002:a2e:904b:: with SMTP id n11mr15068589ljg.85.1614787559593; Wed, 03 Mar 2021 08:05:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614787559; cv=none; d=google.com; s=arc-20160816; b=RI8vL9ScFr4PnGuj9Mul6bNiA+susZ7gmbzcdOWAS4FF+ndyw+yQleX22GFfFJaNS/ +Q9T5UVCVqL2U7q51xRD5Ut3Xyhhw+merq1xTilCFFvUGvMf4DpJV8Go21zgjHDO9p+w pIsUYlSeLvG4eDufCooiIweKCDHkJ4VEUEzCIwvl9kfTOFpkzLberIiIYsfN4fLnkbcy Gmlpjkx64m6ZK/5HwPRxn7U0F8EkNfPpIZYUoseIZIQa8FxF9K8qLNqQhpC6oaV8OelG Km+aICDVsP9yHjZMrHAVUCRbLa6rEsR1Ug9jQuGA4UXweH2lBRqw/1YZR/GXnr8lLpEv 3OKw== 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=2fAYTJ6lT+HdozLcgMOln1npNHh43bJT/rzncAYMe90=; b=qBxGIGuh4WUTTUBg0jDNjDEWgbOPAiSe8QyspSwUqexgrupSqZdkl0Rn0+cqrqd/9d oIPgVhxrFmIczfdWrjv3ip3rYc0K8PMyyP+KsbAlgjtpEZp5yDX0fJSjDaLfauI0GoC6 94wRwhWN0R5DZWE70DuPfYQVQPBlEAY6/E1neXYnkeenIxH6XagmPRF7/jzpnZ/i58rj Gc9aSl+9FJTKw/EH3KtIjSQZx+jbTcdUXCfiVfe8telJaxp2AIyE/RzACeUgKJYITrYY G9OQ4CM9J69d7aNY0WosSK4DqtCCnJWDwuSPIY1YySWi6xnW7VDP4gr2YuLUAmkt8Q6d 73KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ch1BqvjA; 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 p26si14590480edt.29.2021.03.03.08.05.22; Wed, 03 Mar 2021 08:05:59 -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=Ch1BqvjA; 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 S1345742AbhCAXdH (ORCPT + 99 others); Mon, 1 Mar 2021 18:33:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:57190 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239034AbhCASEU (ORCPT ); Mon, 1 Mar 2021 13:04:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 981AA6529D; Mon, 1 Mar 2021 17:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619974; bh=SOAigHL47hsULGlPPzpozP3UHX5sHtQj1aRe3XJC67U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ch1BqvjAXVkeL9OmbmJ4kZxqA5R1XWa6Y5OT33BZpLsP5lr9byAaS4CHkWHhuM4Pv aPEh9fA2bzEbHuFaPhXGTOup7Xs/zhG7nzrXOpucvdKg5CYktFKSV4kU5AGNS7r20b KOAtDhazM/8DiUYkBpGJQ02X5sGit9dAtSqVcRnE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikos Tsironis , Mike Snitzer Subject: [PATCH 5.10 648/663] dm era: Recover committed writeset after crash Date: Mon, 1 Mar 2021 17:14:56 +0100 Message-Id: <20210301161213.906695372@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@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 @@ -71,8 +71,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__); @@ -85,12 +83,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__); @@ -579,6 +579,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); @@ -870,7 +871,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); @@ -882,6 +882,7 @@ static int metadata_era_archive(struct e return r; } + md->current_writeset->md.root = INVALID_WRITESET_ROOT; md->archived_writesets = true; return 0; @@ -898,7 +899,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; @@ -951,7 +952,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) { @@ -1565,7 +1566,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;