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
64extern 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 */
101MALLOC_DECLARE(M_NILFSMNT);
102MALLOC_DECLARE(M_NILFSTEMP);
103
104struct pool nilfs_node_pool;
105struct nilfs_node;
106struct nilfs_mount;
107
108
109#define NILFS_MAXNAMLEN	255
110
111/* structure and derivatives */
112struct nilfs_mdt {
113	uint32_t  entries_per_block;
114	uint32_t  entries_per_group;
115	uint32_t  blocks_per_group;
116	uint32_t  groups_per_desc_block;	/* desc is super group */
117	uint32_t  blocks_per_desc_block;	/* desc is super group */
118};
119
120
121/* all that is related to the nilfs itself */
122struct nilfs_device {
123	/* device info */
124	struct vnode		*devvp;
125	struct mount		*vfs_mountp;
126	int 			 refcnt;
127
128	/* meta : super block etc. */
129	uint64_t devsize;
130	uint32_t blocksize;
131	struct nilfs_super_block super, super2;
132	struct nilfs_node	*dat_node;
133	struct nilfs_node	*cp_node;
134	struct nilfs_node	*su_node;
135
136	/* segment usage */
137	/* checkpoints   */
138
139	/* dat structure and derivatives */
140	struct nilfs_mdt	 dat_mdt;
141	struct nilfs_mdt	 ifile_mdt;
142
143	/* running values */
144	int	 mount_state;	/* ? */
145	uint64_t last_seg_seq;	/* current segment sequence number */
146	uint64_t last_seg_num;	/* last segment                    */
147	uint64_t next_seg_num;	/* next segment to fill            */
148	uint64_t last_cno;	/* current checkpoint number       */
149	struct nilfs_segment_summary last_segsum;
150	struct nilfs_super_root      super_root;
151
152	/* syncing and late allocation */
153	int			 syncing;		/* are we syncing?   */
154	/* XXX sync_cv on what mutex? */
155	kcondvar_t 		 sync_cv;		/* sleeping on sync  */
156	uint32_t		 uncomitted_bl;		/* for free space    */
157
158	/* lists */
159	STAILQ_HEAD(nilfs_mnts, nilfs_mount) mounts;
160	SLIST_ENTRY(nilfs_device) next_device;
161};
162
163extern SLIST_HEAD(_nilfs_devices, nilfs_device) nilfs_devices;
164
165
166/* a specific mountpoint; head or a checkpoint/snapshot */
167struct nilfs_mount {
168	struct mount		*vfs_mountp;
169	struct nilfs_device	*nilfsdev;
170	struct nilfs_args	 mount_args;		/* flags RO access */
171
172	/* instance values */
173	struct nilfs_node	*ifile_node;
174
175	/* hash table to lookup ino -> nilfs_node */
176	kmutex_t		 ihash_lock;
177	kmutex_t		 get_node_lock;
178	LIST_HEAD(, nilfs_node)  nilfs_nodes[NILFS_INODE_HASHSIZE];
179
180	/* lists */
181	STAILQ_ENTRY(nilfs_mount) next_mount;		/* in nilfs_device   */
182};
183
184
185/*
186 * NILFS node describing a file/directory.
187 *
188 * BUGALERT claim node_mutex before reading/writing to prevent inconsistencies !
189 */
190struct nilfs_node {
191	struct genfs_node	 i_gnode;		/* has to be first   */
192	struct vnode		*vnode;			/* vnode associated  */
193	struct nilfs_mount	*ump;
194	struct nilfs_device	*nilfsdev;
195
196	ino_t			 ino;
197	struct nilfs_inode	 inode;			/* readin copy */
198	struct dirhash		*dir_hash;		/* if VDIR */
199
200	/* XXX do we need this lock? */
201	kmutex_t		 node_mutex;
202	kcondvar_t		 node_lock;		/* sleeping lock */
203	char const		*lock_fname;
204	int			 lock_lineno;
205
206	/* misc */
207	uint32_t		 i_flags;		/* associated flags  */
208	struct lockf		*lockf;			/* lock list         */
209
210	LIST_ENTRY(nilfs_node)	 hashchain;		/* inside hash line  */
211};
212
213
214/* misc. flags stored in i_flags (XXX needs cleaning up) */
215#define	IN_ACCESS		0x0001	/* Inode access time update request  */
216#define	IN_CHANGE		0x0002	/* Inode change time update request  */
217#define	IN_UPDATE		0x0004	/* Inode was written to; update mtime*/
218#define	IN_MODIFY		0x0008	/* Modification time update request  */
219#define	IN_MODIFIED		0x0010	/* node has been modified */
220#define	IN_ACCESSED		0x0020	/* node has been accessed */
221#define	IN_RENAME		0x0040	/* node is being renamed. XXX ?? */
222#define	IN_DELETED		0x0080	/* node is unlinked, no FID reference*/
223#define	IN_LOCKED		0x0100	/* node is locked by condvar */
224#define	IN_SYNCED		0x0200	/* node is being used by sync */
225#define	IN_CALLBACK_ULK		0x0400	/* node will be unlocked by callback */
226#define	IN_NODE_REBUILD		0x0800	/* node is rebuild */
227
228#define IN_FLAGBITS \
229	"\10\1IN_ACCESS\2IN_CHANGE\3IN_UPDATE\4IN_MODIFY\5IN_MODIFIED" \
230	"\6IN_ACCESSED\7IN_RENAME\10IN_DELETED\11IN_LOCKED\12IN_SYNCED" \
231	"\13IN_CALLBACK_ULK\14IN_NODE_REBUILD"
232
233#endif /* !_FS_NILFS_NILFS_H_ */
234