1*c0e3afd8Sreinoud /* $NetBSD: nilfs.h,v 1.6 2020/03/21 13:38:29 reinoud Exp $ */ 269a586f2Sreinoud 369a586f2Sreinoud /* 469a586f2Sreinoud * Copyright (c) 2008, 2009 Reinoud Zandijk 569a586f2Sreinoud * All rights reserved. 669a586f2Sreinoud * 769a586f2Sreinoud * Redistribution and use in source and binary forms, with or without 869a586f2Sreinoud * modification, are permitted provided that the following conditions 969a586f2Sreinoud * are met: 1069a586f2Sreinoud * 1. Redistributions of source code must retain the above copyright 1169a586f2Sreinoud * notice, this list of conditions and the following disclaimer. 1269a586f2Sreinoud * 2. Redistributions in binary form must reproduce the above copyright 1369a586f2Sreinoud * notice, this list of conditions and the following disclaimer in the 1469a586f2Sreinoud * documentation and/or other materials provided with the distribution. 1569a586f2Sreinoud * 1669a586f2Sreinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1769a586f2Sreinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1869a586f2Sreinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1969a586f2Sreinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2069a586f2Sreinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2169a586f2Sreinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2269a586f2Sreinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2369a586f2Sreinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2469a586f2Sreinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2569a586f2Sreinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2669a586f2Sreinoud * 2769a586f2Sreinoud */ 2869a586f2Sreinoud 2969a586f2Sreinoud #ifndef _FS_NILFS_NILFS_H_ 3069a586f2Sreinoud #define _FS_NILFS_NILFS_H_ 3169a586f2Sreinoud 3269a586f2Sreinoud #include <sys/queue.h> 3369a586f2Sreinoud #include <sys/uio.h> 3469a586f2Sreinoud #include <sys/mutex.h> 3569a586f2Sreinoud 3669a586f2Sreinoud #include <sys/bufq.h> 3769a586f2Sreinoud #include <sys/disk.h> 3869a586f2Sreinoud #include <sys/kthread.h> 3969a586f2Sreinoud #include <miscfs/genfs/genfs_node.h> 4069a586f2Sreinoud #include "nilfs_fs.h" 4169a586f2Sreinoud 4269a586f2Sreinoud 4369a586f2Sreinoud /* debug categories */ 4469a586f2Sreinoud #define NILFS_DEBUG_VOLUMES 0x000001 4569a586f2Sreinoud #define NILFS_DEBUG_VFSCALL 0x000002 4669a586f2Sreinoud #define NILFS_DEBUG_CALL 0x000004 4769a586f2Sreinoud #define NILFS_DEBUG_LOCKING 0x000008 4869a586f2Sreinoud #define NILFS_DEBUG_NODE 0x000010 4969a586f2Sreinoud #define NILFS_DEBUG_LOOKUP 0x000020 5069a586f2Sreinoud #define NILFS_DEBUG_READDIR 0x000040 5169a586f2Sreinoud #define NILFS_DEBUG_TRANSLATE 0x000080 5269a586f2Sreinoud #define NILFS_DEBUG_STRATEGY 0x000100 5369a586f2Sreinoud #define NILFS_DEBUG_READ 0x000200 5469a586f2Sreinoud #define NILFS_DEBUG_WRITE 0x000400 5569a586f2Sreinoud #define NILFS_DEBUG_ATTR 0x001000 5669a586f2Sreinoud #define NILFS_DEBUG_EXTATTR 0x002000 5769a586f2Sreinoud #define NILFS_DEBUG_ALLOC 0x004000 5869a586f2Sreinoud #define NILFS_DEBUG_DIRHASH 0x010000 5969a586f2Sreinoud #define NILFS_DEBUG_NOTIMPL 0x020000 6069a586f2Sreinoud #define NILFS_DEBUG_SHEDULE 0x040000 6169a586f2Sreinoud #define NILFS_DEBUG_SYNC 0x100000 6269a586f2Sreinoud #define NILFS_DEBUG_PARANOIA 0x200000 6369a586f2Sreinoud 6469a586f2Sreinoud extern int nilfs_verbose; 6569a586f2Sreinoud 6669a586f2Sreinoud /* initial value of nilfs_verbose */ 6769a586f2Sreinoud #define NILFS_DEBUGGING 0 6869a586f2Sreinoud 69*c0e3afd8Sreinoud #ifdef DEBUG 7069a586f2Sreinoud #define DPRINTF(name, arg) { \ 7169a586f2Sreinoud if (nilfs_verbose & NILFS_DEBUG_##name) {\ 7269a586f2Sreinoud printf arg;\ 7369a586f2Sreinoud };\ 7469a586f2Sreinoud } 7569a586f2Sreinoud #define DPRINTFIF(name, cond, arg) { \ 7669a586f2Sreinoud if (nilfs_verbose & NILFS_DEBUG_##name) { \ 7769a586f2Sreinoud if (cond) printf arg;\ 7869a586f2Sreinoud };\ 7969a586f2Sreinoud } 8069a586f2Sreinoud #else 8169a586f2Sreinoud #define DPRINTF(name, arg) {} 8269a586f2Sreinoud #define DPRINTFIF(name, cond, arg) {} 8369a586f2Sreinoud #endif 8469a586f2Sreinoud 8569a586f2Sreinoud 8669a586f2Sreinoud /* Configuration values */ 8769a586f2Sreinoud #define NILFS_INODE_HASHBITS 10 8869a586f2Sreinoud #define NILFS_INODE_HASHSIZE (1<<NILFS_INODE_HASHBITS) 8969a586f2Sreinoud #define NILFS_INODE_HASHMASK (NILFS_INODE_HASHSIZE - 1) 9069a586f2Sreinoud 9169a586f2Sreinoud 9269a586f2Sreinoud /* readdir cookies */ 9369a586f2Sreinoud #define NILFS_DIRCOOKIE_DOT 1 9469a586f2Sreinoud 9569a586f2Sreinoud 9669a586f2Sreinoud /* handies */ 9769a586f2Sreinoud #define VFSTONILFS(mp) ((struct nilfs_mount *)mp->mnt_data) 9869a586f2Sreinoud 9969a586f2Sreinoud 10069a586f2Sreinoud /* malloc pools */ 10169a586f2Sreinoud MALLOC_DECLARE(M_NILFSMNT); 10269a586f2Sreinoud MALLOC_DECLARE(M_NILFSTEMP); 10369a586f2Sreinoud 104b1afbb31Smatt extern struct pool nilfs_node_pool; 10569a586f2Sreinoud struct nilfs_node; 10669a586f2Sreinoud struct nilfs_mount; 10769a586f2Sreinoud 10869a586f2Sreinoud 1091e439c81Schristos #define NILFS_MAXNAMLEN 255 1101e439c81Schristos 11169a586f2Sreinoud /* structure and derivatives */ 11269a586f2Sreinoud struct nilfs_mdt { 11369a586f2Sreinoud uint32_t entries_per_block; 11469a586f2Sreinoud uint32_t entries_per_group; 11569a586f2Sreinoud uint32_t blocks_per_group; 11669a586f2Sreinoud uint32_t groups_per_desc_block; /* desc is super group */ 11769a586f2Sreinoud uint32_t blocks_per_desc_block; /* desc is super group */ 11869a586f2Sreinoud }; 11969a586f2Sreinoud 12069a586f2Sreinoud 12169a586f2Sreinoud /* all that is related to the nilfs itself */ 12269a586f2Sreinoud struct nilfs_device { 12369a586f2Sreinoud /* device info */ 12469a586f2Sreinoud struct vnode *devvp; 12569a586f2Sreinoud struct mount *vfs_mountp; 12669a586f2Sreinoud int refcnt; 12769a586f2Sreinoud 12869a586f2Sreinoud /* meta : super block etc. */ 12969a586f2Sreinoud uint64_t devsize; 13069a586f2Sreinoud uint32_t blocksize; 13169a586f2Sreinoud struct nilfs_super_block super, super2; 13269a586f2Sreinoud struct nilfs_node *dat_node; 13369a586f2Sreinoud struct nilfs_node *cp_node; 13469a586f2Sreinoud struct nilfs_node *su_node; 13569a586f2Sreinoud 13669a586f2Sreinoud /* segment usage */ 13769a586f2Sreinoud /* checkpoints */ 13869a586f2Sreinoud 13969a586f2Sreinoud /* dat structure and derivatives */ 14069a586f2Sreinoud struct nilfs_mdt dat_mdt; 14169a586f2Sreinoud struct nilfs_mdt ifile_mdt; 14269a586f2Sreinoud 14369a586f2Sreinoud /* running values */ 14469a586f2Sreinoud int mount_state; /* ? */ 14569a586f2Sreinoud uint64_t last_seg_seq; /* current segment sequence number */ 14669a586f2Sreinoud uint64_t last_seg_num; /* last segment */ 14769a586f2Sreinoud uint64_t next_seg_num; /* next segment to fill */ 14869a586f2Sreinoud uint64_t last_cno; /* current checkpoint number */ 14969a586f2Sreinoud struct nilfs_segment_summary last_segsum; 15069a586f2Sreinoud struct nilfs_super_root super_root; 15169a586f2Sreinoud 15269a586f2Sreinoud /* syncing and late allocation */ 15369a586f2Sreinoud int syncing; /* are we syncing? */ 15469a586f2Sreinoud /* XXX sync_cv on what mutex? */ 15569a586f2Sreinoud kcondvar_t sync_cv; /* sleeping on sync */ 15669a586f2Sreinoud uint32_t uncomitted_bl; /* for free space */ 15769a586f2Sreinoud 15869a586f2Sreinoud /* lists */ 15969a586f2Sreinoud STAILQ_HEAD(nilfs_mnts, nilfs_mount) mounts; 16069a586f2Sreinoud SLIST_ENTRY(nilfs_device) next_device; 16169a586f2Sreinoud }; 16269a586f2Sreinoud 16369a586f2Sreinoud extern SLIST_HEAD(_nilfs_devices, nilfs_device) nilfs_devices; 16469a586f2Sreinoud 16569a586f2Sreinoud 16669a586f2Sreinoud /* a specific mountpoint; head or a checkpoint/snapshot */ 16769a586f2Sreinoud struct nilfs_mount { 16869a586f2Sreinoud struct mount *vfs_mountp; 16969a586f2Sreinoud struct nilfs_device *nilfsdev; 17069a586f2Sreinoud struct nilfs_args mount_args; /* flags RO access */ 17169a586f2Sreinoud 17269a586f2Sreinoud /* instance values */ 17369a586f2Sreinoud struct nilfs_node *ifile_node; 17469a586f2Sreinoud 17569a586f2Sreinoud /* lists */ 17669a586f2Sreinoud STAILQ_ENTRY(nilfs_mount) next_mount; /* in nilfs_device */ 17769a586f2Sreinoud }; 17869a586f2Sreinoud 17969a586f2Sreinoud 18069a586f2Sreinoud /* 18169a586f2Sreinoud * NILFS node describing a file/directory. 18269a586f2Sreinoud * 18369a586f2Sreinoud * BUGALERT claim node_mutex before reading/writing to prevent inconsistencies ! 18469a586f2Sreinoud */ 18569a586f2Sreinoud struct nilfs_node { 18669a586f2Sreinoud struct genfs_node i_gnode; /* has to be first */ 18769a586f2Sreinoud struct vnode *vnode; /* vnode associated */ 18869a586f2Sreinoud struct nilfs_mount *ump; 18969a586f2Sreinoud struct nilfs_device *nilfsdev; 19069a586f2Sreinoud 19169a586f2Sreinoud ino_t ino; 19269a586f2Sreinoud struct nilfs_inode inode; /* readin copy */ 19369a586f2Sreinoud struct dirhash *dir_hash; /* if VDIR */ 19469a586f2Sreinoud 19569a586f2Sreinoud /* XXX do we need this lock? */ 19669a586f2Sreinoud kmutex_t node_mutex; 19769a586f2Sreinoud kcondvar_t node_lock; /* sleeping lock */ 19869a586f2Sreinoud char const *lock_fname; 19969a586f2Sreinoud int lock_lineno; 20069a586f2Sreinoud 20169a586f2Sreinoud /* misc */ 20269a586f2Sreinoud uint32_t i_flags; /* associated flags */ 20369a586f2Sreinoud struct lockf *lockf; /* lock list */ 20469a586f2Sreinoud 20569a586f2Sreinoud LIST_ENTRY(nilfs_node) hashchain; /* inside hash line */ 20669a586f2Sreinoud }; 20769a586f2Sreinoud 20869a586f2Sreinoud 20969a586f2Sreinoud /* misc. flags stored in i_flags (XXX needs cleaning up) */ 21069a586f2Sreinoud #define IN_ACCESS 0x0001 /* Inode access time update request */ 21169a586f2Sreinoud #define IN_CHANGE 0x0002 /* Inode change time update request */ 21269a586f2Sreinoud #define IN_UPDATE 0x0004 /* Inode was written to; update mtime*/ 21369a586f2Sreinoud #define IN_MODIFY 0x0008 /* Modification time update request */ 21469a586f2Sreinoud #define IN_MODIFIED 0x0010 /* node has been modified */ 21569a586f2Sreinoud #define IN_ACCESSED 0x0020 /* node has been accessed */ 21669a586f2Sreinoud #define IN_RENAME 0x0040 /* node is being renamed. XXX ?? */ 21769a586f2Sreinoud #define IN_DELETED 0x0080 /* node is unlinked, no FID reference*/ 21869a586f2Sreinoud #define IN_LOCKED 0x0100 /* node is locked by condvar */ 21969a586f2Sreinoud #define IN_SYNCED 0x0200 /* node is being used by sync */ 22069a586f2Sreinoud #define IN_CALLBACK_ULK 0x0400 /* node will be unlocked by callback */ 22169a586f2Sreinoud #define IN_NODE_REBUILD 0x0800 /* node is rebuild */ 22269a586f2Sreinoud 22369a586f2Sreinoud #define IN_FLAGBITS \ 22469a586f2Sreinoud "\10\1IN_ACCESS\2IN_CHANGE\3IN_UPDATE\4IN_MODIFY\5IN_MODIFIED" \ 22569a586f2Sreinoud "\6IN_ACCESSED\7IN_RENAME\10IN_DELETED\11IN_LOCKED\12IN_SYNCED" \ 22669a586f2Sreinoud "\13IN_CALLBACK_ULK\14IN_NODE_REBUILD" 22769a586f2Sreinoud 22869a586f2Sreinoud #endif /* !_FS_NILFS_NILFS_H_ */ 229