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

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