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

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

CVSweb <webmaster@jp.NetBSD.org>