Home | History | Annotate | Line # | Download | only in dm
dm_target_mirror.c revision 1.3.2.2
      1  1.3.2.2  mjf /*$NetBSD: dm_target_mirror.c,v 1.3.2.2 2009/01/17 13:28:53 mjf Exp $*/
      2  1.3.2.2  mjf 
      3  1.3.2.2  mjf /*
      4  1.3.2.2  mjf  * Copyright (c) 2009 The NetBSD Foundation, Inc.
      5  1.3.2.2  mjf  * All rights reserved.
      6  1.3.2.2  mjf  *
      7  1.3.2.2  mjf  * This code is derived from software contributed to The NetBSD Foundation
      8  1.3.2.2  mjf  * by Adam Hamsik.
      9  1.3.2.2  mjf  *
     10  1.3.2.2  mjf  * Redistribution and use in source and binary forms, with or without
     11  1.3.2.2  mjf  * modification, are permitted provided that the following conditions
     12  1.3.2.2  mjf  * are met:
     13  1.3.2.2  mjf  * 1. Redistributions of source code must retain the above copyright
     14  1.3.2.2  mjf  *    notice, this list of conditions and the following disclaimer.
     15  1.3.2.2  mjf  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.3.2.2  mjf  *    notice, this list of conditions and the following disclaimer in the
     17  1.3.2.2  mjf  *    documentation and/or other materials provided with the distribution.
     18  1.3.2.2  mjf  *
     19  1.3.2.2  mjf  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.3.2.2  mjf  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.3.2.2  mjf  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.3.2.2  mjf  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.3.2.2  mjf  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.3.2.2  mjf  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.3.2.2  mjf  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.3.2.2  mjf  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.3.2.2  mjf  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.3.2.2  mjf  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.3.2.2  mjf  * POSSIBILITY OF SUCH DAMAGE.
     30  1.3.2.2  mjf  */
     31  1.3.2.2  mjf 
     32  1.3.2.2  mjf /*
     33  1.3.2.2  mjf  * This file implements initial version of device-mapper mirror target.
     34  1.3.2.2  mjf  */
     35  1.3.2.2  mjf #include <sys/types.h>
     36  1.3.2.2  mjf #include <sys/param.h>
     37  1.3.2.2  mjf 
     38  1.3.2.2  mjf #include <sys/buf.h>
     39  1.3.2.2  mjf 
     40  1.3.2.2  mjf #include "dm.h"
     41  1.3.2.2  mjf 
     42  1.3.2.2  mjf #ifdef DM_TARGET_MODULE
     43  1.3.2.2  mjf /*
     44  1.3.2.2  mjf  * Every target can be compiled directly to dm driver or as a
     45  1.3.2.2  mjf  * separate module this part of target is used for loading targets
     46  1.3.2.2  mjf  * to dm driver.
     47  1.3.2.2  mjf  * Target can be unloaded from kernel only if there are no users of
     48  1.3.2.2  mjf  * it e.g. there are no devices which uses that target.
     49  1.3.2.2  mjf  */
     50  1.3.2.2  mjf #include <sys/kernel.h>
     51  1.3.2.2  mjf #include <sys/module.h>
     52  1.3.2.2  mjf 
     53  1.3.2.2  mjf MODULE(MODULE_CLASS_MISC, dm_target_mirror, "dm");
     54  1.3.2.2  mjf 
     55  1.3.2.2  mjf static int
     56  1.3.2.2  mjf dm_target_mirror_modcmd(modcmd_t cmd, void *arg)
     57  1.3.2.2  mjf {
     58  1.3.2.2  mjf 	dm_target_t *dmt;
     59  1.3.2.2  mjf 	int r;
     60  1.3.2.2  mjf 	dmt = NULL;
     61  1.3.2.2  mjf 
     62  1.3.2.2  mjf 	switch (cmd) {
     63  1.3.2.2  mjf 	case MODULE_CMD_INIT:
     64  1.3.2.2  mjf 		if ((dmt = dm_target_lookup("mirror")) != NULL)
     65  1.3.2.2  mjf 			return EEXIST;
     66  1.3.2.2  mjf 
     67  1.3.2.2  mjf 		dmt = dm_target_alloc("mirror");
     68  1.3.2.2  mjf 
     69  1.3.2.2  mjf 		dmt->version[0] = 1;
     70  1.3.2.2  mjf 		dmt->version[1] = 0;
     71  1.3.2.2  mjf 		dmt->version[2] = 0;
     72  1.3.2.2  mjf 		strlcpy(dmt->name, "mirror", DM_MAX_TYPE_NAME);
     73  1.3.2.2  mjf 		dmt->init = &dm_target_mirror_init;
     74  1.3.2.2  mjf 		dmt->status = &dm_target_mirror_status;
     75  1.3.2.2  mjf 		dmt->strategy = &dm_target_mirror_strategy;
     76  1.3.2.2  mjf 		dmt->deps = &dm_target_mirror_deps;
     77  1.3.2.2  mjf 		dmt->destroy = &dm_target_mirror_destroy;
     78  1.3.2.2  mjf 		dmt->upcall = &dm_target_mirror_upcall;
     79  1.3.2.2  mjf 
     80  1.3.2.2  mjf 		r = dm_target_insert(dmt);
     81  1.3.2.2  mjf 
     82  1.3.2.2  mjf 		break;
     83  1.3.2.2  mjf 
     84  1.3.2.2  mjf 	case MODULE_CMD_FINI:
     85  1.3.2.2  mjf 		r = dm_target_rem("mirror");
     86  1.3.2.2  mjf 		break;
     87  1.3.2.2  mjf 
     88  1.3.2.2  mjf 	case MODULE_CMD_STAT:
     89  1.3.2.2  mjf 		return ENOTTY;
     90  1.3.2.2  mjf 
     91  1.3.2.2  mjf 	default:
     92  1.3.2.2  mjf 		return ENOTTY;
     93  1.3.2.2  mjf 	}
     94  1.3.2.2  mjf 
     95  1.3.2.2  mjf 	return r;
     96  1.3.2.2  mjf }
     97  1.3.2.2  mjf 
     98  1.3.2.2  mjf #endif
     99  1.3.2.2  mjf 
    100  1.3.2.2  mjf /* Init function called from dm_table_load_ioctl. */
    101  1.3.2.2  mjf int
    102  1.3.2.2  mjf dm_target_mirror_init(dm_dev_t *dmv, void **target_config, char *argv)
    103  1.3.2.2  mjf {
    104  1.3.2.2  mjf 
    105  1.3.2.2  mjf 	printf("Mirror target init function called!!\n");
    106  1.3.2.2  mjf 
    107  1.3.2.2  mjf 	*target_config = NULL;
    108  1.3.2.2  mjf 
    109  1.3.2.2  mjf 	dmv->dev_type = DM_MIRROR_DEV;
    110  1.3.2.2  mjf 
    111  1.3.2.2  mjf 	return ENOSYS;
    112  1.3.2.2  mjf }
    113  1.3.2.2  mjf 
    114  1.3.2.2  mjf /* Status routine called to get params string. */
    115  1.3.2.2  mjf char *
    116  1.3.2.2  mjf dm_target_mirror_status(void *target_config)
    117  1.3.2.2  mjf {
    118  1.3.2.2  mjf 	return NULL;
    119  1.3.2.2  mjf }
    120  1.3.2.2  mjf 
    121  1.3.2.2  mjf /* Strategy routine called from dm_strategy. */
    122  1.3.2.2  mjf int
    123  1.3.2.2  mjf dm_target_mirror_strategy(dm_table_entry_t *table_en, struct buf *bp)
    124  1.3.2.2  mjf {
    125  1.3.2.2  mjf 
    126  1.3.2.2  mjf 	printf("Mirror target read function called!!\n");
    127  1.3.2.2  mjf 
    128  1.3.2.2  mjf 	bp->b_error = EIO;
    129  1.3.2.2  mjf 	bp->b_resid = 0;
    130  1.3.2.2  mjf 
    131  1.3.2.2  mjf 	biodone(bp);
    132  1.3.2.2  mjf 
    133  1.3.2.2  mjf 	return 0;
    134  1.3.2.2  mjf }
    135  1.3.2.2  mjf 
    136  1.3.2.2  mjf /* Doesn't do anything here. */
    137  1.3.2.2  mjf int
    138  1.3.2.2  mjf dm_target_mirror_destroy(dm_table_entry_t *table_en)
    139  1.3.2.2  mjf {
    140  1.3.2.2  mjf 	table_en->target_config = NULL;
    141  1.3.2.2  mjf 
    142  1.3.2.2  mjf 	/* Unbusy target so we can unload it */
    143  1.3.2.2  mjf 	dm_target_unbusy(table_en->target);
    144  1.3.2.2  mjf 
    145  1.3.2.2  mjf 	return 0;
    146  1.3.2.2  mjf }
    147  1.3.2.2  mjf 
    148  1.3.2.2  mjf /* Doesn't not need to do anything here. */
    149  1.3.2.2  mjf int
    150  1.3.2.2  mjf dm_target_mirror_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
    151  1.3.2.2  mjf {
    152  1.3.2.2  mjf 	return 0;
    153  1.3.2.2  mjf }
    154  1.3.2.2  mjf 
    155  1.3.2.2  mjf /* Unsupported for this target. */
    156  1.3.2.2  mjf int
    157  1.3.2.2  mjf dm_target_mirror_upcall(dm_table_entry_t *table_en, struct buf *bp)
    158  1.3.2.2  mjf {
    159  1.3.2.2  mjf 	return 0;
    160  1.3.2.2  mjf }
    161