1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate * This file contains interface definitions and wrappers for file
31*7c478bd9Sstevel@tonic-gate * system snapshot support. File systems may depend on this module
32*7c478bd9Sstevel@tonic-gate * for symbol resolution while the implementation may remain unloaded
33*7c478bd9Sstevel@tonic-gate * until needed.
34*7c478bd9Sstevel@tonic-gate */
35*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/debug.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/mman.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/systm.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/errno.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/debug.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/proc.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/user.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/conf.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
50*7c478bd9Sstevel@tonic-gate #include <sys/fssnap_if.h>
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate struct fssnap_operations snapops = {
53*7c478bd9Sstevel@tonic-gate NULL, /* fssnap_create */
54*7c478bd9Sstevel@tonic-gate NULL, /* fssnap_set_candidate */
55*7c478bd9Sstevel@tonic-gate NULL, /* fssnap_is_candidate */
56*7c478bd9Sstevel@tonic-gate NULL, /* fssnap_create_done */
57*7c478bd9Sstevel@tonic-gate NULL, /* fssnap_delete */
58*7c478bd9Sstevel@tonic-gate NULL /* fssnap_strategy */
59*7c478bd9Sstevel@tonic-gate };
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@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*7c478bd9Sstevel@tonic-gate fssnap_create(chunknumber_t nchunks, uint_t chunksz, u_offset_t maxsize,
63*7c478bd9Sstevel@tonic-gate struct vnode *fsvp, int backfilecount, struct vnode **bfvpp, char *backpath,
64*7c478bd9Sstevel@tonic-gate u_offset_t max_backfile_size)
65*7c478bd9Sstevel@tonic-gate {
66*7c478bd9Sstevel@tonic-gate void *snapid = NULL;
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate if (snapops.fssnap_create)
69*7c478bd9Sstevel@tonic-gate snapid = (snapops.fssnap_create)(nchunks, chunksz, maxsize,
70*7c478bd9Sstevel@tonic-gate fsvp, backfilecount, bfvpp, backpath, max_backfile_size);
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate return (snapid);
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate void
fssnap_set_candidate(void * snapshot_id,chunknumber_t chunknumber)76*7c478bd9Sstevel@tonic-gate fssnap_set_candidate(void *snapshot_id, chunknumber_t chunknumber)
77*7c478bd9Sstevel@tonic-gate {
78*7c478bd9Sstevel@tonic-gate if (snapops.fssnap_set_candidate)
79*7c478bd9Sstevel@tonic-gate (snapops.fssnap_set_candidate)(snapshot_id, chunknumber);
80*7c478bd9Sstevel@tonic-gate }
81*7c478bd9Sstevel@tonic-gate
82*7c478bd9Sstevel@tonic-gate int
fssnap_is_candidate(void * snapshot_id,u_offset_t off)83*7c478bd9Sstevel@tonic-gate fssnap_is_candidate(void *snapshot_id, u_offset_t off)
84*7c478bd9Sstevel@tonic-gate {
85*7c478bd9Sstevel@tonic-gate int rc = 0;
86*7c478bd9Sstevel@tonic-gate
87*7c478bd9Sstevel@tonic-gate if (snapops.fssnap_is_candidate)
88*7c478bd9Sstevel@tonic-gate rc = (snapops.fssnap_is_candidate)(snapshot_id, off);
89*7c478bd9Sstevel@tonic-gate
90*7c478bd9Sstevel@tonic-gate return (rc);
91*7c478bd9Sstevel@tonic-gate }
92*7c478bd9Sstevel@tonic-gate
93*7c478bd9Sstevel@tonic-gate int
fssnap_create_done(void * snapshot_id)94*7c478bd9Sstevel@tonic-gate fssnap_create_done(void *snapshot_id)
95*7c478bd9Sstevel@tonic-gate {
96*7c478bd9Sstevel@tonic-gate int snapslot = -1;
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gate if (snapops.fssnap_create_done)
99*7c478bd9Sstevel@tonic-gate snapslot = (snapops.fssnap_create_done)(snapshot_id);
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gate return (snapslot);
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate int
fssnap_delete(void * snapshot_id)105*7c478bd9Sstevel@tonic-gate fssnap_delete(void *snapshot_id)
106*7c478bd9Sstevel@tonic-gate {
107*7c478bd9Sstevel@tonic-gate int snapslot = -1;
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate if (snapops.fssnap_delete)
110*7c478bd9Sstevel@tonic-gate snapslot = (snapops.fssnap_delete)(snapshot_id);
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate return (snapslot);
113*7c478bd9Sstevel@tonic-gate }
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate void
fssnap_strategy(void * snapshot_id,struct buf * bp)116*7c478bd9Sstevel@tonic-gate fssnap_strategy(void *snapshot_id, struct buf *bp)
117*7c478bd9Sstevel@tonic-gate {
118*7c478bd9Sstevel@tonic-gate if (snapops.fssnap_strategy)
119*7c478bd9Sstevel@tonic-gate (snapops.fssnap_strategy)(snapshot_id, bp);
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate
123*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate extern struct mod_ops mod_miscops;
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate static struct modlmisc modlmisc = {
128*7c478bd9Sstevel@tonic-gate &mod_miscops, "File System Snapshot Interface",
129*7c478bd9Sstevel@tonic-gate };
130*7c478bd9Sstevel@tonic-gate
131*7c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
132*7c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modlmisc, NULL
133*7c478bd9Sstevel@tonic-gate };
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate int
_init(void)136*7c478bd9Sstevel@tonic-gate _init(void)
137*7c478bd9Sstevel@tonic-gate {
138*7c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage));
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate
141*7c478bd9Sstevel@tonic-gate /*
142*7c478bd9Sstevel@tonic-gate * Unloading is MT-safe because our client drivers use
143*7c478bd9Sstevel@tonic-gate * the _depends_on[] mechanism - we won't go while they're
144*7c478bd9Sstevel@tonic-gate * still around.
145*7c478bd9Sstevel@tonic-gate */
146*7c478bd9Sstevel@tonic-gate int
_fini(void)147*7c478bd9Sstevel@tonic-gate _fini(void)
148*7c478bd9Sstevel@tonic-gate {
149*7c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage));
150*7c478bd9Sstevel@tonic-gate }
151*7c478bd9Sstevel@tonic-gate
152*7c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)153*7c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
154*7c478bd9Sstevel@tonic-gate {
155*7c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
156*7c478bd9Sstevel@tonic-gate }
157