4 * Copyright (C) 2009 Red Hat, Inc. All rights reserved.
6 * This file is part of LVM2.
8 * This copyrighted material is made available to anyone wishing to use,
9 * modify, copy, or redistribute it subject to the terms and conditions
10 * of the GNU Lesser General Public License v.2.1.
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Unit test case for vgcreate and related APIs.
18 * # gcc -g vgcreate.c -I../../liblvm -I../../include -L../../liblvm \
19 * -L../../libdm -ldevmapper -llvm2app
20 * # export LD_LIBRARY_PATH=`pwd`/../../libdm:`pwd`/../../liblvm
31 #define MAX_DEVICES 16
32 const char *device
[MAX_DEVICES
];
35 #define vg_create(vg_name) \
36 printf("Creating VG %s\n", vg_name); \
37 vg = lvm_vg_create(handle, vg_name); \
39 fprintf(stderr, "Error creating volume group %s\n", vg_name); \
42 #define vg_extend(vg, dev) \
43 printf("Extending VG %s by %s\n", vg_name, dev); \
44 status = lvm_vg_extend(vg, dev); \
46 fprintf(stderr, "Error extending volume group %s " \
47 "with device %s\n", vg_name, dev); \
50 #define vg_commit(vg) \
51 printf("Committing VG %s to disk\n", vg_name); \
52 status = lvm_vg_write(vg); \
54 fprintf(stderr, "Commit of volume group '%s' failed\n", \
55 lvm_vg_get_name(vg)); \
58 #define vg_open(vg_name, mode) \
59 printf("Opening VG %s %s\n", vg_name, mode); \
60 vg = lvm_vg_open(handle, vg_name, mode, 0); \
62 fprintf(stderr, "Error opening volume group %s\n", vg_name); \
65 #define vg_close(vg) \
66 printf("Closing VG %s\n", vg_name); \
67 if (lvm_vg_close(vg)) { \
68 fprintf(stderr, "Error closing volume group %s\n", vg_name); \
71 #define vg_reduce(vg, dev) \
72 printf("Reducing VG %s by %s\n", vg_name, dev); \
73 status = lvm_vg_reduce(vg, dev); \
75 fprintf(stderr, "Error reducing volume group %s " \
76 "by device %s\n", vg_name, dev); \
79 #define vg_remove(vg) \
80 printf("Removing VG %s from system\n", vg_name); \
81 status = lvm_vg_remove(vg); \
83 fprintf(stderr, "Revmoval of volume group '%s' failed\n", \
88 static int init_vgtest(int argc
, char *argv
[])
93 fprintf(stderr
, "Usage: %s <vgname> <pv1> <pv2> [... <pvN> ]",
98 for(i
=2; i
<MAX_DEVICES
&& i
< argc
; i
++) {
99 device
[i
-2] = argv
[i
];
104 int main(int argc
, char *argv
[])
108 if (init_vgtest(argc
, argv
) < 0)
111 /* FIXME: make the below messages verbose-only and print PASS/FAIL*/
112 printf("Opening LVM\n");
113 handle
= lvm_init(NULL
);
115 fprintf(stderr
, "Unable to lvm_init\n");
119 printf("Library version: %s\n", lvm_library_get_version());
121 vg_extend(vg
, device
[0]);
123 printf("Setting VG %s extent_size to %"PRIu64
"\n", vg_name
, size
);
124 status
= lvm_vg_set_extent_size(vg
, size
);
126 fprintf(stderr
, "Can not set physical extent "
127 "size '%"PRIu64
"' for '%s'\n",
135 vg_open(vg_name
, "r");
138 vg_open(vg_name
, "w");
139 vg_extend(vg
, device
[1]);
140 vg_reduce(vg
, device
[0]);
144 vg_open(vg_name
, "w");
145 vg_extend(vg
, device
[0]);
149 vg_open(vg_name
, "w");
155 printf("liblvm vgcreate unit test PASS\n");
158 printf("liblvm vgcreate unit test FAIL\n");
159 if (handle
&& lvm_errno(handle
))
160 fprintf(stderr
, "LVM Error: %s\n", lvm_errmsg(handle
));