dm_target_snapshot.c revision 1.19.4.1 1 1.19.4.1 martin /* $NetBSD: dm_target_snapshot.c,v 1.19.4.1 2020/04/08 14:08:03 martin Exp $ */
2 1.2 haad
3 1.2 haad /*
4 1.2 haad * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.2 haad * All rights reserved.
6 1.2 haad *
7 1.2 haad * This code is derived from software contributed to The NetBSD Foundation
8 1.2 haad * by Adam Hamsik.
9 1.2 haad *
10 1.2 haad * Redistribution and use in source and binary forms, with or without
11 1.2 haad * modification, are permitted provided that the following conditions
12 1.2 haad * are met:
13 1.2 haad * 1. Redistributions of source code must retain the above copyright
14 1.2 haad * notice, this list of conditions and the following disclaimer.
15 1.2 haad * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 haad * notice, this list of conditions and the following disclaimer in the
17 1.2 haad * documentation and/or other materials provided with the distribution.
18 1.2 haad *
19 1.2 haad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 haad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 haad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 haad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 haad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 haad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 haad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 haad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 haad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 haad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 haad * POSSIBILITY OF SUCH DAMAGE.
30 1.2 haad */
31 1.19 christos #include <sys/cdefs.h>
32 1.19.4.1 martin __KERNEL_RCSID(0, "$NetBSD: dm_target_snapshot.c,v 1.19.4.1 2020/04/08 14:08:03 martin Exp $");
33 1.2 haad
34 1.2 haad /*
35 1.2 haad * 1. Suspend my_data to temporarily stop any I/O while the snapshot is being
36 1.2 haad * activated.
37 1.2 haad * dmsetup suspend my_data
38 1.2 haad *
39 1.2 haad * 2. Create the snapshot-origin device with no table.
40 1.2 haad * dmsetup create my_data_org
41 1.2 haad *
42 1.2 haad * 3. Read the table from my_data and load it into my_data_org.
43 1.2 haad * dmsetup table my_data | dmsetup load my_data_org
44 1.2 haad *
45 1.2 haad * 4. Resume this new table.
46 1.2 haad * dmsetup resume my_data_org
47 1.2 haad *
48 1.2 haad * 5. Create the snapshot device with no table.
49 1.2 haad * dmsetup create my_data_snap
50 1.2 haad *
51 1.2 haad * 6. Load the table into my_data_snap. This uses /dev/hdd1 as the COW device and
52 1.2 haad * uses a 32kB chunk-size.
53 1.2 haad * echo "0 `blockdev --getsize /dev/mapper/my_data` snapshot \
54 1.2 haad * /dev/mapper/my_data_org /dev/hdd1 p 64" | dmsetup load my_data_snap
55 1.2 haad *
56 1.2 haad * 7. Reload my_data as a snapshot-origin device that points to my_data_org.
57 1.2 haad * echo "0 `blockdev --getsize /dev/mapper/my_data` snapshot-origin \
58 1.2 haad * /dev/mapper/my_data_org" | dmsetup load my_data
59 1.2 haad *
60 1.2 haad * 8. Resume the snapshot and origin devices.
61 1.2 haad * dmsetup resume my_data_snap
62 1.2 haad * dmsetup resume my_data
63 1.5 haad *
64 1.5 haad * Before snapshot creation
65 1.5 haad * dev_name; dev table
66 1.5 haad * | my_data; 0 1024 linear /dev/sd1a 384|
67 1.5 haad *
68 1.5 haad * After snapshot creation
69 1.5 haad * |my_data_org;0 1024 linear /dev/sd1a 384|
70 1.12 haad * /
71 1.5 haad * |my_data; 0 1024 snapshot-origin /dev/vg00/my_data_org|
72 1.5 haad * /
73 1.5 haad * |my_data_snap; 0 1024 snapshot /dev/vg00/my_data /dev/mapper/my_data_cow P 8
74 1.5 haad * \
75 1.5 haad * |my_data_cow; 0 256 linear /dev/sd1a 1408|
76 1.2 haad */
77 1.2 haad
78 1.2 haad /*
79 1.2 haad * This file implements initial version of device-mapper snapshot target.
80 1.2 haad */
81 1.2 haad #include <sys/types.h>
82 1.2 haad #include <sys/param.h>
83 1.2 haad #include <sys/buf.h>
84 1.2 haad #include <sys/kmem.h>
85 1.2 haad
86 1.2 haad #include "dm.h"
87 1.2 haad
88 1.13 haad /* dm_target_snapshot.c */
89 1.19.4.1 martin int dm_target_snapshot_init(dm_table_entry_t *, int, char **);
90 1.19.4.1 martin char *dm_target_snapshot_table(void *);
91 1.13 haad int dm_target_snapshot_strategy(dm_table_entry_t *, struct buf *);
92 1.19.4.1 martin int dm_target_snapshot_sync(dm_table_entry_t *);
93 1.13 haad int dm_target_snapshot_destroy(dm_table_entry_t *);
94 1.19.4.1 martin //int dm_target_snapshot_upcall(dm_table_entry_t *, struct buf *);
95 1.13 haad
96 1.13 haad /* dm snapshot origin driver */
97 1.19.4.1 martin int dm_target_snapshot_orig_init(dm_table_entry_t *, int, char **);
98 1.19.4.1 martin char *dm_target_snapshot_orig_table(void *);
99 1.13 haad int dm_target_snapshot_orig_strategy(dm_table_entry_t *, struct buf *);
100 1.13 haad int dm_target_snapshot_orig_sync(dm_table_entry_t *);
101 1.13 haad int dm_target_snapshot_orig_destroy(dm_table_entry_t *);
102 1.19.4.1 martin //int dm_target_snapshot_orig_upcall(dm_table_entry_t *, struct buf *);
103 1.19.4.1 martin
104 1.19.4.1 martin typedef struct target_snapshot_config {
105 1.19.4.1 martin dm_pdev_t *tsc_snap_dev;
106 1.19.4.1 martin /* cow dev is set only for persistent snapshot devices */
107 1.19.4.1 martin dm_pdev_t *tsc_cow_dev;
108 1.19.4.1 martin
109 1.19.4.1 martin uint64_t tsc_chunk_size;
110 1.19.4.1 martin uint32_t tsc_persistent_dev;
111 1.19.4.1 martin } dm_target_snapshot_config_t;
112 1.19.4.1 martin
113 1.19.4.1 martin typedef struct target_snapshot_origin_config {
114 1.19.4.1 martin dm_pdev_t *tsoc_real_dev;
115 1.19.4.1 martin /* list of snapshots ? */
116 1.19.4.1 martin } dm_target_snapshot_origin_config_t;
117 1.13 haad
118 1.4 haad #ifdef DM_TARGET_MODULE
119 1.4 haad /*
120 1.4 haad * Every target can be compiled directly to dm driver or as a
121 1.4 haad * separate module this part of target is used for loading targets
122 1.4 haad * to dm driver.
123 1.4 haad * Target can be unloaded from kernel only if there are no users of
124 1.4 haad * it e.g. there are no devices which uses that target.
125 1.4 haad */
126 1.4 haad #include <sys/kernel.h>
127 1.4 haad #include <sys/module.h>
128 1.4 haad
129 1.7 haad MODULE(MODULE_CLASS_MISC, dm_target_snapshot, "dm");
130 1.4 haad
131 1.4 haad static int
132 1.4 haad dm_target_snapshot_modcmd(modcmd_t cmd, void *arg)
133 1.4 haad {
134 1.4 haad dm_target_t *dmt, *dmt1;
135 1.4 haad int r;
136 1.8 haad
137 1.4 haad switch (cmd) {
138 1.4 haad case MODULE_CMD_INIT:
139 1.8 haad if (((dmt = dm_target_lookup("snapshot")) != NULL)) {
140 1.8 haad dm_target_unbusy(dmt);
141 1.8 haad return EEXIST;
142 1.8 haad }
143 1.12 haad if (((dmt = dm_target_lookup("snapshot-origin")) != NULL)) {
144 1.8 haad dm_target_unbusy(dmt);
145 1.4 haad return EEXIST;
146 1.8 haad }
147 1.4 haad dmt = dm_target_alloc("snapshot");
148 1.4 haad dmt1 = dm_target_alloc("snapshot-origin");
149 1.4 haad
150 1.4 haad dmt->version[0] = 1;
151 1.4 haad dmt->version[1] = 0;
152 1.4 haad dmt->version[2] = 5;
153 1.4 haad dmt->init = &dm_target_snapshot_init;
154 1.19.4.1 martin dmt->table = &dm_target_snapshot_table;
155 1.4 haad dmt->strategy = &dm_target_snapshot_strategy;
156 1.19.4.1 martin dmt->sync = &dm_target_snapshot_sync;
157 1.4 haad dmt->destroy = &dm_target_snapshot_destroy;
158 1.19.4.1 martin //dmt->upcall = &dm_target_snapshot_upcall;
159 1.4 haad
160 1.4 haad r = dm_target_insert(dmt);
161 1.4 haad
162 1.4 haad dmt1->version[0] = 1;
163 1.4 haad dmt1->version[1] = 0;
164 1.4 haad dmt1->version[2] = 5;
165 1.4 haad dmt1->init = &dm_target_snapshot_orig_init;
166 1.19.4.1 martin dmt1->table = &dm_target_snapshot_orig_table;
167 1.4 haad dmt1->strategy = &dm_target_snapshot_orig_strategy;
168 1.13 haad dmt1->sync = &dm_target_snapshot_orig_sync;
169 1.4 haad dmt1->destroy = &dm_target_snapshot_orig_destroy;
170 1.19.4.1 martin //dmt1->upcall = &dm_target_snapshot_orig_upcall;
171 1.4 haad
172 1.4 haad r = dm_target_insert(dmt1);
173 1.4 haad break;
174 1.4 haad
175 1.4 haad case MODULE_CMD_FINI:
176 1.4 haad /*
177 1.4 haad * Try to remove snapshot target if it works remove snap-origin
178 1.4 haad * it is not possible to remove snapshot and do not remove
179 1.4 haad * snap-origin because they are used together.
180 1.4 haad */
181 1.4 haad if ((r = dm_target_rem("snapshot")) == 0)
182 1.4 haad r = dm_target_rem("snapshot-origin");
183 1.6 haad
184 1.4 haad break;
185 1.4 haad
186 1.4 haad case MODULE_CMD_STAT:
187 1.4 haad return ENOTTY;
188 1.4 haad
189 1.4 haad default:
190 1.4 haad return ENOTTY;
191 1.4 haad }
192 1.4 haad
193 1.4 haad return r;
194 1.4 haad }
195 1.4 haad #endif
196 1.4 haad
197 1.2 haad /*
198 1.2 haad * Init function called from dm_table_load_ioctl.
199 1.12 haad * argv: /dev/mapper/my_data_org /dev/mapper/tsc_cow_dev p 64
200 1.2 haad * snapshot_origin device, cow device, persistent flag, chunk size
201 1.2 haad */
202 1.2 haad int
203 1.19.4.1 martin dm_target_snapshot_init(dm_table_entry_t *table_en, int argc, char **argv)
204 1.2 haad {
205 1.2 haad dm_target_snapshot_config_t *tsc;
206 1.2 haad dm_pdev_t *dmp_snap, *dmp_cow;
207 1.2 haad
208 1.2 haad dmp_cow = NULL;
209 1.2 haad
210 1.2 haad printf("Snapshot target init function called!!\n");
211 1.2 haad printf("Snapshotted device: %s, cow device %s,\n\t persistent flag: %s, "
212 1.2 haad "chunk size: %s\n", argv[0], argv[1], argv[2], argv[3]);
213 1.12 haad
214 1.2 haad /* Insert snap device to global pdev list */
215 1.2 haad if ((dmp_snap = dm_pdev_insert(argv[0])) == NULL)
216 1.2 haad return ENOENT;
217 1.12 haad
218 1.17 agc if ((tsc = kmem_alloc(sizeof(*tsc), KM_NOSLEEP)) == NULL)
219 1.2 haad return 1;
220 1.12 haad
221 1.2 haad tsc->tsc_persistent_dev = 0;
222 1.12 haad
223 1.2 haad /* There is now cow device for nonpersistent snapshot devices */
224 1.2 haad if (strcmp(argv[2], "p") == 0) {
225 1.2 haad tsc->tsc_persistent_dev = 1;
226 1.12 haad
227 1.2 haad /* Insert cow device to global pdev list */
228 1.17 agc if ((dmp_cow = dm_pdev_insert(argv[1])) == NULL) {
229 1.17 agc kmem_free(tsc, sizeof(*tsc));
230 1.12 haad return ENOENT;
231 1.17 agc }
232 1.2 haad }
233 1.19.4.1 martin tsc->tsc_chunk_size = atoi64(argv[3]);
234 1.12 haad
235 1.2 haad tsc->tsc_snap_dev = dmp_snap;
236 1.2 haad tsc->tsc_cow_dev = dmp_cow;
237 1.12 haad
238 1.19.4.1 martin dm_table_add_deps(table_en, dmp_snap);
239 1.19.4.1 martin dm_table_add_deps(table_en, dmp_cow);
240 1.19.4.1 martin table_en->target_config = tsc;
241 1.12 haad
242 1.2 haad return 0;
243 1.2 haad }
244 1.19 christos
245 1.2 haad /*
246 1.19.4.1 martin * Table routine is called to get params string, which is target
247 1.2 haad * specific. When dm_table_status_ioctl is called with flag
248 1.2 haad * DM_STATUS_TABLE_FLAG I have to sent params string back.
249 1.2 haad */
250 1.2 haad char *
251 1.19.4.1 martin dm_target_snapshot_table(void *target_config)
252 1.2 haad {
253 1.2 haad dm_target_snapshot_config_t *tsc;
254 1.12 haad
255 1.2 haad uint32_t i;
256 1.2 haad uint32_t count;
257 1.2 haad size_t prm_len, cow_len;
258 1.19.4.1 martin char *params;
259 1.12 haad
260 1.2 haad tsc = target_config;
261 1.12 haad
262 1.2 haad prm_len = 0;
263 1.2 haad cow_len = 0;
264 1.2 haad count = 0;
265 1.2 haad
266 1.19.4.1 martin printf("Snapshot target table function called\n");
267 1.2 haad
268 1.2 haad /* count number of chars in offset */
269 1.12 haad for (i = tsc->tsc_chunk_size; i != 0; i /= 10)
270 1.2 haad count++;
271 1.12 haad
272 1.12 haad if (tsc->tsc_persistent_dev)
273 1.2 haad cow_len = strlen(tsc->tsc_cow_dev->name);
274 1.12 haad
275 1.2 haad /* length of names + count of chars + spaces and null char */
276 1.2 haad prm_len = strlen(tsc->tsc_snap_dev->name) + cow_len + count + 5;
277 1.12 haad
278 1.2 haad if ((params = kmem_alloc(prm_len, KM_NOSLEEP)) == NULL)
279 1.2 haad return NULL;
280 1.2 haad
281 1.12 haad printf("%s %s %s %" PRIu64 "\n", tsc->tsc_snap_dev->name,
282 1.12 haad tsc->tsc_cow_dev->name, tsc->tsc_persistent_dev ? "p" : "n",
283 1.12 haad tsc->tsc_chunk_size);
284 1.12 haad
285 1.12 haad snprintf(params, prm_len, "%s %s %s %" PRIu64, tsc->tsc_snap_dev->name,
286 1.12 haad tsc->tsc_persistent_dev ? tsc->tsc_cow_dev->name : "",
287 1.12 haad tsc->tsc_persistent_dev ? "p" : "n",
288 1.12 haad tsc->tsc_chunk_size);
289 1.12 haad
290 1.2 haad return params;
291 1.2 haad }
292 1.19 christos
293 1.2 haad /* Strategy routine called from dm_strategy. */
294 1.2 haad int
295 1.19.4.1 martin dm_target_snapshot_strategy(dm_table_entry_t *table_en, struct buf *bp)
296 1.2 haad {
297 1.2 haad
298 1.2 haad bp->b_error = EIO;
299 1.2 haad bp->b_resid = 0;
300 1.2 haad
301 1.2 haad biodone(bp);
302 1.12 haad
303 1.2 haad return 0;
304 1.2 haad }
305 1.19 christos
306 1.19.4.1 martin int
307 1.19.4.1 martin dm_target_snapshot_sync(dm_table_entry_t *table_en)
308 1.19.4.1 martin {
309 1.19.4.1 martin
310 1.19.4.1 martin return 0;
311 1.19.4.1 martin }
312 1.19.4.1 martin
313 1.2 haad /* Doesn't do anything here. */
314 1.2 haad int
315 1.19.4.1 martin dm_target_snapshot_destroy(dm_table_entry_t *table_en)
316 1.2 haad {
317 1.12 haad
318 1.2 haad /*
319 1.2 haad * Destroy function is called for every target even if it
320 1.2 haad * doesn't have target_config.
321 1.2 haad */
322 1.2 haad if (table_en->target_config == NULL)
323 1.19 christos goto out;
324 1.12 haad
325 1.2 haad printf("Snapshot target destroy function called\n");
326 1.12 haad
327 1.19 christos dm_target_snapshot_config_t *tsc = table_en->target_config;
328 1.12 haad
329 1.2 haad /* Decrement pdev ref counter if 0 remove it */
330 1.2 haad dm_pdev_decr(tsc->tsc_snap_dev);
331 1.2 haad if (tsc->tsc_persistent_dev)
332 1.2 haad dm_pdev_decr(tsc->tsc_cow_dev);
333 1.3 haad
334 1.19 christos kmem_free(tsc, sizeof(*tsc));
335 1.19 christos out:
336 1.12 haad /* Unbusy target so we can unload it */
337 1.3 haad dm_target_unbusy(table_en->target);
338 1.12 haad
339 1.2 haad return 0;
340 1.2 haad }
341 1.19 christos
342 1.19.4.1 martin #if 0
343 1.2 haad /* Upcall is used to inform other depended devices about IO. */
344 1.2 haad int
345 1.19.4.1 martin dm_target_snapshot_upcall(dm_table_entry_t *table_en, struct buf *bp)
346 1.2 haad {
347 1.19.4.1 martin
348 1.2 haad printf("dm_target_snapshot_upcall called\n");
349 1.12 haad
350 1.12 haad printf("upcall buf flags %s %s\n",
351 1.12 haad (bp->b_flags & B_WRITE) ? "B_WRITE" : "",
352 1.12 haad (bp->b_flags & B_READ) ? "B_READ" : "");
353 1.12 haad
354 1.2 haad return 0;
355 1.2 haad }
356 1.19.4.1 martin #endif
357 1.19 christos
358 1.2 haad /*
359 1.2 haad * dm target snapshot origin routines.
360 1.2 haad *
361 1.2 haad * Keep for compatibility with linux lvm2tools. They use two targets
362 1.2 haad * to implement snapshots. Snapshot target will implement exception
363 1.2 haad * store and snapshot origin will implement device which calls every
364 1.2 haad * snapshot device when write is done on master device.
365 1.2 haad */
366 1.2 haad
367 1.12 haad /*
368 1.12 haad * Init function called from dm_table_load_ioctl.
369 1.12 haad *
370 1.2 haad * argv: /dev/mapper/my_data_real
371 1.2 haad */
372 1.2 haad int
373 1.19.4.1 martin dm_target_snapshot_orig_init(dm_table_entry_t *table_en, int argc, char **argv)
374 1.2 haad {
375 1.2 haad dm_target_snapshot_origin_config_t *tsoc;
376 1.2 haad dm_pdev_t *dmp_real;
377 1.2 haad
378 1.2 haad printf("Snapshot origin target init function called!!\n");
379 1.19.4.1 martin printf("Parent device: %s\n", argv[0]);
380 1.2 haad
381 1.2 haad /* Insert snap device to global pdev list */
382 1.19.4.1 martin if ((dmp_real = dm_pdev_insert(argv[0])) == NULL)
383 1.2 haad return ENOENT;
384 1.12 haad
385 1.2 haad if ((tsoc = kmem_alloc(sizeof(dm_target_snapshot_origin_config_t), KM_NOSLEEP))
386 1.2 haad == NULL)
387 1.2 haad return 1;
388 1.2 haad
389 1.2 haad tsoc->tsoc_real_dev = dmp_real;
390 1.12 haad
391 1.19.4.1 martin dm_table_add_deps(table_en, dmp_real);
392 1.19.4.1 martin table_en->target_config = tsoc;
393 1.12 haad
394 1.2 haad return 0;
395 1.2 haad }
396 1.19 christos
397 1.2 haad /*
398 1.19.4.1 martin * Table routine is called to get params string, which is target
399 1.2 haad * specific. When dm_table_status_ioctl is called with flag
400 1.2 haad * DM_STATUS_TABLE_FLAG I have to sent params string back.
401 1.2 haad */
402 1.2 haad char *
403 1.19.4.1 martin dm_target_snapshot_orig_table(void *target_config)
404 1.2 haad {
405 1.2 haad dm_target_snapshot_origin_config_t *tsoc;
406 1.2 haad
407 1.2 haad size_t prm_len;
408 1.2 haad char *params;
409 1.12 haad
410 1.2 haad tsoc = target_config;
411 1.12 haad
412 1.2 haad prm_len = 0;
413 1.12 haad
414 1.19.4.1 martin printf("Snapshot origin target table function called\n");
415 1.12 haad
416 1.2 haad /* length of names + count of chars + spaces and null char */
417 1.2 haad prm_len = strlen(tsoc->tsoc_real_dev->name) + 1;
418 1.12 haad
419 1.12 haad printf("real_dev name %s\n", tsoc->tsoc_real_dev->name);
420 1.12 haad
421 1.2 haad if ((params = kmem_alloc(prm_len, KM_NOSLEEP)) == NULL)
422 1.2 haad return NULL;
423 1.2 haad
424 1.2 haad printf("%s\n", tsoc->tsoc_real_dev->name);
425 1.12 haad
426 1.2 haad snprintf(params, prm_len, "%s", tsoc->tsoc_real_dev->name);
427 1.12 haad
428 1.2 haad return params;
429 1.2 haad }
430 1.19 christos
431 1.2 haad /* Strategy routine called from dm_strategy. */
432 1.2 haad int
433 1.19.4.1 martin dm_target_snapshot_orig_strategy(dm_table_entry_t *table_en, struct buf *bp)
434 1.2 haad {
435 1.2 haad
436 1.2 haad bp->b_error = EIO;
437 1.2 haad bp->b_resid = 0;
438 1.2 haad
439 1.2 haad biodone(bp);
440 1.12 haad
441 1.2 haad return 0;
442 1.2 haad }
443 1.19 christos
444 1.13 haad /*
445 1.13 haad * Sync underlying disk caches.
446 1.13 haad */
447 1.13 haad int
448 1.19.4.1 martin dm_target_snapshot_orig_sync(dm_table_entry_t *table_en)
449 1.13 haad {
450 1.13 haad int cmd;
451 1.13 haad dm_target_snapshot_origin_config_t *tsoc;
452 1.13 haad
453 1.13 haad tsoc = table_en->target_config;
454 1.13 haad
455 1.13 haad cmd = 1;
456 1.13 haad
457 1.19 christos return VOP_IOCTL(tsoc->tsoc_real_dev->pdev_vnode, DIOCCACHESYNC,
458 1.19 christos &cmd, FREAD|FWRITE, kauth_cred_get());
459 1.13 haad }
460 1.19 christos
461 1.2 haad /* Decrement pdev and free allocated space. */
462 1.2 haad int
463 1.19.4.1 martin dm_target_snapshot_orig_destroy(dm_table_entry_t *table_en)
464 1.2 haad {
465 1.12 haad
466 1.2 haad /*
467 1.2 haad * Destroy function is called for every target even if it
468 1.2 haad * doesn't have target_config.
469 1.2 haad */
470 1.12 haad
471 1.2 haad if (table_en->target_config == NULL)
472 1.19 christos goto out;
473 1.12 haad
474 1.19 christos dm_target_snapshot_origin_config_t *tsoc = table_en->target_config;
475 1.12 haad
476 1.2 haad /* Decrement pdev ref counter if 0 remove it */
477 1.2 haad dm_pdev_decr(tsoc->tsoc_real_dev);
478 1.3 haad
479 1.19 christos kmem_free(tsoc, sizeof(*tsoc));
480 1.19 christos out:
481 1.3 haad /* Unbusy target so we can unload it */
482 1.3 haad dm_target_unbusy(table_en->target);
483 1.12 haad
484 1.2 haad return 0;
485 1.2 haad }
486 1.19 christos
487 1.19.4.1 martin #if 0
488 1.2 haad /* Unsupported for this target. */
489 1.2 haad int
490 1.19.4.1 martin dm_target_snapshot_orig_upcall(dm_table_entry_t *table_en, struct buf *bp)
491 1.2 haad {
492 1.19.4.1 martin
493 1.2 haad return 0;
494 1.2 haad }
495 1.19.4.1 martin #endif
496