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

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