static int _dm_check_versions(void) { struct dm_task *dmt; struct dm_versions *target, *last_target; if (_dm_crypt_checked) return 1; if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS))) return 0; if (!dm_task_run(dmt)) { dm_task_destroy(dmt); return 0; } target = dm_task_get_versions(dmt); do { last_target = target; if (!strcmp(DM_CRYPT_TARGET, target->name)) { _dm_set_crypt_compat((int)target->version[0], (int)target->version[1], (int)target->version[2]); } target = (void *) target + target->next; } while (last_target != target); dm_task_destroy(dmt); return 1; }
/* * Retrieve list of registered mapping targets. * * dm-library must get inititalized by caller. */ static struct dm_versions * get_target_list(void) { struct dm_task *dmt; return (dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS)) && dm_task_run(dmt) ? dm_task_get_versions(dmt) : NULL; }
int dm_drv_version (unsigned int * version, char * str) { int r = 2; struct dm_task *dmt; struct dm_versions *target; struct dm_versions *last_target; unsigned int *v; version[0] = 0; version[1] = 0; version[2] = 0; if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS))) return 1; dm_task_no_open_count(dmt); if (!dm_task_run(dmt)) { condlog(0, "Can not communicate with kernel DM"); goto out; } target = dm_task_get_versions(dmt); do { last_target = target; if (!strncmp(str, target->name, strlen(str))) { r = 1; break; } target = (void *) target + target->next; } while (last_target != target); if (r == 2) { condlog(0, "DM %s kernel driver not loaded", str); goto out; } v = target->version; version[0] = v[0]; version[1] = v[1]; version[2] = v[2]; r = 0; out: dm_task_destroy(dmt); return r; }
int dm_prereq(char * str, int x, int y, int z) { int r = 1; struct dm_task *dmt; struct dm_versions *target; struct dm_versions *last_target; if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS))) return 1; dm_task_no_open_count(dmt); if (!dm_task_run(dmt)) goto out; target = dm_task_get_versions(dmt); /* Fetch targets and print 'em */ do { last_target = target; if (!strncmp(str, target->name, strlen(str)) && /* dummy prereq on multipath version */ target->version[0] >= x && target->version[1] >= y && target->version[2] >= z ) r = 0; target = (void *) target + target->next; } while (last_target != target); out: dm_task_destroy(dmt); return r; }