mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
storage: fs: Only force directory permissions if required
Only set directory permissions at pool build time, if: - User explicitly requested a mode via the XML - The directory needs to be created - We need to do the crazy NFS root-squash workaround This allows qemu:///session to call build on an existing directory like /tmp.
This commit is contained in:
parent
42dd6a993f
commit
db1140f117
@ -766,9 +766,11 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
int err, ret = -1;
|
int ret = -1;
|
||||||
char *parent = NULL;
|
char *parent = NULL;
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
|
mode_t mode;
|
||||||
|
bool needs_create_as_uid, dir_create_flags;
|
||||||
|
|
||||||
virCheckFlags(VIR_STORAGE_POOL_BUILD_OVERWRITE |
|
virCheckFlags(VIR_STORAGE_POOL_BUILD_OVERWRITE |
|
||||||
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, ret);
|
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, ret);
|
||||||
@ -797,20 +799,25 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dir_create_flags = VIR_DIR_CREATE_ALLOW_EXIST;
|
||||||
|
needs_create_as_uid = (pool->def->type == VIR_STORAGE_POOL_NETFS);
|
||||||
|
mode = pool->def->target.perms.mode;
|
||||||
|
|
||||||
|
if (mode == (mode_t) -1 &&
|
||||||
|
(needs_create_as_uid || !virFileExists(pool->def->target.path)))
|
||||||
|
mode = VIR_STORAGE_DEFAULT_POOL_PERM_MODE;
|
||||||
|
if (needs_create_as_uid)
|
||||||
|
flags |= VIR_DIR_CREATE_AS_UID;
|
||||||
|
|
||||||
/* Now create the final dir in the path with the uid/gid/mode
|
/* Now create the final dir in the path with the uid/gid/mode
|
||||||
* requested in the config. If the dir already exists, just set
|
* requested in the config. If the dir already exists, just set
|
||||||
* the perms. */
|
* the perms. */
|
||||||
if ((err = virDirCreate(pool->def->target.path,
|
if (virDirCreate(pool->def->target.path,
|
||||||
(pool->def->target.perms.mode == (mode_t) -1 ?
|
mode,
|
||||||
VIR_STORAGE_DEFAULT_POOL_PERM_MODE :
|
pool->def->target.perms.uid,
|
||||||
pool->def->target.perms.mode),
|
pool->def->target.perms.gid,
|
||||||
pool->def->target.perms.uid,
|
dir_create_flags) < 0)
|
||||||
pool->def->target.perms.gid,
|
|
||||||
VIR_DIR_CREATE_ALLOW_EXIST |
|
|
||||||
(pool->def->type == VIR_STORAGE_POOL_NETFS
|
|
||||||
? VIR_DIR_CREATE_AS_UID : 0))) < 0) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
if (flags != 0) {
|
if (flags != 0) {
|
||||||
ret = virStorageBackendMakeFileSystem(pool, flags);
|
ret = virStorageBackendMakeFileSystem(pool, flags);
|
||||||
|
@ -2311,7 +2311,7 @@ virDirCreateNoFork(const char *path,
|
|||||||
path, (unsigned int) uid, (unsigned int) gid);
|
path, (unsigned int) uid, (unsigned int) gid);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (chmod(path, mode) < 0) {
|
if (mode != (mode_t) -1 && chmod(path, mode) < 0) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("cannot set mode of '%s' to %04o"),
|
_("cannot set mode of '%s' to %04o"),
|
||||||
@ -2424,7 +2424,7 @@ virDirCreate(const char *path,
|
|||||||
path, (unsigned int) gid);
|
path, (unsigned int) gid);
|
||||||
goto childerror;
|
goto childerror;
|
||||||
}
|
}
|
||||||
if (chmod(path, mode) < 0) {
|
if (mode != (mode_t) -1 && chmod(path, mode) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("cannot set mode of '%s' to %04o"),
|
_("cannot set mode of '%s' to %04o"),
|
||||||
path, mode);
|
path, mode);
|
||||||
|
Loading…
Reference in New Issue
Block a user