mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemu: Use storage driver APIs in qemuDomainBlockPeek
Refactor the access to storage driver usage along with qemuDomainStorageFileInit which ensures that we access the file with correct DAC uid/gid.
This commit is contained in:
parent
204f373a91
commit
3956af495e
@ -11309,9 +11309,9 @@ qemuDomainBlockPeek(virDomainPtr dom,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virQEMUDriverPtr driver = dom->conn->privateData;
|
virQEMUDriverPtr driver = dom->conn->privateData;
|
||||||
|
virDomainDiskDefPtr disk = NULL;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
int fd = -1, ret = -1;
|
int ret = -1;
|
||||||
const char *actual;
|
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
@ -11322,32 +11322,23 @@ qemuDomainBlockPeek(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Check the path belongs to this domain. */
|
/* Check the path belongs to this domain. */
|
||||||
if (!(actual = virDomainDiskPathByName(vm->def, path))) {
|
if (!(disk = virDomainDiskByName(vm->def, path, true))) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
_("invalid path '%s'"), path);
|
_("invalid disk or path '%s'"), path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
path = actual;
|
|
||||||
|
|
||||||
fd = qemuOpenFile(driver, vm, path, O_RDONLY, NULL, NULL);
|
if (qemuDomainStorageFileInit(driver, vm, disk->src) < 0)
|
||||||
if (fd < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Seek and read. */
|
if (virStorageFileRead(disk->src, offset, size, buffer) < 0)
|
||||||
/* NB. Because we configure with AC_SYS_LARGEFILE, off_t should
|
|
||||||
* be 64 bits on all platforms.
|
|
||||||
*/
|
|
||||||
if (lseek(fd, offset, SEEK_SET) == (off_t) -1 ||
|
|
||||||
saferead(fd, buffer, size) == (ssize_t) -1) {
|
|
||||||
virReportSystemError(errno,
|
|
||||||
_("%s: failed to seek or read"), path);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FORCE_CLOSE(fd);
|
if (disk)
|
||||||
|
virStorageFileDeinit(disk->src);
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user