mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 23:37:42 +00:00
storage: simplify fd handling
* src/storage/storage_backend.c (virStorageBackendCreateRaw): Use new virFileOperation flag.
This commit is contained in:
parent
3eede281eb
commit
fe303a4256
@ -370,11 +370,16 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
virStorageVolDefPtr inputvol,
|
virStorageVolDefPtr inputvol,
|
||||||
unsigned int flags ATTRIBUTE_UNUSED)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int createstat;
|
int fd = -1;
|
||||||
struct createRawFileOpHookData hdata = { vol, inputvol };
|
struct createRawFileOpHookData hdata = { vol, inputvol };
|
||||||
|
uid_t uid;
|
||||||
|
gid_t gid;
|
||||||
|
int operation_flags;
|
||||||
|
|
||||||
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
if (vol->target.encryption != NULL) {
|
if (vol->target.encryption != NULL) {
|
||||||
virStorageReportError(VIR_ERR_NO_SUPPORT,
|
virStorageReportError(VIR_ERR_NO_SUPPORT,
|
||||||
@ -383,24 +388,31 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
uid_t uid = (vol->target.perms.uid == -1) ? getuid() : vol->target.perms.uid;
|
uid = (vol->target.perms.uid == -1) ? getuid() : vol->target.perms.uid;
|
||||||
gid_t gid = (vol->target.perms.gid == -1) ? getgid() : vol->target.perms.gid;
|
gid = (vol->target.perms.gid == -1) ? getgid() : vol->target.perms.gid;
|
||||||
|
operation_flags = VIR_FILE_OP_FORCE_PERMS | VIR_FILE_OP_RETURN_FD;
|
||||||
|
if (pool->def->type == VIR_STORAGE_POOL_NETFS)
|
||||||
|
operation_flags |= VIR_FILE_OP_AS_UID;
|
||||||
|
|
||||||
if ((createstat = virFileOperation(vol->target.path,
|
if ((fd = virFileOperation(vol->target.path,
|
||||||
O_RDWR | O_CREAT | O_EXCL,
|
O_RDWR | O_CREAT | O_EXCL,
|
||||||
vol->target.perms.mode, uid, gid,
|
vol->target.perms.mode, uid, gid,
|
||||||
createRawFileOpHook, &hdata,
|
NULL, NULL, operation_flags)) < 0) {
|
||||||
VIR_FILE_OP_FORCE_PERMS |
|
virReportSystemError(-fd,
|
||||||
(pool->def->type == VIR_STORAGE_POOL_NETFS
|
_("cannot create path '%s'"),
|
||||||
? VIR_FILE_OP_AS_UID : 0))) < 0) {
|
vol->target.path);
|
||||||
virReportSystemError(-createstat,
|
goto cleanup;
|
||||||
_("cannot create path '%s'"),
|
}
|
||||||
vol->target.path);
|
|
||||||
goto cleanup;
|
if ((ret = createRawFileOpHook(fd, &hdata)) < 0) {
|
||||||
|
virReportSystemError(-fd,
|
||||||
|
_("cannot create path '%s'"),
|
||||||
|
vol->target.path);
|
||||||
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
VIR_FORCE_CLOSE(fd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user