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

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;    
                     84:        
                     85:        return 0;
                     86: }
                     87: 
                     88: /*
                     89:  * Do IO operation, called from dmstrategy routine.
                     90:  */
                     91: int
                     92: dm_target_linear_strategy(struct dm_table_entry *table_en, struct buf *bp)
                     93: {
                     94:        struct target_linear_config *tlc;
                     95: 
                     96:        tlc = table_en->target_config;
                     97:        
                     98:        printf("Linear target read function called!!\n");
                     99: 
                    100:        bp->b_blkno += tlc->offset;
                    101:        
                    102:        VOP_STRATEGY(tlc->pdev->pdev_vnode, bp);
                    103:        
                    104:        return 0;
                    105: 
                    106: }
                    107: 
                    108: /*
                    109:  * Destroy target specific data.
                    110:  */
                    111: int
                    112: dm_target_linear_destroy(struct dm_table_entry *table_en)
                    113: {
                    114: 
1.1.2.2 ! haad      115:        kmem_free(table_en->target_config, sizeof(struct target_linear_config));
1.1.2.1   haad      116:        
                    117:        return 0;
                    118: }
                    119: 
                    120: /*
                    121:  * Register upcall device.
                    122:  * Linear target doesn't need any upcall devices but other targets like
                    123:  * mirror, snapshot, multipath, stripe will use this functionality.
                    124:  */
                    125: int
                    126: dm_target_linear_upcall(struct dm_table_entry *table_en, struct buf *bp)
                    127: {
                    128: 
                    129:        return 0;
                    130: }
                    131: 
                    132: /*
                    133:  * Transform char s to uint64_t offset number.
                    134:  */
                    135: static uint64_t
                    136: atoi(const char *s)
                    137: {
                    138:        uint64_t n;
                    139: 
                    140:        n = 0;
                    141: 
                    142:        while (*s != '\0') {
                    143: 
                    144:                if (!isdigit(*s))
                    145:                        break;
                    146: 
                    147:                n = (10 * n) + (*s - '0');
                    148:                s++;
                    149:        }
                    150: 
                    151:        return n;
                    152: }

CVSweb <webmaster@jp.NetBSD.org>