From patchwork Sat Mar 10 18:18:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273935 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 B2D9F605D2 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 A2324296E5 for ; Sat, 10 Mar 2018 18:21:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96E6B29762; 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 5B090296E5 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 048752258AF15; 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::241; helo=mail-pl0-x241.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pl0-x241.google.com (mail-pl0-x241.google.com [IPv6:2607:f8b0:400e:c01::241]) (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 22BC922631491 for ; Sat, 10 Mar 2018 10:15:04 -0800 (PST) Received: by mail-pl0-x241.google.com with SMTP id w22-v6so7026134pll.2 for ; Sat, 10 Mar 2018 10:21:22 -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=XmD8ATX4wCc0Z4iIwRqodqgDYe90f06ZSlqLy4YQsbg=; b=gAND/RLyQjyabWwp0eTBw0hke4dfuyXuzUVblZUQ0JZtqb9SDkxB9yA442idV/Vxrt uEfagmDTJWLrP48QORFBtZWAWjsyrud4cC8yyaOkxVR8FyTeqjIjPa1t+/SUaf0xMbIf QaJ2yMktvt0gdRIWum3FpW6mhw9U/rnNFQk0k= 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=XmD8ATX4wCc0Z4iIwRqodqgDYe90f06ZSlqLy4YQsbg=; b=TtEJXuswYj3wEYiaEwrY+0Qyf2Eu8ZFDf1w//Josw2nGMkQzfmT6QOD8PyJKFx1lkt xt+lFED67OMUE5BXMfoXMnIisGOMsta5f8fc19TK1E/bdfxXunCZCd4O/8K2BZATXa2x mGJ4xV8Hxmk6yR9tC/4xXmzAQW1js5/DTmmUj4TjXcLx3pf7jNucmoSO8WYm7PQ+QVTA QrmNQmiKeIziLSRwgMx34UxVGq3HAByPB9xcJ7VfQSrjACkUMeSPv/jAF8QCXTA45459 MQTARTPah2oCJuEcWH1cGWqfD1//etZrhEiUpdFpAvJNvsVRgdsgeYMgO4ZOB9MxwTmh UEAQ== X-Gm-Message-State: AElRT7EtJBtpreVLX2nJ9HLk0NL2oegFrA0viO1SQX6eG176j5Izpo+B xQZe6+mIgpkWmjLLlsgEelPOYg== X-Google-Smtp-Source: AG47ELs3YsaM4vhSYuM5ljMyYWWTdKXBfjusrfBtWDB0ysWcVuSOWef44hYzbuSz7xZBBIqSUUgMcA== X-Received: by 2002:a17:902:4c88:: with SMTP id b8-v6mr2797330ple.0.1520706082530; Sat, 10 Mar 2018 10:21:22 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:21 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 55/83] Namei: mkdir Date: Sat, 10 Mar 2018 10:18:36 -0800 Message-Id: <1520705944-6723-56-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 mkdir is similar to create. The difference is NOVA will allocate log page for the newly created directory, and append init dentries. Signed-off-by: Andiry Xu --- fs/nova/namei.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/fs/nova/namei.c b/fs/nova/namei.c index a07cc4f..a95b2fe 100644 --- a/fs/nova/namei.c +++ b/fs/nova/namei.c @@ -207,6 +207,79 @@ static int nova_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, return err; } +static int nova_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) +{ + struct super_block *sb = dir->i_sb; + struct inode *inode; + struct nova_inode *pidir, *pi; + struct nova_inode_info *si, *sidir; + struct nova_inode_info_header *sih = NULL; + struct nova_inode_update update; + u64 pi_addr = 0; + u64 ino; + u64 epoch_id; + int err = -EMLINK; + timing_t mkdir_time; + + NOVA_START_TIMING(mkdir_t, mkdir_time); + if (dir->i_nlink >= NOVA_LINK_MAX) + goto out; + + ino = nova_new_nova_inode(sb, &pi_addr); + if (ino == 0) + goto out_err; + + epoch_id = nova_get_epoch_id(sb); + nova_dbgv("%s: name %s\n", __func__, dentry->d_name.name); + nova_dbgv("%s: inode %llu, dir %lu, link %d\n", __func__, + ino, dir->i_ino, dir->i_nlink); + + update.tail = 0; + err = nova_add_dentry(dentry, ino, 1, &update, epoch_id); + if (err) { + nova_dbg("failed to add dir entry\n"); + goto out_err; + } + + inode = nova_new_vfs_inode(TYPE_MKDIR, dir, pi_addr, ino, + S_IFDIR | mode, sb->s_blocksize, + 0, &dentry->d_name, epoch_id); + if (IS_ERR(inode)) { + err = PTR_ERR(inode); + goto out_err; + } + + pi = nova_get_inode(sb, inode); + err = nova_append_dir_init_entries(sb, pi, inode->i_ino, dir->i_ino, + epoch_id); + if (err < 0) + goto out_err; + + /* Build the dir tree */ + si = NOVA_I(inode); + sih = &si->header; + nova_rebuild_dir_inode_tree(sb, pi, pi_addr, sih); + + pidir = nova_get_inode(sb, dir); + sidir = NOVA_I(dir); + sih = &si->header; + dir->i_blocks = sih->i_blocks; + inc_nlink(dir); + d_instantiate(dentry, inode); + unlock_new_inode(inode); + + nova_lite_transaction_for_new_inode(sb, pi, pidir, inode, dir, + &update); +out: + NOVA_END_TIMING(mkdir_t, mkdir_time); + return err; + +out_err: +// clear_nlink(inode); + nova_err(sb, "%s return %d\n", __func__, err); + goto out; +} + struct dentry *nova_get_parent(struct dentry *child) { struct inode *inode; @@ -234,5 +307,6 @@ struct dentry *nova_get_parent(struct dentry *child) const struct inode_operations nova_dir_inode_operations = { .create = nova_create, .lookup = nova_lookup, + .mkdir = nova_mkdir, .mknod = nova_mknod, };