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: 10273895 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 2AC6C602BD for ; Sat, 10 Mar 2018 18:21:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A0DE28BAE for ; Sat, 10 Mar 2018 18:21:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EB8229735; Sat, 10 Mar 2018 18:21:11 +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 AA15228BAE for ; Sat, 10 Mar 2018 18:21:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2F3CE22568620; Sat, 10 Mar 2018 10:14:47 -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::244; helo=mail-pf0-x244.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::244]) (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 1FDF5225892DA for ; Sat, 10 Mar 2018 10:14:45 -0800 (PST) Received: by mail-pf0-x244.google.com with SMTP id h19so2612562pfd.12 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=Y6CRCXnC3KxMMXYxSC/5+0i3Zvy17emvt+neuHIMeRqdIybuWcQyiD11Mq4c7SMuEF YQRy/SeSeyeA8C9pIM+g1iMhFIhOklE6kyae/pdKMbaTYC/8n70XRk2QA2X/qQcWNHoV cJKrjkKIr8oupl+e1mNke6dXL3VqyBvmAa2dodk4BOoVJMnXZg1qFHYZ4mFVzBNbcG/O 0bKdM7NJedSt4emrChRvfh+4O8W+cnOcW2euZXNbmYiFIJrt5701bFnW5NOWTrYlv7LJ QJVT+S9vWc48Xl8SavK9rCkBq+oYyZQp2w6PRUiBQmjcu0O2MUSk8Wmww79ATaVOtZRZ KbuA== X-Gm-Message-State: AElRT7G1fTs1EjhowL4JqAM56BAnRKoyMr/V6jmWPHh+RJDJCQMc/KvI nFlXmEpM/vn65t0ms7VygykbuA== 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 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> 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 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);