Received: by 10.223.185.111 with SMTP id b44csp1647216wrg; Sat, 10 Mar 2018 10:31:42 -0800 (PST) X-Google-Smtp-Source: AG47ELsXHUZw/TC37rL1TESXNcTqKDBoQmG0W3NK9viRrfd6asFAb2rktudNFLcHV8erKJhQlmAU X-Received: by 10.98.157.18 with SMTP id i18mr2700841pfd.62.1520706702650; Sat, 10 Mar 2018 10:31:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520706702; cv=none; d=google.com; s=arc-20160816; b=RI9q5sGT76bsHnp4N7QjxdyseqmsRv02cZTgVtT1hNgt25lRm0VFKK8IarC05fl6Fq 2W+q8twz0d9+GEwiYX0RqpKbR1HehSJ2pLsQwYjFkIpVwdmkJxg8g0kN7eZQg1c7hSk1 hCw6hjdjqfQd3oxBcX4jFm2I4bkyN1dMPBr5xIodSL0ao06H6J+oSdZimGiFlj/umjkm Op83jxCjHv4jwcAIv4MbNr0bx+0XmDU+Oul/HYTTX8ykYjUM5tt6VhQLqoqiRjKWfWaa z17qWtpYSJ82zpY3pHgEsHn/rIRRWl6wUuOcZTiVpDxWlwg5OI1cZi8PsM2Si2eGI5MK cFuw== 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=B7XjMReA/LR9l06KEBXXUPquDTtVQBJq5hHgk6XC1yk=; b=rGoaK/pXxuUluYoqUbxZT4512PaUi2YZ94vXdrsX3ZJhHXzX7gMChudETBt8d5uXyv AhXj2z2cZGLBMZJvjMSEXNbXHjnl21u2RlzgxaArjvzghxCIabvWh7yY6lhXw/Q+SjIE kQHHbs1LGDR25XMAsIBTdTTAm97+h7WXuR0RxHN2r924DWVBGeDcmKNRO4exSqg5fBtk mzX5lMs4QOsH7Ux7U7Jy9JhlMM4SAY0pdAeK/fJRoU/xgpypptnKcbzhnPYnosLrbawo 16hw2h0bBlaLjEJ3zXhk8GpIgjZdw6h5itkvvh94p2i8nUsWBBG09liqNmE6PAEdOW2t J1gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=Sel17QKO; 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 x13si2625081pgc.75.2018.03.10.10.31.27; Sat, 10 Mar 2018 10:31:42 -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=Sel17QKO; 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 S932733AbeCJSV2 (ORCPT + 99 others); Sat, 10 Mar 2018 13:21:28 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:38868 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932677AbeCJSVY (ORCPT ); Sat, 10 Mar 2018 13:21:24 -0500 Received: by mail-pl0-f67.google.com with SMTP id m22-v6so7032783pls.5 for ; Sat, 10 Mar 2018 10:21:24 -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=B7XjMReA/LR9l06KEBXXUPquDTtVQBJq5hHgk6XC1yk=; b=Sel17QKOQFnCchagL+uScmvb8+GzjdABTN623pe1+IqnFY+HivcNM2OC2aU6oKbtBa O8LDxTThkcOBXaw98A49VxSPrgORa7IpEAeDf9WPTPaDxiky8NcMPWr9/32CRr/+le/6 Jc4TqfUP8JPYb4sXzWHDppWKUjDKd28bW2DIo= 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=B7XjMReA/LR9l06KEBXXUPquDTtVQBJq5hHgk6XC1yk=; b=i3P/ewo0EaFKX2uDpkUFNQw13L+7tZxw8COjDUT27SEI9O/XXx6JcWUj5GTEhFjMpb ItanChSjIy5WdVRIIhXZuGDSCVq/HT72n1c1lvRnnSRGq6M1TtoJMm1VdLvapSjxARZ2 +Xsy80T1LcgIlKh/Lyc9n9BiVJh0VUjqr+OjTmZkwR69caoNhghj9Jt5BTUKDwcWeMbV f+O4SiaZdKYq9GeC8GtL3itlLEFSbHdr+69DxljMWzD3Q+ne9o0aNRClzOUphj+03tw+ /bx4uHQmzMUsA908nVPRPJGMt4sPqTVleXQFe3QrW8/m7wpfRWbK9zYLtAkpQ/IeLONt evKA== X-Gm-Message-State: AElRT7FoPCHOuwFa7CvCpqGR2XnrcHUSWTyo4g8CAYiy/t5tAmzFyOuW Wgr4TCATv5AbQ96bVqTf3vuWRw== X-Received: by 2002:a17:902:b943:: with SMTP id h3-v6mr2808861pls.45.1520706083675; Sat, 10 Mar 2018 10:21:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:23 -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 56/83] Namei: link and unlink. Date: Sat, 10 Mar 2018 10:18:37 -0800 Message-Id: <1520705944-6723-57-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 link change operations, NOVA appends a link change entry to the affected inode's log, and uses lite transaction to atomically commit changes to multiple logs. Signed-off-by: Andiry Xu --- fs/nova/namei.c | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/fs/nova/namei.c b/fs/nova/namei.c index a95b2fe..360d716 100644 --- a/fs/nova/namei.c +++ b/fs/nova/namei.c @@ -207,6 +207,163 @@ static int nova_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, return err; } +static void nova_lite_transaction_for_time_and_link(struct super_block *sb, + struct nova_inode *pi, struct nova_inode *pidir, struct inode *inode, + struct inode *dir, struct nova_inode_update *update, + struct nova_inode_update *update_dir, int invalidate, u64 epoch_id) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + u64 journal_tail; + int cpu; + timing_t trans_time; + + NOVA_START_TIMING(link_trans_t, trans_time); + + cpu = smp_processor_id(); + spin_lock(&sbi->journal_locks[cpu]); + + // If you change what's required to create a new inode, you need to + // update this functions so the changes will be roll back on failure. + journal_tail = nova_create_inode_transaction(sb, inode, dir, cpu, + 0, invalidate); + + if (invalidate) { + pi->valid = 0; + pi->delete_epoch_id = epoch_id; + } + nova_update_inode(sb, inode, pi, update); + + nova_update_inode(sb, dir, pidir, update_dir); + + PERSISTENT_BARRIER(); + + nova_commit_lite_transaction(sb, journal_tail, cpu); + spin_unlock(&sbi->journal_locks[cpu]); + + NOVA_END_TIMING(link_trans_t, trans_time); +} + +static int nova_link(struct dentry *dest_dentry, struct inode *dir, + struct dentry *dentry) +{ + struct super_block *sb = dir->i_sb; + struct inode *inode = dest_dentry->d_inode; + struct nova_inode *pi = nova_get_inode(sb, inode); + struct nova_inode *pidir; + struct nova_inode_update update_dir; + struct nova_inode_update update; + u64 old_linkc = 0; + u64 epoch_id; + int err = -ENOMEM; + timing_t link_time; + + NOVA_START_TIMING(link_t, link_time); + if (inode->i_nlink >= NOVA_LINK_MAX) { + err = -EMLINK; + goto out; + } + + pidir = nova_get_inode(sb, dir); + if (!pidir) { + err = -EINVAL; + goto out; + } + + ihold(inode); + epoch_id = nova_get_epoch_id(sb); + + nova_dbgv("%s: name %s, dest %s\n", __func__, + dentry->d_name.name, dest_dentry->d_name.name); + nova_dbgv("%s: inode %lu, dir %lu\n", __func__, + inode->i_ino, dir->i_ino); + + update_dir.tail = 0; + err = nova_add_dentry(dentry, inode->i_ino, 0, &update_dir, epoch_id); + if (err) { + iput(inode); + goto out; + } + + inode->i_ctime = current_time(inode); + inc_nlink(inode); + + update.tail = 0; + err = nova_append_link_change_entry(sb, pi, inode, &update, + &old_linkc, epoch_id); + if (err) { + iput(inode); + goto out; + } + + d_instantiate(dentry, inode); + nova_lite_transaction_for_time_and_link(sb, pi, pidir, inode, dir, + &update, &update_dir, 0, epoch_id); + + nova_invalidate_link_change_entry(sb, old_linkc); + +out: + NOVA_END_TIMING(link_t, link_time); + return err; +} + +static int nova_unlink(struct inode *dir, struct dentry *dentry) +{ + struct inode *inode = dentry->d_inode; + struct super_block *sb = dir->i_sb; + int retval = -ENOMEM; + struct nova_inode *pi = nova_get_inode(sb, inode); + struct nova_inode *pidir; + struct nova_inode_update update_dir; + struct nova_inode_update update; + u64 old_linkc = 0; + u64 epoch_id; + int invalidate = 0; + timing_t unlink_time; + + NOVA_START_TIMING(unlink_t, unlink_time); + + pidir = nova_get_inode(sb, dir); + if (!pidir) + goto out; + + epoch_id = nova_get_epoch_id(sb); + nova_dbgv("%s: %s\n", __func__, dentry->d_name.name); + nova_dbgv("%s: inode %lu, dir %lu\n", __func__, + inode->i_ino, dir->i_ino); + + update_dir.tail = 0; + retval = nova_remove_dentry(dentry, 0, &update_dir, epoch_id); + if (retval) + goto out; + + inode->i_ctime = dir->i_ctime; + + if (inode->i_nlink == 1) + invalidate = 1; + + if (inode->i_nlink) + drop_nlink(inode); + + update.tail = 0; + retval = nova_append_link_change_entry(sb, pi, inode, &update, + &old_linkc, epoch_id); + if (retval) + goto out; + + nova_lite_transaction_for_time_and_link(sb, pi, pidir, inode, dir, + &update, &update_dir, invalidate, epoch_id); + + nova_invalidate_link_change_entry(sb, old_linkc); + nova_invalidate_dentries(sb, &update_dir); + + NOVA_END_TIMING(unlink_t, unlink_time); + return 0; +out: + nova_err(sb, "%s return %d\n", __func__, retval); + NOVA_END_TIMING(unlink_t, unlink_time); + return retval; +} + static int nova_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) { struct super_block *sb = dir->i_sb; @@ -307,6 +464,8 @@ struct dentry *nova_get_parent(struct dentry *child) const struct inode_operations nova_dir_inode_operations = { .create = nova_create, .lookup = nova_lookup, + .link = nova_link, + .unlink = nova_unlink, .mkdir = nova_mkdir, .mknod = nova_mknod, }; -- 2.7.4