1ff56536eSAlex Hornung /* $NetBSD: dm_target_error.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 error target.
34ff56536eSAlex Hornung */
35a84e173eSAlex Hornung #include <dev/disk/dm/dm.h>
36ff56536eSAlex Hornung
37ff56536eSAlex Hornung /* Strategy routine called from dm_strategy. */
385c411e8eSAlex Hornung static int
dm_target_error_strategy(dm_table_entry_t * table_en,struct buf * bp)39ff56536eSAlex Hornung dm_target_error_strategy(dm_table_entry_t *table_en, struct buf *bp)
40ff56536eSAlex Hornung {
41ff56536eSAlex Hornung bp->b_error = EIO;
42ff56536eSAlex Hornung bp->b_resid = 0;
43ff56536eSAlex Hornung
445b279a20SAlex Hornung biodone(&bp->b_bio1);
45ff56536eSAlex Hornung
46ff56536eSAlex Hornung return 0;
47ff56536eSAlex Hornung }
485c411e8eSAlex Hornung
495c411e8eSAlex Hornung static int
dmte_mod_handler(module_t mod,int type,void * unused)505c411e8eSAlex Hornung dmte_mod_handler(module_t mod, int type, void *unused)
515c411e8eSAlex Hornung {
525c411e8eSAlex Hornung dm_target_t *dmt = NULL;
535c411e8eSAlex Hornung int err = 0;
545c411e8eSAlex Hornung
555c411e8eSAlex Hornung switch(type) {
565c411e8eSAlex Hornung case MOD_LOAD:
575c411e8eSAlex Hornung if ((dmt = dm_target_lookup("error")) != NULL) {
585c411e8eSAlex Hornung dm_target_unbusy(dmt);
595c411e8eSAlex Hornung return EEXIST;
605c411e8eSAlex Hornung }
615c411e8eSAlex Hornung dmt = dm_target_alloc("error");
625c411e8eSAlex Hornung dmt->version[0] = 1;
635c411e8eSAlex Hornung dmt->version[1] = 0;
645c411e8eSAlex Hornung dmt->version[2] = 0;
65b4e97860STomohiro Kusumi dmt->strategy = &dm_target_error_strategy;
665c411e8eSAlex Hornung
675c411e8eSAlex Hornung err = dm_target_insert(dmt);
685c411e8eSAlex Hornung if (err == 0)
695c411e8eSAlex Hornung kprintf("dm_target_error: Successfully initialized\n");
705c411e8eSAlex Hornung break;
715c411e8eSAlex Hornung
725c411e8eSAlex Hornung case MOD_UNLOAD:
73*a6b470c8STomohiro Kusumi err = dm_target_remove("error");
745c411e8eSAlex Hornung if (err == 0)
755c411e8eSAlex Hornung kprintf("dm_target_error: unloaded\n");
765c411e8eSAlex Hornung break;
775c411e8eSAlex Hornung }
785c411e8eSAlex Hornung
795c411e8eSAlex Hornung return err;
805c411e8eSAlex Hornung }
815c411e8eSAlex Hornung
827115a22bSAlex Hornung DM_TARGET_BUILTIN(dm_target_error, dmte_mod_handler);
83