From e40a285bb7458dc69f360394889b69a8c4d39e19 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 20 May 2010 13:29:24 -0400 Subject: [PATCH] storage: Combine some duplicate code 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 | 4 ++-- src/storage/storage_backend.h | 4 ++-- src/storage/storage_backend_mpath.c | 2 +- src/storage/storage_backend_scsi.c | 32 ++--------------------------- 4 files changed, 7 insertions(+), 35 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 7df61cde1d..f4124dfda4 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -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; diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h index 766f374902..907c4bc29a 100644 --- a/src/storage/storage_backend.h +++ b/src/storage/storage_backend.h @@ -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); diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c index 78d6b31913..8d0a92a410 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -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; diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c index cd01f933c3..40f4fd83ca 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -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; -- GitLab