Merge from vendor branch BSDINSTALLER:
[dragonfly.git] / sys / sys / mountctl.h
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  * $DragonFly: src/sys/sys/mountctl.h,v 1.14 2008/02/05 20:49:52 dillon Exp $
35  */
36
37 #ifndef _SYS_MOUNTCTL_H_
38 #define _SYS_MOUNTCTL_H_
39
40 #ifndef _SYS_TYPES_H_
41 #include <sys/types.h>
42 #endif
43 #ifndef _SYS_TIME_H_
44 #include <sys/time.h>
45 #endif
46 #ifndef _SYS_QUEUE_H_
47 #include <sys/queue.h>
48 #endif
49 #ifndef _SYS_THREAD_H_
50 #include <sys/thread.h>
51 #endif
52
53 #ifdef _KERNEL
54
55 #ifndef _SYS_MALLOC_H_
56 #include <sys/malloc.h>
57 #endif
58
59 #endif
60
61 /*
62  * General constants
63  */
64
65 #define JIDMAX          32      /* id string buf[] size (incls \0) */
66
67 #define MOUNTCTL_INSTALL_VFS_JOURNAL    1
68 #define MOUNTCTL_REMOVE_VFS_JOURNAL     2
69 #define MOUNTCTL_RESYNC_VFS_JOURNAL     3
70 #define MOUNTCTL_STATUS_VFS_JOURNAL     4
71 #define MOUNTCTL_RESTART_VFS_JOURNAL    5
72
73 #define MOUNTCTL_INSTALL_BLK_JOURNAL    8
74 #define MOUNTCTL_REMOVE_BLK_JOURNAL     9
75 #define MOUNTCTL_RESYNC_BLK_JOURNAL     10
76 #define MOUNTCTL_STATUS_BLK_JOURNAL     11
77
78 #define MOUNTCTL_SET_EXPORT             16      /* sys/mount.h:export_args */
79
80 /*
81  * Data structures for the journaling API
82  */
83
84 struct mountctl_install_journal {
85         char    id[JIDMAX];
86         int     flags;          /* journaling flags */
87         int     unused01;
88         int64_t membufsize;     /* backing store */
89         int64_t swapbufsize;    /* backing store */
90         int64_t transid;        /* starting with specified transaction id */
91         int64_t unused02;
92         int     stallwarn;      /* stall warning (seconds) */
93         int     stallerror;     /* stall error (seconds) */
94         int     unused03;
95         int     unused04;
96 };
97
98 #define MC_JOURNAL_UNUSED0001           0x00000001
99 #define MC_JOURNAL_STOP_REQ             0x00000002      /* stop request pend */
100 #define MC_JOURNAL_STOP_IMM             0x00000004      /* STOP+trash fifo */
101 #define MC_JOURNAL_WACTIVE              0x00000008      /* wthread running */
102 #define MC_JOURNAL_RACTIVE              0x00000010      /* rthread running */
103 #define MC_JOURNAL_WWAIT                0x00000040      /* write stall */
104 #define MC_JOURNAL_WANT_AUDIT           0x00010000      /* audit trail */
105 #define MC_JOURNAL_WANT_REVERSABLE      0x00020000      /* reversable stream */
106 #define MC_JOURNAL_WANT_FULLDUPLEX      0x00040000      /* has ack stream */
107
108 struct mountctl_restart_journal {
109         char    id[JIDMAX];
110         int     flags;
111         int     unused01;
112 };
113
114 struct mountctl_remove_journal {
115         char    id[JIDMAX];
116         int     flags;
117 };
118
119 #define MC_JOURNAL_REMOVE_TRASH         0x00000001      /* data -> trash */
120 #define MC_JOURNAL_REMOVE_ASSYNC        0x00000002      /* asynchronous op */
121
122 struct mountctl_status_journal {
123         char    id[JIDMAX];
124         int     index;
125 };
126
127 #define MC_JOURNAL_INDEX_ALL            -2
128 #define MC_JOURNAL_INDEX_ID             -1
129
130 struct mountctl_journal_ret_status {
131         int     recsize;
132         char    id[JIDMAX];
133         int     index;
134         int     flags;
135         int64_t membufsize;
136         int64_t membufused;
137         int64_t membufunacked;
138         int64_t swapbufsize;
139         int64_t swapbufused;
140         int64_t swapbufunacked;
141         int64_t transidstart;
142         int64_t transidcurrent;
143         int64_t transidunacked;
144         int64_t transidacked;
145         int64_t bytessent;
146         int64_t bytesacked;
147         int64_t fifostalls;
148         int64_t reserved[4];
149         struct timeval lastack;
150 };
151
152 #define MC_JOURNAL_STATUS_MORETOCOME    0x00000001
153
154 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
155
156 /*
157  * Support structures for the generic journaling structure
158  */
159 struct journal_memfifo {
160         int     size;           /* size (power of two) */
161         int     mask;           /* index mask (size - 1) */
162         int     rindex;         /* stream reader index (track fd writes) */
163         int     xindex;         /* last acked / reader restart */
164         int     windex;         /* stream writer index */
165         char    *membase;       /* memory buffer representing the FIFO */
166 };
167
168 /*
169  * Generic journaling structure attached to a mount point.
170  */
171 struct journal {
172         TAILQ_ENTRY(journal) jentry;
173         struct file     *fp;
174         char            id[JIDMAX];
175         int             flags;          /* journaling flags */
176         int64_t         transid;
177         int64_t         total_acked;
178         int64_t         fifostalls;
179         struct journal_memfifo fifo;
180         struct thread   wthread;
181         struct thread   rthread;
182 };
183
184
185 /*
186  * The jrecord structure is used to build a journaling transaction.  Since
187  * a single journaling transaction might encompass very large buffers it 
188  * is possible for multiple transactions to be written out to the FIFO
189  * in parallel and in peacemeal.
190  */
191 struct jrecord {
192         struct journal  *jo;
193         char            *stream_ptr;
194         int             stream_residual;
195         int             stream_reserved;
196         struct journal_rawrecbeg *rawp;
197         struct journal_subrecord *parent;
198         struct journal_subrecord *last;
199         int16_t         streamid;
200         int             pushcount;
201         int             pushptrgood;
202         int             residual;
203         int             residual_align;
204
205         /*
206          * These fields are not used by the jrecord routines.  They may
207          * be used by higher level routines to manage multiple jrecords.
208          * See the jreclist_*() functions.
209          */
210         TAILQ_ENTRY(jrecord) user_entry;
211         void *user_save;
212 };
213
214 struct jrecord_list {
215         TAILQ_HEAD(, jrecord) list;
216         int16_t         streamid;
217 };
218
219 #endif  /* kernel or kernel structures */
220
221 #if defined(_KERNEL)
222
223 struct namecache;
224 struct ucred;
225 struct uio;
226 struct vnode;
227 struct vattr;
228 struct vm_page;
229
230 void journal_create_threads(struct journal *jo);
231 void journal_destroy_threads(struct journal *jo, int flags);
232
233 /*
234  * Primary journal record support procedures
235  */
236 void jrecord_init(struct journal *jo,
237                         struct jrecord *jrec, int16_t streamid);
238 struct journal_subrecord *jrecord_push(
239                         struct jrecord *jrec, int16_t rectype);
240 void jrecord_pop(struct jrecord *jrec, struct journal_subrecord *parent);
241 void jrecord_leaf(struct jrecord *jrec,
242                          int16_t rectype, void *ptr, int bytes);
243 struct journal_subrecord *jrecord_write(struct jrecord *jrec,
244                         int16_t rectype, int bytes);
245 void jrecord_data(struct jrecord *jrec, const void *buf, int bytes);
246 void jrecord_done(struct jrecord *jrec, int abortit);
247
248 /*
249  * Rollup journal record support procedures
250  */
251 void jrecord_write_path(struct jrecord *jrec,
252                         int16_t rectype, struct namecache *ncp);
253 void jrecord_write_vattr(struct jrecord *jrec, struct vattr *vat);
254 void jrecord_write_cred(struct jrecord *jrec, struct thread *td,
255                         struct ucred *cred);
256 void jrecord_write_vnode_ref(struct jrecord *jrec, struct vnode *vp);
257 void jrecord_write_vnode_link(struct jrecord *jrec, struct vnode *vp,
258                         struct namecache *notncp);
259 void jrecord_write_pagelist(struct jrecord *jrec, int16_t rectype,
260                         struct vm_page **pglist, int *rtvals, int pgcount,
261                         off_t offset);
262 void jrecord_write_uio(struct jrecord *jrec, int16_t rectype, struct uio *uio);
263 void jrecord_file_data(struct jrecord *jrec, struct vnode *vp,
264                         off_t off, off_t bytes);
265
266 MALLOC_DECLARE(M_JOURNAL);
267 MALLOC_DECLARE(M_JFIFO);
268
269 #else
270
271 #include <sys/cdefs.h>
272
273 __BEGIN_DECLS
274 int     mountctl (const char *path, int op, int fd, void *ctl, int ctllen,
275                   void *buf, int buflen);
276 __END_DECLS
277
278 #endif  /* kernel */
279
280 #endif  /* header */