1 /* $NetBSD: dm_ioctl.c,v 1.21 2010/02/25 20:48:58 jakllsch Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
33 * Locking is used to synchronise between ioctl calls and between dm_table's
37 * Simple reference counting, to count users of device will be used routines
38 * dm_dev_busy/dm_dev_unbusy are used for that.
39 * dm_dev_lookup/dm_dev_rem call dm_dev_busy before return(caller is therefore
40 * holder of reference_counter last).
42 * ioctl routines which change/remove dm_dev parameters must wait on
43 * dm_dev::dev_cv and when last user will call dm_dev_unbusy they will wake
47 * To access table entries dm_table_* routines must be used.
49 * dm_table_get_entry will increment table users reference
50 * counter. It will return active or inactive table depends
51 * on uint8_t argument.
53 * dm_table_release must be called for every table_entry from
54 * dm_table_get_entry. Between these to calls tables can'tbe switched
57 * dm_table_head_init initialize talbe_entries SLISTS and io_cv.
59 * dm_table_head_destroy destroy cv.
61 * There are two types of users for dm_table_head first type will
62 * only read list and try to do anything with it e.g. dmstrategy,
63 * dm_table_size etc. There is another user for table_head which wants
64 * to change table lists e.g. dm_dev_resume_ioctl, dm_dev_remove_ioctl,
65 * dm_table_clear_ioctl.
67 * NOTE: It is not allowed to call dm_table_destroy, dm_table_switch_tables
68 * with hold table reference counter. Table reference counter is hold
69 * after calling dm_table_get_entry routine. After calling this
70 * function user must call dm_table_release before any writer table
73 * Example: dm_table_get_entry
74 * dm_table_destroy/dm_table_switch_tables
75 * This exaple will lead to deadlock situation because after dm_table_get_entry
76 * table reference counter is != 0 and dm_table_destroy have to wait on cv until
77 * reference counter is 0.
81 #include <sys/types.h>
82 #include <sys/param.h>
84 #include <sys/device.h>
85 #include <sys/devicestat.h>
86 #include <sys/devfs.h>
88 #include <sys/disklabel.h>
89 #include <sys/malloc.h>
91 #include <sys/vnode.h>
93 #include "netbsd-dm.h"
96 extern struct dev_ops dm_ops;
97 extern struct devfs_bitmap dm_minor_bitmap;
98 uint64_t dm_dev_counter;
100 #define DM_REMOVE_FLAG(flag, name) do { \
101 prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
103 prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
104 } while (/*CONSTCOND*/0)
106 #define DM_ADD_FLAG(flag, name) do { \
107 prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
109 prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
110 } while (/*CONSTCOND*/0)
112 static int dm_dbg_print_flags(int);
115 * Print flags sent to the kernel from libevmapper.
118 dm_dbg_print_flags(int flags)
120 aprint_debug("dbg_print --- %d\n", flags);
122 if (flags & DM_READONLY_FLAG)
123 aprint_debug("dbg_flags: DM_READONLY_FLAG set In/Out\n");
125 if (flags & DM_SUSPEND_FLAG)
126 aprint_debug("dbg_flags: DM_SUSPEND_FLAG set In/Out \n");
128 if (flags & DM_PERSISTENT_DEV_FLAG)
129 aprint_debug("db_flags: DM_PERSISTENT_DEV_FLAG set In\n");
131 if (flags & DM_STATUS_TABLE_FLAG)
132 aprint_debug("dbg_flags: DM_STATUS_TABLE_FLAG set In\n");
134 if (flags & DM_ACTIVE_PRESENT_FLAG)
135 aprint_debug("dbg_flags: DM_ACTIVE_PRESENT_FLAG set Out\n");
137 if (flags & DM_INACTIVE_PRESENT_FLAG)
138 aprint_debug("dbg_flags: DM_INACTIVE_PRESENT_FLAG set Out\n");
140 if (flags & DM_BUFFER_FULL_FLAG)
141 aprint_debug("dbg_flags: DM_BUFFER_FULL_FLAG set Out\n");
143 if (flags & DM_SKIP_BDGET_FLAG)
144 aprint_debug("dbg_flags: DM_SKIP_BDGET_FLAG set In\n");
146 if (flags & DM_SKIP_LOCKFS_FLAG)
147 aprint_debug("dbg_flags: DM_SKIP_LOCKFS_FLAG set In\n");
149 if (flags & DM_NOFLUSH_FLAG)
150 aprint_debug("dbg_flags: DM_NOFLUSH_FLAG set In\n");
155 * Get version ioctl call I do it as default therefore this
156 * function is unused now.
159 dm_get_version_ioctl(prop_dictionary_t dm_dict)
165 * Get list of all available targets from global
166 * target list and sent them back to libdevmapper.
169 dm_list_versions_ioctl(prop_dictionary_t dm_dict)
171 prop_array_t target_list;
176 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
178 dm_dbg_print_flags(flags);
179 target_list = dm_target_prop_list();
181 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, target_list);
182 prop_object_release(target_list);
187 * Create in-kernel entry for device. Device attributes such as name, uuid are
188 * taken from proplib dictionary.
192 dm_dev_create_ioctl(prop_dictionary_t dm_dict)
195 const char *name, *uuid;
196 char name_buf[MAXPATHLEN];
197 int r, flags, dm_minor;
204 /* Get needed values from dictionary. */
205 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
206 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
207 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
209 dm_dbg_print_flags(flags);
211 /* Lookup name and uuid if device already exist quit. */
212 if ((dmv = dm_dev_lookup(name, uuid, -1)) != NULL) {
213 DM_ADD_FLAG(flags, DM_EXISTS_FLAG); /* Device already exists */
218 if ((devt = config_attach_pseudo(&dm_cfdata)) == NULL) {
219 aprint_error("Unable to attach pseudo device dm/%s\n", name);
223 if ((dmv = dm_dev_alloc()) == NULL)
227 strncpy(dmv->uuid, uuid, DM_UUID_LEN);
232 strlcpy(dmv->name, name, DM_NAME_LEN);
234 dm_minor = devfs_clone_bitmap_get(&dm_minor_bitmap, 0);
235 dmv->flags = 0; /* device flags are set when needed */
241 dm_table_head_init(&dmv->table_head);
243 lockinit(&dmv->dev_mtx, "dmdev", 0, LK_CANRECURSE);
244 lockinit(&dmv->diskp_mtx, "dmdisk", 0, LK_CANRECURSE);
245 cv_init(&dmv->dev_cv, "dm_dev");
247 if (flags & DM_READONLY_FLAG)
248 dmv->flags |= DM_READONLY_FLAG;
250 aprint_debug("Creating device dm/%s\n", name);
251 ksnprintf(name_buf, sizeof(name_buf), "mapper/%s", dmv->name);
253 devstat_add_entry(&dmv->stats, name, 0, DEV_BSIZE,
254 DEVSTAT_NO_ORDERED_TAGS,
255 DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER,
256 DEVSTAT_PRIORITY_DISK);
258 dmv->devt = disk_create_named(name_buf, dm_minor, dmv->diskp, &dm_ops);
259 reference_dev(dmv->devt);
261 dmv->minor = minor(dmv->devt);
262 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
263 udev_dict_set_cstr(dmv->devt, "subsystem", "disk");
265 if ((r = dm_dev_insert(dmv)) != 0)
268 DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
269 DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
271 /* Increment device counter After creating device */
272 ++dm_dev_counter; /* XXX: was atomic 64 */
277 * Get list of created device-mapper devices fromglobal list and
282 * <key>cmd_data</key>
286 * <string>...</string>
289 * <integer>...</integer>
295 dm_dev_list_ioctl(prop_dictionary_t dm_dict)
297 prop_array_t dev_list;
303 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
305 dm_dbg_print_flags(flags);
307 dev_list = dm_dev_prop_list();
309 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, dev_list);
310 prop_object_release(dev_list);
315 * Rename selected devices old name is in struct dm_ioctl.
316 * newname is taken from dictionary
318 * <key>cmd_data</key>
320 * <string>...</string>
324 dm_dev_rename_ioctl(prop_dictionary_t dm_dict)
326 prop_array_t cmd_array;
329 const char *name, *uuid, *n_name;
330 uint32_t flags, minor;
336 /* Get needed values from dictionary. */
337 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
338 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
339 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
340 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
342 dm_dbg_print_flags(flags);
344 cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
346 prop_array_get_cstring_nocopy(cmd_array, 0, &n_name);
348 if (strlen(n_name) + 1 > DM_NAME_LEN)
351 if ((dmv = dm_dev_rem(NULL, name, uuid, minor)) == NULL) {
352 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
355 /* change device name */
357 * XXX How to deal with this change, name only used in
358 * dm_dev_routines, should I add dm_dev_change_name which will run
359 * under the dm_dev_list mutex ?
361 strlcpy(dmv->name, n_name, DM_NAME_LEN);
363 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
364 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
365 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
372 * Remove device from global list I have to remove active
373 * and inactive tables first.
376 dm_dev_remove_ioctl(prop_dictionary_t dm_dict)
379 const char *name, *uuid;
380 uint32_t flags, minor;
386 /* Get needed values from dictionary. */
387 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
388 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
389 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
390 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
392 dm_dbg_print_flags(flags);
395 * This seems as hack to me, probably use routine dm_dev_get_devt to
396 * atomicaly get devt from device.
398 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
399 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
409 * This will call dm_detach routine which will actually removes
412 return dm_detach(dmv);
415 * Return actual state of device to libdevmapper.
418 dm_dev_status_ioctl(prop_dictionary_t dm_dict)
421 const char *name, *uuid;
422 uint32_t flags, j, minor;
429 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
430 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
431 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
432 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
434 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
435 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
438 dm_dbg_print_flags(dmv->flags);
440 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
441 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
442 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
444 if (dmv->flags & DM_SUSPEND_FLAG)
445 DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
448 * Add status flags for tables I have to check both active and
451 if ((j = dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE))) {
452 DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
454 DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
456 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_TARGET_COUNT, j);
458 if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
459 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
461 DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
468 * Set only flag to suggest that device is suspended. This call is
469 * not supported in NetBSD.
473 dm_dev_suspend_ioctl(prop_dictionary_t dm_dict)
476 const char *name, *uuid;
477 uint32_t flags, minor;
483 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
484 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
485 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
486 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
488 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
489 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
492 atomic_set_int(&dmv->flags, DM_SUSPEND_FLAG);
494 dm_dbg_print_flags(dmv->flags);
496 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
497 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, dmv->flags);
498 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
502 /* Add flags to dictionary flag after dmv -> dict copy */
503 DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
508 * Simulate Linux behaviour better and switch tables here and not in
509 * dm_table_load_ioctl.
512 dm_dev_resume_ioctl(prop_dictionary_t dm_dict)
515 const char *name, *uuid;
516 uint32_t flags, minor;
523 * char *xml; xml = prop_dictionary_externalize(dm_dict);
524 * printf("%s\n",xml);
527 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
528 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
529 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
530 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
532 /* Remove device from global device list */
533 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
534 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
537 atomic_clear_int(&dmv->flags, (DM_SUSPEND_FLAG | DM_INACTIVE_PRESENT_FLAG));
538 atomic_set_int(&dmv->flags, DM_ACTIVE_PRESENT_FLAG);
540 dm_table_switch_tables(&dmv->table_head);
542 DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
544 dmsetdiskinfo(dmv->diskp, &dmv->table_head);
546 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
547 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
548 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
552 /* Destroy inactive table after resume. */
553 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
558 * Table management routines
559 * lvm2tools doens't send name/uuid to kernel with table
560 * for lookup I have to use minor number.
564 * Remove inactive table from device. Routines which work's with inactive tables
565 * doesn't need to synchronise with dmstrategy. They can synchronise themselves with mutex?.
569 dm_table_clear_ioctl(prop_dictionary_t dm_dict)
572 const char *name, *uuid;
573 uint32_t flags, minor;
581 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
582 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
583 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
584 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
586 aprint_debug("Clearing inactive table from device: %s--%s\n",
589 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
590 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
593 /* Select unused table */
594 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
596 atomic_clear_int(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);
603 * Get list of physical devices for active table.
604 * Get dev_t from pdev vnode and insert it into cmd_array.
606 * XXX. This function is called from lvm2tools to get information
607 * about physical devices, too e.g. during vgcreate.
610 dm_table_deps_ioctl(prop_dictionary_t dm_dict)
614 dm_table_entry_t *table_en;
616 prop_array_t cmd_array;
617 const char *name, *uuid;
618 uint32_t flags, minor;
630 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
631 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
632 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
633 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
635 /* create array for dev_t's */
636 cmd_array = prop_array_create();
638 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
639 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
642 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
643 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_NAME, dmv->name);
644 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
646 aprint_debug("Getting table deps for device: %s\n", dmv->name);
649 * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
652 if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
653 table_type = DM_TABLE_INACTIVE;
655 table_type = DM_TABLE_ACTIVE;
657 tbl = dm_table_get_entry(&dmv->table_head, table_type);
659 SLIST_FOREACH(table_en, tbl, next)
660 table_en->target->deps(table_en, cmd_array);
662 dm_table_release(&dmv->table_head, table_type);
665 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
666 prop_object_release(cmd_array);
671 * Load new table/tables to device.
672 * Call apropriate target init routine open all physical pdev's and
673 * link them to device. For other targets mirror, strip, snapshot
674 * etc. also add dependency devices to upcalls list.
676 * Load table to inactive slot table are switched in dm_device_resume_ioctl.
677 * This simulates Linux behaviour better there should not be any difference.
681 dm_table_load_ioctl(prop_dictionary_t dm_dict)
684 dm_table_entry_t *table_en, *last_table;
688 prop_object_iterator_t iter;
689 prop_array_t cmd_array;
690 prop_dictionary_t target_dict;
692 const char *name, *uuid, *type;
694 uint32_t flags, ret, minor;
707 * char *xml; xml = prop_dictionary_externalize(dm_dict);
708 * printf("%s\n",xml);
711 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
712 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
713 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
714 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
716 cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
717 iter = prop_array_iterator(cmd_array);
718 dm_dbg_print_flags(flags);
720 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
721 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
724 aprint_debug("Loading table to device: %s--%d\n", name,
725 dmv->table_head.cur_active_table);
728 * I have to check if this table slot is not used by another table list.
729 * if it is used I should free them.
731 if (dmv->flags & DM_INACTIVE_PRESENT_FLAG)
732 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
734 dm_dbg_print_flags(dmv->flags);
735 tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_INACTIVE);
737 aprint_debug("dmv->name = %s\n", dmv->name);
739 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
741 while ((target_dict = prop_object_iterator_next(iter)) != NULL) {
742 prop_dictionary_get_cstring_nocopy(target_dict,
743 DM_TABLE_TYPE, &type);
745 * If we want to deny table with 2 or more different
746 * target we should do it here
748 if ((target = dm_target_lookup(type)) == NULL) {
749 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
753 if ((table_en = kmalloc(sizeof(dm_table_entry_t),
754 M_DM, M_WAITOK)) == NULL) {
755 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
757 dm_target_unbusy(target);
760 prop_dictionary_get_uint64(target_dict, DM_TABLE_START,
762 prop_dictionary_get_uint64(target_dict, DM_TABLE_LENGTH,
765 aprint_debug("dm_ioctl.c... table_en->start = %ju, "
766 "table_en->length = %ju\n",
767 (uintmax_t)table_en->start,
768 (uintmax_t)table_en->length);
770 table_en->target = target;
771 table_en->dm_dev = dmv;
772 table_en->target_config = NULL;
775 * There is a parameter string after dm_target_spec
776 * structure which points to /dev/wd0a 284 part of
777 * table. String str points to this text. This can be
778 * null and therefore it should be checked before we try to
781 prop_dictionary_get_cstring(target_dict,
782 DM_TABLE_PARAMS, (char **) &str);
784 if (SLIST_EMPTY(tbl))
785 /* insert this table to head */
786 SLIST_INSERT_HEAD(tbl, table_en, next);
788 SLIST_INSERT_AFTER(last_table, table_en, next);
791 * Params string is different for every target,
792 * therfore I have to pass it to target init
793 * routine and parse parameters there.
795 aprint_debug("DM: str passed in is: %s", str);
796 if ((ret = target->init(dmv, &table_en->target_config,
799 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
800 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
804 dm_target_unbusy(target);
807 last_table = table_en;
810 prop_object_iterator_release(iter);
812 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
813 atomic_set_int(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);
815 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
819 dmsetdiskinfo(dmv->diskp, &dmv->table_head);
824 * Get description of all tables loaded to device from kernel
825 * and send it to libdevmapper.
827 * Output dictionary for every table:
829 * <key>cmd_data</key>
833 * <string>...</string>
836 * <integer>...</integer>
839 * <integer>...</integer>
842 * <string>...</string>
848 dm_table_status_ioctl(prop_dictionary_t dm_dict)
852 dm_table_entry_t *table_en;
854 prop_array_t cmd_array;
855 prop_dictionary_t target_dict;
857 uint32_t rec_size, minor;
859 const char *name, *uuid;
871 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
872 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
873 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
874 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
876 cmd_array = prop_array_create();
878 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
879 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
883 * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
886 if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
887 table_type = DM_TABLE_INACTIVE;
889 table_type = DM_TABLE_ACTIVE;
891 if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE))
892 DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
894 DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
896 if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
897 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
899 DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
903 if (dmv->flags & DM_SUSPEND_FLAG)
904 DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
906 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
908 aprint_debug("Status of device tables: %s--%d\n",
909 name, dmv->table_head.cur_active_table);
911 tbl = dm_table_get_entry(&dmv->table_head, table_type);
913 SLIST_FOREACH(table_en, tbl, next) {
914 target_dict = prop_dictionary_create();
915 aprint_debug("%016" PRIu64 ", length %016" PRIu64
916 ", target %s\n", table_en->start, table_en->length,
917 table_en->target->name);
919 prop_dictionary_set_uint64(target_dict, DM_TABLE_START,
921 prop_dictionary_set_uint64(target_dict, DM_TABLE_LENGTH,
924 prop_dictionary_set_cstring(target_dict, DM_TABLE_TYPE,
925 table_en->target->name);
927 /* dm_table_get_cur_actv.table ?? */
928 prop_dictionary_set_int32(target_dict, DM_TABLE_STAT,
929 dmv->table_head.cur_active_table);
931 if (flags |= DM_STATUS_TABLE_FLAG) {
932 params = table_en->target->status
933 (table_en->target_config);
935 if (params != NULL) {
936 prop_dictionary_set_cstring(target_dict,
937 DM_TABLE_PARAMS, params);
942 prop_array_add(cmd_array, target_dict);
943 prop_object_release(target_dict);
946 dm_table_release(&dmv->table_head, table_type);
949 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
950 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
951 prop_object_release(cmd_array);
958 * For every call I have to set kernel driver version.
959 * Because I can have commands supported only in other
960 * newer/later version. This routine is called for every
964 dm_check_version(prop_dictionary_t dm_dict)
970 ver = prop_dictionary_get(dm_dict, DM_IOCTL_VERSION);
972 for (i = 0; i < 3; i++)
973 prop_array_get_uint32(ver, i, &dm_version[i]);
975 if (DM_VERSION_MAJOR != dm_version[0] || DM_VERSION_MINOR < dm_version[1]) {
976 aprint_debug("libdevmapper/kernel version mismatch "
977 "kernel: %d.%d.%d libdevmapper: %d.%d.%d\n",
978 DM_VERSION_MAJOR, DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL,
979 dm_version[0], dm_version[1], dm_version[2]);
983 prop_array_set_uint32(ver, 0, DM_VERSION_MAJOR);
984 prop_array_set_uint32(ver, 1, DM_VERSION_MINOR);
985 prop_array_set_uint32(ver, 2, DM_VERSION_PATCHLEVEL);
987 prop_dictionary_set(dm_dict, DM_IOCTL_VERSION, ver);