Received: by 10.223.185.111 with SMTP id b44csp1650596wrg; Sat, 10 Mar 2018 10:36:38 -0800 (PST) X-Google-Smtp-Source: AG47ELvnyOJl9Udz4j/7oExMoRSEukXUpYWZ7MhtOkSJLgEEjGalFIDI9M3PfZ78mORR/yukE9Cm X-Received: by 10.98.58.3 with SMTP id h3mr2696944pfa.178.1520706998211; Sat, 10 Mar 2018 10:36:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520706998; cv=none; d=google.com; s=arc-20160816; b=M9hjjzqoWPif0OfOSK4+cM412eoTYvw66uRGkau0/EetNoWO1yqiqaFtta+uYYHMyf s6FNORZHnVBpXCwqgQs1bIZhYDBIbw60LMZSxRvXQncMMPgjFfFlhsy2yZWMB4MUavcp 7XEyJpssfOb6PTa0cKahOorWWhbpmHmyt5S3l/GXHnGIH9+Cg1E2VpcQydYxT/0S9DOQ UAEsrRHd8yd0n00mD7jH/PXOvQpqG2/jwTxTLMEOkSd0D2H0sSBxLllJuEHJQ6uuCdlF pqkahImjqaaYSK+m3INDWiphiyw2FFFdPV6gQRlFSQauatNegc646K6lBBwQ/3U2ToYk snIw== 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=CjGg1ANCRaMUZHjZ5b41IHNjP+jAduHMKwXNPkJO4pI=; b=Bv1+4ja9t90DrczEzuCDBG2lCiIw+XYuEMErhE8bybTxFrFCMljbstT9n9Cydpc/E5 XGKR68DNWShwuamEA4GvRCeRfx4b9LU8ZyVLiSuQ3LNwBzxF1xV+ePBKvNY/VTwBXN/N EAriwZoFTFDnl2ZlZzF1OQIyA/Y6ScgiViaw1G7NlY7IDgLhuaGQd+QzITNPqsumcarH TOnrhQeF3wUZ/kJbVZDEu8mr9qBMvb5IbfEGyzGGBeN2smqfBxEutDBHzq/PF9PHpCLI Z/BUjgpdHT3aqALgRZckp32S/wAFqm2cddpxa3OfjnSKgi6Xu+2rCZJ3/bWo8eL1GVeE wEgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=WWbVLnUM; 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 33-v6si3082500ple.367.2018.03.10.10.36.23; Sat, 10 Mar 2018 10:36:38 -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=WWbVLnUM; 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 S932600AbeCJSfg (ORCPT + 99 others); Sat, 10 Mar 2018 13:35:36 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:37768 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932499AbeCJSVE (ORCPT ); Sat, 10 Mar 2018 13:21:04 -0500 Received: by mail-pf0-f194.google.com with SMTP id h11so2617610pfn.4 for ; Sat, 10 Mar 2018 10:21:03 -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=CjGg1ANCRaMUZHjZ5b41IHNjP+jAduHMKwXNPkJO4pI=; b=WWbVLnUMhPV5zsWyhoy6sLq0qeqWisbQhpLN1eIYuORMhlHFsfCTTkekIjF96PNL1s 8n2oE2UXBmch1bWughcZq3qcBRP3wjseLBIDXy6BoxSIGcaugYiPWCL9r4LHbsYEq6FZ gnzbAbVPnfxPa2T/8nuO8WOYiIZDuRi4ewAyw= 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=CjGg1ANCRaMUZHjZ5b41IHNjP+jAduHMKwXNPkJO4pI=; b=BsskoKiK4OiawoK4NP4ejjg80H8CkVPdSNFF0DnrekCnR9nq22aFKjLMHHM80lj4+f x+U24jPdxzJp1Ag37Dws44agcRJB2b8HlsZUHm7HuPUZGk0qcingmctcXkEjJ2fLYECA JGaa6t9MEcA2DPImJ5F8ppTaRDuOplc5SZDVn3FBgqi3x+Zq028S+fyrTIv8fhzqGU2Q 57peUguEPaWw0Wf6FCrm+pENG19YlfMFBofJY03Nagn5QJTOqyc6MiTzU05HAq6BaAn0 WFBfJ9ETCaZzbU8ukL/mUMm5o0EkjVwVozGYb6fz/0U4bhSSh5AgrBPemt57STBZl/2A nshA== X-Gm-Message-State: AElRT7G3Hp0a6CGs8vzGI0y6VNpSe/wlg0zxAL7xYuFmEJqWTNyES1Et BsIQRseCRio+urgBmmiqPUg15A== X-Received: by 10.98.238.2 with SMTP id e2mr2686337pfi.68.1520706063562; Sat, 10 Mar 2018 10:21:03 -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.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:02 -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 39/83] Log operation: dentry append. Date: Sat, 10 Mar 2018 10:18:20 -0800 Message-Id: <1520705944-6723-40-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 performs atomic log appending by first appending the entry to the tail of the log, and then atomically update the log tail pointer. Signed-off-by: Andiry Xu --- fs/nova/log.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/log.h | 4 ++ 2 files changed, 166 insertions(+) diff --git a/fs/nova/log.c b/fs/nova/log.c index f01b7c8..13f9597 100644 --- a/fs/nova/log.c +++ b/fs/nova/log.c @@ -20,6 +20,168 @@ #include "inode.h" #include "log.h" +static int nova_update_old_dentry(struct super_block *sb, + struct inode *dir, struct nova_dentry *dentry, + struct nova_log_entry_info *entry_info) +{ + unsigned short links_count; + int link_change = entry_info->link_change; + u64 addr; + + dentry->epoch_id = entry_info->epoch_id; + dentry->trans_id = entry_info->trans_id; + /* Remove_dentry */ + dentry->ino = cpu_to_le64(0); + dentry->invalid = 1; + dentry->mtime = cpu_to_le32(dir->i_mtime.tv_sec); + + links_count = cpu_to_le16(dir->i_nlink); + if (links_count == 0 && link_change == -1) + links_count = 0; + else + links_count += link_change; + dentry->links_count = cpu_to_le16(links_count); + + addr = nova_get_addr_off(NOVA_SB(sb), dentry); + nova_inc_page_invalid_entries(sb, addr); + + nova_persist_entry(dentry); + + return 0; +} + +static int nova_update_new_dentry(struct super_block *sb, + struct inode *dir, struct nova_dentry *entry, + struct nova_log_entry_info *entry_info) +{ + struct dentry *dentry = entry_info->data; + unsigned short links_count; + int link_change = entry_info->link_change; + + entry->entry_type = DIR_LOG; + entry->epoch_id = entry_info->epoch_id; + entry->trans_id = entry_info->trans_id; + entry->ino = entry_info->ino; + entry->name_len = dentry->d_name.len; + memcpy_to_pmem_nocache(entry->name, dentry->d_name.name, + dentry->d_name.len); + entry->name[dentry->d_name.len] = '\0'; + entry->mtime = cpu_to_le32(dir->i_mtime.tv_sec); + //entry->size = cpu_to_le64(dir->i_size); + + links_count = cpu_to_le16(dir->i_nlink); + if (links_count == 0 && link_change == -1) + links_count = 0; + else + links_count += link_change; + entry->links_count = cpu_to_le16(links_count); + + /* Update actual de_len */ + entry->de_len = cpu_to_le16(entry_info->file_size); + + nova_persist_entry(entry); + + return 0; +} + +static int nova_update_log_entry(struct super_block *sb, struct inode *inode, + void *entry, struct nova_log_entry_info *entry_info) +{ + enum nova_entry_type type = entry_info->type; + + switch (type) { + case FILE_WRITE: + break; + case DIR_LOG: + if (entry_info->inplace) + nova_update_old_dentry(sb, inode, entry, entry_info); + else + nova_update_new_dentry(sb, inode, entry, entry_info); + break; + case SET_ATTR: + break; + case LINK_CHANGE: + break; + default: + break; + } + + return 0; +} + +static int nova_append_log_entry(struct super_block *sb, + struct nova_inode *pi, struct inode *inode, + struct nova_inode_info_header *sih, + struct nova_log_entry_info *entry_info) +{ + void *entry; + enum nova_entry_type type = entry_info->type; + struct nova_inode_update *update = entry_info->update; + u64 tail; + u64 curr_p; + size_t size; + int extended = 0; + + if (type == DIR_LOG) + size = entry_info->file_size; + else + size = nova_get_log_entry_size(sb, type); + + tail = update->tail; + + curr_p = nova_get_append_head(sb, pi, sih, tail, size, + MAIN_LOG, 0, &extended); + if (curr_p == 0) + return -ENOSPC; + + nova_dbg_verbose("%s: inode %lu attr change entry @ 0x%llx\n", + __func__, sih->ino, curr_p); + + entry = nova_get_block(sb, curr_p); + /* inode is already updated with attr */ + memset(entry, 0, size); + nova_update_log_entry(sb, inode, entry, entry_info); + nova_inc_page_num_entries(sb, curr_p); + update->curr_entry = curr_p; + update->tail = curr_p + size; + + entry_info->curr_p = curr_p; + return 0; +} + +int nova_append_dentry(struct super_block *sb, struct nova_inode *pi, + struct inode *dir, struct dentry *dentry, u64 ino, + unsigned short de_len, struct nova_inode_update *update, + int link_change, u64 epoch_id) +{ + struct nova_inode_info *si = NOVA_I(dir); + struct nova_inode_info_header *sih = &si->header; + struct nova_log_entry_info entry_info; + timing_t append_time; + int ret; + + NOVA_START_TIMING(append_dir_entry_t, append_time); + + entry_info.type = DIR_LOG; + entry_info.update = update; + entry_info.data = dentry; + entry_info.ino = ino; + entry_info.link_change = link_change; + entry_info.file_size = de_len; + entry_info.epoch_id = epoch_id; + entry_info.trans_id = sih->trans_id; + entry_info.inplace = 0; + + ret = nova_append_log_entry(sb, pi, dir, sih, &entry_info); + if (ret) + nova_err(sb, "%s failed\n", __func__); + + dir->i_blocks = sih->i_blocks; + + NOVA_END_TIMING(append_dir_entry_t, append_time); + return ret; +} + /* Coalesce log pages to a singly linked list */ static int nova_coalesce_log_pages(struct super_block *sb, unsigned long prev_blocknr, unsigned long first_blocknr, diff --git a/fs/nova/log.h b/fs/nova/log.h index 6b4a085..305e69b 100644 --- a/fs/nova/log.h +++ b/fs/nova/log.h @@ -364,6 +364,10 @@ static inline int is_dir_init_entry(struct super_block *sb, } +int nova_append_dentry(struct super_block *sb, struct nova_inode *pi, + struct inode *dir, struct dentry *dentry, u64 ino, + unsigned short de_len, struct nova_inode_update *update, + int link_change, u64 epoch_id); int nova_allocate_inode_log_pages(struct super_block *sb, struct nova_inode_info_header *sih, unsigned long num_pages, u64 *new_block, int cpuid, enum nova_alloc_direction from_tail); -- 2.7.4