Annotation of src/sys/dev/dm/dm_target_linear.c, revision 1.1.2.4

1.1.2.1   haad        1: /*
                      2:  * Copyright (c) 1996, 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to The NetBSD Foundation
                      6:  * by Adam Hamsik.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  *
                     17:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     18:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     19:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     20:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     21:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     22:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     23:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     24:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     25:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     26:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     27:  * POSSIBILITY OF SUCH DAMAGE.
                     28:  */
                     29: 
                     30: 
                     31: /*
                     32:  * This file implements initial version of device-mapper dklinear target.
                     33:  */
                     34: 
                     35: #include <sys/types.h>
                     36: #include <sys/param.h>
                     37: 
                     38: #include <sys/buf.h>
                     39: #include <sys/disk.h>
                     40: #include <sys/errno.h>
                     41: #include <sys/ioctl.h>
                     42: #include <sys/ioccom.h>
                     43: #include <sys/kmem.h>
                     44: #include <sys/types.h>
                     45: #include <sys/param.h>
                     46: #include <sys/queue.h>
                     47: #include <sys/vnode.h>
                     48: 
1.1.2.4 ! haad       49: #include <machine/int_fmtio.h>
        !            50: 
1.1.2.1   haad       51: #include "dm.h"
                     52: 
                     53: static uint64_t atoi(const char *);
                     54: 
                     55: /*
                     56:  * Allocate target specific config data, and link them to table.
1.1.2.4 ! haad       57:  * This function is called only when, flags is not READONLY and
        !            58:  * therefore we can add things to pdev list.
        !            59:  * @argv[0] is name,
        !            60:  * @argv[1] is physical data offset.
1.1.2.1   haad       61:  */
                     62: int
1.1.2.4 ! haad       63: dm_target_linear_init(struct dm_dev *dmv, void **target_config, char *params)
1.1.2.1   haad       64: {
                     65:        struct target_linear_config *tlc;
                     66:        struct dm_pdev *dmp;
1.1.2.4 ! haad       67: 
        !            68:        char **ap, *argv[3];
        !            69: 
        !            70:        /*
        !            71:         * Parse a string, containing tokens delimited by white space,
        !            72:         * into an argument vector
        !            73:         */
        !            74:        for (ap = argv; ap < &argv[9] &&
        !            75:                 (*ap = strsep(&params, " \t")) != NULL;) {
        !            76:                if (**ap != '\0')
        !            77:                        ap++;
        !            78:        }
        !            79: 
        !            80:        /* Insert dmp to list */
        !            81:        if ((dmp = dm_pdev_insert(argv[0])) == NULL)
        !            82:                return ENOENT;
        !            83:        
        !            84:        /* Add dmp to device pdev list */
        !            85:        SLIST_INSERT_HEAD(&dmv->pdevs, dmp, next_pdev);
        !            86:        
1.1.2.2   haad       87:        printf("Linear target init function called %s--%s!!\n",
                     88:            argv[0], argv[1]);
1.1.2.1   haad       89:        
1.1.2.2   haad       90:        if ((tlc = kmem_alloc(sizeof(struct target_linear_config), KM_NOSLEEP))
1.1.2.1   haad       91:            == NULL)
                     92:                return 1;
                     93: 
                     94:        tlc->pdev = dmp;
                     95:        tlc->offset = 0;        /* default settings */
                     96:        
                     97:        /* Check user input if it is not leave offset as 0. */
1.1.2.4 ! haad       98:        tlc->offset = atoi(argv[1]);
1.1.2.1   haad       99: 
                    100:        *target_config = tlc;    
1.1.2.3   haad      101: 
                    102:        dmv->dev_type = DM_LINEAR_DEV;
1.1.2.1   haad      103:        
                    104:        return 0;
                    105: }
                    106: 
                    107: /*
                    108:  * Do IO operation, called from dmstrategy routine.
                    109:  */
                    110: int
                    111: dm_target_linear_strategy(struct dm_table_entry *table_en, struct buf *bp)
                    112: {
                    113:        struct target_linear_config *tlc;
                    114: 
                    115:        tlc = table_en->target_config;
                    116:        
1.1.2.4 ! haad      117:        printf("Linear target read function called %" PRIu64 "!!\n",
        !           118:            tlc->offset);
1.1.2.1   haad      119: 
                    120:        bp->b_blkno += tlc->offset;
                    121:        
                    122:        VOP_STRATEGY(tlc->pdev->pdev_vnode, bp);
                    123:        
                    124:        return 0;
                    125: 
                    126: }
                    127: 
                    128: /*
                    129:  * Destroy target specific data.
                    130:  */
                    131: int
                    132: dm_target_linear_destroy(struct dm_table_entry *table_en)
                    133: {
                    134: 
1.1.2.2   haad      135:        kmem_free(table_en->target_config, sizeof(struct target_linear_config));
1.1.2.1   haad      136:        
                    137:        return 0;
                    138: }
                    139: 
                    140: /*
                    141:  * Register upcall device.
                    142:  * Linear target doesn't need any upcall devices but other targets like
                    143:  * mirror, snapshot, multipath, stripe will use this functionality.
                    144:  */
                    145: int
                    146: dm_target_linear_upcall(struct dm_table_entry *table_en, struct buf *bp)
                    147: {
                    148: 
                    149:        return 0;
                    150: }
                    151: 
                    152: /*
                    153:  * Transform char s to uint64_t offset number.
                    154:  */
                    155: static uint64_t
                    156: atoi(const char *s)
                    157: {
                    158:        uint64_t n;
                    159: 
                    160:        n = 0;
                    161: 
                    162:        while (*s != '\0') {
                    163: 
                    164:                if (!isdigit(*s))
                    165:                        break;
                    166: 
                    167:                n = (10 * n) + (*s - '0');
                    168:                s++;
                    169:        }
                    170: 
                    171:        return n;
                    172: }

CVSweb <webmaster@jp.NetBSD.org>