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