mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
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.
This commit is contained in:
parent
5086f85cc1
commit
e40a285bb7
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
if (virStorageBackendDetectBlockVolFormatFD(target, fd) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
bytes = saferead(fd, buffer, sizeof(buffer));
|
||||
if (bytes < 0) {
|
||||
virReportSystemError(errno,
|
||||
_("cannot read beginning of file '%s'"),
|
||||
target->path);
|
||||
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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user