xref: /dragonfly/sys/sys/mountctl.h (revision 49837aef)
1 /*
2  * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
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  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #ifndef _SYS_MOUNTCTL_H_
36 #define _SYS_MOUNTCTL_H_
37 
38 #ifndef _SYS_TYPES_H_
39 #include <sys/types.h>
40 #endif
41 #ifndef _SYS_TIME_H_
42 #include <sys/time.h>
43 #endif
44 #ifndef _SYS_QUEUE_H_
45 #include <sys/queue.h>
46 #endif
47 
48 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
49 #ifndef _SYS_THREAD_H_
50 #include <sys/thread.h>
51 #endif
52 #endif
53 
54 /*
55  * General constants
56  */
57 
58 #define JIDMAX		32	/* id string buf[] size (incls \0) */
59 
60 #define MOUNTCTL_INSTALL_VFS_JOURNAL	1
61 #define MOUNTCTL_REMOVE_VFS_JOURNAL	2
62 #define MOUNTCTL_RESYNC_VFS_JOURNAL	3
63 #define MOUNTCTL_STATUS_VFS_JOURNAL	4
64 #define MOUNTCTL_RESTART_VFS_JOURNAL	5
65 
66 #define MOUNTCTL_INSTALL_BLK_JOURNAL	8
67 #define MOUNTCTL_REMOVE_BLK_JOURNAL	9
68 #define MOUNTCTL_RESYNC_BLK_JOURNAL	10
69 #define MOUNTCTL_STATUS_BLK_JOURNAL	11
70 
71 #define MOUNTCTL_SET_EXPORT		16	/* sys/mount.h:export_args */
72 #define MOUNTCTL_STATVFS		17	/* get extended stats */
73 #define MOUNTCTL_MOUNTFLAGS		18	/* extract mountflags */
74 
75 /*
76  * Data structures for the journaling API
77  */
78 
79 struct mountctl_install_journal {
80 	char	id[JIDMAX];
81 	int	flags;		/* journaling flags */
82 	int	unused01;
83 	int64_t	membufsize;	/* backing store */
84 	int64_t	swapbufsize;	/* backing store */
85 	int64_t	transid;	/* starting with specified transaction id */
86 	int64_t unused02;
87 	int	stallwarn;	/* stall warning (seconds) */
88 	int	stallerror;	/* stall error (seconds) */
89 	int	unused03;
90 	int	unused04;
91 };
92 
93 #define MC_JOURNAL_UNUSED0001		0x00000001
94 #define MC_JOURNAL_STOP_REQ		0x00000002	/* stop request pend */
95 #define MC_JOURNAL_STOP_IMM		0x00000004	/* STOP+trash fifo */
96 #define MC_JOURNAL_WACTIVE		0x00000008	/* wthread running */
97 #define MC_JOURNAL_RACTIVE		0x00000010	/* rthread running */
98 #define MC_JOURNAL_WWAIT		0x00000040	/* write stall */
99 #define MC_JOURNAL_WANT_AUDIT		0x00010000	/* audit trail */
100 #define MC_JOURNAL_WANT_REVERSABLE	0x00020000	/* reversable stream */
101 #define MC_JOURNAL_WANT_FULLDUPLEX	0x00040000	/* has ack stream */
102 
103 struct mountctl_restart_journal {
104 	char	id[JIDMAX];
105 	int	flags;
106 	int	unused01;
107 };
108 
109 struct mountctl_remove_journal {
110 	char	id[JIDMAX];
111 	int	flags;
112 };
113 
114 #define MC_JOURNAL_REMOVE_TRASH		0x00000001	/* data -> trash */
115 #define MC_JOURNAL_REMOVE_ASSYNC	0x00000002	/* asynchronous op */
116 
117 struct mountctl_status_journal {
118 	char	id[JIDMAX];
119 	int	index;
120 };
121 
122 #define MC_JOURNAL_INDEX_ALL		-2
123 #define MC_JOURNAL_INDEX_ID		-1
124 
125 struct mountctl_journal_ret_status {
126 	int	recsize;
127 	char	id[JIDMAX];
128 	int	index;
129 	int	flags;
130 	int64_t	membufsize;
131 	int64_t	membufused;
132 	int64_t	membufunacked;
133 	int64_t	swapbufsize;
134 	int64_t	swapbufused;
135 	int64_t	swapbufunacked;
136 	int64_t transidstart;
137 	int64_t transidcurrent;
138 	int64_t transidunacked;
139 	int64_t transidacked;
140 	int64_t bytessent;
141 	int64_t bytesacked;
142 	int64_t fifostalls;
143 	int64_t reserved[4];
144 	struct timeval lastack;
145 };
146 
147 #define MC_JOURNAL_STATUS_MORETOCOME	0x00000001
148 
149 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
150 
151 /*
152  * Support structures for the generic journaling structure
153  */
154 struct journal_memfifo {
155 	int	size;		/* size (power of two) */
156 	int	mask;		/* index mask (size - 1) */
157 	int	rindex;		/* stream reader index (track fd writes) */
158 	int	xindex;		/* last acked / reader restart */
159 	int	windex;		/* stream writer index */
160 	char	*membase;	/* memory buffer representing the FIFO */
161 };
162 
163 /*
164  * Generic journaling structure attached to a mount point.
165  */
166 struct journal {
167 	TAILQ_ENTRY(journal) jentry;
168 	struct file	*fp;
169 	char		id[JIDMAX];
170 	int		flags;		/* journaling flags */
171 	int64_t		transid;
172 	int64_t		total_acked;
173 	int64_t		fifostalls;
174 	struct journal_memfifo fifo;
175 	struct thread	wthread;
176 	struct thread	rthread;
177 };
178 
179 
180 /*
181  * The jrecord structure is used to build a journaling transaction.  Since
182  * a single journaling transaction might encompass very large buffers it
183  * is possible for multiple transactions to be written out to the FIFO
184  * in parallel and in peacemeal.
185  */
186 struct jrecord {
187 	struct journal	*jo;
188 	char		*stream_ptr;
189 	int		stream_residual;
190 	int		stream_reserved;
191 	struct journal_rawrecbeg *rawp;
192 	struct journal_subrecord *parent;
193 	struct journal_subrecord *last;
194 	int16_t 	streamid;
195 	int		pushcount;
196 	int		pushptrgood;
197 	int		residual;
198 	int		residual_align;
199 
200 	/*
201 	 * These fields are not used by the jrecord routines.  They may
202 	 * be used by higher level routines to manage multiple jrecords.
203 	 * See the jreclist_*() functions.
204 	 */
205 	TAILQ_ENTRY(jrecord) user_entry;
206 	void *user_save;
207 };
208 
209 struct jrecord_list {
210 	TAILQ_HEAD(, jrecord) list;
211 	int16_t		streamid;
212 };
213 
214 #endif	/* kernel or kernel structures */
215 
216 #if defined(_KERNEL)
217 
218 struct namecache;
219 struct ucred;
220 struct uio;
221 struct xio;
222 struct vnode;
223 struct vattr;
224 struct vm_page;
225 
226 void journal_create_threads(struct journal *jo);
227 void journal_destroy_threads(struct journal *jo, int flags);
228 
229 /*
230  * Primary journal record support procedures
231  */
232 void jrecord_init(struct journal *jo,
233 			struct jrecord *jrec, int16_t streamid);
234 struct journal_subrecord *jrecord_push(
235 			struct jrecord *jrec, int16_t rectype);
236 void jrecord_pop(struct jrecord *jrec, struct journal_subrecord *parent);
237 void jrecord_leaf(struct jrecord *jrec,
238 			int16_t rectype, void *ptr, int bytes);
239 void jrecord_leaf_uio(struct jrecord *jrec,
240 			int16_t rectype, struct uio *uio);
241 void jrecord_leaf_xio(struct jrecord *jrec,
242 			int16_t rectype, struct xio *xio);
243 struct journal_subrecord *jrecord_write(struct jrecord *jrec,
244 			int16_t rectype, int bytes);
245 void jrecord_done(struct jrecord *jrec, int abortit);
246 
247 /*
248  * Rollup journal record support procedures
249  */
250 void jrecord_write_path(struct jrecord *jrec,
251 			int16_t rectype, struct namecache *ncp);
252 void jrecord_write_vattr(struct jrecord *jrec, struct vattr *vat);
253 void jrecord_write_cred(struct jrecord *jrec, struct thread *td,
254 			struct ucred *cred);
255 void jrecord_write_vnode_ref(struct jrecord *jrec, struct vnode *vp);
256 void jrecord_write_vnode_link(struct jrecord *jrec, struct vnode *vp,
257 			struct namecache *notncp);
258 void jrecord_write_pagelist(struct jrecord *jrec, int16_t rectype,
259 			struct vm_page **pglist, int *rtvals, int pgcount,
260 			off_t offset);
261 void jrecord_write_uio(struct jrecord *jrec, int16_t rectype, struct uio *uio);
262 void jrecord_file_data(struct jrecord *jrec, struct vnode *vp,
263 			off_t off, off_t bytes);
264 
265 #ifdef MALLOC_DECLARE
266 MALLOC_DECLARE(M_JOURNAL);
267 MALLOC_DECLARE(M_JFIFO);
268 #endif
269 
270 #else
271 
272 #include <sys/cdefs.h>
273 
274 __BEGIN_DECLS
275 int	mountctl (const char *path, int op, int fd, void *ctl, int ctllen,
276 		  void *buf, int buflen);
277 __END_DECLS
278 
279 #endif	/* kernel */
280 
281 #endif	/* header */
282