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) {
307 for (ro = 0; ro <= 1; ro++) {
310 if (dm_addmap(DM_DEVICE_CREATE, TGT_MPATH, mpp, params, 1, ro))
313 * DM_DEVICE_CREATE is actually DM_DEV_CREATE + DM_TABLE_LOAD.
314 * Failing the second part leaves an empty map. Clean it up.
317 if (dm_map_present(mpp->alias)) {
318 condlog(3, "%s: failed to load map (a path might be in use)", mpp->alias);
319 dm_flush_map_nosync(mpp->alias);
331 dm_addmap_reload (struct multipath *mpp, char *params) {
332 if (dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RW))
336 return dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RO);
340 dm_map_present (const char * str)
346 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
349 if (!dm_task_set_name(dmt, str))
352 dm_task_no_open_count(dmt);
354 if (!dm_task_run(dmt))
357 if (!dm_task_get_info(dmt, &info))
363 dm_task_destroy(dmt);
368 dm_get_map(const char * name, unsigned long long * size, char * outparams)
373 uint64_t start, length;
374 char *target_type = NULL;
377 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
380 if (!dm_task_set_name(dmt, name))
383 dm_task_no_open_count(dmt);
385 if (!dm_task_run(dmt))
388 /* Fetch 1st target */
389 next = dm_get_next_target(dmt, next, &start, &length,
390 &target_type, ¶ms);
399 if (snprintf(outparams, PARAMS_SIZE, "%s", params) <= PARAMS_SIZE)
402 dm_task_destroy(dmt);
407 dm_get_prefixed_uuid(const char *name, char *uuid)
413 dmt = dm_task_create(DM_DEVICE_INFO);
417 if (!dm_task_set_name (dmt, name))
420 if (!dm_task_run(dmt))
423 uuidtmp = dm_task_get_uuid(dmt);
425 strcpy(uuid, uuidtmp);
431 dm_task_destroy(dmt);
436 dm_get_uuid(char *name, char *uuid)
438 char uuidtmp[WWID_SIZE];
440 if (dm_get_prefixed_uuid(name, uuidtmp))
443 if (!strncmp(uuidtmp, UUID_PREFIX, UUID_PREFIX_LEN))
444 strcpy(uuid, uuidtmp + UUID_PREFIX_LEN);
446 strcpy(uuid, uuidtmp);
453 * 0 : if both uuids end with same suffix which starts with UUID_PREFIX
457 dm_compare_uuid(const char* mapname1, const char* mapname2)
460 char uuid1[WWID_SIZE], uuid2[WWID_SIZE];
462 if (dm_get_prefixed_uuid(mapname1, uuid1))
465 if (dm_get_prefixed_uuid(mapname2, uuid2))
468 p1 = strstr(uuid1, UUID_PREFIX);
469 p2 = strstr(uuid2, UUID_PREFIX);
470 if (p1 && p2 && !strcmp(p1, p2))
477 dm_get_status(char * name, char * outstatus)
482 uint64_t start, length;
486 if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
489 if (!dm_task_set_name(dmt, name))
492 dm_task_no_open_count(dmt);
494 if (!dm_task_run(dmt))
497 /* Fetch 1st target */
498 next = dm_get_next_target(dmt, next, &start, &length,
499 &target_type, &status);
501 if (snprintf(outstatus, PARAMS_SIZE, "%s", status) <= PARAMS_SIZE)
505 condlog(0, "%s: error getting map status string", name);
507 dm_task_destroy(dmt);
518 dm_type(const char * name, char * type)
523 uint64_t start, length;
524 char *target_type = NULL;
527 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
530 if (!dm_task_set_name(dmt, name))
533 dm_task_no_open_count(dmt);
535 if (!dm_task_run(dmt))
538 /* Fetch 1st target */
539 next = dm_get_next_target(dmt, next, &start, &length,
540 &target_type, ¶ms);
544 else if (!strcmp(target_type, type))
548 dm_task_destroy(dmt);
553 dm_dev_t (const char * mapname, char * dev_t, int len)
559 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
562 if (!dm_task_set_name(dmt, mapname))
565 if (!dm_task_run(dmt))
568 if (!dm_task_get_info(dmt, &info))
572 if (snprintf(dev_t, len, "%i:%i", info.major, info.minor) > len)
577 dm_task_destroy(dmt);
582 dm_get_opencount (const char * mapname)
588 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
591 if (!dm_task_set_name(dmt, mapname))
594 if (!dm_task_run(dmt))
597 if (!dm_task_get_info(dmt, &info))
602 dm_task_destroy(dmt);
607 dm_get_major (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_minor (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_flush_map (const char * mapname, int need_sync)
661 if (!dm_map_present(mapname))
664 if (dm_type(mapname, TGT_MPATH) <= 0)
665 return 0; /* nothing to do */
667 if (dm_remove_partmaps(mapname, need_sync))
670 if (dm_get_opencount(mapname)) {
671 condlog(2, "%s: map in use", mapname);
675 r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname, need_sync);
678 condlog(4, "multipath map %s removed", mapname);
685 dm_suspend_and_flush_map (const char * mapname)
687 int s = 0, queue_if_no_path = 0;
688 unsigned long long mapsize;
689 char params[PARAMS_SIZE] = {0};
691 if (!dm_map_present(mapname))
694 if (dm_type(mapname, TGT_MPATH) <= 0)
695 return 0; /* nothing to do */
697 if (!dm_get_map(mapname, &mapsize, params)) {
698 if (strstr(params, "queue_if_no_path"))
699 queue_if_no_path = 1;
702 if (queue_if_no_path)
703 s = dm_queue_if_no_path((char *)mapname, 0);
704 /* Leave queue_if_no_path alone if unset failed */
706 queue_if_no_path = 0;
708 s = dm_simplecmd_flush(DM_DEVICE_SUSPEND, mapname, 0);
710 if (!dm_flush_map(mapname)) {
711 condlog(4, "multipath map %s removed", mapname);
714 condlog(2, "failed to remove multipath map %s", mapname);
715 dm_simplecmd_noflush(DM_DEVICE_RESUME, mapname);
716 if (queue_if_no_path)
717 s = dm_queue_if_no_path((char *)mapname, 1);
726 struct dm_names *names;
729 if (!(dmt = dm_task_create (DM_DEVICE_LIST)))
732 dm_task_no_open_count(dmt);
734 if (!dm_task_run (dmt))
737 if (!(names = dm_task_get_names (dmt)))
744 r |= dm_suspend_and_flush_map(names->name);
746 names = (void *) names + next;
750 dm_task_destroy (dmt);
755 dm_message(char * mapname, char * message)
760 if (!(dmt = dm_task_create(DM_DEVICE_TARGET_MSG)))
763 if (!dm_task_set_name(dmt, mapname))
766 if (!dm_task_set_sector(dmt, 0))
769 if (!dm_task_set_message(dmt, message))
772 dm_task_no_open_count(dmt);
774 if (!dm_task_run(dmt))
780 condlog(0, "DM message failed [%s]", message);
782 dm_task_destroy(dmt);
787 dm_fail_path(char * mapname, char * path)
791 if (snprintf(message, 32, "fail_path %s", path) > 32)
794 return dm_message(mapname, message);
798 dm_reinstate_path(char * mapname, char * path)
802 if (snprintf(message, 32, "reinstate_path %s", path) > 32)
805 return dm_message(mapname, message);
809 dm_queue_if_no_path(char *mapname, int enable)
814 message = "queue_if_no_path";
816 message = "fail_if_no_path";
818 return dm_message(mapname, message);
822 dm_groupmsg (char * msg, char * mapname, int index)
826 if (snprintf(message, 32, "%s_group %i", msg, index) > 32)
829 return dm_message(mapname, message);
833 dm_switchgroup(char * mapname, int index)
835 return dm_groupmsg("switch", mapname, index);
839 dm_enablegroup(char * mapname, int index)
841 return dm_groupmsg("enable", mapname, index);
845 dm_disablegroup(char * mapname, int index)
847 return dm_groupmsg("disable", mapname, index);
851 dm_get_maps (vector mp)
853 struct multipath * mpp;
857 struct dm_names *names;
863 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
866 dm_task_no_open_count(dmt);
868 if (!dm_task_run(dmt))
871 if (!(names = dm_task_get_names(dmt)))
875 r = 0; /* this is perfectly valid */
880 info = dm_type(names->name, TGT_MPATH);
885 mpp = alloc_multipath();
890 mpp->alias = STRDUP(names->name);
896 if (dm_get_map(names->name, &mpp->size, NULL))
899 dm_get_uuid(names->name, mpp->wwid);
900 dm_get_info(names->name, &mpp->dmi);
903 if (!vector_alloc_slot(mp))
906 vector_set_slot(mp, mpp);
910 names = (void *) names + next;
916 free_multipath(mpp, KEEP_PATHS);
918 dm_task_destroy (dmt);
923 dm_geteventnr (char *name)
929 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
932 if (!dm_task_set_name(dmt, name))
935 dm_task_no_open_count(dmt);
937 if (!dm_task_run(dmt))
940 if (!dm_task_get_info(dmt, &info))
944 event = info.event_nr;
947 dm_task_destroy(dmt);
953 dm_mapname(int major, int minor)
955 char * response = NULL;
959 int loop = MAX_WAIT * LOOPS_PER_SEC;
961 if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
964 if (!dm_task_set_major(dmt, major) ||
965 !dm_task_set_minor(dmt, minor))
968 dm_task_no_open_count(dmt);
971 * device map might not be ready when we get here from
972 * daemon uev_trigger -> uev_add_map
975 r = dm_task_run(dmt);
980 usleep(1000 * 1000 / LOOPS_PER_SEC);
984 condlog(0, "%i:%i: timeout fetching map name", major, minor);
988 map = dm_task_get_name(dmt);
989 if (map && strlen(map))
990 response = STRDUP((char *)dm_task_get_name(dmt));
992 dm_task_destroy(dmt);
995 dm_task_destroy(dmt);
996 condlog(0, "%i:%i: error fetching map name", major, minor);
1001 dm_remove_partmaps (const char * mapname, int need_sync)
1003 struct dm_task *dmt;
1004 struct dm_names *names;
1006 char params[PARAMS_SIZE];
1007 unsigned long long size;
1011 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
1014 dm_task_no_open_count(dmt);
1016 if (!dm_task_run(dmt))
1019 if (!(names = dm_task_get_names(dmt)))
1023 r = 0; /* this is perfectly valid */
1027 if (dm_dev_t(mapname, &dev_t[0], 32))
1033 * if devmap target is "linear"
1035 (dm_type(names->name, TGT_PART) > 0) &&
1038 * and both uuid end with same suffix starting
1041 (!dm_compare_uuid(names->name, mapname)) &&
1044 * and we can fetch the map table from the kernel
1046 !dm_get_map(names->name, &size, ¶ms[0]) &&
1049 * and the table maps over the multipath map
1051 strstr(params, dev_t)
1054 * then it's a kpartx generated partition.
1058 * if the opencount is 0 maybe some other
1059 * partitions depend on it.
1061 if (dm_get_opencount(names->name)) {
1062 dm_remove_partmaps(names->name, need_sync);
1063 if (dm_get_opencount(names->name)) {
1064 condlog(2, "%s: map in use",
1069 condlog(4, "partition map %s removed",
1071 dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name,
1076 names = (void *) names + next;
1081 dm_task_destroy (dmt);
1085 static struct dm_info *
1088 return MALLOC(sizeof(struct dm_info));
1092 dm_get_info (char * mapname, struct dm_info ** dmi)
1095 struct dm_task *dmt = NULL;
1101 *dmi = alloc_dminfo();
1106 if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
1109 if (!dm_task_set_name(dmt, mapname))
1112 dm_task_no_open_count(dmt);
1114 if (!dm_task_run(dmt))
1117 if (!dm_task_get_info(dmt, *dmi))
1123 memset(*dmi, 0, sizeof(struct dm_info));
1129 dm_task_destroy(dmt);
1135 dm_rename_partmaps (char * old, char * new)
1137 struct dm_task *dmt;
1138 struct dm_names *names;
1140 char buff[PARAMS_SIZE];
1141 unsigned long long size;
1145 if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
1148 dm_task_no_open_count(dmt);
1150 if (!dm_task_run(dmt))
1153 if (!(names = dm_task_get_names(dmt)))
1157 r = 0; /* this is perfectly valid */
1161 if (dm_dev_t(old, &dev_t[0], 32))
1167 * if devmap target is "linear"
1169 (dm_type(names->name, TGT_PART) > 0) &&
1172 * and the multipath mapname and the part mapname start
1175 !strncmp(names->name, old, strlen(old)) &&
1178 * and we can fetch the map table from the kernel
1180 !dm_get_map(names->name, &size, &buff[0]) &&
1183 * and the table maps over the multipath map
1188 * then it's a kpartx generated partition.
1191 snprintf(buff, PARAMS_SIZE, "%s%s",
1192 new, names->name + strlen(old));
1193 dm_rename(names->name, buff);
1194 condlog(4, "partition map %s renamed",
1199 names = (void *) names + next;
1204 dm_task_destroy (dmt);
1209 dm_rename (char * old, char * new)
1212 struct dm_task *dmt;
1214 if (dm_rename_partmaps(old, new))
1217 if (!(dmt = dm_task_create(DM_DEVICE_RENAME)))
1220 if (!dm_task_set_name(dmt, old))
1223 if (!dm_task_set_newname(dmt, new))
1226 dm_task_no_open_count(dmt);
1228 if (!dm_task_set_cookie(dmt, &conf->cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
1230 if (!dm_task_run(dmt))
1235 dm_task_destroy(dmt);
1239 void dm_reassign_deps(char *table, char *dep, char *newdep)
1242 char newtable[PARAMS_SIZE];
1244 strcpy(newtable, table);
1245 p = strstr(newtable, dep);
1246 n = table + (p - newtable);
1248 n += strlen(newdep);
1253 int dm_reassign_table(const char *name, char *old, char *new)
1255 int r, modified = 0;
1256 uint64_t start, length;
1257 struct dm_task *dmt, *reload_dmt;
1258 char *target, *params = NULL;
1259 char buff[PARAMS_SIZE];
1262 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
1265 if (!dm_task_set_name(dmt, name))
1268 dm_task_no_open_count(dmt);
1270 if (!dm_task_run(dmt))
1272 if (!(reload_dmt = dm_task_create(DM_DEVICE_RELOAD)))
1274 if (!dm_task_set_name(reload_dmt, name))
1278 next = dm_get_next_target(dmt, next, &start, &length,
1280 memset(buff, 0, PARAMS_SIZE);
1281 strcpy(buff, params);
1282 if (strcmp(target, TGT_MPATH) && strstr(params, old)) {
1283 condlog(3, "%s: replace target %s %s",
1284 name, target, buff);
1285 dm_reassign_deps(buff, old, new);
1286 condlog(3, "%s: with target %s %s",
1287 name, target, buff);
1290 dm_task_add_target(reload_dmt, start, length, target, buff);
1294 dm_task_no_open_count(reload_dmt);
1296 if (!dm_task_run(reload_dmt)) {
1297 condlog(3, "%s: failed to reassign targets", name);
1300 dm_simplecmd_noflush(DM_DEVICE_RESUME, name);
1305 dm_task_destroy(reload_dmt);
1307 dm_task_destroy(dmt);
1313 * Reassign existing device-mapper table(s) to not use
1314 * the block devices but point to the multipathed
1317 int dm_reassign(const char *mapname)
1319 struct dm_deps *deps;
1320 struct dm_task *dmt;
1321 struct dm_info info;
1322 char dev_t[32], dm_dep[32];
1325 if (dm_dev_t(mapname, &dev_t[0], 32)) {
1326 condlog(3, "%s: failed to get device number", mapname);
1330 if (!(dmt = dm_task_create(DM_DEVICE_DEPS))) {
1331 condlog(3, "%s: couldn't make dm task", mapname);
1335 if (!dm_task_set_name(dmt, mapname))
1338 dm_task_no_open_count(dmt);
1340 if (!dm_task_run(dmt))
1343 if (!dm_task_get_info(dmt, &info))
1346 if (!(deps = dm_task_get_deps(dmt)))
1352 for (i = 0; i < deps->count; i++) {
1353 sprintf(dm_dep, "%d:%d",
1354 major(deps->device[i]),
1355 minor(deps->device[i]));
1356 sysfs_check_holders(dm_dep, dev_t);
1359 dm_task_destroy (dmt);
1366 int dm_setgeometry(struct multipath *mpp)
1368 struct dm_task *dmt;
1370 char heads[4], sectors[4];
1371 char cylinders[10], start[32];
1377 pp = first_path(mpp);
1379 condlog(3, "%s: no path for geometry", mpp->alias);
1382 if (pp->geom.cylinders == 0 ||
1383 pp->geom.heads == 0 ||
1384 pp->geom.sectors == 0) {
1385 condlog(3, "%s: invalid geometry on %s", mpp->alias, pp->dev);
1389 if (!(dmt = dm_task_create(DM_DEVICE_SET_GEOMETRY)))
1392 if (!dm_task_set_name(dmt, mpp->alias))
1395 dm_task_no_open_count(dmt);
1397 /* What a sick interface ... */
1398 snprintf(heads, 4, "%u", pp->geom.heads);
1399 snprintf(sectors, 4, "%u", pp->geom.sectors);
1400 snprintf(cylinders, 10, "%u", pp->geom.cylinders);
1401 snprintf(start, 32, "%lu", pp->geom.start);
1402 if (!dm_task_set_geometry(dmt, cylinders, heads, sectors, start)) {
1403 condlog(3, "%s: Failed to set geometry", mpp->alias);
1407 r = dm_task_run(dmt);
1409 dm_task_destroy(dmt);