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);
101 #define VERSION_GE(v, minv) ( \
102 (v[0] > minv[0]) || \
103 ((v[0] == minv[0]) && (v[1] > minv[1])) || \
104 ((v[0] == minv[0]) && (v[1] == minv[1]) && (v[2] >= minv[2])) \
112 #ifdef LIBDM_API_COOKIE
113 int minv[3] = {1, 2, 38};
115 int minv[3] = {1, 2, 8};
118 dm_get_library_version(version, sizeof(version));
119 condlog(3, "libdevmapper version %s", version);
120 sscanf(version, "%d.%d.%d ", &v[0], &v[1], &v[2]);
122 if VERSION_GE(v, minv)
124 condlog(0, "libdevmapper version must be >= %d.%.2d.%.2d",
125 minv[0], minv[1], minv[2]);
130 dm_drv_version (unsigned int * version, char * str)
134 struct dm_versions *target;
135 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_dmrq[3] = {1, 1, 0};
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 least capable */
184 /* test request based multipath capability */
185 if VERSION_GE(v, minv_dmrq) {
186 condlog(3, "activate request-based multipathing mode "
187 "(driver >= v%u.%u.%u)",
188 minv_dmrq[0], minv_dmrq[1], minv_dmrq[2]);
197 unsigned int minv[3] = {1, 0, 3};
198 unsigned int version[3] = {0, 0, 0};
199 unsigned int * v = version;
201 if (dm_drv_version(v, TGT_MPATH)) {
202 /* in doubt return not capable */
206 /* test request based multipath capability */
207 condlog(3, "DM multipath kernel driver v%u.%u.%u",
210 if VERSION_GE(v, minv)
213 condlog(0, "DM multipath kernel driver must be >= v%u.%u.%u",
214 minv[0], minv[1], minv[2]);
223 return dm_drv_prereq();
227 dm_simplecmd (int task, const char *name, int no_flush, int need_sync) {
229 int udev_wait_flag = (need_sync && (task == DM_DEVICE_RESUME ||
230 task == DM_DEVICE_REMOVE));
233 if (!(dmt = dm_task_create (task)))
236 if (!dm_task_set_name (dmt, name))
239 dm_task_no_open_count(dmt);
240 dm_task_skip_lockfs(dmt); /* for DM_DEVICE_RESUME */
241 #ifdef LIBDM_API_FLUSH
243 dm_task_no_flush(dmt); /* for DM_DEVICE_SUSPEND/RESUME */
246 if (udev_wait_flag && !dm_task_set_cookie(dmt, &conf->cookie, 0))
248 r = dm_task_run (dmt);
251 dm_task_destroy (dmt);
256 dm_simplecmd_flush (int task, const char *name, int needsync) {
257 return dm_simplecmd(task, name, 0, needsync);
261 dm_simplecmd_noflush (int task, const char *name) {
262 return dm_simplecmd(task, name, 1, 1);
266 dm_addmap (int task, const char *target, struct multipath *mpp, char * params,
267 int use_uuid, int ro) {
270 char *prefixed_uuid = NULL;
272 if (!(dmt = dm_task_create (task)))
275 if (!dm_task_set_name (dmt, mpp->alias))
278 if (!dm_task_add_target (dmt, 0, mpp->size, target, params))
284 if (use_uuid && mpp->wwid){
285 prefixed_uuid = MALLOC(UUID_PREFIX_LEN + strlen(mpp->wwid) + 1);
286 if (!prefixed_uuid) {
287 condlog(0, "cannot create prefixed uuid : %s\n",
291 sprintf(prefixed_uuid, UUID_PREFIX "%s", mpp->wwid);
292 if (!dm_task_set_uuid(dmt, prefixed_uuid))
296 if (mpp->attribute_flags & (1 << ATTR_MODE) &&
297 !dm_task_set_mode(dmt, mpp->mode))
299 if (mpp->attribute_flags & (1 << ATTR_UID) &&
300 !dm_task_set_uid(dmt, mpp->uid))
302 if (mpp->attribute_flags & (1 << ATTR_GID) &&
303 !dm_task_set_gid(dmt, mpp->gid))
305 condlog(4, "%s: addmap [0 %llu %s %s]\n", mpp->alias, mpp->size,
308 dm_task_no_open_count(dmt);
310 if (task == DM_DEVICE_CREATE &&
311 !dm_task_set_cookie(dmt, &conf->cookie, 0))
313 r = dm_task_run (dmt);
320 dm_task_destroy (dmt);
326 _dm_addmap_create (struct multipath *mpp, char * params, int ro) {
328 r = dm_addmap(DM_DEVICE_CREATE, TGT_MPATH, mpp, params, 1, ro);
330 * DM_DEVICE_CREATE is actually DM_DEV_CREATE + DM_TABLE_LOAD.
331 * Failing the second part leaves an empty map. Clean it up.
333 if (!r && dm_map_present(mpp->alias)) {
334 condlog(3, "%s: failed to load map (a path might be in use)",
336 dm_flush_map_nosync(mpp->alias);
345 dm_addmap_create (struct multipath *mpp, char *params) {
346 return _dm_addmap_create(mpp, params, ADDMAP_RW);
350 dm_addmap_create_ro (struct multipath *mpp, char *params) {
351 return _dm_addmap_create(mpp, params, ADDMAP_RO);
355 dm_addmap_reload (struct multipath *mpp, char *params) {
356 return dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RW);
360 dm_addmap_reload_ro (struct multipath *mpp, char *params) {
361 return dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RO);
365 dm_map_present (const char * str)
371 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
374 if (!dm_task_set_name(dmt, str))
377 dm_task_no_open_count(dmt);
379 if (!dm_task_run(dmt))
382 if (!dm_task_get_info(dmt, &info))
388 dm_task_destroy(dmt);
393 dm_get_map(char * name, unsigned long long * size, char * outparams)
398 uint64_t start, length;
399 char *target_type = NULL;
402 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
405 if (!dm_task_set_name(dmt, name))
408 dm_task_no_open_count(dmt);
410 if (!dm_task_run(dmt))
413 /* Fetch 1st target */
414 next = dm_get_next_target(dmt, next, &start, &length,
415 &target_type, ¶ms);
424 if (snprintf(outparams, PARAMS_SIZE, "%s", params) <= PARAMS_SIZE)
427 dm_task_destroy(dmt);
432 dm_get_prefixed_uuid(const char *name, char *uuid)
438 dmt = dm_task_create(DM_DEVICE_INFO);
442 if (!dm_task_set_name (dmt, name))
445 if (!dm_task_run(dmt))
448 uuidtmp = dm_task_get_uuid(dmt);
450 strcpy(uuid, uuidtmp);
456 dm_task_destroy(dmt);
461 dm_get_uuid(char *name, char *uuid)
463 char uuidtmp[WWID_SIZE];
465 if (dm_get_prefixed_uuid(name, uuidtmp))
468 if (!strncmp(uuidtmp, UUID_PREFIX, UUID_PREFIX_LEN))
469 strcpy(uuid, uuidtmp + UUID_PREFIX_LEN);
471 strcpy(uuid, uuidtmp);
478 * 0 : if both uuids end with same suffix which starts with UUID_PREFIX
482 dm_compare_uuid(const char* mapname1, const char* mapname2)
485 char uuid1[WWID_SIZE], uuid2[WWID_SIZE];
487 if (dm_get_prefixed_uuid(mapname1, uuid1))
490 if (dm_get_prefixed_uuid(mapname2, uuid2))
493 p1 = strstr(uuid1, UUID_PREFIX);
494 p2 = strstr(uuid2, UUID_PREFIX);
495 if (p1 && p2 && !strcmp(p1, p2))
502 dm_get_status(char * name, char * outstatus)
507 uint64_t start, length;
511 if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
514 if (!dm_task_set_name(dmt, name))
517 dm_task_no_open_count(dmt);
519 if (!dm_task_run(dmt))
522 /* Fetch 1st target */
523 next = dm_get_next_target(dmt, next, &start, &length,
524 &target_type, &status);
526 if (snprintf(outstatus, PARAMS_SIZE, "%s", status) <= PARAMS_SIZE)
530 condlog(0, "%s: error getting map status string", name);
532 dm_task_destroy(dmt);
543 dm_type(const char * name, char * type)
548 uint64_t start, length;
549 char *target_type = NULL;
552 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
555 if (!dm_task_set_name(dmt, name))
558 dm_task_no_open_count(dmt);
560 if (!dm_task_run(dmt))
563 /* Fetch 1st target */
564 next = dm_get_next_target(dmt, next, &start, &length,
565 &target_type, ¶ms);
569 else if (!strcmp(target_type, type))
573 dm_task_destroy(dmt);
578 dm_dev_t (const char * mapname, char * dev_t, int len)
584 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
587 if (!dm_task_set_name(dmt, mapname))
590 if (!dm_task_run(dmt))
593 if (!dm_task_get_info(dmt, &info))
597 if (snprintf(dev_t, len, "%i:%i", info.major, info.minor) > len)
602 dm_task_destroy(dmt);
607 dm_get_opencount (const char * mapname)
613 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
616 if (!dm_task_set_name(dmt, mapname))
619 if (!dm_task_run(dmt))
622 if (!dm_task_get_info(dmt, &info))
627 dm_task_destroy(dmt);
632 dm_get_major (char * mapname)
638 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
641 if (!dm_task_set_name(dmt, mapname))
644 if (!dm_task_run(dmt))
647 if (!dm_task_get_info(dmt, &info))
652 dm_task_destroy(dmt);
657 dm_get_minor (char * mapname)
663 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
666 if (!dm_task_set_name(dmt, mapname))
669 if (!dm_task_run(dmt))
672 if (!dm_task_get_info(dmt, &info))
677 dm_task_destroy(dmt);
682 _dm_flush_map (const char * mapname, int need_sync)
686 if (!dm_map_present(mapname))
689 if (dm_type(mapname, TGT_MPATH) <= 0)
690 return 0; /* nothing to do */
692 if (dm_remove_partmaps(mapname, need_sync))
695 if (dm_get_opencount(mapname)) {
696 condlog(2, "%s: map in use", mapname);
700 r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname, need_sync);
703 condlog(4, "multipath map %s removed", 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_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\n", path) > 32)
782 return dm_message(mapname, message);
786 dm_reinstate_path(char * mapname, char * path)
790 if (snprintf(message, 32, "reinstate_path %s\n", path) > 32)
793 return dm_message(mapname, message);
797 dm_queue_if_no_path(char *mapname, int enable)
802 message = "queue_if_no_path\n";
804 message = "fail_if_no_path\n";
806 return dm_message(mapname, message);
810 dm_set_pg_timeout(char *mapname, int timeout_val)
814 if (snprintf(message, 24, "set_pg_timeout %d", timeout_val) >= 24)
816 return dm_message(mapname, message);
820 dm_groupmsg (char * msg, char * mapname, int index)
824 if (snprintf(message, 32, "%s_group %i\n", msg, index) > 32)
827 return dm_message(mapname, message);
831 dm_switchgroup(char * mapname, int index)
833 return dm_groupmsg("switch", mapname, index);
837 dm_enablegroup(char * mapname, int index)
839 return dm_groupmsg("enable", mapname, index);
843 dm_disablegroup(char * mapname, int index)
845 return dm_groupmsg("disable", mapname, index);
849 dm_get_maps (vector mp)
851 struct multipath * mpp;
855 struct dm_names *names;
861 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
864 dm_task_no_open_count(dmt);
866 if (!dm_task_run(dmt))
869 if (!(names = dm_task_get_names(dmt)))
873 r = 0; /* this is perfectly valid */
878 info = dm_type(names->name, TGT_MPATH);
883 mpp = alloc_multipath();
888 mpp->alias = STRDUP(names->name);
894 if (dm_get_map(names->name, &mpp->size, NULL))
897 dm_get_uuid(names->name, mpp->wwid);
898 dm_get_info(names->name, &mpp->dmi);
901 if (!vector_alloc_slot(mp))
904 vector_set_slot(mp, mpp);
908 names = (void *) names + next;
914 free_multipath(mpp, KEEP_PATHS);
916 dm_task_destroy (dmt);
921 dm_get_name(char *uuid)
925 char *prefixed_uuid, *name = NULL;
928 dmt = dm_task_create(DM_DEVICE_INFO);
932 prefixed_uuid = MALLOC(UUID_PREFIX_LEN + strlen(uuid) + 1);
933 if (!prefixed_uuid) {
934 condlog(0, "cannot create prefixed uuid : %s\n",
938 sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid);
939 if (!dm_task_set_uuid(dmt, prefixed_uuid))
942 if (!dm_task_run(dmt))
945 if (!dm_task_get_info(dmt, &info) || !info.exists)
948 nametmp = dm_task_get_name(dmt);
949 if (nametmp && strlen(nametmp)) {
950 name = MALLOC(strlen(nametmp) + 1);
952 strcpy(name, nametmp);
954 condlog(2, "%s: no device-mapper name found", uuid);
960 dm_task_destroy(dmt);
966 dm_geteventnr (char *name)
972 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
975 if (!dm_task_set_name(dmt, name))
978 dm_task_no_open_count(dmt);
980 if (!dm_task_run(dmt))
983 if (!dm_task_get_info(dmt, &info))
987 event = info.event_nr;
990 dm_task_destroy(dmt);
996 dm_mapname(int major, int minor)
998 char * response = NULL;
1000 struct dm_task *dmt;
1002 int loop = MAX_WAIT * LOOPS_PER_SEC;
1004 if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
1007 if (!dm_task_set_major(dmt, major) ||
1008 !dm_task_set_minor(dmt, minor))
1011 dm_task_no_open_count(dmt);
1014 * device map might not be ready when we get here from
1015 * daemon uev_trigger -> uev_add_map
1018 r = dm_task_run(dmt);
1023 usleep(1000 * 1000 / LOOPS_PER_SEC);
1027 condlog(0, "%i:%i: timeout fetching map name", major, minor);
1031 map = dm_task_get_name(dmt);
1032 if (map && strlen(map))
1033 response = STRDUP((char *)dm_task_get_name(dmt));
1035 dm_task_destroy(dmt);
1038 dm_task_destroy(dmt);
1039 condlog(0, "%i:%i: error fetching map name", major, minor);
1044 dm_remove_partmaps (const char * mapname, int need_sync)
1046 struct dm_task *dmt;
1047 struct dm_names *names;
1049 char params[PARAMS_SIZE];
1050 unsigned long long size;
1054 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
1057 dm_task_no_open_count(dmt);
1059 if (!dm_task_run(dmt))
1062 if (!(names = dm_task_get_names(dmt)))
1066 r = 0; /* this is perfectly valid */
1070 if (dm_dev_t(mapname, &dev_t[0], 32))
1076 * if devmap target is "linear"
1078 (dm_type(names->name, TGT_PART) > 0) &&
1081 * and both uuid end with same suffix starting
1084 (!dm_compare_uuid(names->name, mapname)) &&
1087 * and we can fetch the map table from the kernel
1089 !dm_get_map(names->name, &size, ¶ms[0]) &&
1092 * and the table maps over the multipath map
1094 strstr(params, dev_t)
1097 * then it's a kpartx generated partition.
1101 * if the opencount is 0 maybe some other
1102 * partitions depend on it.
1104 if (dm_get_opencount(names->name)) {
1105 dm_remove_partmaps(names->name, need_sync);
1106 if (dm_get_opencount(names->name)) {
1107 condlog(2, "%s: map in use",
1112 condlog(4, "partition map %s removed",
1114 dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name,
1119 names = (void *) names + next;
1124 dm_task_destroy (dmt);
1128 static struct dm_info *
1131 return MALLOC(sizeof(struct dm_info));
1135 dm_get_info (char * mapname, struct dm_info ** dmi)
1138 struct dm_task *dmt = NULL;
1144 *dmi = alloc_dminfo();
1149 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
1152 if (!dm_task_set_name(dmt, mapname))
1155 dm_task_no_open_count(dmt);
1157 if (!dm_task_run(dmt))
1160 if (!dm_task_get_info(dmt, *dmi))
1166 memset(*dmi, 0, sizeof(struct dm_info));
1172 dm_task_destroy(dmt);
1178 dm_rename_partmaps (char * old, char * new)
1180 struct dm_task *dmt;
1181 struct dm_names *names;
1183 char buff[PARAMS_SIZE];
1184 unsigned long long size;
1188 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
1191 dm_task_no_open_count(dmt);
1193 if (!dm_task_run(dmt))
1196 if (!(names = dm_task_get_names(dmt)))
1200 r = 0; /* this is perfectly valid */
1204 if (dm_dev_t(old, &dev_t[0], 32))
1210 * if devmap target is "linear"
1212 (dm_type(names->name, TGT_PART) > 0) &&
1215 * and the multipath mapname and the part mapname start
1218 !strncmp(names->name, old, strlen(old)) &&
1221 * and we can fetch the map table from the kernel
1223 !dm_get_map(names->name, &size, &buff[0]) &&
1226 * and the table maps over the multipath map
1231 * then it's a kpartx generated partition.
1234 snprintf(buff, PARAMS_SIZE, "%s%s",
1235 new, names->name + strlen(old));
1236 dm_rename(names->name, buff);
1237 condlog(4, "partition map %s renamed",
1242 names = (void *) names + next;
1247 dm_task_destroy (dmt);
1252 dm_rename (char * old, char * new)
1255 struct dm_task *dmt;
1257 if (dm_rename_partmaps(old, new))
1260 if (!(dmt = dm_task_create(DM_DEVICE_RENAME)))
1263 if (!dm_task_set_name(dmt, old))
1266 if (!dm_task_set_newname(dmt, new))
1269 dm_task_no_open_count(dmt);
1271 if (!dm_task_set_cookie(dmt, &conf->cookie, 0))
1273 if (!dm_task_run(dmt))
1278 dm_task_destroy(dmt);
1282 void dm_reassign_deps(char *table, char *dep, char *newdep)
1285 char newtable[PARAMS_SIZE];
1287 strcpy(newtable, table);
1288 p = strstr(newtable, dep);
1289 n = table + (p - newtable);
1291 n += strlen(newdep);
1296 int dm_reassign_table(const char *name, char *old, char *new)
1298 int r, modified = 0;
1299 uint64_t start, length;
1300 struct dm_task *dmt, *reload_dmt;
1301 char *target, *params = NULL;
1302 char buff[PARAMS_SIZE];
1305 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
1308 if (!dm_task_set_name(dmt, name))
1311 dm_task_no_open_count(dmt);
1313 if (!dm_task_run(dmt))
1315 if (!(reload_dmt = dm_task_create(DM_DEVICE_RELOAD)))
1317 if (!dm_task_set_name(reload_dmt, name))
1321 next = dm_get_next_target(dmt, next, &start, &length,
1323 memset(buff, 0, PARAMS_SIZE);
1324 strcpy(buff, params);
1325 if (strcmp(target, TGT_MPATH) && strstr(params, old)) {
1326 condlog(3, "%s: replace target %s %s",
1327 name, target, buff);
1328 dm_reassign_deps(buff, old, new);
1329 condlog(3, "%s: with target %s %s",
1330 name, target, buff);
1333 dm_task_add_target(reload_dmt, start, length, target, buff);
1337 dm_task_no_open_count(reload_dmt);
1339 if (!dm_task_run(reload_dmt)) {
1340 condlog(3, "%s: failed to reassign targets", name);
1343 dm_simplecmd_noflush(DM_DEVICE_RESUME, name);
1348 dm_task_destroy(reload_dmt);
1350 dm_task_destroy(dmt);
1356 * Reassign existing device-mapper table(s) to not use
1357 * the block devices but point to the multipathed
1360 int dm_reassign(const char *mapname)
1362 struct dm_deps *deps;
1363 struct dm_task *dmt;
1364 struct dm_info info;
1365 char dev_t[32], dm_dep[32];
1368 if (dm_dev_t(mapname, &dev_t[0], 32)) {
1369 condlog(3, "%s: failed to get device number\n", mapname);
1373 if (!(dmt = dm_task_create(DM_DEVICE_DEPS)))
1376 if (!dm_task_set_name(dmt, mapname))
1379 dm_task_no_open_count(dmt);
1381 if (!dm_task_run(dmt))
1384 if (!dm_task_get_info(dmt, &info))
1387 if (!(deps = dm_task_get_deps(dmt)))
1393 for (i = 0; i < deps->count; i++) {
1394 sprintf(dm_dep, "%d:%d",
1395 major(deps->device[i]),
1396 minor(deps->device[i]));
1397 sysfs_check_holders(dm_dep, dev_t);
1400 dm_task_destroy (dmt);
1407 int dm_setgeometry(struct multipath *mpp)
1409 struct dm_task *dmt;
1411 char heads[4], sectors[4];
1412 char cylinders[10], start[32];
1418 pp = first_path(mpp);
1420 condlog(3, "%s: no path for geometry", mpp->alias);
1423 if (pp->geom.cylinders == 0 ||
1424 pp->geom.heads == 0 ||
1425 pp->geom.sectors == 0) {
1426 condlog(3, "%s: invalid geometry on %s", mpp->alias, pp->dev);
1430 if (!(dmt = dm_task_create(DM_DEVICE_SET_GEOMETRY)))
1433 if (!dm_task_set_name(dmt, mpp->alias))
1436 dm_task_no_open_count(dmt);
1438 /* What a sick interface ... */
1439 snprintf(heads, 4, "%u", pp->geom.heads);
1440 snprintf(sectors, 4, "%u", pp->geom.sectors);
1441 snprintf(cylinders, 10, "%u", pp->geom.cylinders);
1442 snprintf(start, 32, "%lu", pp->geom.start);
1443 if (!dm_task_set_geometry(dmt, cylinders, heads, sectors, start)) {
1444 condlog(3, "%s: Failed to set geometry", mpp->alias);
1448 r = dm_task_run(dmt);
1450 dm_task_destroy(dmt);