Received: by 10.223.185.111 with SMTP id b44csp1651178wrg; Sat, 10 Mar 2018 10:37:28 -0800 (PST) X-Google-Smtp-Source: AG47ELss8T/oXxM2Qny0nrzCT0ty1FkTo6oweo6putc91htV8CbGDFVUDym+GL1zEIjUPbhMWzB9 X-Received: by 10.99.176.68 with SMTP id z4mr2201069pgo.74.1520707048086; Sat, 10 Mar 2018 10:37:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520707048; cv=none; d=google.com; s=arc-20160816; b=v/C+Kfb4BqNyVk8QvK9TmioJ5WmAlmWWMc2J4CDkLuCsXmvBjO9zaWzhtwC6J5auXD 8JogUJRRUyaLd4GTC1EfXLu5CFYew0O+oMos9r4TTvIqfDBkY3EfVCeRziV6XyH6GFmD i8Y0Fyv1azTP1Rp3vVfO5JCMzuoX/UbazIMd0Uqb+H3GN9A0hIEiIQG9V5vCm4qjYoPa wnPes6d8UIjlnOrTvzn4ftuvcWH2ajq405UTGRP+UZaRu3JczRoWTpcAGP8LkF282Jbe 6vRvaXkNnH4JdWpfCyeAahHlsbftJA7C6iywDln26kyMOmmcEE6hoQ8TtAMmMgWE1ahl POBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=mZoVTbpYe9Ios388QUb4laiDdMez7/Axwp+UO/tiM9U=; b=D7acLq1nRRzrk/eD7csRKtR+mgX3V/baRTLVEtMZCIj+nHQOv9Juvd0eNtvSckxkna AiHW1SHtLC46tprtStX1D0But5E9PTk+jg1xkMAm49slD+WkrcI1zjntWMp4pj8X4cnf 2ZAxZmLKW9C2vxWhedDOuXa+vuL2YvtahqP85N1Rc4A2dUXHtzG5YVIZjoIW1vJdQ70j NeuAMrwlygRXKtSLXorVo0YwsSMJEuuqAGpcs+JVMM55INQrdzg8IA16LOpU0J15c8zw zYsDqSogiqluq9Mbrc0WH/NgHe/QXCQG+l/swMdxSkLKHdtJp4n1Tw4BYkmzwFcpWAOq IH2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=Kca1Pv0u; 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 l12-v6si1256860plc.696.2018.03.10.10.37.14; Sat, 10 Mar 2018 10:37:28 -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=@eng.ucsd.edu header.s=google header.b=Kca1Pv0u; 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 S1751315AbeCJSgD (ORCPT + 99 others); Sat, 10 Mar 2018 13:36:03 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:39703 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932521AbeCJSVC (ORCPT ); Sat, 10 Mar 2018 13:21:02 -0500 Received: by mail-pf0-f195.google.com with SMTP id u5so2617793pfh.6 for ; Sat, 10 Mar 2018 10:21:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eng.ucsd.edu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mZoVTbpYe9Ios388QUb4laiDdMez7/Axwp+UO/tiM9U=; b=Kca1Pv0uVBzWnIHP9QJoBcwZg0T68JdXTJq3KrA1wTQI6lJFSsPwmfsIS7gBmy1kwp Acrig1XlHSG4Z0I/Z9n0bGC7XeiCw2APv4nqsZqJjH2rl9guXRKoXrnjvXTula9nrtgm MyXNeWGar5B8Rnf1stke/xA/CubmRzrT0/zMI= 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; bh=mZoVTbpYe9Ios388QUb4laiDdMez7/Axwp+UO/tiM9U=; b=FrqKWyXK05pOnhlhiAJLhwBy5xobAQJzmI7Vrzp0L6fmkTXFbKQ/AzEawlGqIUJnEz Jz6KsGegF9XaHp7giOEepKuJdD7EuAg2tsdsVWPgd6zyPWkeaQgYIxHTiz3wrogEiejc wcsr/EdpuplqNNpC083LXR0eQoy5dmd0fXfYESZtvtB++NG9b/iOTE9wKsweQpKzREfK n4Gv9r0ttMXzW+KbbZ2bfCgrBajAbUBqVwHdC8Yewt2P61qm95CMULStxQ3KAVAsikwo qvF3ObxbqOB1A7wbHvoex2E9f+Z/6qn1YuVfgOVg+8oJtV3ZXUH1XdS1QfFeApNQPHy/ dKfg== X-Gm-Message-State: AElRT7F/GpKKbwaL65yPdXag9HlCVrYzB5uUdhkWHTs8W3SSsM1E5mYZ L6gT8vrnFlu5nhiUANbJ2G38EQ== X-Received: by 10.99.115.21 with SMTP id o21mr2222444pgc.226.1520706062283; Sat, 10 Mar 2018 10:21:02 -0800 (PST) Received: from brienza-desktop.8.8.4.4 (andxu.ucsd.edu. [132.239.17.134]) by smtp.gmail.com with ESMTPSA id h80sm9210167pfj.181.2018.03.10.10.21.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:01 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Cc: dan.j.williams@intel.com, andy.rudoff@intel.com, coughlan@redhat.com, swanson@cs.ucsd.edu, david@fromorbit.com, jack@suse.com, swhiteho@redhat.com, miklos@szeredi.hu, andiry.xu@gmail.com, Andiry Xu Subject: [RFC v2 38/83] Journal: NOVA lite journal initialization. Date: Sat, 10 Mar 2018 10:18:19 -0800 Message-Id: <1520705944-6723-39-git-send-email-jix024@eng.ucsd.edu> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> References: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andiry Xu NOVA uses per-CPU spinlock to protect the journals. Lite journal initialization consists of two parts: for a new NOVA instance, hard_init allocates the journal pages. soft_init initializes the locks and performs journal recovery. Signed-off-by: Andiry Xu --- fs/nova/journal.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/journal.h | 2 ++ fs/nova/super.c | 15 ++++++++++++ fs/nova/super.h | 3 +++ 4 files changed, 90 insertions(+) diff --git a/fs/nova/journal.c b/fs/nova/journal.c index 0e203fa..d2578e2 100644 --- a/fs/nova/journal.c +++ b/fs/nova/journal.c @@ -340,3 +340,73 @@ void nova_commit_lite_transaction(struct super_block *sb, u64 tail, int cpu) pair->journal_head = tail; nova_flush_buffer(&pair->journal_head, CACHELINE_SIZE, 1); } + +/**************************** Initialization ******************************/ + +// Initialized DRAM journal state, validate, and recover +int nova_lite_journal_soft_init(struct super_block *sb) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + struct journal_ptr_pair *pair; + int i; + int ret = 0; + + sbi->journal_locks = kcalloc(sbi->cpus, sizeof(spinlock_t), + GFP_KERNEL); + if (!sbi->journal_locks) + return -ENOMEM; + + for (i = 0; i < sbi->cpus; i++) + spin_lock_init(&sbi->journal_locks[i]); + + for (i = 0; i < sbi->cpus; i++) { + pair = nova_get_journal_pointers(sb, i); + if (pair->journal_head == pair->journal_tail) + continue; + + /* Ensure all entries are genuine */ + ret = nova_check_journal_entries(sb, pair); + if (ret) { + nova_err(sb, "Journal %d checksum failure\n", i); + ret = -EINVAL; + break; + } + + ret = nova_recover_lite_journal(sb, pair); + } + + return ret; +} + +/* Initialized persistent journal state */ +int nova_lite_journal_hard_init(struct super_block *sb) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + struct nova_inode_info_header sih; + struct journal_ptr_pair *pair; + unsigned long blocknr = 0; + int allocated; + int i; + u64 block; + + sih.ino = NOVA_LITEJOURNAL_INO; + sih.i_blk_type = NOVA_BLOCK_TYPE_4K; + + for (i = 0; i < sbi->cpus; i++) { + pair = nova_get_journal_pointers(sb, i); + + allocated = nova_new_log_blocks(sb, &sih, &blocknr, 1, + ALLOC_INIT_ZERO, ANY_CPU, ALLOC_FROM_HEAD); + nova_dbg_verbose("%s: allocate log @ 0x%lx\n", __func__, + blocknr); + if (allocated != 1 || blocknr == 0) + return -ENOSPC; + + block = nova_get_block_off(sb, blocknr, NOVA_BLOCK_TYPE_4K); + pair->journal_head = pair->journal_tail = block; + nova_flush_buffer(pair, CACHELINE_SIZE, 0); + } + + PERSISTENT_BARRIER(); + return nova_lite_journal_soft_init(sb); +} diff --git a/fs/nova/journal.h b/fs/nova/journal.h index 2259880..6e3a528 100644 --- a/fs/nova/journal.h +++ b/fs/nova/journal.h @@ -50,5 +50,7 @@ u64 nova_create_rename_transaction(struct super_block *sb, u64 nova_create_logentry_transaction(struct super_block *sb, void *entry, enum nova_entry_type type, int cpu); void nova_commit_lite_transaction(struct super_block *sb, u64 tail, int cpu); +int nova_lite_journal_soft_init(struct super_block *sb); +int nova_lite_journal_hard_init(struct super_block *sb); #endif diff --git a/fs/nova/super.c b/fs/nova/super.c index d73c202..216d396 100644 --- a/fs/nova/super.c +++ b/fs/nova/super.c @@ -379,6 +379,11 @@ static struct nova_inode *nova_init(struct super_block *sb, nova_init_blockmap(sb, 0); + if (nova_lite_journal_hard_init(sb) < 0) { + nova_err(sb, "Lite journal hard initialization failed\n"); + return ERR_PTR(-EINVAL); + } + if (nova_init_inode_inuse_list(sb) < 0) return ERR_PTR(-EINVAL); @@ -598,6 +603,12 @@ static int nova_fill_super(struct super_block *sb, void *data, int silent) goto out; } + if (nova_lite_journal_soft_init(sb)) { + retval = -EINVAL; + nova_err(sb, "Lite journal initialization failed\n"); + goto out; + } + blocksize = le32_to_cpu(sbi->nova_sb->s_blocksize); nova_set_blocksize(sb, blocksize); @@ -647,6 +658,9 @@ static int nova_fill_super(struct super_block *sb, void *data, int silent) nova_delete_free_lists(sb); + kfree(sbi->journal_locks); + sbi->journal_locks = NULL; + kfree(sbi->inode_maps); sbi->inode_maps = NULL; @@ -745,6 +759,7 @@ static void nova_put_super(struct super_block *sb) kfree(sbi->zeroed_page); nova_dbgmask = 0; + kfree(sbi->journal_locks); for (i = 0; i < sbi->cpus; i++) { inode_map = &sbi->inode_maps[i]; diff --git a/fs/nova/super.h b/fs/nova/super.h index 9772d2f..56a840e 100644 --- a/fs/nova/super.h +++ b/fs/nova/super.h @@ -119,6 +119,9 @@ struct nova_sb_info { /* ZEROED page for cache page initialized */ void *zeroed_page; + /* Per-CPU journal lock */ + spinlock_t *journal_locks; + /* Per-CPU inode map */ struct inode_map *inode_maps; -- 2.7.4