From patchwork Sat Mar 10 18:18:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273939 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 3C381601A0 for ; Sat, 10 Mar 2018 18:21:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B8FD29106 for ; Sat, 10 Mar 2018 18:21:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2043A29735; Sat, 10 Mar 2018 18:21: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=-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 C38F52974F for ; Sat, 10 Mar 2018 18:21:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3096922603B0C; Sat, 10 Mar 2018 10:15:06 -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:c01::243; helo=mail-pl0-x243.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pl0-x243.google.com (mail-pl0-x243.google.com [IPv6:2607:f8b0:400e:c01::243]) (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 463BC2253FB61 for ; Sat, 10 Mar 2018 10:15:05 -0800 (PST) Received: by mail-pl0-x243.google.com with SMTP id f23-v6so7024300plr.10 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=VIXWdJIA3b1R6smwOHT+mjX5eYRPleS0i9jRfjaX2/WJR7P3Kstkx6lKFZ3ch60lG6 cLSozk3XwRNiAc3zl/e2ACPRe/Fowq5yV/iDZlTIIZJ/JVcuK5nEq2IupngT62x/pH6T bLkLYFdKutel2oxVhj+RTKWuQeu1AyVN+vRlNDhcxIHZDpyEhce2YZK60dieNt4hnILU sqrw/93sGZ4WDBdJfeW2RSNuxjrBHa0QFalfS5ghaykKsGB9DX5XZ5addQLcBWhdYaTR OieiCf+Gq8UBumBp/OW6KOUYx9+YYHdo4UkjRqsjp2+xdei6QVt20v1IO5L5FRuyfXqp 8feg== X-Gm-Message-State: AElRT7F23l3ySZ0t4THRe1K14DOXus9lgW9netVtecOWcEIVxWkR08ry 7MgMXWF/1yBqrg0ww/f8tWcu+A== X-Google-Smtp-Source: AG47ELscuazm6FqZW2p64jWs6gemKOJwutDTPQhijn9g5EDA7yHX0BKiY/Byp3yj3UeYR2PEvaFPjg== 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 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> 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 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, };