1 /* $NetBSD: libdm-nbsd-iface.c,v 1.7 2010/03/12 16:24:40 haad Exp $ */
4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
6 * Copyright (C) 2008 Adam Hamsik. All rights reserved.
7 * Copyright (C) 2010 Alex Hornung. All rights reserved.
9 * This file is part of the device-mapper userspace tools.
11 * This copyrighted material is made available to anyone wishing to use,
12 * modify, copy, or redistribute it subject to the terms and conditions
13 * of the GNU Lesser General Public License v.2.1.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "libdm-targets.h"
23 #include "libdm-common.h"
24 #include "libdm-netbsd.h"
26 #include <sys/param.h>
27 #include <sys/ioctl.h>
28 #include <sys/sysctl.h>
35 #include <netbsd-dm.h>
39 * Ensure build compatibility.
40 * The hard-coded versions here are the highest present
41 * in the _cmd_data arrays.
44 #if !((DM_VERSION_MAJOR == 1 && DM_VERSION_MINOR >= 0) || \
45 (DM_VERSION_MAJOR == 4 && DM_VERSION_MINOR >= 0))
46 #error The version of dm-ioctl.h included is incompatible.
49 /* dm major version no for running kernel */
50 static unsigned _dm_version_minor = 0;
51 static unsigned _dm_version_patchlevel = 0;
53 static int _control_fd = -1;
54 static int _version_checked = 0;
55 static int _version_ok = 1;
56 static unsigned _ioctl_buffer_double_factor = 0;
61 * XXX Remove this structure and write another own one
62 * I don't understand why ioctl calls has different
63 * names then dm task type
65 static struct cmd_data _cmd_data_v4[] = {
66 {"create", DM_DEV_CREATE, {4, 0, 0}},
67 {"reload", DM_TABLE_LOAD, {4, 0, 0}}, /* DM_DEVICE_RELOAD */
68 {"remove", DM_DEV_REMOVE, {4, 0, 0}},
69 {"remove_all", DM_REMOVE_ALL, {4, 0, 0}},
70 {"suspend", DM_DEV_SUSPEND, {4, 0, 0}},
71 {"resume", DM_DEV_SUSPEND, {4, 0, 0}},
72 {"info", DM_DEV_STATUS, {4, 0, 0}},
73 {"deps", DM_TABLE_DEPS, {4, 0, 0}}, /* DM_DEVICE_DEPS */
74 {"rename", DM_DEV_RENAME, {4, 0, 0}},
75 {"version", DM_VERSION, {4, 0, 0}},
76 {"status", DM_TABLE_STATUS, {4, 0, 0}},
77 {"table", DM_TABLE_STATUS, {4, 0, 0}}, /* DM_DEVICE_TABLE */
78 {"waitevent", DM_DEV_WAIT, {4, 0, 0}},
79 {"names", DM_LIST_DEVICES, {4, 0, 0}},
80 {"clear", DM_TABLE_CLEAR, {4, 0, 0}},
81 {"mknodes", DM_DEV_STATUS, {4, 0, 0}},
82 #ifdef DM_LIST_VERSIONS
83 {"targets", DM_LIST_VERSIONS, {4, 1, 0}},
86 {"message", DM_TARGET_MSG, {4, 2, 0}},
88 #ifdef DM_DEV_SET_GEOMETRY
89 {"setgeometry", DM_DEV_SET_GEOMETRY, {4, 6, 0}},
95 * In NetBSD we use sysctl to get kernel drivers info. control device
96 * has predefined minor number 0 and major number = char major number
97 * of dm driver. First slot is therefore ocupied with control device
98 * and minor device starts from 1;
101 static int _control_device_number(uint32_t *major, uint32_t *minor)
104 nbsd_get_dm_major(major, DM_CHAR_MAJOR);
112 * Returns 1 if exists; 0 if it doesn't; -1 if it's wrong
114 static int _control_exists(const char *control, uint32_t major, uint32_t minor)
118 if (stat(control, &buf) < 0) {
120 log_sys_error("stat", control);
124 if (!S_ISCHR(buf.st_mode)) {
125 log_verbose("%s: Wrong inode type", control);
126 if (!unlink(control))
128 log_sys_error("unlink", control);
132 if (major && buf.st_rdev != MKDEV(major, minor)) {
133 log_verbose("%s: Wrong device number: (%u, %u) instead of "
135 MAJOR(buf.st_mode), MINOR(buf.st_mode),
137 if (!unlink(control))
139 log_sys_error("unlink", control);
146 static int _create_control(const char *control, uint32_t major, uint32_t minor)
154 old_umask = umask(0022);
155 ret = dm_create_dir(dm_dir());
161 log_verbose("Creating device %s (%u, %u)", control, major, minor);
163 if (mknod(control, S_IFCHR | S_IRUSR | S_IWUSR,
164 MKDEV(major, minor)) < 0) {
165 log_sys_error("mknod", control);
173 /* Check if major is device-mapper block device major number */
174 int dm_is_dm_major(uint32_t major)
178 nbsd_get_dm_major(&dm_major, DM_BLOCK_MAJOR);
180 if (major == dm_major)
186 /* Open control device if doesn't exist create it. */
187 static int _open_control(void)
189 char control[PATH_MAX];
190 uint32_t major = 0, minor = 0;
192 if (_control_fd != -1)
195 snprintf(control, sizeof(control), "%s/control", dm_dir());
197 if (!_control_device_number(&major, &minor))
198 log_error("Is device-mapper driver missing from kernel?");
200 if ((_control_fd = open(control, O_RDWR)) < 0) {
201 log_sys_error("open", control);
208 log_error("Failure to communicate with kernel device-mapper driver.");
213 * Destroy dm task structure there are some dynamically alocated values there.
214 * name, uuid, head, tail list.
216 void dm_task_destroy(struct dm_task *dmt)
218 struct target *t, *n;
220 for (t = dmt->head; t; t = n) {
228 dm_free(dmt->dev_name);
231 dm_free(dmt->newname);
234 dm_free(dmt->message);
237 dm_free(dmt->dmi.v4);
246 /* Get kernel driver version from dm_ioctl structure. */
247 int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size)
256 v = dmt->dmi.v4->version;
257 snprintf(version, size, "%u.%u.%u", v[0], v[1], v[2]);
258 _dm_version_minor = v[1];
259 _dm_version_patchlevel = v[2];
264 /* Get kernel driver protocol version and comapre it with library version. */
265 static int _check_version(char *version, size_t size)
267 struct dm_task *task;
270 if (!(task = dm_task_create(DM_DEVICE_VERSION))) {
271 log_error("Failed to get device-mapper version");
276 r = dm_task_run(task);
277 dm_task_get_driver_version(task, version, size);
278 dm_task_destroy(task);
284 * Find out device-mapper's major version number the first time
285 * this is called and whether or not we support it.
287 int dm_check_version(void)
291 if (_version_checked)
294 _version_checked = 1;
296 if (_check_version(dmversion, sizeof(dmversion)))
303 int dm_cookie_supported(void)
308 /* Get next target(table description) from list pointed by dmt->head. */
309 void *dm_get_next_target(struct dm_task *dmt, void *next,
310 uint64_t *start, uint64_t *length,
311 char **target_type, char **params)
313 struct target *t = (struct target *) next;
323 *target_type = t->type;
329 /* Unmarshall the target info returned from a status call */
330 static int _unmarshal_status(struct dm_task *dmt, struct dm_ioctl *dmi)
332 char *outbuf = (char *) dmi + dmi->data_start;
333 char *outptr = outbuf;
335 struct dm_target_spec *spec;
337 for (i = 0; i < dmi->target_count; i++) {
338 spec = (struct dm_target_spec *) outptr;
339 if (!dm_task_add_target(dmt, spec->sector_start,
342 outptr + sizeof(*spec))) {
346 outptr = outbuf + spec->next;
353 get_dev_name(char *d_name, uint32_t d_major, uint32_t d_minor)
355 static char d_buf[MAXPATHLEN];
363 dev_dir = opendir("/dev");
365 while ((dire = readdir(dev_dir)) != NULL) {
367 if (strstr(dire->d_name, d_name) == NULL)
370 snprintf(d_buf, MAXPATHLEN, "/dev/%s", dire->d_name);
372 if ((err = stat(d_buf, &st)) < 0)
373 printf("stat failed with %d", err);
375 if (st.st_mode & S_IFBLK){
376 if ((major(st.st_rdev) == d_major) && (minor(st.st_rdev) == d_minor)) {
377 strncpy(d_buf, dire->d_name, strlen(dire->d_name) + 1);
383 memset(d_buf, '0', sizeof(d_buf));
386 (void)closedir(dev_dir);
392 * @dev_major is major number of char device
394 * I have to find it's block device number and lookup dev in
395 * device database to find device path.
399 int dm_format_dev(char *buf, int bufsize, uint32_t dev_major,
403 uint32_t major, dm_major;
409 dev = MKDEV(dev_major,dev_minor);
412 name = devname(dev,mode);
414 r = snprintf(buf, (size_t) bufsize, "/dev/%s",name);
416 if (r < 0 || r > bufsize - 1 || name == NULL)
422 /* Fill info from dm_ioctl structure. Look at DM_EXISTS_FLAG*/
423 int dm_task_get_info(struct dm_task *dmt, struct dm_info *info)
428 memset(info, 0, sizeof(*info));
430 info->exists = dmt->dmi.v4->flags & DM_EXISTS_FLAG ? 1 : 0;
434 info->suspended = dmt->dmi.v4->flags & DM_SUSPEND_FLAG ? 1 : 0;
435 info->read_only = dmt->dmi.v4->flags & DM_READONLY_FLAG ? 1 : 0;
436 info->live_table = dmt->dmi.v4->flags & DM_ACTIVE_PRESENT_FLAG ? 1 : 0;
437 info->inactive_table = dmt->dmi.v4->flags & DM_INACTIVE_PRESENT_FLAG ?
439 info->target_count = dmt->dmi.v4->target_count;
440 info->open_count = dmt->dmi.v4->open_count;
441 info->event_nr = dmt->dmi.v4->event_nr;
443 nbsd_get_dm_major(&info->major, DM_BLOCK_MAJOR); /* get netbsd dm device major number */
444 info->minor = MINOR(dmt->dmi.v4->dev);
449 /* Unsupported on NetBSD */
450 uint32_t dm_task_get_read_ahead(const struct dm_task *dmt, uint32_t *read_ahead)
452 *read_ahead = DM_READ_AHEAD_NONE;
456 const char *dm_task_get_name(const struct dm_task *dmt)
459 return (dmt->dmi.v4->name);
462 const char *dm_task_get_uuid(const struct dm_task *dmt)
465 return (dmt->dmi.v4->uuid);
468 struct dm_deps *dm_task_get_deps(struct dm_task *dmt)
470 return (struct dm_deps *) (((void *) dmt->dmi.v4) +
471 dmt->dmi.v4->data_start);
474 struct dm_names *dm_task_get_names(struct dm_task *dmt)
476 return (struct dm_names *) (((void *) dmt->dmi.v4) +
477 dmt->dmi.v4->data_start);
480 struct dm_versions *dm_task_get_versions(struct dm_task *dmt)
482 return (struct dm_versions *) (((void *) dmt->dmi.v4) +
483 dmt->dmi.v4->data_start);
486 int dm_task_set_ro(struct dm_task *dmt)
492 /* Unsupported on NetBSD */
493 int dm_task_set_read_ahead(struct dm_task *dmt, uint32_t read_ahead,
494 uint32_t read_ahead_flags)
499 int dm_task_suppress_identical_reload(struct dm_task *dmt)
501 dmt->suppress_identical_reload = 1;
505 int dm_task_set_newname(struct dm_task *dmt, const char *newname)
507 if (!(dmt->newname = dm_strdup(newname))) {
508 log_error("dm_task_set_newname: strdup(%s) failed", newname);
515 int dm_task_set_message(struct dm_task *dmt, const char *message)
517 if (!(dmt->message = dm_strdup(message))) {
518 log_error("dm_task_set_message: strdup(%s) failed", message);
525 int dm_task_set_sector(struct dm_task *dmt, uint64_t sector)
527 dmt->sector = sector;
532 /* Unsupported in NetBSD */
533 int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders,
534 const char *heads, const char *sectors, const char *start)
539 int dm_task_no_flush(struct dm_task *dmt)
546 int dm_task_no_open_count(struct dm_task *dmt)
548 dmt->no_open_count = 1;
553 int dm_task_skip_lockfs(struct dm_task *dmt)
555 dmt->skip_lockfs = 1;
560 int dm_task_query_inactive_table(struct dm_task *dmt)
562 dmt->query_inactive_table = 1;
567 int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr)
569 dmt->event_nr = event_nr;
574 /* Allocate one target(table description) entry. */
575 struct target *create_target(uint64_t start, uint64_t len, const char *type,
578 struct target *t = dm_malloc(sizeof(*t));
579 log_verbose("params is at create_target: %s", params);
581 log_error("create_target: malloc(%" PRIsize_t ") failed",
586 memset(t, 0, sizeof(*t));
588 if (!(t->params = dm_strdup(params))) {
589 log_error("create_target: strdup(params) failed");
593 if (!(t->type = dm_strdup(type))) {
594 log_error("create_target: strdup(type) failed");
609 /* Parse given dm task structure to proplib dictionary. */
610 static int _flatten(struct dm_task *dmt, prop_dictionary_t dm_dict)
612 prop_array_t cmd_array;
613 prop_dictionary_t target_spec;
618 char type[DM_MAX_TYPE_NAME];
620 uint32_t major, flags;
623 const int (*version)[3];
626 version = &_cmd_data_v4[dmt->type].version;
628 cmd_array = prop_array_create();
630 for (t = dmt->head; t; t = t->next) {
631 target_spec = prop_dictionary_create();
633 prop_dictionary_set_uint64(target_spec,DM_TABLE_START,t->start);
634 prop_dictionary_set_uint64(target_spec,DM_TABLE_LENGTH,t->length);
636 strlcpy(type,t->type,DM_MAX_TYPE_NAME);
638 prop_dictionary_set_cstring(target_spec,DM_TABLE_TYPE,type);
639 prop_dictionary_set_cstring(target_spec,DM_TABLE_PARAMS,t->params);
641 prop_dictionary_get_cstring(target_spec,
642 DM_TABLE_PARAMS, (char **) &str);
644 prop_array_set(cmd_array,count,target_spec);
646 prop_object_release(target_spec);
652 if (count && (dmt->sector || dmt->message)) {
653 log_error("targets and message are incompatible");
657 if (count && dmt->newname) {
658 log_error("targets and newname are incompatible");
662 if (count && dmt->geometry) {
663 log_error("targets and geometry are incompatible");
667 if (dmt->newname && (dmt->sector || dmt->message)) {
668 log_error("message and newname are incompatible");
672 if (dmt->newname && dmt->geometry) {
673 log_error("geometry and newname are incompatible");
677 if (dmt->geometry && (dmt->sector || dmt->message)) {
678 log_error("geometry and message are incompatible");
682 if (dmt->sector && !dmt->message) {
683 log_error("message is required with sector");
688 len += strlen(dmt->newname) + 1;
691 len += sizeof(struct dm_target_msg) + strlen(dmt->message) + 1;
694 len += strlen(dmt->geometry) + 1;
696 nbsd_dmi_add_version((*version), dm_dict);
698 nbsd_get_dm_major(&major, DM_BLOCK_MAJOR);
700 * Only devices with major which is equal to netbsd dm major
701 * dm devices in NetBSD can't have more majors then one assigned to dm.
703 if (dmt->major != major && dmt->major != -1)
706 if (dmt->minor >= 0) {
707 flags |= DM_PERSISTENT_DEV_FLAG;
709 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmt->minor);
712 /* Set values to dictionary. */
714 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_NAME, dmt->dev_name);
717 prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmt->uuid);
719 if (dmt->type == DM_DEVICE_SUSPEND)
720 flags |= DM_SUSPEND_FLAG;
722 flags |= DM_NOFLUSH_FLAG;
724 flags |= DM_READONLY_FLAG;
725 if (dmt->skip_lockfs)
726 flags |= DM_SKIP_LOCKFS_FLAG;
728 if (dmt->query_inactive_table) {
729 if (_dm_version_minor < 16)
730 log_warn("WARNING: Inactive table query unsupported "
731 "by kernel. It will use live table.");
732 flags |= DM_QUERY_INACTIVE_TABLE_FLAG;
735 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
737 prop_dictionary_set_uint32(dm_dict, DM_IOCTL_EVENT, dmt->event_nr);
740 prop_array_set_cstring(cmd_array, 0, dmt->newname);
742 /* Add array for all COMMAND specific data. */
743 prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
744 prop_object_release(cmd_array);
749 static int _process_mapper_dir(struct dm_task *dmt)
751 struct dirent *dirent;
757 if (!(d = opendir(dir))) {
758 log_sys_error("opendir", dir);
762 while ((dirent = readdir(d))) {
763 if (!strcmp(dirent->d_name, ".") ||
764 !strcmp(dirent->d_name, "..") ||
765 !strcmp(dirent->d_name, "control"))
767 dm_task_set_name(dmt, dirent->d_name);
772 log_sys_error("closedir", dir);
777 /* Get list of all devices. */
778 static int _process_all_v4(struct dm_task *dmt)
780 struct dm_task *task;
781 struct dm_names *names;
785 if (!(task = dm_task_create(DM_DEVICE_LIST)))
788 if (!dm_task_run(task)) {
793 if (!(names = dm_task_get_names(task))) {
802 names = (void *) names + next;
803 if (!dm_task_set_name(dmt, names->name)) {
807 if (!dm_task_run(dmt))
813 dm_task_destroy(task);
817 static int _mknodes_v4(struct dm_task *dmt)
819 (void) _process_mapper_dir(dmt);
821 return _process_all_v4(dmt);
824 /* Create new device and load table to it. */
825 static int _create_and_load_v4(struct dm_task *dmt)
827 struct dm_task *task;
830 log_verbose("create and load called");
832 /* Use new task struct to create the device */
833 if (!(task = dm_task_create(DM_DEVICE_CREATE))) {
834 log_error("Failed to create device-mapper task struct");
838 /* Copy across relevant fields */
839 if (dmt->dev_name && !dm_task_set_name(task, dmt->dev_name)) {
840 dm_task_destroy(task);
844 if (dmt->uuid && !dm_task_set_uuid(task, dmt->uuid)) {
845 dm_task_destroy(task);
849 task->major = dmt->major;
850 task->minor = dmt->minor;
851 task->uid = dmt->uid;
852 task->gid = dmt->gid;
853 task->mode = dmt->mode;
855 r = dm_task_run(task);
856 dm_task_destroy(task);
860 /* Next load the table */
861 if (!(task = dm_task_create(DM_DEVICE_RELOAD))) {
862 log_error("Failed to create device-mapper task struct");
866 /* Copy across relevant fields */
867 if (dmt->dev_name && !dm_task_set_name(task, dmt->dev_name)) {
868 dm_task_destroy(task);
872 task->read_only = dmt->read_only;
873 task->head = dmt->head;
874 task->tail = dmt->tail;
876 r = dm_task_run(task);
880 dm_task_destroy(task);
884 /* Use the original structure last so the info will be correct */
885 dmt->type = DM_DEVICE_RESUME;
889 r = dm_task_run(dmt);
895 dmt->type = DM_DEVICE_REMOVE;
899 if (!dm_task_run(dmt))
900 log_error("Failed to revert device creation.");
905 uint64_t dm_task_get_existing_table_size(struct dm_task *dmt)
907 return dmt->existing_table_size;
910 static int _reload_with_suppression_v4(struct dm_task *dmt)
912 struct dm_task *task;
913 struct target *t1, *t2;
916 /* New task to get existing table information */
917 if (!(task = dm_task_create(DM_DEVICE_TABLE))) {
918 log_error("Failed to create device-mapper task struct");
922 /* Copy across relevant fields */
923 if (dmt->dev_name && !dm_task_set_name(task, dmt->dev_name)) {
924 dm_task_destroy(task);
928 if (dmt->uuid && !dm_task_set_uuid(task, dmt->uuid)) {
929 dm_task_destroy(task);
933 task->major = dmt->major;
934 task->minor = dmt->minor;
936 r = dm_task_run(task);
939 dm_task_destroy(task);
943 /* Store existing table size */
945 while (t2 && t2->next)
947 dmt->existing_table_size = t2 ? t2->start + t2->length : 0;
949 if ((task->dmi.v4->flags & DM_READONLY_FLAG) ? 1 : 0 != dmt->read_only)
956 while (t2->params[strlen(t2->params) - 1] == ' ')
957 t2->params[strlen(t2->params) - 1] = '\0';
958 if ((t1->start != t2->start) ||
959 (t1->length != t2->length) ||
960 (strcmp(t1->type, t2->type)) ||
961 (strcmp(t1->params, t2->params)))
968 dmt->dmi.v4 = task->dmi.v4;
970 dm_task_destroy(task);
975 dm_task_destroy(task);
977 /* Now do the original reload */
978 dmt->suppress_identical_reload = 0;
979 r = dm_task_run(dmt);
985 * This function is heart of NetBSD libdevmapper-> device-mapper kernel protocol
986 * It creates proplib_dictionary from dm task structure and sends it to NetBSD
987 * kernel driver. After succesfull ioctl it create dmi structure from returned
988 * proplib dictionary. This way I keep number of changes in NetBSD version of
989 * libdevmapper as small as posible.
991 static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command)
993 struct dm_ioctl *dmi;
994 prop_dictionary_t dm_dict_in, dm_dict_out;
1000 dm_dict_in = prop_dictionary_create(); /* Dictionary send to kernel */
1001 dm_dict_out = prop_dictionary_create(); /* Dictionary received from kernel */
1003 /* Set command name to dictionary */
1004 prop_dictionary_set_cstring(dm_dict_in, DM_IOCTL_COMMAND,
1005 _cmd_data_v4[dmt->type].name);
1007 /* Parse dmi from libdevmapper to dictionary */
1008 if (_flatten(dmt, dm_dict_in) < 0)
1011 prop_dictionary_get_uint32(dm_dict_in, DM_IOCTL_FLAGS, &flags);
1013 if (dmt->type == DM_DEVICE_TABLE)
1014 flags |= DM_STATUS_TABLE_FLAG;
1016 if (dmt->no_open_count)
1017 flags |= DM_SKIP_BDGET_FLAG;
1019 flags |= DM_EXISTS_FLAG;
1021 /* Set flags to dictionary. */
1022 prop_dictionary_set_uint32(dm_dict_in,DM_IOCTL_FLAGS,flags);
1023 log_very_verbose("Ioctl type %s --- flags %d",_cmd_data_v4[dmt->type].name,flags);
1024 //printf("name %s, major %d minor %d\n uuid %s\n",
1025 //dm_task_get_name(dmt), dmt->minor, dmt->major, dm_task_get_uuid(dmt));
1026 /* Send dictionary to kernel and wait for reply. */
1028 if (prop_dictionary_sendrecv_ioctl(dm_dict_in,_control_fd,
1029 NETBSD_DM_IOCTL,&dm_dict_out) != 0) {
1031 if (errno == ENOENT &&
1032 ((dmt->type == DM_DEVICE_INFO) ||
1033 (dmt->type == DM_DEVICE_MKNODES) ||
1034 (dmt->type == DM_DEVICE_STATUS))) {
1037 * Linux version doesn't fail when ENOENT is returned
1038 * for nonexisting device after info, deps, mknodes call.
1039 * It returns dmi sent to kernel with DM_EXISTS_FLAG = 0;
1042 dmi = nbsd_dm_dict_to_dmi(dm_dict_in,_cmd_data_v4[dmt->type].cmd);
1044 dmi->flags &= ~DM_EXISTS_FLAG;
1046 prop_object_release(dm_dict_in);
1047 prop_object_release(dm_dict_out);
1051 log_error("ioctl %s call failed: %s\n",
1052 _cmd_data_v4[dmt->type].name, strerror(errno));
1054 prop_object_release(dm_dict_in);
1055 prop_object_release(dm_dict_out);
1061 /* Parse kernel dictionary to dmi structure and return it to libdevmapper. */
1062 dmi = nbsd_dm_dict_to_dmi(dm_dict_out,_cmd_data_v4[dmt->type].cmd);
1064 prop_object_release(dm_dict_in);
1065 prop_object_release(dm_dict_out);
1072 /* Create new edvice nodes in mapper/ dir. */
1073 void dm_task_update_nodes(void)
1078 static void _dm_rename_kern(struct dm_task *dmt)
1080 prop_dictionary_t dm_dict_in, dm_dict_out;
1082 dm_dict_in = prop_dictionary_create(); /* Dictionary send to kernel */
1084 /* Set command name to dictionary */
1085 prop_dictionary_set_cstring(dm_dict_in, DM_IOCTL_COMMAND,
1087 prop_dictionary_set_cstring(dm_dict_in, "dev_name", dmt->dev_name);
1088 prop_dictionary_set_cstring(dm_dict_in, "new_name", dmt->newname);
1090 /* Set flags to dictionary. */
1091 prop_dictionary_set_uint32(dm_dict_in,DM_IOCTL_FLAGS,0);
1093 if (prop_dictionary_sendrecv_ioctl(dm_dict_in,_control_fd,
1094 NETBSD_DM_IOCTL,&dm_dict_out) != 0) {
1095 log_error("rename failed");
1099 /* Run dm command which is descirbed in dm_task structure. */
1100 int dm_task_run(struct dm_task *dmt)
1102 struct dm_ioctl *dmi;
1105 if ((unsigned) dmt->type >=
1106 (sizeof(_cmd_data_v4) / sizeof(*_cmd_data_v4))) {
1107 log_error("Internal error: unknown device-mapper task %d",
1112 command = _cmd_data_v4[dmt->type].cmd;
1114 /* Old-style creation had a table supplied */
1115 if (dmt->type == DM_DEVICE_CREATE && dmt->head)
1116 return _create_and_load_v4(dmt);
1118 if (dmt->type == DM_DEVICE_MKNODES && !dmt->dev_name &&
1119 !dmt->uuid && dmt->major <= 0)
1120 return _mknodes_v4(dmt);
1122 if ((dmt->type == DM_DEVICE_RELOAD) && dmt->suppress_identical_reload)
1123 return _reload_with_suppression_v4(dmt);
1125 if (!_open_control())
1128 if (!(dmi = _do_dm_ioctl(dmt, command)))
1131 switch (dmt->type) {
1132 case DM_DEVICE_CREATE:
1133 log_verbose("create dmt->dev_name = %s", dmt->dev_name);
1134 /* kernel takes care of this */
1137 case DM_DEVICE_REMOVE:
1138 log_verbose("remove dmt->dev_name = %s", dmt->dev_name);
1139 /* kernel takes care of this */
1142 case DM_DEVICE_RENAME:
1143 /* FIXME Kernel needs to fill in dmi->name */
1144 log_verbose("rename dmt->dev_name = %s", dmt->dev_name);
1145 _dm_rename_kern(dmt);
1148 case DM_DEVICE_RESUME:
1149 /* FIXME Kernel needs to fill in dmi->name */
1150 set_dev_node_read_ahead(dmt->dev_name, dmt->read_ahead,
1151 dmt->read_ahead_flags);
1154 case DM_DEVICE_MKNODES:
1155 log_verbose("mknodes dmt->dev_name = %s", dmt->dev_name);
1158 case DM_DEVICE_STATUS:
1159 case DM_DEVICE_TABLE:
1160 case DM_DEVICE_WAITEVENT:
1161 if (!_unmarshal_status(dmt, dmi))
1166 /* Was structure reused? */
1168 dm_free(dmt->dmi.v4);
1178 void dm_lib_release(void)
1180 if (_control_fd != -1) {
1187 void dm_lib_exit(void)
1192 _version_checked = 0;