[PATCH v2] launch: add support for autodetection of appliance image format
by Pavel Butsykin
This feature allows you to use different image formats for the fixed
appliance. The raw format is used by default.
Signed-off-by: Pavel Butsykin <pbutsykin(a)virtuozzo.com>
---
lib/launch-direct.c | 2 ++
lib/launch-libvirt.c | 19 ++++++++++++-------
m4/guestfs_appliance.m4 | 11 +++++++++++
3 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/lib/launch-direct.c b/lib/launch-direct.c
index 0be662e25..b9b54857a 100644
--- a/lib/launch-direct.c
+++ b/lib/launch-direct.c
@@ -592,7 +592,9 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
append_list ("id=appliance");
append_list ("cache=unsafe");
append_list ("if=none");
+#ifndef APPLIANCE_FMT_AUTO
append_list ("format=raw");
+#endif
} end_list ();
start_list ("-device") {
append_list ("scsi-hd");
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
index 4adb2cfb3..030ea6911 100644
--- a/lib/launch-libvirt.c
+++ b/lib/launch-libvirt.c
@@ -212,9 +212,10 @@ get_source_format_or_autodetect (guestfs_h *g, struct drive *drv)
/**
* Create a qcow2 format overlay, with the given C<backing_drive>
- * (file). The C<format> parameter, which must be non-NULL, is the
- * backing file format. This is used to create the appliance overlay,
- * and also for read-only drives.
+ * (file). The C<format> parameter is the backing file format.
+ * The C<format> parameter can be NULL, in this case the backing
+ * format will be determined automatically. This is used to create
+ * the appliance overlay, and also for read-only drives.
*/
static char *
make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
@@ -223,8 +224,6 @@ make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
char *overlay;
struct guestfs_disk_create_argv optargs;
- assert (format != NULL);
-
if (guestfs_int_lazy_make_tmpdir (g) == -1)
return NULL;
@@ -232,8 +231,10 @@ make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
optargs.bitmask = GUESTFS_DISK_CREATE_BACKINGFILE_BITMASK;
optargs.backingfile = backing_drive;
- optargs.bitmask |= GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK;
- optargs.backingformat = format;
+ if (format) {
+ optargs.bitmask |= GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK;
+ optargs.backingformat = format;
+ }
if (guestfs_disk_create_argv (g, overlay, "qcow2", -1, &optargs) == -1) {
free (overlay);
@@ -461,7 +462,11 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
/* Note that appliance can be NULL if using the old-style appliance. */
if (appliance) {
+#ifdef APPLIANCE_FMT_AUTO
+ params.appliance_overlay = make_qcow2_overlay (g, appliance, NULL);
+#else
params.appliance_overlay = make_qcow2_overlay (g, appliance, "raw");
+#endif
if (!params.appliance_overlay)
goto cleanup;
}
diff --git a/m4/guestfs_appliance.m4 b/m4/guestfs_appliance.m4
index 81c43879f..4e1ec8135 100644
--- a/m4/guestfs_appliance.m4
+++ b/m4/guestfs_appliance.m4
@@ -139,3 +139,14 @@ AC_SUBST([GUESTFS_DEFAULT_PATH])
AC_DEFINE_UNQUOTED([GUESTFS_DEFAULT_PATH], ["$GUESTFS_DEFAULT_PATH"],
[Define guestfs default path.])
+
+AC_ARG_ENABLE([appliance-fmt-auto],
+ [AS_HELP_STRING([--enable-appliance-fmt-auto],
+ [enable autodetection of appliance image format @<:@default=no@:>@])],
+ [ENABLE_APPLIANCE_FMT_AUTO="$enableval"],
+ [ENABLE_APPLIANCE_FMT_AUTO=no])
+
+if test "x$ENABLE_APPLIANCE_FMT_AUTO" = "xyes"; then
+ AC_DEFINE([APPLIANCE_FMT_AUTO], [1],
+ [Define to 1 if enabled autodetection of appliance image format.])
+fi
--
2.13.0
4 years, 9 months
[PATCH v7 0/9] Introducing virt-builder-repository
by Cédric Bosdonnat
Hi all,
Here is an update of the series fixing Pino's latest comment.
It just doesn't implement the change based on never-accepted
run commands patch.
Cédric Bosdonnat (9):
lib/osinfo.c: Extract xml processing into a callback
lib: extract osinfo DB traversing API
mllib: ocaml wrapper for lib/osinfo
builder: rename docs test script
builder: add a template parameter to get_index
builder: add Index.write_entry function
mllib: add do_mv helper function to Common_utils
mllib: add XPath helper xpath_get_nodes()
Add a virt-builder-repository tool
.gitignore | 4 +
builder/Makefile.am | 124 ++++-
builder/builder.ml | 2 +-
builder/index.mli | 3 +
builder/index_parser.ml | 80 ++-
builder/index_parser.mli | 8 +-
builder/index_parser_tests.ml | 129 +++++
builder/repository_main.ml | 584 +++++++++++++++++++++
.../{test-virt-builder-docs.sh => test-docs.sh} | 2 +
builder/virt-builder-repository.pod | 213 ++++++++
lib/Makefile.am | 2 +
lib/osinfo-iso.c | 462 ++++++++++++++++
lib/osinfo.c | 489 ++---------------
lib/osinfo.h | 27 +
mllib/Makefile.am | 11 +-
mllib/common_utils.ml | 6 +
mllib/common_utils.mli | 3 +
mllib/osinfo-c.c | 103 ++++
mllib/osinfo.ml | 26 +
mllib/osinfo.mli | 31 ++
mllib/xpath_helpers.ml | 9 +
mllib/xpath_helpers.mli | 4 +
22 files changed, 1869 insertions(+), 453 deletions(-)
create mode 100644 builder/index_parser_tests.ml
create mode 100644 builder/repository_main.ml
rename builder/{test-virt-builder-docs.sh => test-docs.sh} (93%)
create mode 100644 builder/virt-builder-repository.pod
create mode 100644 lib/osinfo-iso.c
create mode 100644 lib/osinfo.h
create mode 100644 mllib/osinfo-c.c
create mode 100644 mllib/osinfo.ml
create mode 100644 mllib/osinfo.mli
--
2.12.2
7 years, 4 months
[PATCH] libvirt: disallow non-local connections (RHBZ#1347830)
by Pino Toscano
If the connection is not local, paths of disks will refer to the remote
host, which were mistakenly handled as local paths (in the best case
failing to open a non-existing disk, and in the worst case opening a
different disk!).
In case the disks are remote resources like ssh or ceph, nothing
guarantees that the hostname can be reached from the local machine, or
even that it is actually the same on both machines.
For these reasons, just forbit outright the addition of disks from
non-local libvirt connections for now.
---
lib/libvirt-domain.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/lib/libvirt-domain.c b/lib/libvirt-domain.c
index 37c0b49..6b9467b 100644
--- a/lib/libvirt-domain.c
+++ b/lib/libvirt-domain.c
@@ -32,6 +32,7 @@
#include <libxml/xpath.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
+#include <libxml/uri.h>
#include "base64.h"
@@ -203,7 +204,9 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
size_t ckp;
struct add_disk_data data;
CLEANUP_XMLFREEDOC xmlDocPtr doc = NULL;
- CLEANUP_FREE char *label = NULL, *imagelabel = NULL;
+ CLEANUP_FREE char *label = NULL, *imagelabel = NULL, *uristr = NULL;
+ virConnectPtr conn;
+ CLEANUP_XMLFREEURI xmlURIPtr uri = NULL;
readonly =
optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK
@@ -247,6 +250,37 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
return -1;
}
+ conn = virDomainGetConnect (dom);
+ if (conn == NULL) {
+ virErrorPtr err;
+ err = virGetLastError ();
+ error (g, _("cannot get the libvirt connection of the domain ‘%s’: %s"),
+ virDomainGetName (dom), err ? err->message : "");
+ return -1;
+ }
+
+ uristr = virConnectGetURI (conn);
+ if (uristr == NULL) {
+ virErrorPtr err;
+ err = virGetLastError ();
+ error (g, _("cannot get the URI of the libvirt connection: %s"),
+ err ? err->message : "");
+ return -1;
+ }
+
+ uri = xmlParseURI (uristr);
+ if (uri == NULL) {
+ error (g, _("cannot parse the URI of the libvirt connection: %s"),
+ uristr);
+ return -1;
+ }
+
+ if (uri->server && uri->server[0] != '\0') {
+ error (g, _("cannot add a non-local libvirt connection: %s"),
+ uristr);
+ return -1;
+ }
+
if (!readonly) {
virDomainInfo info;
virErrorPtr err;
@@ -320,7 +354,7 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
* all disks are added or none are added.
*/
ckp = guestfs_int_checkpoint_drives (g);
- r = for_each_disk (g, virDomainGetConnect (dom), doc, add_disk, &data);
+ r = for_each_disk (g, conn, doc, add_disk, &data);
if (r == -1)
guestfs_int_rollback_drives (g, ckp);
--
2.9.4
7 years, 4 months
[PATCH] Fix typos in plugin manual
by Nir Soffer
Replace 'iff' with 'if'.
Signed-off-by: Nir Soffer <nirsof(a)gmail.com>
---
docs/nbdkit-plugin.pod | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/nbdkit-plugin.pod b/docs/nbdkit-plugin.pod
index 4b364f3..b96664f 100644
--- a/docs/nbdkit-plugin.pod
+++ b/docs/nbdkit-plugin.pod
@@ -348,7 +348,7 @@ handle supports writes.
If there is an error, C<.can_write> should call C<nbdkit_error> with
an error message and return C<-1>.
-This callback is not required. If omitted, then we return true iff a
+This callback is not required. If omitted, then we return true if a
C<.pwrite> callback has been defined.
=head2 C<.can_flush>
@@ -361,7 +361,7 @@ handle supports the flush-to-disk operation.
If there is an error, C<.can_flush> should call C<nbdkit_error> with
an error message and return C<-1>.
-This callback is not required. If omitted, then we return true iff a
+This callback is not required. If omitted, then we return true if a
C<.flush> callback has been defined.
=head2 C<.is_rotational>
@@ -389,7 +389,7 @@ backing storage.
If there is an error, C<.can_trim> should call C<nbdkit_error> with an
error message and return C<-1>.
-This callback is not required. If omitted, then we return true iff a
+This callback is not required. If omitted, then we return true if a
C<.trim> callback has been defined.
=head2 C<.pread>
--
2.9.4
7 years, 4 months
[PATCH] lib: libvirt: Pass copyonread flag through to the libvirt XML.
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
We were dropping the add_drive copyonread flag when using the libvirt
backend. This resulted in significant performance degradation (2x-3x
slower) when running virt-v2v against VMware servers.
Thanks: Kun Wei.
---
lib/launch-libvirt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
index 948350b..72f86ba 100644
--- a/lib/launch-libvirt.c
+++ b/lib/launch-libvirt.c
@@ -1593,7 +1593,8 @@ construct_libvirt_xml_disk (guestfs_h *g,
if (construct_libvirt_xml_disk_driver_qemu (g, data, drv, xo, format,
drv->cachemode ? : "writeback",
- drv->discard, false)
+ drv->discard,
+ drv->copyonread)
== -1)
return -1;
}
--
1.8.3.1
7 years, 4 months
[PATCH] v2v: Allow -i libvirtxml to open network disks over http or https.
by Richard W.M. Jones
Currently -i libvirtxml mode only works for local files or NBD disks.
The purpose of NBD is to support virt-p2v.
This change adds support for network disks over http or https, ie:
<disk type='network' device='disk'>
<driver name='qemu' type='raw'/>
<source protocol="http" name="/scratch/disk.img">
<host name="server.example.com" port="80"/>
</source>
<target dev='hda' bus='ide'/>
</disk>
This is just for testing. It's especially useful for exercising curl
support in qemu without requiring VMware to be available.
---
v2v/parse_libvirt_xml.ml | 51 +++++++++++++++++++++++++++++++++++++++---------
v2v/utils.ml | 15 ++++++++++++++
v2v/utils.mli | 3 +++
v2v/vCenter.ml | 16 +--------------
4 files changed, 61 insertions(+), 24 deletions(-)
diff --git a/v2v/parse_libvirt_xml.ml b/v2v/parse_libvirt_xml.ml
index 4ac9b51a5..ed2266232 100644
--- a/v2v/parse_libvirt_xml.ml
+++ b/v2v/parse_libvirt_xml.ml
@@ -23,6 +23,7 @@ open Common_utils
open Types
open Xpath_helpers
+open Utils
type parsed_disk = {
p_source_disk : source_disk;
@@ -43,12 +44,38 @@ let get_drive_slot str offset =
warning (f_"could not parse device name ‘%s’ from the source libvirt XML") str;
None
+(* Create a JSON URI for qemu referring to a remote CURL (http/https)
+ * resource. See also [v2v/vCenter.ml].
+ *)
+let create_curl_qemu_uri driver host port path =
+ let url =
+ let port =
+ match driver, port with
+ | _, None -> ""
+ | "https", Some 443 -> ""
+ | "http", Some 80 -> ""
+ | _, Some port when port >= 1 -> ":" ^ string_of_int port
+ | _, Some port -> invalid_arg "invalid port number in libvirt XML" in
+ sprintf "%s://%s%s%s" driver host port (uri_quote path) in
+
+ let json_params = [
+ "file.driver", JSON.String driver; (* "http" or "https" *)
+ "file.url", JSON.String url;
+ "file.timeout", JSON.Int 2000;
+ "file.readahead", JSON.Int (1024 * 1024);
+ (* "file.sslverify", JSON.String "off"; XXX *)
+ ] in
+
+ (* Turn the JSON parameters into a 'json:' protocol string. *)
+ "json: " ^ JSON.string_of_doc json_params
+
let parse_libvirt_xml ?conn xml =
debug "libvirt xml is:\n%s" xml;
let doc = Xml.parse_memory xml in
let xpathctx = Xml.xpath_new_context doc in
let xpath_string = xpath_string xpathctx
+ and xpath_string_default = xpath_string_default xpathctx
and xpath_int = xpath_int xpathctx
(*and xpath_int_default = xpath_int_default xpathctx*)
and xpath_int64_default = xpath_int64_default xpathctx in
@@ -273,21 +300,27 @@ let parse_libvirt_xml ?conn xml =
| None -> ()
);
| Some "network" ->
- (* We only handle <source protocol="nbd"> here, and that is
- * intended only for virt-p2v.
- *)
(match (xpath_string "source/@protocol",
xpath_string "source/host/@name",
xpath_int "source/host/@port") with
| None, _, _ ->
- warning (f_"<disk type='%s'> was ignored") "network"
+ warning (f_"<disk type='%s'> was ignored") "network"
| Some "nbd", Some ("localhost" as host), Some port when port > 0 ->
- (* virt-p2v: Generate a qemu nbd URL. *)
- let path = sprintf "nbd:%s:%d" host port in
- add_disk path format controller P_dont_rewrite
+ (* <source protocol="nbd"> with host localhost is used by
+ * virt-p2v. Generate a qemu 'nbd:' URL.
+ *)
+ let path = sprintf "nbd:%s:%d" host port in
+ add_disk path format controller P_dont_rewrite
+ | Some ("http"|"https" as driver), Some (_ as host), port ->
+ (* This is for testing curl, eg for testing VMware conversions
+ * without needing VMware around.
+ *)
+ let path = xpath_string_default "source/@name" "" in
+ let qemu_uri = create_curl_qemu_uri driver host port path in
+ add_disk qemu_uri format controller P_dont_rewrite
| Some protocol, _, _ ->
- warning (f_"<disk type='network'> with <source protocol='%s'> was ignored")
- protocol
+ warning (f_"<disk type='network'> with <source protocol='%s'> was ignored")
+ protocol
)
| Some "volume" ->
(match xpath_string "source/@pool", xpath_string "source/@volume" with
diff --git a/v2v/utils.ml b/v2v/utils.ml
index e0275db53..e20159019 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -28,6 +28,21 @@ external drive_index : string -> int = "v2v_utils_drive_index"
external shell_unquote : string -> string = "v2v_utils_shell_unquote"
+(* URI quoting. *)
+let uri_quote str =
+ let len = String.length str in
+ let xs = ref [] in
+ for i = 0 to len-1 do
+ xs :=
+ (match str.[i] with
+ | ('A'..'Z' | 'a'..'z' | '0'..'9' | '/' | '.' | '-') as c ->
+ String.make 1 c
+ | c ->
+ sprintf "%%%02x" (Char.code c)
+ ) :: !xs
+ done;
+ String.concat "" (List.rev !xs)
+
(* Map guest architecture found by inspection to the architecture
* that KVM must emulate. Note for x86 we assume a 64 bit hypervisor.
*)
diff --git a/v2v/utils.mli b/v2v/utils.mli
index 4906f0023..47335cca5 100644
--- a/v2v/utils.mli
+++ b/v2v/utils.mli
@@ -29,6 +29,9 @@ val shell_unquote : string -> string
(like ones under /etc/sysconfig), and it doesn't deal with some
situations such as $variable interpolation. *)
+val uri_quote : string -> string
+(** Take a string and perform %xx escaping as used in some parts of URLs. *)
+
val kvm_arch : string -> string
(** Map guest architecture found by inspection to the architecture
that KVM must emulate. Note for x86 we assume a 64 bit hypervisor. *)
diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml
index 468261d3d..f21324611 100644
--- a/v2v/vCenter.ml
+++ b/v2v/vCenter.ml
@@ -22,21 +22,7 @@ open Common_utils
open Common_gettext.Gettext
open Xml
-
-(* URI quoting. *)
-let uri_quote str =
- let len = String.length str in
- let xs = ref [] in
- for i = 0 to len-1 do
- xs :=
- (match str.[i] with
- | ('A'..'Z' | 'a'..'z' | '0'..'9' | '/' | '.' | '-') as c ->
- String.make 1 c
- | c ->
- sprintf "%%%02x" (Char.code c)
- ) :: !xs
- done;
- String.concat "" (List.rev !xs)
+open Utils
(* Memoized session cookie. *)
let session_cookie = ref ""
--
2.13.2
7 years, 4 months