[Pkg-libvirt-commits] [libguestfs] 68/384: New(ish) API: guestfs_add_libvirt_dom.
Hilko Bengen
bengen at moszumanska.debian.org
Sun Mar 29 16:55:32 UTC 2015
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit 96158d42f5cb9b6c472b4630f2c97edae600f6d3
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Wed Dec 10 17:11:31 2014 +0000
New(ish) API: guestfs_add_libvirt_dom.
This API already existed (as guestfs___add_libvirt_dom), and was used
by a few tools.
This commit changes it to a public API.
Note that for reasons outlined in the previous commit message, it is
impossible to call this from guestfish or from non-C language
bindings.
---
align/scan.c | 8 ++++----
df/df.c | 10 ++++++----
df/domains.h | 2 ++
generator/actions.ml | 7 ++-----
generator/c.ml | 3 ---
gobject/Makefile.inc | 2 ++
perl/typemap | 4 ++++
po/POTFILES | 1 +
src/guestfs-internal-frontend.h | 33 ---------------------------------
src/libvirt-domain.c | 37 +++++++++++++++++++------------------
tests/c-api/Makefile.am | 22 +++++++++++-----------
tests/c-api/test-add-libvirt-dom.c | 2 +-
12 files changed, 52 insertions(+), 79 deletions(-)
diff --git a/align/scan.c b/align/scan.c
index 7da468f..651d805 100644
--- a/align/scan.c
+++ b/align/scan.c
@@ -353,15 +353,15 @@ scan (guestfs_h *g, const char *prefix, FILE *fp)
static int
scan_work (guestfs_h *g, size_t i, FILE *fp)
{
- struct guestfs___add_libvirt_dom_argv optargs;
+ struct guestfs_add_libvirt_dom_argv optargs;
optargs.bitmask =
- GUESTFS___ADD_LIBVIRT_DOM_READONLY_BITMASK |
- GUESTFS___ADD_LIBVIRT_DOM_READONLYDISK_BITMASK;
+ GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK |
+ GUESTFS_ADD_LIBVIRT_DOM_READONLYDISK_BITMASK;
optargs.readonly = 1;
optargs.readonlydisk = "read";
- if (guestfs___add_libvirt_dom (g, domains[i].dom, &optargs) == -1)
+ if (guestfs_add_libvirt_dom_argv (g, domains[i].dom, &optargs) == -1)
return -1;
if (guestfs_launch (g) == -1)
diff --git a/df/df.c b/df/df.c
index 0dcf1c9..a13cc59 100644
--- a/df/df.c
+++ b/df/df.c
@@ -85,6 +85,8 @@ df_on_handle (guestfs_h *g, const char *name, const char *uuid, FILE *fp)
#if defined(HAVE_LIBVIRT)
+#include <libvirt/libvirt.h>
+
/* The multi-threaded version. This callback is called from the code
* in "parallel.c".
*/
@@ -92,16 +94,16 @@ df_on_handle (guestfs_h *g, const char *name, const char *uuid, FILE *fp)
int
df_work (guestfs_h *g, size_t i, FILE *fp)
{
- struct guestfs___add_libvirt_dom_argv optargs;
+ struct guestfs_add_libvirt_dom_argv optargs;
optargs.bitmask =
- GUESTFS___ADD_LIBVIRT_DOM_READONLY_BITMASK |
- GUESTFS___ADD_LIBVIRT_DOM_READONLYDISK_BITMASK;
+ GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK |
+ GUESTFS_ADD_LIBVIRT_DOM_READONLYDISK_BITMASK;
optargs.readonly = 1;
optargs.readonlydisk = "read";
/* Traditionally we have ignored errors from adding disks in virt-df. */
- if (guestfs___add_libvirt_dom (g, domains[i].dom, &optargs) == -1)
+ if (guestfs_add_libvirt_dom_argv (g, domains[i].dom, &optargs) == -1)
return 0;
if (guestfs_launch (g) == -1)
diff --git a/df/domains.h b/df/domains.h
index 50e8762..ecf791b 100644
--- a/df/domains.h
+++ b/df/domains.h
@@ -21,6 +21,8 @@
#if defined(HAVE_LIBVIRT)
+#include <libvirt/libvirt.h>
+
/* The list of domains that we build up in get_all_libvirt_guests. */
struct domain {
virDomainPtr dom;
diff --git a/generator/actions.ml b/generator/actions.ml
index 93e3d0d..4bd0788 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1705,12 +1705,10 @@ Disks with the E<lt>readonly/E<gt> flag are skipped.
The other optional parameters are passed directly through to
C<guestfs_add_drive_opts>." };
-(*
-This interface is not quite baked yet. -- RWMJ 2010-11-11
{ defaults with
name = "add_libvirt_dom";
- style = RInt "nrdisks", [Pointer ("virDomainPtr", "dom")], [Bool "readonly"; String "iface"; Bool "live"; String "readonlydisk"; OString "cachemode"; OString "discard"; OBool "copyonread"];
- in_fish = false;
+ style = RInt "nrdisks", [Pointer ("virDomainPtr", "dom")], [OBool "readonly"; OString "iface"; OBool "live"; OString "readonlydisk"; OString "cachemode"; OString "discard"; OBool "copyonread"];
+ config_only = true;
shortdesc = "add the disk(s) from a libvirt domain";
longdesc = "\
This function adds the disk(s) attached to the libvirt domain C<dom>.
@@ -1745,7 +1743,6 @@ See C<guestfs_add_domain> for possible values.
The other optional parameters are passed directly through to
C<guestfs_add_drive_opts>." };
-*)
{ defaults with
name = "inspect_get_package_format";
diff --git a/generator/c.ml b/generator/c.ml
index 541c843..10dea84 100644
--- a/generator/c.ml
+++ b/generator/c.ml
@@ -2182,9 +2182,6 @@ and generate_linker_script () =
"guestfs___safe_malloc";
"guestfs___safe_strdup";
"guestfs___safe_memdup";
-
- (* Used only by virt-df and virt-alignment-scan. *)
- "guestfs___add_libvirt_dom";
] in
let functions =
List.flatten (
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
index 56a2fc3..218eef7 100644
--- a/gobject/Makefile.inc
+++ b/gobject/Makefile.inc
@@ -47,6 +47,7 @@ guestfs_gobject_headers= \
include/guestfs-gobject/optargs-add_domain.h \
include/guestfs-gobject/optargs-add_drive.h \
include/guestfs-gobject/optargs-add_drive_scratch.h \
+ include/guestfs-gobject/optargs-add_libvirt_dom.h \
include/guestfs-gobject/optargs-btrfs_filesystem_resize.h \
include/guestfs-gobject/optargs-btrfs_fsck.h \
include/guestfs-gobject/optargs-btrfs_subvolume_create.h \
@@ -127,6 +128,7 @@ guestfs_gobject_sources= \
src/optargs-add_domain.c \
src/optargs-add_drive.c \
src/optargs-add_drive_scratch.c \
+ src/optargs-add_libvirt_dom.c \
src/optargs-btrfs_filesystem_resize.c \
src/optargs-btrfs_fsck.c \
src/optargs-btrfs_subvolume_create.c \
diff --git a/perl/typemap b/perl/typemap
index 43e7948..e6f95d2 100644
--- a/perl/typemap
+++ b/perl/typemap
@@ -3,6 +3,7 @@ char * T_PV
const char * T_PV
guestfs_h * O_OBJECT_guestfs_h
int64_t O_OBJECT_int64
+void * /* virDomainPtr */ O_OBJECT_virDomainPtr
INPUT
O_OBJECT_guestfs_h
@@ -21,6 +22,9 @@ O_OBJECT_guestfs_h
O_OBJECT_int64
$var = my_SvIV64 ($arg);
+O_OBJECT_virDomainPtr
+ $var = POINTER_NOT_IMPLEMENTED (\"virDomainPtr\");
+
OUTPUT
O_OBJECT_guestfs_h
sv_setiv ($arg, PTR2IV ($var));
diff --git a/po/POTFILES b/po/POTFILES
index 36f61b2..a8e211f 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -173,6 +173,7 @@ fuse/test-guestunmount-fd.c
gobject/src/optargs-add_domain.c
gobject/src/optargs-add_drive.c
gobject/src/optargs-add_drive_scratch.c
+gobject/src/optargs-add_libvirt_dom.c
gobject/src/optargs-btrfs_filesystem_resize.c
gobject/src/optargs-btrfs_fsck.c
gobject/src/optargs-btrfs_subvolume_create.c
diff --git a/src/guestfs-internal-frontend.h b/src/guestfs-internal-frontend.h
index acb7014..cddf719 100644
--- a/src/guestfs-internal-frontend.h
+++ b/src/guestfs-internal-frontend.h
@@ -127,39 +127,6 @@ extern void guestfs___cleanup_pclose (void *ptr);
*/
#include "guestfs-internal-frontend-cleanups.h"
-#if defined(HAVE_LIBVIRT)
-
-#include <libvirt/libvirt.h>
-
-/* This was proposed as an external API, but there's a problem: the
- * generator is unable to bind a virDomainPtr in any language other
- * than C. For now this API is only used by virt-df and
- * virt-alignment-scan (both C tools) and it's only exported
- * internally within the libguestfs code, not to external users.
- */
-
-struct guestfs___add_libvirt_dom_argv {
- uint64_t bitmask;
-#define GUESTFS___ADD_LIBVIRT_DOM_READONLY_BITMASK (UINT64_C(1)<<0)
- int readonly;
-#define GUESTFS___ADD_LIBVIRT_DOM_IFACE_BITMASK (UINT64_C(1)<<1)
- const char *iface;
-#define GUESTFS___ADD_LIBVIRT_DOM_LIVE_BITMASK (UINT64_C(1)<<2)
- int live;
-#define GUESTFS___ADD_LIBVIRT_DOM_READONLYDISK_BITMASK (UINT64_C(1)<<3)
- const char *readonlydisk;
-#define GUESTFS___ADD_LIBVIRT_DOM_CACHEMODE_BITMASK (UINT64_C(1)<<4)
- const char *cachemode;
-#define GUESTFS___ADD_LIBVIRT_DOM_DISCARD_BITMASK (UINT64_C(1)<<5)
- const char *discard;
-#define GUESTFS___ADD_LIBVIRT_DOM_COPYONREAD_BITMASK (UINT64_C(1)<<6)
- int copyonread;
-};
-
-extern GUESTFS_DLL_PUBLIC int guestfs___add_libvirt_dom (guestfs_h *g, virDomainPtr dom, const struct guestfs___add_libvirt_dom_argv *optargs);
-
-#endif /* HAVE_LIBVIRT */
-
/* Current program name. Note <errno.h> must be included in all files
* that want to use 'program_name'.
*/
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 59bb4bc..78503e5 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -67,7 +67,7 @@ guestfs__add_domain (guestfs_h *g, const char *domain_name,
const char *cachemode;
const char *discard;
bool copyonread;
- struct guestfs___add_libvirt_dom_argv optargs2 = { .bitmask = 0 };
+ struct guestfs_add_libvirt_dom_argv optargs2 = { .bitmask = 0 };
libvirturi = optargs->bitmask & GUESTFS_ADD_DOMAIN_LIBVIRTURI_BITMASK
? optargs->libvirturi : NULL;
@@ -124,35 +124,35 @@ guestfs__add_domain (guestfs_h *g, const char *domain_name,
}
if (readonly) {
- optargs2.bitmask |= GUESTFS___ADD_LIBVIRT_DOM_READONLY_BITMASK;
+ optargs2.bitmask |= GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK;
optargs2.readonly = readonly;
}
if (iface) {
- optargs2.bitmask |= GUESTFS___ADD_LIBVIRT_DOM_IFACE_BITMASK;
+ optargs2.bitmask |= GUESTFS_ADD_LIBVIRT_DOM_IFACE_BITMASK;
optargs2.iface = iface;
}
if (live) {
- optargs2.bitmask |= GUESTFS___ADD_LIBVIRT_DOM_LIVE_BITMASK;
+ optargs2.bitmask |= GUESTFS_ADD_LIBVIRT_DOM_LIVE_BITMASK;
optargs2.live = live;
}
if (readonlydisk) {
- optargs2.bitmask |= GUESTFS___ADD_LIBVIRT_DOM_READONLYDISK_BITMASK;
+ optargs2.bitmask |= GUESTFS_ADD_LIBVIRT_DOM_READONLYDISK_BITMASK;
optargs2.readonlydisk = readonlydisk;
}
if (cachemode) {
- optargs2.bitmask |= GUESTFS___ADD_LIBVIRT_DOM_CACHEMODE_BITMASK;
+ optargs2.bitmask |= GUESTFS_ADD_LIBVIRT_DOM_CACHEMODE_BITMASK;
optargs2.cachemode = cachemode;
}
if (discard) {
- optargs2.bitmask |= GUESTFS___ADD_LIBVIRT_DOM_DISCARD_BITMASK;
+ optargs2.bitmask |= GUESTFS_ADD_LIBVIRT_DOM_DISCARD_BITMASK;
optargs2.discard = discard;
}
if (copyonread) {
- optargs2.bitmask |= GUESTFS___ADD_LIBVIRT_DOM_COPYONREAD_BITMASK;
+ optargs2.bitmask |= GUESTFS_ADD_LIBVIRT_DOM_COPYONREAD_BITMASK;
optargs2.copyonread = copyonread;
}
- r = guestfs___add_libvirt_dom (g, dom, &optargs2);
+ r = guestfs_add_libvirt_dom_argv (g, dom, &optargs2);
cleanup:
if (dom) virDomainFree (dom);
@@ -179,9 +179,10 @@ struct add_disk_data {
};
GUESTFS_DLL_PUBLIC int
-guestfs___add_libvirt_dom (guestfs_h *g, virDomainPtr dom,
- const struct guestfs___add_libvirt_dom_argv *optargs)
+guestfs__add_libvirt_dom (guestfs_h *g, void *domvp,
+ const struct guestfs_add_libvirt_dom_argv *optargs)
{
+ virDomainPtr dom = domvp;
ssize_t r;
int readonly;
const char *iface;
@@ -197,16 +198,16 @@ guestfs___add_libvirt_dom (guestfs_h *g, virDomainPtr dom,
CLEANUP_FREE char *label = NULL, *imagelabel = NULL;
readonly =
- optargs->bitmask & GUESTFS___ADD_LIBVIRT_DOM_READONLY_BITMASK
+ optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK
? optargs->readonly : 0;
iface =
- optargs->bitmask & GUESTFS___ADD_LIBVIRT_DOM_IFACE_BITMASK
+ optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_IFACE_BITMASK
? optargs->iface : NULL;
live =
- optargs->bitmask & GUESTFS___ADD_LIBVIRT_DOM_LIVE_BITMASK
+ optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_LIVE_BITMASK
? optargs->live : 0;
- if ((optargs->bitmask & GUESTFS___ADD_LIBVIRT_DOM_READONLYDISK_BITMASK)) {
+ if ((optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_READONLYDISK_BITMASK)) {
if (STREQ (optargs->readonlydisk, "error"))
readonlydisk = readonlydisk_error;
else if (STREQ (optargs->readonlydisk, "read"))
@@ -222,15 +223,15 @@ guestfs___add_libvirt_dom (guestfs_h *g, virDomainPtr dom,
}
cachemode =
- optargs->bitmask & GUESTFS___ADD_LIBVIRT_DOM_CACHEMODE_BITMASK
+ optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_CACHEMODE_BITMASK
? optargs->cachemode : NULL;
discard =
- optargs->bitmask & GUESTFS___ADD_LIBVIRT_DOM_DISCARD_BITMASK
+ optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_DISCARD_BITMASK
? optargs->discard : NULL;
copyonread =
- optargs->bitmask & GUESTFS___ADD_LIBVIRT_DOM_COPYONREAD_BITMASK
+ optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_COPYONREAD_BITMASK
? optargs->copyonread : false;
if (live && readonly) {
diff --git a/tests/c-api/Makefile.am b/tests/c-api/Makefile.am
index 94cdd0a..57f75fe 100644
--- a/tests/c-api/Makefile.am
+++ b/tests/c-api/Makefile.am
@@ -240,17 +240,17 @@ test_event_string_LDADD = \
$(LTLIBINTL) \
$(top_builddir)/gnulib/lib/libgnu.la
-#if HAVE_LIBVIRT
-#test_add_libvirt_dom_SOURCES = test-add-libvirt-dom.c
-#test_add_libvirt_dom_CPPFLAGS = \
-# -I$(top_srcdir)/src -I$(top_builddir)/src -I$(top_srcdir)/gnulib/lib
-#test_add_libvirt_dom_CFLAGS = \
-# $(LIBVIRT_CFLAGS) \
-# $(WARN_CFLAGS) $(WERROR_CFLAGS)
-#test_add_libvirt_dom_LDADD = \
-# $(top_builddir)/src/libguestfs.la $(LIBVIRT_LIBS) \
-# $(LTLIBTHREAD) $(top_builddir)/gnulib/lib/libgnu.la
-#endif
+if HAVE_LIBVIRT
+test_add_libvirt_dom_SOURCES = test-add-libvirt-dom.c
+test_add_libvirt_dom_CPPFLAGS = \
+ -I$(top_srcdir)/src -I$(top_builddir)/src -I$(top_srcdir)/gnulib/lib
+test_add_libvirt_dom_CFLAGS = \
+ $(LIBVIRT_CFLAGS) \
+ $(WARN_CFLAGS) $(WERROR_CFLAGS)
+test_add_libvirt_dom_LDADD = \
+ $(top_builddir)/src/libguestfs.la $(LIBVIRT_LIBS) \
+ $(LTLIBTHREAD) $(top_builddir)/gnulib/lib/libgnu.la
+endif
check-valgrind:
$(MAKE) VG="$(top_builddir)/run @VG@" check
diff --git a/tests/c-api/test-add-libvirt-dom.c b/tests/c-api/test-add-libvirt-dom.c
index 4768f8e..952b9a8 100644
--- a/tests/c-api/test-add-libvirt-dom.c
+++ b/tests/c-api/test-add-libvirt-dom.c
@@ -1,5 +1,5 @@
/* libguestfs
- * Copyright (C) 2010 Red Hat Inc.
+ * Copyright (C) 2010-2014 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list