Received: by 10.223.185.111 with SMTP id b44csp1648731wrg; Sat, 10 Mar 2018 10:33:55 -0800 (PST) X-Google-Smtp-Source: AG47ELtg5uH6D2JMwZdxohneuKiTfujkhQqXNm9eYSz2yZo0DnJ1D0VYU6Jm38W0ZG/pjsIikQ/q X-Received: by 2002:a17:902:2803:: with SMTP id e3-v6mr2821251plb.238.1520706835278; Sat, 10 Mar 2018 10:33:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520706835; cv=none; d=google.com; s=arc-20160816; b=SzGix763NHiOHkAuxb0HhPt3OUlbxR84mTweSB6chBwBNBBcarr34Q9BGrbVTX6nTi sZ0+l286+VyHdU22UzdR4ngh+rgevf3ufWRH76F4LVGbuf/SCI5X9u4Ezg6/zZcO8KUx wg/5+kczvtZyaMrZpXmaJnaxmjKHk3gSnlnY6rI5xTRgqwcMu6xSkAE1q+htvzt0zYo3 O9nqqRjfv6hN8WGzNFuYUGvoK8KG0XqIq1oHmixgetvlI2pkL902YUYCIujHKTcBJQ+D hR28CaYyZkxLSZM4f4myB0PIx7wWbyoXeAitBV4JM7r5wy6ts8z7rIqE+MlEHLEXWwgx zmBw== 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=VqTt2aTE8VgJdfVjclox+mnT4m/BuJdx8ABvkXuuyZc=; b=oZZKuht2K+9ja/twq8QtwLX/WVk2P5pcmlhzeVms85VNsNOe0UU7uQmLlGmIMmghld x5gO3D8ySs4IxU5YuwEtN2Nf+yKVG5oi+LrkpsRzqhfrb4JvTJUbOfzgMhn/qvDBnE1g eUOsbvfEJhoROOhyODo9EtF/MbcyTRo5mluaOQ/qq/Wm7yJUhu2A5GruXP6WqIo7EHA9 VTOwxe9T1nFRFUNktfuE4X/0uzCQxmanUdUPn9KL24Ot7HY5vUTSKJczStLifC5Va9H3 uFDZxSi2NnoG/e8wXLyOccyFa6BvJhdwI5QXg/iEoVj1YTazs1RNm4CSOMLA0/I7GwFH x4DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=J4/Z6Ypa; 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 z31-v6si3044682plb.613.2018.03.10.10.33.40; Sat, 10 Mar 2018 10:33:55 -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=J4/Z6Ypa; 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 S932663AbeCJSVT (ORCPT + 99 others); Sat, 10 Mar 2018 13:21:19 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:46194 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932632AbeCJSVO (ORCPT ); Sat, 10 Mar 2018 13:21:14 -0500 Received: by mail-pg0-f67.google.com with SMTP id r26so4828559pgv.13 for ; Sat, 10 Mar 2018 10:21:14 -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=VqTt2aTE8VgJdfVjclox+mnT4m/BuJdx8ABvkXuuyZc=; b=J4/Z6Ypa8UK+60lNnvamYEe9d9jNDx4p6Ykv5fdYZQQF5wyRGvx9jtJEfcUCk8A2MH q04gB5ebkpMScuDgCOzTXTDvusiOXJ/BBaPRLox0FD3VdKtoqavIz7I9DTmIv4ySWq06 EKicbfYSUK3mwgZHhSWxBxUfM6VIBybwbh4l8= 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=VqTt2aTE8VgJdfVjclox+mnT4m/BuJdx8ABvkXuuyZc=; b=fdvJT01mZqjeNnR0fAj9yqF6HNuBPaTKY7ADeYsmvQxHBK4IkYSKv4TENLUxEm4nc8 pihzg1EeQKakHKXdZZNYIKNQuavn9CCScAveszQ2H3Lm/JQZDCju2DYBwBZBrfXOS2ER GIZA9LtdwX5kwXWA8++2ZkJtUdZDccNB9HJ1djIPsApRaeF9fSX5GbSG+Gr37Y+QY9CF x+VCzCu80I+sRhNDHOKl2AqRfn5ES9YPCWt6woiPm6/1qNJrPxJudCMn6+U4KQDogw59 /CD+T0hA/Eii7RvucnL6cKYu7Etdg4PCgW7LAchBgmoqE/ghCiBf6zGAZLuJD5r7eYka 5e9g== X-Gm-Message-State: AElRT7GcKEiSfjH4/vFY8K524XlbX1L2ZUHWL32NHqiNPOjIJ/B9u5GF xYLMwIrunHHMsTWFYN7GEX0dlw== X-Received: by 10.98.134.10 with SMTP id x10mr2674722pfd.78.1520706074078; Sat, 10 Mar 2018 10:21:14 -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.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:13 -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 48/83] Dir: Readdir operation. Date: Sat, 10 Mar 2018 10:18:29 -0800 Message-Id: <1520705944-6723-49-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 reads the directory by traversing the log and reports the valid dentries. Valid dentris have inode number greater than zero, meaning it's a create dentry. Signed-off-by: Andiry Xu --- fs/nova/dir.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/inode.c | 2 + fs/nova/nova.h | 1 + 3 files changed, 156 insertions(+) diff --git a/fs/nova/dir.c b/fs/nova/dir.c index 377d2da..35a66f9 100644 --- a/fs/nova/dir.c +++ b/fs/nova/dir.c @@ -221,3 +221,156 @@ int nova_append_dir_init_entries(struct super_block *sb, return 0; } + +static u64 nova_find_next_dentry_addr(struct super_block *sb, + struct nova_inode_info_header *sih, u64 pos) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + struct nova_file_write_entry *entry = NULL; + struct nova_file_write_entry *entries[1]; + int nr_entries; + u64 addr = 0; + + nr_entries = radix_tree_gang_lookup(&sih->tree, + (void **)entries, pos, 1); + if (nr_entries == 1) { + entry = entries[0]; + addr = nova_get_addr_off(sbi, entry); + } + + return addr; +} + +static int nova_readdir(struct file *file, struct dir_context *ctx) +{ + struct inode *inode = file_inode(file); + struct super_block *sb = inode->i_sb; + struct nova_inode *pidir; + struct nova_inode_info *si = NOVA_I(inode); + struct nova_inode_info_header *sih = &si->header; + struct nova_inode *child_pi; + struct nova_inode *prev_child_pi = NULL; + struct nova_dentry *entry = NULL; + struct nova_dentry *prev_entry = NULL; + unsigned short de_len; + u64 pi_addr; + unsigned long pos = 0; + ino_t ino; + void *addr; + u64 curr_p; + u8 type; + int ret = 0; + timing_t readdir_time; + + NOVA_START_TIMING(readdir_t, readdir_time); + pidir = nova_get_inode(sb, inode); + nova_dbgv("%s: ino %llu, size %llu, pos 0x%llx\n", + __func__, (u64)inode->i_ino, + pidir->i_size, ctx->pos); + + if (sih->log_head == 0) { + nova_err(sb, "Dir %lu log is NULL!\n", inode->i_ino); + ret = -ENOSPC; + goto out; + } + + pos = ctx->pos; + + if (pos == 0) + curr_p = sih->log_head; + else if (pos == READDIR_END) + goto out; + else { + curr_p = nova_find_next_dentry_addr(sb, sih, pos); + if (curr_p == 0) + goto out; + } + + while (curr_p != sih->log_tail) { + if (goto_next_page(sb, curr_p)) + curr_p = next_log_page(sb, curr_p); + + + if (curr_p == 0) { + nova_err(sb, "Dir %lu log is NULL!\n", inode->i_ino); + ret = -EINVAL; + goto out; + } + + addr = (void *)nova_get_block(sb, curr_p); + type = nova_get_entry_type(addr); + switch (type) { + case SET_ATTR: + curr_p += sizeof(struct nova_setattr_logentry); + continue; + case LINK_CHANGE: + curr_p += sizeof(struct nova_link_change_entry); + continue; + case DIR_LOG: + break; + default: + nova_err(sb, "%s: unknown type %d, 0x%llx\n", + __func__, type, curr_p); + ret = -EINVAL; + goto out; + } + + entry = (struct nova_dentry *)nova_get_block(sb, curr_p); + nova_dbgv("curr_p: 0x%llx, type %d, ino %llu, name %s, namelen %u, rec len %u\n", + curr_p, entry->entry_type, le64_to_cpu(entry->ino), + entry->name, entry->name_len, + le16_to_cpu(entry->de_len)); + + de_len = le16_to_cpu(entry->de_len); + if (entry->ino > 0 && entry->invalid == 0 + && entry->reassigned == 0) { + ino = __le64_to_cpu(entry->ino); + pos = BKDRHash(entry->name, entry->name_len); + + ret = nova_get_inode_address(sb, ino, + &pi_addr, 0); + if (ret) { + nova_dbg("%s: get child inode %lu address failed %d\n", + __func__, ino, ret); + ctx->pos = READDIR_END; + goto out; + } + + child_pi = nova_get_block(sb, pi_addr); + nova_dbgv("ctx: ino %llu, name %s, name_len %u, de_len %u\n", + (u64)ino, entry->name, entry->name_len, + entry->de_len); + if (prev_entry && !dir_emit(ctx, prev_entry->name, + prev_entry->name_len, ino, + IF2DT(le16_to_cpu(prev_child_pi->i_mode)))) { + nova_dbgv("Here: pos %llu\n", ctx->pos); + ret = 0; + goto out; + } + prev_entry = entry; + + prev_child_pi = child_pi; + } + ctx->pos = pos; + curr_p += de_len; + } + + if (prev_entry && !dir_emit(ctx, prev_entry->name, + prev_entry->name_len, ino, + IF2DT(le16_to_cpu(prev_child_pi->i_mode)))) + return 0; + + ctx->pos = READDIR_END; + ret = 0; +out: + NOVA_END_TIMING(readdir_t, readdir_time); + nova_dbgv("%s return\n", __func__); + return ret; +} + +const struct file_operations nova_dir_operations = { + .llseek = generic_file_llseek, + .read = generic_read_dir, + .iterate = nova_readdir, + .fsync = noop_fsync, +}; diff --git a/fs/nova/inode.c b/fs/nova/inode.c index 15517cc..41417e3 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_fop = &nova_dir_operations; break; case S_IFLNK: break; @@ -625,6 +626,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_fop = &nova_dir_operations; inode->i_mapping->a_ops = &nova_aops_dax; set_nlink(inode, 2); break; diff --git a/fs/nova/nova.h b/fs/nova/nova.h index a94f44d..ed269fe 100644 --- a/fs/nova/nova.h +++ b/fs/nova/nova.h @@ -447,6 +447,7 @@ nova_get_blocknr(struct super_block *sb, u64 block, unsigned short btype) /* ====================================================== */ /* dir.c */ +extern const struct file_operations nova_dir_operations; int nova_insert_dir_radix_tree(struct super_block *sb, struct nova_inode_info_header *sih, const char *name, int namelen, struct nova_dentry *direntry); -- 2.7.4