提交 d5aa75e6 编写于 作者: J John Ferlan

storage: Rework ret logic in storageBackendUpdateVolTargetInfo

Rather than overload @ret with trying serve multiple purposes,
let's initialize @ret to -1 and introduce an @rc function return
value that can be used for functions that may return -1 or -2
and only override @ret when rc < 0.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 821dd6d8
......@@ -1754,24 +1754,26 @@ storageBackendUpdateVolTargetInfo(virStorageVolType voltype,
unsigned int openflags,
unsigned int readflags)
{
int ret, fd = -1;
int ret = -1;
int rc;
int fd = -1;
struct stat sb;
ssize_t len = VIR_STORAGE_MAX_HEADER;
VIR_AUTOFREE(char *) buf = NULL;
if ((ret = virStorageBackendVolOpen(target->path, &sb, openflags)) < 0)
goto cleanup;
fd = ret;
if ((rc = virStorageBackendVolOpen(target->path, &sb, openflags)) < 0)
return rc;
fd = rc;
if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0)
if ((virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0)
goto cleanup;
if ((voltype == VIR_STORAGE_VOL_FILE || voltype == VIR_STORAGE_VOL_BLOCK) &&
target->format != VIR_STORAGE_FILE_NONE) {
if (S_ISDIR(sb.st_mode)) {
if (storageBackendIsPloopDir(target->path)) {
if ((ret = storageBackendRedoPloopUpdate(target, &sb, &fd,
openflags)) < 0)
if ((storageBackendRedoPloopUpdate(target, &sb, &fd,
openflags)) < 0)
goto cleanup;
target->format = VIR_STORAGE_FILE_PLOOP;
} else {
......@@ -1782,7 +1784,6 @@ storageBackendUpdateVolTargetInfo(virStorageVolType voltype,
if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
virReportSystemError(errno, _("cannot seek to start of '%s'"), target->path);
ret = -1;
goto cleanup;
}
......@@ -1795,23 +1796,24 @@ storageBackendUpdateVolTargetInfo(virStorageVolType voltype,
virReportSystemError(errno,
_("cannot read header '%s'"),
target->path);
ret = -1;
}
goto cleanup;
}
if (virStorageSourceUpdateCapacity(target, buf, len, false) < 0) {
ret = -1;
if (virStorageSourceUpdateCapacity(target, buf, len, false) < 0)
goto cleanup;
}
}
if (withBlockVolFormat) {
if ((ret = virStorageBackendDetectBlockVolFormatFD(target, fd,
readflags)) < 0)
if ((rc = virStorageBackendDetectBlockVolFormatFD(target, fd,
readflags)) < 0) {
ret = rc;
goto cleanup;
}
}
ret = 0;
cleanup:
VIR_FORCE_CLOSE(fd);
return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册