From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqGzA-0000Xb-Bl for qemu-devel@nongnu.org; Wed, 13 Apr 2016 05:21:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aqGz9-0004gw-8F for qemu-devel@nongnu.org; Wed, 13 Apr 2016 05:21:20 -0400 Date: Wed, 13 Apr 2016 10:21:06 +0100 From: "Daniel P. Berrange" Message-ID: <20160413092106.GD8847@redhat.com> Reply-To: "Daniel P. Berrange" References: <1460538604-12132-1-git-send-email-famz@redhat.com> <1460538604-12132-6-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1460538604-12132-6-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH for-2.7 05/15] raw-posix: Implement .bdrv_lockf List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: qemu-devel@nongnu.org, Kevin Wolf , Max Reitz , Jeff Cody , Markus Armbruster , Eric Blake , John Snow , qemu-block@nongnu.org, pbonzini@redhat.com, den@openvz.org 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 > --- > 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 > @@ -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 :|