xref: /illumos-gate/usr/src/uts/common/io/fssnap_if.c (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
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 /*
28  * This file contains interface definitions and wrappers for file
29  * system snapshot support.  File systems may depend on this module
30  * for symbol resolution while the implementation may remain unloaded
31  * until needed.
32  */
33 #include <sys/types.h>
34 #include <sys/debug.h>
35 #include <sys/t_lock.h>
36 #include <sys/param.h>
37 #include <sys/mman.h>
38 #include <sys/systm.h>
39 #include <sys/errno.h>
40 #include <sys/kmem.h>
41 #include <sys/cmn_err.h>
42 #include <sys/vnode.h>
43 #include <sys/debug.h>
44 #include <sys/proc.h>
45 #include <sys/user.h>
46 #include <sys/conf.h>
47 #include <sys/modctl.h>
48 #include <sys/fssnap_if.h>
49 
50 struct fssnap_operations snapops = {
51 	NULL,	/* fssnap_create */
52 	NULL,	/* fssnap_set_candidate */
53 	NULL,	/* fssnap_is_candidate */
54 	NULL,	/* fssnap_create_done */
55 	NULL,	/* fssnap_delete */
56 	NULL	/* fssnap_strategy */
57 };
58 
59 void *
60 fssnap_create(chunknumber_t nchunks, uint_t chunksz, u_offset_t maxsize,
61     struct vnode *fsvp, int backfilecount, struct vnode **bfvpp, char *backpath,
62     u_offset_t max_backfile_size)
63 {
64 	void *snapid = NULL;
65 
66 	if (snapops.fssnap_create)
67 		snapid = (snapops.fssnap_create)(nchunks, chunksz, maxsize,
68 		    fsvp, backfilecount, bfvpp, backpath, max_backfile_size);
69 
70 	return (snapid);
71 }
72 
73 void
74 fssnap_set_candidate(void *snapshot_id, chunknumber_t chunknumber)
75 {
76 	if (snapops.fssnap_set_candidate)
77 		(snapops.fssnap_set_candidate)(snapshot_id, chunknumber);
78 }
79 
80 int
81 fssnap_is_candidate(void *snapshot_id, u_offset_t off)
82 {
83 	int rc = 0;
84 
85 	if (snapops.fssnap_is_candidate)
86 		rc = (snapops.fssnap_is_candidate)(snapshot_id, off);
87 
88 	return (rc);
89 }
90 
91 int
92 fssnap_create_done(void *snapshot_id)
93 {
94 	int snapslot = -1;
95 
96 	if (snapops.fssnap_create_done)
97 		snapslot = (snapops.fssnap_create_done)(snapshot_id);
98 
99 	return (snapslot);
100 }
101 
102 int
103 fssnap_delete(void *snapshot_id)
104 {
105 	int snapslot = -1;
106 
107 	if (snapops.fssnap_delete)
108 		snapslot = (snapops.fssnap_delete)(snapshot_id);
109 
110 	return (snapslot);
111 }
112 
113 void
114 fssnap_strategy(void *snapshot_id, struct buf *bp)
115 {
116 	if (snapops.fssnap_strategy)
117 		(snapops.fssnap_strategy)(snapshot_id, bp);
118 }
119 
120 
121 #include <sys/modctl.h>
122 
123 extern struct mod_ops mod_miscops;
124 
125 static struct modlmisc modlmisc = {
126 	&mod_miscops, "File System Snapshot Interface",
127 };
128 
129 static struct modlinkage modlinkage = {
130 	MODREV_1, (void *)&modlmisc, NULL
131 };
132 
133 int
134 _init(void)
135 {
136 	return (mod_install(&modlinkage));
137 }
138 
139 /*
140  * Unloading is MT-safe because our client drivers use
141  * the _depends_on[] mechanism - we won't go while they're
142  * still around.
143  */
144 int
145 _fini(void)
146 {
147 	return (mod_remove(&modlinkage));
148 }
149 
150 int
151 _info(struct modinfo *modinfop)
152 {
153 	return (mod_info(&modlinkage, modinfop));
154 }
155