----------------------------------------------------------------------
Complete the Haskell bindings (see discussion on haskell-cafe).
-
-----------------------------------------------------------------------
-
-Practically, resizing the partitions when a block device is resized
-isn't possible. So for example it's not possible to resize a Fedora
-block device. If you try to use sfdisk-N to change the boundaries of
-the existing partition to fill up the new space, you get an error that
-the partition is in use.
-
-The reason, I now think, is because LVM is using the partition as a
-PV, and this locks it as far as the kernel is concerned.
-
-Removing the PV [which is what we do in the test suite] isn't
-desirable if the PV contains data you care about. Rebooting the qemu
-subprocess after the partition table change works, but isn't very
-cool. I believe what we need to do is to temporarily reconfigure LVM
-(using /etc/lvm/lvm.conf) to ignore the PV, vgscan (which will then
-ignore the PV), make the changes to the partition table, then set the
-LVM configuration back and do a final vgscan.
-
-Need to test the above, and find a nice way to present it through
-the API.
extern char *do_sfdisk_l (const char *device);
extern char *do_sfdisk_kernel_geometry (const char *device);
extern char *do_sfdisk_disk_geometry (const char *device);
+extern int do_vg_activate_all (int activate);
+extern int do_vg_activate (int activate, char * const* const volgroups);
free (err);
return 0;
}
+
+int
+do_vg_activate (int activate, char * const* const volgroups)
+{
+ char *err;
+ int r, i, argc;
+ const char **argv;
+
+ argc = count_strings (volgroups) + 4;
+ argv = malloc (sizeof (char *) * (argc+1));
+ if (argv == NULL) {
+ reply_with_perror ("malloc");
+ return -1;
+ }
+
+ argv[0] = "/sbin/lvm";
+ argv[1] = "vgchange";
+ argv[2] = "-a";
+ argv[3] = activate ? "y" : "n";
+ for (i = 4; i <= argc; ++i)
+ argv[i] = volgroups[i-4];
+
+ r = commandv (NULL, &err, argv);
+ if (r == -1) {
+ reply_with_error ("vgchange: %s", err);
+ free (err);
+ return -1;
+ }
+
+ free (err);
+ return 0;
+}
+
+int
+do_vg_activate_all (int activate)
+{
+ char *empty[] = { NULL };
+ return do_vg_activate (activate, empty);
+}
IS_DEVICE (device, -1);
- strcpy (buf, "/sbin/sfdisk --no-reread");
+ strcpy (buf, "/sbin/sfdisk");
if (n > 0)
sprintf (buf + strlen (buf), " -N %d", n);
if (cyls)
/* Safe because of IS_DEVICE above: */
sprintf (buf + strlen (buf), " %s", device);
+ if (verbose)
+ printf ("%s\n", buf);
+
fp = popen (buf, "w");
if (fp == NULL) {
reply_with_perror (buf);
xdr_free ((xdrproc_t) xdr_guestfs_sfdisk_disk_geometry_args, (char *) &args);
}
+static void vg_activate_all_stub (XDR *xdr_in)
+{
+ int r;
+ struct guestfs_vg_activate_all_args args;
+ int activate;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_vg_activate_all_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "vg_activate_all");
+ return;
+ }
+ activate = args.activate;
+
+ r = do_vg_activate_all (activate);
+ if (r == -1)
+ /* do_vg_activate_all has already called reply_with_error */
+ goto done;
+
+ reply (NULL, NULL);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_vg_activate_all_args, (char *) &args);
+}
+
+static void vg_activate_stub (XDR *xdr_in)
+{
+ int r;
+ struct guestfs_vg_activate_args args;
+ int activate;
+ char **volgroups;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_vg_activate_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "vg_activate");
+ return;
+ }
+ activate = args.activate;
+ volgroups = realloc (args.volgroups.volgroups_val,
+ sizeof (char *) * (args.volgroups.volgroups_len+1));
+ if (volgroups == NULL) {
+ reply_with_perror ("realloc");
+ goto done;
+ }
+ volgroups[args.volgroups.volgroups_len] = NULL;
+ args.volgroups.volgroups_val = volgroups;
+
+ r = do_vg_activate (activate, volgroups);
+ if (r == -1)
+ /* do_vg_activate has already called reply_with_error */
+ goto done;
+
+ reply (NULL, NULL);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_vg_activate_args, (char *) &args);
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_SFDISK_DISK_GEOMETRY:
sfdisk_disk_geometry_stub (xdr_in);
break;
+ case GUESTFS_PROC_VG_ACTIVATE_ALL:
+ vg_activate_all_stub (xdr_in);
+ break;
+ case GUESTFS_PROC_VG_ACTIVATE:
+ vg_activate_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
}
printf ("%-20s %s\n", "umount", "unmount a filesystem");
printf ("%-20s %s\n", "umount-all", "unmount all filesystems");
printf ("%-20s %s\n", "upload", "upload a file from the local machine");
+ printf ("%-20s %s\n", "vg-activate", "activate or deactivate some volume groups");
+ printf ("%-20s %s\n", "vg-activate-all", "activate or deactivate all volume groups");
printf ("%-20s %s\n", "vgcreate", "create an LVM volume group");
printf ("%-20s %s\n", "vgremove", "remove an LVM volume group");
printf ("%-20s %s\n", "vgs", "list the LVM volume groups (VGs)");
if (strcasecmp (cmd, "sfdisk_disk_geometry") == 0 || strcasecmp (cmd, "sfdisk-disk-geometry") == 0)
pod2text ("sfdisk-disk-geometry - display the disk geometry from the partition table", " sfdisk-disk-geometry <device>\n\nThis displays the disk geometry of C<device> read from the\npartition table. Especially in the case where the underlying\nblock device has been resized, this can be different from the\nkernel's idea of the geometry (see C<sfdisk_kernel_geometry>).\n\nThe result is in human-readable format, and not designed to\nbe parsed.");
else
+ if (strcasecmp (cmd, "vg_activate_all") == 0 || strcasecmp (cmd, "vg-activate-all") == 0)
+ pod2text ("vg-activate-all - activate or deactivate all volume groups", " vg-activate-all <activate>\n\nThis command activates or (if C<activate> is false) deactivates\nall logical volumes in all volume groups.\nIf activated, then they are made known to the\nkernel, ie. they appear as C</dev/mapper> devices. If deactivated,\nthen those devices disappear.\n\nThis command is the same as running C<vgchange -a y|n>");
+ else
+ if (strcasecmp (cmd, "vg_activate") == 0 || strcasecmp (cmd, "vg-activate") == 0)
+ pod2text ("vg-activate - activate or deactivate some volume groups", " vg-activate <activate> <volgroups>\n\nThis command activates or (if C<activate> is false) deactivates\nall logical volumes in the listed volume groups C<volgroups>.\nIf activated, then they are made known to the\nkernel, ie. they appear as C</dev/mapper> devices. If deactivated,\nthen those devices disappear.\n\nThis command is the same as running C<vgchange -a y|n volgroups...>\n\nNote that if C<volgroups> is an empty list then B<all> volume groups\nare activated or deactivated.");
+ else
display_builtin_command (cmd);
}
return 0;
}
+static int run_vg_activate_all (const char *cmd, int argc, char *argv[])
+{
+ int r;
+ int activate;
+ if (argc != 1) {
+ fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ activate = is_true (argv[0]) ? 1 : 0;
+ r = guestfs_vg_activate_all (g, activate);
+ return r;
+}
+
+static int run_vg_activate (const char *cmd, int argc, char *argv[])
+{
+ int r;
+ int activate;
+ char **volgroups;
+ if (argc != 2) {
+ fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ activate = is_true (argv[0]) ? 1 : 0;
+ volgroups = parse_string_list (argv[1]);
+ r = guestfs_vg_activate (g, activate, volgroups);
+ return r;
+}
+
int run_action (const char *cmd, int argc, char *argv[])
{
if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
if (strcasecmp (cmd, "sfdisk_disk_geometry") == 0 || strcasecmp (cmd, "sfdisk-disk-geometry") == 0)
return run_sfdisk_disk_geometry (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "vg_activate_all") == 0 || strcasecmp (cmd, "vg-activate-all") == 0)
+ return run_vg_activate_all (cmd, argc, argv);
+ else
+ if (strcasecmp (cmd, "vg_activate") == 0 || strcasecmp (cmd, "vg-activate") == 0)
+ return run_vg_activate (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
"unmount-all",
"upload",
"verbose",
+ "vg-activate",
+ "vg-activate-all",
"vgcreate",
"vgremove",
"vgs",
Use C<-> instead of a filename to read/write from stdin/stdout.
+=head2 vg-activate
+
+ vg-activate true|false 'volgroups ...'
+
+This command activates or (if C<activate> is false) deactivates
+all logical volumes in the listed volume groups C<volgroups>.
+If activated, then they are made known to the
+kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
+then those devices disappear.
+
+This command is the same as running C<vgchange -a y|n volgroups...>
+
+Note that if C<volgroups> is an empty list then B<all> volume groups
+are activated or deactivated.
+
+=head2 vg-activate-all
+
+ vg-activate-all true|false
+
+This command activates or (if C<activate> is false) deactivates
+all logical volumes in all volume groups.
+If activated, then they are made known to the
+kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
+then those devices disappear.
+
+This command is the same as running C<vgchange -a y|n>
+
=head2 vgcreate
vgcreate volgroup 'physvols ...'
This function returns 0 on success or -1 on error.
+=head2 guestfs_vg_activate
+
+ int guestfs_vg_activate (guestfs_h *handle,
+ int activate,
+ char * const* const volgroups);
+
+This command activates or (if C<activate> is false) deactivates
+all logical volumes in the listed volume groups C<volgroups>.
+If activated, then they are made known to the
+kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
+then those devices disappear.
+
+This command is the same as running C<vgchange -a y|n volgroups...>
+
+Note that if C<volgroups> is an empty list then B<all> volume groups
+are activated or deactivated.
+
+This function returns 0 on success or -1 on error.
+
+=head2 guestfs_vg_activate_all
+
+ int guestfs_vg_activate_all (guestfs_h *handle,
+ int activate);
+
+This command activates or (if C<activate> is false) deactivates
+all logical volumes in all volume groups.
+If activated, then they are made known to the
+kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
+then those devices disappear.
+
+This command is the same as running C<vgchange -a y|n>
+
+This function returns 0 on success or -1 on error.
+
=head2 guestfs_vgcreate
int guestfs_vgcreate (guestfs_h *handle,
private native String _sfdisk_disk_geometry (long g, String device)
throws LibGuestFSException;
+ /**
+ * activate or deactivate all volume groups
+ *
+ * This command activates or (if "activate" is false)
+ * deactivates all logical volumes in all volume groups. If
+ * activated, then they are made known to the kernel, ie.
+ * they appear as "/dev/mapper" devices. If deactivated,
+ * then those devices disappear.
+ *
+ * This command is the same as running "vgchange -a y|n"
+ *
+ * @throws LibGuestFSException
+ */
+ public void vg_activate_all (boolean activate)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("vg_activate_all: handle is closed");
+ _vg_activate_all (g, activate);
+ }
+ private native void _vg_activate_all (long g, boolean activate)
+ throws LibGuestFSException;
+
+ /**
+ * activate or deactivate some volume groups
+ *
+ * This command activates or (if "activate" is false)
+ * deactivates all logical volumes in the listed volume
+ * groups "volgroups". If activated, then they are made
+ * known to the kernel, ie. they appear as "/dev/mapper"
+ * devices. If deactivated, then those devices disappear.
+ *
+ * This command is the same as running "vgchange -a y|n
+ * volgroups..."
+ *
+ * Note that if "volgroups" is an empty list then all
+ * volume groups are activated or deactivated.
+ *
+ * @throws LibGuestFSException
+ */
+ public void vg_activate (boolean activate, String[] volgroups)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("vg_activate: handle is closed");
+ _vg_activate (g, activate, volgroups);
+ }
+ private native void _vg_activate (long g, boolean activate, String[] volgroups)
+ throws LibGuestFSException;
+
}
return jr;
}
+JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1vg_1activate_1all
+ (JNIEnv *env, jobject obj, jlong jg, jboolean jactivate)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ int r;
+ int activate;
+
+ activate = jactivate;
+ r = guestfs_vg_activate_all (g, activate);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
+JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1vg_1activate
+ (JNIEnv *env, jobject obj, jlong jg, jboolean jactivate, jobjectArray jvolgroups)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ int r;
+ int activate;
+ int volgroups_len;
+ const char **volgroups;
+ int i;
+
+ activate = jactivate;
+ volgroups_len = (*env)->GetArrayLength (env, jvolgroups);
+ volgroups = guestfs_safe_malloc (g, sizeof (char *) * (volgroups_len+1));
+ for (i = 0; i < volgroups_len; ++i) {
+ jobject o = (*env)->GetObjectArrayElement (env, jvolgroups, i);
+ volgroups[i] = (*env)->GetStringUTFChars (env, o, NULL);
+ }
+ volgroups[volgroups_len] = NULL;
+ r = guestfs_vg_activate (g, activate, volgroups);
+ for (i = 0; i < volgroups_len; ++i) {
+ jobject o = (*env)->GetObjectArrayElement (env, jvolgroups, i);
+ (*env)->ReleaseStringUTFChars (env, o, volgroups[i]);
+ }
+ free (volgroups);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
external sfdisk_l : t -> string -> string = "ocaml_guestfs_sfdisk_l"
external sfdisk_kernel_geometry : t -> string -> string = "ocaml_guestfs_sfdisk_kernel_geometry"
external sfdisk_disk_geometry : t -> string -> string = "ocaml_guestfs_sfdisk_disk_geometry"
+external vg_activate_all : t -> bool -> unit = "ocaml_guestfs_vg_activate_all"
+external vg_activate : t -> bool -> string array -> unit = "ocaml_guestfs_vg_activate"
val sfdisk_disk_geometry : t -> string -> string
(** display the disk geometry from the partition table *)
+val vg_activate_all : t -> bool -> unit
+(** activate or deactivate all volume groups *)
+
+val vg_activate : t -> bool -> string array -> unit
+(** activate or deactivate some volume groups *)
+
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_vg_activate_all (value gv, value activatev)
+{
+ CAMLparam2 (gv, activatev);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("vg_activate_all: used handle after closing it");
+
+ int activate = Bool_val (activatev);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_vg_activate_all (g, activate);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "vg_activate_all");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_vg_activate (value gv, value activatev, value volgroupsv)
+{
+ CAMLparam3 (gv, activatev, volgroupsv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("vg_activate: used handle after closing it");
+
+ int activate = Bool_val (activatev);
+ char **volgroups = ocaml_guestfs_strings_val (g, volgroupsv);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_vg_activate (g, activate, volgroups);
+ caml_leave_blocking_section ();
+ ocaml_guestfs_free_strings (volgroups);
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "vg_activate");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
OUTPUT:
RETVAL
+void
+vg_activate_all (g, activate)
+ guestfs_h *g;
+ int activate;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_vg_activate_all (g, activate);
+ if (r == -1)
+ croak ("vg_activate_all: %s", guestfs_last_error (g));
+
+void
+vg_activate (g, activate, volgroups)
+ guestfs_h *g;
+ int activate;
+ char **volgroups;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_vg_activate (g, activate, volgroups);
+ free (volgroups);
+ if (r == -1)
+ croak ("vg_activate: %s", guestfs_last_error (g));
+
See also C<$h-E<gt>download>.
+=item $h->vg_activate ($activate, \@volgroups);
+
+This command activates or (if C<activate> is false) deactivates
+all logical volumes in the listed volume groups C<volgroups>.
+If activated, then they are made known to the
+kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
+then those devices disappear.
+
+This command is the same as running C<vgchange -a y|n volgroups...>
+
+Note that if C<volgroups> is an empty list then B<all> volume groups
+are activated or deactivated.
+
+=item $h->vg_activate_all ($activate);
+
+This command activates or (if C<activate> is false) deactivates
+all logical volumes in all volume groups.
+If activated, then they are made known to the
+kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
+then those devices disappear.
+
+This command is the same as running C<vgchange -a y|n>
+
=item $h->vgcreate ($volgroup, \@physvols);
This creates an LVM volume group called C<volgroup>
return py_r;
}
+static PyObject *
+py_guestfs_vg_activate_all (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ int r;
+ int activate;
+
+ if (!PyArg_ParseTuple (args, (char *) "Oi:guestfs_vg_activate_all",
+ &py_g, &activate))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_vg_activate_all (g, activate);
+ if (r == -1) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ Py_INCREF (Py_None);
+ py_r = Py_None;
+ return py_r;
+}
+
+static PyObject *
+py_guestfs_vg_activate (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ int r;
+ int activate;
+ PyObject *py_volgroups;
+ const char **volgroups;
+
+ if (!PyArg_ParseTuple (args, (char *) "OiO:guestfs_vg_activate",
+ &py_g, &activate, &py_volgroups))
+ return NULL;
+ g = get_handle (py_g);
+ volgroups = get_string_list (py_volgroups);
+ if (!volgroups) return NULL;
+
+ r = guestfs_vg_activate (g, activate, volgroups);
+ free (volgroups);
+ if (r == -1) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ Py_INCREF (Py_None);
+ py_r = Py_None;
+ return py_r;
+}
+
static PyMethodDef methods[] = {
{ (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
{ (char *) "close", py_guestfs_close, METH_VARARGS, NULL },
{ (char *) "sfdisk_l", py_guestfs_sfdisk_l, METH_VARARGS, NULL },
{ (char *) "sfdisk_kernel_geometry", py_guestfs_sfdisk_kernel_geometry, METH_VARARGS, NULL },
{ (char *) "sfdisk_disk_geometry", py_guestfs_sfdisk_disk_geometry, METH_VARARGS, NULL },
+ { (char *) "vg_activate_all", py_guestfs_vg_activate_all, METH_VARARGS, NULL },
+ { (char *) "vg_activate", py_guestfs_vg_activate, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
"""
return libguestfsmod.sfdisk_disk_geometry (self._o, device)
+ def vg_activate_all (self, activate):
+ u"""This command activates or (if "activate" is false)
+ deactivates all logical volumes in all volume groups. If
+ activated, then they are made known to the kernel, ie.
+ they appear as "/dev/mapper" devices. If deactivated,
+ then those devices disappear.
+
+ This command is the same as running "vgchange -a y|n"
+ """
+ return libguestfsmod.vg_activate_all (self._o, activate)
+
+ def vg_activate (self, activate, volgroups):
+ u"""This command activates or (if "activate" is false)
+ deactivates all logical volumes in the listed volume
+ groups "volgroups". If activated, then they are made
+ known to the kernel, ie. they appear as "/dev/mapper"
+ devices. If deactivated, then those devices disappear.
+
+ This command is the same as running "vgchange -a y|n
+ volgroups..."
+
+ Note that if "volgroups" is an empty list then all
+ volume groups are activated or deactivated.
+ """
+ return libguestfsmod.vg_activate (self._o, activate, volgroups)
+
--- /dev/null
+<p>
+This example shows how a block device containing a partition
+and a physical volume can be resized.
+</p>
+
+<p>
+If you try this out, you
+may find that attempts to repartition the disk fail because the
+disk is locked by the LVM devices which exist on it. You have
+to deactivate (temporarily) the volume groups, perform the
+fdisk, and then activate them again.
+</p>
+
+<p>
+This example script is self-contained. It first creates a
+block device (a temporary file) containing some LVs, then it extends
+the temporary file, and shows how to deactivate volgroups, repartition,
+and activate them again.
+</p>
--- /dev/null
+#!/bin/sh -
+
+guestfish <<EOF
+alloc test.img 130M
+run
+# You can uncomment the following to see the
+# geometry (CHS), which is needed to repartition.
+#sfdisk-disk-geometry /dev/sda
+sfdisk /dev/sda 0 0 0 ,
+pvcreate /dev/sda1
+vgcreate VG /dev/sda1
+lvcreate LV1 VG 32M
+lvcreate LV2 VG 32M
+lvcreate LV3 VG 32M
+sync
+EOF
+
+truncate --size=260M test.img
+
+guestfish -a test.img <<EOF
+run
+# Turn off the VGs before we can repartition.
+vg-activate-all false
+sfdisk-N /dev/sda 1 32 255 63 0,31
+vg-activate-all true
+
+pvresize /dev/sda1
+
+# The following command would fail if the
+# partition or PV hadn't been resized:
+lvcreate LV4 VG 64M
+
+echo New LV list:
+lvs
+EOF
\ No newline at end of file
--- /dev/null
+Repartition and resize a block device
\ No newline at end of file
return rv;
}
+static VALUE ruby_guestfs_vg_activate_all (VALUE gv, VALUE activatev)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "vg_activate_all");
+
+ int activate = NUM2INT (activatev);
+
+ int r;
+
+ r = guestfs_vg_activate_all (g, activate);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
+static VALUE ruby_guestfs_vg_activate (VALUE gv, VALUE activatev, VALUE volgroupsv)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "vg_activate");
+
+ int activate = NUM2INT (activatev);
+ char **volgroups; {
+ int i, len;
+ len = RARRAY_LEN (volgroupsv);
+ volgroups = guestfs_safe_malloc (g, sizeof (char *) * (len+1));
+ for (i = 0; i < len; ++i) {
+ VALUE v = rb_ary_entry (volgroupsv, i);
+ volgroups[i] = StringValueCStr (v);
+ }
+ volgroups[len] = NULL;
+ }
+
+ int r;
+
+ r = guestfs_vg_activate (g, activate, volgroups);
+ free (volgroups);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
/* Initialize the module. */
void Init__guestfs ()
{
ruby_guestfs_sfdisk_kernel_geometry, 1);
rb_define_method (c_guestfs, "sfdisk_disk_geometry",
ruby_guestfs_sfdisk_disk_geometry, 1);
+ rb_define_method (c_guestfs, "vg_activate_all",
+ ruby_guestfs_vg_activate_all, 1);
+ rb_define_method (c_guestfs, "vg_activate",
+ ruby_guestfs_vg_activate, 2);
}
The result is in human-readable format, and not designed to
be parsed.");
+ ("vg_activate_all", (RErr, [Bool "activate"]), 103, [],
+ [],
+ "activate or deactivate all volume groups",
+ "\
+This command activates or (if C<activate> is false) deactivates
+all logical volumes in all volume groups.
+If activated, then they are made known to the
+kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
+then those devices disappear.
+
+This command is the same as running C<vgchange -a y|n>");
+
+ ("vg_activate", (RErr, [Bool "activate"; StringList "volgroups"]), 104, [],
+ [],
+ "activate or deactivate some volume groups",
+ "\
+This command activates or (if C<activate> is false) deactivates
+all logical volumes in the listed volume groups C<volgroups>.
+If activated, then they are made known to the
+kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
+then those devices disappear.
+
+This command is the same as running C<vgchange -a y|n volgroups...>
+
+Note that if C<volgroups> is an empty list then B<all> volume groups
+are activated or deactivated.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
return ctx.ret.partitions; /* caller will free */
}
+struct vg_activate_all_ctx {
+ /* This flag is set by the callbacks, so we know we've done
+ * the callbacks as expected, and in the right sequence.
+ * 0 = not called, 1 = reply_cb called.
+ */
+ int cb_sequence;
+ struct guestfs_message_header hdr;
+ struct guestfs_message_error err;
+};
+
+static void vg_activate_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct vg_activate_all_ctx *ctx = (struct vg_activate_all_ctx *) data;
+
+ /* This should definitely not happen. */
+ if (ctx->cb_sequence != 0) {
+ ctx->cb_sequence = 9999;
+ error (g, "%s: internal error: reply callback called twice", "guestfs_vg_activate_all");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_vg_activate_all");
+ return;
+ }
+ if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+ if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+ error (g, "%s: failed to parse reply error", "guestfs_vg_activate_all");
+ return;
+ }
+ goto done;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+int guestfs_vg_activate_all (guestfs_h *g,
+ int activate)
+{
+ struct guestfs_vg_activate_all_args args;
+ struct vg_activate_all_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_vg_activate_all") == -1) return -1;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.activate = activate;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_VG_ACTIVATE_ALL,
+ (xdrproc_t) xdr_guestfs_vg_activate_all_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, vg_activate_all_reply_cb, &ctx);
+ (void) ml->main_loop_run (ml, g);
+ guestfs_set_reply_callback (g, NULL, NULL);
+ if (ctx.cb_sequence != 1) {
+ error (g, "%s reply failed, see earlier error messages", "guestfs_vg_activate_all");
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VG_ACTIVATE_ALL, serial) == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ free (ctx.err.error_message);
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs_end_busy (g);
+ return 0;
+}
+
+struct vg_activate_ctx {
+ /* This flag is set by the callbacks, so we know we've done
+ * the callbacks as expected, and in the right sequence.
+ * 0 = not called, 1 = reply_cb called.
+ */
+ int cb_sequence;
+ struct guestfs_message_header hdr;
+ struct guestfs_message_error err;
+};
+
+static void vg_activate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct vg_activate_ctx *ctx = (struct vg_activate_ctx *) data;
+
+ /* This should definitely not happen. */
+ if (ctx->cb_sequence != 0) {
+ ctx->cb_sequence = 9999;
+ error (g, "%s: internal error: reply callback called twice", "guestfs_vg_activate");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_vg_activate");
+ return;
+ }
+ if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+ if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+ error (g, "%s: failed to parse reply error", "guestfs_vg_activate");
+ return;
+ }
+ goto done;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+int guestfs_vg_activate (guestfs_h *g,
+ int activate,
+ char * const* const volgroups)
+{
+ struct guestfs_vg_activate_args args;
+ struct vg_activate_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_vg_activate") == -1) return -1;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.activate = activate;
+ args.volgroups.volgroups_val = (char **) volgroups;
+ for (args.volgroups.volgroups_len = 0; volgroups[args.volgroups.volgroups_len]; args.volgroups.volgroups_len++) ;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_VG_ACTIVATE,
+ (xdrproc_t) xdr_guestfs_vg_activate_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, vg_activate_reply_cb, &ctx);
+ (void) ml->main_loop_run (ml, g);
+ guestfs_set_reply_callback (g, NULL, NULL);
+ if (ctx.cb_sequence != 1) {
+ error (g, "%s reply failed, see earlier error messages", "guestfs_vg_activate");
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VG_ACTIVATE, serial) == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ free (ctx.err.error_message);
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs_end_busy (g);
+ return 0;
+}
+
extern char *guestfs_sfdisk_l (guestfs_h *handle, const char *device);
extern char *guestfs_sfdisk_kernel_geometry (guestfs_h *handle, const char *device);
extern char *guestfs_sfdisk_disk_geometry (guestfs_h *handle, const char *device);
+extern int guestfs_vg_activate_all (guestfs_h *handle, int activate);
+extern int guestfs_vg_activate (guestfs_h *handle, int activate, char * const* const volgroups);
}
bool_t
+xdr_guestfs_vg_activate_all_args (XDR *xdrs, guestfs_vg_activate_all_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_bool (xdrs, &objp->activate))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_guestfs_vg_activate_args (XDR *xdrs, guestfs_vg_activate_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_bool (xdrs, &objp->activate))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **)&objp->volgroups.volgroups_val, (u_int *) &objp->volgroups.volgroups_len, ~0,
+ sizeof (str), (xdrproc_t) xdr_str))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp)
{
register int32_t *buf;
};
typedef struct guestfs_sfdisk_disk_geometry_ret guestfs_sfdisk_disk_geometry_ret;
+struct guestfs_vg_activate_all_args {
+ bool_t activate;
+};
+typedef struct guestfs_vg_activate_all_args guestfs_vg_activate_all_args;
+
+struct guestfs_vg_activate_args {
+ bool_t activate;
+ struct {
+ u_int volgroups_len;
+ str *volgroups_val;
+ } volgroups;
+};
+typedef struct guestfs_vg_activate_args guestfs_vg_activate_args;
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_SFDISK_L = 100,
GUESTFS_PROC_SFDISK_KERNEL_GEOMETRY = 101,
GUESTFS_PROC_SFDISK_DISK_GEOMETRY = 102,
- GUESTFS_PROC_NR_PROCS = 102 + 1,
+ GUESTFS_PROC_VG_ACTIVATE_ALL = 103,
+ GUESTFS_PROC_VG_ACTIVATE = 104,
+ GUESTFS_PROC_NR_PROCS = 104 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
extern bool_t xdr_guestfs_sfdisk_kernel_geometry_ret (XDR *, guestfs_sfdisk_kernel_geometry_ret*);
extern bool_t xdr_guestfs_sfdisk_disk_geometry_args (XDR *, guestfs_sfdisk_disk_geometry_args*);
extern bool_t xdr_guestfs_sfdisk_disk_geometry_ret (XDR *, guestfs_sfdisk_disk_geometry_ret*);
+extern bool_t xdr_guestfs_vg_activate_all_args (XDR *, guestfs_vg_activate_all_args*);
+extern bool_t xdr_guestfs_vg_activate_args (XDR *, guestfs_vg_activate_args*);
extern bool_t xdr_guestfs_procedure (XDR *, guestfs_procedure*);
extern bool_t xdr_guestfs_message_direction (XDR *, guestfs_message_direction*);
extern bool_t xdr_guestfs_message_status (XDR *, guestfs_message_status*);
extern bool_t xdr_guestfs_sfdisk_kernel_geometry_ret ();
extern bool_t xdr_guestfs_sfdisk_disk_geometry_args ();
extern bool_t xdr_guestfs_sfdisk_disk_geometry_ret ();
+extern bool_t xdr_guestfs_vg_activate_all_args ();
+extern bool_t xdr_guestfs_vg_activate_args ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
string partitions<>;
};
+struct guestfs_vg_activate_all_args {
+ bool activate;
+};
+
+struct guestfs_vg_activate_args {
+ bool activate;
+ str volgroups<>;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_SFDISK_L = 100,
GUESTFS_PROC_SFDISK_KERNEL_GEOMETRY = 101,
GUESTFS_PROC_SFDISK_DISK_GEOMETRY = 102,
+ GUESTFS_PROC_VG_ACTIVATE_ALL = 103,
+ GUESTFS_PROC_VG_ACTIVATE = 104,
GUESTFS_PROC_NR_PROCS
};
fprintf (stderr, "warning: \"guestfs_sfdisk_l\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_sfdisk_kernel_geometry\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_sfdisk_disk_geometry\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_vg_activate_all\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_vg_activate\" has no tests\n");
}
static int test_zerofree_0 (void)