]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
storage: Add startPool and stopPool for scsi backend
authorOsier Yang <jyang@redhat.com>
Mon, 25 Mar 2013 16:43:41 +0000 (00:43 +0800)
committerOsier Yang <jyang@redhat.com>
Mon, 8 Apr 2013 10:41:06 +0000 (18:41 +0800)
startPool creates the vHBA if it's not existed yet, stopPool destroys
the vHBA. Also to support autostart, checkPool will creates the vHBA
if it's not existed yet.

src/storage/storage_backend_scsi.c

index 275458b32f5c0a7b6b4a6ef95b725c4517379275..d72c1533548e7c075f2ae23dc945cf9ba8c14d3c 100644 (file)
@@ -644,6 +644,62 @@ getAdapterName(virStoragePoolSourceAdapter adapter)
     return name;
 }
 
+static int
+createVport(virStoragePoolSourceAdapter adapter)
+{
+    unsigned int parent_host;
+    char *name = NULL;
+
+    if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)
+        return 0;
+
+    /* This filters either HBA or already created vHBA */
+    if ((name = virGetFCHostNameByWWN(NULL, adapter.data.fchost.wwnn,
+                                      adapter.data.fchost.wwpn))) {
+        VIR_FREE(name);
+        return 0;
+    }
+
+    if (!adapter.data.fchost.parent) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("'parent' for vHBA must be specified"));
+        return -1;
+    }
+
+    if (getHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
+        return -1;
+
+    if (virManageVport(parent_host, adapter.data.fchost.wwnn,
+                       adapter.data.fchost.wwpn, VPORT_CREATE) < 0)
+        return -1;
+
+    virFileWaitForDevices();
+    return 0;
+}
+
+static int
+deleteVport(virStoragePoolSourceAdapter adapter)
+{
+    unsigned int parent_host;
+
+    if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)
+        return 0;
+
+    if (!(virGetFCHostNameByWWN(NULL, adapter.data.fchost.wwnn,
+                                adapter.data.fchost.wwpn)))
+        return -1;
+
+    if (getHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
+        return -1;
+
+    if (virManageVport(parent_host, adapter.data.fchost.wwnn,
+                       adapter.data.fchost.wwpn, VPORT_DELETE) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 virStorageBackendSCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                                virStoragePoolObjPtr pool,
@@ -706,10 +762,27 @@ out:
     return ret;
 }
 
+static int
+virStorageBackendSCSIStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
+                               virStoragePoolObjPtr pool)
+{
+    virStoragePoolSourceAdapter adapter = pool->def->source.adapter;
+    return createVport(adapter);
+}
+
+static int
+virStorageBackendSCSIStopPool(virConnectPtr conn ATTRIBUTE_UNUSED,
+                              virStoragePoolObjPtr pool)
+{
+    virStoragePoolSourceAdapter adapter = pool->def->source.adapter;
+    return deleteVport(adapter);
+}
 
 virStorageBackend virStorageBackendSCSI = {
     .type = VIR_STORAGE_POOL_SCSI,
 
     .checkPool = virStorageBackendSCSICheckPool,
     .refreshPool = virStorageBackendSCSIRefreshPool,
+    .startPool = virStorageBackendSCSIStartPool,
+    .stopPool = virStorageBackendSCSIStopPool,
 };