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)
75 time_t t = time(NULL);
76 struct tm *tb = localtime(&t);
79 strftime(buff, sizeof(buff), "%b %d %H:%M:%S", tb);
80 buff[sizeof(buff)-1] = '\0';
82 fprintf(stdout, "%s | ", buff);
83 fprintf(stdout, "libdevmapper: %s(%i): ", file, line);
84 vfprintf(stdout, f, ap);
85 fprintf(stdout, "\n");
87 condlog(level, "libdevmapper: %s(%i): ", file, line);
88 log_safe(level + 3, f, ap);
97 dm_log_init(&dm_write_log);
98 dm_log_init_verbose(conf ? conf->verbosity + 3 : 0);
106 #ifdef LIBDM_API_COOKIE
107 int minv[3] = {1, 2, 38};
109 int minv[3] = {1, 2, 8};
112 dm_get_library_version(version, sizeof(version));
113 condlog(3, "libdevmapper version %s", version);
114 sscanf(version, "%d.%d.%d ", &v[0], &v[1], &v[2]);
116 if VERSION_GE(v, minv)
118 condlog(0, "libdevmapper version must be >= %d.%.2d.%.2d",
119 minv[0], minv[1], minv[2]);
124 dm_drv_version (unsigned int * version, char * str)
128 struct dm_versions *target;
129 struct dm_versions *last_target;
136 if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS)))
139 dm_task_no_open_count(dmt);
141 if (!dm_task_run(dmt)) {
142 condlog(0, "Can not communicate with kernel DM");
145 target = dm_task_get_versions(dmt);
148 last_target = target;
149 if (!strncmp(str, target->name, strlen(str))) {
153 target = (void *) target + target->next;
154 } while (last_target != target);
157 condlog(0, "DM %s kernel driver not loaded", str);
166 dm_task_destroy(dmt);
173 unsigned int minv[3] = {1, 0, 3};
174 unsigned int version[3] = {0, 0, 0};
175 unsigned int * v = version;
177 if (dm_drv_version(v, TGT_MPATH)) {
178 /* in doubt return not capable */
182 /* test request based multipath capability */
183 condlog(3, "DM multipath kernel driver v%u.%u.%u",
186 if VERSION_GE(v, minv)
189 condlog(0, "DM multipath kernel driver must be >= v%u.%u.%u",
190 minv[0], minv[1], minv[2]);
199 return dm_drv_prereq();
203 dm_simplecmd (int task, const char *name, int no_flush, int need_sync) {
205 int udev_wait_flag = (need_sync && (task == DM_DEVICE_RESUME ||
206 task == DM_DEVICE_REMOVE));
209 if (!(dmt = dm_task_create (task)))
212 if (!dm_task_set_name (dmt, name))
215 dm_task_no_open_count(dmt);
216 dm_task_skip_lockfs(dmt); /* for DM_DEVICE_RESUME */
217 #ifdef LIBDM_API_FLUSH
219 dm_task_no_flush(dmt); /* for DM_DEVICE_SUSPEND/RESUME */
222 if (udev_wait_flag && !dm_task_set_cookie(dmt, &conf->cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
224 r = dm_task_run (dmt);
227 dm_task_destroy (dmt);
232 dm_simplecmd_flush (int task, const char *name, int needsync) {
233 return dm_simplecmd(task, name, 0, needsync);
237 dm_simplecmd_noflush (int task, const char *name) {
238 return dm_simplecmd(task, name, 1, 1);
242 dm_addmap (int task, const char *target, struct multipath *mpp, char * params,
243 int use_uuid, int ro) {
246 char *prefixed_uuid = NULL;
248 if (!(dmt = dm_task_create (task)))
251 if (!dm_task_set_name (dmt, mpp->alias))
254 if (!dm_task_add_target (dmt, 0, mpp->size, target, params))
260 if (use_uuid && strlen(mpp->wwid) > 0){
261 prefixed_uuid = MALLOC(UUID_PREFIX_LEN + strlen(mpp->wwid) + 1);
262 if (!prefixed_uuid) {
263 condlog(0, "cannot create prefixed uuid : %s",
267 sprintf(prefixed_uuid, UUID_PREFIX "%s", mpp->wwid);
268 if (!dm_task_set_uuid(dmt, prefixed_uuid))
272 if (mpp->attribute_flags & (1 << ATTR_MODE) &&
273 !dm_task_set_mode(dmt, mpp->mode))
275 if (mpp->attribute_flags & (1 << ATTR_UID) &&
276 !dm_task_set_uid(dmt, mpp->uid))
278 if (mpp->attribute_flags & (1 << ATTR_GID) &&
279 !dm_task_set_gid(dmt, mpp->gid))
281 condlog(4, "%s: addmap [0 %llu %s %s]", mpp->alias, mpp->size,
284 dm_task_no_open_count(dmt);
286 if (task == DM_DEVICE_CREATE &&
287 !dm_task_set_cookie(dmt, &conf->cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
289 r = dm_task_run (dmt);
296 dm_task_destroy (dmt);
302 _dm_addmap_create (struct multipath *mpp, char * params, int ro) {
304 r = dm_addmap(DM_DEVICE_CREATE, TGT_MPATH, mpp, params, 1, ro);
306 * DM_DEVICE_CREATE is actually DM_DEV_CREATE + DM_TABLE_LOAD.
307 * Failing the second part leaves an empty map. Clean it up.
309 if (!r && dm_map_present(mpp->alias)) {
310 condlog(3, "%s: failed to load map (a path might be in use)",
312 dm_flush_map_nosync(mpp->alias);
321 dm_addmap_create (struct multipath *mpp, char *params) {
322 return _dm_addmap_create(mpp, params, ADDMAP_RW);
326 dm_addmap_create_ro (struct multipath *mpp, char *params) {
327 return _dm_addmap_create(mpp, params, ADDMAP_RO);
331 dm_addmap_reload (struct multipath *mpp, char *params) {
332 return dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RW);
336 dm_addmap_reload_ro (struct multipath *mpp, char *params) {
337 return dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RO);
341 dm_map_present (const char * str)
347 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
350 if (!dm_task_set_name(dmt, str))
353 dm_task_no_open_count(dmt);
355 if (!dm_task_run(dmt))
358 if (!dm_task_get_info(dmt, &info))
364 dm_task_destroy(dmt);
369 dm_get_map(char * name, unsigned long long * size, char * outparams)
374 uint64_t start, length;
375 char *target_type = NULL;
378 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
381 if (!dm_task_set_name(dmt, name))
384 dm_task_no_open_count(dmt);
386 if (!dm_task_run(dmt))
389 /* Fetch 1st target */
390 next = dm_get_next_target(dmt, next, &start, &length,
391 &target_type, ¶ms);
400 if (snprintf(outparams, PARAMS_SIZE, "%s", params) <= PARAMS_SIZE)
403 dm_task_destroy(dmt);
408 dm_get_prefixed_uuid(const char *name, char *uuid)
414 dmt = dm_task_create(DM_DEVICE_INFO);
418 if (!dm_task_set_name (dmt, name))
421 if (!dm_task_run(dmt))
424 uuidtmp = dm_task_get_uuid(dmt);
426 strcpy(uuid, uuidtmp);
432 dm_task_destroy(dmt);
437 dm_get_uuid(char *name, char *uuid)
439 char uuidtmp[WWID_SIZE];
441 if (dm_get_prefixed_uuid(name, uuidtmp))
444 if (!strncmp(uuidtmp, UUID_PREFIX, UUID_PREFIX_LEN))
445 strcpy(uuid, uuidtmp + UUID_PREFIX_LEN);
447 strcpy(uuid, uuidtmp);
454 * 0 : if both uuids end with same suffix which starts with UUID_PREFIX
458 dm_compare_uuid(const char* mapname1, const char* mapname2)
461 char uuid1[WWID_SIZE], uuid2[WWID_SIZE];
463 if (dm_get_prefixed_uuid(mapname1, uuid1))
466 if (dm_get_prefixed_uuid(mapname2, uuid2))
469 p1 = strstr(uuid1, UUID_PREFIX);
470 p2 = strstr(uuid2, UUID_PREFIX);
471 if (p1 && p2 && !strcmp(p1, p2))
478 dm_get_status(char * name, char * outstatus)
483 uint64_t start, length;
487 if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
490 if (!dm_task_set_name(dmt, name))
493 dm_task_no_open_count(dmt);
495 if (!dm_task_run(dmt))
498 /* Fetch 1st target */
499 next = dm_get_next_target(dmt, next, &start, &length,
500 &target_type, &status);
502 if (snprintf(outstatus, PARAMS_SIZE, "%s", status) <= PARAMS_SIZE)
506 condlog(0, "%s: error getting map status string", name);
508 dm_task_destroy(dmt);
519 dm_type(const char * name, char * type)
524 uint64_t start, length;
525 char *target_type = NULL;
528 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
531 if (!dm_task_set_name(dmt, name))
534 dm_task_no_open_count(dmt);
536 if (!dm_task_run(dmt))
539 /* Fetch 1st target */
540 next = dm_get_next_target(dmt, next, &start, &length,
541 &target_type, ¶ms);
545 else if (!strcmp(target_type, type))
549 dm_task_destroy(dmt);
554 dm_dev_t (const char * mapname, char * dev_t, int len)
560 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
563 if (!dm_task_set_name(dmt, mapname))
566 if (!dm_task_run(dmt))
569 if (!dm_task_get_info(dmt, &info))
573 if (snprintf(dev_t, len, "%i:%i", info.major, info.minor) > len)
578 dm_task_destroy(dmt);
583 dm_get_opencount (const char * mapname)
589 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
592 if (!dm_task_set_name(dmt, mapname))
595 if (!dm_task_run(dmt))
598 if (!dm_task_get_info(dmt, &info))
603 dm_task_destroy(dmt);
608 dm_get_major (char * mapname)
614 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
617 if (!dm_task_set_name(dmt, mapname))
620 if (!dm_task_run(dmt))
623 if (!dm_task_get_info(dmt, &info))
628 dm_task_destroy(dmt);
633 dm_get_minor (char * mapname)
639 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
642 if (!dm_task_set_name(dmt, mapname))
645 if (!dm_task_run(dmt))
648 if (!dm_task_get_info(dmt, &info))
653 dm_task_destroy(dmt);
658 _dm_flush_map (const char * mapname, int need_sync)
662 if (!dm_map_present(mapname))
665 if (dm_type(mapname, TGT_MPATH) <= 0)
666 return 0; /* nothing to do */
668 if (dm_remove_partmaps(mapname, need_sync))
671 if (dm_get_opencount(mapname)) {
672 condlog(2, "%s: map in use", mapname);
676 r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname, need_sync);
679 condlog(4, "multipath map %s removed", mapname);
686 dm_suspend_and_flush_map (const char * mapname)
690 if (!dm_map_present(mapname))
693 if (dm_type(mapname, TGT_MPATH) <= 0)
694 return 0; /* nothing to do */
696 s = dm_queue_if_no_path((char *)mapname, 0);
698 s = dm_simplecmd_flush(DM_DEVICE_SUSPEND, mapname, 0);
700 if (!dm_flush_map(mapname)) {
701 condlog(4, "multipath map %s removed", mapname);
704 condlog(2, "failed to remove multipath map %s", mapname);
705 dm_simplecmd_noflush(DM_DEVICE_RESUME, mapname);
714 struct dm_names *names;
717 if (!(dmt = dm_task_create (DM_DEVICE_LIST)))
720 dm_task_no_open_count(dmt);
722 if (!dm_task_run (dmt))
725 if (!(names = dm_task_get_names (dmt)))
732 r |= dm_suspend_and_flush_map(names->name);
734 names = (void *) names + next;
738 dm_task_destroy (dmt);
743 dm_message(char * mapname, char * message)
748 if (!(dmt = dm_task_create(DM_DEVICE_TARGET_MSG)))
751 if (!dm_task_set_name(dmt, mapname))
754 if (!dm_task_set_sector(dmt, 0))
757 if (!dm_task_set_message(dmt, message))
760 dm_task_no_open_count(dmt);
762 if (!dm_task_run(dmt))
768 condlog(0, "DM message failed [%s]", message);
770 dm_task_destroy(dmt);
775 dm_fail_path(char * mapname, char * path)
779 if (snprintf(message, 32, "fail_path %s", path) > 32)
782 return dm_message(mapname, message);
786 dm_reinstate_path(char * mapname, char * path)
790 if (snprintf(message, 32, "reinstate_path %s", path) > 32)
793 return dm_message(mapname, message);
797 dm_queue_if_no_path(char *mapname, int enable)
802 message = "queue_if_no_path";
804 message = "fail_if_no_path";
806 return dm_message(mapname, message);
810 dm_groupmsg (char * msg, char * mapname, int index)
814 if (snprintf(message, 32, "%s_group %i", msg, index) > 32)
817 return dm_message(mapname, message);
821 dm_switchgroup(char * mapname, int index)
823 return dm_groupmsg("switch", mapname, index);
827 dm_enablegroup(char * mapname, int index)
829 return dm_groupmsg("enable", mapname, index);
833 dm_disablegroup(char * mapname, int index)
835 return dm_groupmsg("disable", mapname, index);
839 dm_get_maps (vector mp)
841 struct multipath * mpp;
845 struct dm_names *names;
851 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
854 dm_task_no_open_count(dmt);
856 if (!dm_task_run(dmt))
859 if (!(names = dm_task_get_names(dmt)))
863 r = 0; /* this is perfectly valid */
868 info = dm_type(names->name, TGT_MPATH);
873 mpp = alloc_multipath();
878 mpp->alias = STRDUP(names->name);
884 if (dm_get_map(names->name, &mpp->size, NULL))
887 dm_get_uuid(names->name, mpp->wwid);
888 dm_get_info(names->name, &mpp->dmi);
891 if (!vector_alloc_slot(mp))
894 vector_set_slot(mp, mpp);
898 names = (void *) names + next;
904 free_multipath(mpp, KEEP_PATHS);
906 dm_task_destroy (dmt);
911 dm_get_name(char *uuid)
915 char *prefixed_uuid, *name = NULL;
918 dmt = dm_task_create(DM_DEVICE_INFO);
922 prefixed_uuid = MALLOC(UUID_PREFIX_LEN + strlen(uuid) + 1);
923 if (!prefixed_uuid) {
924 condlog(0, "cannot create prefixed uuid : %s",
928 sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid);
929 if (!dm_task_set_uuid(dmt, prefixed_uuid))
932 if (!dm_task_run(dmt))
935 if (!dm_task_get_info(dmt, &info) || !info.exists)
938 nametmp = dm_task_get_name(dmt);
939 if (nametmp && strlen(nametmp)) {
940 name = MALLOC(strlen(nametmp) + 1);
942 strcpy(name, nametmp);
944 condlog(2, "%s: no device-mapper name found", uuid);
950 dm_task_destroy(dmt);
956 dm_geteventnr (char *name)
962 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
965 if (!dm_task_set_name(dmt, name))
968 dm_task_no_open_count(dmt);
970 if (!dm_task_run(dmt))
973 if (!dm_task_get_info(dmt, &info))
977 event = info.event_nr;
980 dm_task_destroy(dmt);
986 dm_mapname(int major, int minor)
988 char * response = NULL;
992 int loop = MAX_WAIT * LOOPS_PER_SEC;
994 if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
997 if (!dm_task_set_major(dmt, major) ||
998 !dm_task_set_minor(dmt, minor))
1001 dm_task_no_open_count(dmt);
1004 * device map might not be ready when we get here from
1005 * daemon uev_trigger -> uev_add_map
1008 r = dm_task_run(dmt);
1013 usleep(1000 * 1000 / LOOPS_PER_SEC);
1017 condlog(0, "%i:%i: timeout fetching map name", major, minor);
1021 map = dm_task_get_name(dmt);
1022 if (map && strlen(map))
1023 response = STRDUP((char *)dm_task_get_name(dmt));
1025 dm_task_destroy(dmt);
1028 dm_task_destroy(dmt);
1029 condlog(0, "%i:%i: error fetching map name", major, minor);
1034 dm_remove_partmaps (const char * mapname, int need_sync)
1036 struct dm_task *dmt;
1037 struct dm_names *names;
1039 char params[PARAMS_SIZE];
1040 unsigned long long size;
1044 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
1047 dm_task_no_open_count(dmt);
1049 if (!dm_task_run(dmt))
1052 if (!(names = dm_task_get_names(dmt)))
1056 r = 0; /* this is perfectly valid */
1060 if (dm_dev_t(mapname, &dev_t[0], 32))
1066 * if devmap target is "linear"
1068 (dm_type(names->name, TGT_PART) > 0) &&
1071 * and both uuid end with same suffix starting
1074 (!dm_compare_uuid(names->name, mapname)) &&
1077 * and we can fetch the map table from the kernel
1079 !dm_get_map(names->name, &size, ¶ms[0]) &&
1082 * and the table maps over the multipath map
1084 strstr(params, dev_t)
1087 * then it's a kpartx generated partition.
1091 * if the opencount is 0 maybe some other
1092 * partitions depend on it.
1094 if (dm_get_opencount(names->name)) {
1095 dm_remove_partmaps(names->name, need_sync);
1096 if (dm_get_opencount(names->name)) {
1097 condlog(2, "%s: map in use",
1102 condlog(4, "partition map %s removed",
1104 dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name,
1109 names = (void *) names + next;
1114 dm_task_destroy (dmt);
1118 static struct dm_info *
1121 return MALLOC(sizeof(struct dm_info));
1125 dm_get_info (char * mapname, struct dm_info ** dmi)
1128 struct dm_task *dmt = NULL;
1134 *dmi = alloc_dminfo();
1139 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
1142 if (!dm_task_set_name(dmt, mapname))
1145 dm_task_no_open_count(dmt);
1147 if (!dm_task_run(dmt))
1150 if (!dm_task_get_info(dmt, *dmi))
1156 memset(*dmi, 0, sizeof(struct dm_info));
1162 dm_task_destroy(dmt);
1168 dm_rename_partmaps (char * old, char * new)
1170 struct dm_task *dmt;
1171 struct dm_names *names;
1173 char buff[PARAMS_SIZE];
1174 unsigned long long size;
1178 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
1181 dm_task_no_open_count(dmt);
1183 if (!dm_task_run(dmt))
1186 if (!(names = dm_task_get_names(dmt)))
1190 r = 0; /* this is perfectly valid */
1194 if (dm_dev_t(old, &dev_t[0], 32))
1200 * if devmap target is "linear"
1202 (dm_type(names->name, TGT_PART) > 0) &&
1205 * and the multipath mapname and the part mapname start
1208 !strncmp(names->name, old, strlen(old)) &&
1211 * and we can fetch the map table from the kernel
1213 !dm_get_map(names->name, &size, &buff[0]) &&
1216 * and the table maps over the multipath map
1221 * then it's a kpartx generated partition.
1224 snprintf(buff, PARAMS_SIZE, "%s%s",
1225 new, names->name + strlen(old));
1226 dm_rename(names->name, buff);
1227 condlog(4, "partition map %s renamed",
1232 names = (void *) names + next;
1237 dm_task_destroy (dmt);
1242 dm_rename (char * old, char * new)
1245 struct dm_task *dmt;
1247 if (dm_rename_partmaps(old, new))
1250 if (!(dmt = dm_task_create(DM_DEVICE_RENAME)))
1253 if (!dm_task_set_name(dmt, old))
1256 if (!dm_task_set_newname(dmt, new))
1259 dm_task_no_open_count(dmt);
1261 if (!dm_task_set_cookie(dmt, &conf->cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
1263 if (!dm_task_run(dmt))
1268 dm_task_destroy(dmt);
1272 void dm_reassign_deps(char *table, char *dep, char *newdep)
1275 char newtable[PARAMS_SIZE];
1277 strcpy(newtable, table);
1278 p = strstr(newtable, dep);
1279 n = table + (p - newtable);
1281 n += strlen(newdep);
1286 int dm_reassign_table(const char *name, char *old, char *new)
1288 int r, modified = 0;
1289 uint64_t start, length;
1290 struct dm_task *dmt, *reload_dmt;
1291 char *target, *params = NULL;
1292 char buff[PARAMS_SIZE];
1295 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
1298 if (!dm_task_set_name(dmt, name))
1301 dm_task_no_open_count(dmt);
1303 if (!dm_task_run(dmt))
1305 if (!(reload_dmt = dm_task_create(DM_DEVICE_RELOAD)))
1307 if (!dm_task_set_name(reload_dmt, name))
1311 next = dm_get_next_target(dmt, next, &start, &length,
1313 memset(buff, 0, PARAMS_SIZE);
1314 strcpy(buff, params);
1315 if (strcmp(target, TGT_MPATH) && strstr(params, old)) {
1316 condlog(3, "%s: replace target %s %s",
1317 name, target, buff);
1318 dm_reassign_deps(buff, old, new);
1319 condlog(3, "%s: with target %s %s",
1320 name, target, buff);
1323 dm_task_add_target(reload_dmt, start, length, target, buff);
1327 dm_task_no_open_count(reload_dmt);
1329 if (!dm_task_run(reload_dmt)) {
1330 condlog(3, "%s: failed to reassign targets", name);
1333 dm_simplecmd_noflush(DM_DEVICE_RESUME, name);
1338 dm_task_destroy(reload_dmt);
1340 dm_task_destroy(dmt);
1346 * Reassign existing device-mapper table(s) to not use
1347 * the block devices but point to the multipathed
1350 int dm_reassign(const char *mapname)
1352 struct dm_deps *deps;
1353 struct dm_task *dmt;
1354 struct dm_info info;
1355 char dev_t[32], dm_dep[32];
1358 if (dm_dev_t(mapname, &dev_t[0], 32)) {
1359 condlog(3, "%s: failed to get device number", mapname);
1363 if (!(dmt = dm_task_create(DM_DEVICE_DEPS))) {
1364 condlog(3, "%s: couldn't make dm task", mapname);
1368 if (!dm_task_set_name(dmt, mapname))
1371 dm_task_no_open_count(dmt);
1373 if (!dm_task_run(dmt))
1376 if (!dm_task_get_info(dmt, &info))
1379 if (!(deps = dm_task_get_deps(dmt)))
1385 for (i = 0; i < deps->count; i++) {
1386 sprintf(dm_dep, "%d:%d",
1387 major(deps->device[i]),
1388 minor(deps->device[i]));
1389 sysfs_check_holders(dm_dep, dev_t);
1392 dm_task_destroy (dmt);
1399 int dm_setgeometry(struct multipath *mpp)
1401 struct dm_task *dmt;
1403 char heads[4], sectors[4];
1404 char cylinders[10], start[32];
1410 pp = first_path(mpp);
1412 condlog(3, "%s: no path for geometry", mpp->alias);
1415 if (pp->geom.cylinders == 0 ||
1416 pp->geom.heads == 0 ||
1417 pp->geom.sectors == 0) {
1418 condlog(3, "%s: invalid geometry on %s", mpp->alias, pp->dev);
1422 if (!(dmt = dm_task_create(DM_DEVICE_SET_GEOMETRY)))
1425 if (!dm_task_set_name(dmt, mpp->alias))
1428 dm_task_no_open_count(dmt);
1430 /* What a sick interface ... */
1431 snprintf(heads, 4, "%u", pp->geom.heads);
1432 snprintf(sectors, 4, "%u", pp->geom.sectors);
1433 snprintf(cylinders, 10, "%u", pp->geom.cylinders);
1434 snprintf(start, 32, "%lu", pp->geom.start);
1435 if (!dm_task_set_geometry(dmt, cylinders, heads, sectors, start)) {
1436 condlog(3, "%s: Failed to set geometry", mpp->alias);
1440 r = dm_task_run(dmt);
1442 dm_task_destroy(dmt);