mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-25 10:04:17 +03:00
Update test/api/test.c to include lvm_vg_reduce and lvm_vg_extend.
Author: Dave Wysochanski <dwysocha@redhat.com>
This commit is contained in:
parent
9b367aa0a1
commit
a92bdc094d
@ -72,6 +72,10 @@ static void _show_help(void)
|
|||||||
"List the VGs that are currently open\n");
|
"List the VGs that are currently open\n");
|
||||||
printf("'vgs': "
|
printf("'vgs': "
|
||||||
"List all VGs known to the system\n");
|
"List all VGs known to the system\n");
|
||||||
|
printf("'vg_extend vgname device: "
|
||||||
|
"Issue a lvm_vg_extend() API call on VG 'vgname'\n");
|
||||||
|
printf("'vg_reduce vgname device: "
|
||||||
|
"Issue a lvm_vg_reduce() API call on VG 'vgname'\n");
|
||||||
printf("'vg_open vgname ['r' | 'w']': "
|
printf("'vg_open vgname ['r' | 'w']': "
|
||||||
"Issue a lvm_vg_open() API call on VG 'vgname'\n");
|
"Issue a lvm_vg_open() API call on VG 'vgname'\n");
|
||||||
printf("'vg_close vgname': "
|
printf("'vg_close vgname': "
|
||||||
@ -172,6 +176,80 @@ static void _add_pvs_to_pvname_hash(struct dm_list *pvs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _remove_device_from_pvname_hash(struct dm_list *pvs, const char *name)
|
||||||
|
{
|
||||||
|
struct lvm_pv_list *pvl;
|
||||||
|
dm_list_iterate_items(pvl, pvs) {
|
||||||
|
if (!strncmp(lvm_pv_get_name(pvl->pv), name, strlen(name)))
|
||||||
|
dm_hash_remove(_pvname_hash, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void _add_device_to_pvname_hash(struct dm_list *pvs, const char *name)
|
||||||
|
{
|
||||||
|
struct lvm_pv_list *pvl;
|
||||||
|
dm_list_iterate_items(pvl, pvs) {
|
||||||
|
if (!strncmp(lvm_pv_get_name(pvl->pv), name, strlen(name)))
|
||||||
|
dm_hash_insert(_pvname_hash, name, pvl->pv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void _vg_reduce(char **argv, int argc, lvm_t libh)
|
||||||
|
{
|
||||||
|
vg_t *vg;
|
||||||
|
struct dm_list *pvs;
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
printf ("Please enter vg_name\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(vg = dm_hash_lookup(_vgid_hash, argv[1])) &&
|
||||||
|
!(vg = dm_hash_lookup(_vgname_hash, argv[1]))) {
|
||||||
|
printf ("VG not open\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (lvm_vg_reduce(vg, argv[2])) {
|
||||||
|
printf("Error reducing %s by %s\n", argv[1], argv[2]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Success reducing vg %s by %s\n", argv[1], argv[2]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add the device into the hashes for lookups
|
||||||
|
*/
|
||||||
|
pvs = lvm_vg_list_pvs(vg);
|
||||||
|
if (pvs && !dm_list_empty(pvs))
|
||||||
|
_remove_device_from_pvname_hash(pvs, argv[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _vg_extend(char **argv, int argc, lvm_t libh)
|
||||||
|
{
|
||||||
|
vg_t *vg;
|
||||||
|
struct dm_list *pvs;
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
printf ("Please enter vg_name\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(vg = dm_hash_lookup(_vgid_hash, argv[1])) &&
|
||||||
|
!(vg = dm_hash_lookup(_vgname_hash, argv[1]))) {
|
||||||
|
printf ("VG not open\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (lvm_vg_extend(vg, argv[2])) {
|
||||||
|
printf("Error extending %s with %s\n", argv[1], argv[2]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Success extending vg %s with %s\n", argv[1], argv[2]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add the device into the hashes for lookups
|
||||||
|
*/
|
||||||
|
pvs = lvm_vg_list_pvs(vg);
|
||||||
|
if (pvs && !dm_list_empty(pvs))
|
||||||
|
_add_device_to_pvname_hash(pvs, argv[2]);
|
||||||
|
}
|
||||||
|
|
||||||
static void _vg_open(char **argv, int argc, lvm_t libh)
|
static void _vg_open(char **argv, int argc, lvm_t libh)
|
||||||
{
|
{
|
||||||
vg_t *vg;
|
vg_t *vg;
|
||||||
@ -443,6 +521,10 @@ static int lvmapi_test_shell(lvm_t libh)
|
|||||||
break;
|
break;
|
||||||
} else if (!strcmp(argv[0], "?") || !strcmp(argv[0], "help")) {
|
} else if (!strcmp(argv[0], "?") || !strcmp(argv[0], "help")) {
|
||||||
_show_help();
|
_show_help();
|
||||||
|
} else if (!strcmp(argv[0], "vg_extend")) {
|
||||||
|
_vg_extend(argv, argc, libh);
|
||||||
|
} else if (!strcmp(argv[0], "vg_reduce")) {
|
||||||
|
_vg_reduce(argv, argc, libh);
|
||||||
} else if (!strcmp(argv[0], "vg_open")) {
|
} else if (!strcmp(argv[0], "vg_open")) {
|
||||||
_vg_open(argv, argc, libh);
|
_vg_open(argv, argc, libh);
|
||||||
} else if (!strcmp(argv[0], "vg_close")) {
|
} else if (!strcmp(argv[0], "vg_close")) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user