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