xref: /onnv-gate/usr/src/uts/common/sys/fssnap_if.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_SYS_FSSNAP_IF_H
28*0Sstevel@tonic-gate #define	_SYS_FSSNAP_IF_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #include <sys/types.h>
33*0Sstevel@tonic-gate #include <sys/fssnap.h>
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #ifdef	__cplusplus
36*0Sstevel@tonic-gate extern "C" {
37*0Sstevel@tonic-gate #endif
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate /*
40*0Sstevel@tonic-gate  * ioctl's for communicating between the user and the fssnapctl device.
41*0Sstevel@tonic-gate  * Also used to communicate between fssnapctl and the file system.
42*0Sstevel@tonic-gate  * Pack fiosnapcreate for amd64 to make struct size same as x86.
43*0Sstevel@tonic-gate  */
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
46*0Sstevel@tonic-gate #pragma pack(4)
47*0Sstevel@tonic-gate #endif
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate struct fiosnapcreate {
50*0Sstevel@tonic-gate 	int	rootfiledesc;	/* IN  fd for root of fs to be snapshotted */
51*0Sstevel@tonic-gate 	int	backfiledesc;	/* IN  backing store file for snapshot data */
52*0Sstevel@tonic-gate 	uint_t	snapshotnumber;	/* OUT snapshot number created */
53*0Sstevel@tonic-gate 	uint_t	chunksize;	/* IN  chunk size, 0 == fs defined */
54*0Sstevel@tonic-gate 	u_offset_t	maxsize; /* IN  maximum size of backing file */
55*0Sstevel@tonic-gate 	char	backfilename[MAXPATHLEN];	/* IN  for bookkeeping */
56*0Sstevel@tonic-gate 	int	error;		/* OUT error code */
57*0Sstevel@tonic-gate };
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate struct fiosnapcreate_multi {
60*0Sstevel@tonic-gate 	int	rootfiledesc;	/* IN  fd for root of fs to be snapshotted */
61*0Sstevel@tonic-gate 	uint_t	snapshotnumber;	/* OUT snapshot number created */
62*0Sstevel@tonic-gate 	uint_t	chunksize;	/* IN  chunk size, 0 == fs defined */
63*0Sstevel@tonic-gate 	u_offset_t	maxsize; /* IN  max size of entire backing store */
64*0Sstevel@tonic-gate 	char	backfilename[MAXPATHLEN];	/* IN  for bookkeeping */
65*0Sstevel@tonic-gate 	int	error;		/* OUT error code */
66*0Sstevel@tonic-gate 	int	backfilecount;	/* IN  number of backing store files */
67*0Sstevel@tonic-gate 	u_offset_t	backfilesize; /* IN maximum size of each backfile */
68*0Sstevel@tonic-gate 	int	backfiledesc[1]; /* IN  backing store files for snapshot data */
69*0Sstevel@tonic-gate };
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
72*0Sstevel@tonic-gate #pragma pack()
73*0Sstevel@tonic-gate #endif
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate struct fiosnapdelete {
76*0Sstevel@tonic-gate 	int	rootfiledesc;	/* IN  fd for root of fs to be unsnapshotted */
77*0Sstevel@tonic-gate 	uint_t	snapshotnumber;	/* OUT snapshot number deleted */
78*0Sstevel@tonic-gate 	int	error;		/* OUT error code */
79*0Sstevel@tonic-gate };
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate /* ioctl error returns */
82*0Sstevel@tonic-gate #define	FIOCOW_EREADONLY (1)	/* read only file system */
83*0Sstevel@tonic-gate #define	FIOCOW_EBUSY	(2)	/* snapshot already enabled */
84*0Sstevel@tonic-gate #define	FIOCOW_EULOCK	(3)	/* file system is locked */
85*0Sstevel@tonic-gate #define	FIOCOW_EWLOCK	(4)	/* file system could not be write locked */
86*0Sstevel@tonic-gate #define	FIOCOW_EFLUSH	(5)	/* file system could not be flushed */
87*0Sstevel@tonic-gate #define	FIOCOW_ECLEAN	(6)	/* file system may not be stable */
88*0Sstevel@tonic-gate #define	FIOCOW_ENOULOCK	(7)	/* file system could not be unlocked */
89*0Sstevel@tonic-gate #define	FIOCOW_ECHUNKSZ	(8)	/* chunksize is less than fs fragment size */
90*0Sstevel@tonic-gate #define	FIOCOW_ECREATE	(9)	/* could not allocate/create snapshot */
91*0Sstevel@tonic-gate #define	FIOCOW_EBITMAP	(10)	/* error scanning file system bitmaps */
92*0Sstevel@tonic-gate #define	FIOCOW_EBACKFILE (11)	/* bad backing file path passed in */
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate /*
95*0Sstevel@tonic-gate  * make the control device minor number high so minor numbers match
96*0Sstevel@tonic-gate  * snapshot numbers.
97*0Sstevel@tonic-gate  */
98*0Sstevel@tonic-gate #define	SNAP_CTL_MINOR	(L_MAXMIN32)
99*0Sstevel@tonic-gate #define	SNAP_NAME	"fssnap"
100*0Sstevel@tonic-gate #define	SNAP_CTL_NODE	"ctl"
101*0Sstevel@tonic-gate #define	SNAP_CTL_NAME	SNAP_NAME SNAP_CTL_NODE
102*0Sstevel@tonic-gate #define	SNAP_BLOCK_NAME	SNAP_NAME
103*0Sstevel@tonic-gate #define	SNAP_CHAR_NAME	"r" SNAP_NAME
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate /* kstat names */
106*0Sstevel@tonic-gate #define	FSSNAP_KSTAT_HIGHWATER		"highwater"
107*0Sstevel@tonic-gate #define	FSSNAP_KSTAT_MNTPT		"mountpoint"
108*0Sstevel@tonic-gate #define	FSSNAP_KSTAT_BFNAME		"bfname"
109*0Sstevel@tonic-gate #define	FSSNAP_KSTAT_NUM		"numericstats"
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate /* numericstats kstat names */
112*0Sstevel@tonic-gate #define	FSSNAP_KSTAT_NUM_STATE		"state"
113*0Sstevel@tonic-gate #define	FSSNAP_KSTAT_NUM_BFSIZE		"bfsize"
114*0Sstevel@tonic-gate #define	FSSNAP_KSTAT_NUM_MAXSIZE	"maxsize"
115*0Sstevel@tonic-gate #define	FSSNAP_KSTAT_NUM_CHUNKSIZE	"chunksize"
116*0Sstevel@tonic-gate #define	FSSNAP_KSTAT_NUM_CREATETIME	"createtime"
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate #if defined(_KERNEL)
119*0Sstevel@tonic-gate /*
120*0Sstevel@tonic-gate  * snapshot operations implemented by the loadable snapshot subsystem
121*0Sstevel@tonic-gate  */
122*0Sstevel@tonic-gate struct fssnap_operations {
123*0Sstevel@tonic-gate 	void *(*fssnap_create)(chunknumber_t, uint_t, u_offset_t,
124*0Sstevel@tonic-gate 	    struct vnode *, int, struct vnode **, char *, u_offset_t);
125*0Sstevel@tonic-gate 	void (*fssnap_set_candidate)(void *, chunknumber_t);
126*0Sstevel@tonic-gate 	int (*fssnap_is_candidate)(void *, u_offset_t);
127*0Sstevel@tonic-gate 	int  (*fssnap_create_done)(void *);
128*0Sstevel@tonic-gate 	int (*fssnap_delete)(void *);
129*0Sstevel@tonic-gate 	void (*fssnap_strategy)(void *, struct buf *);
130*0Sstevel@tonic-gate };
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate /* global variables to manage interface operations */
134*0Sstevel@tonic-gate extern struct fssnap_operations snapops;
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate /* External functions called by file systems that use snapshots */
137*0Sstevel@tonic-gate extern int fssnap_init(void);
138*0Sstevel@tonic-gate extern int fssnap_fini(void);
139*0Sstevel@tonic-gate extern void *fssnap_create(chunknumber_t, uint_t, u_offset_t, struct vnode *,
140*0Sstevel@tonic-gate     int, struct vnode **, char *, u_offset_t);
141*0Sstevel@tonic-gate extern void fssnap_set_candidate(void *, chunknumber_t);
142*0Sstevel@tonic-gate extern int fssnap_is_candidate(void *, u_offset_t);
143*0Sstevel@tonic-gate extern int  fssnap_create_done(void *);
144*0Sstevel@tonic-gate extern int fssnap_delete(void *);
145*0Sstevel@tonic-gate extern void fssnap_strategy(void *, struct buf *);
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate #endif /* _KERNEL */
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate #ifdef	__cplusplus
150*0Sstevel@tonic-gate }
151*0Sstevel@tonic-gate #endif
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate #endif /* _SYS_FSSNAP_IF_H */
154