Received: by 10.223.185.111 with SMTP id b44csp1657172wrg; Sat, 10 Mar 2018 10:47:19 -0800 (PST) X-Google-Smtp-Source: AG47ELt+M/Nl19fgl4Elm+cLaJaXbX5EalJ26PqNxFyVs9piTZXogxvA5GCeaTnAOxeYtBM3zOjD X-Received: by 10.101.64.194 with SMTP id u2mr2275504pgp.280.1520707639518; Sat, 10 Mar 2018 10:47:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520707639; cv=none; d=google.com; s=arc-20160816; b=YHxoWMhIPH2PkjriXtcCtFsyEkSOyytl728sYDWCo1jgTrd83wyXp/GfR00twrK4M6 FfySiJ2QM9Gxt80xQ7krjQUZN784VlNyRY/yNEiN+LcwjGhS61rOcOJEXDs0wsZ+rdJm 3kBvieqmCNAhZqb3ADW9QVHl0RpULmq2fQM0RcNRV+7n0YnY1bsrPypJPI7xQnX5xLaA 6R1Yzt0s7d5sXy3RtZ13mOEXD5am/A8FT9Z8uW6QWNK3y73raCCjjgZ+02qdPLLk0Q/k aS3sZb1Q6rttuqvy+hj8RzfAwalk8ys7icm8+xBBNCPK+96t52q8EQAVwfV/v2iaQkAg gGKA== 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=jNciQNYhV/VSLOizUkdnViiqXMlMLrr9PeqYVej0eXI=; b=hPVd8bv3a7XI8oI5tZTKv4SNSNAw02i5Cs7OtzCa1AGDy4sCScCTfrtFiIdt5CjrQ0 fIdY8LTTeH2eVAzyPxvSeBb7CsJ4Pyhx4SvyEETkMRXddzw/kgDSaEDKIgQVchiephWs qts/Q5WiBKxvolHNR8Tpv5urs01t3WSGOSp2Vnj6CJ6AWpmwYcmAlKJMRXzOJ96nWSTG ogOqZVJS/ELAdDfN3fvKgPxwSyjHXA0ZAfcvtEU0zp4N1C9RyAC1zCdCFAauilOHY9iH QHpiz02XPQ/oUnPCtihs8/6YRZATGHDeeyZgXthDe6sFDfLhq/xbIKMQlqJaF7TmQ3gt KUgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=VDmhH3Iz; 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 d21-v6si3046665pll.559.2018.03.10.10.47.05; Sat, 10 Mar 2018 10:47:19 -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=VDmhH3Iz; 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 S932344AbeCJSpz (ORCPT + 99 others); Sat, 10 Mar 2018 13:45:55 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:41835 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932171AbeCJSUU (ORCPT ); Sat, 10 Mar 2018 13:20:20 -0500 Received: by mail-pg0-f65.google.com with SMTP id w17so767611pgq.8 for ; Sat, 10 Mar 2018 10:20: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=jNciQNYhV/VSLOizUkdnViiqXMlMLrr9PeqYVej0eXI=; b=VDmhH3IzIqtOrfgJ/+9nIPPtoGxwSgMebRG4TbcG7k+Q+F0AELAVQnJV0HlYhIyZeK jkZ2TuRoPEjPb0HtZJdHTBcSWI86ordtMxwgl1xZpvuLIEgnLNKq18CS28Q7MzDiH7L/ Q70BLc78pjWXvk/R2oo0C+Ils4h9dwkw/jXfc= 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=jNciQNYhV/VSLOizUkdnViiqXMlMLrr9PeqYVej0eXI=; b=E1a8uxtzp7veP9aX3ed8krscnOxtPa/hubHfqf3yf10kDBKtyfshbx+wgKHYThJJ3R g2xZMjv5Qbu/EC976mDnpnvbkZrKwHgabIGFSE/2RwLBlNcuXjpVxcX2raKNTBUzPFlZ xn7BlGgAQAtxMiYlSjIq9pcT8/EC7BCMIcCGMk7ycKVg3wjaxOawG3cPOGnPDhKZC38c IDQjyFKYXVqwueXPYBSvOTjGvB71c64bECxEUdbIc6ssb2vzjtuUvlZFcna+FRULWu0f XxXYVWAwWpqLGvH7hMZJGua/VU3XxKjw2Z63p2FOy+lz3svUhTeNlQLL3vac9f06+Vkb lZxQ== X-Gm-Message-State: AElRT7HSksff6Q0aEJxHit11OJJPdiNdXEIjsSZnCr0dBK5f5gXwlFTt moEMSnuWBLC8WwbJz8R+Q8PX3A== X-Received: by 10.98.238.2 with SMTP id e2mr2684965pfi.68.1520706020033; Sat, 10 Mar 2018 10:20: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.20.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:20:19 -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 04/83] NOVA inode definition. Date: Sat, 10 Mar 2018 10:17:45 -0800 Message-Id: <1520705944-6723-5-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 inode.h defines the non-volatile and volatile NOVA inode data structures. The non-volatile NOVA inode (nova_inode) is aligned to 128 bytes and contains file/directory metadata information. The most important fields are log_head and log_tail. log_head points to the start of the log, and log_tail points to the end of the latest committed log entry. NOVA make updates to the inode by appending to the log tail and update the log_tail pointer atomically. The volatile NOVA inode (nova_inode_info) contains necessary information to limit access to the non-volatile NOVA inode during runtime. It has a radix tree to map file offset or filenames to the corresponding log entries. Signed-off-by: Andiry Xu --- fs/nova/inode.h | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 fs/nova/inode.h diff --git a/fs/nova/inode.h b/fs/nova/inode.h new file mode 100644 index 0000000..f9187e3 --- /dev/null +++ b/fs/nova/inode.h @@ -0,0 +1,187 @@ +#ifndef __INODE_H +#define __INODE_H + +struct nova_inode_info_header; +struct nova_inode; + +#include "super.h" + +enum nova_new_inode_type { + TYPE_CREATE = 0, + TYPE_MKNOD, + TYPE_SYMLINK, + TYPE_MKDIR +}; + + +/* + * Structure of an inode in PMEM + * Keep the inode size to within 120 bytes: We use the last eight bytes + * as inode table tail pointer. + */ +struct nova_inode { + + /* first 40 bytes */ + u8 i_rsvd; /* reserved. used to be checksum */ + u8 valid; /* Is this inode valid? */ + u8 deleted; /* Is this inode deleted? */ + u8 i_blk_type; /* data block size this inode uses */ + __le32 i_flags; /* Inode flags */ + __le64 i_size; /* Size of data in bytes */ + __le32 i_ctime; /* Inode modification time */ + __le32 i_mtime; /* Inode b-tree Modification time */ + __le32 i_atime; /* Access time */ + __le16 i_mode; /* File mode */ + __le16 i_links_count; /* Links count */ + + __le64 i_xattr; /* Extended attribute block */ + + /* second 40 bytes */ + __le32 i_uid; /* Owner Uid */ + __le32 i_gid; /* Group Id */ + __le32 i_generation; /* File version (for NFS) */ + __le32 i_create_time; /* Create time */ + __le64 nova_ino; /* nova inode number */ + + __le64 log_head; /* Log head pointer */ + __le64 log_tail; /* Log tail pointer */ + + /* last 40 bytes */ + __le64 create_epoch_id; /* Transaction ID when create */ + __le64 delete_epoch_id; /* Transaction ID when deleted */ + + struct { + __le32 rdev; /* major/minor # */ + } dev; /* device inode */ + + __le32 csum; /* CRC32 checksum */ + + /* Leave 8 bytes for inode table tail pointer */ +} __attribute((__packed__)); + +/* + * NOVA-specific inode state kept in DRAM + */ +struct nova_inode_info_header { + /* For files, tree holds a map from file offsets to + * write log entries. + * + * For directories, tree holds a map from a hash of the file name to + * dentry log entry. + */ + struct radix_tree_root tree; + struct rw_semaphore i_sem; /* Protect log and tree */ + unsigned short i_mode; /* Dir or file? */ + unsigned int i_flags; + unsigned long log_pages; /* Num of log pages */ + unsigned long i_size; + unsigned long i_blocks; + unsigned long ino; + unsigned long pi_addr; + unsigned long valid_entries; /* For thorough GC */ + unsigned long num_entries; /* For thorough GC */ + u64 last_setattr; /* Last setattr entry */ + u64 last_link_change; /* Last link change entry */ + u64 last_dentry; /* Last updated dentry */ + u64 trans_id; /* Transaction ID */ + u64 log_head; /* Log head pointer */ + u64 log_tail; /* Log tail pointer */ + u8 i_blk_type; +}; + +/* + * DRAM state for inodes + */ +struct nova_inode_info { + struct nova_inode_info_header header; + struct inode vfs_inode; +}; + + +static inline struct nova_inode_info *NOVA_I(struct inode *inode) +{ + return container_of(inode, struct nova_inode_info, vfs_inode); +} + +static inline void sih_lock(struct nova_inode_info_header *header) +{ + down_write(&header->i_sem); +} + +static inline void sih_unlock(struct nova_inode_info_header *header) +{ + up_write(&header->i_sem); +} + +static inline void sih_lock_shared(struct nova_inode_info_header *header) +{ + down_read(&header->i_sem); +} + +static inline void sih_unlock_shared(struct nova_inode_info_header *header) +{ + up_read(&header->i_sem); +} + +static inline unsigned int +nova_inode_blk_shift(struct nova_inode_info_header *sih) +{ + return blk_type_to_shift[sih->i_blk_type]; +} + +static inline uint32_t nova_inode_blk_size(struct nova_inode_info_header *sih) +{ + return blk_type_to_size[sih->i_blk_type]; +} + +static inline u64 nova_get_reserved_inode_addr(struct super_block *sb, + u64 inode_number) +{ + return (NOVA_DEF_BLOCK_SIZE_4K * RESERVE_INODE_START) + + inode_number * NOVA_INODE_SIZE; +} + +static inline struct nova_inode *nova_get_reserved_inode(struct super_block *sb, + u64 inode_number) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + u64 addr; + + addr = nova_get_reserved_inode_addr(sb, inode_number); + + return (struct nova_inode *)(sbi->virt_addr + addr); +} + +static inline struct nova_inode *nova_get_inode_by_ino(struct super_block *sb, + u64 ino) +{ + if (ino == 0 || ino >= NOVA_NORMAL_INODE_START) + return NULL; + + return nova_get_reserved_inode(sb, ino); +} + +static inline struct nova_inode *nova_get_inode(struct super_block *sb, + struct inode *inode) +{ + struct nova_inode_info *si = NOVA_I(inode); + struct nova_inode_info_header *sih = &si->header; + struct nova_inode fake_pi; + void *addr; + int rc; + + addr = nova_get_block(sb, sih->pi_addr); + rc = memcpy_mcsafe(&fake_pi, addr, sizeof(struct nova_inode)); + if (rc) + return NULL; + + return (struct nova_inode *)addr; +} + +static inline int nova_persist_inode(struct nova_inode *pi) +{ + nova_flush_buffer(pi, sizeof(struct nova_inode), 1); + return 0; +} + +#endif -- 2.7.4