Received: by 10.223.185.111 with SMTP id b44csp1649007wrg; Sat, 10 Mar 2018 10:34:17 -0800 (PST) X-Google-Smtp-Source: AG47ELt+Wx7nNiXDggTLMCNVAEw7tIZyqPPxjj8vaiJz8rP2mj/D76ore9l+k+9wFZGbjlgVfs80 X-Received: by 10.98.153.157 with SMTP id t29mr2697838pfk.201.1520706857454; Sat, 10 Mar 2018 10:34:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520706857; cv=none; d=google.com; s=arc-20160816; b=mZ28tVUIuX6Bvzndmzkrvqh2ZY1aZ1ZAWFnN5Dl4RN5UdpfSjR9B/bMSQqU6kkPx1j EVZDxEWgWho58X6J/Wq0t71mdYCmrEiq47M5KjFmYLvoDrNvt1wY0+9vN8z4m0YydWQJ eg2ef2uF9qeWxlhnBFfEHrY/Town1GMME5lMSTwGCnALR4DuYooUuB5Q267UhWZnUJeK Xe85orM8rlcWoFjhTqVoQt4ngfrgIVNYJdros2Ww8X+BcyiBUo91BSdKB6UcW8i/4lLt rzHSCziO2mXet4/NKXXxiA9oPIoMscy8OdGVeEADMqJGJ9HsEc7Jnew3KgGPYh1jsZB4 WNvQ== 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=hZF1cWDIOz0NFHRnLo36miIppk5+DU2x8NDIOS8sv9w=; b=Es1bPOoeArYqJPqm8KgUrHLELeM1HdGY59ZmACiFbkC/CSqk4vw7YUqPFNGyx2gcE8 RWha7gVMwSJnIsZ2zz3dKwAoCWLKYLG0FRk6xHNW1rzF4rFNAFYuTek9C9eookYdS8E7 QLpAmANT9Ka6eNNMDTSWIPrhaaq96yed5Hnxw7DtFlypri6RMqM543DoB+VNUp8vDLHa fK7lyiI57Q2uFUFyVpc3XSRBOBXZx5SD5JReTTOWcQbWPt3aBflp7UVrn1svxWCu+9od Scq2A/IjH7LntOS1xA5uKBI4C48Wc9W0E2b+s/FKDZF97w6fz/XcCkCJVoay0D/+hzGT tOsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=CmjLWFfi; 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 j65si1150242pge.291.2018.03.10.10.34.03; Sat, 10 Mar 2018 10:34:17 -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=CmjLWFfi; 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 S932550AbeCJSdO (ORCPT + 99 others); Sat, 10 Mar 2018 13:33:14 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:45301 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932615AbeCJSVN (ORCPT ); Sat, 10 Mar 2018 13:21:13 -0500 Received: by mail-pf0-f196.google.com with SMTP id h19so2612637pfd.12 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=t6ZK8G0Rxsu3FPlAshSFCVvAfDQR03cuWptsF2m9ktwsK7Hh0pgZWLJfJb2LR4g+ay cVlDGVSosuHsSarkXm4YFF6R1cnn0FygOF+7hEDLI1NIOhQC3OH+8QCkLWA8zCt5DIcd tYLBpnwICpXUBTZZl9Qn56CY6FMTjgy0bIPvNjyHFasK/6RBGJBk+QmGVlLaK0Wx93mp E+bNmKSoNUz0Li05ruxcp82whJ3jcG8kI0WIueiAsQ3xB1vkrUpkFYU77vJZOh6CXmQw auI/9JAuVAxoetGtsc/UHJ9RSjzPqK+0Gj9arv/hmX6DH06UqqjsBomysKDl/n/s3327 aACw== X-Gm-Message-State: AElRT7Eq9ZTgRMJhb4UN6EMoTVVw8UstkW7iX+ZZ0RS0+H+BNL1KY3d1 BlH7Hlq1HnmQ9QI8ST7YgMS7rg== 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 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 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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"); -- 2.7.4