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;
46 pend = strchr (p, '\n'); /* Get the next line of output. */
52 while (*p && isspace (*p)) /* Skip any leading whitespace. */
55 /* Sigh, skip trailing whitespace too. "pvs", I'm looking at you. */
57 while (*p && isspace (p[len]))
60 if (!*p) { /* Empty line? Skip it. */
67 snprintf (buf, sizeof buf, "%s%s", prefix, p);
72 if (add_string (&r, &size, &alloc, str) == -1) {
82 if (add_string (&r, &size, &alloc, NULL) == -1)
85 sort_strings (r, size-1);
95 r = command (&out, &err,
96 "/sbin/lvm", "pvs", "-o", "pv_name", "--noheadings", NULL);
98 reply_with_error ("%s", err);
106 return convert_lvm_output (out, NULL);
115 r = command (&out, &err,
116 "/sbin/lvm", "vgs", "-o", "vg_name", "--noheadings", NULL);
118 reply_with_error ("%s", err);
126 return convert_lvm_output (out, NULL);
135 r = command (&out, &err,
137 "-o", "vg_name,lv_name", "--noheadings",
138 "--separator", "/", NULL);
140 reply_with_error ("%s", err);
148 return convert_lvm_output (out, "/dev/");
151 /* These were so complex to implement that I ended up auto-generating
152 * the code. That code is in stubs.c, and it is generated as usual
155 guestfs_lvm_int_pv_list *
158 return parse_command_line_pvs ();
161 guestfs_lvm_int_vg_list *
164 return parse_command_line_vgs ();
167 guestfs_lvm_int_lv_list *
170 return parse_command_line_lvs ();