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>
83 #include <sys/device.h>
84 #include <sys/malloc.h>
85 #include <sys/vnode.h>
86 #include <dev/disk/dm/dm.h>
88 #include "netbsd-dm.h"
90 #define DM_REMOVE_FLAG(flag, name) do { \
91 prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
93 prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
94 } while (/*CONSTCOND*/0)
96 #define DM_ADD_FLAG(flag, name) do { \
97 prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
99 prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
100 } while (/*CONSTCOND*/0)
102 static int dm_dbg_print_flags(int);
105 * Print flags sent to the kernel from libevmapper.
108 dm_dbg_print_flags(int flags)
110 aprint_debug("dbg_print --- %d\n", flags);
112 if (flags & DM_READONLY_FLAG)
113 aprint_debug("dbg_flags: DM_READONLY_FLAG set In/Out\n");
115 if (flags & DM_SUSPEND_FLAG)
116 aprint_debug("dbg_flags: DM_SUSPEND_FLAG set In/Out \n");
118 if (flags & DM_PERSISTENT_DEV_FLAG)
119 aprint_debug("db_flags: DM_PERSISTENT_DEV_FLAG set In\n");
121 if (flags & DM_STATUS_TABLE_FLAG)
122 aprint_debug("dbg_flags: DM_STATUS_TABLE_FLAG set In\n");
124 if (flags & DM_ACTIVE_PRESENT_FLAG)
125 aprint_debug("dbg_flags: DM_ACTIVE_PRESENT_FLAG set Out\n");
127 if (flags & DM_INACTIVE_PRESENT_FLAG)
128 aprint_debug("dbg_flags: DM_INACTIVE_PRESENT_FLAG set Out\n");
130 if (flags & DM_BUFFER_FULL_FLAG)
131 aprint_debug("dbg_flags: DM_BUFFER_FULL_FLAG set Out\n");
133 if (flags & DM_SKIP_BDGET_FLAG)
134 aprint_debug("dbg_flags: DM_SKIP_BDGET_FLAG set In\n");
136 if (flags & DM_SKIP_LOCKFS_FLAG)
137 aprint_debug("dbg_flags: DM_SKIP_LOCKFS_FLAG set In\n");
139 if (flags & DM_NOFLUSH_FLAG)
140 aprint_debug("dbg_flags: DM_NOFLUSH_FLAG set In\n");
145 * Get version ioctl call I do it as default therefore this
146 * function is unused now.
149 dm_get_version_ioctl(prop_dictionary_t dm_dict)
154 * Get list of all available targets from global
155 * target list and sent them back to libdevmapper.
158 dm_list_versions_ioctl(prop_dictionary_t dm_dict)
160 prop_array_t target_list;
165 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
167 dm_dbg_print_flags(flags);
168 target_list = dm_target_prop_list();
170 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, target_list);
171 prop_object_release(target_list);
176 * Create in-kernel entry for device. Device attributes such as name, uuid are
177 * taken from proplib dictionary.
181 dm_dev_create_ioctl(prop_dictionary_t dm_dict)
184 const char *name, *uuid;
192 /* Get needed values from dictionary. */
193 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
194 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
195 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
197 dm_dbg_print_flags(flags);
199 /* Lookup name and uuid if device already exist quit. */
200 if ((dmv = dm_dev_lookup(name, uuid, -1)) != NULL) {
201 DM_ADD_FLAG(flags, DM_EXISTS_FLAG); /* Device already exists */
206 r = dm_dev_create(&dmv, name, uuid, flags);
209 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
210 DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
211 DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
217 * Get list of created device-mapper devices fromglobal list and
222 * <key>cmd_data</key>
226 * <string>...</string>
229 * <integer>...</integer>
235 dm_dev_list_ioctl(prop_dictionary_t dm_dict)
237 prop_array_t dev_list;
243 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
245 dm_dbg_print_flags(flags);
247 dev_list = dm_dev_prop_list();
249 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, dev_list);
250 prop_object_release(dev_list);
255 * Rename selected devices old name is in struct dm_ioctl.
256 * newname is taken from dictionary
258 * <key>cmd_data</key>
260 * <string>...</string>
264 dm_dev_rename_ioctl(prop_dictionary_t dm_dict)
267 prop_array_t cmd_array;
270 const char *name, *uuid, *n_name;
271 uint32_t flags, minor;
277 /* Get needed values from dictionary. */
278 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
279 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
280 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
281 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
283 dm_dbg_print_flags(flags);
285 cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
287 prop_array_get_cstring_nocopy(cmd_array, 0, &n_name);
289 if (strlen(n_name) + 1 > DM_NAME_LEN)
292 if ((dmv = dm_dev_rem(NULL, name, uuid, minor)) == NULL) {
293 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
296 /* change device name */
298 * XXX How to deal with this change, name only used in
299 * dm_dev_routines, should I add dm_dev_change_name which will run
300 * under the dm_dev_list mutex ?
302 strlcpy(dmv->name, n_name, DM_NAME_LEN);
304 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
305 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
306 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
312 * XXX: the rename is not yet implemented. The main complication
313 * here is devfs. We'd probably need a new function, rename_dev()
314 * that would trigger a node rename in devfs.
316 kprintf("dm_dev_rename_ioctl called, but not implemented!\n");
324 dm_dev_remove_ioctl(prop_dictionary_t dm_dict)
327 const char *name, *uuid;
328 uint32_t flags, minor, is_open;
334 /* Get needed values from dictionary. */
335 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
336 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
337 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
338 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
340 dm_dbg_print_flags(flags);
342 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
343 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
347 is_open = dmv->is_open;
355 * This will call dm_detach routine which will actually remove
358 return dm_dev_remove(dmv);
362 * Try to remove all devices
365 dm_dev_remove_all_ioctl(prop_dictionary_t dm_dict)
369 /* Get needed values from dictionary. */
370 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
372 dm_dbg_print_flags(flags);
374 /* Gently remove all devices, if possible */
375 return dm_dev_remove_all(1);
379 * Return actual state of device to libdevmapper.
382 dm_dev_status_ioctl(prop_dictionary_t dm_dict)
385 const char *name, *uuid;
386 uint32_t flags, j, minor;
393 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
394 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
395 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
396 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
398 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
399 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
402 dm_dbg_print_flags(dmv->flags);
404 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
405 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
406 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
408 if (dmv->flags & DM_SUSPEND_FLAG)
409 DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
412 * Add status flags for tables I have to check both active and
415 if ((j = dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE))) {
416 DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
418 DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
420 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_TARGET_COUNT, j);
422 if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
423 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
425 DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
432 * Set only flag to suggest that device is suspended. This call is
433 * not supported in NetBSD.
437 dm_dev_suspend_ioctl(prop_dictionary_t dm_dict)
440 const char *name, *uuid;
441 uint32_t flags, minor;
447 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
448 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
449 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
450 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
452 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
453 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
456 atomic_set_int(&dmv->flags, DM_SUSPEND_FLAG);
458 dm_dbg_print_flags(dmv->flags);
460 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
461 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, dmv->flags);
462 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
466 /* Add flags to dictionary flag after dmv -> dict copy */
467 DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
472 * Simulate Linux behaviour better and switch tables here and not in
473 * dm_table_load_ioctl.
476 dm_dev_resume_ioctl(prop_dictionary_t dm_dict)
479 const char *name, *uuid;
480 uint32_t flags, minor;
487 * char *xml; xml = prop_dictionary_externalize(dm_dict);
488 * printf("%s\n",xml);
491 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
492 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
493 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
494 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
496 /* Remove device from global device list */
497 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
498 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
501 atomic_clear_int(&dmv->flags, (DM_SUSPEND_FLAG | DM_INACTIVE_PRESENT_FLAG));
502 atomic_set_int(&dmv->flags, DM_ACTIVE_PRESENT_FLAG);
504 dm_table_switch_tables(&dmv->table_head);
506 DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
508 dmsetdiskinfo(dmv->diskp, &dmv->table_head);
510 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
511 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
512 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
516 /* Destroy inactive table after resume. */
517 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
522 * Table management routines
523 * lvm2tools doens't send name/uuid to kernel with table
524 * for lookup I have to use minor number.
528 * Remove inactive table from device. Routines which work's with inactive tables
529 * doesn't need to synchronise with dmstrategy. They can synchronise themselves with mutex?.
533 dm_table_clear_ioctl(prop_dictionary_t dm_dict)
536 const char *name, *uuid;
537 uint32_t flags, minor;
545 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
546 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
547 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
548 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
550 aprint_debug("Clearing inactive table from device: %s--%s\n",
553 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
554 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
557 /* Select unused table */
558 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
560 atomic_clear_int(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);
567 * Get list of physical devices for active table.
568 * Get dev_t from pdev vnode and insert it into cmd_array.
570 * XXX. This function is called from lvm2tools to get information
571 * about physical devices, too e.g. during vgcreate.
574 dm_table_deps_ioctl(prop_dictionary_t dm_dict)
578 dm_table_entry_t *table_en;
580 prop_array_t cmd_array;
581 const char *name, *uuid;
582 uint32_t flags, minor;
594 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
595 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
596 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
597 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
599 /* create array for dev_t's */
600 cmd_array = prop_array_create();
602 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
603 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
606 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
607 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_NAME, dmv->name);
608 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
610 aprint_debug("Getting table deps for device: %s\n", dmv->name);
613 * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
616 if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
617 table_type = DM_TABLE_INACTIVE;
619 table_type = DM_TABLE_ACTIVE;
621 tbl = dm_table_get_entry(&dmv->table_head, table_type);
623 SLIST_FOREACH(table_en, tbl, next)
624 table_en->target->deps(table_en, cmd_array);
626 dm_table_release(&dmv->table_head, table_type);
629 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
630 prop_object_release(cmd_array);
635 * Load new table/tables to device.
636 * Call apropriate target init routine open all physical pdev's and
637 * link them to device. For other targets mirror, strip, snapshot
638 * etc. also add dependency devices to upcalls list.
640 * Load table to inactive slot table are switched in dm_device_resume_ioctl.
641 * This simulates Linux behaviour better there should not be any difference.
645 dm_table_load_ioctl(prop_dictionary_t dm_dict)
648 dm_table_entry_t *table_en, *last_table;
652 prop_object_iterator_t iter;
653 prop_array_t cmd_array;
654 prop_dictionary_t target_dict;
656 const char *name, *uuid, *type;
658 uint32_t flags, ret, minor;
671 * char *xml; xml = prop_dictionary_externalize(dm_dict);
672 * printf("%s\n",xml);
675 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
676 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
677 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
678 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
680 cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
681 iter = prop_array_iterator(cmd_array);
682 dm_dbg_print_flags(flags);
684 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
685 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
688 aprint_debug("Loading table to device: %s--%d\n", name,
689 dmv->table_head.cur_active_table);
692 * I have to check if this table slot is not used by another table list.
693 * if it is used I should free them.
695 if (dmv->flags & DM_INACTIVE_PRESENT_FLAG)
696 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
698 dm_dbg_print_flags(dmv->flags);
699 tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_INACTIVE);
701 aprint_debug("dmv->name = %s\n", dmv->name);
703 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
705 while ((target_dict = prop_object_iterator_next(iter)) != NULL) {
706 prop_dictionary_get_cstring_nocopy(target_dict,
707 DM_TABLE_TYPE, &type);
709 * If we want to deny table with 2 or more different
710 * target we should do it here
712 if (((target = dm_target_lookup(type)) == NULL) &&
713 ((target = dm_target_autoload(type)) == NULL)) {
714 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
718 if ((table_en = kmalloc(sizeof(dm_table_entry_t),
719 M_DM, M_WAITOK)) == NULL) {
720 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
722 dm_target_unbusy(target);
725 prop_dictionary_get_uint64(target_dict, DM_TABLE_START,
727 prop_dictionary_get_uint64(target_dict, DM_TABLE_LENGTH,
730 aprint_debug("dm_ioctl.c... table_en->start = %ju, "
731 "table_en->length = %ju\n",
732 (uintmax_t)table_en->start,
733 (uintmax_t)table_en->length);
735 table_en->target = target;
736 table_en->dm_dev = dmv;
737 table_en->target_config = NULL;
740 * There is a parameter string after dm_target_spec
741 * structure which points to /dev/wd0a 284 part of
742 * table. String str points to this text. This can be
743 * null and therefore it should be checked before we try to
746 prop_dictionary_get_cstring(target_dict,
747 DM_TABLE_PARAMS, (char **) &str);
749 if (SLIST_EMPTY(tbl))
750 /* insert this table to head */
751 SLIST_INSERT_HEAD(tbl, table_en, next);
753 SLIST_INSERT_AFTER(last_table, table_en, next);
756 * Params string is different for every target,
757 * therfore I have to pass it to target init
758 * routine and parse parameters there.
760 aprint_debug("DM: str passed in is: %s", str);
761 if ((ret = target->init(dmv, &table_en->target_config,
764 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
765 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
769 dm_target_unbusy(target);
772 last_table = table_en;
775 prop_object_iterator_release(iter);
777 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
778 atomic_set_int(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);
780 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
784 dmsetdiskinfo(dmv->diskp, &dmv->table_head);
789 * Get description of all tables loaded to device from kernel
790 * and send it to libdevmapper.
792 * Output dictionary for every table:
794 * <key>cmd_data</key>
798 * <string>...</string>
801 * <integer>...</integer>
804 * <integer>...</integer>
807 * <string>...</string>
813 dm_table_status_ioctl(prop_dictionary_t dm_dict)
817 dm_table_entry_t *table_en;
819 prop_array_t cmd_array;
820 prop_dictionary_t target_dict;
822 uint32_t rec_size, minor;
824 const char *name, *uuid;
836 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
837 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
838 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
839 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
841 cmd_array = prop_array_create();
843 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
844 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
848 * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
851 if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
852 table_type = DM_TABLE_INACTIVE;
854 table_type = DM_TABLE_ACTIVE;
856 if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE))
857 DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
859 DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
861 if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
862 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
864 DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
868 if (dmv->flags & DM_SUSPEND_FLAG)
869 DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
871 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
873 aprint_debug("Status of device tables: %s--%d\n",
874 name, dmv->table_head.cur_active_table);
876 tbl = dm_table_get_entry(&dmv->table_head, table_type);
878 SLIST_FOREACH(table_en, tbl, next) {
879 target_dict = prop_dictionary_create();
880 aprint_debug("%016" PRIu64 ", length %016" PRIu64
881 ", target %s\n", table_en->start, table_en->length,
882 table_en->target->name);
884 prop_dictionary_set_uint64(target_dict, DM_TABLE_START,
886 prop_dictionary_set_uint64(target_dict, DM_TABLE_LENGTH,
889 prop_dictionary_set_cstring(target_dict, DM_TABLE_TYPE,
890 table_en->target->name);
892 /* dm_table_get_cur_actv.table ?? */
893 prop_dictionary_set_int32(target_dict, DM_TABLE_STAT,
894 dmv->table_head.cur_active_table);
896 if (flags & DM_STATUS_TABLE_FLAG) {
897 params = table_en->target->status
898 (table_en->target_config);
900 if (params != NULL) {
901 prop_dictionary_set_cstring(target_dict,
902 DM_TABLE_PARAMS, params);
907 prop_array_add(cmd_array, target_dict);
908 prop_object_release(target_dict);
911 dm_table_release(&dmv->table_head, table_type);
914 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
915 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
916 prop_object_release(cmd_array);
922 dm_message_ioctl(prop_dictionary_t dm_dict)
925 dm_table_entry_t *table_en;
927 const char *name, *uuid;
928 uint32_t flags, minor;
929 uint64_t table_start, table_end, sector;
937 /* Get needed values from dictionary. */
938 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
939 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
940 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
941 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
942 prop_dictionary_get_uint64(dm_dict, DM_MESSAGE_SECTOR, §or);
944 dm_dbg_print_flags(flags);
946 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
947 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
951 /* Get message string */
952 prop_dictionary_get_cstring(dm_dict, DM_MESSAGE_STR, &msg);
954 tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_ACTIVE);
959 if (!SLIST_EMPTY(tbl)) {
960 table_en = SLIST_FIRST(tbl);
964 SLIST_FOREACH(table_en, tbl, next) {
965 table_start = table_en->start;
966 table_end = table_start + (table_en->length);
968 if ((sector >= table_start) && (sector < table_end)) {
976 if (table_en->target->message != NULL)
977 ret = table_en->target->message(table_en, msg);
980 dm_table_release(&dmv->table_head, DM_TABLE_ACTIVE);
990 * For every call I have to set kernel driver version.
991 * Because I can have commands supported only in other
992 * newer/later version. This routine is called for every
996 dm_check_version(prop_dictionary_t dm_dict)
1002 ver = prop_dictionary_get(dm_dict, DM_IOCTL_VERSION);
1004 for (i = 0; i < 3; i++)
1005 prop_array_get_uint32(ver, i, &dm_version[i]);
1007 if (DM_VERSION_MAJOR != dm_version[0] || DM_VERSION_MINOR < dm_version[1]) {
1008 aprint_debug("libdevmapper/kernel version mismatch "
1009 "kernel: %d.%d.%d libdevmapper: %d.%d.%d\n",
1010 DM_VERSION_MAJOR, DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL,
1011 dm_version[0], dm_version[1], dm_version[2]);
1015 prop_array_set_uint32(ver, 0, DM_VERSION_MAJOR);
1016 prop_array_set_uint32(ver, 1, DM_VERSION_MINOR);
1017 prop_array_set_uint32(ver, 2, DM_VERSION_PATCHLEVEL);
1019 prop_dictionary_set(dm_dict, DM_IOCTL_VERSION, ver);