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