From patchwork Sat Mar 10 18:17:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273805 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 14815605D2 for ; Sat, 10 Mar 2018 18:20:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F29BE29762 for ; Sat, 10 Mar 2018 18:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DADAF2975F; Sat, 10 Mar 2018 18:20:30 +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 D723F299B3 for ; Sat, 10 Mar 2018 18:20:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5D0BB22568620; Sat, 10 Mar 2018 10:14:02 -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:c05::243; helo=mail-pg0-x243.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) (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 78B1821E082A6 for ; Sat, 10 Mar 2018 10:14:00 -0800 (PST) Received: by mail-pg0-x243.google.com with SMTP id e3so4833091pga.6 for ; Sat, 10 Mar 2018 10:20:19 -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=V0Gf9BG7l0ALCKyZSvo6HQoDMH8kkZtTR2bY665oyJQ=; b=B/mQ4t8uiGbpj2t0bEfbzx9b2BnZzgMgZnv3kADA/vGJkWQyS+hj91y55LDr9LkKuA 5GbyP5w3oJVPcwFjR8/YjtGFF234lEfbMDXHvSV+PFDle1WIPzMgqvu86eZucE9PTMJG c7l8WZ/CSYdW4phq7xxStOg0w0v3vgY98WNpQ= 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=V0Gf9BG7l0ALCKyZSvo6HQoDMH8kkZtTR2bY665oyJQ=; b=gCqJtajqbHxZ5C6sifPiEN2ddFG86QSf946AFYcCWHDDmvvU91g7JRs56Cs/gMG76W b8LS4f1IzUk3KpDBIHGBCsPknoorMjJF10rrHt20VZseaIw3Eedat+1cPHrbyOZbey2g DleP9iDWgQR13icNMGQhXOqDzc/lm8VZ5V6ig/mYfIlFvTVH7X4ozZtnekOx0CIOPpqI ey9jlbrZr4IT70+ZEi0rSnEFh3vaDhvB8h883eL7zhw6os+s2ZSZWag06XHy1tB+L+S9 IyRRqPMDkpRLvxExbfOMFR6sv32IQL6B6VZjk8fqPx/uhtcJf0HwyxKRxDsuY9jLibks /tMg== X-Gm-Message-State: AElRT7Httc0/ZJOu9giwTL7CP63VlYewRbHZId+kxR9ApjZArsjbGhAV N898+SA3lDxNPRA8XYhqvD8QNBN22pk= X-Google-Smtp-Source: AG47ELtp3+qRgnLQIWQx0Wvbjdp+HEWDuqosPY3ORCW1WaYoODdVdQJJd8QZIlH4LRO+CdTXZCmtfw== X-Received: by 10.98.254.6 with SMTP id z6mr2646507pfh.155.1520706018772; Sat, 10 Mar 2018 10:20:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:20:18 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 03/83] Add super.h. Date: Sat, 10 Mar 2018 10:17:44 -0800 Message-Id: <1520705944-6723-4-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 This header file defines NOVA persistent and volatile superblock data structures. It also defines NOVA block layout: Page 0: Superblock Page 1: Reserved inodes Page 2 - 15: Reserved Page 16 - 31: Inode table pointers Page 32 - 47: Journal address pointers Page 48 - 63: Reserved Pages n-2: Replicate reserved inodes Pages n-1: Replicate superblock Other pages are for normal inodes, logs and data. Signed-off-by: Andiry Xu --- fs/nova/super.h | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 fs/nova/super.h diff --git a/fs/nova/super.h b/fs/nova/super.h new file mode 100644 index 0000000..cb53908 --- /dev/null +++ b/fs/nova/super.h @@ -0,0 +1,149 @@ +#ifndef __SUPER_H +#define __SUPER_H +/* + * Structure of the NOVA super block in PMEM + * + * The fields are partitioned into static and dynamic fields. The static fields + * never change after file system creation. This was primarily done because + * nova_get_block() returns NULL if the block offset is 0 (helps in catching + * bugs). So if we modify any field using journaling (for consistency), we + * will have to modify s_sum which is at offset 0. So journaling code fails. + * This (static+dynamic fields) is a temporary solution and can be avoided + * once the file system becomes stable and nova_get_block() returns correct + * pointers even for offset 0. + */ +struct nova_super_block { + /* static fields. they never change after file system creation. + * checksum only validates up to s_start_dynamic field below + */ + __le32 s_sum; /* checksum of this sb */ + __le32 s_magic; /* magic signature */ + __le32 s_padding32; + __le32 s_blocksize; /* blocksize in bytes */ + __le64 s_size; /* total size of fs in bytes */ + char s_volume_name[16]; /* volume name */ + + /* all the dynamic fields should go here */ + __le64 s_epoch_id; /* Epoch ID */ + + /* s_mtime and s_wtime should be together and their order should not be + * changed. we use an 8 byte write to update both of them atomically + */ + __le32 s_mtime; /* mount time */ + __le32 s_wtime; /* write time */ +} __attribute((__packed__)); + +#define NOVA_SB_SIZE 512 /* must be power of two */ + +/* ======================= Reserved blocks ========================= */ + +/* + * Page 0 contains super blocks; + * Page 1 contains reserved inodes; + * Page 2 - 15 are reserved. + * Page 16 - 31 contain pointers to inode tables. + * Page 32 - 47 contain pointers to journal pages. + */ +#define HEAD_RESERVED_BLOCKS 64 +#define NUM_JOURNAL_PAGES 16 + +#define SUPER_BLOCK_START 0 // Superblock +#define RESERVE_INODE_START 1 // Reserved inodes +#define INODE_TABLE_START 16 // inode table pointers +#define JOURNAL_START 32 // journal pointer table + +/* For replica super block and replica reserved inodes */ +#define TAIL_RESERVED_BLOCKS 2 + +/* ======================= Reserved inodes ========================= */ + +/* We have space for 31 reserved inodes */ +#define NOVA_ROOT_INO (1) +#define NOVA_INODETABLE_INO (2) /* Fake inode associated with inode + * stroage. We need this because our + * allocator requires inode to be + * associated with each allocation. + * The data actually lives in linked + * lists in INODE_TABLE_START. */ +#define NOVA_BLOCKNODE_INO (3) /* Storage for allocator state */ +#define NOVA_LITEJOURNAL_INO (4) /* Storage for lightweight journals */ +#define NOVA_INODELIST_INO (5) /* Storage for Inode free list */ + + +/* Normal inode starts at 32 */ +#define NOVA_NORMAL_INODE_START (32) + + + +/* + * NOVA super-block data in DRAM + */ +struct nova_sb_info { + struct super_block *sb; /* VFS super block */ + struct nova_super_block *nova_sb; /* DRAM copy of SB */ + struct block_device *s_bdev; + struct dax_device *s_dax_dev; + + /* + * base physical and virtual address of NOVA (which is also + * the pointer to the super block) + */ + phys_addr_t phys_addr; + void *virt_addr; + void *replica_reserved_inodes_addr; + void *replica_sb_addr; + + unsigned long num_blocks; + + /* Mount options */ + unsigned long bpi; + unsigned long blocksize; + unsigned long initsize; + unsigned long s_mount_opt; + kuid_t uid; /* Mount uid for root directory */ + kgid_t gid; /* Mount gid for root directory */ + umode_t mode; /* Mount mode for root directory */ + atomic_t next_generation; + /* inode tracking */ + unsigned long s_inodes_used_count; + unsigned long head_reserved_blocks; + unsigned long tail_reserved_blocks; + + struct mutex s_lock; /* protects the SB's buffer-head */ + + int cpus; + + /* Current epoch. volatile guarantees visibility */ + volatile u64 s_epoch_id; + + /* ZEROED page for cache page initialized */ + void *zeroed_page; +}; + +static inline struct nova_sb_info *NOVA_SB(struct super_block *sb) +{ + return sb->s_fs_info; +} + +static inline struct nova_super_block +*nova_get_redund_super(struct super_block *sb) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + + return (struct nova_super_block *)(sbi->replica_sb_addr); +} + + +/* If this is part of a read-modify-write of the super block, + * nova_memunlock_super() before calling! + */ +static inline struct nova_super_block *nova_get_super(struct super_block *sb) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + + return (struct nova_super_block *)sbi->virt_addr; +} + +extern void nova_error_mng(struct super_block *sb, const char *fmt, ...); + +#endif