Received: by 10.192.165.148 with SMTP id m20csp3070050imm; Sun, 22 Apr 2018 23:21:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx48m02717hZDsbJ80ntRkIu8WDNK9iDZ1/sSDlLAVcBTn7G/6SActSbiMWFZt8hbQ/h/pVUG X-Received: by 2002:a17:902:820d:: with SMTP id x13-v6mr19030483pln.225.1524464464640; Sun, 22 Apr 2018 23:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524464464; cv=none; d=google.com; s=arc-20160816; b=1I1zC5TduTYH3bllSkXC89iHFvAkQToX3V8lvO4Xn/+S7W/wwx95Cpz6jsnzJtzwcB PZXdBf3C0jFg96dyayUmYPdLokMwEs32ylASXtLThM8AznHcCN0WwfFe7RL/jkas8AfL gv3VW5AAHKL2KJpeOY6RDz5t8Axx2mKFT0OjtSCiQMTSCK+7qBAbDlpwd1LAdu/6r5Q3 PULC0/AOQytTKgt36n2xHEdDGkvVtqTL8wxw6UzuXpCHyJ1lFA4+NgIPcEhg8CUjjhfn O+4I9BSJGOgTzbAiR43/LVBhiO8NdJ467WOCi7w4csDMp1d1U4kEVquFz20TIfFtBNRN htMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=QLGo0v1JaPWdHZ8Od+Q1yuRsmP4UgdEFF7r9cZci+Ko=; b=PwM8T55dAHaYVARv2lwn8abczJS925AX68mkg5l0jxpdVpOPsxXo4Fyqocjc6ZN9IJ 3XNM+vXhjO0dtE4O5kDeNjLEQY6K60T9UvONVUytJt2+xCJpwJJvodApL2RiIpyhnG3a D/+jcb5+FyX+pmvwJHQmwGAHkjjI8PNc9s22y2Dka/oJPOttABD2rLW/ugIwCQLQ6ODd loTDbC9oa0fzWQsCsSv3B89b6M4suRH3acrbYfk8D74RGr7bSYQYhaByBdP9Szl+a79f 6J5ZMNMEk/n5b6YLpPTtiS/1BDZJbHOT/PVc6D22GrGq6+FkaIbph3skDr273pY2Vzd0 rusg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=h96btOKK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m6-v6si7844659pln.382.2018.04.22.23.20.50; Sun, 22 Apr 2018 23:21:04 -0700 (PDT) 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=@oracle.com header.s=corp-2017-10-26 header.b=h96btOKK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751503AbeDWGSp (ORCPT + 99 others); Mon, 23 Apr 2018 02:18:45 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:53714 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750852AbeDWGSm (ORCPT ); Mon, 23 Apr 2018 02:18:42 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3N6Awhr010391; Mon, 23 Apr 2018 06:12:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=QLGo0v1JaPWdHZ8Od+Q1yuRsmP4UgdEFF7r9cZci+Ko=; b=h96btOKK1OylWlQnwYoycAyp5fLZ9Ow/G9W4TBU5yLuM7gfIzUDdoBOYJr2UD81016Hr 3cvyQhBICLAvUzC+hEFT+SrEDCZbqE9VDYwbugAS5iWeqNABNaAQBwx326QLAgSYHyhd qukwfLSACb1crccXODPVkUUDUnFLz0k/4UBp511K+k68FGD+WKddhC6VQ+ODgO5PybdK VkCHO13L3C9TfWihiMxSWl1jxZnzGvsSjD+1DYMrV7cekF/X/omOdfX9kolJVxuG5yob CDhevucKzxqjeLnLCtbOv4ghpazEiQrRakim+W+qzTD+0G1AIZzg8tNPtGiukwPxbBTF 2g== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2hfvrbkncq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Apr 2018 06:12:08 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w3N6C6pq026562 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Apr 2018 06:12:07 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w3N6C4Yd004903; Mon, 23 Apr 2018 06:12:04 GMT Received: from localhost (/174.23.196.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 22 Apr 2018 23:12:03 -0700 Date: Sun, 22 Apr 2018 23:12:01 -0700 From: "Darrick J. Wong" To: Andiry Xu Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, 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: Re: [RFC v2 06/83] Add inode get/read methods. Message-ID: <20180423061201.GC26268@magnolia> References: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> <1520705944-6723-7-git-send-email-jix024@eng.ucsd.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1520705944-6723-7-git-send-email-jix024@eng.ucsd.edu> User-Agent: Mutt/1.5.24 (2015-08-30) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8871 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=888 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804230066 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [haaa, I finally found time to read more of these] On Sat, Mar 10, 2018 at 10:17:47AM -0800, Andiry Xu wrote: > From: Andiry Xu > > These routines are incomplete and currently only support reserved inodes, > whose addresses are fixed. This is necessary for fill_super to work. > File/dir operations are left NULL. > > Signed-off-by: Andiry Xu > --- > fs/nova/inode.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > fs/nova/inode.h | 3 + > 2 files changed, 179 insertions(+) > create mode 100644 fs/nova/inode.c > > diff --git a/fs/nova/inode.c b/fs/nova/inode.c > new file mode 100644 > index 0000000..bfdc5dc > --- /dev/null > +++ b/fs/nova/inode.c > @@ -0,0 +1,176 @@ > +/* > + * BRIEF DESCRIPTION > + * > + * Inode methods (allocate/free/read/write). > + * > + * 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 > +#include > +#include > +#include > +#include > +#include > +#include "nova.h" > +#include "inode.h" > + > +unsigned int blk_type_to_shift[NOVA_BLOCK_TYPE_MAX] = {12, 21, 30}; > +uint32_t blk_type_to_size[NOVA_BLOCK_TYPE_MAX] = {0x1000, 0x200000, 0x40000000}; > + > +void nova_set_inode_flags(struct inode *inode, struct nova_inode *pi, > + unsigned int flags) > +{ > + inode->i_flags &= > + ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | S_DIRSYNC); > + if (flags & FS_SYNC_FL) > + inode->i_flags |= S_SYNC; > + if (flags & FS_APPEND_FL) > + inode->i_flags |= S_APPEND; > + if (flags & FS_IMMUTABLE_FL) > + inode->i_flags |= S_IMMUTABLE; > + if (flags & FS_NOATIME_FL) > + inode->i_flags |= S_NOATIME; > + if (flags & FS_DIRSYNC_FL) > + inode->i_flags |= S_DIRSYNC; > + if (!pi->i_xattr) > + inode_has_no_xattr(inode); > + inode->i_flags |= S_DAX; > +} > + > +/* copy persistent state to struct inode */ > +static int nova_read_inode(struct super_block *sb, struct inode *inode, > + u64 pi_addr) > +{ > + struct nova_inode_info *si = NOVA_I(inode); > + struct nova_inode *pi, fake_pi; > + struct nova_inode_info_header *sih = &si->header; > + int ret = -EIO; > + unsigned long ino; > + > + ret = nova_get_reference(sb, pi_addr, &fake_pi, > + (void **)&pi, sizeof(struct nova_inode)); > + if (ret) { > + nova_dbg("%s: read pi @ 0x%llx failed\n", > + __func__, pi_addr); > + goto bad_inode; > + } > + > + inode->i_mode = sih->i_mode; Hm, do you validate the on-pmem metadata as it's read in? What if i_mode is garbage? > + i_uid_write(inode, le32_to_cpu(pi->i_uid)); > + i_gid_write(inode, le32_to_cpu(pi->i_gid)); > +// set_nlink(inode, le16_to_cpu(pi->i_links_count)); C++ comment? > + inode->i_generation = le32_to_cpu(pi->i_generation); > + nova_set_inode_flags(inode, pi, le32_to_cpu(pi->i_flags)); > + ino = inode->i_ino; > + > + /* check if the inode is active. */ > + if (inode->i_mode == 0 || pi->deleted == 1) { > + /* this inode is deleted */ > + ret = -ESTALE; > + goto bad_inode; > + } > + > + inode->i_blocks = sih->i_blocks; Not le64_to_cpu(sih->i_blocks)? Or is that somewhere else I'm missing... > + > + switch (inode->i_mode & S_IFMT) { > + case S_IFREG: > + break; > + case S_IFDIR: > + break; > + case S_IFLNK: > + break; > + default: > + init_special_inode(inode, inode->i_mode, > + le32_to_cpu(pi->dev.rdev)); > + break; > + } > + > + /* Update size and time after rebuild the tree */ > + inode->i_size = le64_to_cpu(sih->i_size); FWIW the type of i_size is loff_t, which is an unsigned type. Despite this, the VFS does not support files with negative sizes... which means that this probably ought to check for that. --D > + inode->i_atime.tv_sec = (__s32)le32_to_cpu(pi->i_atime); > + inode->i_ctime.tv_sec = (__s32)le32_to_cpu(pi->i_ctime); > + inode->i_mtime.tv_sec = (__s32)le32_to_cpu(pi->i_mtime); > + inode->i_atime.tv_nsec = inode->i_mtime.tv_nsec = > + inode->i_ctime.tv_nsec = 0; > + set_nlink(inode, le16_to_cpu(pi->i_links_count)); > + return 0; > + > +bad_inode: > + make_bad_inode(inode); > + return ret; > +} > + > +/* Get the address in PMEM of an inode by inode number. Allocate additional > + * block to store additional inodes if necessary. > + */ > +int nova_get_inode_address(struct super_block *sb, u64 ino, > + u64 *pi_addr, int extendable) > +{ > + if (ino < NOVA_NORMAL_INODE_START) { > + *pi_addr = nova_get_reserved_inode_addr(sb, ino); > + return 0; > + } > + > + *pi_addr = 0; > + return 0; > +} > + > +struct inode *nova_iget(struct super_block *sb, unsigned long ino) > +{ > + struct nova_inode_info *si; > + struct inode *inode; > + u64 pi_addr; > + int err; > + > + inode = iget_locked(sb, ino); > + if (unlikely(!inode)) > + return ERR_PTR(-ENOMEM); > + if (!(inode->i_state & I_NEW)) > + return inode; > + > + si = NOVA_I(inode); > + > + nova_dbgv("%s: inode %lu\n", __func__, ino); > + > + err = nova_get_inode_address(sb, ino, &pi_addr, 0); > + if (err) { > + nova_dbg("%s: get inode %lu address failed %d\n", > + __func__, ino, err); > + goto fail; > + } > + > + if (pi_addr == 0) { > + nova_dbg("%s: failed to get pi_addr for inode %lu\n", > + __func__, ino); > + err = -EACCES; > + goto fail; > + } > + > + err = nova_read_inode(sb, inode, pi_addr); > + if (unlikely(err)) { > + nova_dbg("%s: failed to read inode %lu\n", __func__, ino); > + goto fail; > + > + } > + > + inode->i_ino = ino; > + > + unlock_new_inode(inode); > + return inode; > +fail: > + iget_failed(inode); > + return ERR_PTR(err); > +} > + > diff --git a/fs/nova/inode.h b/fs/nova/inode.h > index f9187e3..dbd5256 100644 > --- a/fs/nova/inode.h > +++ b/fs/nova/inode.h > @@ -184,4 +184,7 @@ static inline int nova_persist_inode(struct nova_inode *pi) > return 0; > } > > +int nova_get_inode_address(struct super_block *sb, u64 ino, > + u64 *pi_addr, int extendable); > +struct inode *nova_iget(struct super_block *sb, unsigned long ino); > #endif > -- > 2.7.4 >