1 /* $NetBSD: dm_ioctl.c,v 1.21 2010/02/25 20:48:58 jakllsch Exp $ */
4 * Copyright (c) 2010-2011 Alex Hornung <alex@alexhornung.com>
5 * Copyright (c) 2008 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Locking is used to synchronise between ioctl calls and between dm_table's
38 * Simple reference counting, to count users of device will be used routines
39 * dm_dev_busy/dm_dev_unbusy are used for that.
40 * dm_dev_lookup/dm_dev_rem call dm_dev_busy before return(caller is therefore
41 * holder of reference_counter last).
43 * ioctl routines which change/remove dm_dev parameters must wait on
44 * dm_dev::dev_cv and when last user will call dm_dev_unbusy they will wake
48 * To access table entries dm_table_* routines must be used.
50 * dm_table_get_entry will increment table users reference
51 * counter. It will return active or inactive table depends
52 * on uint8_t argument.
54 * dm_table_release must be called for every table_entry from
55 * dm_table_get_entry. Between these to calls tables can'tbe switched
58 * dm_table_head_init initialize talbe_entries SLISTS and io_cv.
60 * dm_table_head_destroy destroy cv.
62 * There are two types of users for dm_table_head first type will
63 * only read list and try to do anything with it e.g. dmstrategy,
64 * dm_table_size etc. There is another user for table_head which wants
65 * to change table lists e.g. dm_dev_resume_ioctl, dm_dev_remove_ioctl,
66 * dm_table_clear_ioctl.
68 * NOTE: It is not allowed to call dm_table_destroy, dm_table_switch_tables
69 * with hold table reference counter. Table reference counter is hold
70 * after calling dm_table_get_entry routine. After calling this
71 * function user must call dm_table_release before any writer table
74 * Example: dm_table_get_entry
75 * dm_table_destroy/dm_table_switch_tables
76 * This exaple will lead to deadlock situation because after dm_table_get_entry
77 * table reference counter is != 0 and dm_table_destroy have to wait on cv until
78 * reference counter is 0.
82 #include <sys/types.h>
83 #include <sys/param.h>
84 #include <sys/device.h>
85 #include <sys/malloc.h>
86 #include <sys/vnode.h>
87 #include <dev/disk/dm/dm.h>
89 #include "netbsd-dm.h"
91 #define DM_REMOVE_FLAG(flag, name) do { \
92 prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
94 prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
95 } while (/*CONSTCOND*/0)
97 #define DM_ADD_FLAG(flag, name) do { \
98 prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
100 prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
101 } while (/*CONSTCOND*/0)
104 * Print flags sent to the kernel from libevmapper.
107 dm_dbg_print_flags(int flags)
109 aprint_debug("dbg_print --- %d\n", flags);
111 if (flags & DM_READONLY_FLAG)
112 aprint_debug("dbg_flags: DM_READONLY_FLAG set In/Out\n");
114 if (flags & DM_SUSPEND_FLAG)
115 aprint_debug("dbg_flags: DM_SUSPEND_FLAG set In/Out \n");
117 if (flags & DM_PERSISTENT_DEV_FLAG)
118 aprint_debug("db_flags: DM_PERSISTENT_DEV_FLAG set In\n");
120 if (flags & DM_STATUS_TABLE_FLAG)
121 aprint_debug("dbg_flags: DM_STATUS_TABLE_FLAG set In\n");
123 if (flags & DM_ACTIVE_PRESENT_FLAG)
124 aprint_debug("dbg_flags: DM_ACTIVE_PRESENT_FLAG set Out\n");
126 if (flags & DM_INACTIVE_PRESENT_FLAG)
127 aprint_debug("dbg_flags: DM_INACTIVE_PRESENT_FLAG set Out\n");
129 if (flags & DM_BUFFER_FULL_FLAG)
130 aprint_debug("dbg_flags: DM_BUFFER_FULL_FLAG set Out\n");
132 if (flags & DM_SKIP_BDGET_FLAG)
133 aprint_debug("dbg_flags: DM_SKIP_BDGET_FLAG set In\n");
135 if (flags & DM_SKIP_LOCKFS_FLAG)
136 aprint_debug("dbg_flags: DM_SKIP_LOCKFS_FLAG set In\n");
138 if (flags & DM_NOFLUSH_FLAG)
139 aprint_debug("dbg_flags: DM_NOFLUSH_FLAG set In\n");
144 * Get version ioctl call I do it as default therefore this
145 * function is unused now.
148 dm_get_version_ioctl(prop_dictionary_t dm_dict)
153 * Get list of all available targets from global
154 * target list and sent them back to libdevmapper.
157 dm_list_versions_ioctl(prop_dictionary_t dm_dict)
159 prop_array_t target_list;
164 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
166 dm_dbg_print_flags(flags);
167 target_list = dm_target_prop_list();
169 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, target_list);
170 prop_object_release(target_list);
175 * Create in-kernel entry for device. Device attributes such as name, uuid are
176 * taken from proplib dictionary.
180 dm_dev_create_ioctl(prop_dictionary_t dm_dict)
183 const char *name, *uuid;
191 /* Get needed values from dictionary. */
192 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
193 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
194 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
196 dm_dbg_print_flags(flags);
198 /* Lookup name and uuid if device already exist quit. */
199 if ((dmv = dm_dev_lookup(name, uuid, -1)) != NULL) {
200 DM_ADD_FLAG(flags, DM_EXISTS_FLAG); /* Device already exists */
205 r = dm_dev_create(&dmv, name, uuid, flags);
207 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
208 DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
209 DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
215 * Get list of created device-mapper devices fromglobal list and
220 * <key>cmd_data</key>
224 * <string>...</string>
227 * <integer>...</integer>
233 dm_dev_list_ioctl(prop_dictionary_t dm_dict)
235 prop_array_t dev_list;
241 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
243 dm_dbg_print_flags(flags);
245 dev_list = dm_dev_prop_list();
247 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, dev_list);
248 prop_object_release(dev_list);
253 * Rename selected devices old name is in struct dm_ioctl.
254 * newname is taken from dictionary
256 * <key>cmd_data</key>
258 * <string>...</string>
262 dm_dev_rename_ioctl(prop_dictionary_t dm_dict)
265 prop_array_t cmd_array;
268 const char *name, *uuid, *n_name;
269 uint32_t flags, minor;
275 /* Get needed values from dictionary. */
276 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
277 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
278 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
279 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
281 dm_dbg_print_flags(flags);
283 cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
285 prop_array_get_cstring_nocopy(cmd_array, 0, &n_name);
287 if (strlen(n_name) + 1 > DM_NAME_LEN)
290 if ((dmv = dm_dev_rem(NULL, name, uuid, minor)) == NULL) {
291 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
294 /* change device name */
296 * XXX How to deal with this change, name only used in
297 * dm_dev_routines, should I add dm_dev_change_name which will run
298 * under the dm_dev_list mutex ?
300 strlcpy(dmv->name, n_name, DM_NAME_LEN);
302 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
303 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
304 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
310 * XXX: the rename is not yet implemented. The main complication
311 * here is devfs. We'd probably need a new function, rename_dev()
312 * that would trigger a node rename in devfs.
314 kprintf("dm_dev_rename_ioctl called, but not implemented!\n");
322 dm_dev_remove_ioctl(prop_dictionary_t dm_dict)
325 const char *name, *uuid;
326 uint32_t flags, minor, is_open;
332 /* Get needed values from dictionary. */
333 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
334 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
335 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
336 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
338 dm_dbg_print_flags(flags);
340 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
341 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
345 is_open = dmv->is_open;
353 * This will call dm_detach routine which will actually remove
356 return dm_dev_remove(dmv);
360 * Try to remove all devices
363 dm_dev_remove_all_ioctl(prop_dictionary_t dm_dict)
367 /* Get needed values from dictionary. */
368 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
370 dm_dbg_print_flags(flags);
372 /* Gently remove all devices, if possible */
373 return dm_dev_remove_all(1);
377 * Return actual state of device to libdevmapper.
380 dm_dev_status_ioctl(prop_dictionary_t dm_dict)
383 const char *name, *uuid;
384 uint32_t flags, j, minor;
391 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
392 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
393 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
394 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
396 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
397 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
400 dm_dbg_print_flags(dmv->flags);
402 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
403 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
404 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
406 if (dmv->flags & DM_SUSPEND_FLAG)
407 DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
410 * Add status flags for tables I have to check both active and
413 if ((j = dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE))) {
414 DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
416 DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
418 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_TARGET_COUNT, j);
420 if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
421 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
423 DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
430 * Set only flag to suggest that device is suspended. This call is
431 * not supported in NetBSD.
435 dm_dev_suspend_ioctl(prop_dictionary_t dm_dict)
438 const char *name, *uuid;
439 uint32_t flags, minor;
445 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
446 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
447 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
448 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
450 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
451 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
454 atomic_set_int(&dmv->flags, DM_SUSPEND_FLAG);
456 dm_dbg_print_flags(dmv->flags);
458 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
459 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, dmv->flags);
460 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
464 /* Add flags to dictionary flag after dmv -> dict copy */
465 DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
470 * Simulate Linux behaviour better and switch tables here and not in
471 * dm_table_load_ioctl.
474 dm_dev_resume_ioctl(prop_dictionary_t dm_dict)
477 const char *name, *uuid;
478 uint32_t flags, minor;
485 * char *xml; xml = prop_dictionary_externalize(dm_dict);
486 * printf("%s\n",xml);
489 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
490 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
491 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
492 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
494 /* Remove device from global device list */
495 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
496 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
499 atomic_clear_int(&dmv->flags, (DM_SUSPEND_FLAG | DM_INACTIVE_PRESENT_FLAG));
500 atomic_set_int(&dmv->flags, DM_ACTIVE_PRESENT_FLAG);
502 dm_table_switch_tables(&dmv->table_head);
504 DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
506 dmsetdiskinfo(dmv->diskp, &dmv->table_head);
508 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
509 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
510 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
514 /* Destroy inactive table after resume. */
515 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
520 * Table management routines
521 * lvm2tools doens't send name/uuid to kernel with table
522 * for lookup I have to use minor number.
526 * Remove inactive table from device. Routines which work's with inactive tables
527 * doesn't need to synchronise with dmstrategy. They can synchronise themselves with mutex?.
531 dm_table_clear_ioctl(prop_dictionary_t dm_dict)
534 const char *name, *uuid;
535 uint32_t flags, minor;
543 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
544 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
545 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
546 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
548 aprint_debug("Clearing inactive table from device: %s--%s\n",
551 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
552 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
555 /* Select unused table */
556 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
558 atomic_clear_int(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);
565 * Get list of physical devices for active table.
566 * Get dev_t from pdev vnode and insert it into cmd_array.
568 * XXX. This function is called from lvm2tools to get information
569 * about physical devices, too e.g. during vgcreate.
572 dm_table_deps_ioctl(prop_dictionary_t dm_dict)
576 dm_table_entry_t *table_en;
578 prop_array_t cmd_array;
579 const char *name, *uuid;
580 uint32_t flags, minor;
589 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
590 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
591 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
592 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
594 /* create array for dev_t's */
595 cmd_array = prop_array_create();
597 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
598 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
601 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
602 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_NAME, dmv->name);
603 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
605 aprint_debug("Getting table deps for device: %s\n", dmv->name);
608 * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
611 if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
612 table_type = DM_TABLE_INACTIVE;
614 table_type = DM_TABLE_ACTIVE;
616 tbl = dm_table_get_entry(&dmv->table_head, table_type);
618 SLIST_FOREACH(table_en, tbl, next)
619 table_en->target->deps(table_en, cmd_array);
621 dm_table_release(&dmv->table_head, table_type);
624 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
625 prop_object_release(cmd_array);
630 * Load new table/tables to device.
631 * Call apropriate target init routine open all physical pdev's and
632 * link them to device. For other targets mirror, strip, snapshot
633 * etc. also add dependency devices to upcalls list.
635 * Load table to inactive slot table are switched in dm_device_resume_ioctl.
636 * This simulates Linux behaviour better there should not be any difference.
640 dm_table_load_ioctl(prop_dictionary_t dm_dict)
643 dm_table_entry_t *table_en, *last_table;
647 prop_object_iterator_t iter;
648 prop_array_t cmd_array;
649 prop_dictionary_t target_dict;
651 const char *name, *uuid, *type;
653 uint32_t flags, ret, minor;
666 * char *xml; xml = prop_dictionary_externalize(dm_dict);
667 * printf("%s\n",xml);
670 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
671 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
672 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
673 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
675 cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
676 iter = prop_array_iterator(cmd_array);
677 dm_dbg_print_flags(flags);
679 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
680 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
683 aprint_debug("Loading table to device: %s--%d\n", name,
684 dmv->table_head.cur_active_table);
687 * I have to check if this table slot is not used by another table list.
688 * if it is used I should free them.
690 if (dmv->flags & DM_INACTIVE_PRESENT_FLAG)
691 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
693 dm_dbg_print_flags(dmv->flags);
694 tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_INACTIVE);
696 aprint_debug("dmv->name = %s\n", dmv->name);
698 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
700 while ((target_dict = prop_object_iterator_next(iter)) != NULL) {
701 prop_dictionary_get_cstring_nocopy(target_dict,
702 DM_TABLE_TYPE, &type);
704 * If we want to deny table with 2 or more different
705 * target we should do it here
707 if (((target = dm_target_lookup(type)) == NULL) &&
708 ((target = dm_target_autoload(type)) == NULL)) {
709 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
713 if ((table_en = kmalloc(sizeof(dm_table_entry_t),
714 M_DM, M_WAITOK)) == NULL) {
715 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
717 dm_target_unbusy(target);
720 prop_dictionary_get_uint64(target_dict, DM_TABLE_START,
722 prop_dictionary_get_uint64(target_dict, DM_TABLE_LENGTH,
725 aprint_debug("dm_ioctl.c... table_en->start = %ju, "
726 "table_en->length = %ju\n",
727 (uintmax_t)table_en->start,
728 (uintmax_t)table_en->length);
730 table_en->target = target;
731 table_en->dm_dev = dmv;
732 table_en->target_config = NULL;
735 * There is a parameter string after dm_target_spec
736 * structure which points to /dev/wd0a 284 part of
737 * table. String str points to this text. This can be
738 * null and therefore it should be checked before we try to
741 prop_dictionary_get_cstring(target_dict,
742 DM_TABLE_PARAMS, &str);
744 if (SLIST_EMPTY(tbl))
745 /* insert this table to head */
746 SLIST_INSERT_HEAD(tbl, table_en, next);
748 SLIST_INSERT_AFTER(last_table, table_en, next);
751 * Params string is different for every target,
752 * therfore I have to pass it to target init
753 * routine and parse parameters there.
755 aprint_debug("DM: str passed in is: %s", str);
756 if ((ret = target->init(dmv, &table_en->target_config,
759 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
760 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
764 dm_target_unbusy(target);
767 last_table = table_en;
770 prop_object_iterator_release(iter);
772 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
773 atomic_set_int(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);
775 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
779 dmsetdiskinfo(dmv->diskp, &dmv->table_head);
784 * Get description of all tables loaded to device from kernel
785 * and send it to libdevmapper.
787 * Output dictionary for every table:
789 * <key>cmd_data</key>
793 * <string>...</string>
796 * <integer>...</integer>
799 * <integer>...</integer>
802 * <string>...</string>
808 dm_table_status_ioctl(prop_dictionary_t dm_dict)
812 dm_table_entry_t *table_en;
814 prop_array_t cmd_array;
815 prop_dictionary_t target_dict;
819 const char *name, *uuid;
830 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
831 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
832 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
833 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
835 cmd_array = prop_array_create();
837 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
838 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
842 * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
845 if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
846 table_type = DM_TABLE_INACTIVE;
848 table_type = DM_TABLE_ACTIVE;
850 if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE))
851 DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
853 DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
855 if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
856 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
858 DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
862 if (dmv->flags & DM_SUSPEND_FLAG)
863 DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
865 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
867 aprint_debug("Status of device tables: %s--%d\n",
868 name, dmv->table_head.cur_active_table);
870 tbl = dm_table_get_entry(&dmv->table_head, table_type);
872 SLIST_FOREACH(table_en, tbl, next) {
873 target_dict = prop_dictionary_create();
874 aprint_debug("%016" PRIu64 ", length %016" PRIu64
875 ", target %s\n", table_en->start, table_en->length,
876 table_en->target->name);
878 prop_dictionary_set_uint64(target_dict, DM_TABLE_START,
880 prop_dictionary_set_uint64(target_dict, DM_TABLE_LENGTH,
883 prop_dictionary_set_cstring(target_dict, DM_TABLE_TYPE,
884 table_en->target->name);
886 /* dm_table_get_cur_actv.table ?? */
887 prop_dictionary_set_int32(target_dict, DM_TABLE_STAT,
888 dmv->table_head.cur_active_table);
890 if (flags & DM_STATUS_TABLE_FLAG) {
891 params = table_en->target->status
892 (table_en->target_config);
894 if (params != NULL) {
895 prop_dictionary_set_cstring(target_dict,
896 DM_TABLE_PARAMS, params);
901 prop_array_add(cmd_array, target_dict);
902 prop_object_release(target_dict);
905 dm_table_release(&dmv->table_head, table_type);
908 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
909 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
910 prop_object_release(cmd_array);
916 dm_message_ioctl(prop_dictionary_t dm_dict)
919 dm_table_entry_t *table_en;
921 const char *name, *uuid;
922 uint32_t flags, minor;
923 uint64_t table_start, table_end, sector;
931 /* Get needed values from dictionary. */
932 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
933 prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
934 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
935 prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
936 prop_dictionary_get_uint64(dm_dict, DM_MESSAGE_SECTOR, §or);
938 dm_dbg_print_flags(flags);
940 if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
941 DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
945 /* Get message string */
946 prop_dictionary_get_cstring(dm_dict, DM_MESSAGE_STR, &msg);
948 tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_ACTIVE);
953 if (!SLIST_EMPTY(tbl)) {
954 table_en = SLIST_FIRST(tbl);
958 SLIST_FOREACH(table_en, tbl, next) {
959 table_start = table_en->start;
960 table_end = table_start + (table_en->length);
962 if ((sector >= table_start) && (sector < table_end)) {
970 if (table_en->target->message != NULL)
971 ret = table_en->target->message(table_en, msg);
974 dm_table_release(&dmv->table_head, DM_TABLE_ACTIVE);
984 * For every call I have to set kernel driver version.
985 * Because I can have commands supported only in other
986 * newer/later version. This routine is called for every
990 dm_check_version(prop_dictionary_t dm_dict)
996 ver = prop_dictionary_get(dm_dict, DM_IOCTL_VERSION);
998 for (i = 0; i < 3; i++)
999 prop_array_get_uint32(ver, i, &dm_version[i]);
1001 if (DM_VERSION_MAJOR != dm_version[0] || DM_VERSION_MINOR < dm_version[1]) {
1002 aprint_debug("libdevmapper/kernel version mismatch "
1003 "kernel: %d.%d.%d libdevmapper: %d.%d.%d\n",
1004 DM_VERSION_MAJOR, DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL,
1005 dm_version[0], dm_version[1], dm_version[2]);
1009 prop_array_set_uint32(ver, 0, DM_VERSION_MAJOR);
1010 prop_array_set_uint32(ver, 1, DM_VERSION_MINOR);
1011 prop_array_set_uint32(ver, 2, DM_VERSION_PATCHLEVEL);
1013 prop_dictionary_set(dm_dict, DM_IOCTL_VERSION, ver);