int main(int argc, char *argv[]) { lvm_t handle; vg_t vg; lv_t lv; struct lvm_property_value v; handle = lvm_init(NULL); assert(handle); vg = lvm_vg_open(handle, argv[1], "r", 0); assert(vg); lv = lvm_lv_from_name(vg, "pool"); assert(lv); v = lvm_lv_get_property(lv, "data_percent"); assert(v.is_valid); assert(v.value.integer == 25 * PERCENT_1); lv = lvm_lv_from_name(vg, "thin"); assert(lv); v = lvm_lv_get_property(lv, "data_percent"); assert(v.is_valid); assert(v.value.integer == 50 * PERCENT_1); lv = lvm_lv_from_name(vg, "snap"); assert(lv); v = lvm_lv_get_property(lv, "data_percent"); assert(v.is_valid); assert(v.value.integer == 75 * PERCENT_1); v = lvm_lv_get_property(lv, "snap_percent"); assert(v.is_valid); assert(v.value.integer == PERCENT_INVALID); v = lvm_lv_get_property(lv, "origin"); assert(v.is_valid); assert(strcmp(v.value.string, "thin") == 0); lvm_vg_close(vg); lvm_quit(handle); return 0; }
int main(int argc, char *argv[]) { lvm_t handle; vg_t vg = NULL; lv_t lv; struct lvm_property_value v; struct lvm_property_value d; handle = lvm_init(NULL); assert(handle); vg = lvm_vg_open(handle, argv[1], "r", 0); assert(vg); lv = lvm_lv_from_name(vg, "snap"); assert(lv); v = lvm_lv_get_property(lv, "snap_percent"); assert(v.is_valid); assert(v.value.integer == PERCENT_0); lv = lvm_lv_from_name(vg, "mirr"); assert(lv); v = lvm_lv_get_property(lv, "copy_percent"); assert(v.is_valid); assert(v.value.integer == PERCENT_100); lv = lvm_lv_from_name(vg, "snap2"); assert(lv); v = lvm_lv_get_property(lv, "snap_percent"); assert(v.is_valid); assert(v.value.integer == 50 * PERCENT_1); d = lvm_lv_get_property(lv, "data_percent"); assert(d.is_valid); assert(d.value.integer == v.value.integer); lvm_vg_close(vg); lvm_quit(handle); return 0; }
int main(int argc, char *argv[]) { lvm_t handle; vg_t vg; lv_t lv; int r = -1; if (!(handle = lvm_init(NULL))) return -1; if (!(vg = lvm_vg_open(handle, argv[1], "w", 0))) err("VG open %s failed.\n", argv[1]); if (!(lv = lvm_lv_from_name(vg, "test"))) err("LV test not found.\n"); if (lvm_lv_deactivate(lv)) err("LV test deactivation failed.\n"); if (lvm_lv_activate(lv)) err("LV test activation failed.\n"); if (lvm_lv_activate(lv)) err("LV test repeated activation failed.\n"); if (lvm_lv_rename(lv, "test1")) err("LV test rename to test1 failed.\n"); if (lvm_lv_rename(lv, "test2")) err("LV test1 rename to test2 failed.\n"); if (lvm_lv_rename(lv, "test")) err("LV test2 rename to test failed.\n"); if (lvm_vg_close(vg)) err("VG close failed.\n"); r = 0; bad: lvm_quit(handle); return r; }
int main(int argc, char *argv[]) { char* vgName; vgName = argv[1]; uint64_t ans_64; long ans_long; double ans_dbl; int ans_int; int count; lvm_t libh = lvm_init(NULL); if (!libh) { fprintf(stderr, "Error: Unable to open lvm library instance"); abort(); } if (lvm_scan(libh)) { fprintf(stderr, "Error: Unable to find any volume groups"); lvm_quit(libh); abort(); } vg_t vg = lvm_vg_open(libh, vgName, "r", 0); if (vg == NULL) { fprintf(stderr, "Error: Unable to open Volume Group"); lvm_quit(libh); abort(); } int sw_bt = atoi(argv[2]); switch(sw_bt) { case 1: ans_64 = lvm_vg_get_free_size(vg); fprintf(stdout, "Answer: %" PRIu64 "\n", ans_64); break; case 2: ans_dbl = lvm_vg_get_free_size(vg) * 100.0 / lvm_vg_get_size(vg); fprintf(stdout, "Answer: %f \n", ans_dbl); break; case 3: struct dm_list *logical_volumes; struct lvm_lv_list *lv_iter; logical_volumes = lvm_vg_list_lvs(vg); count = 0; dm_list_iterate_items( lv_iter, logical_volumes) count++; ans_int = count; fprintf(stdout, "Answer: %d \n", ans_int); break; case 4: //ret_int(value, vg->getActivePhysicalVolumes()); struct dm_list *phisical_volumes; struct lvm_pv_list *pv_iter; struct lvm_property_value pv_prop; phisical_volumes = lvm_vg_list_pvs(vg); count = 0; dm_list_iterate_items(pv_iter, phisical_volumes) { //if (lvm_pv_get_property(pv_iter->pv, "pv_missing")) // ++ count; pv_prop = lvm_pv_get_property(pv_iter->pv, "pv_missing"); if (!pv_prop.is_valid) { printf("Invalid property name or unable to query" "'%s', errno = %d.\n", "pv_missing", lvm_errno(libh)); printf("%s\n", lvm_errmsg(libh)); return 99; } fprintf(stdout, "Is missing = %" PRIu64 " \n", pv_prop.value); } ans_int = lvm_vg_get_pv_count(vg) - count; fprintf(stdout, "Answer: %d \n", ans_int); break; case 5: ans_int = lvm_vg_get_pv_count(vg); fprintf(stdout, "Answer: %d \n", ans_int); break; case 6: //ret_uint64(value, vg->getPhyPartResync()); ans_64 = 100; fprintf(stdout, "Answer: %" PRIu64 "\n", ans_64); break; case 7: //ret_uint64(value, vg->getPhyPartStale()); ans_64 = 100; fprintf(stdout, "Answer: %" PRIu64 "\n", ans_64); break; case 8: ans_64 = lvm_vg_get_size(vg); fprintf(stdout, "Answer: %" PRIu64 "\n", ans_64); break; case 9: ans_64 = lvm_vg_get_size(vg) - lvm_vg_get_free_size(vg); fprintf(stdout, "Answer: %" PRIu64 "\n", ans_64); break; case 10: ans_dbl = (lvm_vg_get_size(vg) - lvm_vg_get_free_size(vg)) * 100.0 / lvm_vg_get_size(vg); fprintf(stdout, "Answer: %f \n", ans_dbl); break; default: fprintf(stderr, "Error: Usupported"); break; }