xref: /titanic_44/usr/src/uts/common/sys/fs/cachefs_log.h (revision 9dd0f810214fdc8e1af881a9a5c4b6927629ff9e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_FS_CACHEFS_LOG_H
28 #define	_SYS_FS_CACHEFS_LOG_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/types32.h>
34 #include <sys/vfs.h>
35 #include <sys/fs/cachefs_fs.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /* constants, etc. */
42 
43 #define	CACHEFS_LOG_MAGIC	32321
44 #define	CACHEFS_LOG_FILE_REV	    2
45 
46 #define	CACHEFS_LOG_MOUNT		 1
47 #define	CACHEFS_LOG_UMOUNT		 2
48 #define	CACHEFS_LOG_GETPAGE		 3
49 #define	CACHEFS_LOG_READDIR		 4
50 #define	CACHEFS_LOG_READLINK		 5
51 #define	CACHEFS_LOG_REMOVE		 6
52 #define	CACHEFS_LOG_RMDIR		 7
53 #define	CACHEFS_LOG_TRUNCATE		 8
54 #define	CACHEFS_LOG_PUTPAGE		 9
55 #define	CACHEFS_LOG_CREATE		10
56 #define	CACHEFS_LOG_MKDIR		11
57 #define	CACHEFS_LOG_RENAME		12
58 #define	CACHEFS_LOG_SYMLINK		13
59 #define	CACHEFS_LOG_POPULATE		14
60 #define	CACHEFS_LOG_CSYMLINK		15
61 #define	CACHEFS_LOG_FILLDIR		16
62 #define	CACHEFS_LOG_MDCREATE		17
63 #define	CACHEFS_LOG_GPFRONT		18
64 #define	CACHEFS_LOG_RFDIR		19
65 #define	CACHEFS_LOG_UALLOC		20
66 #define	CACHEFS_LOG_CALLOC		21
67 #define	CACHEFS_LOG_NOCACHE		22
68 #define	CACHEFS_LOG_NUMRECS		22
69 
70 /*
71  * cachefs_log_* are stored on disk, so they need to be the same
72  * 32-bit vs. 64-bit.
73  */
74 
75 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
76 #pragma pack(4)
77 #endif
78 
79 /*
80  * for communicating from user to kernel, or for storing state.
81  */
82 
83 typedef struct cachefs_log_control {
84 	int	lc_magic;
85 	char	lc_path[MAXPATHLEN];
86 	uchar_t	lc_which[(CACHEFS_LOG_NUMRECS / NBBY) + 1];
87 	uint64_t lc_cachep; /* really cachefscache_t * */
88 } cachefs_log_control_t;
89 
90 /*
91  * per-cachefscache information
92  */
93 
94 typedef struct cachefs_log_cookie {
95 	void		*cl_head;	/* head of records to be written */
96 	void		*cl_tail;	/* tail of records to be written */
97 	uint_t		cl_size;	/* # of bytes to be written */
98 
99 	struct vnode	*cl_logvp;	/* vnode for logfile */
100 
101 	cachefs_log_control_t *cl_logctl; /* points at ksp->ks_data */
102 
103 	int		cl_magic;	/* cheap sanity check */
104 } cachefs_log_cookie_t;
105 
106 /* macros for determining which things we're logging + misc stuff */
107 #define	CACHEFS_LOG_LOGGING(cp, which)				\
108 	((cp != NULL) &&					\
109 	(cp->c_log != NULL) &&				\
110 	(cp->c_log_ctl->lc_which[which / NBBY] &	\
111 	(1 << (which % NBBY))))
112 #define	CACHEFS_LOG_SET(lc, which)	\
113 	(lc->lc_which[which / NBBY] |= (1 << (which % NBBY)))
114 #define	CACHEFS_LOG_CLEAR(lc, which)	\
115 	(lc->lc_which[which / NBBY] &= ~(1 << (which % NBBY)))
116 #define	CLPAD(sname, field)			\
117 	(sizeof (struct sname) -		\
118 	offsetof(struct sname, field) -	\
119 	sizeof (((struct sname *)0)->field))
120 
121 struct cachefs_log_logfile_header {
122 	uint_t lh_magic;
123 	uint_t lh_revision;
124 	int lh_errno;
125 	uint_t lh_blocks;
126 	uint_t lh_files;
127 	uint_t lh_maxbsize;
128 	uint_t lh_pagesize;
129 };
130 
131 /*
132  * declarations of the logging records.
133  *
134  * note -- the first three fields must be int, int, and time_t (time32_t),
135  * corresponding to record type, error status, and timestamp.
136  *
137  * note -- the size of a trailing string should be large enough to
138  * hold any necessary null-terminating bytes.  i.e. for one string,
139  * say `char foo[1]'.  for two strings, null-separated, say `char
140  * foo[2]'.
141  *
142  * XX64	time32_t (above) is going to be a problem when the underlying
143  *	filesystems support 64-bit time.
144  */
145 
146 /*
147  * XX64 - for now define all time types as 32-bits.
148  */
149 
150 #if (defined(_SYSCALL32) && defined(_LP64))
151 typedef uid32_t		cfs_uid_t;
152 #else /* not _SYSCALL32 && _LP64 */
153 typedef uid_t		cfs_uid_t;
154 #endif /* _SYSCALL32 && _LP64 */
155 
156 struct cachefs_log_mount_record {
157 	int type;		/* == CACHEFS_LOG_MOUNT */
158 	int error;		/* errno */
159 	cfs_time_t time;	/* timestamp */
160 	uint64_t vfsp;		/* vfs pointer -- unique while mounted */
161 	uint_t flags;		/* opt_flags from cachefsoptions */
162 	uint_t popsize;		/* opt_popsize from cachefsoptions */
163 	uint_t fgsize;		/* opt_fgsize from cachefsoptions */
164 	ushort_t pathlen;	/* length of path */
165 	ushort_t cacheidlen;	/* length of cacheid */
166 	char path[2];		/* the path of the mountpoint, and cacheid */
167 };
168 
169 struct cachefs_log_umount_record {
170 	int type;		/* == CACHEFS_LOG_UMOUNT */
171 	int error;		/* errno */
172 	cfs_time_t time;	/* timestamp */
173 	uint64_t vfsp;		/* vfs pointer we're unmounting */
174 };
175 
176 struct cachefs_log_getpage_record {
177 	int type;		/* == CACHEFS_LOG_GETPAGE */
178 	int error;		/* errno */
179 	cfs_time_t time;	/* timestamp */
180 	uint64_t vfsp;		/* which filesystem */
181 	cfs_fid_t fid;		/* file identifier */
182 	ino64_t fileno;		/* fileno */
183 	cfs_uid_t uid;		/* uid of credential */
184 	u_offset_t offset;	/* offset we're getting */
185 	uint_t len;		/* how many bytes we're getting */
186 };
187 
188 struct cachefs_log_readdir_record {
189 	int type;		/* == CACHEFS_LOG_READDIR */
190 	int error;		/* errno */
191 	cfs_time_t time;	/* timestamp */
192 	uint64_t vfsp;		/* which filesystem */
193 	cfs_fid_t fid;		/* file identifier */
194 	ino64_t fileno;		/* fileno */
195 	cfs_uid_t uid;		/* uid of credential */
196 	u_offset_t offset;	/* offset into directory */
197 	int eof;		/* like `*eofp' in VOP_READDIR */
198 };
199 
200 struct cachefs_log_readlink_record {
201 	int type;		/* == CACHEFS_LOG_READLINK */
202 	int error;		/* errno */
203 	cfs_time_t time;	/* timestamp */
204 	uint64_t vfsp;		/* which filesystem */
205 	cfs_fid_t fid;		/* file identifier */
206 	ino64_t fileno;		/* fileno */
207 	cfs_uid_t uid;		/* uid of credential */
208 	uint_t length;		/* length of symlink */
209 };
210 
211 struct cachefs_log_remove_record {
212 	int type;		/* == CACHEFS_LOG_REMOVE */
213 	int error;		/* errno */
214 	cfs_time_t time;	/* timestamp */
215 	uint64_t vfsp;		/* which filesystem */
216 	cfs_fid_t fid;		/* fid of file being removed */
217 				/* (not the directory holding the file) */
218 	ino64_t fileno;		/* fileno */
219 	cfs_uid_t uid;		/* uid of credential */
220 };
221 
222 struct cachefs_log_rmdir_record {
223 	int type;		/* == CACHEFS_LOG_RMDIR */
224 	int error;		/* errno */
225 	cfs_time_t time;	/* timestamp */
226 	uint64_t vfsp;		/* which filesystem */
227 	cfs_fid_t fid;		/* fid of directory being removed */
228 	ino64_t fileno;		/* fileno */
229 	cfs_uid_t uid;		/* uid of credential */
230 };
231 
232 struct cachefs_log_truncate_record {
233 	int type;		/* == CACHEFS_LOG_TRUNCATE */
234 	int error;		/* errno */
235 	cfs_time_t time;	/* timestamp */
236 	uint64_t vfsp;		/* which filesystem */
237 	cfs_fid_t fid;		/* file being truncated */
238 	ino64_t fileno;		/* fileno */
239 	cfs_uid_t uid;		/* uid of credential */
240 	u_offset_t size;	/* new size */
241 };
242 
243 struct cachefs_log_putpage_record {
244 	int type;		/* == CACHEFS_LOG_PUTPAGE */
245 	int error;		/* errno */
246 	cfs_time_t time;	/* timestamp */
247 	uint64_t vfsp;		/* which filesystem */
248 	cfs_fid_t fid;		/* file being written */
249 	ino64_t fileno;		/* fileno */
250 	cfs_uid_t uid;		/* uid of credential */
251 	u_offset_t offset;	/* offset */
252 	uint_t len;		/* length */
253 };
254 
255 struct cachefs_log_create_record {
256 	int type;		/* == CACHEFS_LOG_CREATE */
257 	int error;		/* errno */
258 	cfs_time_t time;	/* timestamp */
259 	uint64_t vfsp;		/* which filesystem */
260 	cfs_fid_t fid;		/* fid of newly created file */
261 	ino64_t fileno;		/* fileno */
262 	cfs_uid_t uid;		/* uid of credential */
263 };
264 
265 struct cachefs_log_mkdir_record {
266 	int type;		/* == CACHEFS_LOG_MKDIR */
267 	int error;		/* errno */
268 	cfs_time_t time;	/* timestamp */
269 	uint64_t vfsp;		/* which filesystem */
270 	cfs_fid_t fid;		/* fid of newly created directory */
271 	ino64_t fileno;		/* fileno */
272 	cfs_uid_t uid;		/* uid of credential */
273 };
274 
275 struct cachefs_log_rename_record {
276 	int type;		/* == CACHEFS_LOG_RENAME */
277 	int error;		/* errno */
278 	cfs_time_t time;	/* timestamp */
279 	uint64_t vfsp;		/* which filesystem */
280 	cfs_fid_t gone;		/* fid of file removed (may be undefined) */
281 	ino64_t fileno;		/* fileno */
282 	int removed;		/* nonzero if file was removed */
283 	cfs_uid_t uid;		/* uid of credential */
284 };
285 
286 struct cachefs_log_symlink_record {
287 	int type;		/* == CACHEFS_LOG_SYMLINK */
288 	int error;		/* errno */
289 	cfs_time_t time;	/* timestamp */
290 	uint64_t vfsp;		/* which filesystem */
291 	cfs_fid_t fid;		/* fid of newly created symlink */
292 	ino64_t fileno;		/* fileno */
293 	uint_t size;		/* size of newly created symlink */
294 	cfs_uid_t uid;		/* uid of credential */
295 };
296 
297 struct cachefs_log_populate_record {
298 	int type;		/* == CACHEFS_LOG_POPULATE */
299 	int error;		/* errno */
300 	cfs_time_t time;	/* timestamp */
301 	uint64_t vfsp;		/* which filesystem */
302 	cfs_fid_t fid;		/* fid of file being populated */
303 	ino64_t fileno;		/* fileno */
304 	u_offset_t off;		/* offset */
305 	uint_t size;		/* popsize */
306 };
307 
308 struct cachefs_log_csymlink_record {
309 	int type;		/* == CACHEFS_LOG_CSYMLINK */
310 	int error;		/* errno */
311 	cfs_time_t time;	/* timestamp */
312 	uint64_t vfsp;		/* which filesystem */
313 	cfs_fid_t fid;		/* fid of symlink being cached */
314 	ino64_t fileno;		/* fileno */
315 	int size;		/* size of symlink being cached */
316 };
317 
318 struct cachefs_log_filldir_record {
319 	int type;		/* == CACHEFS_LOG_FILLDIR */
320 	int error;		/* errno */
321 	cfs_time_t time;	/* timestamp */
322 	uint64_t vfsp;		/* which filesystem */
323 	cfs_fid_t fid;		/* fid of directory being filled */
324 	ino64_t fileno;		/* fileno */
325 	int size;		/* size of frontfile after filling */
326 };
327 
328 struct cachefs_log_mdcreate_record {
329 	int type;		/* == CACHEFS_LOG_MDCREATE */
330 	int error;		/* errno */
331 	cfs_time_t time;	/* timestamp */
332 	uint64_t vfsp;		/* which filesystem */
333 	cfs_fid_t fid;		/* fid of file for whom md slot is created */
334 	ino64_t fileno;		/* fileno */
335 	uint_t count;		/* new number of entries in attrcache */
336 };
337 
338 struct cachefs_log_gpfront_record {
339 	int type;		/* == CACHEFS_LOG_GPFRONT */
340 	int error;		/* errno */
341 	cfs_time_t time;	/* timestamp */
342 	uint64_t vfsp;		/* which filesystem */
343 	cfs_fid_t fid;		/* fid of file for whom md slot is created */
344 	ino64_t fileno;		/* fileno */
345 	cfs_uid_t uid;		/* uid of credential */
346 	u_offset_t off;		/* offset */
347 	uint_t len;		/* length */
348 };
349 
350 struct cachefs_log_rfdir_record {
351 	int type;		/* == CACHEFS_LOG_GPFRONT */
352 	int error;		/* errno */
353 	cfs_time_t time;	/* timestamp */
354 	uint64_t vfsp;		/* which filesystem */
355 	cfs_fid_t fid;		/* fid of directory */
356 	ino64_t fileno;		/* fileno */
357 	cfs_uid_t uid;		/* uid of credential */
358 };
359 
360 struct cachefs_log_ualloc_record {
361 	int type;		/* == CACHEFS_LOG_UALLOC */
362 	int error;		/* errno */
363 	cfs_time_t time;	/* timestamp */
364 	uint64_t vfsp;		/* which filesystem */
365 	cfs_fid_t fid;		/* fid of allocmap-updated file */
366 	ino64_t fileno;		/* fileno of allocmap-updated file */
367 	u_offset_t off;		/* offset of new area */
368 	uint_t len;		/* length of new area */
369 };
370 
371 struct cachefs_log_calloc_record {
372 	int type;		/* == CACHEFS_LOG_CALLOC */
373 	int error;		/* errno */
374 	cfs_time_t time;	/* timestamp */
375 	uint64_t vfsp;		/* which filesystem */
376 	cfs_fid_t fid;		/* fid of allocmap-checked file */
377 	ino64_t fileno;		/* fileno of allocmap-checked file */
378 	u_offset_t off;		/* offset of successful check_allocmap */
379 	uint_t len;		/* length of successful check_allocmap */
380 };
381 
382 struct cachefs_log_nocache_record {
383 	int type;		/* == CACHEFS_LOG_NOCACHE */
384 	int error;		/* errno */
385 	cfs_time_t time;	/* timestamp */
386 	uint64_t vfsp;		/* which filesystem */
387 	cfs_fid_t fid;		/* fid of file being nocached */
388 	ino64_t fileno;		/* fileno of file being nocached */
389 };
390 
391 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
392 #pragma pack()
393 #endif
394 
395 #ifdef __cplusplus
396 }
397 #endif
398 
399 
400 #endif /* _SYS_FS_CACHEFS_LOG_H */
401