提交 effbb11e 编写于 作者: J Ján Tomko

Simplify conditions in virStorageBackendProbeTarget

Jump out early if no metadata was detected (for directories).
Join the error and cleanup labels.
上级 febcb89c
...@@ -84,27 +84,27 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, ...@@ -84,27 +84,27 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
fd = rc; fd = rc;
if (virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb, true) < 0) if (virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb, true) < 0)
goto error; goto cleanup;
if (S_ISDIR(sb.st_mode)) { if (S_ISDIR(sb.st_mode)) {
target->format = VIR_STORAGE_FILE_DIR; target->format = VIR_STORAGE_FILE_DIR;
} else { ret = 0;
if (!(meta = virStorageFileGetMetadataFromFD(target->path, goto cleanup;
fd,
VIR_STORAGE_FILE_AUTO,
backingStoreFormat)))
goto error;
if (VIR_STRDUP(*backingStore, meta->backingStoreRaw) < 0)
goto error;
} }
VIR_FORCE_CLOSE(fd); if (!(meta = virStorageFileGetMetadataFromFD(target->path,
fd,
VIR_STORAGE_FILE_AUTO,
backingStoreFormat)))
goto cleanup;
if (VIR_STRDUP(*backingStore, meta->backingStoreRaw) < 0)
goto cleanup;
/* Default to success below this point */ /* Default to success below this point */
ret = 0; ret = 0;
if (meta && *backingStore && if (*backingStore &&
*backingStoreFormat == VIR_STORAGE_FILE_AUTO && *backingStoreFormat == VIR_STORAGE_FILE_AUTO &&
virStorageIsFile(*backingStore)) { virStorageIsFile(*backingStore)) {
if ((rc = virStorageFileProbeFormat(*backingStore, -1, -1)) < 0) { if ((rc = virStorageFileProbeFormat(*backingStore, -1, -1)) < 0) {
...@@ -120,10 +120,10 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, ...@@ -120,10 +120,10 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
} }
} }
if (meta && meta->capacity) if (meta->capacity)
target->capacity = meta->capacity; target->capacity = meta->capacity;
if (encryption && meta && meta->encryption) { if (encryption && meta->encryption) {
*encryption = meta->encryption; *encryption = meta->encryption;
meta->encryption = NULL; meta->encryption = NULL;
...@@ -144,23 +144,17 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, ...@@ -144,23 +144,17 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
} }
virBitmapFree(target->features); virBitmapFree(target->features);
if (meta) { target->features = meta->features;
target->features = meta->features; meta->features = NULL;
meta->features = NULL;
}
if (meta && meta->compat) { if (meta->compat) {
VIR_FREE(target->compat); VIR_FREE(target->compat);
target->compat = meta->compat; target->compat = meta->compat;
meta->compat = NULL; meta->compat = NULL;
} }
goto cleanup;
error:
VIR_FORCE_CLOSE(fd);
cleanup: cleanup:
VIR_FORCE_CLOSE(fd);
virStorageSourceFree(meta); virStorageSourceFree(meta);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册