Blame SOURCES/0001-Add-a-binding-for-virDomainCreateXML.patch

ca920e
From 7483c7454538584a3dbe4582096f058e6e877df6 Mon Sep 17 00:00:00 2001
ca920e
From: "Richard W.M. Jones" <rjones@redhat.com>
ca920e
Date: Fri, 6 Mar 2015 15:35:46 +0000
ca920e
Subject: [PATCH] Add a binding for virDomainCreateXML.
ca920e
ca920e
This is more modern than the ancient virDomainCreateLinux API,
ca920e
and crucially allows you to pass flags such as AUTODESTROY.
ca920e
---
ca920e
 configure.ac         |  2 +-
ca920e
 libvirt/generator.pl | 23 +++++++++++++++++++++--
ca920e
 libvirt/libvirt.ml   | 19 ++++++++++++++++++-
ca920e
 libvirt/libvirt.mli  | 13 +++++++++++--
ca920e
 libvirt/libvirt_c.c  | 25 ++++++++++++++++++++++++-
ca920e
 5 files changed, 75 insertions(+), 7 deletions(-)
ca920e
ca920e
diff --git a/configure.ac b/configure.ac
ca920e
index b7544b4..a719fb3 100644
ca920e
--- a/configure.ac
ca920e
+++ b/configure.ac
ca920e
@@ -1,5 +1,5 @@
ca920e
 # ocaml-libvirt
ca920e
-# Copyright (C) 2007-2008 Red Hat Inc., Richard W.M. Jones
ca920e
+# Copyright (C) 2007-2015 Red Hat Inc., Richard W.M. Jones
ca920e
 #
ca920e
 # This library is free software; you can redistribute it and/or
ca920e
 # modify it under the terms of the GNU Lesser General Public
ca920e
diff --git a/libvirt/generator.pl b/libvirt/generator.pl
ca920e
index 8229ad1..421592b 100755
ca920e
--- a/libvirt/generator.pl
ca920e
+++ b/libvirt/generator.pl
ca920e
@@ -1,7 +1,7 @@
ca920e
 #!/usr/bin/perl -w
ca920e
 #
ca920e
 # OCaml bindings for libvirt.
ca920e
-# (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
ca920e
+# (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
ca920e
 # http://libvirt.org/
ca920e
 #
ca920e
 # This library is free software; you can redistribute it and/or
ca920e
@@ -63,6 +63,7 @@ my @functions = (
ca920e
       sig => "conn, int : unit" },
ca920e
 
ca920e
     { name => "virDomainCreateLinux", sig => "conn, string, 0U : dom" },
ca920e
+    { name => "virDomainCreateXML", sig => "conn, string, unsigned : dom" },
ca920e
     { name => "virDomainFree", sig => "dom : free" },
ca920e
     { name => "virDomainDestroy", sig => "dom : free" },
ca920e
     { name => "virDomainLookupByName", sig => "conn, string : dom" },
ca920e
@@ -198,7 +199,7 @@ print F <<'END';
ca920e
  */
ca920e
 
