[libvirt] [PATCH] minor usb masstorage hotadd cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
this just brings qemudDomainAttachUsbMassstorageDevice in line with the
rest of the code:

* don't allow to add the same target device name more than once
* escape paths for qemu's monitor command

Cheers,
 -- Guido
>From e8a83a21642c78f22c80750b280c67fb9a7e0c06 Mon Sep 17 00:00:00 2001
From: Guido Guenther <agx@xxxxxxxxxxx>
Date: Fri, 17 Oct 2008 12:28:50 +0200
Subject: [PATCH] cleanup usb attach code

* don't allow to add the same target device name more than once
* escape paths for qemu's monitor command
---
 src/qemu_driver.c |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index af25d07..3df208d 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -2577,7 +2577,8 @@ static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDevi
 {
     struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
     virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid);
-    int ret;
+    int ret, i;
+    char *safe_path;
     char *cmd, *reply;
 
     if (!vm) {
@@ -2586,12 +2587,28 @@ static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDevi
         return -1;
     }
 
+    for (i = 0 ; i < vm->def->ndisks ; i++) {
+        if (STREQ(vm->def->disks[i]->dst, dev->data.disk->dst)) {
+            qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+                           _("target %s already exists"), dev->data.disk->dst);
+            return -1;
+        }
+    }
+
     if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) {
         qemudReportError(dom->conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
         return -1;
     }
 
-    ret = asprintf(&cmd, "usb_add disk:%s", dev->data.disk->src);
+    safe_path = qemudEscapeMonitorArg(dev->data.disk->src);
+    if (!safe_path) {
+        qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+                         "%s", _("out of memory"));
+        return -1;
+    }
+
+    ret = asprintf(&cmd, "usb_add disk:%s", safe_path);
+    VIR_FREE(safe_path);
     if (ret == -1) {
         qemudReportError(dom->conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
         return ret;
-- 
1.6.0.2

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]