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