]> git.proxmox.com Git - mirror_qemu.git/commit
file-posix: Skip effectiveless OFD lock operations
authorFam Zheng <famz@redhat.com>
Thu, 11 Oct 2018 07:21:33 +0000 (15:21 +0800)
committerKevin Wolf <kwolf@redhat.com>
Mon, 12 Nov 2018 16:46:57 +0000 (17:46 +0100)
commit2996ffad3acabe890fbb4f84a069cdc325a68108
treef26d0eccb1316859f48e5a15508b7caa9d1e3ade
parenta883d6a0bcbff889c932015179a25a1b5ea8e096
file-posix: Skip effectiveless OFD lock operations

If we know we've already locked the bytes, don't do it again; similarly
don't unlock a byte if we haven't locked it. This doesn't change the
behavior, but fixes a corner case explained below.

Libvirt had an error handling bug that an image can get its (ownership,
file mode, SELinux) permissions changed (RHBZ 1584982) by mistake behind
QEMU. Specifically, an image in use by Libvirt VM has:

    $ ls -lhZ b.img
    -rw-r--r--. qemu qemu system_u:object_r:svirt_image_t:s0:c600,c690 b.img

Trying to attach it a second time won't work because of image locking.
And after the error, it becomes:

    $ ls -lhZ b.img
    -rw-r--r--. root root system_u:object_r:virt_image_t:s0 b.img

Then, we won't be able to do OFD lock operations with the existing fd.
In other words, the code such as in blk_detach_dev:

    blk_set_perm(blk, 0, BLK_PERM_ALL, &error_abort);

can abort() QEMU, out of environmental changes.

This patch is an easy fix to this and the change is regardlessly
reasonable, so do it.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/file-posix.c