From patchwork Sat Mar 10 18:18:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273933 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 A7041602BD for ; Sat, 10 Mar 2018 18:21:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 969E529759 for ; Sat, 10 Mar 2018 18:21:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87C4F29106; Sat, 10 Mar 2018 18:21:31 +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 3185E29106 for ; Sat, 10 Mar 2018 18:21:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C71762258AF0E; Sat, 10 Mar 2018 10:15:04 -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::242; helo=mail-pl0-x242.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pl0-x242.google.com (mail-pl0-x242.google.com [IPv6:2607:f8b0:400e:c01::242]) (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 D5E342263149B for ; Sat, 10 Mar 2018 10:15:02 -0800 (PST) Received: by mail-pl0-x242.google.com with SMTP id 61-v6so7023997plf.3 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=LpPSvK8akufoOx8S93ahl4UFoyl3++Am4J0O9Fn0LAw9DhQ7B92xCElAjqgUVHkCWw psIenXNDO85FsmkW18al7E08PxOmghhXBx7eGSeDKafKRZdG8tEUvC8q12G4HRyKALRj FV2R8V1vXZgMKGvvUI9cbcnEroSi0hJKL2R1qj7w11Hjny7b85xlVLIYuWjZ+umlp7+9 fiV4BhOLMVX3eJamYBqKS52I6hjJjSVs1Tt5vSL6TbLQFFU46yOBCpcaC58/XyBNBLQX P3EbwyBxS9MzH7KXHsowo0bGsMUiqmibZLGTpzwuVmAUEXMGK3LoC1vw8Mf2dV3Nwrlk m/Ig== X-Gm-Message-State: AElRT7HkdlTPh0kmh6JCvN/Ztk0vfkujXi+i8ysFhYcowUrnaTEXKftR RN/Vbu8EEEKFiqgQqahzb+Ro1A== X-Google-Smtp-Source: AG47ELuEK4FCTohSroXD45zNjuE086Yg212QxXSq7M/aM4/FUm3xL9fAdCicFgAWsM9Tmun9Gypu2A== 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 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> 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 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, };