From patchwork Sat Mar 10 18:18:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10274169 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 1DD9F60594 for ; Sat, 10 Mar 2018 18:35:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B07C290FA for ; Sat, 10 Mar 2018 18:35:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3F16299D6; Sat, 10 Mar 2018 18:35:34 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64613290FA for ; Sat, 10 Mar 2018 18:35:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751191AbeCJSfc (ORCPT ); Sat, 10 Mar 2018 13:35:32 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34924 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932531AbeCJSVE (ORCPT ); Sat, 10 Mar 2018 13:21:04 -0500 Received: by mail-pf0-f194.google.com with SMTP id y186so2626895pfb.2 for ; Sat, 10 Mar 2018 10:21:04 -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=qBQ6048CqesP6dcgrB7lEyTDvrECsJjVvsw3N8Rs0lLlx7TX6YWdOqZshyXICrz6qn vL/j1f6+tAM3N80a8c2KqaSpwha5l0RMtk5nltSD4KjILoxlXWYRha7AHcC53TpEuXAS x7+cQFxOULgME7VLXKQTyIZaWtXSuPbA4D/TdAGCtkKRfnYTImD8Z8IF6QF37pA4ufH3 10EnL5ZUYuT0SJvml5VYWs8HoP+GSf+f5/5+EK+HzJ+osd1rnFv+iLDob8225e0YowmS 45EFWB0EKVF59DUi2KRt5fgFXY+M9It1OWVShcGpZjykhlKGkhXa/gQeJpGqbDMm6h9i ohzQ== X-Gm-Message-State: AElRT7F0WujeEF8ASe99y+ZzrcQ3LHk9z4VtIWK127osJEj6/zinDulX s8AQRrJmH4F6e71rJqdn2k4l0YvI/Ts= X-Google-Smtp-Source: AG47ELuWpUlBGY4tAjWecu5oxHK4i4Q+qMeB87WoH42wXKqK2qTASCCskfmjNgIfY4X96elL6k92Gw== 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);