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