Annotation of src/sys/dev/dm/dm_target_linear.c, revision 1.1.2.7
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
1.1.2.6 haad 58: * therefore we can add things to pdev list. This function have to
59: * be called with held dev_mtx. This should not e a problem because
60: * this routine is called onyl from dm_table_load_ioctl.
1.1.2.4 haad 61: * @argv[0] is name,
62: * @argv[1] is physical data offset.
1.1.2.1 haad 63: */
64: int
1.1.2.4 haad 65: dm_target_linear_init(struct dm_dev *dmv, void **target_config, char *params)
1.1.2.1 haad 66: {
67: struct target_linear_config *tlc;
68: struct dm_pdev *dmp;
1.1.2.4 haad 69:
70: char **ap, *argv[3];
71:
72: /*
73: * Parse a string, containing tokens delimited by white space,
74: * into an argument vector
75: */
76: for (ap = argv; ap < &argv[9] &&
77: (*ap = strsep(¶ms, " \t")) != NULL;) {
78: if (**ap != '\0')
79: ap++;
80: }
81:
82: /* Insert dmp to list */
83: if ((dmp = dm_pdev_insert(argv[0])) == NULL)
84: return ENOENT;
85:
86: /* Add dmp to device pdev list */
87: SLIST_INSERT_HEAD(&dmv->pdevs, dmp, next_pdev);
88:
1.1.2.2 haad 89: printf("Linear target init function called %s--%s!!\n",
90: argv[0], argv[1]);
1.1.2.1 haad 91:
1.1.2.2 haad 92: if ((tlc = kmem_alloc(sizeof(struct target_linear_config), KM_NOSLEEP))
1.1.2.1 haad 93: == NULL)
94: return 1;
95:
96: tlc->pdev = dmp;
97: tlc->offset = 0; /* default settings */
98:
99: /* Check user input if it is not leave offset as 0. */
1.1.2.4 haad 100: tlc->offset = atoi(argv[1]);
1.1.2.1 haad 101:
102: *target_config = tlc;
1.1.2.3 haad 103:
104: dmv->dev_type = DM_LINEAR_DEV;
1.1.2.1 haad 105:
106: return 0;
107: }
108:
109: /*
1.1.2.5 haad 110: * Status routine is called to get params string, which is target
111: * specific. When dm_table_status_ioctl is called with flag
112: * DM_STATUS_TABLE_FLAG I have to sent params string back.
113: */
114: char *
115: dm_target_linear_status(void *target_config)
116: {
117: struct target_linear_config *tlc;
118: char *params;
119: uint32_t i;
120: uint32_t count;
121: size_t prm_len;
122:
123:
124: tlc = target_config;
125: prm_len = 0;
126: count = 0;
127:
128: /* count number of chars in offset */
129: for(i = tlc->offset; i != 0; i /= 10)
130: count++;
131:
132: printf("Linear target status function called\n");
133:
134: /* length of name + count of chars + one space and null char */
135: prm_len = strlen(tlc->pdev->name) + count + 2;
136:
137: if ((params = kmem_alloc(prm_len, KM_NOSLEEP)) == NULL)
138: return NULL;
139:
140: printf("%s %"PRIu64, tlc->pdev->name, tlc->offset);
141: snprintf(params, prm_len,"%s %"PRIu64, tlc->pdev->name, tlc->offset);
142:
143:
144: return params;
145: }
146:
147: /*
1.1.2.1 haad 148: * Do IO operation, called from dmstrategy routine.
149: */
150: int
151: dm_target_linear_strategy(struct dm_table_entry *table_en, struct buf *bp)
152: {
153: struct target_linear_config *tlc;
154:
155: tlc = table_en->target_config;
156:
1.1.2.4 haad 157: printf("Linear target read function called %" PRIu64 "!!\n",
158: tlc->offset);
1.1.2.1 haad 159:
160: bp->b_blkno += tlc->offset;
161:
162: VOP_STRATEGY(tlc->pdev->pdev_vnode, bp);
163:
164: return 0;
165:
166: }
167:
168: /*
169: * Destroy target specific data.
170: */
171: int
172: dm_target_linear_destroy(struct dm_table_entry *table_en)
173: {
174:
1.1.2.2 haad 175: kmem_free(table_en->target_config, sizeof(struct target_linear_config));
1.1.2.7 ! haad 176:
! 177: table_en->target_config = NULL;
1.1.2.1 haad 178:
179: return 0;
180: }
181:
182: /*
183: * Register upcall device.
184: * Linear target doesn't need any upcall devices but other targets like
185: * mirror, snapshot, multipath, stripe will use this functionality.
186: */
187: int
188: dm_target_linear_upcall(struct dm_table_entry *table_en, struct buf *bp)
189: {
190:
191: return 0;
192: }
193:
194: /*
195: * Transform char s to uint64_t offset number.
196: */
197: static uint64_t
198: atoi(const char *s)
199: {
200: uint64_t n;
201:
202: n = 0;
203:
204: while (*s != '\0') {
205:
206: if (!isdigit(*s))
207: break;
208:
209: n = (10 * n) + (*s - '0');
210: s++;
211: }
212:
213: return n;
214: }
CVSweb <webmaster@jp.NetBSD.org>