[PATCH 2/n] conf: split network host structs to util/

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

 



Continuing the refactoring of host-side storage descriptions out
of conf/domain_conf and into util/virstoragefile, this patch
focuses on details about a host name/port/transport as used by
a network storage volume.

* src/conf/domain_conf.h (virDomainDiskProtocolTransport)
(virDomainDiskHostDef, virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): Move...
* src/util/virstoragefile.h (virStorageNetHostTransport)
(virStorageNetHostDef, virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): ...here,
with better names.
* src/util/virstoragefile.c (virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): Moved from...
* src/conf/domain_conf.c (virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): ...here.
(virDomainDiskSourceDefClear, virDomainDiskSourceDefParse)
(virDomainDiskSourceDefFormatInternal): Adjust callers.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear):
Likewise.
* src/qemu/qemu_command.c (qemuAddRBDHost)
(qemuParseDriveURIString, qemuParseNBDString)
(qemuBuildNetworkDriveURI, qemuParseCommandLineDisk)
(qemuParseCommandLine, qemuGetDriveSourceString): Likewise.
* src/qemu/qemu_command.h: Likewise.
* src/qemu/qemu_conf.c (qemuAddISCSIPoolSourceHost)
(qemuTranslateDiskSourcePool): Likewise.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGlusterInit): Likewise.
* src/storage/storage_driver.c (virStorageFileFree)
(virStorageFileInitInternal): Likewise.
* src/storage/storage_driver.h (_virStorageFile): Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/conf/domain_conf.c                | 88 +++++------------------------------
 src/conf/domain_conf.h                | 28 ++---------
 src/conf/snapshot_conf.c              |  5 +-
 src/conf/snapshot_conf.h              |  4 +-
 src/libvirt_private.syms              | 10 ++--
 src/qemu/qemu_command.c               | 38 +++++++--------
 src/qemu/qemu_command.h               |  6 +--
 src/qemu/qemu_conf.c                  |  4 +-
 src/qemu/qemu_driver.c                | 24 +++++-----
 src/storage/storage_backend_gluster.c |  8 ++--
 src/storage/storage_driver.c          |  8 ++--
 src/storage/storage_driver.h          |  2 +-
 src/util/virstoragefile.c             | 71 +++++++++++++++++++++++++++-
 src/util/virstoragefile.h             | 30 +++++++++++-
 14 files changed, 167 insertions(+), 159 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 66eeaa9..159a9c3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -276,11 +276,6 @@ VIR_ENUM_IMPL(virDomainDiskProtocol, VIR_DOMAIN_DISK_PROTOCOL_LAST,
               "ftps",
               "tftp")

-VIR_ENUM_IMPL(virDomainDiskProtocolTransport, VIR_DOMAIN_DISK_PROTO_TRANS_LAST,
-              "tcp",
-              "unix",
-              "rdma")
-
 VIR_ENUM_IMPL(virDomainDiskSecretType, VIR_DOMAIN_DISK_SECRET_TYPE_LAST,
               "none",
               "uuid",
@@ -1245,7 +1240,7 @@ virDomainDiskSourceDefClear(virDomainDiskSourceDefPtr def)
         VIR_FREE(def->seclabels);
     }

-    virDomainDiskHostDefFree(def->nhosts, def->hosts);
+    virStorageNetHostDefFree(def->nhosts, def->hosts);
     virDomainDiskAuthClear(def);
 }

@@ -1282,67 +1277,6 @@ virDomainDiskAuthClear(virDomainDiskSourceDefPtr def)
 }


