xref: /dragonfly/sys/sys/mountctl.h (revision 805c8e8e)
1949ecb9bSMatthew Dillon /*
2949ecb9bSMatthew Dillon  * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
3949ecb9bSMatthew Dillon  *
4949ecb9bSMatthew Dillon  * This code is derived from software contributed to The DragonFly Project
5949ecb9bSMatthew Dillon  * by Matthew Dillon <dillon@backplane.com>
6949ecb9bSMatthew Dillon  *
7949ecb9bSMatthew Dillon  * Redistribution and use in source and binary forms, with or without
8949ecb9bSMatthew Dillon  * modification, are permitted provided that the following conditions
9949ecb9bSMatthew Dillon  * are met:
10949ecb9bSMatthew Dillon  *
11949ecb9bSMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
12949ecb9bSMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
13949ecb9bSMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
14949ecb9bSMatthew Dillon  *    notice, this list of conditions and the following disclaimer in
15949ecb9bSMatthew Dillon  *    the documentation and/or other materials provided with the
16949ecb9bSMatthew Dillon  *    distribution.
17949ecb9bSMatthew Dillon  * 3. Neither the name of The DragonFly Project nor the names of its
18949ecb9bSMatthew Dillon  *    contributors may be used to endorse or promote products derived
19949ecb9bSMatthew Dillon  *    from this software without specific, prior written permission.
20949ecb9bSMatthew Dillon  *
21949ecb9bSMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22949ecb9bSMatthew Dillon  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23949ecb9bSMatthew Dillon  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24949ecb9bSMatthew Dillon  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25949ecb9bSMatthew Dillon  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26949ecb9bSMatthew Dillon  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27949ecb9bSMatthew Dillon  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28949ecb9bSMatthew Dillon  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29949ecb9bSMatthew Dillon  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30949ecb9bSMatthew Dillon  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31949ecb9bSMatthew Dillon  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32949ecb9bSMatthew Dillon  * SUCH DAMAGE.
33949ecb9bSMatthew Dillon  */
34949ecb9bSMatthew Dillon 
35b2f7ec6cSMatthew Dillon #ifndef _SYS_MOUNTCTL_H_
36b2f7ec6cSMatthew Dillon #define _SYS_MOUNTCTL_H_
371bd40720SMatthew Dillon 
381bd40720SMatthew Dillon #ifndef _SYS_TYPES_H_
391bd40720SMatthew Dillon #include <sys/types.h>
401bd40720SMatthew Dillon #endif
411bd40720SMatthew Dillon #ifndef _SYS_TIME_H_
421bd40720SMatthew Dillon #include <sys/time.h>
431bd40720SMatthew Dillon #endif
441bd40720SMatthew Dillon #ifndef _SYS_QUEUE_H_
451bd40720SMatthew Dillon #include <sys/queue.h>
461bd40720SMatthew Dillon #endif
471bd40720SMatthew Dillon 
48*805c8e8eSzrj #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
496f9b7349SMatthew Dillon #ifndef _SYS_THREAD_H_
506f9b7349SMatthew Dillon #include <sys/thread.h>
516f9b7349SMatthew Dillon #endif
521bd40720SMatthew Dillon #endif
531bd40720SMatthew Dillon 
54949ecb9bSMatthew Dillon /*
552281065eSMatthew Dillon  * General constants
562281065eSMatthew Dillon  */
572281065eSMatthew Dillon 
582281065eSMatthew Dillon #define JIDMAX		32	/* id string buf[] size (incls \0) */
592281065eSMatthew Dillon 
60949ecb9bSMatthew Dillon #define MOUNTCTL_INSTALL_VFS_JOURNAL	1
61949ecb9bSMatthew Dillon #define MOUNTCTL_REMOVE_VFS_JOURNAL	2
62949ecb9bSMatthew Dillon #define MOUNTCTL_RESYNC_VFS_JOURNAL	3
6339b13188SMatthew Dillon #define MOUNTCTL_STATUS_VFS_JOURNAL	4
64500b6a22SMatthew Dillon #define MOUNTCTL_RESTART_VFS_JOURNAL	5
65949ecb9bSMatthew Dillon 
66949ecb9bSMatthew Dillon #define MOUNTCTL_INSTALL_BLK_JOURNAL	8
67949ecb9bSMatthew Dillon #define MOUNTCTL_REMOVE_BLK_JOURNAL	9
68949ecb9bSMatthew Dillon #define MOUNTCTL_RESYNC_BLK_JOURNAL	10
6939b13188SMatthew Dillon #define MOUNTCTL_STATUS_BLK_JOURNAL	11
70949ecb9bSMatthew Dillon 
711aa89f17SMatthew Dillon #define MOUNTCTL_SET_EXPORT		16	/* sys/mount.h:export_args */
72d9fad06eSMatthew Dillon #define MOUNTCTL_STATVFS		17	/* get extended stats */
73177403a9SMatthew Dillon #define MOUNTCTL_MOUNTFLAGS		18	/* extract mountflags */
741aa89f17SMatthew Dillon 
751aa89f17SMatthew Dillon /*
761aa89f17SMatthew Dillon  * Data structures for the journaling API
771aa89f17SMatthew Dillon  */
781aa89f17SMatthew Dillon 
79949ecb9bSMatthew Dillon struct mountctl_install_journal {
802281065eSMatthew Dillon 	char	id[JIDMAX];
81949ecb9bSMatthew Dillon 	int	flags;		/* journaling flags */
82949ecb9bSMatthew Dillon 	int	unused01;
83949ecb9bSMatthew Dillon 	int64_t	membufsize;	/* backing store */
84949ecb9bSMatthew Dillon 	int64_t	swapbufsize;	/* backing store */
85949ecb9bSMatthew Dillon 	int64_t	transid;	/* starting with specified transaction id */
86949ecb9bSMatthew Dillon 	int64_t unused02;
87949ecb9bSMatthew Dillon 	int	stallwarn;	/* stall warning (seconds) */
88949ecb9bSMatthew Dillon 	int	stallerror;	/* stall error (seconds) */
89949ecb9bSMatthew Dillon 	int	unused03;
90949ecb9bSMatthew Dillon 	int	unused04;
91949ecb9bSMatthew Dillon };
92949ecb9bSMatthew Dillon 
93432b8263SMatthew Dillon #define MC_JOURNAL_UNUSED0001		0x00000001
9482eaef15SMatthew Dillon #define MC_JOURNAL_STOP_REQ		0x00000002	/* stop request pend */
9582eaef15SMatthew Dillon #define MC_JOURNAL_STOP_IMM		0x00000004	/* STOP+trash fifo */
96432b8263SMatthew Dillon #define MC_JOURNAL_WACTIVE		0x00000008	/* wthread running */
97432b8263SMatthew Dillon #define MC_JOURNAL_RACTIVE		0x00000010	/* rthread running */
982281065eSMatthew Dillon #define MC_JOURNAL_WWAIT		0x00000040	/* write stall */
9982eaef15SMatthew Dillon #define MC_JOURNAL_WANT_AUDIT		0x00010000	/* audit trail */
10082eaef15SMatthew Dillon #define MC_JOURNAL_WANT_REVERSABLE	0x00020000	/* reversable stream */
101432b8263SMatthew Dillon #define MC_JOURNAL_WANT_FULLDUPLEX	0x00040000	/* has ack stream */
102949ecb9bSMatthew Dillon 
103500b6a22SMatthew Dillon struct mountctl_restart_journal {
104500b6a22SMatthew Dillon 	char	id[JIDMAX];
105500b6a22SMatthew Dillon 	int	flags;
106500b6a22SMatthew Dillon 	int	unused01;
107500b6a22SMatthew Dillon };
108500b6a22SMatthew Dillon 
109949ecb9bSMatthew Dillon struct mountctl_remove_journal {
1102281065eSMatthew Dillon 	char	id[JIDMAX];
111949ecb9bSMatthew Dillon 	int	flags;
112949ecb9bSMatthew Dillon };
113949ecb9bSMatthew Dillon 
114949ecb9bSMatthew Dillon #define MC_JOURNAL_REMOVE_TRASH		0x00000001	/* data -> trash */
115949ecb9bSMatthew Dillon #define MC_JOURNAL_REMOVE_ASSYNC	0x00000002	/* asynchronous op */
116949ecb9bSMatthew Dillon 
11739b13188SMatthew Dillon struct mountctl_status_journal {
1182281065eSMatthew Dillon 	char	id[JIDMAX];
11939b13188SMatthew Dillon 	int	index;
12039b13188SMatthew Dillon };
12139b13188SMatthew Dillon 
12239b13188SMatthew Dillon #define MC_JOURNAL_INDEX_ALL		-2
12339b13188SMatthew Dillon #define MC_JOURNAL_INDEX_ID		-1
12439b13188SMatthew Dillon 
12539b13188SMatthew Dillon struct mountctl_journal_ret_status {
12639b13188SMatthew Dillon 	int	recsize;
12739b13188SMatthew Dillon 	char	id[JIDMAX];
12839b13188SMatthew Dillon 	int	index;
129949ecb9bSMatthew Dillon 	int	flags;
130949ecb9bSMatthew Dillon 	int64_t	membufsize;
131949ecb9bSMatthew Dillon 	int64_t	membufused;
1323119bac5SMatthew Dillon 	int64_t	membufunacked;
133949ecb9bSMatthew Dillon 	int64_t	swapbufsize;
134949ecb9bSMatthew Dillon 	int64_t	swapbufused;
1353119bac5SMatthew Dillon 	int64_t	swapbufunacked;
136949ecb9bSMatthew Dillon 	int64_t transidstart;
137949ecb9bSMatthew Dillon 	int64_t transidcurrent;
1383119bac5SMatthew Dillon 	int64_t transidunacked;
139949ecb9bSMatthew Dillon 	int64_t transidacked;
140949ecb9bSMatthew Dillon 	int64_t bytessent;
141949ecb9bSMatthew Dillon 	int64_t bytesacked;
1423119bac5SMatthew Dillon 	int64_t fifostalls;
1433119bac5SMatthew Dillon 	int64_t reserved[4];
144949ecb9bSMatthew Dillon 	struct timeval lastack;
145949ecb9bSMatthew Dillon };
146949ecb9bSMatthew Dillon 
14739b13188SMatthew Dillon #define MC_JOURNAL_STATUS_MORETOCOME	0x00000001
148949ecb9bSMatthew Dillon 
1492281065eSMatthew Dillon #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
150949ecb9bSMatthew Dillon 
1512281065eSMatthew Dillon /*
1522281065eSMatthew Dillon  * Support structures for the generic journaling structure
1532281065eSMatthew Dillon  */
1542281065eSMatthew Dillon struct journal_memfifo {
1552281065eSMatthew Dillon 	int	size;		/* size (power of two) */
1562281065eSMatthew Dillon 	int	mask;		/* index mask (size - 1) */
15782eaef15SMatthew Dillon 	int	rindex;		/* stream reader index (track fd writes) */
1582281065eSMatthew Dillon 	int	xindex;		/* last acked / reader restart */
1592281065eSMatthew Dillon 	int	windex;		/* stream writer index */
1602281065eSMatthew Dillon 	char	*membase;	/* memory buffer representing the FIFO */
1612281065eSMatthew Dillon };
1622281065eSMatthew Dillon 
1632281065eSMatthew Dillon /*
1642281065eSMatthew Dillon  * Generic journaling structure attached to a mount point.
1652281065eSMatthew Dillon  */
1662281065eSMatthew Dillon struct journal {
1672281065eSMatthew Dillon 	TAILQ_ENTRY(journal) jentry;
1682281065eSMatthew Dillon 	struct file	*fp;
1692281065eSMatthew Dillon 	char		id[JIDMAX];
1702281065eSMatthew Dillon 	int		flags;		/* journaling flags */
1712281065eSMatthew Dillon 	int64_t		transid;
17239b13188SMatthew Dillon 	int64_t		total_acked;
1733119bac5SMatthew Dillon 	int64_t		fifostalls;
1742281065eSMatthew Dillon 	struct journal_memfifo fifo;
175432b8263SMatthew Dillon 	struct thread	wthread;
176432b8263SMatthew Dillon 	struct thread	rthread;
1772281065eSMatthew Dillon };
1782281065eSMatthew Dillon 
17926e603edSMatthew Dillon 
18082eaef15SMatthew Dillon /*
18182eaef15SMatthew Dillon  * The jrecord structure is used to build a journaling transaction.  Since
18282eaef15SMatthew Dillon  * a single journaling transaction might encompass very large buffers it
18382eaef15SMatthew Dillon  * is possible for multiple transactions to be written out to the FIFO
18482eaef15SMatthew Dillon  * in parallel and in peacemeal.
18582eaef15SMatthew Dillon  */
18682eaef15SMatthew Dillon struct jrecord {
18782eaef15SMatthew Dillon 	struct journal	*jo;
18882eaef15SMatthew Dillon 	char		*stream_ptr;
18982eaef15SMatthew Dillon 	int		stream_residual;
19082eaef15SMatthew Dillon 	int		stream_reserved;
19182eaef15SMatthew Dillon 	struct journal_rawrecbeg *rawp;
19282eaef15SMatthew Dillon 	struct journal_subrecord *parent;
19382eaef15SMatthew Dillon 	struct journal_subrecord *last;
19482eaef15SMatthew Dillon 	int16_t 	streamid;
19582eaef15SMatthew Dillon 	int		pushcount;
19682eaef15SMatthew Dillon 	int		pushptrgood;
19782eaef15SMatthew Dillon 	int		residual;
19882eaef15SMatthew Dillon 	int		residual_align;
19926e603edSMatthew Dillon 
20026e603edSMatthew Dillon 	/*
20126e603edSMatthew Dillon 	 * These fields are not used by the jrecord routines.  They may
20226e603edSMatthew Dillon 	 * be used by higher level routines to manage multiple jrecords.
20326e603edSMatthew Dillon 	 * See the jreclist_*() functions.
20426e603edSMatthew Dillon 	 */
20526e603edSMatthew Dillon 	TAILQ_ENTRY(jrecord) user_entry;
20626e603edSMatthew Dillon 	void *user_save;
20782eaef15SMatthew Dillon };
20882eaef15SMatthew Dillon 
209797e4fe9SMatthew Dillon struct jrecord_list {
210797e4fe9SMatthew Dillon 	TAILQ_HEAD(, jrecord) list;
211797e4fe9SMatthew Dillon 	int16_t		streamid;
212797e4fe9SMatthew Dillon };
21326e603edSMatthew Dillon 
214f56dc967SMatthew Dillon #endif	/* kernel or kernel structures */
215f56dc967SMatthew Dillon 
216f56dc967SMatthew Dillon #if defined(_KERNEL)
217f56dc967SMatthew Dillon 
2181bd40720SMatthew Dillon struct namecache;
2191bd40720SMatthew Dillon struct ucred;
2201bd40720SMatthew Dillon struct uio;
2219f5f0021SSamuel J. Greear struct xio;
222f56dc967SMatthew Dillon struct vnode;
223f56dc967SMatthew Dillon struct vattr;
224f56dc967SMatthew Dillon struct vm_page;
225f56dc967SMatthew Dillon 
226f56dc967SMatthew Dillon void journal_create_threads(struct journal *jo);
227f56dc967SMatthew Dillon void journal_destroy_threads(struct journal *jo, int flags);
228f56dc967SMatthew Dillon 
229f56dc967SMatthew Dillon /*
230f56dc967SMatthew Dillon  * Primary journal record support procedures
231f56dc967SMatthew Dillon  */
232f56dc967SMatthew Dillon void jrecord_init(struct journal *jo,
233f56dc967SMatthew Dillon 			struct jrecord *jrec, int16_t streamid);
234f56dc967SMatthew Dillon struct journal_subrecord *jrecord_push(
235f56dc967SMatthew Dillon 			struct jrecord *jrec, int16_t rectype);
236f56dc967SMatthew Dillon void jrecord_pop(struct jrecord *jrec, struct journal_subrecord *parent);
237f56dc967SMatthew Dillon void jrecord_leaf(struct jrecord *jrec,
238f56dc967SMatthew Dillon 			int16_t rectype, void *ptr, int bytes);
2399f5f0021SSamuel J. Greear void jrecord_leaf_uio(struct jrecord *jrec,
2409f5f0021SSamuel J. Greear 			int16_t rectype, struct uio *uio);
2419f5f0021SSamuel J. Greear void jrecord_leaf_xio(struct jrecord *jrec,
2429f5f0021SSamuel J. Greear 			int16_t rectype, struct xio *xio);
243f56dc967SMatthew Dillon struct journal_subrecord *jrecord_write(struct jrecord *jrec,
244f56dc967SMatthew Dillon 			int16_t rectype, int bytes);
245f56dc967SMatthew Dillon void jrecord_done(struct jrecord *jrec, int abortit);
246f56dc967SMatthew Dillon 
247f56dc967SMatthew Dillon /*
248f56dc967SMatthew Dillon  * Rollup journal record support procedures
249f56dc967SMatthew Dillon  */
250f56dc967SMatthew Dillon void jrecord_write_path(struct jrecord *jrec,
251f56dc967SMatthew Dillon 			int16_t rectype, struct namecache *ncp);
252f56dc967SMatthew Dillon void jrecord_write_vattr(struct jrecord *jrec, struct vattr *vat);
253f56dc967SMatthew Dillon void jrecord_write_cred(struct jrecord *jrec, struct thread *td,
254f56dc967SMatthew Dillon 			struct ucred *cred);
255f56dc967SMatthew Dillon void jrecord_write_vnode_ref(struct jrecord *jrec, struct vnode *vp);
256f56dc967SMatthew Dillon void jrecord_write_vnode_link(struct jrecord *jrec, struct vnode *vp,
257f56dc967SMatthew Dillon 			struct namecache *notncp);
258f56dc967SMatthew Dillon void jrecord_write_pagelist(struct jrecord *jrec, int16_t rectype,
259f56dc967SMatthew Dillon 			struct vm_page **pglist, int *rtvals, int pgcount,
260f56dc967SMatthew Dillon 			off_t offset);
261f56dc967SMatthew Dillon void jrecord_write_uio(struct jrecord *jrec, int16_t rectype, struct uio *uio);
262f56dc967SMatthew Dillon void jrecord_file_data(struct jrecord *jrec, struct vnode *vp,
263f56dc967SMatthew Dillon 			off_t off, off_t bytes);
264f56dc967SMatthew Dillon 
265*805c8e8eSzrj #ifdef MALLOC_DECLARE
266f56dc967SMatthew Dillon MALLOC_DECLARE(M_JOURNAL);
267f56dc967SMatthew Dillon MALLOC_DECLARE(M_JFIFO);
268*805c8e8eSzrj #endif
269f56dc967SMatthew Dillon 
2701aa89f17SMatthew Dillon #else
2711aa89f17SMatthew Dillon 
2721aa89f17SMatthew Dillon #include <sys/cdefs.h>
2731aa89f17SMatthew Dillon 
2741aa89f17SMatthew Dillon __BEGIN_DECLS
2751aa89f17SMatthew Dillon int	mountctl (const char *path, int op, int fd, void *ctl, int ctllen,
2761aa89f17SMatthew Dillon 		  void *buf, int buflen);
2771aa89f17SMatthew Dillon __END_DECLS
2781aa89f17SMatthew Dillon 
279f56dc967SMatthew Dillon #endif	/* kernel */
280f56dc967SMatthew Dillon 
281f56dc967SMatthew Dillon #endif	/* header */
282