1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +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:
Dave Wysochanski 2009-07-27 17:45:21 +00:00
parent ed8031de4f
commit c533b9a305

View File

@ -72,6 +72,10 @@ static void _show_help(void)
"List the VGs that are currently open\n");
printf("'vgs': "
"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']': "
"Issue a lvm_vg_open() API call on VG 'vgname'\n");
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)
{
vg_t *vg;
@ -443,6 +521,10 @@ static int lvmapi_test_shell(lvm_t libh)
break;
} else if (!strcmp(argv[0], "?") || !strcmp(argv[0], "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")) {
_vg_open(argv, argc, libh);
} else if (!strcmp(argv[0], "vg_close")) {