]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodedev: Abstract nodeDeviceVportCreateDelete as util function
authorOsier Yang <jyang@redhat.com>
Mon, 7 Jan 2013 17:05:34 +0000 (01:05 +0800)
committerOsier Yang <jyang@redhat.com>
Mon, 25 Mar 2013 12:46:05 +0000 (20:46 +0800)
This abstracts nodeDeviceVportCreateDelete as an util function
virManageVport, which can be further used by later storage patches
(to support persistent vHBA, I don't want to create the vHBA
using the public API, which is not good).

src/libvirt_private.syms
src/node_device/node_device_driver.c
src/util/virutil.c
src/util/virutil.h

index 53d99cba529efbcaf17c1c0e7a0468087b7f385f..a2c4a54c9103f7d08e653290feb4755ed06e1fd3 100644 (file)
@@ -1867,6 +1867,7 @@ virIndexToDiskName;
 virIsCapableFCHost;
 virIsCapableVport;
 virIsDevMapperDevice;
+virManageVport;
 virParseNumber;
 virParseVersionString;
 virPipeReadUntilEOF;
index b4749fbef0115b5197eee32c50421eb9cd0816a3..6be7a254760e30255e5636aa07540432dafab067 100644 (file)
@@ -408,91 +408,6 @@ cleanup:
     return ret;
 }
 
