xref: /netbsd/sys/fs/nilfs/nilfs.h (revision 2a71850e)
1 /* $NetBSD: nilfs.h,v 1.6 2020/03/21 13:38:29 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 extern struct pool nilfs_node_pool;
105 struct nilfs_node;
106 struct nilfs_mount;
107 
108 
109 #define NILFS_MAXNAMLEN	255
110 
111 /* structure and derivatives */
112 struct 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 */
122 struct 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 
163 extern SLIST_HEAD(_nilfs_devices, nilfs_device) nilfs_devices;
164 
165 
166 /* a specific mountpoint; head or a checkpoint/snapshot */
167 struct 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 	/* lists */
176 	STAILQ_ENTRY(nilfs_mount) next_mount;		/* in nilfs_device   */
177 };
178 
179 
180 /*
181  * NILFS node describing a file/directory.
182  *
183  * BUGALERT claim node_mutex before reading/writing to prevent inconsistencies !
184  */
185 struct nilfs_node {
186 	struct genfs_node	 i_gnode;		/* has to be first   */
187 	struct vnode		*vnode;			/* vnode associated  */
188 	struct nilfs_mount	*ump;
189 	struct nilfs_device	*nilfsdev;
190 
191 	ino_t			 ino;
192 	struct nilfs_inode	 inode;			/* readin copy */
193 	struct dirhash		*dir_hash;		/* if VDIR */
194 
195 	/* XXX do we need this lock? */
196 	kmutex_t		 node_mutex;
197 	kcondvar_t		 node_lock;		/* sleeping lock */
198 	char const		*lock_fname;
199 	int			 lock_lineno;
200 
201 	/* misc */
202 	uint32_t		 i_flags;		/* associated flags  */
203 	struct lockf		*lockf;			/* lock list         */
204 
205 	LIST_ENTRY(nilfs_node)	 hashchain;		/* inside hash line  */
206 };
207 
208 
209 /* misc. flags stored in i_flags (XXX needs cleaning up) */
210 #define	IN_ACCESS		0x0001	/* Inode access time update request  */
211 #define	IN_CHANGE		0x0002	/* Inode change time update request  */
212 #define	IN_UPDATE		0x0004	/* Inode was written to; update mtime*/
213 #define	IN_MODIFY		0x0008	/* Modification time update request  */
214 #define	IN_MODIFIED		0x0010	/* node has been modified */
215 #define	IN_ACCESSED		0x0020	/* node has been accessed */
216 #define	IN_RENAME		0x0040	/* node is being renamed. XXX ?? */
217 #define	IN_DELETED		0x0080	/* node is unlinked, no FID reference*/
218 #define	IN_LOCKED		0x0100	/* node is locked by condvar */
219 #define	IN_SYNCED		0x0200	/* node is being used by sync */
220 #define	IN_CALLBACK_ULK		0x0400	/* node will be unlocked by callback */
221 #define	IN_NODE_REBUILD		0x0800	/* node is rebuild */
222 
223 #define IN_FLAGBITS \
224 	"\10\1IN_ACCESS\2IN_CHANGE\3IN_UPDATE\4IN_MODIFY\5IN_MODIFIED" \
225 	"\6IN_ACCESSED\7IN_RENAME\10IN_DELETED\11IN_LOCKED\12IN_SYNCED" \
226 	"\13IN_CALLBACK_ULK\14IN_NODE_REBUILD"
227 
228 #endif /* !_FS_NILFS_NILFS_H_ */
229