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.
v2: Rebased around other storage changes
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
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 7df61cd..f4124df 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 766f374..907c4bc 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 78d6b31..8d0a92a 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 cd01f93..40f4fd8 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;
--
1.6.6.1