1ff56536eSAlex Hornung /* $NetBSD: dm_target_zero.c,v 1.10 2010/01/04 00:12:22 haad Exp $ */
2ff56536eSAlex Hornung
3ff56536eSAlex Hornung /*
4ff56536eSAlex Hornung * Copyright (c) 2008 The NetBSD Foundation, Inc.
5ff56536eSAlex Hornung * All rights reserved.
6ff56536eSAlex Hornung *
7ff56536eSAlex Hornung * This code is derived from software contributed to The NetBSD Foundation
8ff56536eSAlex Hornung * by Adam Hamsik.
9ff56536eSAlex Hornung *
10ff56536eSAlex Hornung * Redistribution and use in source and binary forms, with or without
11ff56536eSAlex Hornung * modification, are permitted provided that the following conditions
12ff56536eSAlex Hornung * are met:
13ff56536eSAlex Hornung * 1. Redistributions of source code must retain the above copyright
14ff56536eSAlex Hornung * notice, this list of conditions and the following disclaimer.
15ff56536eSAlex Hornung * 2. Redistributions in binary form must reproduce the above copyright
16ff56536eSAlex Hornung * notice, this list of conditions and the following disclaimer in the
17ff56536eSAlex Hornung * documentation and/or other materials provided with the distribution.
18ff56536eSAlex Hornung *
19ff56536eSAlex Hornung * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20ff56536eSAlex Hornung * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21ff56536eSAlex Hornung * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22ff56536eSAlex Hornung * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23ff56536eSAlex Hornung * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24ff56536eSAlex Hornung * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25ff56536eSAlex Hornung * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26ff56536eSAlex Hornung * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ff56536eSAlex Hornung * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28ff56536eSAlex Hornung * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29ff56536eSAlex Hornung * POSSIBILITY OF SUCH DAMAGE.
30ff56536eSAlex Hornung */
31ff56536eSAlex Hornung
32ff56536eSAlex Hornung /*
33ff56536eSAlex Hornung * This file implements initial version of device-mapper zero target.
34ff56536eSAlex Hornung */
35a84e173eSAlex Hornung #include <dev/disk/dm/dm.h>
36ff56536eSAlex Hornung
37ff56536eSAlex Hornung /*
38ff56536eSAlex Hornung * This routine does IO operations.
39ff56536eSAlex Hornung */
405c411e8eSAlex Hornung static int
dm_target_zero_strategy(dm_table_entry_t * table_en,struct buf * bp)41ff56536eSAlex Hornung dm_target_zero_strategy(dm_table_entry_t *table_en, struct buf *bp)
42ff56536eSAlex Hornung {
43ff56536eSAlex Hornung memset(bp->b_data, 0, bp->b_bcount);
443adc52bcSMatthew Dillon bp->b_resid = 0;
455b279a20SAlex Hornung biodone(&bp->b_bio1);
46ff56536eSAlex Hornung
47ff56536eSAlex Hornung return 0;
48ff56536eSAlex Hornung }
495c411e8eSAlex Hornung
505c411e8eSAlex Hornung static int
dmtz_mod_handler(module_t mod,int type,void * unused)515c411e8eSAlex Hornung dmtz_mod_handler(module_t mod, int type, void *unused)
525c411e8eSAlex Hornung {
535c411e8eSAlex Hornung dm_target_t *dmt = NULL;
545c411e8eSAlex Hornung int err = 0;
555c411e8eSAlex Hornung
565c411e8eSAlex Hornung switch(type) {
575c411e8eSAlex Hornung case MOD_LOAD:
585c411e8eSAlex Hornung if ((dmt = dm_target_lookup("zero")) != NULL) {
595c411e8eSAlex Hornung dm_target_unbusy(dmt);
605c411e8eSAlex Hornung return EEXIST;
615c411e8eSAlex Hornung }
625c411e8eSAlex Hornung dmt = dm_target_alloc("zero");
635c411e8eSAlex Hornung dmt->version[0] = 1;
645c411e8eSAlex Hornung dmt->version[1] = 0;
655c411e8eSAlex Hornung dmt->version[2] = 0;
66b4e97860STomohiro Kusumi dmt->strategy = &dm_target_zero_strategy;
675c411e8eSAlex Hornung
685c411e8eSAlex Hornung err = dm_target_insert(dmt);
695c411e8eSAlex Hornung if (err == 0)
705c411e8eSAlex Hornung kprintf("dm_target_zero: Successfully initialized\n");
715c411e8eSAlex Hornung break;
725c411e8eSAlex Hornung
735c411e8eSAlex Hornung case MOD_UNLOAD:
74*a6b470c8STomohiro Kusumi err = dm_target_remove("zero");
755c411e8eSAlex Hornung if (err == 0)
765c411e8eSAlex Hornung kprintf("dm_target_zero: unloaded\n");
775c411e8eSAlex Hornung break;
785c411e8eSAlex Hornung }
795c411e8eSAlex Hornung
805c411e8eSAlex Hornung return err;
815c411e8eSAlex Hornung }
825c411e8eSAlex Hornung
837115a22bSAlex Hornung DM_TARGET_BUILTIN(dm_target_zero, dmtz_mod_handler);
84