From patchwork Sat Mar 10 18:18:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273931 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 2A4FA601A0 for ; Sat, 10 Mar 2018 18:21:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1946A28BAE for ; Sat, 10 Mar 2018 18:21:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DBFF296E5; Sat, 10 Mar 2018 18:21:29 +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 ADD6B29106 for ; Sat, 10 Mar 2018 18:21:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 97C0E2258AEF8; 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::244; helo=mail-pl0-x244.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pl0-x244.google.com (mail-pl0-x244.google.com [IPv6:2607:f8b0:400e:c01::244]) (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 ACC722263149B for ; Sat, 10 Mar 2018 10:15:01 -0800 (PST) Received: by mail-pl0-x244.google.com with SMTP id 9-v6so7020007ple.11 for ; Sat, 10 Mar 2018 10:21:20 -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=jbcZdLSdt0UoJaDqfSpySCW+vJWUKepO4tMGeovnmps=; b=fPAKd/iseLubs+xgYbeFMsHivpuEtCOVweHQN0gcfSsjsz+vmeVUwkYHj5LqFAwtVb 5cOeE/UmcBQcNx1+YRPsXKBv3ZuldCb4ZH3nun2S4cDnZc3MWDDsMqeaqj/xIGRMvmYc iobXtNFJoxPQvgam3Kn8pnTK2Ru+rC7bvuDbQ= 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=jbcZdLSdt0UoJaDqfSpySCW+vJWUKepO4tMGeovnmps=; b=uPX3O9i1eZ3UkyL4G/71OShIFReJy9AwYxht/K8H8NLbvWA+l2wuvvnhSwpoqSmQ2i 8rnxQ3ymdXNfqvYBissdGXGNIjkvncrn1KRZo/27qMZt78QrNSL6tsLN6xrwBaOGcX4D NsYSwNbf4dF2uelVZzfOzYZxFJnVolfbm+sL+tEgX2wFwu5M/w0qc6p5xRHNxl6tSl0O 6NpEN/iP7WjKxi4SJhOrfJFZAktWT+ZVogauMNrfU8zkiICjvVNdZztYl1+LYZRRqkoo Qt4TkEtZtllaVNZd45/hNA04LHQaWkqw620YHfvPEChR57bfGUvG2Aj8fuNvR6TOfx3c Iowg== X-Gm-Message-State: AElRT7H+yk+yg41R0u5yAaDyNVbdjYJLTR7o1ZWg08Md8W7lky5j9285 9tMenIO7HlIhHtecdfhyVsJtCQ== X-Google-Smtp-Source: AG47ELuy5m4KW6XcJzPNyw/ZH5FX0+9U3Z8wiwEr0Mst0n7uGOpxJCX8tuO9YiOn2qQyMCy7LDN4Aw== X-Received: by 2002:a17:902:42a3:: with SMTP id h32-v6mr2658659pld.231.1520706080108; Sat, 10 Mar 2018 10:21:20 -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.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:19 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 53/83] Namei: lookup. Date: Sat, 10 Mar 2018 10:18:34 -0800 Message-Id: <1520705944-6723-54-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 lookup the inode number by searching the radix tree with the filename hash value and locating the corresponding dentry on the log. Signed-off-by: Andiry Xu --- fs/nova/Makefile | 3 +- fs/nova/inode.c | 2 ++ fs/nova/namei.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/nova.h | 4 +++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 fs/nova/namei.c diff --git a/fs/nova/Makefile b/fs/nova/Makefile index 3a3243c..eb97e46 100644 --- a/fs/nova/Makefile +++ b/fs/nova/Makefile @@ -4,4 +4,5 @@ obj-$(CONFIG_NOVA_FS) += nova.o -nova-y := balloc.o bbuild.o dir.o inode.o journal.o log.o rebuild.o stats.o super.o +nova-y := balloc.o bbuild.o dir.o inode.o journal.o log.o namei.o\ + rebuild.o stats.o super.o diff --git a/fs/nova/inode.c b/fs/nova/inode.c index 17addd3..2d3f7a3 100644 --- a/fs/nova/inode.c +++ b/fs/nova/inode.c @@ -181,6 +181,7 @@ static int nova_read_inode(struct super_block *sb, struct inode *inode, case S_IFREG: break; case S_IFDIR: + inode->i_op = &nova_dir_inode_operations; inode->i_fop = &nova_dir_operations; break; case S_IFLNK: @@ -881,6 +882,7 @@ struct inode *nova_new_vfs_inode(enum nova_new_inode_type type, inode->i_mapping->a_ops = &nova_aops_dax; break; case TYPE_MKDIR: + inode->i_op = &nova_dir_inode_operations; inode->i_fop = &nova_dir_operations; inode->i_mapping->a_ops = &nova_aops_dax; set_nlink(inode, 2); diff --git a/fs/nova/namei.c b/fs/nova/namei.c new file mode 100644 index 0000000..8076f5b --- /dev/null +++ b/fs/nova/namei.c @@ -0,0 +1,97 @@ +/* + * BRIEF DESCRIPTION + * + * Inode operations for directories. + * + * Copyright 2015-2016 Regents of the University of California, + * UCSD Non-Volatile Systems Lab, Andiry Xu + * Copyright 2012-2013 Intel Corporation + * Copyright 2009-2011 Marco Stornelli + * Copyright 2003 Sony Corporation + * Copyright 2003 Matsushita Electric Industrial Co., Ltd. + * 2003-2004 (c) MontaVista Software, Inc. , Steve Longerbeam + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ +#include +#include +#include "nova.h" +#include "journal.h" +#include "inode.h" + +static ino_t nova_inode_by_name(struct inode *dir, struct qstr *entry, + struct nova_dentry **res_entry) +{ + struct super_block *sb = dir->i_sb; + struct nova_dentry *direntry; + + direntry = nova_find_dentry(sb, NULL, dir, + entry->name, entry->len); + if (direntry == NULL) + return 0; + + *res_entry = direntry; + return direntry->ino; +} + +static struct dentry *nova_lookup(struct inode *dir, struct dentry *dentry, + unsigned int flags) +{ + struct inode *inode = NULL; + struct nova_dentry *de; + ino_t ino; + timing_t lookup_time; + + NOVA_START_TIMING(lookup_t, lookup_time); + if (dentry->d_name.len > NOVA_NAME_LEN) { + nova_dbg("%s: namelen %u exceeds limit\n", + __func__, dentry->d_name.len); + return ERR_PTR(-ENAMETOOLONG); + } + + nova_dbg_verbose("%s: %s\n", __func__, dentry->d_name.name); + ino = nova_inode_by_name(dir, &dentry->d_name, &de); + nova_dbg_verbose("%s: ino %lu\n", __func__, ino); + if (ino) { + inode = nova_iget(dir->i_sb, ino); + if (inode == ERR_PTR(-ESTALE) || inode == ERR_PTR(-ENOMEM) + || inode == ERR_PTR(-EACCES)) { + nova_err(dir->i_sb, + "%s: get inode failed: %lu\n", + __func__, (unsigned long)ino); + return ERR_PTR(-EIO); + } + } + + NOVA_END_TIMING(lookup_t, lookup_time); + return d_splice_alias(inode, dentry); +} + +struct dentry *nova_get_parent(struct dentry *child) +{ + struct inode *inode; + struct qstr dotdot = QSTR_INIT("..", 2); + struct nova_dentry *de = NULL; + ino_t ino; + + nova_inode_by_name(child->d_inode, &dotdot, &de); + if (!de) + return ERR_PTR(-ENOENT); + + /* FIXME: can de->ino be avoided by using the return value of + * nova_inode_by_name()? + */ + ino = le64_to_cpu(de->ino); + + if (ino) + inode = nova_iget(child->d_inode->i_sb, ino); + else + return ERR_PTR(-ENOENT); + + return d_obtain_alias(inode); +} + +const struct inode_operations nova_dir_inode_operations = { + .lookup = nova_lookup, +}; diff --git a/fs/nova/nova.h b/fs/nova/nova.h index 983c6b2..03ea0bd 100644 --- a/fs/nova/nova.h +++ b/fs/nova/nova.h @@ -484,6 +484,10 @@ int nova_add_dentry(struct dentry *dentry, u64 ino, int inc_link, int nova_remove_dentry(struct dentry *dentry, int dec_link, struct nova_inode_update *update, u64 epoch_id); +/* namei.c */ +extern const struct inode_operations nova_dir_inode_operations; +extern struct dentry *nova_get_parent(struct dentry *child); + /* rebuild.c */ int nova_rebuild_dir_inode_tree(struct super_block *sb, struct nova_inode *pi, u64 pi_addr,