-void virDomainDiskHostDefClear(virDomainDiskHostDefPtr def)
-{
-    if (!def)
-        return;
-
-    VIR_FREE(def->name);
-    VIR_FREE(def->port);
-    VIR_FREE(def->socket);
-}
-
-
-void
-virDomainDiskHostDefFree(size_t nhosts,
-                         virDomainDiskHostDefPtr hosts)
-{
-    size_t i;
-
-    if (!hosts)
-        return;
-
-    for (i = 0; i < nhosts; i++)
-        virDomainDiskHostDefClear(&hosts[i]);
-
-    VIR_FREE(hosts);
-}
-
-
-virDomainDiskHostDefPtr
-virDomainDiskHostDefCopy(size_t nhosts,
-                         virDomainDiskHostDefPtr hosts)
-{
-    virDomainDiskHostDefPtr ret = NULL;
-    size_t i;
-
-    if (VIR_ALLOC_N(ret, nhosts) < 0)
-        goto error;
-
-    for (i = 0; i < nhosts; i++) {
-        virDomainDiskHostDefPtr src = &hosts[i];
-        virDomainDiskHostDefPtr dst = &ret[i];
-
-        dst->transport = src->transport;
-
-        if (VIR_STRDUP(dst->name, src->name) < 0)
-            goto error;
-
-        if (VIR_STRDUP(dst->port, src->port) < 0)
-            goto error;
-
-        if (VIR_STRDUP(dst->socket, src->socket) < 0)
-            goto error;
-    }
-
-    return ret;
-
- error:
-    virDomainDiskHostDefFree(nhosts, ret);
-    return NULL;
-}
-
-
 int
 virDomainDiskGetType(virDomainDiskDefPtr def)
 {
@@ -5102,12 +5036,12 @@ virDomainDiskSourceDefParse(xmlNodePtr node,
                             char **source,
                             int *proto,
                             size_t *nhosts,
-                            virDomainDiskHostDefPtr *hosts,
+                            virStorageNetHostDefPtr *hosts,
                             virDomainDiskSourcePoolDefPtr *srcpool)
 {
     char *protocol = NULL;
     char *transport = NULL;
-    virDomainDiskHostDef host;
+    virStorageNetHostDef host;
     xmlNodePtr child;
     int ret = -1;

@@ -5148,11 +5082,11 @@ virDomainDiskSourceDefParse(xmlNodePtr node,
             if (child->type == XML_ELEMENT_NODE &&
                 xmlStrEqual(child->name, BAD_CAST "host")) {

-                host.transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
+                host.transport = VIR_STORAGE_NET_HOST_TRANS_TCP;

                 /* transport can be tcp (default), unix or rdma.  */
                 if ((transport = virXMLPropString(child, "transport"))) {
-                    host.transport = virDomainDiskProtocolTransportTypeFromString(transport);
+                    host.transport = virStorageNetHostTransportTypeFromString(transport);
                     if (host.transport < 0) {
                         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                        _("unknown protocol transport type '%s'"),
@@ -5163,14 +5097,14 @@ virDomainDiskSourceDefParse(xmlNodePtr node,

                 host.socket = virXMLPropString(child, "socket");

-                if (host.transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX &&
+                if (host.transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
                     host.socket == NULL) {
                     virReportError(VIR_ERR_XML_ERROR, "%s",
                                    _("missing socket for unix transport"));
                     goto cleanup;
                 }

-                if (host.transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX &&
+                if (host.transport != VIR_STORAGE_NET_HOST_TRANS_UNIX &&
                     host.socket != NULL) {
                     virReportError(VIR_ERR_XML_ERROR,
                                    _("transport '%s' does not support "
@@ -5181,7 +5115,7 @@ virDomainDiskSourceDefParse(xmlNodePtr node,

                 VIR_FREE(transport);

-                if (host.transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX) {
+                if (host.transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) {
                     if (!(host.name = virXMLPropString(child, "name"))) {
                         virReportError(VIR_ERR_XML_ERROR, "%s",
                                        _("missing name for host"));
@@ -5217,7 +5151,7 @@ virDomainDiskSourceDefParse(xmlNodePtr node,
     ret = 0;

  cleanup:
-    virDomainDiskHostDefClear(&host);
+    virStorageNetHostDefClear(&host);
     VIR_FREE(protocol);
     VIR_FREE(transport);
     return ret;
@@ -14843,7 +14777,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
                                      int policy,
                                      int protocol,
                                      size_t nhosts,
-                                     virDomainDiskHostDefPtr hosts,
+                                     virStorageNetHostDefPtr hosts,
                                      size_t nseclabels,
                                      virSecurityDeviceLabelDefPtr *seclabels,
                                      virDomainDiskSourcePoolDefPtr srcpool,
@@ -14897,7 +14831,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,

                     if (hosts[n].transport)
                         virBufferAsprintf(buf, " transport='%s'",
-                                          virDomainDiskProtocolTransportTypeToString(hosts[n].transport));
+                                          virStorageNetHostTransportTypeToString(hosts[n].transport));

                     virBufferEscapeString(buf, " socket='%s'", hosts[n].socket);

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a249208..cbf2dca 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -533,14 +533,6 @@ enum virDomainDiskProtocol {
     VIR_DOMAIN_DISK_PROTOCOL_LAST
 };

-enum virDomainDiskProtocolTransport {
-    VIR_DOMAIN_DISK_PROTO_TRANS_TCP,
-    VIR_DOMAIN_DISK_PROTO_TRANS_UNIX,
-    VIR_DOMAIN_DISK_PROTO_TRANS_RDMA,
-
-    VIR_DOMAIN_DISK_PROTO_TRANS_LAST
-};
-
 enum virDomainDiskTray {
     VIR_DOMAIN_DISK_TRAY_CLOSED,
     VIR_DOMAIN_DISK_TRAY_OPEN,
@@ -557,15 +549,6 @@ enum virDomainDiskGeometryTrans {
     VIR_DOMAIN_DISK_TRANS_LAST
 };

-typedef struct _virDomainDiskHostDef virDomainDiskHostDef;
-typedef virDomainDiskHostDef *virDomainDiskHostDefPtr;
-struct _virDomainDiskHostDef {
-    char *name;
-    char *port;
-    int transport; /* enum virDomainDiskProtocolTransport */
-    char *socket;  /* path to unix socket */
-};
-
 enum virDomainDiskIo {
     VIR_DOMAIN_DISK_IO_DEFAULT,
     VIR_DOMAIN_DISK_IO_NATIVE,
@@ -684,7 +667,7 @@ struct _virDomainDiskSourceDef {
     char *path;
     int protocol; /* enum virDomainDiskProtocol */
     size_t nhosts;
-    virDomainDiskHostDefPtr hosts;
+    virStorageNetHostDefPtr hosts;
     virDomainDiskSourcePoolDefPtr srcpool;
     struct {
         char *username;
@@ -2232,10 +2215,6 @@ void virDomainInputDefFree(virDomainInputDefPtr def);
 void virDomainDiskDefFree(virDomainDiskDefPtr def);
 void virDomainLeaseDefFree(virDomainLeaseDefPtr def);
 void virDomainDiskAuthClear(virDomainDiskSourceDefPtr def);
-void virDomainDiskHostDefClear(virDomainDiskHostDefPtr def);
-void virDomainDiskHostDefFree(size_t nhosts, virDomainDiskHostDefPtr hosts);
-virDomainDiskHostDefPtr virDomainDiskHostDefCopy(size_t nhosts,
-                                                 virDomainDiskHostDefPtr hosts);
 int virDomainDiskGetType(virDomainDiskDefPtr def);
 void virDomainDiskSetType(virDomainDiskDefPtr def, int type);
 int virDomainDiskGetActualType(virDomainDiskDefPtr def);
@@ -2388,7 +2367,7 @@ int virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
                                          int policy,
                                          int protocol,
                                          size_t nhosts,
-                                         virDomainDiskHostDefPtr hosts,
+                                         virStorageNetHostDefPtr hosts,
                                          size_t nseclabels,
                                          virSecurityDeviceLabelDefPtr *seclabels,
                                          virDomainDiskSourcePoolDefPtr srcpool,
@@ -2444,7 +2423,7 @@ int virDomainDiskSourceDefParse(xmlNodePtr node,
                                 char **source,
                                 int *proto,
                                 size_t *nhosts,
-                                virDomainDiskHostDefPtr *hosts,
+                                virStorageNetHostDefPtr *hosts,
                                 virDomainDiskSourcePoolDefPtr *srcpool);

 bool virDomainHasDiskMirror(virDomainObjPtr vm);
@@ -2664,7 +2643,6 @@ VIR_ENUM_DECL(virDomainDiskBus)
 VIR_ENUM_DECL(virDomainDiskCache)
 VIR_ENUM_DECL(virDomainDiskErrorPolicy)
 VIR_ENUM_DECL(virDomainDiskProtocol)
-VIR_ENUM_DECL(virDomainDiskProtocolTransport)
 VIR_ENUM_DECL(virDomainDiskIo)
 VIR_ENUM_DECL(virDomainDiskSecretType)
 VIR_ENUM_DECL(virDomainDeviceSGIO)
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index ccce46c..9f4ea7f 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -84,9 +84,8 @@ virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk)
 {
     VIR_FREE(disk->name);
     VIR_FREE(disk->file);
-    while (disk->nhosts)
-        virDomainDiskHostDefClear(&disk->hosts[--disk->nhosts]);
-    VIR_FREE(disk->hosts);
+    virStorageNetHostDefFree(disk->nhosts, disk->hosts);
+    disk->nhosts = 0;
 }

 void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h
index 59c6d92..fc73438 100644
--- a/src/conf/snapshot_conf.h
+++ b/src/conf/snapshot_conf.h
@@ -1,7 +1,7 @@
 /*
  * snapshot_conf.h: domain snapshot XML processing
  *
- * Copyright (C) 2006-2013 Red Hat, Inc.
+ * Copyright (C) 2006-2014 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -56,7 +56,7 @@ struct _virDomainSnapshotDiskDef {
     int format;     /* enum virStorageFileFormat */
     int protocol;   /* network source protocol */
     size_t nhosts;  /* network source hosts count */
-    virDomainDiskHostDefPtr hosts; /* network source hosts */
+    virStorageNetHostDefPtr hosts; /* network source hosts */
 };

 /* Stores the complete snapshot metadata */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 74b8a7e..64c63ff 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -203,17 +203,12 @@ virDomainDiskGetDriver;
 virDomainDiskGetFormat;
 virDomainDiskGetSource;
 virDomainDiskGetType;
-virDomainDiskHostDefClear;
-virDomainDiskHostDefCopy;
-virDomainDiskHostDefFree;
 virDomainDiskIndexByName;
 virDomainDiskInsert;
 virDomainDiskInsertPreAlloced;
 virDomainDiskIoTypeFromString;
 virDomainDiskIoTypeToString;
 virDomainDiskPathByName;
-virDomainDiskProtocolTransportTypeFromString;
-virDomainDiskProtocolTransportTypeToString;
 virDomainDiskProtocolTypeToString;
 virDomainDiskRemove;
 virDomainDiskRemoveByName;
@@ -1841,6 +1836,11 @@ virStorageFileIsSharedFSType;
 virStorageFileProbeFormat;
 virStorageFileProbeFormatFromBuf;
 virStorageFileResize;
+virStorageNetHostDefClear;
+virStorageNetHostDefCopy;
+virStorageNetHostDefFree;
+virStorageNetHostTransportTypeFromString;
+virStorageNetHostTransportTypeToString;


 # util/virstring.h
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9a314bf..c43a0f7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3285,7 +3285,7 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport)
     if (!disk->src.hosts[disk->src.nhosts-1].name)
         goto error;

-    disk->src.hosts[disk->src.nhosts-1].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
+    disk->src.hosts[disk->src.nhosts-1].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
     disk->src.hosts[disk->src.nhosts-1].socket = NULL;

     return 0;
@@ -3388,9 +3388,9 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
     }

     if (!transp) {
-        def->src.hosts->transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
+        def->src.hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
     } else {
-        def->src.hosts->transport = virDomainDiskProtocolTransportTypeFromString(transp);
+        def->src.hosts->transport = virStorageNetHostTransportTypeFromString(transp);
         if (def->src.hosts->transport < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Invalid %s transport type '%s'"), scheme, transp);
@@ -3399,7 +3399,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
     }
     def->src.nhosts = 0; /* set to 1 once everything succeeds */

-    if (def->src.hosts->transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX) {
+    if (def->src.hosts->transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) {
         if (VIR_STRDUP(def->src.hosts->name, uri->server) < 0)
             goto error;

@@ -3447,7 +3447,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
     return ret;

  error:
-    virDomainDiskHostDefClear(def->src.hosts);
+    virStorageNetHostDefClear(def->src.hosts);
     VIR_FREE(def->src.hosts);
     goto cleanup;
 }
@@ -3492,7 +3492,7 @@ qemuParseISCSIString(virDomainDiskDefPtr def)
 static int
 qemuParseNBDString(virDomainDiskDefPtr disk)
 {
-    virDomainDiskHostDefPtr h = NULL;
+    virStorageNetHostDefPtr h = NULL;
     char *host, *port;
     char *src;

@@ -3513,7 +3513,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk)
         if (src)
             *src++ = '\0';

-        h->transport = VIR_DOMAIN_DISK_PROTO_TRANS_UNIX;
+        h->transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;
         if (VIR_STRDUP(h->socket, host + strlen("unix:")) < 0)
             goto error;
     } else {
@@ -3550,7 +3550,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk)
     return 0;

  error:
-    virDomainDiskHostDefClear(h);
+    virStorageNetHostDefClear(h);
     VIR_FREE(h);
     return -1;
 }
@@ -3615,7 +3615,7 @@ char *
 qemuBuildNetworkDriveURI(int protocol,
                          const char *src,
                          size_t nhosts,
-                         virDomainDiskHostDefPtr hosts,
+                         virStorageNetHostDefPtr hosts,
                          const char *username,
                          const char *secret)
 {
@@ -3634,23 +3634,23 @@ qemuBuildNetworkDriveURI(int protocol,
             }

             if (!((hosts->name && strchr(hosts->name, ':')) ||
-                  (hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP &&
+                  (hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP &&
                    !hosts->name) ||
-                  (hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX &&
+                  (hosts->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
                    hosts->socket &&
                    hosts->socket[0] != '/'))) {

                 virBufferAddLit(&buf, "nbd:");

                 switch (hosts->transport) {
-                case VIR_DOMAIN_DISK_PROTO_TRANS_TCP:
+                case VIR_STORAGE_NET_HOST_TRANS_TCP:
                     virBufferStrcat(&buf, hosts->name, NULL);
                     virBufferAsprintf(&buf, ":%s",
                                       hosts->port ? hosts->port :
                                       QEMU_DEFAULT_NBD_PORT);
                     break;

-                case VIR_DOMAIN_DISK_PROTO_TRANS_UNIX:
+                case VIR_STORAGE_NET_HOST_TRANS_UNIX:
                     if (!hosts->socket) {
                         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                        _("socket attribute required for "
@@ -3664,7 +3664,7 @@ qemuBuildNetworkDriveURI(int protocol,
                 default:
                     virReportError(VIR_ERR_INTERNAL_ERROR,
                                    _("nbd does not support transport '%s'"),
-                                   virDomainDiskProtocolTransportTypeToString(hosts->transport));
+                                   virStorageNetHostTransportTypeToString(hosts->transport));
                     goto cleanup;
                 }

@@ -3699,14 +3699,14 @@ qemuBuildNetworkDriveURI(int protocol,
             if (VIR_ALLOC(uri) < 0)
                 goto cleanup;

-            if (hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) {
+            if (hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
                 if (VIR_STRDUP(uri->scheme,
                                virDomainDiskProtocolTypeToString(protocol)) < 0)
                     goto cleanup;
             } else {
                 if (virAsprintf(&uri->scheme, "%s+%s",
                                 virDomainDiskProtocolTypeToString(protocol),
-                                virDomainDiskProtocolTransportTypeToString(hosts->transport)) < 0)
+                                virStorageNetHostTransportTypeToString(hosts->transport)) < 0)
                     goto cleanup;
             }

@@ -3826,7 +3826,7 @@ qemuGetDriveSourceString(int type,
                          const char *src,
                          int protocol,
                          size_t nhosts,
-                         virDomainDiskHostDefPtr hosts,
+                         virStorageNetHostDefPtr hosts,
                          const char *username,
                          const char *secret,
                          char **path)
@@ -10274,7 +10274,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
                         def->src.hosts->name = def->src.path;
                         if (VIR_STRDUP(def->src.hosts->port, port) < 0)
                             goto error;
-                        def->src.hosts->transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
+                        def->src.hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
                         def->src.hosts->socket = NULL;
                         if (VIR_STRDUP(def->src.path, vdi) < 0)
                             goto error;
@@ -12070,7 +12070,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
                 VIR_FREE(hosts);
                 goto error;
             }
-            first_rbd_disk->src.hosts[first_rbd_disk->src.nhosts].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
+            first_rbd_disk->src.hosts[first_rbd_disk->src.nhosts].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
             first_rbd_disk->src.hosts[first_rbd_disk->src.nhosts].socket = NULL;

             first_rbd_disk->src.nhosts++;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 50dc4a0..ea3ff8b 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -1,7 +1,7 @@
 /*
  * qemu_command.h: QEMU command generation
  *
- * Copyright (C) 2006-2013 Red Hat, Inc.
+ * Copyright (C) 2006-2014 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -185,7 +185,7 @@ char * qemuBuildRedirdevDevStr(virDomainDefPtr def,
 char *qemuBuildNetworkDriveURI(int proto,
                                const char *src,
                                size_t nhosts,
-                               virDomainDiskHostDefPtr hosts,
+                               virStorageNetHostDefPtr hosts,
                                const char *username,
                                const char *secret);

@@ -318,7 +318,7 @@ int qemuGetDriveSourceString(int type,
                              const char *src,
                              int protocol,
                              size_t nhosts,
-                             virDomainDiskHostDefPtr hosts,
+                             virStorageNetHostDefPtr hosts,
                              const char *username,
                              const char *secret,
                              char **path);
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index dc9b3ae..78ab02a 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1192,7 +1192,7 @@ qemuAddISCSIPoolSourceHost(virDomainDiskDefPtr def,
     /* Storage pool have not supported these 2 attributes yet,
      * use the defaults.
      */
-    def->src.hosts[0].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
+    def->src.hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
     def->src.hosts[0].socket = NULL;

     def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_ISCSI;
@@ -1309,7 +1309,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
     }

     VIR_FREE(def->src.path);
-    virDomainDiskHostDefFree(def->src.nhosts, def->src.hosts);
+    virStorageNetHostDefFree(def->src.nhosts, def->src.hosts);
     virDomainDiskAuthClear(&def->src);

     switch ((enum virStoragePoolType) pooldef->type) {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b032441..60dbb7f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12748,8 +12748,8 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     char *device = NULL;
     char *source = NULL;
     char *newsource = NULL;
-    virDomainDiskHostDefPtr newhosts = NULL;
-    virDomainDiskHostDefPtr persistHosts = NULL;
+    virStorageNetHostDefPtr newhosts = NULL;
+    virStorageNetHostDefPtr persistHosts = NULL;
     int format = snap->format;
     const char *formatStr = NULL;
     char *persistSource = NULL;
@@ -12815,11 +12815,11 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     case VIR_DOMAIN_DISK_TYPE_NETWORK:
         switch (snap->protocol) {
         case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER:
-            if (!(newhosts = virDomainDiskHostDefCopy(snap->nhosts, snap->hosts)))
+            if (!(newhosts = virStorageNetHostDefCopy(snap->nhosts, snap->hosts)))
                 goto cleanup;

             if (persistDisk &&
-                !(persistHosts = virDomainDiskHostDefCopy(snap->nhosts, snap->hosts)))
+                !(persistHosts = virStorageNetHostDefCopy(snap->nhosts, snap->hosts)))
                 goto cleanup;

             break;
@@ -12870,7 +12870,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     need_unlink = false;

     VIR_FREE(disk->src.path);
-    virDomainDiskHostDefFree(disk->src.nhosts, disk->src.hosts);
+    virStorageNetHostDefFree(disk->src.nhosts, disk->src.hosts);

     disk->src.path = newsource;
     disk->src.format = format;
@@ -12884,7 +12884,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,

     if (persistDisk) {
         VIR_FREE(persistDisk->src.path);
-        virDomainDiskHostDefFree(persistDisk->src.nhosts,
+        virStorageNetHostDefFree(persistDisk->src.nhosts,
                                  persistDisk->src.hosts);

         persistDisk->src.path = persistSource;
@@ -12906,8 +12906,8 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     VIR_FREE(source);
     VIR_FREE(newsource);
     VIR_FREE(persistSource);
-    virDomainDiskHostDefFree(snap->nhosts, newhosts);
-    virDomainDiskHostDefFree(snap->nhosts, persistHosts);
+    virStorageNetHostDefFree(snap->nhosts, newhosts);
+    virStorageNetHostDefFree(snap->nhosts, persistHosts);
     return ret;
 }

@@ -12947,9 +12947,9 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
     disk->src.format = origdisk->src.format;
     disk->src.type = origdisk->src.type;
     disk->src.protocol = origdisk->src.protocol;
-    virDomainDiskHostDefFree(disk->src.nhosts, disk->src.hosts);
+    virStorageNetHostDefFree(disk->src.nhosts, disk->src.hosts);
     disk->src.nhosts = origdisk->src.nhosts;
-    disk->src.hosts = virDomainDiskHostDefCopy(origdisk->src.nhosts,
+    disk->src.hosts = virStorageNetHostDefCopy(origdisk->src.nhosts,
                                                origdisk->src.hosts);
     if (persistDisk) {
         VIR_FREE(persistDisk->src.path);
@@ -12958,10 +12958,10 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
         persistDisk->src.format = origdisk->src.format;
         persistDisk->src.type = origdisk->src.type;
         persistDisk->src.protocol = origdisk->src.protocol;
-        virDomainDiskHostDefFree(persistDisk->src.nhosts,
+        virStorageNetHostDefFree(persistDisk->src.nhosts,
                                  persistDisk->src.hosts);
         persistDisk->src.nhosts = origdisk->src.nhosts;
-        persistDisk->src.hosts = virDomainDiskHostDefCopy(origdisk->src.nhosts,
+        persistDisk->src.hosts = virStorageNetHostDefCopy(origdisk->src.nhosts,
                                                           origdisk->src.hosts);
     }

diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 9a6180e..84c5fe2 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -1,7 +1,7 @@
 /*
  * storage_backend_gluster.c: storage backend for Gluster handling
  *
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (C) 2013-2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -509,7 +509,7 @@ static int
 virStorageFileBackendGlusterInit(virStorageFilePtr file)
 {
     virStorageFileBackendGlusterPrivPtr priv = NULL;
-    virDomainDiskHostDefPtr host = &(file->hosts[0]);
+    virStorageNetHostDefPtr host = &(file->hosts[0]);
     const char *hostname = host->name;
     int port = 0;

@@ -540,7 +540,7 @@ virStorageFileBackendGlusterInit(virStorageFilePtr file)
         goto error;
     }

-    if (host->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX)
+    if (host->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX)
         hostname = host->socket;


@@ -550,7 +550,7 @@ virStorageFileBackendGlusterInit(virStorageFilePtr file)
     }

     if (glfs_set_volfile_server(priv->vol,
-                                virDomainDiskProtocolTransportTypeToString(host->transport),
+                                virStorageNetHostTransportTypeToString(host->transport),
                                 hostname, port) < 0) {
         virReportSystemError(errno,
                              _("failed to set gluster volfile server '%s'"),
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 70a122d..cdb8536 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2742,7 +2742,7 @@ virStorageFileFree(virStorageFilePtr file)
         file->backend->backendDeinit(file);

     VIR_FREE(file->path);
-    virDomainDiskHostDefFree(file->nhosts, file->hosts);
+    virStorageNetHostDefFree(file->nhosts, file->hosts);
     VIR_FREE(file);
 }

@@ -2752,7 +2752,7 @@ virStorageFileInitInternal(int type,
                            const char *path,
                            int protocol,
                            size_t nhosts,
-                           virDomainDiskHostDefPtr hosts)
+                           virStorageNetHostDefPtr hosts)
 {
     virStorageFilePtr file = NULL;

@@ -2766,7 +2766,7 @@ virStorageFileInitInternal(int type,
     if (VIR_STRDUP(file->path, path) < 0)
         goto error;

-    if (!(file->hosts = virDomainDiskHostDefCopy(nhosts, hosts)))
+    if (!(file->hosts = virStorageNetHostDefCopy(nhosts, hosts)))
         goto error;

     if (!(file->backend = virStorageFileBackendForType(file->type,
@@ -2781,7 +2781,7 @@ virStorageFileInitInternal(int type,

  error:
     VIR_FREE(file->path);
-    virDomainDiskHostDefFree(file->nhosts, file->hosts);
+    virStorageNetHostDefFree(file->nhosts, file->hosts);
     VIR_FREE(file);
     return NULL;
 }
diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h
index 993bba5..886a4d5 100644
--- a/src/storage/storage_driver.h
+++ b/src/storage/storage_driver.h
@@ -42,7 +42,7 @@ struct _virStorageFile {
     int protocol;

     size_t nhosts;
-    virDomainDiskHostDefPtr hosts;
+    virStorageNetHostDefPtr hosts;
 };

 virStorageFilePtr
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index c7384d1..320473d 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1,7 +1,7 @@
 /*
  * virstoragefile.c: file utility functions for FS storage backend
  *
- * Copyright (C) 2007-2013 Red Hat, Inc.
+ * Copyright (C) 2007-2014 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -66,6 +66,13 @@ VIR_ENUM_IMPL(virStorageFileFeature,
               "lazy_refcounts",
               )

+
+VIR_ENUM_IMPL(virStorageNetHostTransport, VIR_STORAGE_NET_HOST_TRANS_LAST,
+              "tcp",
+              "unix",
+              "rdma")
+
+
 enum lv_endian {
     LV_LITTLE_ENDIAN = 1, /* 1234 */
     LV_BIG_ENDIAN         /* 4321 */
@@ -1556,3 +1563,65 @@ virStorageFileChainLookup(virStorageFileMetadataPtr chain, const char *start,
         *meta = NULL;
     return NULL;
 }
+
+
+void
+virStorageNetHostDefClear(virStorageNetHostDefPtr def)
+{
+    if (!def)
+        return;
+
+    VIR_FREE(def->name);
+    VIR_FREE(def->port);
+    VIR_FREE(def->socket);
+}
+
+
+void
+virStorageNetHostDefFree(size_t nhosts,
+                         virStorageNetHostDefPtr hosts)
+{
+    size_t i;
+
+    if (!hosts)
+        return;
+
+    for (i = 0; i < nhosts; i++)
+        virStorageNetHostDefClear(&hosts[i]);
+
+    VIR_FREE(hosts);
+}
+
+
+virStorageNetHostDefPtr
+virStorageNetHostDefCopy(size_t nhosts,
+                         virStorageNetHostDefPtr hosts)
+{
+    virStorageNetHostDefPtr ret = NULL;
+    size_t i;
+
+    if (VIR_ALLOC_N(ret, nhosts) < 0)
+        goto error;
+
+    for (i = 0; i < nhosts; i++) {
+        virStorageNetHostDefPtr src = &hosts[i];
+        virStorageNetHostDefPtr dst = &ret[i];
+
+        dst->transport = src->transport;
+
+        if (VIR_STRDUP(dst->name, src->name) < 0)
+            goto error;
+
+        if (VIR_STRDUP(dst->port, src->port) < 0)
+            goto error;
+
+        if (VIR_STRDUP(dst->socket, src->socket) < 0)
+            goto error;
+    }
+
+    return ret;
+
+ error:
+    virStorageNetHostDefFree(nhosts, ret);
+    return NULL;
+}
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 7bd2fe0..7b8a7f7 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -1,7 +1,7 @@
 /*
  * virstoragefile.h: file utility functions for FS storage backend
  *
- * Copyright (C) 2007-2009, 2012-2013 Red Hat, Inc.
+ * Copyright (C) 2007-2009, 2012-2014 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -83,6 +83,28 @@ struct _virStorageFileMetadata {
     char *compat;
 };

+
+/* Information related to network storage */
+enum virStorageNetHostTransport {
+    VIR_STORAGE_NET_HOST_TRANS_TCP,
+    VIR_STORAGE_NET_HOST_TRANS_UNIX,
+    VIR_STORAGE_NET_HOST_TRANS_RDMA,
+
+    VIR_STORAGE_NET_HOST_TRANS_LAST
+};
+
+VIR_ENUM_DECL(virStorageNetHostTransport)
+
+typedef struct _virStorageNetHostDef virStorageNetHostDef;
+typedef virStorageNetHostDef *virStorageNetHostDefPtr;
+struct _virStorageNetHostDef {
+    char *name;
+    char *port;
+    int transport; /* enum virStorageNetHostTransport */
+    char *socket;  /* path to unix socket */
+};
+
+
 # ifndef DEV_BSIZE
 #  define DEV_BSIZE 512
 # endif
@@ -138,4 +160,10 @@ int virStorageFileGetLVMKey(const char *path,
 int virStorageFileGetSCSIKey(const char *path,
                              char **key);

+void virStorageNetHostDefClear(virStorageNetHostDefPtr def);
+void virStorageNetHostDefFree(size_t nhosts, virStorageNetHostDefPtr hosts);
+virStorageNetHostDefPtr virStorageNetHostDefCopy(size_t nhosts,
+                                                 virStorageNetHostDefPtr hosts);
+
+
 #endif /* __VIR_STORAGE_FILE_H__ */
-- 
1.8.5.3

--
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]