From patchwork Sat Mar 10 18:18:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273917 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 CD619601A0 for ; Sat, 10 Mar 2018 18:21:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC53628BAE for ; Sat, 10 Mar 2018 18:21:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B111C29735; Sat, 10 Mar 2018 18:21:21 +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 63F6728BAE for ; Sat, 10 Mar 2018 18:21:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 14A7522631460; Sat, 10 Mar 2018 10:14:57 -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 6A0A722631477 for ; Sat, 10 Mar 2018 10:14:54 -0800 (PST) Received: by mail-pf0-x242.google.com with SMTP id q13so2624170pff.0 for ; Sat, 10 Mar 2018 10:21:13 -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=hZF1cWDIOz0NFHRnLo36miIppk5+DU2x8NDIOS8sv9w=; b=CmjLWFfie7TvqzIdfo+MnDEwcwf4tntE+UDDTssyo7+T9kpPFGAOqn6Rd7OqA/GAGI Rf4KXgIkm7ukUA+HXm1vL1KbmIrRQs1oCZqZZEy2OskQA2IjtemqI9fk1p0KPnvUXCRW iiaEWHTJyYnL8dHA1bVM5PiVdLlZdCZ567qOQ= 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=hZF1cWDIOz0NFHRnLo36miIppk5+DU2x8NDIOS8sv9w=; b=d9XXPFPkYfX+gyg+UqVQmMvEHUv8QS2/d62NE78dcYjVq5hYPDDrTpa5m2XixM7Cxz ydGsSZdj66kaCa7rhwA1rH5EB8dcufmv45w7AaEngFi6b2UZIy4STifMV5G1RgRPJYKX 2hIXk4CrD2oxGEeGRTY1O0bxr0XpCWJH5oVV/7KWi1Wy1Mc3+1ppG6t1NhdYbBOcTHZK CI8Lj/NXy7SCsc4fpvjqSgVQxyiO6Vq1IrS2+owGBwpqYLpjMILIKUnz5HUt/pGD8JiH vLejPOoU7vPgD6SHbcaKiKOHSg4b8y+u1PzTURgQ7m2DDhK17IA/CbkNzlwC+PiE/bO1 9Obg== X-Gm-Message-State: AElRT7EMu4Z+xy3T6AVRfKK/HuEZEgVyzUhSDSRsdJUOHO6/JZCybKyX MeDSK/FVK+tu2BRqR4allSUBeg== X-Google-Smtp-Source: AG47ELvzbtaIoV7CjFuiddHq6NcbUD1RntixR4/hI433Y7CMYtWZfmXWW1EBRjzGm8IM5Z15tjJymA== X-Received: by 10.101.97.139 with SMTP id c11mr2239921pgv.447.1520706072850; Sat, 10 Mar 2018 10:21:12 -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.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:12 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 47/83] Dir: Add initial dentries when initializing a directory inode log. Date: Sat, 10 Mar 2018 10:18:28 -0800 Message-Id: <1520705944-6723-48-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 For root directory and newly created directory via mkdir(), we append . and .. dentries to the directory inode log. Signed-off-by: Andiry Xu --- fs/nova/dir.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/nova.h | 2 ++ fs/nova/super.c | 5 ++++ 3 files changed, 89 insertions(+) diff --git a/fs/nova/dir.c b/fs/nova/dir.c index 5bea57a..377d2da 100644 --- a/fs/nova/dir.c +++ b/fs/nova/dir.c @@ -139,3 +139,85 @@ void nova_delete_dir_tree(struct super_block *sb, NOVA_END_TIMING(delete_dir_tree_t, delete_time); } + +/* ========================= Entry operations ============================= */ + +static unsigned int nova_init_dentry(struct super_block *sb, + struct nova_dentry *de_entry, u64 self_ino, u64 parent_ino, + u64 epoch_id) +{ + void *start = de_entry; + struct nova_inode_log_page *curr_page = start; + unsigned int length; + unsigned short de_len; + + de_len = NOVA_DIR_LOG_REC_LEN(1); + memset(de_entry, 0, de_len); + de_entry->entry_type = DIR_LOG; + de_entry->epoch_id = epoch_id; + de_entry->trans_id = 0; + de_entry->ino = cpu_to_le64(self_ino); + de_entry->name_len = 1; + de_entry->de_len = cpu_to_le16(de_len); + de_entry->mtime = timespec_trunc(current_kernel_time(), + sb->s_time_gran).tv_sec; + + de_entry->links_count = 1; + strncpy(de_entry->name, ".\0", 2); + nova_persist_entry(de_entry); + + length = de_len; + + de_entry = (struct nova_dentry *)((char *)de_entry + length); + de_len = NOVA_DIR_LOG_REC_LEN(2); + memset(de_entry, 0, de_len); + de_entry->entry_type = DIR_LOG; + de_entry->epoch_id = epoch_id; + de_entry->trans_id = 0; + de_entry->ino = cpu_to_le64(parent_ino); + de_entry->name_len = 2; + de_entry->de_len = cpu_to_le16(de_len); + de_entry->mtime = timespec_trunc(current_kernel_time(), + sb->s_time_gran).tv_sec; + + de_entry->links_count = 2; + strncpy(de_entry->name, "..\0", 3); + nova_persist_entry(de_entry); + length += de_len; + + nova_set_page_num_entries(sb, curr_page, 2, 1); + + nova_flush_buffer(start, length, 0); + return length; +} + +/* Append . and .. entries */ +int nova_append_dir_init_entries(struct super_block *sb, + struct nova_inode *pi, u64 self_ino, u64 parent_ino, u64 epoch_id) +{ + struct nova_inode_info_header sih; + int allocated; + u64 new_block; + unsigned int length; + struct nova_dentry *de_entry; + + sih.ino = self_ino; + sih.i_blk_type = NOVA_DEFAULT_BLOCK_TYPE; + + allocated = nova_allocate_inode_log_pages(sb, &sih, 1, &new_block, + ANY_CPU, 0); + if (allocated != 1) { + nova_err(sb, "ERROR: no inode log page available\n"); + return -ENOMEM; + } + + pi->log_tail = pi->log_head = new_block; + + de_entry = (struct nova_dentry *)nova_get_block(sb, new_block); + + length = nova_init_dentry(sb, de_entry, self_ino, parent_ino, epoch_id); + + nova_update_tail(pi, new_block + length); + + return 0; +} diff --git a/fs/nova/nova.h b/fs/nova/nova.h index 3890479..a94f44d 100644 --- a/fs/nova/nova.h +++ b/fs/nova/nova.h @@ -458,6 +458,8 @@ void nova_delete_dir_tree(struct super_block *sb, struct nova_dentry *nova_find_dentry(struct super_block *sb, struct nova_inode *pi, struct inode *inode, const char *name, unsigned long name_len); +int nova_append_dir_init_entries(struct super_block *sb, + struct nova_inode *pi, u64 self_ino, u64 parent_ino, u64 epoch_id); /* rebuild.c */ int nova_rebuild_inode(struct super_block *sb, struct nova_inode_info *si, diff --git a/fs/nova/super.c b/fs/nova/super.c index 216d396..1e67062 100644 --- a/fs/nova/super.c +++ b/fs/nova/super.c @@ -349,6 +349,7 @@ static struct nova_inode *nova_init(struct super_block *sb, struct nova_inode *root_i, *pi; struct nova_super_block *super; struct nova_sb_info *sbi = NOVA_SB(sb); + u64 epoch_id; timing_t init_time; NOVA_START_TIMING(new_init_t, init_time); @@ -415,6 +416,10 @@ static struct nova_inode *nova_init(struct super_block *sb, nova_flush_buffer(root_i, sizeof(*root_i), false); + epoch_id = nova_get_epoch_id(sb); + nova_append_dir_init_entries(sb, root_i, NOVA_ROOT_INO, + NOVA_ROOT_INO, epoch_id); + PERSISTENT_MARK(); PERSISTENT_BARRIER(); nova_info("NOVA initialization finish\n");