From patchwork Sat Mar 10 18:18:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273887 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 05B98601A0 for ; Sat, 10 Mar 2018 18:21:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7C9D29106 for ; Sat, 10 Mar 2018 18:21:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC8612974F; Sat, 10 Mar 2018 18:21:05 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 04C9E28BAE for ; Sat, 10 Mar 2018 18:21:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 408FB225892B9; Sat, 10 Mar 2018 10:14:42 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c00::242; helo=mail-pf0-x242.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4095222603B1B for ; Sat, 10 Mar 2018 10:14:40 -0800 (PST) Received: by mail-pf0-x242.google.com with SMTP id h19so2612510pfd.12 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=DV+Ppx0p1u7dRJuHQ9wNevMEO+kOH7PrdzzfLGDfTznR32Dkp1tP+KQh30/x9zNeHV 9AltrYSvYwAzyHSkAns4sPipe072NOWbk3XuBJVd+LsaQZZjvyeenzU8Dbkx2mCGSSxC 32WOL27IOkwAZqobceus2Ahb0YWDwiZNBER190nf4/Y2Mh6gDUgz576qvmesphcuzNuy TDddfwDMDytTfkNNxYv/LowmPx/HGMZLXcr2P8L5yfr9fEpfWjbdMQCy+kJ/ny+5XE5Y 4ACA7V9Ne1ofmqApDF46JAd3F34vXQhaBmv71hSN61UQcIkmKDD4GJMQqww6jx6c3Ee/ CXLg== X-Gm-Message-State: AElRT7GoLKxFbTqeW+UwueQ1PYTDycJ12w0j6NrbertWGp06r5VMSyyi NJHuwVPXSqSdyMDkwzRIV7xj9Y5K1xE= X-Google-Smtp-Source: AG47ELvr6b5rRM+2Pn96KS8PoiMy9Lfyqpo9wQfF3/LGt7tMnAGlwfysw6tG5nhIm0hpXfF7oaQM4g== 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 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> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: coughlan@redhat.com, miklos@szeredi.hu, Andiry Xu , david@fromorbit.com, jack@suse.com, swanson@cs.ucsd.edu, swhiteho@redhat.com, andiry.xu@gmail.com MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP 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; +}