Received: by 10.223.185.111 with SMTP id b44csp1650543wrg; Sat, 10 Mar 2018 10:36:31 -0800 (PST) X-Google-Smtp-Source: AG47ELtic1WGObbFJ6LoFT0bSnU6sq1w7UDABsBw7MbeGJwiN+thZXkMGfvS1tQTtkmJUfvwzcGf X-Received: by 2002:a17:902:42e:: with SMTP id 43-v6mr2752364ple.186.1520706991676; Sat, 10 Mar 2018 10:36:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520706991; cv=none; d=google.com; s=arc-20160816; b=xVU9TsRIW/7V8pYV/3Pizrc4lkAXQJ/X1jA/92cKsUejHA6NgccOV6BAnkT8ihGhTv EoTzJohGZJidpMxJ2boKJoNQVSxir/eVQicr7djZV4hrccJDfn9FHIJHi+fR8uckF0Eo r/2B+vpUT8AS9yotTp+z9JxSCADPFgijtU++LBr5Ju6BM/vSmObVCiEHuVm632oApcsD gSoVZfQa1JJQcyX/FwkOw/tGbcy/0kywKTd+SGRDhhYP8DVc0Q9vRQL0yglOVgFvyarm PbQexmvplLShI0RItehp2HBChoBU78b6r1KiotMxw1E9n76firyJUDFBxW62CWz3qb5R lxZA== 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=uONmAC4tnN4IxHixyv9RrE3bCyrqnimeBLKSvIsudDY=; b=XCHyhOMwCYxLOpFGCnjAZex1Bp/Ck79zg+24x4cRhf3urx2NBOvYPH40kwZMj9bkIH TxdEVCIfKQSGCfpT8IMoiCyfvD0ZSTEI6DKjkbCTkAagSNXXH+ql7xlq5GwVmtub8dEj 3bZFhNwY1UiN1tkvqBaEsExcjLURQPtp055orN6gWYWKW5B+g0ibh4+8AUR4rsg/IJxC IxAPJJnIY5rJYq4tl0g4ALBQ8Cgd631kyqzQq2GruLxB2jntRa/b2h1JNSMbScdKqRSu Bh4sfH9hxTlLwQRWeSHLgJMrLvQjEFetQSlCiBsAAQXBhGBndFrg52bFdtVAXGS6GuTZ JKOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=Dax+P0Y6; 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 6-v6si3130488plf.263.2018.03.10.10.36.17; Sat, 10 Mar 2018 10:36:31 -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=Dax+P0Y6; 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 S932541AbeCJSVE (ORCPT + 99 others); Sat, 10 Mar 2018 13:21:04 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:44079 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932374AbeCJSU7 (ORCPT ); Sat, 10 Mar 2018 13:20:59 -0500 Received: by mail-pf0-f194.google.com with SMTP id 17so2613929pfw.11 for ; Sat, 10 Mar 2018 10:20:59 -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=uONmAC4tnN4IxHixyv9RrE3bCyrqnimeBLKSvIsudDY=; b=Dax+P0Y6f0/YisWfA0hqssp3AwCfSc7Vp0azmkz3/vmvVywYRKJOYQuw1gXn0ydfvY Mf9zWg1JDtRpuiRN+dw6nj9ZE//Ck4RKefovsF0vytUWiBGPOboOdIsOsrkl0RBYIVtT VZVTpPTA+oLIeru6p5GSCMOSLA0ucz0TqYgSo= 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=uONmAC4tnN4IxHixyv9RrE3bCyrqnimeBLKSvIsudDY=; b=Cvz48mcXeZM3RqFPnGSSlU3DrqxDkmtttpwPJmG/HMiT9k4ylw3/zZFCyNHTe85Xac Xye9vCfEsL99br5CN3K6OKSwwq8qKvagRda0jMvOwSmRc5oT/gWvvarlbOGNy+S/PYVS 8iWQ7mo/TEc+PrQF5Oc0My2yLocd0Nc357ofyFD9GjVa2DWjaKRUWMbg1apuHS3qOTne TWjL6XytOtOvvkPF99/cuq98us5nHM2/ago3nEPHd+wm0xUnhPlu+k2udi4rHqJlWGbj fZL2W8HHFSEdq+ZBN8B87TYdZUbmE4ldBfqHw+4HrhHXCzMxWGO4ruHVTA1v6UNn5NHn v8jQ== X-Gm-Message-State: AElRT7FWcf/ZQQVsOEkSCWxC9kakonedvbSPiyvLW7koDZjiWrN2cgvV K9xoTGbGA49jWIWhSIdhPdSokA== X-Received: by 10.101.89.6 with SMTP id f6mr2244266pgu.22.1520706058686; Sat, 10 Mar 2018 10:20:58 -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.20.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:20:58 -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 35/83] Journal: Lite journal helper routines. Date: Sat, 10 Mar 2018 10:18:16 -0800 Message-Id: <1520705944-6723-36-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 Signed-off-by: Andiry Xu --- fs/nova/Makefile | 2 +- fs/nova/journal.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 fs/nova/journal.c diff --git a/fs/nova/Makefile b/fs/nova/Makefile index b3638a4..4aeadea 100644 --- a/fs/nova/Makefile +++ b/fs/nova/Makefile @@ -4,4 +4,4 @@ obj-$(CONFIG_NOVA_FS) += nova.o -nova-y := balloc.o bbuild.o inode.o log.o rebuild.o stats.o super.o +nova-y := balloc.o bbuild.o inode.o journal.o log.o rebuild.o stats.o super.o diff --git a/fs/nova/journal.c b/fs/nova/journal.c new file mode 100644 index 0000000..75d590f --- /dev/null +++ b/fs/nova/journal.c @@ -0,0 +1,108 @@ +/* + * NOVA journaling facility. + * + * This file contains journaling code to guarantee the atomicity of directory + * operations that span multiple inodes (unlink, rename, etc). + * + * Copyright 2015-2016 Regents of the University of California, + * UCSD Non-Volatile Systems Lab, Andiry Xu + * Copyright 2012-2013 Intel Corporation + * Copyright 2009-2011 Marco Stornelli + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "nova.h" +#include "journal.h" + +/**************************** Lite journal ******************************/ + +static inline void +nova_print_lite_transaction(struct nova_lite_journal_entry *entry) +{ + nova_dbg("Entry %p: Type %llu, data1 0x%llx, data2 0x%llx\n, checksum %u\n", + entry, entry->type, + entry->data1, entry->data2, entry->csum); +} + +static inline int nova_update_journal_entry_csum(struct super_block *sb, + struct nova_lite_journal_entry *entry) +{ + u32 crc = 0; + + crc = nova_crc32c(~0, (__u8 *)entry, + (sizeof(struct nova_lite_journal_entry) + - sizeof(__le32))); + + entry->csum = cpu_to_le32(crc); + nova_flush_buffer(entry, sizeof(struct nova_lite_journal_entry), 0); + return 0; +} + +static inline int nova_check_entry_integrity(struct super_block *sb, + struct nova_lite_journal_entry *entry) +{ + u32 crc = 0; + + crc = nova_crc32c(~0, (__u8 *)entry, + (sizeof(struct nova_lite_journal_entry) + - sizeof(__le32))); + + if (entry->csum == cpu_to_le32(crc)) + return 0; + else + return 1; +} + +// Get the next journal entry. Journal entries are stored in a circular +// buffer. They live a 1-page circular buffer. +// +// TODO: Add check to ensure that the journal doesn't grow too large. +static inline u64 next_lite_journal(u64 curr_p) +{ + size_t size = sizeof(struct nova_lite_journal_entry); + + if ((curr_p & (PAGE_SIZE - 1)) + size >= PAGE_SIZE) + return (curr_p & PAGE_MASK); + + return curr_p + size; +} + +// Walk the journal for one CPU, and verify the checksum on each entry. +static int nova_check_journal_entries(struct super_block *sb, + struct journal_ptr_pair *pair) +{ + struct nova_lite_journal_entry *entry; + u64 temp; + int ret; + + temp = pair->journal_head; + while (temp != pair->journal_tail) { + entry = (struct nova_lite_journal_entry *)nova_get_block(sb, + temp); + ret = nova_check_entry_integrity(sb, entry); + if (ret) { + nova_dbg("Entry %p checksum failure\n", entry); + nova_print_lite_transaction(entry); + return ret; + } + temp = next_lite_journal(temp); + } + + return 0; +} -- 2.7.4