Received: by 10.192.165.148 with SMTP id m20csp3585614imm; Mon, 23 Apr 2018 08:57:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/RWCP9CnbIUfrF8EumV6VUKqxP0TQHv7Qqf0ykQ3BDtqhi2i+5Uupn62Ww1q0Q77tLvv7C X-Received: by 10.99.117.93 with SMTP id f29mr16933353pgn.401.1524499046072; Mon, 23 Apr 2018 08:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524499046; cv=none; d=google.com; s=arc-20160816; b=K/SyycZCDgbhNnIKiYppP34cXb2puSxhcFfmMrd5PVFuPe/QY2HYzXuynO3tJUncI6 U2NF1TNCiie4g/zWgQQZ9/2vy2+fbHUP/Vsde+3iEnBs4mWYQ+KjRTVDpH/Bli/NyjCe T+Oz1M11EsjTAMfU3oF6WBjsbzIXKcEKReNsC1esDw5uxYe7iwPLdKnSiqVof3r7byta QZzJ1MqAR+37vuxYdyEXGZIWx4CUktfL4bM9zYur5QXNhgK+hNNyWYU3lSzyuTpH8Ngi PulR2NVhg6P1+2yuEfFjb5SnyFq2+8nl37yPGesMZob9Fh3Oa53UxuKmu1X/8NzOAXbQ MOcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=KP94zFidULxjPXSfcBRvr6E4Y3XEtwXuo9HaDfzw8HY=; b=qv68c136nC5fSDerOSvqior+wY7+hFCvPgG3/CM0k3gZx9KwacQTkY8n6Apo4uZrDe BGXGVYjBM5T+HWFb46d/JnXe2AWMiYnYCdGupEP8aONEssjNl05uJdKBb5L+X6ad8ps9 hpQufdwGKalabmbBu1Dk95RMoGYjaRtT+t1IbM+mctqVOjKdnU25MyW9CoFJQLsmWuT4 7DFEZ+Ai+If5sOy4e0Aeyeq2F3cyoz6ovPcsnzWzJC5A5dv3sSVBAR68qK5iNHAXknzF NbkGk9srvd6oX0IcTmGMbk0t0IJquzDMXn0QEs2MttiiVxnufjAyWRGp7StTRwwuDaZ5 81vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=XaPRjGIJ; 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 k19si10949884pff.41.2018.04.23.08.57.11; Mon, 23 Apr 2018 08:57:26 -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=@eng.ucsd.edu header.s=google header.b=XaPRjGIJ; 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 S932361AbeDWPze (ORCPT + 99 others); Mon, 23 Apr 2018 11:55:34 -0400 Received: from mail-it0-f47.google.com ([209.85.214.47]:39530 "EHLO mail-it0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932238AbeDWPz0 (ORCPT ); Mon, 23 Apr 2018 11:55:26 -0400 Received: by mail-it0-f47.google.com with SMTP id 85-v6so11283765iti.4 for ; Mon, 23 Apr 2018 08:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eng.ucsd.edu; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=KP94zFidULxjPXSfcBRvr6E4Y3XEtwXuo9HaDfzw8HY=; b=XaPRjGIJ1czIULz+VvO5KPI5FPahOkJ1iC74zxlyN9sFxcP8V5N6aY+gHjEPZl98M5 9rNnepVZWiSzzZnBy+UcCpBIbUxW+2HfXEvfDw75ZNKt0oEj/k5sn/eXaR7+kEzLS0n2 Fqz80v46Gfdk+OvsmeBMX8CAfWXX5ktuM3BZ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=KP94zFidULxjPXSfcBRvr6E4Y3XEtwXuo9HaDfzw8HY=; b=d44q/hx0LdyW8TCBIomcevvugr/NlbXPYiFviqMREkz7mITsTwhiSs77pT65iX7KD5 HCO6pei11Gy8zO967gLpy2s16BuPYqfTMUjqpxfVeHzu/jOjUguTRUsF/CShnE5uYROI 6qYQT+8cR9Lsvykk/2YCjEUrEpel2hB+oaebF9QsKw+aMrwncR4VV/G0GGKddDAsntqN ckmbghUONrpVgPO3TSgnmmpkhnFnB1VjkCB32p1p75Df4S8IYBJ8hg96KU/Ms3fXfxiW z5KvDQ8EYxpK7JUWNjraTyMhfR+cNVipIKyxd/Zc0WFuXd274JBVGxec2c85AGdZqjya Oc0w== X-Gm-Message-State: ALQs6tCF8+v1xdipHx+hlxB3sn6j6G3NsVl5Vcha8c89Wb6OaMYC0K2b NsC/+BEKVq6heZOdTHDYEMi35PaXSmal2az0COhGHQ== X-Received: by 2002:a24:56d5:: with SMTP id o204-v6mr15046032itb.88.1524498925721; Mon, 23 Apr 2018 08:55:25 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:58c5:0:0:0:0:0 with HTTP; Mon, 23 Apr 2018 08:55:24 -0700 (PDT) In-Reply-To: <20180423061201.GC26268@magnolia> References: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> <1520705944-6723-7-git-send-email-jix024@eng.ucsd.edu> <20180423061201.GC26268@magnolia> From: Andiry Xu Date: Mon, 23 Apr 2018 08:55:24 -0700 Message-ID: Subject: Re: [RFC v2 06/83] Add inode get/read methods. To: "Darrick J. Wong" Cc: Linux FS Devel , Linux Kernel Mailing List , "linux-nvdimm@lists.01.org" , Dan Williams , "Rudoff, Andy" , Tom Coughlan , Steven Swanson , Dave Chinner , Jan Kara , Steven Whitehouse , miklos@szeredi.hu, Jian Xu , Andiry Xu Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 22, 2018 at 11:12 PM, Darrick J. Wong wrote: > [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 have checksum for inode and all metadata structures in the NOVA-fortis code. I removed them in this patchset to make the code shorter and simpler. >> + 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? > Will fix. >> + 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... > sih is the in-DRAM inode structure, so le64_to_cpu is not needed. When we read inode from pmem (nova_inode *pi) to sih, we need le64_to_cpu(). The endian checking is not performed thoroughly as it only supports x86-64 now. >> + >> + 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. > I will think about that. Thanks. Thanks, Andiry > --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 >>