2 * Copyright (c) 2004 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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
34 * $DragonFly: src/sys/sys/mountctl.h,v 1.13 2006/05/20 02:42:13 dillon Exp $
37 #ifndef _SYS_MOUNTCTL_H_
38 #define _SYS_MOUNTCTL_H_
41 #include <sys/types.h>
47 #include <sys/queue.h>
49 #ifndef _SYS_THREAD_H_
50 #include <sys/thread.h>
55 #ifndef _SYS_MALLOC_H_
56 #include <sys/malloc.h>
65 #define JIDMAX 32 /* id string buf[] size (incls \0) */
68 * Data structures for the journaling API
71 #define MOUNTCTL_INSTALL_VFS_JOURNAL 1
72 #define MOUNTCTL_REMOVE_VFS_JOURNAL 2
73 #define MOUNTCTL_RESYNC_VFS_JOURNAL 3
74 #define MOUNTCTL_STATUS_VFS_JOURNAL 4
75 #define MOUNTCTL_RESTART_VFS_JOURNAL 5
77 #define MOUNTCTL_INSTALL_BLK_JOURNAL 8
78 #define MOUNTCTL_REMOVE_BLK_JOURNAL 9
79 #define MOUNTCTL_RESYNC_BLK_JOURNAL 10
80 #define MOUNTCTL_STATUS_BLK_JOURNAL 11
82 struct mountctl_install_journal
{
84 int flags
; /* journaling flags */
86 int64_t membufsize
; /* backing store */
87 int64_t swapbufsize
; /* backing store */
88 int64_t transid
; /* starting with specified transaction id */
90 int stallwarn
; /* stall warning (seconds) */
91 int stallerror
; /* stall error (seconds) */
96 #define MC_JOURNAL_UNUSED0001 0x00000001
97 #define MC_JOURNAL_STOP_REQ 0x00000002 /* stop request pend */
98 #define MC_JOURNAL_STOP_IMM 0x00000004 /* STOP+trash fifo */
99 #define MC_JOURNAL_WACTIVE 0x00000008 /* wthread running */
100 #define MC_JOURNAL_RACTIVE 0x00000010 /* rthread running */
101 #define MC_JOURNAL_WWAIT 0x00000040 /* write stall */
102 #define MC_JOURNAL_WANT_AUDIT 0x00010000 /* audit trail */
103 #define MC_JOURNAL_WANT_REVERSABLE 0x00020000 /* reversable stream */
104 #define MC_JOURNAL_WANT_FULLDUPLEX 0x00040000 /* has ack stream */
106 struct mountctl_restart_journal
{
112 struct mountctl_remove_journal
{
117 #define MC_JOURNAL_REMOVE_TRASH 0x00000001 /* data -> trash */
118 #define MC_JOURNAL_REMOVE_ASSYNC 0x00000002 /* asynchronous op */
120 struct mountctl_status_journal
{
125 #define MC_JOURNAL_INDEX_ALL -2
126 #define MC_JOURNAL_INDEX_ID -1
128 struct mountctl_journal_ret_status
{
135 int64_t membufunacked
;
138 int64_t swapbufunacked
;
139 int64_t transidstart
;
140 int64_t transidcurrent
;
141 int64_t transidunacked
;
142 int64_t transidacked
;
147 struct timeval lastack
;
150 #define MC_JOURNAL_STATUS_MORETOCOME 0x00000001
152 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
155 * Support structures for the generic journaling structure
157 struct journal_memfifo
{
158 int size
; /* size (power of two) */
159 int mask
; /* index mask (size - 1) */
160 int rindex
; /* stream reader index (track fd writes) */
161 int xindex
; /* last acked / reader restart */
162 int windex
; /* stream writer index */
163 char *membase
; /* memory buffer representing the FIFO */
167 * Generic journaling structure attached to a mount point.
170 TAILQ_ENTRY(journal
) jentry
;
173 int flags
; /* journaling flags */
177 struct journal_memfifo fifo
;
178 struct thread wthread
;
179 struct thread rthread
;
184 * The jrecord structure is used to build a journaling transaction. Since
185 * a single journaling transaction might encompass very large buffers it
186 * is possible for multiple transactions to be written out to the FIFO
187 * in parallel and in peacemeal.
194 struct journal_rawrecbeg
*rawp
;
195 struct journal_subrecord
*parent
;
196 struct journal_subrecord
*last
;
204 * These fields are not used by the jrecord routines. They may
205 * be used by higher level routines to manage multiple jrecords.
206 * See the jreclist_*() functions.
208 TAILQ_ENTRY(jrecord
) user_entry
;
212 struct jrecord_list
{
213 TAILQ_HEAD(, jrecord
) list
;
217 #endif /* kernel or kernel structures */
228 void journal_create_threads(struct journal
*jo
);
229 void journal_destroy_threads(struct journal
*jo
, int flags
);
232 * Primary journal record support procedures
234 void jrecord_init(struct journal
*jo
,
235 struct jrecord
*jrec
, int16_t streamid
);
236 struct journal_subrecord
*jrecord_push(
237 struct jrecord
*jrec
, int16_t rectype
);
238 void jrecord_pop(struct jrecord
*jrec
, struct journal_subrecord
*parent
);
239 void jrecord_leaf(struct jrecord
*jrec
,
240 int16_t rectype
, void *ptr
, int bytes
);
241 struct journal_subrecord
*jrecord_write(struct jrecord
*jrec
,
242 int16_t rectype
, int bytes
);
243 void jrecord_data(struct jrecord
*jrec
, const void *buf
, int bytes
);
244 void jrecord_done(struct jrecord
*jrec
, int abortit
);
247 * Rollup journal record support procedures
249 void jrecord_write_path(struct jrecord
*jrec
,
250 int16_t rectype
, struct namecache
*ncp
);
251 void jrecord_write_vattr(struct jrecord
*jrec
, struct vattr
*vat
);
252 void jrecord_write_cred(struct jrecord
*jrec
, struct thread
*td
,
254 void jrecord_write_vnode_ref(struct jrecord
*jrec
, struct vnode
*vp
);
255 void jrecord_write_vnode_link(struct jrecord
*jrec
, struct vnode
*vp
,
256 struct namecache
*notncp
);
257 void jrecord_write_pagelist(struct jrecord
*jrec
, int16_t rectype
,
258 struct vm_page
**pglist
, int *rtvals
, int pgcount
,
260 void jrecord_write_uio(struct jrecord
*jrec
, int16_t rectype
, struct uio
*uio
);
261 void jrecord_file_data(struct jrecord
*jrec
, struct vnode
*vp
,
262 off_t off
, off_t bytes
);
264 MALLOC_DECLARE(M_JOURNAL
);
265 MALLOC_DECLARE(M_JFIFO
);