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,44 @@ static void xl_ctx_free(void) } } +/* + Return 0 if domain is managed by libvirt +*/ +static int xl_lookup_libvirt_managed_domains(int argc, char **argv) +{ + FILE *fp; + int i; + char line[1024]; + char *libvirt_sock = "/run/libvirt/libvirt-sock"; + + /* Check for the libvirt socket file */ + if (access(libvirt_sock, F_OK) != 0) { + return 1; + } + + /* Run virsh to get a list of running domains managed by libvirt */ + fp = popen("/usr/bin/virsh list --name 2>&1", "r"); + if (fp == NULL) { + return 1; + } + + /* Read the list of domains looking for each name in the xl command */ + while (fgets(line, sizeof(line)-1, fp) != NULL) { + line[strlen(line)-1] = '\0'; + for (i=0; imodifies && !dryrun_only) { + if (!force_execution) { + if (!xl_lookup_libvirt_managed_domains(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,