Home | History | Annotate | Line # | Download | only in dm
dm_target_snapshot.c revision 1.37.2.1
      1  1.37.2.1        ad /*        $NetBSD: dm_target_snapshot.c,v 1.37.2.1 2020/01/25 22:38:45 ad 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.37.2.1        ad __KERNEL_RCSID(0, "$NetBSD: dm_target_snapshot.c,v 1.37.2.1 2020/01/25 22:38:45 ad 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.30   tkusumi int dm_target_snapshot_init(dm_table_entry_t *, int, char **);
     90      1.32   tkusumi char *dm_target_snapshot_table(void *);
     91      1.13      haad int dm_target_snapshot_strategy(dm_table_entry_t *, struct buf *);
     92      1.29   tkusumi int dm_target_snapshot_sync(dm_table_entry_t *);
     93      1.13      haad int dm_target_snapshot_destroy(dm_table_entry_t *);
     94  1.37.2.1        ad //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.30   tkusumi int dm_target_snapshot_orig_init(dm_table_entry_t *, int, char **);
     98      1.32   tkusumi 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.37.2.1        ad //int dm_target_snapshot_orig_upcall(dm_table_entry_t *, struct buf *);
    103      1.13      haad 
    104      1.28   tkusumi typedef struct target_snapshot_config {
    105      1.28   tkusumi 	dm_pdev_t *tsc_snap_dev;
    106      1.28   tkusumi 	/* cow dev is set only for persistent snapshot devices */
    107      1.28   tkusumi 	dm_pdev_t *tsc_cow_dev;
    108      1.28   tkusumi 
    109      1.28   tkusumi 	uint64_t tsc_chunk_size;
    110      1.28   tkusumi 	uint32_t tsc_persistent_dev;
    111      1.28   tkusumi } dm_target_snapshot_config_t;
    112      1.28   tkusumi 
    113      1.28   tkusumi typedef struct target_snapshot_origin_config {
    114      1.28   tkusumi 	dm_pdev_t *tsoc_real_dev;
    115      1.28   tkusumi 	/* list of snapshots ? */
    116      1.28   tkusumi } dm_target_snapshot_origin_config_t;
    117      1.28   tkusumi 
    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.32   tkusumi 		dmt->table = &dm_target_snapshot_table;
    155       1.4      haad 		dmt->strategy = &dm_target_snapshot_strategy;
    156      1.29   tkusumi 		dmt->sync = &dm_target_snapshot_sync;
    157       1.4      haad 		dmt->destroy = &dm_target_snapshot_destroy;
    158  1.37.2.1        ad 		//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.32   tkusumi 		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.37.2.1        ad 		//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.30   tkusumi 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.20       chs 	tsc = kmem_alloc(sizeof(*tsc), KM_SLEEP);
    219       1.2      haad 	tsc->tsc_persistent_dev = 0;
    220      1.12      haad 
    221       1.2      haad 	/* There is now cow device for nonpersistent snapshot devices */
    222       1.2      haad 	if (strcmp(argv[2], "p") == 0) {
    223       1.2      haad 		tsc->tsc_persistent_dev = 1;
    224      1.12      haad 
    225       1.2      haad 		/* Insert cow device to global pdev list */
    226      1.17       agc 		if ((dmp_cow = dm_pdev_insert(argv[1])) == NULL) {
    227      1.17       agc 			kmem_free(tsc, sizeof(*tsc));
    228      1.12      haad 			return ENOENT;
    229      1.17       agc 		}
    230       1.2      haad 	}
    231      1.36   tkusumi 	tsc->tsc_chunk_size = atoi64(argv[3]);
    232      1.12      haad 
    233       1.2      haad 	tsc->tsc_snap_dev = dmp_snap;
    234       1.2      haad 	tsc->tsc_cow_dev = dmp_cow;
    235      1.12      haad 
    236      1.37   tkusumi 	dm_table_add_deps(table_en, dmp_snap);
    237      1.37   tkusumi 	dm_table_add_deps(table_en, dmp_cow);
    238      1.26   tkusumi 	table_en->target_config = tsc;
    239      1.12      haad 
    240       1.2      haad 	return 0;
    241       1.2      haad }
    242      1.19  christos 
    243       1.2      haad /*
    244      1.32   tkusumi  * Table routine is called to get params string, which is target
    245       1.2      haad  * specific. When dm_table_status_ioctl is called with flag
    246       1.2      haad  * DM_STATUS_TABLE_FLAG I have to sent params string back.
    247       1.2      haad  */
    248       1.2      haad char *
    249      1.32   tkusumi dm_target_snapshot_table(void *target_config)
    250       1.2      haad {
    251       1.2      haad 	dm_target_snapshot_config_t *tsc;
    252      1.12      haad 
    253       1.2      haad 	uint32_t i;
    254       1.2      haad 	uint32_t count;
    255       1.2      haad 	size_t prm_len, cow_len;
    256      1.27   tkusumi 	char *params;
    257      1.12      haad 
    258       1.2      haad 	tsc = target_config;
    259      1.12      haad 
    260       1.2      haad 	prm_len = 0;
    261       1.2      haad 	cow_len = 0;
    262       1.2      haad 	count = 0;
    263       1.2      haad 
    264      1.32   tkusumi 	printf("Snapshot target table function called\n");
    265       1.2      haad 
    266       1.2      haad 	/* count number of chars in offset */
    267      1.12      haad 	for (i = tsc->tsc_chunk_size; i != 0; i /= 10)
    268       1.2      haad 		count++;
    269      1.12      haad 
    270      1.12      haad 	if (tsc->tsc_persistent_dev)
    271       1.2      haad 		cow_len = strlen(tsc->tsc_cow_dev->name);
    272      1.12      haad 
    273       1.2      haad 	/* length of names + count of chars + spaces and null char */
    274       1.2      haad 	prm_len = strlen(tsc->tsc_snap_dev->name) + cow_len + count + 5;
    275      1.12      haad 
    276      1.20       chs 	params = kmem_alloc(prm_len, KM_SLEEP);
    277       1.2      haad 
    278      1.12      haad 	printf("%s %s %s %" PRIu64 "\n", tsc->tsc_snap_dev->name,
    279      1.12      haad 	    tsc->tsc_cow_dev->name, tsc->tsc_persistent_dev ? "p" : "n",
    280      1.12      haad 	    tsc->tsc_chunk_size);
    281      1.12      haad 
    282      1.12      haad 	snprintf(params, prm_len, "%s %s %s %" PRIu64, tsc->tsc_snap_dev->name,
    283      1.12      haad 	    tsc->tsc_persistent_dev ? tsc->tsc_cow_dev->name : "",
    284      1.12      haad 	    tsc->tsc_persistent_dev ? "p" : "n",
    285      1.12      haad 	    tsc->tsc_chunk_size);
    286      1.12      haad 
    287       1.2      haad 	return params;
    288       1.2      haad }
    289      1.19  christos 
    290       1.2      haad /* Strategy routine called from dm_strategy. */
    291       1.2      haad int
    292      1.25   tkusumi dm_target_snapshot_strategy(dm_table_entry_t *table_en, struct buf *bp)
    293       1.2      haad {
    294       1.2      haad 
    295       1.2      haad 	bp->b_error = EIO;
    296       1.2      haad 	bp->b_resid = 0;
    297       1.2      haad 
    298       1.2      haad 	biodone(bp);
    299      1.12      haad 
    300       1.2      haad 	return 0;
    301       1.2      haad }
    302      1.19  christos 
    303      1.29   tkusumi int
    304      1.29   tkusumi dm_target_snapshot_sync(dm_table_entry_t *table_en)
    305      1.29   tkusumi {
    306      1.35   tkusumi 
    307      1.29   tkusumi 	return 0;
    308      1.29   tkusumi }
    309      1.29   tkusumi 
    310       1.2      haad /* Doesn't do anything here. */
    311       1.2      haad int
    312      1.25   tkusumi dm_target_snapshot_destroy(dm_table_entry_t *table_en)
    313       1.2      haad {
    314      1.12      haad 
    315       1.2      haad 	/*
    316       1.2      haad 	 * Destroy function is called for every target even if it
    317       1.2      haad 	 * doesn't have target_config.
    318       1.2      haad 	 */
    319       1.2      haad 	if (table_en->target_config == NULL)
    320      1.19  christos 		goto out;
    321      1.12      haad 
    322       1.2      haad 	printf("Snapshot target destroy function called\n");
    323      1.12      haad 
    324      1.19  christos 	dm_target_snapshot_config_t *tsc = table_en->target_config;
    325      1.12      haad 
    326       1.2      haad 	/* Decrement pdev ref counter if 0 remove it */
    327       1.2      haad 	dm_pdev_decr(tsc->tsc_snap_dev);
    328       1.2      haad 	if (tsc->tsc_persistent_dev)
    329       1.2      haad 		dm_pdev_decr(tsc->tsc_cow_dev);
    330       1.3      haad 
    331      1.19  christos 	kmem_free(tsc, sizeof(*tsc));
    332      1.19  christos out:
    333      1.12      haad 	/* Unbusy target so we can unload it */
    334       1.3      haad 	dm_target_unbusy(table_en->target);
    335      1.12      haad 
    336       1.2      haad 	return 0;
    337       1.2      haad }
    338      1.19  christos 
    339  1.37.2.1        ad #if 0
    340       1.2      haad /* Upcall is used to inform other depended devices about IO. */
    341       1.2      haad int
    342      1.25   tkusumi dm_target_snapshot_upcall(dm_table_entry_t *table_en, struct buf *bp)
    343       1.2      haad {
    344      1.35   tkusumi 
    345       1.2      haad 	printf("dm_target_snapshot_upcall called\n");
    346      1.12      haad 
    347      1.12      haad 	printf("upcall buf flags %s %s\n",
    348      1.12      haad 	    (bp->b_flags & B_WRITE) ? "B_WRITE" : "",
    349      1.12      haad 	    (bp->b_flags & B_READ) ? "B_READ" : "");
    350      1.12      haad 
    351       1.2      haad 	return 0;
    352       1.2      haad }
    353  1.37.2.1        ad #endif
    354      1.19  christos 
    355       1.2      haad /*
    356       1.2      haad  * dm target snapshot origin routines.
    357       1.2      haad  *
    358       1.2      haad  * Keep for compatibility with linux lvm2tools. They use two targets
    359       1.2      haad  * to implement snapshots. Snapshot target will implement exception
    360       1.2      haad  * store and snapshot origin will implement device which calls every
    361       1.2      haad  * snapshot device when write is done on master device.
    362       1.2      haad  */
    363       1.2      haad 
    364      1.12      haad /*
    365      1.12      haad  * Init function called from dm_table_load_ioctl.
    366      1.12      haad  *
    367       1.2      haad  * argv: /dev/mapper/my_data_real
    368       1.2      haad  */
    369       1.2      haad int
    370      1.30   tkusumi dm_target_snapshot_orig_init(dm_table_entry_t *table_en, int argc, char **argv)
    371       1.2      haad {
    372       1.2      haad 	dm_target_snapshot_origin_config_t *tsoc;
    373       1.2      haad 	dm_pdev_t *dmp_real;
    374       1.2      haad 
    375       1.2      haad 	printf("Snapshot origin target init function called!!\n");
    376      1.30   tkusumi 	printf("Parent device: %s\n", argv[0]);
    377       1.2      haad 
    378       1.2      haad 	/* Insert snap device to global pdev list */
    379      1.30   tkusumi 	if ((dmp_real = dm_pdev_insert(argv[0])) == NULL)
    380       1.2      haad 		return ENOENT;
    381      1.12      haad 
    382      1.20       chs 	tsoc = kmem_alloc(sizeof(dm_target_snapshot_origin_config_t), KM_SLEEP);
    383       1.2      haad 	tsoc->tsoc_real_dev = dmp_real;
    384      1.12      haad 
    385      1.37   tkusumi 	dm_table_add_deps(table_en, dmp_real);
    386      1.26   tkusumi 	table_en->target_config = tsoc;
    387      1.12      haad 
    388       1.2      haad 	return 0;
    389       1.2      haad }
    390      1.19  christos 
    391       1.2      haad /*
    392      1.32   tkusumi  * Table routine is called to get params string, which is target
    393       1.2      haad  * specific. When dm_table_status_ioctl is called with flag
    394       1.2      haad  * DM_STATUS_TABLE_FLAG I have to sent params string back.
    395       1.2      haad  */
    396       1.2      haad char *
    397      1.32   tkusumi dm_target_snapshot_orig_table(void *target_config)
    398       1.2      haad {
    399       1.2      haad 	dm_target_snapshot_origin_config_t *tsoc;
    400       1.2      haad 
    401       1.2      haad 	size_t prm_len;
    402       1.2      haad 	char *params;
    403      1.12      haad 
    404       1.2      haad 	tsoc = target_config;
    405      1.12      haad 
    406       1.2      haad 	prm_len = 0;
    407      1.12      haad 
    408      1.32   tkusumi 	printf("Snapshot origin target table function called\n");
    409      1.12      haad 
    410       1.2      haad 	/* length of names + count of chars + spaces and null char */
    411       1.2      haad 	prm_len = strlen(tsoc->tsoc_real_dev->name) + 1;
    412      1.12      haad 
    413      1.12      haad 	printf("real_dev name %s\n", tsoc->tsoc_real_dev->name);
    414      1.12      haad 
    415      1.20       chs 	params = kmem_alloc(prm_len, KM_SLEEP);
    416       1.2      haad 
    417       1.2      haad 	printf("%s\n", tsoc->tsoc_real_dev->name);
    418      1.12      haad 
    419       1.2      haad 	snprintf(params, prm_len, "%s", tsoc->tsoc_real_dev->name);
    420      1.12      haad 
    421       1.2      haad 	return params;
    422       1.2      haad }
    423      1.19  christos 
    424       1.2      haad /* Strategy routine called from dm_strategy. */
    425       1.2      haad int
    426      1.25   tkusumi dm_target_snapshot_orig_strategy(dm_table_entry_t *table_en, struct buf *bp)
    427       1.2      haad {
    428       1.2      haad 
    429       1.2      haad 	bp->b_error = EIO;
    430       1.2      haad 	bp->b_resid = 0;
    431       1.2      haad 
    432       1.2      haad 	biodone(bp);
    433      1.12      haad 
    434       1.2      haad 	return 0;
    435       1.2      haad }
    436      1.19  christos 
    437      1.13      haad /*
    438      1.13      haad  * Sync underlying disk caches.
    439      1.13      haad  */
    440      1.13      haad int
    441      1.25   tkusumi dm_target_snapshot_orig_sync(dm_table_entry_t *table_en)
    442      1.13      haad {
    443      1.13      haad 	int cmd;
    444      1.13      haad 	dm_target_snapshot_origin_config_t *tsoc;
    445      1.13      haad 
    446      1.13      haad 	tsoc = table_en->target_config;
    447      1.13      haad 
    448      1.13      haad 	cmd = 1;
    449      1.13      haad 
    450      1.19  christos 	return VOP_IOCTL(tsoc->tsoc_real_dev->pdev_vnode,  DIOCCACHESYNC,
    451      1.19  christos 	    &cmd, FREAD|FWRITE, kauth_cred_get());
    452      1.13      haad }
    453      1.19  christos 
    454       1.2      haad /* Decrement pdev and free allocated space. */
    455       1.2      haad int
    456      1.25   tkusumi dm_target_snapshot_orig_destroy(dm_table_entry_t *table_en)
    457       1.2      haad {
    458      1.12      haad 
    459       1.2      haad 	/*
    460       1.2      haad 	 * Destroy function is called for every target even if it
    461       1.2      haad 	 * doesn't have target_config.
    462       1.2      haad 	 */
    463      1.12      haad 
    464       1.2      haad 	if (table_en->target_config == NULL)
    465      1.19  christos 		goto out;
    466      1.12      haad 
    467      1.19  christos 	dm_target_snapshot_origin_config_t *tsoc = table_en->target_config;
    468      1.12      haad 
    469       1.2      haad 	/* Decrement pdev ref counter if 0 remove it */
    470       1.2      haad 	dm_pdev_decr(tsoc->tsoc_real_dev);
    471       1.3      haad 
    472      1.19  christos 	kmem_free(tsoc, sizeof(*tsoc));
    473      1.19  christos out:
    474       1.3      haad 	/* Unbusy target so we can unload it */
    475       1.3      haad 	dm_target_unbusy(table_en->target);
    476      1.12      haad 
    477       1.2      haad 	return 0;
    478       1.2      haad }
    479      1.19  christos 
    480  1.37.2.1        ad #if 0
    481       1.2      haad /* Unsupported for this target. */
    482       1.2      haad int
    483      1.25   tkusumi dm_target_snapshot_orig_upcall(dm_table_entry_t *table_en, struct buf *bp)
    484       1.2      haad {
    485      1.35   tkusumi 
    486       1.2      haad 	return 0;
    487       1.2      haad }
    488  1.37.2.1        ad #endif
    489