File xl-check-for-libvirt-managed-domain.patch of Package xen.4507

Index: xen-4.4.0-testing/tools/libxl/xl.c
===================================================================
--- xen-4.4.0-testing.orig/tools/libxl/xl.c
+++ xen-4.4.0-testing/tools/libxl/xl.c
@@ -282,6 +282,32 @@ static void xl_ctx_free(void)
     }
 }
 
+/*
+  Return 0 if domain is managed by libvirt
+*/
+static int xl_lookup_libvirt_managed_domain(int argc, char **argv)
+{
+    uint32_t domid;
+    uint8_t *t_data;
+    char *domname;
+    int i, rc, t_len;
+
+    for (i=0; i<argc; ++i) {
+        rc = libxl_domain_qualifier_to_domid(ctx, argv[i], &domid);
+        if (!rc) {
+            domname = libxl_domid_to_name(ctx, domid);
+            if (domname != NULL) {
+                rc = libxl_userdata_retrieve(ctx, domid, "libvirt-xml", &t_data, &t_len);
+                if (!rc && t_len)
+                    return 0;
+                break;
+            }
+        }
+    }
+
+    return 1;
+}
+
 int main(int argc, char **argv)
 {
     int opt = 0;
@@ -345,6 +371,18 @@ int main(int argc, char **argv)
             goto xit;
         }
         if (cspec->modifies && !dryrun_only) {
+            if (!force_execution) {
+                if (!xl_lookup_libvirt_managed_domain(argc, argv)) {
+                    fprintf(stderr,
+"Warning: This domain is managed by libvirt. Using xl commands to modify this\n"
+"domain will result in errors when virsh or virt-manager is used.\n"
+"Please use only virsh or virt-manager to manage this domain.\n\n"
+"(This check can be overridden with the -f option.)\n"
+                            );
+                    ret = 1;
+                    goto xit;
+                }
+            }
             for (int i = 0; i < sizeof(locks)/sizeof(locks[0]); i++) {
                 if (!access(locks[i], F_OK) && !force_execution) {
                     fprintf(stderr,
openSUSE Build Service is sponsored by