static int _detach_pvmove_mirror(struct cmd_context *cmd, struct logical_volume *lv_mirr) { uint32_t mimage_to_remove = 0; struct dm_list lvs_completed; struct lv_list *lvl; /* Update metadata to remove mirror segments and break dependencies */ dm_list_init(&lvs_completed); if (arg_is_set(cmd, abort_ARG) && (seg_type(first_seg(lv_mirr), 0) == AREA_LV)) mimage_to_remove = 1; /* remove the second mirror leg */ if (!lv_remove_mirrors(cmd, lv_mirr, 1, 0, _is_pvmove_image_removable, &mimage_to_remove, PVMOVE) || !remove_layers_for_segments_all(cmd, lv_mirr, PVMOVE, &lvs_completed)) { return 0; } dm_list_iterate_items(lvl, &lvs_completed) /* FIXME Assumes only one pvmove at a time! */ lvl->lv->status &= ~LOCKED; return 1; }
int update_vdo_pool_virtual_size(struct lv_segment *vdo_pool_seg) { struct seg_list *sl; uint32_t extents = 0; /* FIXME: as long as we have only SINGLE VDO with vdo-pool this works */ /* after adding support for multiple VDO LVs - this needs heavy rework */ dm_list_iterate_items(sl, &vdo_pool_seg->lv->segs_using_this_lv) extents += sl->seg->len; /* Only growing virtual/logical VDO size */ if (extents > vdo_pool_seg->vdo_pool_virtual_extents) vdo_pool_seg->vdo_pool_virtual_extents = extents; return 1; }
char *alloc_printed_tags(struct dm_list *tags) { struct str_list *sl; int first = 1; size_t size = 0; char *buffer, *buf; dm_list_iterate_items(sl, tags) /* '"' + tag + '"' + ',' + ' ' */ size += strlen(sl->str) + 4; /* '[' + ']' + '\0' */ size += 3; if (!(buffer = buf = dm_malloc(size))) { log_error("Could not allocate memory for tag list buffer."); return NULL; } if (!emit_to_buffer(&buf, &size, "[")) goto_bad; dm_list_iterate_items(sl, tags) { if (!first) { if (!emit_to_buffer(&buf, &size, ", ")) goto_bad; } else first = 0; if (!emit_to_buffer(&buf, &size, "\"%s\"", sl->str)) goto_bad; } if (!emit_to_buffer(&buf, &size, "]")) goto_bad; return buffer; bad: dm_free(buffer); return_NULL; }
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; }