ca920e
 /* OCaml bindings for libvirt.
ca920e
- * (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
ca920e
+ * (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
ca920e
  * http://libvirt.org/
ca920e
  *
ca920e
  * This library is free software; you can redistribute it and/or
ca920e
@@ -310,6 +311,8 @@ sub gen_arg_names
ca920e
 	( "$1v", "strv" )
ca920e
     } elsif ($sig =~ /^(\w+), string, 0U? : (\w+)$/) {
ca920e
 	( "$1v", "strv" )
ca920e
+    } elsif ($sig =~ /^(\w+), string, unsigned : (\w+)$/) {
ca920e
+	( "$1v", "strv", "uv" )
ca920e
     } elsif ($sig =~ /^(\w+), u?int : (\w+)$/) {
ca920e
 	( "$1v", "iv" )
ca920e
     } elsif ($sig =~ /^(\w+), uuid : (\w+)$/) {
ca920e
@@ -632,6 +635,22 @@ sub gen_c_code
ca920e
 
ca920e
   CAMLreturn (rv);
ca920e
 "
ca920e
+    } elsif ($sig =~ /^(\w+), string, unsigned : (\w+)$/) {
ca920e
+	my $c_ret_type = short_name_to_c_type ($2);
ca920e
+	"\
ca920e
+  CAMLlocal1 (rv);
ca920e
+  " . gen_unpack_args ($1) . "
ca920e
+  char *str = String_val (strv);
ca920e
+  unsigned int u = Int_val (uv);
ca920e
+  $c_ret_type r;
ca920e
+
ca920e
+  NONBLOCKING (r = $c_name ($1, str, u));
ca920e
+  CHECK_ERROR (!r, conn, \"$c_name\");
ca920e
+
ca920e
+  " . gen_pack_result ($2) . "
ca920e
+
ca920e
+  CAMLreturn (rv);
ca920e
+"
ca920e
     } elsif ($sig =~ /^(\w+), (u?)int : unit$/) {
ca920e
 	my $unsigned = $2 eq "u" ? "unsigned " : "";
ca920e
 	"\
ca920e
diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml
ca920e
index 9c9368a..1be023d 100644
ca920e
--- a/libvirt/libvirt.ml
ca920e
+++ b/libvirt/libvirt.ml
ca920e
@@ -1,5 +1,5 @@
ca920e
 (* OCaml bindings for libvirt.
ca920e
-   (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
ca920e
+   (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
ca920e
    http://libvirt.org/
ca920e
 
ca920e
    This library is free software; you can redistribute it and/or
ca920e
@@ -337,6 +337,20 @@ struct
ca920e
     cpu : int;
ca920e
   }
ca920e
 
ca920e
+  type domain_create_flag =
ca920e
+  | START_PAUSED
ca920e
+  | START_AUTODESTROY
ca920e
+  | START_BYPASS_CACHE
ca920e
+  | START_FORCE_BOOT
ca920e
+  | START_VALIDATE
ca920e
+  let rec int_of_domain_create_flags = function
ca920e
+    | [] -> 0
ca920e
+    | START_PAUSED :: flags ->       1 lor int_of_domain_create_flags flags
ca920e
+    | START_AUTODESTROY :: flags ->  2 lor int_of_domain_create_flags flags
ca920e
+    | START_BYPASS_CACHE :: flags -> 4 lor int_of_domain_create_flags flags
ca920e
+    | START_FORCE_BOOT :: flags ->   8 lor int_of_domain_create_flags flags
ca920e
+    | START_VALIDATE :: flags ->    16 lor int_of_domain_create_flags flags
ca920e
+
ca920e
   type sched_param = string * sched_param_value
ca920e
   and sched_param_value =
ca920e
     | SchedFieldInt32 of int32 | SchedFieldUInt32 of int32
ca920e
@@ -385,6 +399,9 @@ struct
ca920e
   let max_peek _ = 65536
ca920e
 
ca920e
   external create_linux : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_domain_create_linux"
ca920e
+  external _create_xml : [>`W] Connect.t -> xml -> int -> rw t = "ocaml_libvirt_domain_create_xml"
ca920e
+  let create_xml conn xml flags =
ca920e
+    _create_xml conn xml (int_of_domain_create_flags flags)
ca920e
   external lookup_by_id : 'a Connect.t -> int -> 'a t = "ocaml_libvirt_domain_lookup_by_id"
ca920e
   external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_domain_lookup_by_uuid"
ca920e
   external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_domain_lookup_by_uuid_string"
ca920e
diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli
ca920e
index 36cd113..8cfcae2 100644
ca920e
--- a/libvirt/libvirt.mli
ca920e
+++ b/libvirt/libvirt.mli
ca920e
@@ -1,5 +1,5 @@
ca920e
 (** OCaml bindings for libvirt. *)
ca920e
-(* (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
ca920e
+(* (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
ca920e
    http://libvirt.org/
ca920e
 
ca920e
    This library is free software; you can redistribute it and/or
ca920e
@@ -430,6 +430,13 @@ sig
ca920e
     cpu : int;				(** real CPU number, -1 if offline *)
ca920e
   }
ca920e
 
ca920e
+  type domain_create_flag =
ca920e
+  | START_PAUSED                        (** Launch guest in paused state *)
ca920e
+  | START_AUTODESTROY                   (** Automatically kill guest on close *)
ca920e
+  | START_BYPASS_CACHE                  (** Avoid filesystem cache pollution *)
ca920e
+  | START_FORCE_BOOT                    (** Discard any managed save *)
ca920e
+  | START_VALIDATE                      (** Validate XML against schema *)
ca920e
+
ca920e
   type sched_param = string * sched_param_value
ca920e
   and sched_param_value =
ca920e
     | SchedFieldInt32 of int32 | SchedFieldUInt32 of int32
ca920e
@@ -478,8 +485,10 @@ sig
ca920e
 
ca920e
   val create_linux : [>`W] Connect.t -> xml -> rw t
ca920e
     (** Create a new guest domain (not necessarily a Linux one)
ca920e
-	from the given XML.
ca920e
+	from the given XML.  Use {!create_xml} instead.
ca920e
     *)
ca920e
+  val create_xml : [>`W] Connect.t -> xml -> domain_create_flag list -> rw t
ca920e
+    (** Create a new guest domain from the given XML. *)
ca920e
   val lookup_by_id : 'a Connect.t -> int -> 'a t
ca920e
     (** Lookup a domain by ID. *)
ca920e
   val lookup_by_uuid : 'a Connect.t -> uuid -> 'a t
ca920e
diff --git a/libvirt/libvirt_c.c b/libvirt/libvirt_c.c
ca920e
index 71e6f61..6e56682 100644
ca920e
--- a/libvirt/libvirt_c.c
ca920e
+++ b/libvirt/libvirt_c.c
ca920e
@@ -6,7 +6,7 @@
ca920e
  */
