1 /* libguestfs - the guestfsd daemon
2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 /* LVM actions. Keep an eye on liblvm, although at the time
31 * of writing it hasn't progressed very far.
35 convert_lvm_output (char *out, char *prefix)
39 int size = 0, alloc = 0;
45 pend = strchr (p, '\n'); /* Get the next line of output. */
51 while (*p && isspace (*p)) /* Skip any leading whitespace. */
54 if (!*p) { /* Empty line? Skip it. */
61 snprintf (buf, sizeof buf, "%s%s", prefix, p);
66 if (add_string (&r, &size, &alloc, str) == -1) {
76 if (add_string (&r, &size, &alloc, NULL) == -1)
79 sort_strings (r, size-1);
89 r = command (&out, &err,
90 "/sbin/lvm", "pvs", "-o", "pv_name", "--noheadings", NULL);
92 reply_with_error ("%s", err);
100 return convert_lvm_output (out, NULL);
109 r = command (&out, &err,
110 "/sbin/lvm", "vgs", "-o", "vg_name", "--noheadings", NULL);
112 reply_with_error ("%s", err);
120 return convert_lvm_output (out, NULL);
129 r = command (&out, &err,
131 "-o", "vg_name,lv_name", "--noheadings",
132 "--separator", "/", NULL);
134 reply_with_error ("%s", err);
142 return convert_lvm_output (out, "/dev/");
145 /* These were so complex to implement that I ended up auto-generating
146 * the code. That code is in stubs.c, and it is generated as usual
149 guestfs_lvm_int_pv_list *
152 return parse_command_line_pvs ();
155 guestfs_lvm_int_vg_list *
158 return parse_command_line_vgs ();
161 guestfs_lvm_int_lv_list *
164 return parse_command_line_lvs ();