Received: by 10.223.185.111 with SMTP id b44csp1645318wrg; Sat, 10 Mar 2018 10:29:13 -0800 (PST) X-Google-Smtp-Source: AG47ELuUXIKoU6ZMhtl0gx+3xEyCTrszw3DzS8MMEI2PFOqP5/pcy4tqdwPMATp7iTnj4ZvvjOVy X-Received: by 10.101.69.4 with SMTP id n4mr2242698pgq.184.1520706553452; Sat, 10 Mar 2018 10:29:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520706553; cv=none; d=google.com; s=arc-20160816; b=0EeIzN7RHGIzkuqCFbDVOqUpw3OyqH5VtoIBeW+ae/zXMo84xPAWOYNDEQQOeGXOKV 227acC+7N9GXC/05u+O2x2Be7shHm6AHWeJrPe1WgYRArDFI1sgWKeVqD1RDsZmOmoxA c0+6bb8Y4mh3AO8TzD7B8yRiiA8Ko+LDcouLVDEj2kWN99t4RXJaLyJ6seLb5IwkQXLH udNjCcAUunu6frBRLFfLWsoPVjtwzAQmFLMlsd6M3I5DSehiFPc9GKD1Mo9SQry78Yqb ttV1jJU2pGx0TOtp8s+7MJE29Rbyzl0oJomQfqvaqi7K104bnL5MNcAZbKBUD/yccyEW 7KnQ== 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=GoyUktXpPYMRC43DoQOX8LhCEPRw7HigWWSWP49LnQ0=; b=wRE6yMdq0W4C9UuLPGQ6IzC4Bzx4CHxL/ZqoevjNzuD7UHa+ivPVZOkxitBGLXG64u drOJ2lR3jrMxWJd3Nn4m/FMHADGypzDiwZ7rFU/eD/yda8otp7uOfFT/t25laYpEXvU8 Nn/O5ZrCWvvJDkpoYdNEKC6ccGKCWMMqoosA9Mdtba87xNFVy7nORoFVOp5V81mKUeUU WQUUzqTjWWmoeFWXn8tqmIY934OA3YSAX4xRnTo07RYYJD76LN+Y6YoUwmTKMVQ+XBUW WkkaCc038lca4t1phNz5AL2W+a2vmt2Npq32gqyIVCoLLZbJsBkVXyQUWeZd1uiYvLsU 7wgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=gt5pwiz8; 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 y15si2964826pfe.184.2018.03.10.10.28.59; Sat, 10 Mar 2018 10:29:13 -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=gt5pwiz8; 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 S1751743AbeCJS2C (ORCPT + 99 others); Sat, 10 Mar 2018 13:28:02 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45315 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932199AbeCJSVh (ORCPT ); Sat, 10 Mar 2018 13:21:37 -0500 Received: by mail-pf0-f193.google.com with SMTP id h19so2612884pfd.12 for ; Sat, 10 Mar 2018 10:21:37 -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=GoyUktXpPYMRC43DoQOX8LhCEPRw7HigWWSWP49LnQ0=; b=gt5pwiz8gsdHr7IzCByYHg6aa1LxeSJuwyDsYFD0SNZRpQvcTCGJ4T5YsXfTtw10rv XWbV/igx/Goy2IEUAsAGsA/IMEFRRfBkq9fu707bx2yBOUIbGrKfdImfYLINOXBGUULI ucScvLIWsgneq5wY7RJkMFKUlDJJAOzrUYiTI= 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=GoyUktXpPYMRC43DoQOX8LhCEPRw7HigWWSWP49LnQ0=; b=J5NTfTK81gNFzc3N49930sx6itFrw/Q7Q3rUD0k3B/TuXQUHQ8kIiwvReWC/3bDSBx ElYw4okO1VSOuGmHOBoulx55l9fviZ9hHRwvy/5PpaQ1RwtkTh2Na2i/BkErcROJhgnE 9Ht7tLVmIgpmLV3teGfspNmbuK9Unh7wGHIVrPpPEQ816Q2ByRsdKYmfkfdVS7qHkbed 2TVT0zsqGXbpN9PnOMR8k1z0XHpt4C1qek+fn3WxYrInBLP2k0hMoqAFXre+sUmH3Owv /XMD4GQLS/TszHo7N9q9YJXTVcx/l1w1SJaykMbVxfgv32WM1MLH+kkVEaWX+kCwAms2 JHfg== X-Gm-Message-State: AElRT7H2xNWxW330eOFJhJbgMYD8SZkdkHtDy1yKDcK8RHS44wUGHQ25 IuRPARAtMVFshFfh6Po6YN+Dhw== X-Received: by 10.101.90.140 with SMTP id c12mr2198949pgt.56.1520706097206; Sat, 10 Mar 2018 10:21:37 -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.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:36 -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 67/83] Dax: commit list of file write items to log. Date: Sat, 10 Mar 2018 10:18:48 -0800 Message-Id: <1520705944-6723-68-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 Given a list of file write items, NOVA commits them by appending each file write entry to the log, and then updates the radix tree to point to these new entries, and updates log tail pointer to commit all the writes atomically. If the items are allocated on heap, free them on success. Signed-off-by: Andiry Xu --- fs/nova/Makefile | 2 +- fs/nova/dax.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/nova.h | 5 +++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 fs/nova/dax.c diff --git a/fs/nova/Makefile b/fs/nova/Makefile index 468ed6f..7f851f2 100644 --- a/fs/nova/Makefile +++ b/fs/nova/Makefile @@ -4,5 +4,5 @@ obj-$(CONFIG_NOVA_FS) += nova.o -nova-y := balloc.o bbuild.o dir.o file.o inode.o journal.o log.o namei.o\ +nova-y := balloc.o bbuild.o dax.o dir.o file.o inode.o journal.o log.o namei.o\ rebuild.o stats.o super.o diff --git a/fs/nova/dax.c b/fs/nova/dax.c new file mode 100644 index 0000000..1669dc0 --- /dev/null +++ b/fs/nova/dax.c @@ -0,0 +1,112 @@ +/* + * BRIEF DESCRIPTION + * + * DAX file operations. + * + * Copyright 2015-2016 Regents of the University of California, + * UCSD Non-Volatile Systems Lab, Andiry Xu + * Copyright 2012-2013 Intel Corporation + * Copyright 2009-2011 Marco Stornelli + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include "nova.h" +#include "inode.h" + + +static int nova_reassign_file_tree(struct super_block *sb, + struct nova_inode_info_header *sih, u64 begin_tail, u64 end_tail) +{ + void *addr; + struct nova_file_write_entry *entry; + u64 curr_p = begin_tail; + size_t entry_size = sizeof(struct nova_file_write_entry); + + while (curr_p && curr_p != end_tail) { + if (is_last_entry(curr_p, entry_size)) + curr_p = next_log_page(sb, curr_p); + + if (curr_p == 0) { + nova_err(sb, "%s: File inode %lu log is NULL!\n", + __func__, sih->ino); + return -EINVAL; + } + + addr = (void *) nova_get_block(sb, curr_p); + entry = (struct nova_file_write_entry *) addr; + + if (nova_get_entry_type(entry) != FILE_WRITE) { + nova_dbg("%s: entry type is not write? %d\n", + __func__, nova_get_entry_type(entry)); + curr_p += entry_size; + continue; + } + + nova_assign_write_entry(sb, sih, entry, true); + curr_p += entry_size; + } + + return 0; +} + +int nova_commit_writes_to_log(struct super_block *sb, struct nova_inode *pi, + struct inode *inode, struct list_head *head, unsigned long new_blocks, + int free) +{ + struct nova_inode_info *si = NOVA_I(inode); + struct nova_inode_info_header *sih = &si->header; + struct nova_file_write_item *entry_item, *temp; + struct nova_inode_update update; + unsigned int data_bits; + u64 begin_tail = 0; + int ret = 0; + + if (list_empty(head)) + return 0; + + update.tail = 0; + + list_for_each_entry(entry_item, head, list) { + ret = nova_append_file_write_entry(sb, pi, inode, + entry_item, &update); + if (ret) { + nova_dbg("%s: append inode entry failed\n", __func__); + return -ENOSPC; + } + + if (begin_tail == 0) + begin_tail = update.curr_entry; + } + + /* Update file tree */ + ret = nova_reassign_file_tree(sb, sih, begin_tail, update.tail); + if (ret < 0) { + /* FIXME: Need to rebuild the tree */ + return ret; + } + + data_bits = blk_type_to_shift[sih->i_blk_type]; + sih->i_blocks += (new_blocks << (data_bits - sb->s_blocksize_bits)); + + inode->i_blocks = sih->i_blocks; + + nova_update_inode(sb, inode, pi, &update); + NOVA_STATS_ADD(inplace_new_blocks, 1); + + sih->trans_id++; + + if (free) { + list_for_each_entry_safe(entry_item, temp, head, list) + nova_free_file_write_item(entry_item); + } + + return ret; +} diff --git a/fs/nova/nova.h b/fs/nova/nova.h index b2831f6..dcda02a 100644 --- a/fs/nova/nova.h +++ b/fs/nova/nova.h @@ -464,6 +464,11 @@ nova_get_blocknr(struct super_block *sb, u64 block, unsigned short btype) /* ============== Function prototypes ================= */ /* ====================================================== */ +/* dax.c */ +int nova_commit_writes_to_log(struct super_block *sb, struct nova_inode *pi, + struct inode *inode, struct list_head *head, unsigned long new_blocks, + int free); + /* dir.c */ extern const struct file_operations nova_dir_operations; int nova_insert_dir_radix_tree(struct super_block *sb, -- 2.7.4