-
-static int
-nodeDeviceVportCreateDelete(const int parent_host,
-                            const char *wwpn,
-                            const char *wwnn,
-                            int operation)
-{
-    int retval = 0;
-    char *operation_path = NULL, *vport_name = NULL;
-    const char *operation_file = NULL;
-
-    switch (operation) {
-    case VPORT_CREATE:
-        operation_file = LINUX_SYSFS_VPORT_CREATE_POSTFIX;
-        break;
-    case VPORT_DELETE:
-        operation_file = LINUX_SYSFS_VPORT_DELETE_POSTFIX;
-        break;
-    default:
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Invalid vport operation (%d)"), operation);
-        retval = -1;
-        goto cleanup;
-        break;
-    }
-
-    if (virAsprintf(&operation_path,
-                    "%shost%d%s",
-                    LINUX_SYSFS_FC_HOST_PREFIX,
-                    parent_host,
-                    operation_file) < 0) {
-
-        virReportOOMError();
-        retval = -1;
-        goto cleanup;
-    }
-
-    if (!virFileExists(operation_path)) {
-        VIR_FREE(operation_path);
-        if (virAsprintf(&operation_path,
-                        "%shost%d%s",
-                        LINUX_SYSFS_SCSI_HOST_PREFIX,
-                        parent_host,
-                        operation_file) < 0) {
-            virReportOOMError();
-            retval = -1;
-            goto cleanup;
-        }
-
-        if (!virFileExists(operation_path)) {
-            VIR_ERROR(_("No vport operation path found for host%d"),
-                      parent_host);
-            retval = -1;
-            goto cleanup;
-        }
-    }
-
-    VIR_DEBUG("Vport operation path is '%s'", operation_path);
-
-    if (virAsprintf(&vport_name,
-                    "%s:%s",
-                    wwpn,
-                    wwnn) < 0) {
-
-        virReportOOMError();
-        retval = -1;
-        goto cleanup;
-    }
-
-    if (virFileWriteStr(operation_path, vport_name, 0) == -1) {
-        virReportSystemError(errno,
-                             _("Write of '%s' to '%s' during "
-                               "vport create/delete failed"),
-                             vport_name, operation_path);
-        retval = -1;
-    }
-
-cleanup:
-    VIR_FREE(vport_name);
-    VIR_FREE(operation_path);
-    VIR_DEBUG("%s", _("Vport operation complete"));
-    return retval;
-}
-
-
 static int
 get_time(time_t *t)
 {
@@ -594,10 +509,10 @@ nodeDeviceCreateXML(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (nodeDeviceVportCreateDelete(parent_host,
-                                    wwpn,
-                                    wwnn,
-                                    VPORT_CREATE) == -1) {
+    if (virManageVport(parent_host,
+                       wwpn,
+                       wwnn,
+                       VPORT_CREATE) == -1) {
         goto cleanup;
     }
 
@@ -661,10 +576,10 @@ nodeDeviceDestroy(virNodeDevicePtr dev)
         goto out;
     }
 
-    if (nodeDeviceVportCreateDelete(parent_host,
-                                    wwpn,
-                                    wwnn,
-                                    VPORT_DELETE) == -1) {
+    if (virManageVport(parent_host,
+                       wwpn,
+                       wwnn,
+                       VPORT_DELETE) == -1) {
         goto out;
     }
 
index 456e3958dcca79a10d7c6ce44bbabe90a2b755a7..4175824ce8c1a763376aa5512febbf6c8001dce8 100644 (file)
@@ -3497,6 +3497,79 @@ cleanup:
     VIR_FREE(scsi_host_path);
     return ret;
 }
+
+int
+virManageVport(const int parent_host,
+               const char *wwpn,
+               const char *wwnn,
+               int operation)
+{
+    int ret = -1;
+    char *operation_path = NULL, *vport_name = NULL;
+    const char *operation_file = NULL;
+
+    switch (operation) {
+    case VPORT_CREATE:
+        operation_file = "vport_create";
+        break;
+    case VPORT_DELETE:
+        operation_file = "vport_delete";
+        break;
+    default:
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       _("Invalid vport operation (%d)"), operation);
+        goto cleanup;
+    }
+
+    if (virAsprintf(&operation_path,
+                    "%shost%d/%s",
+                    SYSFS_FC_HOST_PATH,
+                    parent_host,
+                    operation_file) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    if (!virFileExists(operation_path)) {
+        VIR_FREE(operation_path);
+        if (virAsprintf(&operation_path,
+                        "%shost%d/%s",
+                        SYSFS_SCSI_HOST_PATH,
+                        parent_host,
+                        operation_file) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        if (!virFileExists(operation_path)) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("vport operation '%s' is not supported for host%d"),
+                           operation_file, parent_host);
+            goto cleanup;
+        }
+    }
+
+    if (virAsprintf(&vport_name,
+                    "%s:%s",
+                    wwpn,
+                    wwnn) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    if (virFileWriteStr(operation_path, vport_name, 0) == 0)
+        ret = 0;
+    else
+        virReportSystemError(errno,
+                             _("Write of '%s' to '%s' during "
+                               "vport create/delete failed"),
+                             vport_name, operation_path);
+
+cleanup:
+    VIR_FREE(vport_name);
+    VIR_FREE(operation_path);
+    return ret;
+}
 #else
 int
 virReadFCHost(const char *sysfs_prefix ATTRIBUTE_UNUSED,
@@ -3522,4 +3595,15 @@ virIsCapbleVport(const char *sysfs_prefix ATTRIBUTE_UNUSED,
     virReportSystemError(ENOSYS, "%s", _("Not supported on this platform"));
     return -1;
 }
+
+int
+virManageVport(const int parent_host ATTRIBUTE_UNUSED,
+               const char *wwpn ATTRIBUTE_UNUSED,
+               const char *wwnn ATTRIBUTE_UNUSED,
+               int operation ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s", _("Not supported on this platform"));
+    return -1;
+}
+
 #endif /* __linux__ */
index 6fc10a483e89fa743e9b97fed5042c8a3f8f6369..47357fad1f68dedd019706599b42d67974ab8325 100644 (file)
@@ -306,4 +306,15 @@ int virReadFCHost(const char *sysfs_prefix,
 int virIsCapableFCHost(const char *sysfs_prefix, int host);
 int virIsCapableVport(const char *sysfs_prefix, int host);
 
+enum {
+    VPORT_CREATE,
+    VPORT_DELETE,
+};
+
+int virManageVport(const int parent_host,
+                   const char *wwpn,
+                   const char *wwnn,
+                  int operation)
+    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+
 #endif /* __VIR_UTIL_H__ */