int main(int argc, char *argv[]) { lvm_t handle; vg_t vg = NULL; pv_t pv; struct lvm_property_value v; handle = lvm_init(NULL); assert(handle); vg = lvm_vg_create(handle, argv[1]); assert(vg); if (lvm_vg_extend(vg, argv[2])) abort(); pv = lvm_pv_from_name(vg, argv[2]); assert(pv); v = lvm_pv_get_property(pv, "pe_start"); assert(v.is_valid); fprintf(stderr, "pe_start = %d\n", (int)v.value.integer); assert(v.value.integer == 2048 * 512); lvm_vg_close(vg); lvm_quit(handle); return 0; }
static lvm_t _lvm_init(const char *system_dir) { struct cmd_context *cmd; /* FIXME: logging bound to handle */ if (!udev_init_library_context()) stack; /* * It's not necessary to use name mangling for LVM: * - the character set used for VG-LV names is subset of udev character set * - when we check other devices (e.g. device_is_usable fn), we use major:minor, not dm names */ dm_set_name_mangling_mode(DM_STRING_MANGLING_NONE); /* create context */ /* FIXME: split create_toolcontext */ /* FIXME: make all globals configurable */ cmd = create_toolcontext(0, system_dir, 0, 0, 1, 1); if (!cmd) return NULL; if (stored_errno()) return (lvm_t) cmd; /* * FIXME: if an non memory error occured, return the cmd (maybe some * cleanup needed). */ /* initialization from lvm_run_command */ init_error_message_produced(0); /* FIXME: locking_type config option needed? */ /* initialize locking */ if (!init_locking(-1, cmd, 0)) { /* FIXME: use EAGAIN as error code here */ lvm_quit((lvm_t) cmd); return NULL; } /* * FIXME: Use cmd->cmd_line as audit trail for liblvm calls. Used in * archive() call. Possible example: * cmd_line = "lvm_vg_create: vg1\nlvm_vg_extend vg1 /dev/sda1\n" */ cmd->cmd_line = "liblvm"; /* * Turn off writing to stdout/stderr. * FIXME Fix lib/ to support a non-interactive mode instead. */ log_suppress(1); return (lvm_t) cmd; }
static void done(int ok) { if (handle && lvm_errno(handle)) { fprintf(stderr, "LVM Error: %s\n", lvm_errmsg(handle)); ok = 0; } if (handle) lvm_quit(handle); if (!ok) abort(); }
static PyObject *_liblvm_lvm_gc(void) { if (_libh) { lvm_quit(_libh); _libh = NULL; } Py_INCREF(Py_None); return Py_None; }
lvm_t lvm_init(const char *system_dir) { struct cmd_context *cmd; /* FIXME: logging bound to handle */ if (!udev_init_library_context()) stack; /* create context */ /* FIXME: split create_toolcontext */ /* FIXME: make all globals configurable */ cmd = create_toolcontext(0, system_dir, 0, 0); if (!cmd) return NULL; if (stored_errno()) return (lvm_t) cmd; /* * FIXME: if an non memory error occured, return the cmd (maybe some * cleanup needed). */ /* initialization from lvm_run_command */ init_error_message_produced(0); /* FIXME: locking_type config option needed? */ /* initialize locking */ if (!init_locking(-1, cmd, 0)) { /* FIXME: use EAGAIN as error code here */ lvm_quit((lvm_t) cmd); return NULL; } /* * FIXME: Use cmd->cmd_line as audit trail for liblvm calls. Used in * archive() call. Possible example: * cmd_line = "lvm_vg_create: vg1\nlvm_vg_extend vg1 /dev/sda1\n" */ cmd->cmd_line = "liblvm"; /* * Turn off writing to stdout/stderr. * FIXME Fix lib/ to support a non-interactive mode instead. */ log_suppress(1); return (lvm_t) cmd; }
static int lvm_uses_lvmetad(void) { lvm_t lvm; int r; if (!(lvm = lvm_init(NULL))) { kmsg(LOG_ERR, "LVM: Failed to initialize library context for activation generator.\n"); return 0; } r = lvm_config_find_bool(lvm, LVM_CONF_USE_LVMETAD, 0); lvm_quit(lvm); return r; }
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; }