]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Combine some duplicate code
authorCole Robinson <crobinso@redhat.com>
Thu, 20 May 2010 17:29:24 +0000 (13:29 -0400)
committerCole Robinson <crobinso@redhat.com>
Mon, 24 May 2010 14:43:19 +0000 (10:43 -0400)
Volume detection in the scsi backend was duplicating code already
present in storage_backend.c. Let's drop the duplicate code.

Also, change the shared function name to be less generic, and remove
some error squashing in the other call site.

src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_backend_mpath.c
src/storage/storage_backend_scsi.c

index 7df61cde1d0e8148527eb399b20f374ea6946394..f4124dfda4eb55082d586bd1aabf76bfa27341e0 100644 (file)
@@ -1050,8 +1050,8 @@ static struct diskType const disk_types[] = {
 
 
 int
-virStorageBackendUpdateVolTargetFormatFD(virStorageVolTargetPtr target,
-                                         int fd)
+virStorageBackendDetectBlockVolFormatFD(virStorageVolTargetPtr target,
+                                        int fd)
 {
     int i;
     off_t start;
index 766f374902a2cbe5b4d9a650c5fc3336d3b64c7d..907c4bc29a70f84855bb68f2bb5a541ef2635d10 100644 (file)
@@ -92,8 +92,8 @@ int virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
                                            unsigned long long *allocation,
                                            unsigned long long *capacity);
 int
-virStorageBackendUpdateVolTargetFormatFD(virStorageVolTargetPtr target,
-                                         int fd);
+virStorageBackendDetectBlockVolFormatFD(virStorageVolTargetPtr target,
+                                        int fd);
 
 char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
                                   const char *devpath);
index 78d6b31913d9334210c0a8dba53bad1478dbe5e5..8d0a92a4107cb9d0076a478ce56247999e6ee2f1 100644 (file)
@@ -59,7 +59,7 @@ virStorageBackendMpathUpdateVolTargetInfo(virStorageVolTargetPtr target,
                                                capacity) < 0)
         goto out;
 
-    if (virStorageBackendUpdateVolTargetFormatFD(target, fd) < 0)
+    if (virStorageBackendDetectBlockVolFormatFD(target, fd) < 0)
         goto out;
 
     ret = 0;
index cd01f933c3afb75b199122cade98d63eaeb53bb6..40f4fd83cab0c16b5a7e81e8fc9d9c14619cb02b 100644 (file)
@@ -135,10 +135,7 @@ virStorageBackendSCSIUpdateVolTargetInfo(virStorageVolTargetPtr target,
                                          unsigned long long *allocation,
                                          unsigned long long *capacity)
 {
-    int fd, i, ret = -1;
-    off_t start;
-    unsigned char buffer[1024];
-    ssize_t bytes;
+    int fd, ret = -1;
 
     if ((fd = open(target->path, O_RDONLY)) < 0) {
         virReportSystemError(errno,
@@ -153,33 +150,8 @@ virStorageBackendSCSIUpdateVolTargetInfo(virStorageVolTargetPtr target,
                                                capacity) < 0)
         goto cleanup;
 
-    /* make sure to set the target format "unknown" to begin with */
-    target->format = VIR_STORAGE_POOL_DISK_UNKNOWN;
-
-    start = lseek(fd, 0, SEEK_SET);
-    if (start < 0) {
-        virReportSystemError(errno,
-                             _("cannot seek to beginning of file '%s'"),
-                             target->path);
-        goto cleanup;
-    }
-    bytes = saferead(fd, buffer, sizeof(buffer));
-    if (bytes < 0) {
-        virReportSystemError(errno,
-                             _("cannot read beginning of file '%s'"),
-                             target->path);
+    if (virStorageBackendDetectBlockVolFormatFD(target, fd) < 0)
         goto cleanup;
-    }
-
-    for (i = 0; disk_types[i].part_table_type != -1; i++) {
-        if (disk_types[i].offset + disk_types[i].length > bytes)
-            continue;
-        if (memcmp(buffer+disk_types[i].offset, &disk_types[i].magic,
-            disk_types[i].length) == 0) {
-            target->format = disk_types[i].part_table_type;
-            break;
-        }
-    }
 
     ret = 0;