Home | History | Annotate | Line # | Download | only in dm
dm_target_zero.c revision 1.10.4.1
      1  1.10.4.1  rmind /*        $NetBSD: dm_target_zero.c,v 1.10.4.1 2010/05/30 05:17:20 rmind 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.2   haad 
     32       1.2   haad 
     33       1.2   haad /*
     34       1.2   haad  * This file implements initial version of device-mapper zero target.
     35       1.2   haad  */
     36       1.2   haad #include <sys/types.h>
     37       1.2   haad #include <sys/param.h>
     38       1.2   haad 
     39       1.2   haad #include <sys/buf.h>
     40       1.2   haad 
     41       1.2   haad #include "dm.h"
     42       1.2   haad 
     43  1.10.4.1  rmind /* dm_target_zero.c */
     44  1.10.4.1  rmind int dm_target_zero_init(dm_dev_t *, void**,  char *);
     45  1.10.4.1  rmind char * dm_target_zero_status(void *);
     46  1.10.4.1  rmind int dm_target_zero_strategy(dm_table_entry_t *, struct buf *);
     47  1.10.4.1  rmind int dm_target_zero_sync(dm_table_entry_t *);
     48  1.10.4.1  rmind int dm_target_zero_destroy(dm_table_entry_t *);
     49  1.10.4.1  rmind int dm_target_zero_deps(dm_table_entry_t *, prop_array_t);
     50  1.10.4.1  rmind int dm_target_zero_upcall(dm_table_entry_t *, struct buf *);
     51  1.10.4.1  rmind 
     52       1.4   haad #ifdef DM_TARGET_MODULE
     53       1.4   haad /*
     54       1.4   haad  * Every target can be compiled directly to dm driver or as a
     55       1.4   haad  * separate module this part of target is used for loading targets
     56       1.4   haad  * to dm driver.
     57       1.4   haad  * Target can be unloaded from kernel only if there are no users of
     58       1.4   haad  * it e.g. there are no devices which uses that target.
     59       1.4   haad  */
     60       1.4   haad #include <sys/kernel.h>
     61       1.4   haad #include <sys/module.h>
     62       1.4   haad 
     63       1.6   haad MODULE(MODULE_CLASS_MISC, dm_target_zero, "dm");
     64       1.4   haad 
     65       1.4   haad static int
     66       1.4   haad dm_target_zero_modcmd(modcmd_t cmd, void *arg)
     67       1.4   haad {
     68       1.4   haad 	dm_target_t *dmt;
     69       1.4   haad 	int r;
     70       1.4   haad 	dmt = NULL;
     71      1.10   haad 
     72       1.4   haad 	switch (cmd) {
     73       1.4   haad 	case MODULE_CMD_INIT:
     74      1.10   haad 		if ((dmt = dm_target_lookup("zero")) != NULL) {
     75       1.7   haad 			dm_target_unbusy(dmt);
     76       1.4   haad 			return EEXIST;
     77       1.7   haad 		}
     78       1.4   haad 		dmt = dm_target_alloc("zero");
     79      1.10   haad 
     80       1.4   haad 		dmt->version[0] = 1;
     81       1.4   haad 		dmt->version[1] = 0;
     82       1.4   haad 		dmt->version[2] = 0;
     83       1.4   haad 		strlcpy(dmt->name, "zero", DM_MAX_TYPE_NAME);
     84       1.4   haad 		dmt->init = &dm_target_zero_init;
     85       1.4   haad 		dmt->status = &dm_target_zero_status;
     86       1.4   haad 		dmt->strategy = &dm_target_zero_strategy;
     87  1.10.4.1  rmind 		dmt->sync = &dm_target_zero_sync;
     88       1.4   haad 		dmt->deps = &dm_target_zero_deps;
     89       1.4   haad 		dmt->destroy = &dm_target_zero_destroy;
     90       1.4   haad 		dmt->upcall = &dm_target_zero_upcall;
     91       1.4   haad 
     92       1.4   haad 		r = dm_target_insert(dmt);
     93       1.4   haad 		break;
     94       1.4   haad 
     95       1.4   haad 	case MODULE_CMD_FINI:
     96       1.4   haad 		r = dm_target_rem("zero");
     97       1.5   haad 
     98       1.4   haad 		break;
     99       1.4   haad 
    100       1.4   haad 	case MODULE_CMD_STAT:
    101       1.4   haad 		return ENOTTY;
    102       1.4   haad 
    103       1.4   haad 	default:
    104       1.4   haad 		return ENOTTY;
    105       1.4   haad 	}
    106       1.4   haad 
    107       1.4   haad 	return r;
    108       1.4   haad }
    109       1.4   haad #endif
    110       1.4   haad 
    111       1.2   haad /*
    112       1.2   haad  * Zero target init function. This target doesn't need
    113       1.2   haad  * target specific config area.
    114       1.2   haad  */
    115       1.2   haad int
    116      1.10   haad dm_target_zero_init(dm_dev_t * dmv, void **target_config, char *argv)
    117       1.2   haad {
    118       1.2   haad 
    119       1.2   haad 	printf("Zero target init function called!!\n");
    120       1.2   haad 
    121       1.2   haad 	dmv->dev_type = DM_ZERO_DEV;
    122      1.10   haad 
    123       1.2   haad 	*target_config = NULL;
    124      1.10   haad 
    125       1.2   haad 	return 0;
    126       1.2   haad }
    127       1.2   haad /* Status routine called to get params string. */
    128       1.2   haad char *
    129       1.2   haad dm_target_zero_status(void *target_config)
    130       1.2   haad {
    131       1.2   haad 	return NULL;
    132      1.10   haad }
    133      1.10   haad 
    134       1.2   haad 
    135       1.2   haad /*
    136       1.2   haad  * This routine does IO operations.
    137       1.2   haad  */
    138       1.2   haad int
    139      1.10   haad dm_target_zero_strategy(dm_table_entry_t * table_en, struct buf * bp)
    140       1.2   haad {
    141       1.2   haad 
    142       1.2   haad 	/* printf("Zero target read function called %d!!\n", bp->b_bcount); */
    143       1.2   haad 
    144      1.10   haad 	memset(bp->b_data, 0, bp->b_bcount);
    145      1.10   haad 	bp->b_resid = 0;	/* nestiobuf_done wants b_resid = 0 to be sure
    146      1.10   haad 				 * that there is no other io to done  */
    147      1.10   haad 
    148       1.2   haad 	biodone(bp);
    149       1.2   haad 
    150       1.2   haad 	return 0;
    151       1.2   haad }
    152  1.10.4.1  rmind /* Sync underlying disk caches. */
    153  1.10.4.1  rmind int
    154  1.10.4.1  rmind dm_target_zero_sync(dm_table_entry_t * table_en)
    155  1.10.4.1  rmind {
    156  1.10.4.1  rmind 
    157  1.10.4.1  rmind 	return 0;
    158  1.10.4.1  rmind }
    159       1.2   haad /* Doesn't not need to do anything here. */
    160       1.2   haad int
    161      1.10   haad dm_target_zero_destroy(dm_table_entry_t * table_en)
    162       1.2   haad {
    163       1.2   haad 	table_en->target_config = NULL;
    164       1.3   haad 
    165       1.3   haad 	/* Unbusy target so we can unload it */
    166       1.3   haad 	dm_target_unbusy(table_en->target);
    167      1.10   haad 
    168       1.2   haad 	return 0;
    169       1.2   haad }
    170       1.2   haad /* Doesn't not need to do anything here. */
    171       1.2   haad int
    172      1.10   haad dm_target_zero_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
    173      1.10   haad {
    174       1.2   haad 	return 0;
    175       1.2   haad }
    176       1.2   haad /* Unsuported for this target. */
    177       1.2   haad int
    178      1.10   haad dm_target_zero_upcall(dm_table_entry_t * table_en, struct buf * bp)
    179       1.2   haad {
    180       1.2   haad 	return 0;
    181       1.2   haad }
    182