public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2/test/api test.c
@ 2011-03-01 23:29 zkabelac
0 siblings, 0 replies; 23+ messages in thread
From: zkabelac @ 2011-03-01 23:29 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: zkabelac@sourceware.org 2011-03-01 23:29:15
Modified files:
test/api : test.c
Log message:
Invert condition for READLINE check
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.35&r2=1.36
--- LVM2/test/api/test.c 2011/03/01 23:18:40 1.35
+++ LVM2/test/api/test.c 2011/03/01 23:29:14 1.36
@@ -21,7 +21,7 @@
#include "configure.h"
#include "lvm2app.h"
-#ifndef READLINE_SUPPORT
+#ifdef READLINE_SUPPORT
#include <readline/readline.h>
#define MAX_ARGS 64
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2011-03-01 23:18 zkabelac
0 siblings, 0 replies; 23+ messages in thread
From: zkabelac @ 2011-03-01 23:18 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: zkabelac@sourceware.org 2011-03-01 23:18:40
Modified files:
test/api : test.c
Log message:
Build test.c also without readline library
Allow bulding of this testing tool also without readline library.
Outputs message about build without readline library then.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.34&r2=1.35
--- LVM2/test/api/test.c 2010/11/25 14:35:46 1.34
+++ LVM2/test/api/test.c 2011/03/01 23:18:40 1.35
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -12,13 +12,18 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <readline/readline.h>
+#include <ctype.h>
+#include "configure.h"
#include "lvm2app.h"
+#ifndef READLINE_SUPPORT
+#include <readline/readline.h>
+
#define MAX_ARGS 64
static int lvm_split(char *str, int *argc, char **argv, int max)
@@ -1071,6 +1076,13 @@
free(input);
return 0;
}
+#else /* !READLINE_SUPPORT */
+static int lvmapi_test_shell(lvm_t libh)
+{
+ printf("Build without readline library, no interactive testing.\n");
+ return 1;
+}
+#endif
int main (int argc, char *argv[])
{
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2010-11-25 14:35 mornfall
0 siblings, 0 replies; 23+ messages in thread
From: mornfall @ 2010-11-25 14:35 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: mornfall@sourceware.org 2010-11-25 14:35:47
Modified files:
test/api : test.c
Log message:
Add interactive tests for functions to lookup a pv|lv by name|uuid.
Signed-off-by: Dave Wysochanski <wysochanski@pobox.com>
Reviewed-by: Petr Rockai <prockai@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.33&r2=1.34
--- LVM2/test/api/test.c 2010/11/17 20:13:51 1.33
+++ LVM2/test/api/test.c 2010/11/25 14:35:46 1.34
@@ -113,6 +113,14 @@
"Lookup a vgname from a device name\n");
printf("'vgname_from_pvid pvid': "
"Lookup a vgname from a pvid\n");
+ printf("'lv_from_uuid vgname lvuuid': "
+ "Lookup an LV from an LV uuid\n");
+ printf("'lv_from_name vgname lvname': "
+ "Lookup an LV from an LV name\n");
+ printf("'pv_from_uuid vgname pvuuid': "
+ "Lookup an LV from an LV uuid\n");
+ printf("'pv_from_name vgname pvname': "
+ "Lookup an LV from an LV name\n");
printf("'quit': exit the program\n");
}
@@ -468,6 +476,30 @@
lvm_vg_get_pv_count(vg), lvm_vg_get_seqno(vg));
}
+static void _print_pv(pv_t pv)
+{
+ if (!pv)
+ return;
+ printf("%s (%s): size=%"PRIu64", free=%"PRIu64
+ ", dev_size=%"PRIu64", mda_count=%"PRIu64"\n",
+ lvm_pv_get_name(pv), lvm_pv_get_uuid(pv),
+ lvm_pv_get_size(pv), lvm_pv_get_free(pv),
+ lvm_pv_get_dev_size(pv),
+ lvm_pv_get_mda_count(pv));
+}
+
+static void _print_lv(vg_t vg, lv_t lv)
+{
+ if (!lv)
+ return;
+ printf("%s/%s (%s): size=%"PRIu64", %sACTIVE / %sSUSPENDED\n",
+ lvm_vg_get_name(vg),
+ lvm_lv_get_name(lv), lvm_lv_get_uuid(lv),
+ lvm_lv_get_size(lv),
+ lvm_lv_is_active(lv) ? "" : "IN",
+ lvm_lv_is_suspended(lv) ? "" : "NOT ");
+}
+
static void _list_open_vgs(void)
{
dm_hash_iter(_vgid_hash, (dm_hash_iterate_fn) _show_one_vg);
@@ -488,12 +520,7 @@
}
printf("PVs in VG %s:\n", lvm_vg_get_name(vg));
dm_list_iterate_items(pvl, pvs) {
- printf("%s (%s): size=%"PRIu64", free=%"PRIu64
- ", dev_size=%"PRIu64", mda_count=%"PRIu64"\n",
- lvm_pv_get_name(pvl->pv), lvm_pv_get_uuid(pvl->pv),
- lvm_pv_get_size(pvl->pv), lvm_pv_get_free(pvl->pv),
- lvm_pv_get_dev_size(pvl->pv),
- lvm_pv_get_mda_count(pvl->pv));
+ _print_pv(pvl->pv);
}
}
@@ -715,6 +742,59 @@
printf("%s tag %s to LV %s\n",
add ? "adding":"removing", argv[3], argv[2]);
}
+
+static void _lv_from_uuid(char **argv, int argc)
+{
+ vg_t vg;
+
+ if (argc < 3) {
+ printf("Please enter vgname, lv_uuid\n");
+ return;
+ }
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ _print_lv(vg, lvm_lv_from_uuid(vg, argv[2]));
+}
+
+static void _lv_from_name(char **argv, int argc)
+{
+ vg_t vg;
+
+ if (argc < 3) {
+ printf("Please enter vgname, lv_uuid\n");
+ return;
+ }
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ _print_lv(vg, lvm_lv_from_name(vg, argv[2]));
+}
+
+static void _pv_from_uuid(char **argv, int argc)
+{
+ vg_t vg;
+
+ if (argc < 3) {
+ printf("Please enter vgname, pv_uuid\n");
+ return;
+ }
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ _print_pv(lvm_pv_from_uuid(vg, argv[2]));
+}
+
+static void _pv_from_name(char **argv, int argc)
+{
+ vg_t vg;
+
+ if (argc < 3) {
+ printf("Please enter vgname, pv_uuid\n");
+ return;
+ }
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ _print_pv(lvm_pv_from_name(vg, argv[2]));
+}
+
static void _vgname_from_pvid(char **argv, int argc, lvm_t libh)
{
const char *vgname;
@@ -762,12 +842,7 @@
}
printf("LVs in VG %s:\n", lvm_vg_get_name(vg));
dm_list_iterate_items(lvl, lvs) {
- printf("%s/%s (%s): size=%"PRIu64", %sACTIVE / %sSUSPENDED\n",
- lvm_vg_get_name(vg),
- lvm_lv_get_name(lvl->lv), lvm_lv_get_uuid(lvl->lv),
- lvm_lv_get_size(lvl->lv),
- lvm_lv_is_active(lvl->lv) ? "" : "IN",
- lvm_lv_is_suspended(lvl->lv) ? "" : "NOT ");
+ _print_lv(vg, lvl->lv);
}
}
@@ -978,6 +1053,14 @@
_vgname_from_devname(argv, argc, libh);
} else if (!strcmp(argv[0], "vgname_from_pvid")) {
_vgname_from_pvid(argv, argc, libh);
+ } else if (!strcmp(argv[0], "lv_from_uuid")) {
+ _lv_from_uuid(argv, argc);
+ } else if (!strcmp(argv[0], "lv_from_name")) {
+ _lv_from_name(argv, argc);
+ } else if (!strcmp(argv[0], "pv_from_uuid")) {
+ _pv_from_uuid(argv, argc);
+ } else if (!strcmp(argv[0], "pv_from_name")) {
+ _pv_from_name(argv, argc);
} else {
printf ("Unrecognized command %s\n", argv[0]);
}
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2010-11-17 20:13 mornfall
0 siblings, 0 replies; 23+ messages in thread
From: mornfall @ 2010-11-17 20:13 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: mornfall@sourceware.org 2010-11-17 20:13:51
Modified files:
test/api : test.c
Log message:
Update interactive tests for lvm2app lvseg and pvseg apis.
Signed-off-by: Dave Wysochanski <wysochanski@pobox.com>
Reviewed-by: Petr Rockai <prockai@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.32&r2=1.33
--- LVM2/test/api/test.c 2010/11/17 19:17:07 1.32
+++ LVM2/test/api/test.c 2010/11/17 20:13:51 1.33
@@ -67,8 +67,12 @@
"List the uuids of the VGs that exist in the system\n");
printf("'vg_list_pvs vgname': "
"List the PVs that exist in VG vgname\n");
+ printf("'pv_list_pvsegs pvname': "
+ "List the PV segments that exist in PV pvname\n");
printf("'vg_list_lvs vgname': "
"List the LVs that exist in VG vgname\n");
+ printf("'lv_list_lvsegs vgname lvname': "
+ "List the LV segments that exist in LV vgname/lvname\n");
printf("'vgs_open': "
"List the VGs that are currently open\n");
printf("'vgs': "
@@ -189,17 +193,13 @@
return vg;
}
-static pv_t _lookup_pv_by_name(char **argv, int argc)
+static pv_t _lookup_pv_by_name(const char *name)
{
pv_t pv;
- if (argc < 2) {
- printf ("Please enter vg_name\n");
- return NULL;
- }
- if (!(pv = dm_hash_lookup(_pvname_hash, argv[1]))) {
+ if (!(pv = dm_hash_lookup(_pvname_hash, name))) {
printf ("Can't find %s in open PVs - run vg_open first\n",
- argv[1]);
+ name);
return NULL;
}
return pv;
@@ -238,6 +238,7 @@
dm_hash_insert(_pvname_hash, name, pvl->pv);
}
}
+
static void _vg_reduce(char **argv, int argc, lvm_t libh)
{
vg_t vg;
@@ -496,6 +497,40 @@
}
}
+static void _print_property_value(const char *name,
+ struct lvm_property_value v)
+{
+ if (!v.is_valid)
+ printf("%s = INVALID\n", name);
+ else if (v.is_string)
+ printf("%s = %s\n", name, v.value.string);
+ else
+ printf("%s = %"PRIu64"\n", name, v.value.integer);
+}
+
+static void _pvsegs_in_pv(char **argv, int argc)
+{
+ struct dm_list *pvsegs;
+ struct lvm_pvseg_list *pvl;
+ pv_t pv;
+
+ if (!(pv = _lookup_pv_by_name(argv[1])))
+ return;
+ pvsegs = lvm_pv_list_pvsegs(pv);
+ if (!pvsegs || dm_list_empty(pvsegs)) {
+ printf("No PV segments in pv %s\n", argv[1]);
+ return;
+ }
+ printf("PV segments in pv %s:\n", argv[1]);
+ dm_list_iterate_items(pvl, pvsegs) {
+ struct lvm_property_value v;
+ v = lvm_pvseg_get_property(pvl->pvseg, "pvseg_start");
+ _print_property_value("pvseg_start", v);
+ v = lvm_pvseg_get_property(pvl->pvseg, "pvseg_size");
+ _print_property_value("pvseg_size", v);
+ }
+}
+
static void _scan_vgs(lvm_t libh)
{
lvm_scan(libh);
@@ -571,14 +606,6 @@
add ? "adding":"removing", argv[2], argv[1]);
}
-static void _print_property_value(struct lvm_property_value value)
-{
- if (value.is_string)
- printf(", value = %s\n", value.value.string);
- else
- printf(", value = %"PRIu64"\n", value.value.integer);
-}
-
static void _pv_get_property(char **argv, int argc)
{
pv_t pv;
@@ -588,20 +615,10 @@
printf("Please enter pvname, field_id\n");
return;
}
- if (!(pv = _lookup_pv_by_name(argv, argc)))
+ if (!(pv = _lookup_pv_by_name(argv[1])))
return;
v = lvm_pv_get_property(pv, argv[2]);
- if (!v.is_valid)
- printf("Error ");
- else
- printf("Success ");
- printf("obtaining value of property %s in PV %s",
- argv[2], argv[1]);
- if (!v.is_valid) {
- printf("\n");
- return;
- }
- _print_property_value(v);
+ _print_property_value(argv[2], v);
}
static void _vg_get_property(char **argv, int argc)
@@ -616,17 +633,7 @@
if (!(vg = _lookup_vg_by_name(argv, argc)))
return;
v = lvm_vg_get_property(vg, argv[2]);
- if (!v.is_valid)
- printf("Error ");
- else
- printf("Success ");
- printf("obtaining value of property %s in VG %s",
- argv[2], argv[1]);
- if (!v.is_valid) {
- printf("\n");
- return;
- }
- _print_property_value(v);
+ _print_property_value(argv[2], v);
}
static void _lv_get_property(char **argv, int argc)
@@ -641,17 +648,7 @@
if (!(lv = _lookup_lv_by_name(argv[2])))
return;
v = lvm_lv_get_property(lv, argv[3]);
- if (!v.is_valid)
- printf("Error ");
- else
- printf("Success ");
- printf("obtaining value of property %s in LV %s",
- argv[3], argv[2]);
- if (!v.is_valid) {
- printf("\n");
- return;
- }
- _print_property_value(v);
+ _print_property_value(argv[3], v);
}
static void _vg_set_property(char **argv, int argc)
@@ -774,6 +771,31 @@
}
}
+static void _lvsegs_in_lv(char **argv, int argc)
+{
+ struct dm_list *lvsegs;
+ struct lvm_lvseg_list *lvl;
+ lv_t lv;
+
+ if (!(lv = _lookup_lv_by_name(argv[2])))
+ return;
+ lvsegs = lvm_lv_list_lvsegs(lv);
+ if (!lvsegs || dm_list_empty(lvsegs)) {
+ printf("No LV segments in lv %s\n", lvm_lv_get_name(lv));
+ return;
+ }
+ printf("LV segments in lv %s:\n", lvm_lv_get_name(lv));
+ dm_list_iterate_items(lvl, lvsegs) {
+ struct lvm_property_value v;
+ v = lvm_lvseg_get_property(lvl->lvseg, "segtype");
+ _print_property_value("segtype", v);
+ v = lvm_lvseg_get_property(lvl->lvseg, "seg_start_pe");
+ _print_property_value("seg_start_pe", v);
+ v = lvm_lvseg_get_property(lvl->lvseg, "seg_size");
+ _print_property_value("seg_size", v);
+ }
+}
+
static void _lv_deactivate(char **argv, int argc)
{
lv_t lv;
@@ -918,8 +940,12 @@
_list_open_vgs();
} else if (!strcmp(argv[0], "vg_list_pvs")) {
_pvs_in_vg(argv, argc);
+ } else if (!strcmp(argv[0], "pv_list_pvsegs")) {
+ _pvsegs_in_pv(argv, argc);
} else if (!strcmp(argv[0], "vg_list_lvs")) {
_lvs_in_vg(argv, argc);
+ } else if (!strcmp(argv[0], "lv_list_lvsegs")) {
+ _lvsegs_in_lv(argv, argc);
} else if (!strcmp(argv[0], "list_vg_names")) {
_list_vg_names(libh);
} else if (!strcmp(argv[0], "list_vg_ids")) {
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2010-11-17 19:17 mornfall
0 siblings, 0 replies; 23+ messages in thread
From: mornfall @ 2010-11-17 19:17 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: mornfall@sourceware.org 2010-11-17 19:17:07
Modified files:
test/api : test.c
Log message:
Add vg_set_property to the interactive lvm2app test program.
Signed-off-by: Dave Wysochanski <wysochanski@pobox.com>
Reviewed-by: Petr Rockai <prockai@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.31&r2=1.32
--- LVM2/test/api/test.c 2010/10/25 14:09:19 1.31
+++ LVM2/test/api/test.c 2010/11/17 19:17:07 1.32
@@ -97,6 +97,8 @@
"Display the value of VG property\n");
printf("'pv_get_property pvname property_name': "
"Display the value of PV property\n");
+ printf("'vg_set_property vgname property_name': "
+ "Set the value of VG property\n");
printf("'lv_get_tags vgname lvname': "
"List the tags of a LV\n");
printf("'vg_{add|remove}_tag vgname tag': "
@@ -652,6 +654,36 @@
_print_property_value(v);
}
+static void _vg_set_property(char **argv, int argc)
+{
+ vg_t vg;
+ struct lvm_property_value value;
+ int rc;
+
+ if (argc < 4) {
+ printf("Please enter vgname, field_id, value\n");
+ return;
+ }
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ value = lvm_vg_get_property(vg, argv[2]);
+ if (!value.is_valid) {
+ printf("Error obtaining property value\n");
+ return;
+ }
+ if (value.is_string)
+ value.value.string = argv[3];
+ else
+ value.value.integer = atoi(argv[3]);
+ rc = lvm_vg_set_property(vg, argv[2], &value);
+ if (rc)
+ printf("Error ");
+ else
+ printf("Success ");
+ printf("setting value of property %s in VG %s\n",
+ argv[2], argv[1]);
+}
+
static void _lv_get_tags(char **argv, int argc)
{
lv_t lv;
@@ -908,6 +940,8 @@
_vg_get_property(argv, argc);
} else if (!strcmp(argv[0], "pv_get_property")) {
_pv_get_property(argv, argc);
+ } else if (!strcmp(argv[0], "vg_set_property")) {
+ _vg_set_property(argv, argc);
} else if (!strcmp(argv[0], "lv_add_tag")) {
_lv_tag(argv, argc, 1);
} else if (!strcmp(argv[0], "lv_remove_tag")) {
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2010-10-25 14:09 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2010-10-25 14:09 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2010-10-25 14:09:20
Modified files:
test/api : test.c
Log message:
Add interactive tests for lvm_{pv|vg|lv}_get_property().
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.30&r2=1.31
--- LVM2/test/api/test.c 2010/05/19 11:53:30 1.30
+++ LVM2/test/api/test.c 2010/10/25 14:09:19 1.31
@@ -91,6 +91,12 @@
"Issue a lvm_config_override() with accept device filter\n");
printf("'vg_get_tags vgname': "
"List the tags of a VG\n");
+ printf("'lv_get_property vgname lvname property_name': "
+ "Display the value of LV property\n");
+ printf("'vg_get_property vgname property_name': "
+ "Display the value of VG property\n");
+ printf("'pv_get_property pvname property_name': "
+ "Display the value of PV property\n");
printf("'lv_get_tags vgname lvname': "
"List the tags of a LV\n");
printf("'vg_{add|remove}_tag vgname tag': "
@@ -180,6 +186,23 @@
}
return vg;
}
+
+static pv_t _lookup_pv_by_name(char **argv, int argc)
+{
+ pv_t pv;
+
+ if (argc < 2) {
+ printf ("Please enter vg_name\n");
+ return NULL;
+ }
+ if (!(pv = dm_hash_lookup(_pvname_hash, argv[1]))) {
+ printf ("Can't find %s in open PVs - run vg_open first\n",
+ argv[1]);
+ return NULL;
+ }
+ return pv;
+}
+
static void _add_lvs_to_lvname_hash(struct dm_list *lvs)
{
struct lvm_lv_list *lvl;
@@ -546,6 +569,89 @@
add ? "adding":"removing", argv[2], argv[1]);
}
+static void _print_property_value(struct lvm_property_value value)
+{
+ if (value.is_string)
+ printf(", value = %s\n", value.value.string);
+ else
+ printf(", value = %"PRIu64"\n", value.value.integer);
+}
+
+static void _pv_get_property(char **argv, int argc)
+{
+ pv_t pv;
+ struct lvm_property_value v;
+
+ if (argc < 3) {
+ printf("Please enter pvname, field_id\n");
+ return;
+ }
+ if (!(pv = _lookup_pv_by_name(argv, argc)))
+ return;
+ v = lvm_pv_get_property(pv, argv[2]);
+ if (!v.is_valid)
+ printf("Error ");
+ else
+ printf("Success ");
+ printf("obtaining value of property %s in PV %s",
+ argv[2], argv[1]);
+ if (!v.is_valid) {
+ printf("\n");
+ return;
+ }
+ _print_property_value(v);
+}
+
+static void _vg_get_property(char **argv, int argc)
+{
+ vg_t vg;
+ struct lvm_property_value v;
+
+ if (argc < 3) {
+ printf("Please enter vgname, field_id\n");
+ return;
+ }
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ v = lvm_vg_get_property(vg, argv[2]);
+ if (!v.is_valid)
+ printf("Error ");
+ else
+ printf("Success ");
+ printf("obtaining value of property %s in VG %s",
+ argv[2], argv[1]);
+ if (!v.is_valid) {
+ printf("\n");
+ return;
+ }
+ _print_property_value(v);
+}
+
+static void _lv_get_property(char **argv, int argc)
+{
+ lv_t lv;
+ struct lvm_property_value v;
+
+ if (argc < 4) {
+ printf("Please enter vgname, lvname, field_id\n");
+ return;
+ }
+ if (!(lv = _lookup_lv_by_name(argv[2])))
+ return;
+ v = lvm_lv_get_property(lv, argv[3]);
+ if (!v.is_valid)
+ printf("Error ");
+ else
+ printf("Success ");
+ printf("obtaining value of property %s in LV %s",
+ argv[3], argv[2]);
+ if (!v.is_valid) {
+ printf("\n");
+ return;
+ }
+ _print_property_value(v);
+}
+
static void _lv_get_tags(char **argv, int argc)
{
lv_t lv;
@@ -796,6 +902,12 @@
_vg_tag(argv, argc, 0);
} else if (!strcmp(argv[0], "vg_get_tags")) {
_vg_get_tags(argv, argc);
+ } else if (!strcmp(argv[0], "lv_get_property")) {
+ _lv_get_property(argv, argc);
+ } else if (!strcmp(argv[0], "vg_get_property")) {
+ _vg_get_property(argv, argc);
+ } else if (!strcmp(argv[0], "pv_get_property")) {
+ _pv_get_property(argv, argc);
} else if (!strcmp(argv[0], "lv_add_tag")) {
_lv_tag(argv, argc, 1);
} else if (!strcmp(argv[0], "lv_remove_tag")) {
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2010-05-19 11:53 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2010-05-19 11:53 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2010-05-19 11:53:30
Modified files:
test/api : test.c
Log message:
Test lvm_vgname_from_{pvid|device}.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.29&r2=1.30
--- LVM2/test/api/test.c 2010/02/24 18:16:35 1.29
+++ LVM2/test/api/test.c 2010/05/19 11:53:30 1.30
@@ -97,6 +97,10 @@
"Add/remove a tag from a VG\n");
printf("'lv_{add|remove}_tag vgname lvname tag': "
"Add/remove a tag from a LV\n");
+ printf("'vgname_from_devname device': "
+ "Lookup a vgname from a device name\n");
+ printf("'vgname_from_pvid pvid': "
+ "Lookup a vgname from a pvid\n");
printf("'quit': exit the program\n");
}
@@ -576,6 +580,38 @@
printf("%s tag %s to LV %s\n",
add ? "adding":"removing", argv[3], argv[2]);
}
+static void _vgname_from_pvid(char **argv, int argc, lvm_t libh)
+{
+ const char *vgname;
+
+ if (argc < 1) {
+ printf("Please enter pvid\n");
+ return;
+ }
+ if (!(vgname = lvm_vgname_from_pvid(libh, argv[1]))) {
+ printf("Error ");
+ } else {
+ printf("Success ");
+ }
+ printf("looking up vgname=%s from PVID=%s\n",
+ vgname, argv[1]);
+}
+static void _vgname_from_devname(char **argv, int argc, lvm_t libh)
+{
+ const char *vgname;
+
+ if (argc < 1) {
+ printf("Please enter device\n");
+ return;
+ }
+ if (!(vgname = lvm_vgname_from_device(libh, argv[1]))) {
+ printf("Error ");
+ } else {
+ printf("Success ");
+ }
+ printf("looking up vgname=%s from device name=%s\n",
+ vgname, argv[1]);
+}
static void _lvs_in_vg(char **argv, int argc)
{
struct dm_list *lvs;
@@ -766,6 +802,10 @@
_lv_tag(argv, argc, 0);
} else if (!strcmp(argv[0], "lv_get_tags")) {
_lv_get_tags(argv, argc);
+ } else if (!strcmp(argv[0], "vgname_from_devname")) {
+ _vgname_from_devname(argv, argc, libh);
+ } else if (!strcmp(argv[0], "vgname_from_pvid")) {
+ _vgname_from_pvid(argv, argc, libh);
} else {
printf ("Unrecognized command %s\n", argv[0]);
}
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2010-02-24 18:16 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2010-02-24 18:16 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2010-02-24 18:16:36
Modified files:
test/api : test.c
Log message:
Update lvm2app interactive unit test for vg/lv tags.
Simple test of vg/lv tag addition/deletion.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.28&r2=1.29
--- LVM2/test/api/test.c 2010/02/14 03:23:07 1.28
+++ LVM2/test/api/test.c 2010/02/24 18:16:35 1.29
@@ -89,6 +89,14 @@
"Issue a lvm_config_reload() API to reload LVM config\n");
printf("'config_override' device: "
"Issue a lvm_config_override() with accept device filter\n");
+ printf("'vg_get_tags vgname': "
+ "List the tags of a VG\n");
+ printf("'lv_get_tags vgname lvname': "
+ "List the tags of a LV\n");
+ printf("'vg_{add|remove}_tag vgname tag': "
+ "Add/remove a tag from a VG\n");
+ printf("'lv_{add|remove}_tag vgname lvname tag': "
+ "Add/remove a tag from a LV\n");
printf("'quit': exit the program\n");
}
@@ -468,13 +476,11 @@
{
struct dm_list *list;
struct lvm_str_list *strl;
- const char *tmp;
list = lvm_list_vg_names(libh);
printf("VG names:\n");
dm_list_iterate_items(strl, list) {
- tmp = strl->str;
- printf("%s\n", tmp);
+ printf("%s\n", strl->str);
}
}
@@ -482,17 +488,94 @@
{
struct dm_list *list;
struct lvm_str_list *strl;
- const char *tmp;
list = lvm_list_vg_uuids(libh);
printf("VG uuids:\n");
dm_list_iterate_items(strl, list) {
- tmp = strl->str;
- printf("%s\n", tmp);
+ printf("%s\n", strl->str);
}
}
+static void _display_tags(struct dm_list *list)
+{
+ struct lvm_str_list *strl;
+ if (dm_list_empty(list)) {
+ printf("No tags exist\n");
+ return;
+ } else if (!list) {
+ printf("Error obtaining tags\n");
+ return;
+ }
+ dm_list_iterate_items(strl, list) {
+ printf("%s\n", strl->str);
+ }
+}
+
+static void _vg_get_tags(char **argv, int argc)
+{
+ vg_t vg;
+
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ printf("VG tags:\n");
+ _display_tags(lvm_vg_get_tags(vg));
+}
+
+static void _vg_tag(char **argv, int argc, int add)
+{
+ vg_t vg;
+ if (argc < 3) {
+ printf("Please enter vgname, tag\n");
+ return;
+ }
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ if (add && lvm_vg_add_tag(vg, argv[2]))
+ printf("Error ");
+ else if (!add && lvm_vg_remove_tag(vg, argv[2])){
+ printf("Error ");
+ } else {
+ printf("Success ");
+ }
+ printf("%s tag %s to VG %s\n",
+ add ? "adding":"removing", argv[2], argv[1]);
+}
+
+static void _lv_get_tags(char **argv, int argc)
+{
+ lv_t lv;
+
+ if (argc < 3) {
+ printf("Please enter vgname, lvname\n");
+ return;
+ }
+ if (!(lv = _lookup_lv_by_name(argv[2])))
+ return;
+ printf("LV tags:\n");
+ _display_tags(lvm_lv_get_tags(lv));
+}
+
+static void _lv_tag(char **argv, int argc, int add)
+{
+ lv_t lv;
+
+ if (argc < 3) {
+ printf("Please enter vgname, lvname\n");
+ return;
+ }
+ if (!(lv = _lookup_lv_by_name(argv[2])))
+ return;
+ if (add && lvm_lv_add_tag(lv, argv[3]))
+ printf("Error ");
+ else if (!add && lvm_lv_remove_tag(lv, argv[3])){
+ printf("Error ");
+ } else {
+ printf("Success ");
+ }
+ printf("%s tag %s to LV %s\n",
+ add ? "adding":"removing", argv[3], argv[2]);
+}
static void _lvs_in_vg(char **argv, int argc)
{
struct dm_list *lvs;
@@ -549,6 +632,7 @@
printf("activating LV %s in VG %s\n",
argv[2], argv[1]);
}
+
static void _vg_remove_lv(char **argv, int argc)
{
lv_t lv;
@@ -670,6 +754,18 @@
_scan_vgs(libh);
} else if (!strcmp(argv[0], "vg_create_lv_linear")) {
_vg_create_lv_linear(argv, argc);
+ } else if (!strcmp(argv[0], "vg_add_tag")) {
+ _vg_tag(argv, argc, 1);
+ } else if (!strcmp(argv[0], "vg_remove_tag")) {
+ _vg_tag(argv, argc, 0);
+ } else if (!strcmp(argv[0], "vg_get_tags")) {
+ _vg_get_tags(argv, argc);
+ } else if (!strcmp(argv[0], "lv_add_tag")) {
+ _lv_tag(argv, argc, 1);
+ } else if (!strcmp(argv[0], "lv_remove_tag")) {
+ _lv_tag(argv, argc, 0);
+ } else if (!strcmp(argv[0], "lv_get_tags")) {
+ _lv_get_tags(argv, argc);
} else {
printf ("Unrecognized command %s\n", argv[0]);
}
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-08-07 21:22 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-08-07 21:22 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-08-07 21:22:37
Modified files:
test/api : test.c
Log message:
Update test/api/test.c to call lvm_vg_create and lvm_vg_remove.
Also fix a couple bugs.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.24&r2=1.25
--- LVM2/test/api/test.c 2009/07/29 14:06:31 1.24
+++ LVM2/test/api/test.c 2009/08/07 21:22:37 1.25
@@ -81,6 +81,10 @@
"Issue a lvm_vg_open() API call on VG 'vgname'\n");
printf("'vg_close vgname': "
"Issue a lvm_vg_close() API call on VG 'vgname'\n");
+ printf("'vg_create vgname: "
+ "Issue a lvm_vg_create() to create VG 'vgname'\n");
+ printf("'vg_remove vgname: "
+ "Issue a lvm_vg_remove() to remove VG 'vgname'\n");
printf("'config_reload': "
"Issue a lvm_config_reload() API to reload LVM config\n");
printf("'config_override' device: "
@@ -351,24 +355,70 @@
return;
}
vg = _lookup_vg_by_name(argv, argc);
- if (vg)
- rc = lvm_vg_write(vg);
+ if (!vg) {
+ printf("Can't find vg_name %s\n", argv[1]);
+ return;
+ }
+ rc = lvm_vg_write(vg);
_lvm_status_to_pass_fail(rc);
printf("writing VG %s\n", lvm_vg_get_name(vg));
}
+static void _vg_create(char **argv, int argc, lvm_t libh)
+{
+ vg_t *vg;
+
+ if (argc < 2) {
+ printf ("Please enter vg_name\n");
+ return;
+ }
+ vg = lvm_vg_create(libh, argv[1]);
+ if (!vg || !lvm_vg_get_name(vg)) {
+ printf("Error creating %s\n", argv[1]);
+ return;
+ }
+
+ printf("Success creating vg %s\n", argv[1]);
+ dm_hash_insert(_vgname_hash, lvm_vg_get_name(vg), vg);
+ dm_hash_insert(_vgid_hash, lvm_vg_get_uuid(vg), vg);
+}
+
+static void _vg_remove(char **argv, int argc)
+{
+ vg_t *vg;
+ int rc = 0;
+
+ if (argc < 2) {
+ printf ("Please enter vg_name\n");
+ return;
+ }
+ vg = _lookup_vg_by_name(argv, argc);
+ if (!vg) {
+ printf("Can't find vg_name %s\n", argv[1]);
+ return;
+ }
+ rc = lvm_vg_remove(vg);
+ _lvm_status_to_pass_fail(rc);
+ printf("removing VG\n");
+}
+
static void _vg_close(char **argv, int argc)
{
vg_t *vg;
+ int rc = 0;
if (argc < 2) {
printf ("Please enter vg_name\n");
return;
}
vg = _lookup_and_remove_vg(argv[1]);
- if (vg)
- lvm_vg_close(vg);
- /* FIXME: remove LVs from lvname_hash */
+ if (!vg) {
+ printf("Can't find vg_name %s\n", argv[1]);
+ return;
+ }
+ rc = lvm_vg_close(vg);
+ _lvm_status_to_pass_fail(rc);
+ printf("closing VG\n");
}
static void _show_one_vg(vg_t *vg)
@@ -593,6 +643,10 @@
_vg_open(argv, argc, libh);
} else if (!strcmp(argv[0], "vg_close")) {
_vg_close(argv, argc);
+ } else if (!strcmp(argv[0], "vg_create")) {
+ _vg_create(argv, argc, libh);
+ } else if (!strcmp(argv[0], "vg_remove")) {
+ _vg_remove(argv, argc);
} else if (!strcmp(argv[0], "lv_activate")) {
_lv_activate(argv, argc);
} else if (!strcmp(argv[0], "lv_deactivate")) {
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-28 14:12 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-28 14:12 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-28 14:12:30
Modified files:
test/api : test.c
Log message:
Update interactive unit test - fix silly vg_close error.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.22&r2=1.23
--- LVM2/test/api/test.c 2009/07/28 13:49:28 1.22
+++ LVM2/test/api/test.c 2009/07/28 14:12:29 1.23
@@ -329,11 +329,11 @@
{
vg_t *vg=NULL;
- while((vg = dm_hash_lookup(_vgname_hash, vgname))) {
+ if ((vg = dm_hash_lookup(_vgname_hash, vgname))) {
dm_hash_remove(_vgid_hash, lvm_vg_get_uuid(vg));
dm_hash_remove(_vgname_hash, lvm_vg_get_name(vg));
}
- while(vg && (vg = dm_hash_lookup(_vgid_hash, vgname))) {
+ if (!vg && (vg = dm_hash_lookup(_vgid_hash, vgname))) {
dm_hash_remove(_vgid_hash, lvm_vg_get_uuid(vg));
dm_hash_remove(_vgname_hash, lvm_vg_get_name(vg));
}
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-28 13:49 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-28 13:49 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-28 13:49:29
Modified files:
test/api : test.c
Log message:
Update interactive unit test for liblvm - add vg_write, general cleanup.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.21&r2=1.22
--- LVM2/test/api/test.c 2009/07/28 13:17:04 1.21
+++ LVM2/test/api/test.c 2009/07/28 13:49:28 1.22
@@ -225,6 +225,15 @@
_remove_device_from_pvname_hash(pvs, argv[2]);
}
+/* Print "Error" or "Success" depending on lvm status */
+static int _lvm_status_to_pass_fail(int rc)
+{
+ if (rc)
+ printf("Error ");
+ else
+ printf("Success ");
+ return rc;
+}
static void _config_override(char **argv, int argc, lvm_t libh)
{
int rc;
@@ -236,10 +245,7 @@
}
snprintf(tmp, 63, "devices{filter=[\"a|%s|\", \"r|.*|\"]}", argv[1]);
rc = lvm_config_override(libh, tmp);
- if (rc)
- printf("Error ");
- else
- printf("Success ");
+ _lvm_status_to_pass_fail(rc);
printf("overriding LVM configuration\n");
}
@@ -247,10 +253,7 @@
{
int rc;
rc = lvm_config_reload(libh);
- if (rc)
- printf("Error ");
- else
- printf("Success ");
+ _lvm_status_to_pass_fail(rc);
printf("reloading LVM configuration\n");
}
@@ -321,25 +324,49 @@
if (pvs && !dm_list_empty(pvs))
_add_pvs_to_pvname_hash(pvs);
}
+/* Lookup the vg and remove it from the vgname and vgid hashes */
+static vg_t *_lookup_and_remove_vg(const char *vgname)
+{
+ vg_t *vg=NULL;
-static void _vg_close(char **argv, int argc)
+ while((vg = dm_hash_lookup(_vgname_hash, vgname))) {
+ dm_hash_remove(_vgid_hash, lvm_vg_get_uuid(vg));
+ dm_hash_remove(_vgname_hash, lvm_vg_get_name(vg));
+ }
+ while(vg && (vg = dm_hash_lookup(_vgid_hash, vgname))) {
+ dm_hash_remove(_vgid_hash, lvm_vg_get_uuid(vg));
+ dm_hash_remove(_vgname_hash, lvm_vg_get_name(vg));
+ }
+ return vg;
+}
+
+static void _vg_write(char **argv, int argc)
{
vg_t *vg;
+ int rc = 0;
if (argc < 2) {
printf ("Please enter vg_name\n");
return;
}
- while((vg = dm_hash_lookup(_vgname_hash, argv[1]))) {
- dm_hash_remove(_vgid_hash, lvm_vg_get_uuid(vg));
- dm_hash_remove(_vgname_hash, lvm_vg_get_name(vg));
- lvm_vg_close(vg);
+ vg = _lookup_vg_by_name(argv, argc);
+ if (vg)
+ rc = lvm_vg_write(vg);
+ _lvm_status_to_pass_fail(rc);
+ printf("writing VG %s\n", lvm_vg_get_name(vg));
+}
+
+static void _vg_close(char **argv, int argc)
+{
+ vg_t *vg;
+
+ if (argc < 2) {
+ printf ("Please enter vg_name\n");
+ return;
}
- while((vg = dm_hash_lookup(_vgid_hash, argv[1]))) {
- dm_hash_remove(_vgid_hash, lvm_vg_get_uuid(vg));
- dm_hash_remove(_vgname_hash, lvm_vg_get_name(vg));
+ vg = _lookup_and_remove_vg(argv[1]);
+ if (vg)
lvm_vg_close(vg);
- }
/* FIXME: remove LVs from lvname_hash */
}
@@ -439,6 +466,7 @@
static void _lv_deactivate(char **argv, int argc)
{
lv_t *lv;
+ int rc=0;
if (argc < 3) {
printf("Please enter vgname, lvname\n");
@@ -446,17 +474,15 @@
}
if (!(lv = _lookup_lv_by_name(argv[2])))
return;
- if (lvm_lv_deactivate(lv))
- printf("Error ");
- else {
- printf("Success ");
- }
+ rc = lvm_lv_deactivate(lv);
+ _lvm_status_to_pass_fail(rc);
printf("De-activating LV %s in VG %s\n",
argv[2], argv[1]);
}
static void _lv_activate(char **argv, int argc)
{
lv_t *lv;
+ int rc=0;
if (argc < 3) {
printf("Please enter vgname, lvname\n");
@@ -464,11 +490,8 @@
}
if (!(lv = _lookup_lv_by_name(argv[2])))
return;
- if (lvm_lv_activate(lv))
- printf("Error ");
- else {
- printf("Success ");
- }
+ rc = lvm_lv_activate(lv);
+ _lvm_status_to_pass_fail(rc);
printf("activating LV %s in VG %s\n",
argv[2], argv[1]);
}
@@ -563,6 +586,8 @@
_vg_extend(argv, argc, libh);
} else if (!strcmp(argv[0], "vg_reduce")) {
_vg_reduce(argv, argc, libh);
+ } else if (!strcmp(argv[0], "vg_write")) {
+ _vg_write(argv, argc);
} else if (!strcmp(argv[0], "vg_open")) {
_vg_open(argv, argc, libh);
} else if (!strcmp(argv[0], "vg_close")) {
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-27 21:02 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-27 21:02 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-27 21:02:51
Modified files:
test/api : test.c
Log message:
Add config_reload and config_override to test.c, change prompt.
PV PV UUID VG
/dev/loop1 A95EvV-iqmb-ZFuJ-u8MV-Npwn-wlc2-Ul1Mnn vg1
/dev/loop0 R16FDG-OmoS-HNGt-LSZY-OAlC-7qeU-t2gztp vg1
lvm> config_override loop0
Success overriding LVM configuration
lvm> config_reload
Success reloading LVM configuration
lvm> vg_open vg1
Couldn't find device with uuid 'A95EvV-iqmb-ZFuJ-u8MV-Npwn-wlc2-Ul1Mnn'.
Success opening vg vg1
lvm> vg_close vg1
lvm> quit
Maybe a bug in lvm_vg_open for missing pvs but the filter seems to work.
Change prompt from "lvm>" to "liblvm>".
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.17&r2=1.18
--- LVM2/test/api/test.c 2009/07/27 17:45:21 1.17
+++ LVM2/test/api/test.c 2009/07/27 21:02:51 1.18
@@ -80,6 +80,10 @@
"Issue a lvm_vg_open() API call on VG 'vgname'\n");
printf("'vg_close vgname': "
"Issue a lvm_vg_close() API call on VG 'vgname'\n");
+ printf("'config_reload': "
+ "Issue a lvm_config_reload() API to reload LVM config\n");
+ printf("'config_override' device: "
+ "Issue a lvm_config_override() with accept device filter\n");
printf("'quit': exit the program\n");
}
@@ -221,6 +225,35 @@
_remove_device_from_pvname_hash(pvs, argv[2]);
}
+static void _config_override(char **argv, int argc, lvm_t libh)
+{
+ int rc;
+ char tmp[64];
+
+ if (argc < 2) {
+ printf ("Please enter device\n");
+ return;
+ }
+ snprintf(tmp, 63, "devices{filter=[\"a|%s|\", \"r|.*|\"]}", argv[1]);
+ rc = lvm_config_override(libh, tmp);
+ if (rc)
+ printf("Error ");
+ else
+ printf("Success ");
+ printf("overriding LVM configuration\n");
+}
+
+static void _config_reload(char **argv, int argc, lvm_t libh)
+{
+ int rc;
+ rc = lvm_config_reload(libh);
+ if (rc)
+ printf("Error ");
+ else
+ printf("Success ");
+ printf("reloading LVM configuration\n");
+}
+
static void _vg_extend(char **argv, int argc, lvm_t libh)
{
vg_t *vg;
@@ -489,7 +522,7 @@
argc=0;
while (1) {
free(input);
- input = readline("lvm> ");
+ input = readline("liblvm> ");
/* EOF */
if (!input) {
@@ -521,6 +554,10 @@
break;
} else if (!strcmp(argv[0], "?") || !strcmp(argv[0], "help")) {
_show_help();
+ } else if (!strcmp(argv[0], "config_reload")) {
+ _config_reload(argv, argc, libh);
+ } else if (!strcmp(argv[0], "config_override")) {
+ _config_override(argv, argc, libh);
} else if (!strcmp(argv[0], "vg_extend")) {
_vg_extend(argv, argc, libh);
} else if (!strcmp(argv[0], "vg_reduce")) {
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-27 17:45 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-27 17:45 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-27 17:45:22
Modified files:
test/api : test.c
Log message:
Update test/api/test.c to include lvm_vg_reduce and lvm_vg_extend.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.16&r2=1.17
--- LVM2/test/api/test.c 2009/07/26 20:59:02 1.16
+++ LVM2/test/api/test.c 2009/07/27 17:45:21 1.17
@@ -72,6 +72,10 @@
"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 _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 @@
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")) {
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-26 20:59 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-26 20:59 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-26 20:59:02
Modified files:
test/api : test.c
Log message:
Update test/api/test.c to display lvm_lv_is_active and lvm_lv_is_suspended.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.15&r2=1.16
--- LVM2/test/api/test.c 2009/07/26 20:58:38 1.15
+++ LVM2/test/api/test.c 2009/07/26 20:59:02 1.16
@@ -315,9 +315,12 @@
}
printf("LVs in VG %s:\n", lvm_vg_get_name(vg));
dm_list_iterate_items(lvl, lvs) {
- printf("%s/%s (%s): size=%"PRIu64"\n", lvm_vg_get_name(vg),
+ printf("%s/%s (%s): size=%"PRIu64", %sACTIVE / %sSUSPENDED\n",
+ lvm_vg_get_name(vg),
lvm_lv_get_name(lvl->lv), lvm_lv_get_uuid(lvl->lv),
- lvm_lv_get_size(lvl->lv));
+ lvm_lv_get_size(lvl->lv),
+ lvm_lv_is_active(lvl->lv) ? "" : "IN",
+ lvm_lv_is_suspended(lvl->lv) ? "" : "NOT ");
}
}
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-26 20:58 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-26 20:58 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-26 20:58:38
Modified files:
test/api : test.c
Log message:
Update test/api/test.c to call lv_deactivate and lv_activate.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.14&r2=1.15
--- LVM2/test/api/test.c 2009/07/26 20:29:56 1.14
+++ LVM2/test/api/test.c 2009/07/26 20:58:38 1.15
@@ -50,6 +50,10 @@
static void _show_help(void)
{
+ printf("'lv_activate vgname lvname: "
+ "Activate an LV\n");
+ printf("'lv_deactivate vgname lvname: "
+ "Deactivate an LV\n");
printf("'vg_remove_lv vgname lvname': "
"Remove a LV\n");
printf("'vg_create_lv_linear vgname lvname size_in_bytes': "
@@ -317,6 +321,42 @@
}
}
+static void _lv_deactivate(char **argv, int argc)
+{
+ lv_t *lv;
+
+ if (argc < 3) {
+ printf("Please enter vgname, lvname\n");
+ return;
+ }
+ if (!(lv = _lookup_lv_by_name(argv[2])))
+ return;
+ if (lvm_lv_deactivate(lv))
+ printf("Error ");
+ else {
+ printf("Success ");
+ }
+ printf("De-activating LV %s in VG %s\n",
+ argv[2], argv[1]);
+}
+static void _lv_activate(char **argv, int argc)
+{
+ lv_t *lv;
+
+ if (argc < 3) {
+ printf("Please enter vgname, lvname\n");
+ return;
+ }
+ if (!(lv = _lookup_lv_by_name(argv[2])))
+ return;
+ if (lvm_lv_activate(lv))
+ printf("Error ");
+ else {
+ printf("Success ");
+ }
+ printf("activating LV %s in VG %s\n",
+ argv[2], argv[1]);
+}
static void _vg_remove_lv(char **argv, int argc)
{
lv_t *lv;
@@ -404,6 +444,10 @@
_vg_open(argv, argc, libh);
} else if (!strcmp(argv[0], "vg_close")) {
_vg_close(argv, argc);
+ } else if (!strcmp(argv[0], "lv_activate")) {
+ _lv_activate(argv, argc);
+ } else if (!strcmp(argv[0], "lv_deactivate")) {
+ _lv_deactivate(argv, argc);
} else if (!strcmp(argv[0], "vg_remove_lv")) {
_vg_remove_lv(argv, argc);
} else if (!strcmp(argv[0], "vgs_open")) {
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-26 14:37 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-26 14:37 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-26 14:37:15
Modified files:
test/api : test.c
Log message:
Update test/api/test.c to call lvm_lv_remove.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.9&r2=1.10
--- LVM2/test/api/test.c 2009/07/26 13:08:00 1.9
+++ LVM2/test/api/test.c 2009/07/26 14:37:15 1.10
@@ -50,6 +50,8 @@
static void _show_help(void)
{
+ printf("'vg_remove_lv vgname lvname': "
+ "Remove a LV\n");
printf("'vg_create_lv_linear vgname lvname size_in_bytes': "
"Create a linear LV\n");
printf("'scan_vgs': "
@@ -116,6 +118,23 @@
return 1;
}
+/* FIXME: this should be per vg */
+static lv_t *_lookup_lv_by_name(const char *name)
+{
+ lv_t *lv;
+
+ if (!name) {
+ printf ("Invalid LV name\n");
+ return NULL;
+ }
+ if (!(lv = dm_hash_lookup(_lvname_hash, name))) {
+ printf ("Can't find %s in LVs - run vg_create_lv first\n",
+ name);
+ return NULL;
+ }
+ return lv;
+}
+
static vg_t *_lookup_vg_by_name(char **argv, int argc)
{
vg_t *vg;
@@ -206,6 +225,7 @@
dm_hash_remove(_vgname_hash, lvm_vg_get_name(vg));
lvm_vg_close(vg);
}
+ /* FIXME: remove LVs from lvname_hash */
}
static void _show_one_vg(vg_t *vg)
@@ -297,6 +317,26 @@
}
}
+static void _vg_remove_lv(char **argv, int argc)
+{
+ lv_t *lv;
+
+ if (argc < 3) {
+ printf("Please enter vgname, lvname\n");
+ return;
+ }
+ if (!(lv = _lookup_lv_by_name(argv[2])))
+ return;
+ if (!lvm_vg_remove_lv(lv))
+ printf("Error ");
+ else {
+ printf("Success ");
+ dm_hash_remove(_lvname_hash, argv[2]);
+ }
+ printf("removing LV %s in VG %s\n",
+ argv[2], argv[1]);
+}
+
static void _vg_create_lv_linear(char **argv, int argc)
{
vg_t *vg;
@@ -311,10 +351,12 @@
lv = lvm_vg_create_lv_linear(vg, argv[2], atol(argv[3]));
if (!lv)
printf("Error ");
- else
+ else {
printf("Success ");
+ dm_hash_insert(_lvname_hash, argv[2], lv);
+ }
printf("creating LV %s in VG %s\n",
- argv[2], lvm_vg_get_name(vg));
+ argv[2], argv[1]);
}
static int lvmapi_test_shell(lvm_t libh)
@@ -362,6 +404,8 @@
_vg_open(argv, argc, libh);
} else if (!strcmp(argv[0], "vg_close")) {
_vg_close(argv, argc);
+ } else if (!strcmp(argv[0], "vg_remove_lv")) {
+ _vg_remove_lv(argv, argc);
} else if (!strcmp(argv[0], "vgs_open")) {
_list_open_vgs();
} else if (!strcmp(argv[0], "vg_list_pvs")) {
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-26 13:08 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-26 13:08 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-26 13:08:00
Modified files:
test/api : test.c
Log message:
Update test/api/test.c - correct list_vg_names and list_vg_ids.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.8&r2=1.9
--- LVM2/test/api/test.c 2009/07/26 13:07:41 1.8
+++ LVM2/test/api/test.c 2009/07/26 13:08:00 1.9
@@ -54,9 +54,9 @@
"Create a linear LV\n");
printf("'scan_vgs': "
"Scan the system for LVM metadata\n");
- printf("'vg_list_names': "
+ printf("'list_vg_names': "
"List the names of the VGs that exist in the system\n");
- printf("'vg_list_ids': "
+ printf("'list_vg_ids': "
"List the uuids of the VGs that exist in the system\n");
printf("'vg_list_pvs vgname': "
"List the PVs that exist in VG vgname\n");
@@ -247,7 +247,7 @@
lvm_scan_vgs(libh);
}
-static void _vg_list_names(lvm_t libh)
+static void _list_vg_names(lvm_t libh)
{
struct dm_list *list;
struct lvm_str_list *strl;
@@ -261,7 +261,7 @@
}
}
-static void _vg_list_ids(lvm_t libh)
+static void _list_vg_ids(lvm_t libh)
{
struct dm_list *list;
struct lvm_str_list *strl;
@@ -368,10 +368,10 @@
_pvs_in_vg(argv, argc);
} else if (!strcmp(argv[0], "vg_list_lvs")) {
_lvs_in_vg(argv, argc);
- } else if (!strcmp(argv[0], "vg_list_names")) {
- _vg_list_names(libh);
- } else if (!strcmp(argv[0], "vg_list_ids")) {
- _vg_list_ids(libh);
+ } else if (!strcmp(argv[0], "list_vg_names")) {
+ _list_vg_names(libh);
+ } else if (!strcmp(argv[0], "list_vg_ids")) {
+ _list_vg_ids(libh);
} else if (!strcmp(argv[0], "scan_vgs")) {
_scan_vgs(libh);
} else if (!strcmp(argv[0], "vg_create_lv_linear")) {
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-26 13:07 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-26 13:07 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-26 13:07:41
Modified files:
test/api : test.c
Log message:
Update test/api/test.c for liblvm 'get' functions.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.7&r2=1.8
--- LVM2/test/api/test.c 2009/07/26 02:35:47 1.7
+++ LVM2/test/api/test.c 2009/07/26 13:07:41 1.8
@@ -210,9 +210,10 @@
static void _show_one_vg(vg_t *vg)
{
- /* FIXME: uuid is not null terminated */
- printf("%s (%s): mode = %s\n", lvm_vg_get_name(vg),
- lvm_vg_get_uuid(vg), "READ");
+ printf("%s (%s): size=%"PRIu64", free=%"PRIu64", #pv=%"PRIu64"\n",
+ lvm_vg_get_name(vg), lvm_vg_get_uuid(vg),
+ lvm_vg_get_size(vg), lvm_vg_get_free(vg),
+ lvm_vg_get_pv_count(vg));
}
static void _list_open_vgs(void)
@@ -235,8 +236,9 @@
}
printf("PVs in VG %s:\n", lvm_vg_get_name(vg));
dm_list_iterate_items(pvl, pvs) {
- printf("%s (%s)\n",
- lvm_pv_get_name(pvl->pv), lvm_pv_get_uuid(pvl->pv));
+ printf("%s (%s): mda_count=%"PRIu64"\n",
+ lvm_pv_get_name(pvl->pv), lvm_pv_get_uuid(pvl->pv),
+ lvm_pv_get_mda_count(pvl->pv));
}
}
@@ -289,8 +291,9 @@
}
printf("LVs in VG %s:\n", lvm_vg_get_name(vg));
dm_list_iterate_items(lvl, lvs) {
- printf("%s/%s (%s)\n", lvm_vg_get_name(vg),
- lvm_lv_get_name(lvl->lv), lvm_lv_get_uuid(lvl->lv));
+ printf("%s/%s (%s): size=%"PRIu64"\n", lvm_vg_get_name(vg),
+ lvm_lv_get_name(lvl->lv), lvm_lv_get_uuid(lvl->lv),
+ lvm_lv_get_size(lvl->lv));
}
}
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-26 2:35 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-26 2:35 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-26 02:35:20
Modified files:
test/api : test.c
Log message:
Update test/api/test.c to handle read/write open modes.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.5&r2=1.6
--- LVM2/test/api/test.c 2009/07/24 12:51:32 1.5
+++ LVM2/test/api/test.c 2009/07/26 02:35:19 1.6
@@ -162,8 +162,10 @@
printf ("VG already open\n");
return;
}
- /* FIXME: allow different open modes */
- vg = lvm_vg_open(libh, argv[1], "r", 0);
+ if (argc < 3)
+ vg = lvm_vg_open(libh, argv[1], "r", 0);
+ else
+ vg = lvm_vg_open(libh, argv[1], argv[2], 0);
if (!vg || !lvm_vg_get_name(vg)) {
printf("Error opening %s\n", argv[1]);
return;
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-26 2:35 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-26 2:35 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-26 02:35:47
Modified files:
test/api : test.c
Log message:
Update test/api/test.c to call lvm_vg_create_lv_linear.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.6&r2=1.7
--- LVM2/test/api/test.c 2009/07/26 02:35:19 1.6
+++ LVM2/test/api/test.c 2009/07/26 02:35:47 1.7
@@ -50,6 +50,8 @@
static void _show_help(void)
{
+ printf("'vg_create_lv_linear vgname lvname size_in_bytes': "
+ "Create a linear LV\n");
printf("'scan_vgs': "
"Scan the system for LVM metadata\n");
printf("'vg_list_names': "
@@ -292,6 +294,26 @@
}
}
+static void _vg_create_lv_linear(char **argv, int argc)
+{
+ vg_t *vg;
+ lv_t *lv;
+
+ if (argc < 4) {
+ printf("Please enter vgname, lvname, and size\n");
+ return;
+ }
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ lv = lvm_vg_create_lv_linear(vg, argv[2], atol(argv[3]));
+ if (!lv)
+ printf("Error ");
+ else
+ printf("Success ");
+ printf("creating LV %s in VG %s\n",
+ argv[2], lvm_vg_get_name(vg));
+}
+
static int lvmapi_test_shell(lvm_t libh)
{
int argc;
@@ -349,6 +371,8 @@
_vg_list_ids(libh);
} else if (!strcmp(argv[0], "scan_vgs")) {
_scan_vgs(libh);
+ } else if (!strcmp(argv[0], "vg_create_lv_linear")) {
+ _vg_create_lv_linear(argv, argc);
} else {
printf ("Unrecognized command %s\n", argv[0]);
}
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-24 12:51 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-24 12:51 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-24 12:51:32
Modified files:
test/api : test.c
Log message:
Add tests for lvm_vg_name_list, lvm_vg_id_list and lvm_scan_vgs.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.4&r2=1.5
--- LVM2/test/api/test.c 2009/07/24 04:15:30 1.4
+++ LVM2/test/api/test.c 2009/07/24 12:51:32 1.5
@@ -50,6 +50,12 @@
static void _show_help(void)
{
+ printf("'scan_vgs': "
+ "Scan the system for LVM metadata\n");
+ printf("'vg_list_names': "
+ "List the names of the VGs that exist in the system\n");
+ printf("'vg_list_ids': "
+ "List the uuids of the VGs that exist in the system\n");
printf("'vg_list_pvs vgname': "
"List the PVs that exist in VG vgname\n");
printf("'vg_list_lvs vgname': "
@@ -230,6 +236,40 @@
}
}
+static void _scan_vgs(lvm_t libh)
+{
+ lvm_scan_vgs(libh);
+}
+
+static void _vg_list_names(lvm_t libh)
+{
+ struct dm_list *list;
+ struct lvm_str_list *strl;
+ const char *tmp;
+
+ list = lvm_list_vg_names(libh);
+ printf("VG names:\n");
+ dm_list_iterate_items(strl, list) {
+ tmp = strl->str;
+ printf("%s\n", tmp);
+ }
+}
+
+static void _vg_list_ids(lvm_t libh)
+{
+ struct dm_list *list;
+ struct lvm_str_list *strl;
+ const char *tmp;
+
+ list = lvm_list_vg_ids(libh);
+ printf("VG uuids:\n");
+ dm_list_iterate_items(strl, list) {
+ tmp = strl->str;
+ printf("%s\n", tmp);
+ }
+}
+
+
static void _lvs_in_vg(char **argv, int argc)
{
struct dm_list *lvs;
@@ -301,6 +341,12 @@
_pvs_in_vg(argv, argc);
} else if (!strcmp(argv[0], "vg_list_lvs")) {
_lvs_in_vg(argv, argc);
+ } else if (!strcmp(argv[0], "vg_list_names")) {
+ _vg_list_names(libh);
+ } else if (!strcmp(argv[0], "vg_list_ids")) {
+ _vg_list_ids(libh);
+ } else if (!strcmp(argv[0], "scan_vgs")) {
+ _scan_vgs(libh);
} else {
printf ("Unrecognized command %s\n", argv[0]);
}
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-24 4:15 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-24 4:15 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-24 04:15:30
Modified files:
test/api : test.c
Log message:
Update test/api/test.c to not segfault if null lists of pvs/lvs returned.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.3&r2=1.4
--- LVM2/test/api/test.c 2009/07/23 23:40:50 1.3
+++ LVM2/test/api/test.c 2009/07/24 04:15:30 1.4
@@ -124,14 +124,28 @@
}
return vg;
}
+static void _add_lvs_to_lvname_hash(struct dm_list *lvs)
+{
+ struct lvm_lv_list *lvl;
+ dm_list_iterate_items(lvl, lvs) {
+ /* Concatenate VG name with LV name */
+ dm_hash_insert(_lvname_hash, lvm_lv_get_name(lvl->lv), lvl->lv);
+ }
+}
+
+static void _add_pvs_to_pvname_hash(struct dm_list *pvs)
+{
+ struct lvm_pv_list *pvl;
+ dm_list_iterate_items(pvl, pvs) {
+ dm_hash_insert(_pvname_hash, lvm_pv_get_name(pvl->pv), pvl->pv);
+ }
+}
static void _vg_open(char **argv, int argc, lvm_t libh)
{
vg_t *vg;
struct dm_list *lvs;
- struct lvm_lv_list *lvl;
struct dm_list *pvs;
- struct lvm_pv_list *pvl;
if (argc < 2) {
printf ("Please enter vg_name\n");
@@ -157,14 +171,11 @@
* Add the LVs and PVs into the hashes for lookups
*/
lvs = lvm_vg_list_lvs(vg);
- dm_list_iterate_items(lvl, lvs) {
- /* Concatenate VG name with LV name */
- dm_hash_insert(_lvname_hash, lvm_lv_get_name(lvl->lv), lvl->lv);
- }
+ if (lvs && !dm_list_empty(lvs))
+ _add_lvs_to_lvname_hash(lvs);
pvs = lvm_vg_list_pvs(vg);
- dm_list_iterate_items(pvl, pvs) {
- dm_hash_insert(_pvname_hash, lvm_pv_get_name(pvl->pv), pvl->pv);
- }
+ if (pvs && !dm_list_empty(pvs))
+ _add_pvs_to_pvname_hash(pvs);
}
static void _vg_close(char **argv, int argc)
^ permalink raw reply [flat|nested] 23+ messages in thread
* LVM2/test/api test.c
@ 2009-07-23 23:40 wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: wysochanski @ 2009-07-23 23:40 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2009-07-23 23:40:50
Modified files:
test/api : test.c
Log message:
Update test/api/test.c for simple tests involving pv/vg/lv name/uuid attributes.
Tests the following APIs:
- lvm_{pv|vg|lv}_get_{name|uuid}()
- lvm_{lvs|pvs}_in_vg()
Example:
lvm> vg_open VolGroup00
Success opening vg VolGroup00
lvm> vg_list_lvs VolGroup00
LVs in VG VolGroup00:
VolGroup00/LogVol00 (bFO4EU-UaDu-iuMm-N6BA-xcZc-nm3u-J5K5lu)
VolGroup00/LogVol01 (BHGsPK-PwzY-kye0-MEWa-a67z-BiYE-03ZjwM)
lvm> vg_list_pvs VolGroup00
PVs in VG VolGroup00:
/dev/sda2 (Be91pt-CqT0-4YJE-nGI6-Oisz-hy0N-l9CHgn)
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Acked-by: Thomas Woerner <twoerner@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/test.c.diff?cvsroot=lvm2&r1=1.2&r2=1.3
--- LVM2/test/api/test.c 2009/02/24 13:03:45 1.2
+++ LVM2/test/api/test.c 2009/07/23 23:40:50 1.3
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
+ * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
@@ -29,7 +29,7 @@
while (*b && isspace(*b))
b++;
- if ((!*b) || (*b == '#'))
+ if ((!*b) || ((*argc == 0)&&(*b == '#')))
break;
e = b;
@@ -48,11 +48,204 @@
return *argc;
}
+static void _show_help(void)
+{
+ printf("'vg_list_pvs vgname': "
+ "List the PVs that exist in VG vgname\n");
+ printf("'vg_list_lvs vgname': "
+ "List the LVs that exist in VG vgname\n");
+ printf("'vgs_open': "
+ "List the VGs that are currently open\n");
+ printf("'vgs': "
+ "List all VGs known to the system\n");
+ printf("'vg_open vgname ['r' | 'w']': "
+ "Issue a lvm_vg_open() API call on VG 'vgname'\n");
+ printf("'vg_close vgname': "
+ "Issue a lvm_vg_close() API call on VG 'vgname'\n");
+ printf("'quit': exit the program\n");
+}
+
+static struct dm_hash_table *_vgid_hash = NULL;
+static struct dm_hash_table *_vgname_hash = NULL;
+static struct dm_hash_table *_pvname_hash = NULL;
+static struct dm_hash_table *_lvname_hash = NULL;
+
+static void _hash_destroy_single(struct dm_hash_table **htable)
+{
+ if (htable && *htable) {
+ dm_hash_destroy(*htable);
+ *htable = NULL;
+ }
+}
+
+static void _hash_destroy(void)
+{
+ _hash_destroy_single(&_vgname_hash);
+ _hash_destroy_single(&_vgid_hash);
+ _hash_destroy_single(&_pvname_hash);
+ _hash_destroy_single(&_lvname_hash);
+}
+
+static int _hash_create(void)
+{
+ if (!(_vgname_hash = dm_hash_create(128)))
+ return 0;
+ if (!(_pvname_hash = dm_hash_create(128))) {
+ _hash_destroy_single(&_vgname_hash);
+ return 0;
+ }
+ if (!(_lvname_hash = dm_hash_create(128))) {
+ _hash_destroy_single(&_vgname_hash);
+ _hash_destroy_single(&_pvname_hash);
+ return 0;
+ }
+ if (!(_vgid_hash = dm_hash_create(128))) {
+ _hash_destroy_single(&_vgname_hash);
+ _hash_destroy_single(&_pvname_hash);
+ _hash_destroy_single(&_lvname_hash);
+ return 0;
+ }
+ return 1;
+}
+
+static vg_t *_lookup_vg_by_name(char **argv, int argc)
+{
+ vg_t *vg;
+
+ if (argc < 2) {
+ printf ("Please enter vg_name\n");
+ return NULL;
+ }
+ if (!(vg = dm_hash_lookup(_vgid_hash, argv[1])) &&
+ !(vg = dm_hash_lookup(_vgname_hash, argv[1]))) {
+ printf ("Can't find %s in open VGs - run vg_open first\n",
+ argv[1]);
+ return NULL;
+ }
+ return vg;
+}
+
+static void _vg_open(char **argv, int argc, lvm_t libh)
+{
+ vg_t *vg;
+ struct dm_list *lvs;
+ struct lvm_lv_list *lvl;
+ struct dm_list *pvs;
+ struct lvm_pv_list *pvl;
+
+ 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 already open\n");
+ return;
+ }
+ /* FIXME: allow different open modes */
+ vg = lvm_vg_open(libh, argv[1], "r", 0);
+ if (!vg || !lvm_vg_get_name(vg)) {
+ printf("Error opening %s\n", argv[1]);
+ return;
+ }
+
+ printf("Success opening vg %s\n", argv[1]);
+ dm_hash_insert(_vgname_hash, lvm_vg_get_name(vg), vg);
+ dm_hash_insert(_vgid_hash, lvm_vg_get_uuid(vg), vg);
+
+ /*
+ * Add the LVs and PVs into the hashes for lookups
+ */
+ lvs = lvm_vg_list_lvs(vg);
+ dm_list_iterate_items(lvl, lvs) {
+ /* Concatenate VG name with LV name */
+ dm_hash_insert(_lvname_hash, lvm_lv_get_name(lvl->lv), lvl->lv);
+ }
+ pvs = lvm_vg_list_pvs(vg);
+ dm_list_iterate_items(pvl, pvs) {
+ dm_hash_insert(_pvname_hash, lvm_pv_get_name(pvl->pv), pvl->pv);
+ }
+}
+
+static void _vg_close(char **argv, int argc)
+{
+ vg_t *vg;
+
+ if (argc < 2) {
+ printf ("Please enter vg_name\n");
+ return;
+ }
+ while((vg = dm_hash_lookup(_vgname_hash, argv[1]))) {
+ dm_hash_remove(_vgid_hash, lvm_vg_get_uuid(vg));
+ dm_hash_remove(_vgname_hash, lvm_vg_get_name(vg));
+ lvm_vg_close(vg);
+ }
+ while((vg = dm_hash_lookup(_vgid_hash, argv[1]))) {
+ dm_hash_remove(_vgid_hash, lvm_vg_get_uuid(vg));
+ dm_hash_remove(_vgname_hash, lvm_vg_get_name(vg));
+ lvm_vg_close(vg);
+ }
+}
+
+static void _show_one_vg(vg_t *vg)
+{
+ /* FIXME: uuid is not null terminated */
+ printf("%s (%s): mode = %s\n", lvm_vg_get_name(vg),
+ lvm_vg_get_uuid(vg), "READ");
+}
+
+static void _list_open_vgs(void)
+{
+ dm_hash_iter(_vgid_hash, (dm_hash_iterate_fn) _show_one_vg);
+}
+
+static void _pvs_in_vg(char **argv, int argc)
+{
+ struct dm_list *pvs;
+ struct lvm_pv_list *pvl;
+ vg_t *vg;
+
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ pvs = lvm_vg_list_pvs(vg);
+ if (!pvs || dm_list_empty(pvs)) {
+ printf("No PVs in VG %s\n", lvm_vg_get_name(vg));
+ return;
+ }
+ printf("PVs in VG %s:\n", lvm_vg_get_name(vg));
+ dm_list_iterate_items(pvl, pvs) {
+ printf("%s (%s)\n",
+ lvm_pv_get_name(pvl->pv), lvm_pv_get_uuid(pvl->pv));
+ }
+}
+
+static void _lvs_in_vg(char **argv, int argc)
+{
+ struct dm_list *lvs;
+ struct lvm_lv_list *lvl;
+ vg_t *vg;
+
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ lvs = lvm_vg_list_lvs(vg);
+ if (!lvs || dm_list_empty(lvs)) {
+ printf("No LVs in VG %s\n", lvm_vg_get_name(vg));
+ return;
+ }
+ printf("LVs in VG %s:\n", lvm_vg_get_name(vg));
+ dm_list_iterate_items(lvl, lvs) {
+ printf("%s/%s (%s)\n", lvm_vg_get_name(vg),
+ lvm_lv_get_name(lvl->lv), lvm_lv_get_uuid(lvl->lv));
+ }
+}
+
static int lvmapi_test_shell(lvm_t libh)
{
- int argc, i;
+ int argc;
char *input = NULL, *args[MAX_ARGS], **argv;
+ _hash_create();
+ argc=0;
while (1) {
free(input);
input = readline("lvm> ");
@@ -86,17 +279,28 @@
printf("Exiting.\n");
break;
} else if (!strcmp(argv[0], "?") || !strcmp(argv[0], "help")) {
- printf("No commands defined\n");
- } else if (!strcmp(argv[0], "scan")) {
- for (i=1; i < argc; i++)
- printf("Scan a path!\n");
+ _show_help();
+ } else if (!strcmp(argv[0], "vg_open")) {
+ _vg_open(argv, argc, libh);
+ } else if (!strcmp(argv[0], "vg_close")) {
+ _vg_close(argv, argc);
+ } else if (!strcmp(argv[0], "vgs_open")) {
+ _list_open_vgs();
+ } else if (!strcmp(argv[0], "vg_list_pvs")) {
+ _pvs_in_vg(argv, argc);
+ } else if (!strcmp(argv[0], "vg_list_lvs")) {
+ _lvs_in_vg(argv, argc);
+ } else {
+ printf ("Unrecognized command %s\n", argv[0]);
}
}
+ dm_hash_iter(_vgname_hash, (dm_hash_iterate_fn) lvm_vg_close);
+ _hash_destroy();
free(input);
return 0;
}
-
+
int main (int argc, char *argv[])
{
lvm_t libh;
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2011-03-01 23:29 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-01 23:29 LVM2/test/api test.c zkabelac
-- strict thread matches above, loose matches on Subject: below --
2011-03-01 23:18 zkabelac
2010-11-25 14:35 mornfall
2010-11-17 20:13 mornfall
2010-11-17 19:17 mornfall
2010-10-25 14:09 wysochanski
2010-05-19 11:53 wysochanski
2010-02-24 18:16 wysochanski
2009-08-07 21:22 wysochanski
2009-07-28 14:12 wysochanski
2009-07-28 13:49 wysochanski
2009-07-27 21:02 wysochanski
2009-07-27 17:45 wysochanski
2009-07-26 20:59 wysochanski
2009-07-26 20:58 wysochanski
2009-07-26 14:37 wysochanski
2009-07-26 13:08 wysochanski
2009-07-26 13:07 wysochanski
2009-07-26 2:35 wysochanski
2009-07-26 2:35 wysochanski
2009-07-24 12:51 wysochanski
2009-07-24 4:15 wysochanski
2009-07-23 23:40 wysochanski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).