ca920e
 
ca920e
 /* OCaml bindings for libvirt.
ca920e
- * (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
ca920e
+ * (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
ca920e
  * http://libvirt.org/
ca920e
  *
ca920e
  * This library is free software; you can redistribute it and/or
ca920e
@@ -525,6 +525,29 @@ ocaml_libvirt_domain_create_linux (value connv, value strv)
ca920e
   CAMLreturn (rv);
ca920e
 }
ca920e
 
ca920e
+/* Automatically generated binding for virDomainCreateXML.
ca920e
+ * In generator.pl this function has signature "conn, string, unsigned : dom".
ca920e
+ */
ca920e
+
ca920e
+CAMLprim value
ca920e
+ocaml_libvirt_domain_create_xml (value connv, value strv, value uv)
ca920e
+{
ca920e
+  CAMLparam3 (connv, strv, uv);
ca920e
+
ca920e
+  CAMLlocal1 (rv);
ca920e
+  virConnectPtr conn = Connect_val (connv);
ca920e
+  char *str = String_val (strv);
ca920e
+  unsigned int u = Int_val (uv);
ca920e
+  virDomainPtr r;
ca920e
+
ca920e
+  NONBLOCKING (r = virDomainCreateXML (conn, str, u));
ca920e
+  CHECK_ERROR (!r, conn, "virDomainCreateXML");
ca920e
+
ca920e
+  rv = Val_domain (r, connv);
ca920e
+
ca920e
+  CAMLreturn (rv);
ca920e
+}
ca920e
+
ca920e
 /* Automatically generated binding for virDomainFree.
ca920e
  * In generator.pl this function has signature "dom : free".
ca920e
  */
ca920e
-- 
ca920e
2.3.1
ca920e