2 * snippets copied from device-mapper dmsetup.c
3 * Copyright (c) 2004, 2005 Christophe Varoqui
4 * Copyright (c) 2005 Kiyoshi Ueda, NEC
5 * Copyright (c) 2005 Patrick Caulfield, Redhat
11 #include <libdevmapper.h>
21 #include "devmapper.h"
25 #include "log_pthread.h"
26 #include <sys/types.h>
30 #define LOOPS_PER_SEC 5
32 #define UUID_PREFIX "mpath-"
33 #define UUID_PREFIX_LEN 6
35 #ifndef LIBDM_API_COOKIE
36 static inline int dm_task_set_cookie(struct dm_task *dmt, uint32_t *c, int a)
41 void udev_wait(unsigned int c)
45 void udev_set_sync_support(int c)
49 void udev_wait(unsigned int c)
54 void udev_set_sync_support(int c)
56 dm_udev_set_sync_support(c);
61 dm_write_log (int level, const char *file, int line, const char *f, ...)
69 thres = (conf) ? conf->verbosity : 0;
70 if (thres <= 3 || level > thres)
76 time_t t = time(NULL);
77 struct tm *tb = localtime(&t);
80 strftime(buff, sizeof(buff), "%b %d %H:%M:%S", tb);
81 buff[sizeof(buff)-1] = '\0';
83 fprintf(stdout, "%s | ", buff);
85 fprintf(stdout, "libdevmapper: %s(%i): ", file, line);
86 vfprintf(stdout, f, ap);
87 fprintf(stdout, "\n");
89 condlog(level, "libdevmapper: %s(%i): ", file, line);
90 log_safe(level + 3, f, ap);
99 dm_log_init(&dm_write_log);
100 dm_log_init_verbose(conf ? conf->verbosity + 3 : 0);
108 #ifdef LIBDM_API_COOKIE
109 int minv[3] = {1, 2, 38};
111 int minv[3] = {1, 2, 8};
114 dm_get_library_version(version, sizeof(version));
115 condlog(3, "libdevmapper version %s", version);
116 sscanf(version, "%d.%d.%d ", &v[0], &v[1], &v[2]);
118 if VERSION_GE(v, minv)
120 condlog(0, "libdevmapper version must be >= %d.%.2d.%.2d",
121 minv[0], minv[1], minv[2]);
126 dm_drv_version (unsigned int * version, char * str)
130 struct dm_versions *target;
131 struct dm_versions *last_target;
138 if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS)))
141 dm_task_no_open_count(dmt);
143 if (!dm_task_run(dmt)) {
144 condlog(0, "Can not communicate with kernel DM");
147 target = dm_task_get_versions(dmt);
150 last_target = target;
151 if (!strncmp(str, target->name, strlen(str))) {
155 target = (void *) target + target->next;
156 } while (last_target != target);
159 condlog(0, "DM %s kernel driver not loaded", str);
168 dm_task_destroy(dmt);
175 unsigned int minv[3] = {1, 0, 3};
176 unsigned int version[3] = {0, 0, 0};
177 unsigned int * v = version;
179 if (dm_drv_version(v, TGT_MPATH)) {
180 /* in doubt return not capable */
184 /* test request based multipath capability */
185 condlog(3, "DM multipath kernel driver v%u.%u.%u",
188 if VERSION_GE(v, minv)
191 condlog(0, "DM multipath kernel driver must be >= v%u.%u.%u",
192 minv[0], minv[1], minv[2]);
201 return dm_drv_prereq();
205 dm_simplecmd (int task, const char *name, int no_flush, int need_sync) {
207 int udev_wait_flag = (need_sync && (task == DM_DEVICE_RESUME ||
208 task == DM_DEVICE_REMOVE));
211 if (!(dmt = dm_task_create (task)))
214 if (!dm_task_set_name (dmt, name))
217 dm_task_no_open_count(dmt);
218 dm_task_skip_lockfs(dmt); /* for DM_DEVICE_RESUME */
219 #ifdef LIBDM_API_FLUSH
221 dm_task_no_flush(dmt); /* for DM_DEVICE_SUSPEND/RESUME */
224 if (udev_wait_flag && !dm_task_set_cookie(dmt, &conf->cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
226 r = dm_task_run (dmt);
229 dm_task_destroy (dmt);
234 dm_simplecmd_flush (int task, const char *name, int needsync) {
235 return dm_simplecmd(task, name, 0, needsync);
239 dm_simplecmd_noflush (int task, const char *name) {
240 return dm_simplecmd(task, name, 1, 1);
244 dm_addmap (int task, const char *target, struct multipath *mpp, char * params,
245 int use_uuid, int ro) {
248 char *prefixed_uuid = NULL;
250 if (!(dmt = dm_task_create (task)))
253 if (!dm_task_set_name (dmt, mpp->alias))
256 if (!dm_task_add_target (dmt, 0, mpp->size, target, params))
262 if (use_uuid && strlen(mpp->wwid) > 0){
263 prefixed_uuid = MALLOC(UUID_PREFIX_LEN + strlen(mpp->wwid) + 1);
264 if (!prefixed_uuid) {
265 condlog(0, "cannot create prefixed uuid : %s",
269 sprintf(prefixed_uuid, UUID_PREFIX "%s", mpp->wwid);
270 if (!dm_task_set_uuid(dmt, prefixed_uuid))
274 if (mpp->attribute_flags & (1 << ATTR_MODE) &&
275 !dm_task_set_mode(dmt, mpp->mode))
277 if (mpp->attribute_flags & (1 << ATTR_UID) &&
278 !dm_task_set_uid(dmt, mpp->uid))
280 if (mpp->attribute_flags & (1 << ATTR_GID) &&
281 !dm_task_set_gid(dmt, mpp->gid))
283 condlog(4, "%s: addmap [0 %llu %s %s]", mpp->alias, mpp->size,
286 dm_task_no_open_count(dmt);
288 if (task == DM_DEVICE_CREATE &&
289 !dm_task_set_cookie(dmt, &conf->cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
291 r = dm_task_run (dmt);
298 dm_task_destroy (dmt);
304 _dm_addmap_create (struct multipath *mpp, char * params, int ro) {
306 r = dm_addmap(DM_DEVICE_CREATE, TGT_MPATH, mpp, params, 1, ro);
308 * DM_DEVICE_CREATE is actually DM_DEV_CREATE + DM_TABLE_LOAD.
309 * Failing the second part leaves an empty map. Clean it up.
311 if (!r && dm_map_present(mpp->alias)) {
312 condlog(3, "%s: failed to load map (a path might be in use)",
314 dm_flush_map_nosync(mpp->alias);
323 dm_addmap_create (struct multipath *mpp, char *params) {
324 return _dm_addmap_create(mpp, params, ADDMAP_RW);
328 dm_addmap_create_ro (struct multipath *mpp, char *params) {
329 return _dm_addmap_create(mpp, params, ADDMAP_RO);
333 dm_addmap_reload (struct multipath *mpp, char *params) {
334 return dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RW);
338 dm_addmap_reload_ro (struct multipath *mpp, char *params) {
339 return dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RO);
343 dm_map_present (const char * str)
349 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
352 if (!dm_task_set_name(dmt, str))
355 dm_task_no_open_count(dmt);
357 if (!dm_task_run(dmt))
360 if (!dm_task_get_info(dmt, &info))
366 dm_task_destroy(dmt);
371 dm_get_map(const char * name, unsigned long long * size, char * outparams)
376 uint64_t start, length;
377 char *target_type = NULL;
380 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
383 if (!dm_task_set_name(dmt, name))
386 dm_task_no_open_count(dmt);
388 if (!dm_task_run(dmt))
391 /* Fetch 1st target */
392 next = dm_get_next_target(dmt, next, &start, &length,
393 &target_type, ¶ms);
402 if (snprintf(outparams, PARAMS_SIZE, "%s", params) <= PARAMS_SIZE)
405 dm_task_destroy(dmt);
410 dm_get_prefixed_uuid(const char *name, char *uuid)
416 dmt = dm_task_create(DM_DEVICE_INFO);
420 if (!dm_task_set_name (dmt, name))
423 if (!dm_task_run(dmt))
426 uuidtmp = dm_task_get_uuid(dmt);
428 strcpy(uuid, uuidtmp);
434 dm_task_destroy(dmt);
439 dm_get_uuid(char *name, char *uuid)
441 char uuidtmp[WWID_SIZE];
443 if (dm_get_prefixed_uuid(name, uuidtmp))
446 if (!strncmp(uuidtmp, UUID_PREFIX, UUID_PREFIX_LEN))
447 strcpy(uuid, uuidtmp + UUID_PREFIX_LEN);
449 strcpy(uuid, uuidtmp);
456 * 0 : if both uuids end with same suffix which starts with UUID_PREFIX
460 dm_compare_uuid(const char* mapname1, const char* mapname2)
463 char uuid1[WWID_SIZE], uuid2[WWID_SIZE];
465 if (dm_get_prefixed_uuid(mapname1, uuid1))
468 if (dm_get_prefixed_uuid(mapname2, uuid2))
471 p1 = strstr(uuid1, UUID_PREFIX);
472 p2 = strstr(uuid2, UUID_PREFIX);
473 if (p1 && p2 && !strcmp(p1, p2))
480 dm_get_status(char * name, char * outstatus)
485 uint64_t start, length;
489 if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
492 if (!dm_task_set_name(dmt, name))
495 dm_task_no_open_count(dmt);
497 if (!dm_task_run(dmt))
500 /* Fetch 1st target */
501 next = dm_get_next_target(dmt, next, &start, &length,
502 &target_type, &status);
504 if (snprintf(outstatus, PARAMS_SIZE, "%s", status) <= PARAMS_SIZE)
508 condlog(0, "%s: error getting map status string", name);
510 dm_task_destroy(dmt);
521 dm_type(const char * name, char * type)
526 uint64_t start, length;
527 char *target_type = NULL;
530 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
533 if (!dm_task_set_name(dmt, name))
536 dm_task_no_open_count(dmt);
538 if (!dm_task_run(dmt))
541 /* Fetch 1st target */
542 next = dm_get_next_target(dmt, next, &start, &length,
543 &target_type, ¶ms);
547 else if (!strcmp(target_type, type))
551 dm_task_destroy(dmt);
556 dm_dev_t (const char * mapname, char * dev_t, int len)
562 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
565 if (!dm_task_set_name(dmt, mapname))
568 if (!dm_task_run(dmt))
571 if (!dm_task_get_info(dmt, &info))
575 if (snprintf(dev_t, len, "%i:%i", info.major, info.minor) > len)
580 dm_task_destroy(dmt);
585 dm_get_opencount (const char * mapname)
591 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
594 if (!dm_task_set_name(dmt, mapname))
597 if (!dm_task_run(dmt))
600 if (!dm_task_get_info(dmt, &info))
605 dm_task_destroy(dmt);
610 dm_get_major (char * mapname)
616 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
619 if (!dm_task_set_name(dmt, mapname))
622 if (!dm_task_run(dmt))
625 if (!dm_task_get_info(dmt, &info))
630 dm_task_destroy(dmt);
635 dm_get_minor (char * mapname)
641 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
644 if (!dm_task_set_name(dmt, mapname))
647 if (!dm_task_run(dmt))
650 if (!dm_task_get_info(dmt, &info))
655 dm_task_destroy(dmt);
660 _dm_flush_map (const char * mapname, int need_sync)
664 if (!dm_map_present(mapname))
667 if (dm_type(mapname, TGT_MPATH) <= 0)
668 return 0; /* nothing to do */
670 if (dm_remove_partmaps(mapname, need_sync))
673 if (dm_get_opencount(mapname)) {
674 condlog(2, "%s: map in use", mapname);
678 r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname, need_sync);
681 condlog(4, "multipath map %s removed", mapname);
688 dm_suspend_and_flush_map (const char * mapname)
690 int s = 0, queue_if_no_path = 0;
691 unsigned long long mapsize;
692 char params[PARAMS_SIZE] = {0};
694 if (!dm_map_present(mapname))
697 if (dm_type(mapname, TGT_MPATH) <= 0)
698 return 0; /* nothing to do */
700 if (!dm_get_map(mapname, &mapsize, params)) {
701 if (strstr(params, "queue_if_no_path"))
702 queue_if_no_path = 1;
705 if (queue_if_no_path)
706 s = dm_queue_if_no_path((char *)mapname, 0);
707 /* Leave queue_if_no_path alone if unset failed */
709 queue_if_no_path = 0;
711 s = dm_simplecmd_flush(DM_DEVICE_SUSPEND, mapname, 0);
713 if (!dm_flush_map(mapname)) {
714 condlog(4, "multipath map %s removed", mapname);
717 condlog(2, "failed to remove multipath map %s", mapname);
718 dm_simplecmd_noflush(DM_DEVICE_RESUME, mapname);
719 if (queue_if_no_path)
720 s = dm_queue_if_no_path((char *)mapname, 1);
729 struct dm_names *names;
732 if (!(dmt = dm_task_create (DM_DEVICE_LIST)))
735 dm_task_no_open_count(dmt);
737 if (!dm_task_run (dmt))
740 if (!(names = dm_task_get_names (dmt)))
747 r |= dm_suspend_and_flush_map(names->name);
749 names = (void *) names + next;
753 dm_task_destroy (dmt);
758 dm_message(char * mapname, char * message)
763 if (!(dmt = dm_task_create(DM_DEVICE_TARGET_MSG)))
766 if (!dm_task_set_name(dmt, mapname))
769 if (!dm_task_set_sector(dmt, 0))
772 if (!dm_task_set_message(dmt, message))
775 dm_task_no_open_count(dmt);
777 if (!dm_task_run(dmt))
783 condlog(0, "DM message failed [%s]", message);
785 dm_task_destroy(dmt);
790 dm_fail_path(char * mapname, char * path)
794 if (snprintf(message, 32, "fail_path %s", path) > 32)
797 return dm_message(mapname, message);
801 dm_reinstate_path(char * mapname, char * path)
805 if (snprintf(message, 32, "reinstate_path %s", path) > 32)
808 return dm_message(mapname, message);
812 dm_queue_if_no_path(char *mapname, int enable)
817 message = "queue_if_no_path";
819 message = "fail_if_no_path";
821 return dm_message(mapname, message);
825 dm_groupmsg (char * msg, char * mapname, int index)
829 if (snprintf(message, 32, "%s_group %i", msg, index) > 32)
832 return dm_message(mapname, message);
836 dm_switchgroup(char * mapname, int index)
838 return dm_groupmsg("switch", mapname, index);
842 dm_enablegroup(char * mapname, int index)
844 return dm_groupmsg("enable", mapname, index);
848 dm_disablegroup(char * mapname, int index)
850 return dm_groupmsg("disable", mapname, index);
854 dm_get_maps (vector mp)
856 struct multipath * mpp;
860 struct dm_names *names;
866 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
869 dm_task_no_open_count(dmt);
871 if (!dm_task_run(dmt))
874 if (!(names = dm_task_get_names(dmt)))
878 r = 0; /* this is perfectly valid */
883 info = dm_type(names->name, TGT_MPATH);
888 mpp = alloc_multipath();
893 mpp->alias = STRDUP(names->name);
899 if (dm_get_map(names->name, &mpp->size, NULL))
902 dm_get_uuid(names->name, mpp->wwid);
903 dm_get_info(names->name, &mpp->dmi);
906 if (!vector_alloc_slot(mp))
909 vector_set_slot(mp, mpp);
913 names = (void *) names + next;
919 free_multipath(mpp, KEEP_PATHS);
921 dm_task_destroy (dmt);
926 dm_get_name(char *uuid)
930 char *prefixed_uuid, *name = NULL;
933 dmt = dm_task_create(DM_DEVICE_INFO);
937 prefixed_uuid = MALLOC(UUID_PREFIX_LEN + strlen(uuid) + 1);
938 if (!prefixed_uuid) {
939 condlog(0, "cannot create prefixed uuid : %s",
943 sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid);
944 if (!dm_task_set_uuid(dmt, prefixed_uuid))
947 if (!dm_task_run(dmt))
950 if (!dm_task_get_info(dmt, &info) || !info.exists)
953 nametmp = dm_task_get_name(dmt);
954 if (nametmp && strlen(nametmp)) {
955 name = MALLOC(strlen(nametmp) + 1);
957 strcpy(name, nametmp);
959 condlog(2, "%s: no device-mapper name found", uuid);
965 dm_task_destroy(dmt);
971 dm_geteventnr (char *name)
977 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
980 if (!dm_task_set_name(dmt, name))
983 dm_task_no_open_count(dmt);
985 if (!dm_task_run(dmt))
988 if (!dm_task_get_info(dmt, &info))
992 event = info.event_nr;
995 dm_task_destroy(dmt);
1001 dm_mapname(int major, int minor)
1003 char * response = NULL;
1005 struct dm_task *dmt;
1007 int loop = MAX_WAIT * LOOPS_PER_SEC;
1009 if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
1012 if (!dm_task_set_major(dmt, major) ||
1013 !dm_task_set_minor(dmt, minor))
1016 dm_task_no_open_count(dmt);
1019 * device map might not be ready when we get here from
1020 * daemon uev_trigger -> uev_add_map
1023 r = dm_task_run(dmt);
1028 usleep(1000 * 1000 / LOOPS_PER_SEC);
1032 condlog(0, "%i:%i: timeout fetching map name", major, minor);
1036 map = dm_task_get_name(dmt);
1037 if (map && strlen(map))
1038 response = STRDUP((char *)dm_task_get_name(dmt));
1040 dm_task_destroy(dmt);
1043 dm_task_destroy(dmt);
1044 condlog(0, "%i:%i: error fetching map name", major, minor);
1049 dm_remove_partmaps (const char * mapname, int need_sync)
1051 struct dm_task *dmt;
1052 struct dm_names *names;
1054 char params[PARAMS_SIZE];
1055 unsigned long long size;
1059 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
1062 dm_task_no_open_count(dmt);
1064 if (!dm_task_run(dmt))
1067 if (!(names = dm_task_get_names(dmt)))
1071 r = 0; /* this is perfectly valid */
1075 if (dm_dev_t(mapname, &dev_t[0], 32))
1081 * if devmap target is "linear"
1083 (dm_type(names->name, TGT_PART) > 0) &&
1086 * and both uuid end with same suffix starting
1089 (!dm_compare_uuid(names->name, mapname)) &&
1092 * and we can fetch the map table from the kernel
1094 !dm_get_map(names->name, &size, ¶ms[0]) &&
1097 * and the table maps over the multipath map
1099 strstr(params, dev_t)
1102 * then it's a kpartx generated partition.
1106 * if the opencount is 0 maybe some other
1107 * partitions depend on it.
1109 if (dm_get_opencount(names->name)) {
1110 dm_remove_partmaps(names->name, need_sync);
1111 if (dm_get_opencount(names->name)) {
1112 condlog(2, "%s: map in use",
1117 condlog(4, "partition map %s removed",
1119 dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name,
1124 names = (void *) names + next;
1129 dm_task_destroy (dmt);
1133 static struct dm_info *
1136 return MALLOC(sizeof(struct dm_info));
1140 dm_get_info (char * mapname, struct dm_info ** dmi)
1143 struct dm_task *dmt = NULL;
1149 *dmi = alloc_dminfo();
1154 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
1157 if (!dm_task_set_name(dmt, mapname))
1160 dm_task_no_open_count(dmt);
1162 if (!dm_task_run(dmt))
1165 if (!dm_task_get_info(dmt, *dmi))
1171 memset(*dmi, 0, sizeof(struct dm_info));
1177 dm_task_destroy(dmt);
1183 dm_rename_partmaps (char * old, char * new)
1185 struct dm_task *dmt;
1186 struct dm_names *names;
1188 char buff[PARAMS_SIZE];
1189 unsigned long long size;
1193 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
1196 dm_task_no_open_count(dmt);
1198 if (!dm_task_run(dmt))
1201 if (!(names = dm_task_get_names(dmt)))
1205 r = 0; /* this is perfectly valid */
1209 if (dm_dev_t(old, &dev_t[0], 32))
1215 * if devmap target is "linear"
1217 (dm_type(names->name, TGT_PART) > 0) &&
1220 * and the multipath mapname and the part mapname start
1223 !strncmp(names->name, old, strlen(old)) &&
1226 * and we can fetch the map table from the kernel
1228 !dm_get_map(names->name, &size, &buff[0]) &&
1231 * and the table maps over the multipath map
1236 * then it's a kpartx generated partition.
1239 snprintf(buff, PARAMS_SIZE, "%s%s",
1240 new, names->name + strlen(old));
1241 dm_rename(names->name, buff);
1242 condlog(4, "partition map %s renamed",
1247 names = (void *) names + next;
1252 dm_task_destroy (dmt);
1257 dm_rename (char * old, char * new)
1260 struct dm_task *dmt;
1262 if (dm_rename_partmaps(old, new))
1265 if (!(dmt = dm_task_create(DM_DEVICE_RENAME)))
1268 if (!dm_task_set_name(dmt, old))
1271 if (!dm_task_set_newname(dmt, new))
1274 dm_task_no_open_count(dmt);
1276 if (!dm_task_set_cookie(dmt, &conf->cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
1278 if (!dm_task_run(dmt))
1283 dm_task_destroy(dmt);
1287 void dm_reassign_deps(char *table, char *dep, char *newdep)
1290 char newtable[PARAMS_SIZE];
1292 strcpy(newtable, table);
1293 p = strstr(newtable, dep);
1294 n = table + (p - newtable);
1296 n += strlen(newdep);
1301 int dm_reassign_table(const char *name, char *old, char *new)
1303 int r, modified = 0;
1304 uint64_t start, length;
1305 struct dm_task *dmt, *reload_dmt;
1306 char *target, *params = NULL;
1307 char buff[PARAMS_SIZE];
1310 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
1313 if (!dm_task_set_name(dmt, name))
1316 dm_task_no_open_count(dmt);
1318 if (!dm_task_run(dmt))
1320 if (!(reload_dmt = dm_task_create(DM_DEVICE_RELOAD)))
1322 if (!dm_task_set_name(reload_dmt, name))
1326 next = dm_get_next_target(dmt, next, &start, &length,
1328 memset(buff, 0, PARAMS_SIZE);
1329 strcpy(buff, params);
1330 if (strcmp(target, TGT_MPATH) && strstr(params, old)) {
1331 condlog(3, "%s: replace target %s %s",
1332 name, target, buff);
1333 dm_reassign_deps(buff, old, new);
1334 condlog(3, "%s: with target %s %s",
1335 name, target, buff);
1338 dm_task_add_target(reload_dmt, start, length, target, buff);
1342 dm_task_no_open_count(reload_dmt);
1344 if (!dm_task_run(reload_dmt)) {
1345 condlog(3, "%s: failed to reassign targets", name);
1348 dm_simplecmd_noflush(DM_DEVICE_RESUME, name);
1353 dm_task_destroy(reload_dmt);
1355 dm_task_destroy(dmt);
1361 * Reassign existing device-mapper table(s) to not use
1362 * the block devices but point to the multipathed
1365 int dm_reassign(const char *mapname)
1367 struct dm_deps *deps;
1368 struct dm_task *dmt;
1369 struct dm_info info;
1370 char dev_t[32], dm_dep[32];
1373 if (dm_dev_t(mapname, &dev_t[0], 32)) {
1374 condlog(3, "%s: failed to get device number", mapname);
1378 if (!(dmt = dm_task_create(DM_DEVICE_DEPS))) {
1379 condlog(3, "%s: couldn't make dm task", mapname);
1383 if (!dm_task_set_name(dmt, mapname))
1386 dm_task_no_open_count(dmt);
1388 if (!dm_task_run(dmt))
1391 if (!dm_task_get_info(dmt, &info))
1394 if (!(deps = dm_task_get_deps(dmt)))
1400 for (i = 0; i < deps->count; i++) {
1401 sprintf(dm_dep, "%d:%d",
1402 major(deps->device[i]),
1403 minor(deps->device[i]));
1404 sysfs_check_holders(dm_dep, dev_t);
1407 dm_task_destroy (dmt);
1414 int dm_setgeometry(struct multipath *mpp)
1416 struct dm_task *dmt;
1418 char heads[4], sectors[4];
1419 char cylinders[10], start[32];
1425 pp = first_path(mpp);
1427 condlog(3, "%s: no path for geometry", mpp->alias);
1430 if (pp->geom.cylinders == 0 ||
1431 pp->geom.heads == 0 ||
1432 pp->geom.sectors == 0) {
1433 condlog(3, "%s: invalid geometry on %s", mpp->alias, pp->dev);
1437 if (!(dmt = dm_task_create(DM_DEVICE_SET_GEOMETRY)))
1440 if (!dm_task_set_name(dmt, mpp->alias))
1443 dm_task_no_open_count(dmt);
1445 /* What a sick interface ... */
1446 snprintf(heads, 4, "%u", pp->geom.heads);
1447 snprintf(sectors, 4, "%u", pp->geom.sectors);
1448 snprintf(cylinders, 10, "%u", pp->geom.cylinders);
1449 snprintf(start, 32, "%lu", pp->geom.start);
1450 if (!dm_task_set_geometry(dmt, cylinders, heads, sectors, start)) {
1451 condlog(3, "%s: Failed to set geometry", mpp->alias);
1455 r = dm_task_run(dmt);
1457 dm_task_destroy(dmt);