if (virCommandRun(cmd, NULL) == 0) {
/* command was successfully run, check if the file was created */
- if (stat(vol->target.path, &st) >= 0)
+ if (stat(vol->target.path, &st) >= 0) {
filecreated = true;
+
+ /* seems qemu-img disregards umask and open/creates using 0644.
+ * If that doesn't match what we expect, then let's try to
+ * re-open the file and attempt to force the mode change.
+ */
+ if (mode != (st.st_mode & S_IRWXUGO)) {
+ int fd = -1;
+ int flags = VIR_FILE_OPEN_FORK | VIR_FILE_OPEN_FORCE_MODE;
+
+ if ((fd = virFileOpenAs(vol->target.path, O_RDWR, mode,
+ vol->target.perms->uid,
+ vol->target.perms->gid,
+ flags)) >= 0) {
+ /* Success - means we're good */
+ VIR_FORCE_CLOSE(fd);
+ ret = 0;
+ goto cleanup;
+ }
+ }
+ }
}
}