1 /* $NetBSD: nilfs.h,v 1.1 2009/07/18 16:31:42 reinoud Exp $ */ 2 3 /* 4 * Copyright (c) 2008, 2009 Reinoud Zandijk 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 */ 28 29 #ifndef _FS_NILFS_NILFS_H_ 30 #define _FS_NILFS_NILFS_H_ 31 32 #include <sys/queue.h> 33 #include <sys/uio.h> 34 #include <sys/mutex.h> 35 36 #include <sys/bufq.h> 37 #include <sys/disk.h> 38 #include <sys/kthread.h> 39 #include <miscfs/genfs/genfs_node.h> 40 #include "nilfs_fs.h" 41 42 43 /* debug categories */ 44 #define NILFS_DEBUG_VOLUMES 0x000001 45 #define NILFS_DEBUG_VFSCALL 0x000002 46 #define NILFS_DEBUG_CALL 0x000004 47 #define NILFS_DEBUG_LOCKING 0x000008 48 #define NILFS_DEBUG_NODE 0x000010 49 #define NILFS_DEBUG_LOOKUP 0x000020 50 #define NILFS_DEBUG_READDIR 0x000040 51 #define NILFS_DEBUG_TRANSLATE 0x000080 52 #define NILFS_DEBUG_STRATEGY 0x000100 53 #define NILFS_DEBUG_READ 0x000200 54 #define NILFS_DEBUG_WRITE 0x000400 55 #define NILFS_DEBUG_ATTR 0x001000 56 #define NILFS_DEBUG_EXTATTR 0x002000 57 #define NILFS_DEBUG_ALLOC 0x004000 58 #define NILFS_DEBUG_DIRHASH 0x010000 59 #define NILFS_DEBUG_NOTIMPL 0x020000 60 #define NILFS_DEBUG_SHEDULE 0x040000 61 #define NILFS_DEBUG_SYNC 0x100000 62 #define NILFS_DEBUG_PARANOIA 0x200000 63 64 extern int nilfs_verbose; 65 66 /* initial value of nilfs_verbose */ 67 #define NILFS_DEBUGGING 0 68 69 #ifdef DEBUG 70 #define DPRINTF(name, arg) { \ 71 if (nilfs_verbose & NILFS_DEBUG_##name) {\ 72 printf arg;\ 73 };\ 74 } 75 #define DPRINTFIF(name, cond, arg) { \ 76 if (nilfs_verbose & NILFS_DEBUG_##name) { \ 77 if (cond) printf arg;\ 78 };\ 79 } 80 #else 81 #define DPRINTF(name, arg) {} 82 #define DPRINTFIF(name, cond, arg) {} 83 #endif 84 85 86 /* Configuration values */ 87 #define NILFS_INODE_HASHBITS 10 88 #define NILFS_INODE_HASHSIZE (1<<NILFS_INODE_HASHBITS) 89 #define NILFS_INODE_HASHMASK (NILFS_INODE_HASHSIZE - 1) 90 91 92 /* readdir cookies */ 93 #define NILFS_DIRCOOKIE_DOT 1 94 95 96 /* handies */ 97 #define VFSTONILFS(mp) ((struct nilfs_mount *)mp->mnt_data) 98 99 100 /* malloc pools */ 101 MALLOC_DECLARE(M_NILFSMNT); 102 MALLOC_DECLARE(M_NILFSTEMP); 103 104 struct pool nilfs_node_pool; 105 struct nilfs_node; 106 struct nilfs_mount; 107 108 109 /* structure and derivatives */ 110 struct nilfs_mdt { 111 uint32_t entries_per_block; 112 uint32_t entries_per_group; 113 uint32_t blocks_per_group; 114 uint32_t groups_per_desc_block; /* desc is super group */ 115 uint32_t blocks_per_desc_block; /* desc is super group */ 116 }; 117 118 119 /* all that is related to the nilfs itself */ 120 struct nilfs_device { 121 /* device info */ 122 struct vnode *devvp; 123 struct mount *vfs_mountp; 124 int refcnt; 125 126 /* meta : super block etc. */ 127 uint64_t devsize; 128 uint32_t blocksize; 129 struct nilfs_super_block super, super2; 130 struct nilfs_node *dat_node; 131 struct nilfs_node *cp_node; 132 struct nilfs_node *su_node; 133 134 /* segment usage */ 135 /* checkpoints */ 136 137 /* dat structure and derivatives */ 138 struct nilfs_mdt dat_mdt; 139 struct nilfs_mdt ifile_mdt; 140 141 /* running values */ 142 int mount_state; /* ? */ 143 uint64_t last_seg_seq; /* current segment sequence number */ 144 uint64_t last_seg_num; /* last segment */ 145 uint64_t next_seg_num; /* next segment to fill */ 146 uint64_t last_cno; /* current checkpoint number */ 147 struct nilfs_segment_summary last_segsum; 148 struct nilfs_super_root super_root; 149 150 /* syncing and late allocation */ 151 int syncing; /* are we syncing? */ 152 /* XXX sync_cv on what mutex? */ 153 kcondvar_t sync_cv; /* sleeping on sync */ 154 uint32_t uncomitted_bl; /* for free space */ 155 156 /* lists */ 157 STAILQ_HEAD(nilfs_mnts, nilfs_mount) mounts; 158 SLIST_ENTRY(nilfs_device) next_device; 159 }; 160 161 extern SLIST_HEAD(_nilfs_devices, nilfs_device) nilfs_devices; 162 163 164 /* a specific mountpoint; head or a checkpoint/snapshot */ 165 struct nilfs_mount { 166 struct mount *vfs_mountp; 167 struct nilfs_device *nilfsdev; 168 struct nilfs_args mount_args; /* flags RO access */ 169 170 /* instance values */ 171 struct nilfs_node *ifile_node; 172 173 /* hash table to lookup ino -> nilfs_node */ 174 kmutex_t ihash_lock; 175 kmutex_t get_node_lock; 176 LIST_HEAD(, nilfs_node) nilfs_nodes[NILFS_INODE_HASHSIZE]; 177 178 /* lists */ 179 STAILQ_ENTRY(nilfs_mount) next_mount; /* in nilfs_device */ 180 }; 181 182 183 /* 184 * NILFS node describing a file/directory. 185 * 186 * BUGALERT claim node_mutex before reading/writing to prevent inconsistencies ! 187 */ 188 struct nilfs_node { 189 struct genfs_node i_gnode; /* has to be first */ 190 struct vnode *vnode; /* vnode associated */ 191 struct nilfs_mount *ump; 192 struct nilfs_device *nilfsdev; 193 194 ino_t ino; 195 struct nilfs_inode inode; /* readin copy */ 196 struct dirhash *dir_hash; /* if VDIR */ 197 198 /* XXX do we need this lock? */ 199 kmutex_t node_mutex; 200 kcondvar_t node_lock; /* sleeping lock */ 201 char const *lock_fname; 202 int lock_lineno; 203 204 /* misc */ 205 uint32_t i_flags; /* associated flags */ 206 struct lockf *lockf; /* lock list */ 207 208 LIST_ENTRY(nilfs_node) hashchain; /* inside hash line */ 209 }; 210 211 212 /* misc. flags stored in i_flags (XXX needs cleaning up) */ 213 #define IN_ACCESS 0x0001 /* Inode access time update request */ 214 #define IN_CHANGE 0x0002 /* Inode change time update request */ 215 #define IN_UPDATE 0x0004 /* Inode was written to; update mtime*/ 216 #define IN_MODIFY 0x0008 /* Modification time update request */ 217 #define IN_MODIFIED 0x0010 /* node has been modified */ 218 #define IN_ACCESSED 0x0020 /* node has been accessed */ 219 #define IN_RENAME 0x0040 /* node is being renamed. XXX ?? */ 220 #define IN_DELETED 0x0080 /* node is unlinked, no FID reference*/ 221 #define IN_LOCKED 0x0100 /* node is locked by condvar */ 222 #define IN_SYNCED 0x0200 /* node is being used by sync */ 223 #define IN_CALLBACK_ULK 0x0400 /* node will be unlocked by callback */ 224 #define IN_NODE_REBUILD 0x0800 /* node is rebuild */ 225 226 #define IN_FLAGBITS \ 227 "\10\1IN_ACCESS\2IN_CHANGE\3IN_UPDATE\4IN_MODIFY\5IN_MODIFIED" \ 228 "\6IN_ACCESSED\7IN_RENAME\10IN_DELETED\11IN_LOCKED\12IN_SYNCED" \ 229 "\13IN_CALLBACK_ULK\14IN_NODE_REBUILD" 230 231 #endif /* !_FS_NILFS_NILFS_H_ */ 232