[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2/5] block: implemented bdrv_lock_image for raw
From: |
Daniel P. Berrange |
Subject: |
Re: [Qemu-devel] [PATCH 2/5] block: implemented bdrv_lock_image for raw file |
Date: |
Wed, 23 Dec 2015 12:40:36 +0000 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
On Wed, Dec 23, 2015 at 10:46:53AM +0300, Denis V. Lunev wrote:
> From: Olga Krishtal <address@hidden>
>
> To lock the image file flock (LockFileEx) is used.
> We lock file handle/descriptor. If lock is failed -
> an error is returned.
>
> In win32 realization we can lock reagion of bytes within the file.
> For this reason we at first have to get file size and only than lock it.
>
> Signed-off-by: Olga Krishtal <address@hidden>
> Signed-off-by: Denis V. Lunev <address@hidden>
> CC: Kevin Wolf <address@hidden>
> CC: Max Reitz <address@hidden>
> CC: Eric Blake <address@hidden>
> CC: Fam Zheng <address@hidden>
> ---
> block/raw-posix.c | 15 +++++++++++++++
> block/raw-win32.c | 19 +++++++++++++++++++
> 2 files changed, 34 insertions(+)
>
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index 076d070..6226a5c 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -33,6 +33,7 @@
> #include "raw-aio.h"
> #include "qapi/util.h"
> #include "qapi/qmp/qstring.h"
> +#include <sys/file.h>
>
> #if defined(__APPLE__) && (__MACH__)
> #include <paths.h>
> @@ -576,6 +577,19 @@ fail:
> return ret;
> }
>
> +static int raw_lock_image(BlockDriverState *bs, BdrvLockImage lock)
> +{
> + int ret;
> + if (lock != BDRV_LOCK_IMAGE_LOCKFILE) {
> + return -ENOTSUP;
> + }
> + ret = flock(((BDRVRawState *)(bs->opaque))->fd, LOCK_EX|LOCK_NB);
> + if (ret != 0) {
> + return -ret;
> + }
> + return ret;
> +}
flock() is a pretty bad choice wrt to NFS. Historically it was often
a no-op. Some impls treat it as a client-local lock and not a server
side lock. Linux apparently now converts flock locks to fcntl locks,
but on NFS only. As a result they'll suffer from the problem that
a close() on any file descriptor pointing to the file will release
the lock. So IMHO both flock() and fcntl() are unusable in practice
from within QEMU, as I don't think it is practical to guarantee
QEMU won't accidentally release the lock by closing another file
descriptor pointing to the same file. If you want to use flock or
fcntl() and provide a strong safety guarantee the only option is to
acquire the locks in a dedicated process prior to giving QEMU access
to the files, which is what libvirt does with its virtlockd daemon.
Regards,
Daniel
[1] http://0pointer.de/blog/projects/locking.html
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
- [Qemu-devel] [PATCH 08/10] qcow2: Fix BDRV_O_INCOMING handling in qcow2_invalidate_cache(), (continued)
- [Qemu-devel] [PATCH 08/10] qcow2: Fix BDRV_O_INCOMING handling in qcow2_invalidate_cache(), Kevin Wolf, 2015/12/22
- [Qemu-devel] [PATCH 09/10] qcow2: Make image inaccessible after failed qcow2_invalidate_cache(), Kevin Wolf, 2015/12/22
- [Qemu-devel] [PATCH 10/10] qcow2: Add image locking, Kevin Wolf, 2015/12/22
- Re: [Qemu-devel] [PATCH 00/10] qcow2: Implement image locking, Fam Zheng, 2015/12/22
- [Qemu-devel] [PATCH 3/5] block: added check image option and callback bdrv_is_opened_unclean, Denis V. Lunev, 2015/12/23
- Re: [Qemu-devel] [PATCH 3/5] block: added check image option and callback bdrv_is_opened_unclean, Fam Zheng, 2015/12/23
- Re: [Qemu-devel] [PATCH 3/5] block: added check image option and callback bdrv_is_opened_unclean, Denis V. Lunev, 2015/12/23
- [Qemu-devel] [PATCH 4/5] qcow2: implemented bdrv_is_opened_unclean, Denis V. Lunev, 2015/12/23
- [Qemu-devel] [PATCH 5/5] block/paralels: added paralles implementation for bdrv_is_opened_unclean, Denis V. Lunev, 2015/12/23
- Re: [Qemu-devel] [PATCH RFC 0/5] generic image locking and crash recovery, Fam Zheng, 2015/12/23
- Re: [Qemu-devel] [PATCH RFC 0/5] generic image locking and crash recovery, Denis V. Lunev, 2015/12/23
Re: [Qemu-devel] [PATCH 00/10] qcow2: Implement image locking, Daniel P. Berrange, 2015/12/23