From patchwork Wed Jan 31 02:06:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= X-Patchwork-Id: 10193053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4DE65601A0 for ; Wed, 31 Jan 2018 02:08:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EDF8284E4 for ; Wed, 31 Jan 2018 02:08:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 333C7284F4; Wed, 31 Jan 2018 02:08:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EB42284E4 for ; Wed, 31 Jan 2018 02:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752874AbeAaCH6 (ORCPT ); Tue, 30 Jan 2018 21:07:58 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35860 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751735AbeAaCHD (ORCPT ); Tue, 30 Jan 2018 21:07:03 -0500 Received: by mail-wm0-f66.google.com with SMTP id f3so4913201wmc.1 for ; Tue, 30 Jan 2018 18:07:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HjY70/szO4TGMtLeAgP6WZfnVGOI6+1kNMFM+w7Xbao=; b=0yf1U2ZSgFlENBQyIRdegMuBBKocYqrxYvitlWWH3eA+D6e7uWAihomPx5kwaEBK0k qETe62RCo2biubjLKSMnEYgSwWVmjJhmmwTKM+ZWH6tpCtbPm2M5vj9BUpqfULoyJ0zv yn7e/MmyMIHhRdtM05WHIFiAeQFFzR4qOaU56mnWTD2oIIcTNdQgdUgdCWVachcdzOsv GMnEy5jk/7OdJTrLt9QL5UGgTihUQF/idGcNk8VmSPKKHg80zHduIHW5C/og+r7ToGfG n3hyqi9tckbX+Q8hRdwSnzAZ/DcwCSMkK9/gcu6tOfmSqautqbtfAseJGN8N427TqFjr +4xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HjY70/szO4TGMtLeAgP6WZfnVGOI6+1kNMFM+w7Xbao=; b=cXhUts+ZX1FBXJTfyIjGynTc8rxZYLzSei2/iS9VwMC3HqJTg6vnGpHjzqHXQlNgi4 gUeCP+5tCf+6ddtGxyStj/M5kMULm3IP3ErldRpBk9s23LJ0ds8WPlNzpIXHFvsAuA60 3ntZaR66vvwbHZk6voINYFxQhV5f22UmFPWW46VTDQsJ3/G+tAhMzCZBhmwMaoCznKJd wKekliaSVv1sxpwhDWJOl7nFBuaf4nR/mW3lHxLkBaHN+Dzu0geJi/shROyA2P03/VQx sSIbJ1MWEuqyG7QdIpkCYNkjXCSl6zpRBB6Xp0ZS5BfnKSpKhyVFR5m+ph2n+p1haCgZ bRSw== X-Gm-Message-State: AKwxyteSqqtv9aDONYe6lv6bN9gZLN5/qgNW/qZesUmxjFKNbuvJYV5M Iv9wVf8T/98i3XhXhjEFCivZ5w== X-Google-Smtp-Source: AH8x226RojRNWmqyDfrXYW7TIK0xrHbujx+Pl6SVcb0+JGm9kvIj3SQwBZHALXlJz2CFojJStXO/Dg== X-Received: by 10.80.218.4 with SMTP id z4mr15537305edj.173.1517364421996; Tue, 30 Jan 2018 18:07:01 -0800 (PST) Received: from uHalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id m17sm8249001edc.31.2018.01.30.18.07.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Jan 2018 18:07:01 -0800 (PST) From: "=?UTF-8?q?Javier=20Gonz=C3=A1lez?=" X-Google-Original-From: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= To: mb@lightnvm.io Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Holmberg , =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH 2/5] lightnvm: pblk: check data lines version on recovery Date: Wed, 31 Jan 2018 03:06:48 +0100 Message-Id: <1517364411-22386-2-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517364411-22386-1-git-send-email-javier@cnexlabs.com> References: <1517364411-22386-1-git-send-email-javier@cnexlabs.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Holmberg As a preparation for future bumps of data line persistent storage versions, we need to start checking the emeta line version during recovery. Also slit up the current emeta/smeta version into two bytes (major,minor). Recovering lines with the same major number as the current pblk data line version must succeed. This means that any changes in the persistent format must be: (1) Backward compatible: if we switch back to and older kernel, recovery of lines stored with major == current_major and minor > current_minor must succeed. (2) Forward compatible: switching to a newer kernel, recovery of lines stored with major=current_major and minor < minor must handle the data format differences gracefully(i.e. initialize new data structures to default values). If we detect lines that have a different major number than the current we must abort recovery. The user must manually migrate the data in this case. Previously the version stored in the emeta header was copied from smeta, which has version 1, so we need to set the minor version to 1. Signed-off-by: Hans Holmberg Signed-off-by: Javier González --- drivers/lightnvm/pblk-core.c | 9 ++++++++- drivers/lightnvm/pblk-recovery.c | 26 ++++++++++++++++++++++++-- drivers/lightnvm/pblk.h | 16 ++++++++++++++-- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c index 9027cf2ed1d8..155e42a26293 100644 --- a/drivers/lightnvm/pblk-core.c +++ b/drivers/lightnvm/pblk-core.c @@ -975,7 +975,8 @@ static int pblk_line_init_metadata(struct pblk *pblk, struct pblk_line *line, memcpy(smeta_buf->header.uuid, pblk->instance_uuid, 16); smeta_buf->header.id = cpu_to_le32(line->id); smeta_buf->header.type = cpu_to_le16(line->type); - smeta_buf->header.version = SMETA_VERSION; + smeta_buf->header.version_major = SMETA_VERSION_MAJOR; + smeta_buf->header.version_minor = SMETA_VERSION_MINOR; /* Start metadata */ smeta_buf->seq_nr = cpu_to_le64(line->seq_nr); @@ -998,6 +999,12 @@ static int pblk_line_init_metadata(struct pblk *pblk, struct pblk_line *line, /* End metadata */ memcpy(&emeta_buf->header, &smeta_buf->header, sizeof(struct line_header)); + + emeta_buf->header.version_major = EMETA_VERSION_MAJOR; + emeta_buf->header.version_minor = EMETA_VERSION_MINOR; + emeta_buf->header.crc = cpu_to_le32( + pblk_calc_meta_header_crc(pblk, &emeta_buf->header)); + emeta_buf->seq_nr = cpu_to_le64(line->seq_nr); emeta_buf->nr_lbas = cpu_to_le64(line->sec_in_line); emeta_buf->nr_valid_lbas = cpu_to_le64(0); diff --git a/drivers/lightnvm/pblk-recovery.c b/drivers/lightnvm/pblk-recovery.c index 1d5e961bf5e0..a30fe203d454 100644 --- a/drivers/lightnvm/pblk-recovery.c +++ b/drivers/lightnvm/pblk-recovery.c @@ -826,6 +826,25 @@ static u64 pblk_line_emeta_start(struct pblk *pblk, struct pblk_line *line) return emeta_start; } +static int pblk_recov_check_line_version(struct pblk *pblk, + struct line_emeta *emeta) +{ + struct line_header *header = &emeta->header; + + if (header->version_major != EMETA_VERSION_MAJOR) { + pr_err("pblk: line major version mismatch: %d, expected: %d\n", + header->version_major, EMETA_VERSION_MAJOR); + return 1; + } + +#ifdef NVM_DEBUG + if (header->version_minor > EMETA_VERSION_MINOR) + pr_info("pblk: newer line minor version found: %d\n", line_v); +#endif + + return 0; +} + struct pblk_line *pblk_recov_l2p(struct pblk *pblk) { struct pblk_line_meta *lm = &pblk->lm; @@ -873,9 +892,9 @@ struct pblk_line *pblk_recov_l2p(struct pblk *pblk) if (le32_to_cpu(smeta_buf->header.identifier) != PBLK_MAGIC) continue; - if (smeta_buf->header.version != SMETA_VERSION) { + if (smeta_buf->header.version_major != SMETA_VERSION_MAJOR) { pr_err("pblk: found incompatible line version %u\n", - le16_to_cpu(smeta_buf->header.version)); + smeta_buf->header.version_major); return ERR_PTR(-EINVAL); } @@ -943,6 +962,9 @@ struct pblk_line *pblk_recov_l2p(struct pblk *pblk) goto next; } + if (pblk_recov_check_line_version(pblk, line->emeta->buf)) + return ERR_PTR(-EINVAL); + if (pblk_recov_l2p_from_emeta(pblk, line)) pblk_recov_l2p_from_oob(pblk, line); diff --git a/drivers/lightnvm/pblk.h b/drivers/lightnvm/pblk.h index 8c357fb6538e..fae2526f80b2 100644 --- a/drivers/lightnvm/pblk.h +++ b/drivers/lightnvm/pblk.h @@ -320,14 +320,26 @@ enum { }; #define PBLK_MAGIC 0x70626c6b /*pblk*/ -#define SMETA_VERSION cpu_to_le16(1) + +/* emeta/smeta persistent storage format versions: + * Changes in major version requires offline migration. + * Changes in minor version are handled automatically during + * recovery. + */ + +#define SMETA_VERSION_MAJOR (0) +#define SMETA_VERSION_MINOR (1) + +#define EMETA_VERSION_MAJOR (0) +#define EMETA_VERSION_MINOR (1) struct line_header { __le32 crc; __le32 identifier; /* pblk identifier */ __u8 uuid[16]; /* instance uuid */ __le16 type; /* line type */ - __le16 version; /* type version */ + __u8 version_major; /* version major */ + __u8 version_minor; /* version minor */ __le32 id; /* line id for current line */ };