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

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: 
                     49: #include "dm.h"
                     50: 
                     51: static uint64_t atoi(const char *);
                     52: 
                     53: /*
                     54:  * Allocate target specific config data, and link them to table.
                     55:  * argv[0] is name,
                     56:  * argv[1] is physical data offset.
                     57:  */
                     58: int
                     59: dm_target_linear_init(struct dm_dev *dmv, void **target_config, 
                     60:                int argc, const char **argv)
                     61: {
                     62:        struct target_linear_config *tlc;
                     63:        struct dm_pdev *dmp;
                     64:                
1.1.2.2   haad       65:        printf("Linear target init function called %s--%s!!\n",
                     66:            argv[0], argv[1]);
1.1.2.1   haad       67:        
                     68:        dmp = dm_pdev_lookup_name(argv[0]);
                     69:                
1.1.2.2   haad       70:        if ((tlc = kmem_alloc(sizeof(struct target_linear_config), KM_NOSLEEP))
1.1.2.1   haad       71:            == NULL)
                     72:                return 1;
                     73: 
                     74:        /* XXX howto convert char* to number ? tlc->offset = atoi(argv[1]); */
                     75: 
                     76:        tlc->pdev = dmp;
                     77:        tlc->offset = 0;        /* default settings */
                     78:        
                     79:        /* Check user input if it is not leave offset as 0. */
                     80:        if (isdigit((int)argv[1]))
                     81:                tlc->offset = atoi(argv[1]);
                     82: 
                     83:        *target_config = tlc;    
1.1.2.3 ! haad       84: 
        !            85:        dmv->dev_type = DM_LINEAR_DEV;
1.1.2.1   haad       86:        
                     87:        return 0;
                     88: }
                     89: 
                     90: /*
                     91:  * Do IO operation, called from dmstrategy routine.
                     92:  */
                     93: int
                     94: dm_target_linear_strategy(struct dm_table_entry *table_en, struct buf *bp)
                     95: {
                     96:        struct target_linear_config *tlc;
                     97: 
                     98:        tlc = table_en->target_config;
                     99:        
                    100:        printf("Linear target read function called!!\n");
                    101: 
                    102:        bp->b_blkno += tlc->offset;
                    103:        
                    104:        VOP_STRATEGY(tlc->pdev->pdev_vnode, bp);
                    105:        
                    106:        return 0;
                    107: 
                    108: }
                    109: 
                    110: /*
                    111:  * Destroy target specific data.
                    112:  */
                    113: int
                    114: dm_target_linear_destroy(struct dm_table_entry *table_en)
                    115: {
                    116: 
1.1.2.2   haad      117:        kmem_free(table_en->target_config, sizeof(struct target_linear_config));
1.1.2.1   haad      118:        
                    119:        return 0;
                    120: }
                    121: 
                    122: /*
                    123:  * Register upcall device.
                    124:  * Linear target doesn't need any upcall devices but other targets like
                    125:  * mirror, snapshot, multipath, stripe will use this functionality.
                    126:  */
                    127: int
                    128: dm_target_linear_upcall(struct dm_table_entry *table_en, struct buf *bp)
                    129: {
                    130: 
                    131:        return 0;
                    132: }
                    133: 
                    134: /*
                    135:  * Transform char s to uint64_t offset number.
                    136:  */
                    137: static uint64_t
                    138: atoi(const char *s)
                    139: {
                    140:        uint64_t n;
                    141: 
                    142:        n = 0;
                    143: 
                    144:        while (*s != '\0') {
                    145: 
                    146:                if (!isdigit(*s))
                    147:                        break;
                    148: 
                    149:                n = (10 * n) + (*s - '0');
                    150:                s++;
                    151:        }
                    152: 
                    153:        return n;
                    154: }

CVSweb <webmaster@jp.NetBSD.org>