On Wed, Apr 13, 2016 at 05:09:54PM +0800, Fam Zheng wrote: > Because virtlockd in libvirt already uses the fcntl lock on the image file, we > have to workaround this by locking a digest-mapped temporary file. > > Signed-off-by: Fam Zheng <f...@redhat.com> > --- > block/raw-posix.c | 97 > +++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 97 insertions(+) > > diff --git a/block/raw-posix.c b/block/raw-posix.c > index 906d5c9..277f20d 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -35,6 +35,7 @@ > #include "raw-aio.h" > #include "qapi/util.h" > #include "qapi/qmp/qstring.h" > +#include "glib.h" > > #if defined(__APPLE__) && (__MACH__) > #include <paths.h> > @@ -149,6 +150,9 @@ typedef struct BDRVRawState { > bool discard_zeroes:1; > bool has_fallocate; > bool needs_alignment; > + bool image_locked; > + int lock_file_fd; > + char *lock_file_name; > } BDRVRawState; > > typedef struct BDRVRawReopenState { > @@ -397,6 +401,87 @@ static void raw_attach_aio_context(BlockDriverState *bs, > #endif > } > > +static int raw_do_lockf(int fd, BdrvLockfCmd cmd) > +{ > + int ret; > + struct flock fl = (struct flock) { > + .l_start = 0, > + .l_whence = SEEK_SET, > + .l_len = 0, > + };
If you change this to .l_start = 1, .l_len = 1, then you would be telling a selective lock at byte 1 which would not interfere with anything virtlockd currently does, and also leave the other bytes unlocked for future use by QEMU or libvirt as needed. Regards, Daniel -- |: 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 :|