Annotation of src/sys/dev/dm/dm_ioctl.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: #include <sys/types.h>
31: #include <sys/param.h>
32:
33: #include <sys/errno.h>
34: #include <sys/ioctl.h>
35: #include <sys/ioccom.h>
36: #include <sys/kmem.h>
37: #include <sys/lkm.h>
38: #include <sys/namei.h>
39: #include <sys/vnode.h>
40:
41: #include <miscfs/specfs/specdev.h>
42:
43: #include <machine/int_fmtio.h>
44:
45: #include "netbsd-dm.h"
46: #include "dm.h"
47:
48: extern struct dm_softc *dm_sc;
49:
50: #define DM_REMOVE_FLAG(flag, name) do { \
51: prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
52: flag &= ~name; \
53: prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
54: } while (/*CONSTCOND*/0)
55:
56: #define DM_ADD_FLAG(flag, name) do { \
57: prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
58: flag |= name; \
59: prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
60: } while (/*CONSTCOND*/0)
61:
62: static int dm_dbg_print_flags(int);
63:
64: /*
65: * Print flags sent to the kernel from libevmapper.
66: */
67: static int
68: dm_dbg_print_flags(int flags)
69: {
70: aprint_verbose("dbg_print --- %d\n",flags);
71:
72: if (flags & DM_READONLY_FLAG)
73: aprint_verbose("dbg_flags: DM_READONLY_FLAG set In/Out\n");
74:
75: if (flags & DM_SUSPEND_FLAG)
76: aprint_verbose("dbg_flags: DM_SUSPEND_FLAG set In/Out \n");
77:
78: if (flags & DM_PERSISTENT_DEV_FLAG)
79: aprint_verbose("dbg_flags: DM_PERSISTENT_DEV_FLAG set In\n");
80:
81: if (flags & DM_STATUS_TABLE_FLAG)
82: aprint_verbose("dbg_flags: DM_STATUS_TABLE_FLAG set In\n");
83:
84: if (flags & DM_ACTIVE_PRESENT_FLAG)
85: aprint_verbose("dbg_flags: DM_ACTIVE_PRESENT_FLAG set Out\n");
86:
87: if (flags & DM_INACTIVE_PRESENT_FLAG)
1.1.2.2 haad 88: aprint_verbose("dbg_flags: DM_INACTIVE_PRESENT_FLAG set Out\n");
1.1.2.1 haad 89:
90: if (flags & DM_BUFFER_FULL_FLAG)
91: aprint_verbose("dbg_flags: DM_BUFFER_FULL_FLAG set Out\n");
92:
93: if (flags & DM_SKIP_BDGET_FLAG)
94: aprint_verbose("dbg_flags: DM_SKIP_BDGET_FLAG set In\n");
95:
96: if (flags & DM_SKIP_LOCKFS_FLAG)
97: aprint_verbose("dbg_flags: DM_SKIP_LOCKFS_FLAG set In\n");
98:
99: if (flags & DM_NOFLUSH_FLAG)
100: aprint_verbose("dbg_flags: DM_NOFLUSH_FLAG set In\n");
101:
102: return 0;
103: }
104:
1.1.2.2 haad 105: /*
106: * Get version ioctl call I do it as default therefore this
107: * function is unused now.
108: */
1.1.2.1 haad 109: int
110: dm_get_version_ioctl(prop_dictionary_t dm_dict)
111: {
112: int r;
113:
114: r = 0;
115:
116: aprint_verbose("dm_get_version_ioctl called\n");
117:
118: return 0;
119: }
120:
121: /*
122: * Get list of all available targets from global
123: * target list and sent them back to libdevmapper.
124: */
125: int
126: dm_list_versions_ioctl(prop_dictionary_t dm_dict)
127: {
128: prop_array_t target_list;
129:
130: int r;
131: uint32_t flags;
132:
133: r = 0;
134:
135: aprint_verbose("dm_list_versions_ioctl called\n");
136:
1.1.2.2 haad 137: prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.1.2.1 haad 138:
139: dm_dbg_print_flags(flags);
140:
141: target_list = dm_target_prop_list();
142:
1.1.2.2 haad 143: prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, target_list);
1.1.2.1 haad 144:
145: return r;
146: }
147:
148: /*
149: * Create in-kernel entry for device. Device attributes such as name, uuid are
150: * taken from proplib dictionary.
151: */
152: int
153: dm_dev_create_ioctl(prop_dictionary_t dm_dict)
154: {
155: struct dm_dev *dmv;
156: const char *name, *uuid;
157: int r,flags;
158:
159: r = 0;
160: flags = 0;
161: name = NULL;
162: uuid = NULL;
163:
164: /* Get needed values from dictionary. */
1.1.2.2 haad 165: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
166: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
167: prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.1.2.1 haad 168:
169: dm_dbg_print_flags(flags);
170:
171: /* Lookup name and uuid if device already exist quit. */
172: if ((dm_dev_lookup_name(name) != NULL) &&
173: (dm_dev_lookup_uuid(uuid) != NULL)) {
174: DM_ADD_FLAG(flags, DM_EXISTS_FLAG); /* Device already exists */
175: return EEXIST;
176: }
177:
178:
179: if ((dmv = dm_dev_alloc()) == NULL)
180: return ENOMEM;
181: /* printf("%d---%d\n",sizeof(dmv->uuid),DM_UUID_LEN);
182: printf("%s\n",uuid);
183: if (uuid)
184: memcpy(dmv->uuid,uuid,DM_UUID_LEN);*/
185: printf("%s\n",name);
186: if (name)
1.1.2.2 haad 187: strlcpy(dmv->name, name, DM_NAME_LEN);
1.1.2.1 haad 188:
189: dmv->flags = flags;
190:
191: dmv->minor = ++(dm_sc->sc_minor_num);
192:
193: dmv->ref_cnt = 0;
194: dmv->event_nr = 0;
195: dmv->cur_active_table = 0;
196:
1.1.2.3 haad 197: dmv->dev_type = 0;
198: dmv->dm_dklabel = NULL;
199:
1.1.2.1 haad 200: /* Initialize tables. */
201: SLIST_INIT(&dmv->tables[0]);
202: SLIST_INIT(&dmv->tables[1]);
203:
204: /* init device list of physical devices. */
205: SLIST_INIT(&dmv->pdevs);
206: /*
207: * Locking strategy here is this: this is per device mutex lock
208: * and it should be taken when we work with device. Almost all
209: * ioctl callbacks for tables and devices must acquire this lock.
210: */
211:
1.1.2.2 haad 212: prop_dictionary_set_uint64(dm_dict, DM_IOCTL_DEV, dmv->minor);
1.1.2.1 haad 213:
1.1.2.2 haad 214: mutex_init(&dmv->dev_mtx, MUTEX_DEFAULT, IPL_NONE);
1.1.2.1 haad 215:
216: /* Test readonly flag change anything only if it is not set*/
217: if (flags & DM_READONLY_FLAG)
218: dm_dev_free(dmv);
219: else
220: r = dm_dev_insert(dmv);
221:
222: return r;
223: }
224:
225: /*
226: * Get list of created device-mapper devices fromglobal list and
227: * send it to kernel.
228: *
229: * Output dictionary:
230: *
231: * <key>cmd_data</key>
232: * <array>
233: * <dict>
234: * <key>name<key>
235: * <string>...</string>
236: *
237: * <key>dev</key>
238: * <integer>...</integer>
239: * </dict>
240: * </array>
241: *
242: */
243: int
244: dm_dev_list_ioctl(prop_dictionary_t dm_dict)
245: {
246: prop_array_t dev_list;
247:
248: int r;
249: uint32_t flags;
250:
251: r = 0;
252:
253: aprint_verbose("dm_dev_list called\n");
254:
1.1.2.2 haad 255: prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.1.2.1 haad 256:
257: dm_dbg_print_flags(flags);
258:
259: dev_list = dm_dev_prop_list();
260:
1.1.2.2 haad 261: prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, dev_list);
1.1.2.1 haad 262:
263: return 0;
264: }
265:
266: /*
267: * Rename selected devices old name is in struct dm_ioctl.
268: * newname is taken from dictionary
269: *
270: * <key>cmd_data</key>
271: * <array>
272: * <string>...</string>
273: * </array>
274: */
275: int
276: dm_dev_rename_ioctl(prop_dictionary_t dm_dict)
277: {
278: prop_array_t cmd_array;
279: struct dm_dev *dmv;
280:
281: const char *name,*uuid,*n_name;
282: uint32_t flags;
283:
284: name = NULL;
285: uuid = NULL;
286:
287: /* Get needed values from dictionary. */
1.1.2.2 haad 288: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
289: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
290: prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
291: cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
1.1.2.1 haad 292:
1.1.2.2 haad 293: prop_array_get_cstring_nocopy(cmd_array, 0, &n_name);
1.1.2.1 haad 294:
295: if (strlen(n_name) + 1 > DM_NAME_LEN)
296: return EINVAL;
297:
298: if (((dmv = dm_dev_lookup_uuid(uuid)) == NULL) ||
299: (dmv = dm_dev_lookup_name(name)) == NULL) {
300: DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
301: return ENOENT;
302: }
303:
304: /* Test readonly flag change anything only if it is not set*/
305: if (!(flags & DM_READONLY_FLAG))
1.1.2.2 haad 306: strlcpy(dmv->name, n_name, DM_NAME_LEN);
1.1.2.1 haad 307:
308: return 0;
309: }
310:
311: /*
312: * Remove device from global list I have to remove active
313: * and inactive tables first and decrement reference_counters
314: * for used pdevs.
315: */
316: int
317: dm_dev_remove_ioctl(prop_dictionary_t dm_dict)
318: {
319: struct dm_dev *dmv;
320:
321: const char *name, *uuid;
322: uint32_t flags;
323:
324: name = NULL;
325: uuid = NULL;
326:
327: /* Get needed values from dictionary. */
1.1.2.2 haad 328: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
329: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
330: prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.1.2.1 haad 331:
332: dm_dbg_print_flags(flags);
333:
334: if (((dmv = dm_dev_lookup_uuid(uuid)) == NULL) &&
335: (dmv = dm_dev_lookup_name(name)) == NULL) {
336: DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
337: return ENOENT;
338: }
339:
340: if (!(flags & DM_READONLY_FLAG)) {
341: if (dmv->ref_cnt == 0){
342: /* Destroy active table first. */
343: dm_table_destroy(&dmv->tables[dmv->cur_active_table]);
344:
345: /* Destroy unactive table if exits, too. */
346: if (!SLIST_EMPTY(&dmv->tables[1 - dmv->cur_active_table]))
347: dm_table_destroy(&dmv->tables[1 - dmv->cur_active_table]);
348:
349: /* Decrement reference counters for all pdevs from this
350: device if they are unused close vnode and remove them
351: from global pdev list, too. */
352: dm_pdev_decr(&dmv->pdevs);
353:
354: /* Test readonly flag change anything only if it is not set*/
355:
356: dm_dev_rem(name); /* XXX. try to use uuid, too */
357: }
358:
359: }
360: return 0;
361: }
362:
363: /*
364: * Return actual state of device to libdevmapper.
365: */
366: int
367: dm_dev_status_ioctl(prop_dictionary_t dm_dict)
368: {
369: struct dm_dev *dmv;
370: const char *name, *uuid;
371: uint32_t flags;
372:
373: name = NULL;
374: uuid = NULL;
375:
1.1.2.2 haad 376: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
377: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
378: prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.1.2.1 haad 379:
380: if (((dmv = dm_dev_lookup_name(name)) == NULL) &&
381: ((dmv = dm_dev_lookup_uuid(uuid)) == NULL)) {
382: DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
383: return 0;
384: }
385:
1.1.2.2 haad 386: prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->ref_cnt);
387: prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, dmv->flags);
1.1.2.1 haad 388:
1.1.2.2 haad 389: prop_dictionary_set_uint64(dm_dict, DM_IOCTL_DEV, dmv->minor);
1.1.2.1 haad 390:
391: return 0;
392: }
393:
394: /*
395: * Unsupported on NetBSD.
396: */
397: int
398: dm_dev_suspend_ioctl(prop_dictionary_t dm_dict)
399: {
400: return 0;
401: }
402:
403: /*
404: * Unsupported on NetBSD.
405: */
406: int
407: dm_dev_resume_ioctl(prop_dictionary_t dm_dict)
408: {
409: // DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
410:
411: return 0;
412: }
413:
414: /*
415: * Table management routines
416: * lvm2tools doens't send name/uuid to kernel with table for lookup I have to use minor number.
417: */
418:
419:
420: /*
421: * Remove active table from device.
422: */
423: int
424: dm_table_clear_ioctl(prop_dictionary_t dm_dict)
425: {
426: struct dm_dev *dmv;
427: struct dm_table *tbl;
428:
429: const char *name, *uuid;
430: int flags;
431:
432: dmv = NULL;
433: name = NULL;
434: uuid = NULL;
435:
1.1.2.2 haad 436: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
437: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
438: prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.1.2.1 haad 439:
1.1.2.2 haad 440: aprint_verbose("Clearing inactive table from device: %s--%s\n",
441: name, uuid);
1.1.2.1 haad 442:
443: if (((dmv = dm_dev_lookup_name(name)) == NULL) &&
444: ((dmv = dm_dev_lookup_uuid(uuid)) == NULL)) {
445: DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
446: return ENOENT;
447: }
448:
449: /* Select unused table */
450: tbl = &dmv->tables[1-dmv->cur_active_table];
451:
452: /* Test readonly flag change anything only if it is not set*/
453: if (!(flags & DM_READONLY_FLAG))
454: dm_table_destroy(tbl);
455:
1.1.2.3 haad 456: dmv->dev_type = 0;
457:
1.1.2.1 haad 458: return 0;
459: }
460:
461: /*
462: * Get list of physical devices for active table.
463: * Get dev_t from pdev vnode and insert it into cmd_array.
464: *
465: * XXX. This function is called from lvm2tools to get information
466: * about physical devices, too e.g. during vgcreate.
467: */
468: int
469: dm_table_deps_ioctl(prop_dictionary_t dm_dict)
470: {
471: int error;
472: struct dm_dev *dmv;
473: struct dm_pdev *dmp;
474: struct vattr va;
475:
476: prop_array_t cmd_array;
477:
478: const char *name, *uuid;
479: int flags;
480: uint64_t dev;
481:
482: size_t i;
483:
484: name = NULL;
485: uuid = NULL;
486: dmv = NULL;
487:
488: i=0;
489:
1.1.2.2 haad 490: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
491: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
492: prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
493: prop_dictionary_get_uint64(dm_dict, DM_IOCTL_DEV, &dev);
1.1.2.1 haad 494:
495: cmd_array = prop_dictionary_get(dm_dict,DM_IOCTL_CMD_DATA);
496:
497: if (((dmv = dm_dev_lookup_name(name)) == NULL) &&
498: ((dmv = dm_dev_lookup_uuid(uuid)) == NULL) &&
499: ((dmv = dm_dev_lookup_minor(minor(dev))) == NULL)) {
500: DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
501: return ENOENT;
502: }
503:
504: aprint_verbose("Getting table deps for device: %s\n",name);
505:
506: SLIST_FOREACH(dmp, &dmv->pdevs, next_pdev){
507:
1.1.2.2 haad 508: if ((error = VOP_GETATTR(dmp->pdev_vnode, &va, curlwp->l_cred))
509: != 0)
1.1.2.1 haad 510: return (error);
511:
1.1.2.2 haad 512: prop_array_set_uint64(cmd_array, i, (uint64_t)va.va_rdev);
1.1.2.1 haad 513:
514: i++;
515: }
516:
517: return 0;
518: }
519:
520: /*
521: * Load new table/tables to device.
522: * Call apropriate target init routine open all physical pdev's and
523: * link them to device. For other targets mirror, strip, snapshot
524: * etc. also add dependency devices to upcalls list.
525: *
526: * XXX. It would be usefull to refactorize this routine to be shorter ?
527: */
528: int
529: dm_table_load_ioctl(prop_dictionary_t dm_dict)
530: {
531: struct dm_dev *dmv;
532: struct dm_pdev *dmp;
533: struct dm_table_entry *table_en, *last_table;
534: struct dm_table *tbl;
535: struct dm_target *target;
536:
537: prop_object_iterator_t iter;
538: prop_array_t cmd_array;
539: prop_dictionary_t target_dict;
540:
1.1.2.4 ! haad 541: const char *name, *uuid, *type;
1.1.2.1 haad 542:
543: uint32_t flags;
544:
545: uint64_t dev;
546:
1.1.2.4 ! haad 547: char *str;
1.1.2.1 haad 548:
549: flags = 0;
550: name = NULL;
551: uuid = NULL;
552: dmv = NULL;
553: dmp = NULL;
554: last_table = NULL;
555:
556: char *xml;
557: xml = prop_dictionary_externalize(dm_dict);
558: printf("%s\n",xml);
559:
1.1.2.2 haad 560: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
561: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
562: prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
563: prop_dictionary_get_uint64(dm_dict, DM_IOCTL_DEV, &dev);
1.1.2.1 haad 564:
1.1.2.2 haad 565: cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
1.1.2.1 haad 566: iter = prop_array_iterator(cmd_array);
567:
568: dm_dbg_print_flags(flags);
569:
570: aprint_verbose("Loading table to device: %s--%s\n",name,uuid);
571:
572: if (((dmv = dm_dev_lookup_name(name)) == NULL) &&
573: ((dmv = dm_dev_lookup_uuid(uuid)) == NULL) &&
574: ((dmv = dm_dev_lookup_minor(minor(dev))) == NULL)) {
575: DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
576: return ENOENT;
577: }
578:
579: /* Select unused table */
580: tbl = &dmv->tables[1-dmv->cur_active_table];
581:
582: /*
583: * I have to check if this table slot is not used by another table list.
584: * if it is used I should free them.
585: */
586:
587: dm_table_destroy(tbl);
588:
589: while((target_dict = prop_object_iterator_next(iter)) != NULL){
590:
1.1.2.2 haad 591: prop_dictionary_get_cstring_nocopy(target_dict,
592: DM_TABLE_TYPE, &type);
1.1.2.1 haad 593:
1.1.2.2 haad 594: /*
595: * If we want to deny table with 2 or more different
596: * target we should do it here
597: */
1.1.2.1 haad 598: if ((target = dm_target_lookup_name(type)) == NULL)
599: return ENOENT;
600:
1.1.2.2 haad 601: if ((table_en=kmem_alloc(sizeof(struct dm_table_entry),
602: KM_NOSLEEP)) == NULL)
1.1.2.1 haad 603: return ENOMEM;
604:
1.1.2.2 haad 605: prop_dictionary_get_uint64(target_dict, DM_TABLE_START,
606: &table_en->start);
607: prop_dictionary_get_uint64(target_dict, DM_TABLE_LENGTH,
608: &table_en->length);
1.1.2.1 haad 609:
610: table_en->target=target;
611: table_en->dm_dev=dmv;
612:
613: /*
614: * There is a parameter string after dm_target_spec
615: * structure which points to /dev/wd0a 284 part of
616: * table. String str points to this text.
617: */
618:
1.1.2.4 ! haad 619: prop_dictionary_get_cstring(target_dict,
! 620: DM_TABLE_PARAMS, (char**)&str);
1.1.2.1 haad 621:
622: /* Test readonly flag change anything only if it is not set*/
623: if (!(flags & DM_READONLY_FLAG)){
624:
625: if (SLIST_EMPTY(tbl))
626: /* insert this table to head */
1.1.2.2 haad 627: SLIST_INSERT_HEAD(tbl, table_en, next);
1.1.2.1 haad 628: else
1.1.2.2 haad 629: SLIST_INSERT_AFTER(last_table, table_en, next);
630:
1.1.2.1 haad 631: prop_dictionary_get_cstring(target_dict,
1.1.2.2 haad 632: DM_TABLE_PARAMS, (char **)&table_en->params);
1.1.2.1 haad 633:
634: /*
1.1.2.4 ! haad 635: * Params string is different for every target,
! 636: * therfore I have to pass it to target init
! 637: * routine and parse parameters there.
1.1.2.1 haad 638: */
1.1.2.4 ! haad 639: if (target->init != NULL && strlen(str) != 0)
1.1.2.2 haad 640: target->init(dmv, &table_en->target_config,
1.1.2.4 ! haad 641: str);
1.1.2.1 haad 642:
643: last_table = table_en;
644:
645: } else {
1.1.2.2 haad 646: kmem_free(table_en, sizeof(struct dm_table_entry));
1.1.2.1 haad 647: dm_pdev_destroy(dmp);
648: }
649:
1.1.2.4 ! haad 650: prop_object_release(str);
1.1.2.1 haad 651: }
652:
653: dmv->cur_active_table = 1 - dmv->cur_active_table;
654:
655: prop_object_release(cmd_array);
656:
657: DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
658:
659: return 0;
660: }
661:
662: /*
663: * Get description of all tables loaded to device from kernel
664: * and send it to libdevmapper.
665: *
666: * Output dictionary for every table:
667: *
668: * <key>cmd_data</key>
669: * <array>
670: * <dict>
671: * <key>type<key>
672: * <string>...</string>
673: *
674: * <key>start</key>
675: * <integer>...</integer>
676: *
677: * <key>length</key>
678: * <integer>...</integer>
679: *
680: * <key>params</key>
681: * <string>...</string>
682: * </dict>
683: * </array>
684: *
685: */
686: int
687: dm_table_status_ioctl(prop_dictionary_t dm_dict)
688: {
689: struct dm_dev *dmv;
690: struct dm_table *tbl;
691: struct dm_table_entry *table_en;
692:
693: prop_array_t cmd_array;
694: prop_dictionary_t target_dict;
695:
696: uint32_t rec_size;
697: uint64_t dev;
698:
699: const char *name, *uuid;
700: int flags,i;
701:
702: dmv = NULL;
703: uuid = NULL;
704: name = NULL;
705:
706: flags = 0;
707: rec_size = 0;
708: i=0;
709:
1.1.2.2 haad 710: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
711: prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
712: prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
713: prop_dictionary_get_uint64(dm_dict, DM_IOCTL_DEV, &dev);
1.1.2.1 haad 714:
1.1.2.2 haad 715: cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
1.1.2.1 haad 716:
717: if (((dmv = dm_dev_lookup_name(name)) == NULL) &&
718: ((dmv = dm_dev_lookup_uuid(uuid)) == NULL) &&
719: ((dmv = dm_dev_lookup_minor(minor(dev)))) == NULL) {
720: DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
721: return ENOENT;
722: }
723:
1.1.2.2 haad 724: aprint_verbose("Status of device tables: %s--%d\n",
725: name, dmv->cur_active_table);
1.1.2.1 haad 726:
727: tbl = &dmv->tables[dmv->cur_active_table];
728:
1.1.2.4 ! haad 729: if (tbl != NULL)
! 730: DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
! 731: else
! 732: DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
! 733:
1.1.2.1 haad 734: SLIST_FOREACH(table_en,tbl,next)
735: {
736: target_dict = prop_dictionary_create();
1.1.2.2 haad 737: aprint_verbose("%016" PRIu64 ", length %016" PRIu64
738: ", target %s\n", table_en->start, table_en->length,
739: table_en->target->name);
740:
741: prop_dictionary_set_uint64(target_dict, DM_TABLE_START,
742: table_en->start);
743: prop_dictionary_set_uint64(target_dict, DM_TABLE_LENGTH,
744: table_en->length);
745:
746: prop_dictionary_set_cstring(target_dict, DM_TABLE_TYPE,
747: table_en->target->name);
748: prop_dictionary_set_cstring(target_dict, DM_TABLE_PARAMS,
749: table_en->params);
1.1.2.1 haad 750:
1.1.2.2 haad 751: prop_dictionary_set_int32(target_dict, DM_TABLE_STAT,
752: dmv->cur_active_table);
1.1.2.1 haad 753:
1.1.2.2 haad 754: prop_array_set(cmd_array, i, target_dict);
1.1.2.1 haad 755:
756: prop_object_release(target_dict);
757:
758: i++;
759: }
760:
761: return 0;
762: }
763:
764:
765: /*
766: * For every call I have to set kernel driver version.
767: * Because I can have commands supported only in other
768: * newer/later version. This routine is called for every
769: * ioctl command.
770: */
771: int
772: dm_check_version(prop_dictionary_t dm_dict)
773: {
774: size_t i;
775: int dm_version[3];
776: prop_array_t ver;
777: int r;
778:
779: r = 0;
780:
1.1.2.2 haad 781: ver = prop_dictionary_get(dm_dict, DM_IOCTL_VERSION);
1.1.2.1 haad 782:
783: for(i=0; i < 3; i++)
1.1.2.2 haad 784: prop_array_get_uint32(ver, i, &dm_version[i]);
1.1.2.1 haad 785:
786:
1.1.2.2 haad 787: if (DM_VERSION_MAJOR != dm_version[0] ||
788: DM_VERSION_MINOR < dm_version[1])
1.1.2.1 haad 789: {
790: aprint_verbose("libdevmapper/kernel version mismatch "
791: "kernel: %d.%d.%d libdevmapper: %d.%d.%d\n",
1.1.2.2 haad 792: DM_VERSION_MAJOR, DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL,
793: dm_version[0], dm_version[1], dm_version[2]);
794:
1.1.2.1 haad 795: r = EIO;
796: goto out;
797: }
798:
1.1.2.2 haad 799: prop_array_set_uint32(ver, 0, DM_VERSION_MAJOR);
800: prop_array_set_uint32(ver, 1, DM_VERSION_MINOR);
801: prop_array_set_uint32(ver, 2, DM_VERSION_PATCHLEVEL);
1.1.2.1 haad 802:
803: out:
804: return r;
805: }
CVSweb <webmaster@jp.NetBSD.org>