Received: by 10.223.185.111 with SMTP id b44csp1646687wrg; Sat, 10 Mar 2018 10:30:57 -0800 (PST) X-Google-Smtp-Source: AG47ELtIxM5HvWrTMxx2y7f7Tn1GwltfeWeyk4kX6DL2ZFIrX4RxUXRwrwiy4oTQsBUbb4++1h3y X-Received: by 2002:a17:902:5a0d:: with SMTP id q13-v6mr2738923pli.152.1520706657297; Sat, 10 Mar 2018 10:30:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520706657; cv=none; d=google.com; s=arc-20160816; b=ER/odLLGeUQ0UdE+HqAHiWRu34QSeMs5Bv3vq+MKM8eN0f79N9lFNmUlinoD9/5RcF WVp/LqNZ2rupcV8nR+Qy/23+Kd1UR7yCxWZxQTjwVBgF8axGLQbYZloSb62KwyRLPN28 3VUbgb4QV8bOKnI1GvL5loh/VgFsSeFkybgxXCnN+2cH7UONroxyiOn9aRnZ7sqjUsLr g+IFADtMe1kWkLWoQP7Aw0Ai5hS6UbspMEPpuwfwkF0xPP/QnyIbQrqn6GGpH0kiDCrB cgqFpOajLAnzzWUn8HvShm9+MTM7mYo/HQ5dvM/+5sUh26bFYPs7i75fSjZkJX4sjtWF eWlg== 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=Z9sfKCnmc7ZeFPXgWL5LzyZP7SIAzNl8zPFy9Jdq4U8=; b=m7NnZz5dAhxzkxJC80xouKdLRMh/7TF/DJVsDkA8ApJ33Yf5YCUCCzGaUTvchT8gVF u/HgKUPDVRRN+GPaA/0pStPoJOITRGkel9D93zFBDQJTC6f2G4hBLauvJLQk2JyqbAQP oJjMmtI5TScJUyrmjTb87fyWFwJ8FYSOTz3nKhP7tahYIgiwtVuDWCTJIRoK0+1gDiuW VEiIB09elP/RL/6PkRavllFQoGD7A52HK+XEatO8c8OU/5vuxfrj7nlZqwHWjWHLW5YP vRiXSNjvHuo4HY3LoFFlSGBkvwpvSCtRGeRpbduhWN6LdXP4HBwkW5xz+d8Wm76hGwSv CWEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=h90vAqoQ; 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 r8-v6si3099191pli.324.2018.03.10.10.30.43; Sat, 10 Mar 2018 10:30:57 -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=h90vAqoQ; 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 S932754AbeCJSVb (ORCPT + 99 others); Sat, 10 Mar 2018 13:21:31 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:36896 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932673AbeCJSVV (ORCPT ); Sat, 10 Mar 2018 13:21:21 -0500 Received: by mail-pl0-f65.google.com with SMTP id w12-v6so7031005plp.4 for ; Sat, 10 Mar 2018 10:21:21 -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=Z9sfKCnmc7ZeFPXgWL5LzyZP7SIAzNl8zPFy9Jdq4U8=; b=h90vAqoQlnQ4oBkFF6P1M1/RC6RL1tSTML784Cif6udUsmcfJCPGj66SZQiczywcuk Sg4nn3MndxwcNpms3oK6SLTAscz9hjjyTPKa26uB9Q2RhJOJEwk47IcAXoLn2eZqEtNJ kaorklzpwxELxhf+3vZQsPXr89BVBTahlob50= 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=Z9sfKCnmc7ZeFPXgWL5LzyZP7SIAzNl8zPFy9Jdq4U8=; b=ZwCzfMWvtBc6wvPjSfGVzwzN0NiBk0aiqTuFsRqKf8Sa2YTbOZ2wUzPNo1X8PYlWki Y/FOWp9l5R9j5XfyPqVx5R+fhL17RYSFeOBqro8ICZv9wDDWnjonSgdIbv/XZLhoJkEV nCF38zIcvDrxoDfG5IYVLv6f0gmAMb4ABilbGPphorHmoj3BtJJ30q+OiKVCALUbM1zo U+tO7npkfBJ929F3kx2QPYa3aG+CKcUtmy/YhVdXOm6grZns6vmVqZjx02rL9HJFahtk gdbuSUxbEdJWOSo2iOL5m/coChqUdTXYtJuWPHGq4KC6TXuv3NMWCqPMnpIXylDLvuyj 5xaA== X-Gm-Message-State: AElRT7F7EdXPkZ0DSnM9BVXup3nNmozJGaEwl/K4KjgHfizxZmxgBMZk Dpq+MxDRpYkrsFwL8qujPXpxCw== X-Received: by 2002:a17:902:a610:: with SMTP id u16-v6mr2688362plq.293.1520706081350; Sat, 10 Mar 2018 10:21:21 -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.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:20 -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 54/83] Namei: create and mknod. Date: Sat, 10 Mar 2018 10:18:35 -0800 Message-Id: <1520705944-6723-55-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 NOVA allocates and initializes a new inode, and appends a dentry to the directory's log. Then NOVA creates a transaction to commit both changes atomically: update the directory log tail pointer and validate the new inode. Signed-off-by: Andiry Xu --- fs/nova/namei.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/fs/nova/namei.c b/fs/nova/namei.c index 8076f5b..a07cc4f 100644 --- a/fs/nova/namei.c +++ b/fs/nova/namei.c @@ -68,6 +68,145 @@ static struct dentry *nova_lookup(struct inode *dir, struct dentry *dentry, return d_splice_alias(inode, dentry); } +static void nova_lite_transaction_for_new_inode(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_sb_info *sbi = NOVA_SB(sb); + int cpu; + u64 journal_tail; + timing_t trans_time; + + NOVA_START_TIMING(create_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, 1, 0); + + nova_update_inode(sb, dir, pidir, update); + + pi->valid = 1; + nova_persist_inode(pi); + PERSISTENT_BARRIER(); + + nova_commit_lite_transaction(sb, journal_tail, cpu); + spin_unlock(&sbi->journal_locks[cpu]); + + NOVA_END_TIMING(create_trans_t, trans_time); +} + +/* Returns new tail after append */ +/* + * By the time this is called, we already have created + * the directory cache entry for the new file, but it + * is so far negative - it has no inode. + * + * If the create succeeds, we fill in the inode information + * with d_instantiate(). + */ +static int nova_create(struct inode *dir, struct dentry *dentry, umode_t mode, + bool excl) +{ + struct inode *inode = NULL; + int err = PTR_ERR(inode); + struct super_block *sb = dir->i_sb; + struct nova_inode *pidir, *pi; + struct nova_inode_update update; + u64 pi_addr = 0; + u64 ino, epoch_id; + timing_t create_time; + + NOVA_START_TIMING(create_t, create_time); + + pidir = nova_get_inode(sb, dir); + if (!pidir) + goto out_err; + + epoch_id = nova_get_epoch_id(sb); + ino = nova_new_nova_inode(sb, &pi_addr); + if (ino == 0) + goto out_err; + + update.tail = 0; + err = nova_add_dentry(dentry, ino, 0, &update, epoch_id); + if (err) + goto out_err; + + nova_dbgv("%s: %s\n", __func__, dentry->d_name.name); + nova_dbgv("%s: inode %llu, dir %lu\n", __func__, ino, dir->i_ino); + inode = nova_new_vfs_inode(TYPE_CREATE, dir, pi_addr, ino, mode, + 0, 0, &dentry->d_name, epoch_id); + if (IS_ERR(inode)) + goto out_err; + + d_instantiate(dentry, inode); + unlock_new_inode(inode); + + pi = nova_get_block(sb, pi_addr); + nova_lite_transaction_for_new_inode(sb, pi, pidir, inode, dir, + &update); + NOVA_END_TIMING(create_t, create_time); + return err; +out_err: + nova_err(sb, "%s return %d\n", __func__, err); + NOVA_END_TIMING(create_t, create_time); + return err; +} + +static int nova_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, + dev_t rdev) +{ + struct inode *inode = NULL; + int err = PTR_ERR(inode); + struct super_block *sb = dir->i_sb; + u64 pi_addr = 0; + struct nova_inode *pidir, *pi; + struct nova_inode_update update; + u64 ino; + u64 epoch_id; + timing_t mknod_time; + + NOVA_START_TIMING(mknod_t, mknod_time); + + pidir = nova_get_inode(sb, dir); + if (!pidir) + goto out_err; + + epoch_id = nova_get_epoch_id(sb); + ino = nova_new_nova_inode(sb, &pi_addr); + if (ino == 0) + goto out_err; + + nova_dbgv("%s: %s\n", __func__, dentry->d_name.name); + nova_dbgv("%s: inode %llu, dir %lu\n", __func__, ino, dir->i_ino); + + update.tail = 0; + err = nova_add_dentry(dentry, ino, 0, &update, epoch_id); + if (err) + goto out_err; + + inode = nova_new_vfs_inode(TYPE_MKNOD, dir, pi_addr, ino, mode, + 0, rdev, &dentry->d_name, epoch_id); + if (IS_ERR(inode)) + goto out_err; + + d_instantiate(dentry, inode); + unlock_new_inode(inode); + + pi = nova_get_block(sb, pi_addr); + nova_lite_transaction_for_new_inode(sb, pi, pidir, inode, dir, + &update); + NOVA_END_TIMING(mknod_t, mknod_time); + return err; +out_err: + nova_err(sb, "%s return %d\n", __func__, err); + NOVA_END_TIMING(mknod_t, mknod_time); + return err; +} + struct dentry *nova_get_parent(struct dentry *child) { struct inode *inode; @@ -93,5 +232,7 @@ struct dentry *nova_get_parent(struct dentry *child) } const struct inode_operations nova_dir_inode_operations = { + .create = nova_create, .lookup = nova_lookup, + .mknod = nova_mknod, }; -- 2.7.4