2 * Copyright (C) 2009 Red Hat, Inc. All rights reserved.
4 * This file is part of LVM2.
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU Lesser General Public License v.2.1.
10 * You should have received a copy of the GNU Lesser General Public License
11 * along with this program; if not, write to the Free Software Foundation,
12 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 * Unit test case for vgcreate and related APIs.
16 * # gcc -g vgcreate.c -I../../liblvm -I../../include -L../../liblvm \
17 * -L../../libdm -ldevmapper -llvm2app
18 * # export LD_LIBRARY_PATH=`pwd`/../../libdm:`pwd`/../../liblvm
29 #define MAX_DEVICES 16
30 const char *device[MAX_DEVICES];
33 #define vg_create(vg_name) \
34 printf("Creating VG %s\n", vg_name); \
35 vg = lvm_vg_create(handle, vg_name); \
37 fprintf(stderr, "Error creating volume group %s\n", vg_name); \
40 #define vg_extend(vg, dev) \
41 printf("Extending VG %s by %s\n", vg_name, dev); \
42 status = lvm_vg_extend(vg, dev); \
44 fprintf(stderr, "Error extending volume group %s " \
45 "with device %s\n", vg_name, dev); \
48 #define vg_commit(vg) \
49 printf("Committing VG %s to disk\n", vg_name); \
50 status = lvm_vg_write(vg); \
52 fprintf(stderr, "Commit of volume group '%s' failed\n", \
53 lvm_vg_get_name(vg)); \
56 #define vg_open(vg_name, mode) \
57 printf("Opening VG %s %s\n", vg_name, mode); \
58 vg = lvm_vg_open(handle, vg_name, mode, 0); \
60 fprintf(stderr, "Error opening volume group %s\n", vg_name); \
63 #define vg_close(vg) \
64 printf("Closing VG %s\n", vg_name); \
65 if (lvm_vg_close(vg)) { \
66 fprintf(stderr, "Error closing volume group %s\n", vg_name); \
69 #define vg_reduce(vg, dev) \
70 printf("Reducing VG %s by %s\n", vg_name, dev); \
71 status = lvm_vg_reduce(vg, dev); \
73 fprintf(stderr, "Error reducing volume group %s " \
74 "by device %s\n", vg_name, dev); \
77 #define vg_remove(vg) \
78 printf("Removing VG %s from system\n", vg_name); \
79 status = lvm_vg_remove(vg); \
81 fprintf(stderr, "Revmoval of volume group '%s' failed\n", \
86 static int init_vgtest(int argc, char *argv[])
91 fprintf(stderr, "Usage: %s <vgname> <pv1> <pv2> [... <pvN> ]",
96 for(i=2; i<MAX_DEVICES && i < argc; i++) {
97 device[i-2] = argv[i];
102 int main(int argc, char *argv[])
106 if (init_vgtest(argc, argv) < 0)
109 /* FIXME: make the below messages verbose-only and print PASS/FAIL*/
110 printf("Opening LVM\n");
111 handle = lvm_init(NULL);
113 fprintf(stderr, "Unable to lvm_init\n");
117 printf("Library version: %s\n", lvm_library_get_version());
119 vg_extend(vg, device[0]);
121 printf("Setting VG %s extent_size to %"PRIu64"\n", vg_name, size);
122 status = lvm_vg_set_extent_size(vg, size);
124 fprintf(stderr, "Can not set physical extent "
125 "size '%"PRIu64"' for '%s'\n",
133 vg_open(vg_name, "r");
136 vg_open(vg_name, "w");
137 vg_extend(vg, device[1]);
138 vg_reduce(vg, device[0]);
142 vg_open(vg_name, "w");
143 vg_extend(vg, device[0]);
147 vg_open(vg_name, "w");
153 printf("liblvm vgcreate unit test PASS\n");
156 printf("liblvm vgcreate unit test FAIL\n");
157 if (handle && lvm_errno(handle))
158 fprintf(stderr, "LVM Error: %s\n", lvm_errmsg(handle));