From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqWxG-0007ew-DT for qemu-devel@nongnu.org; Wed, 13 Apr 2016 22:24:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aqWxF-0003Zc-KH for qemu-devel@nongnu.org; Wed, 13 Apr 2016 22:24:26 -0400 Date: Thu, 14 Apr 2016 10:24:18 +0800 From: Fam Zheng Message-ID: <20160414022418.GB31467@ad.usersys.redhat.com> References: <1460538604-12132-1-git-send-email-famz@redhat.com> <1460538604-12132-6-git-send-email-famz@redhat.com> <20160413092106.GD8847@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160413092106.GD8847@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: "Daniel P. Berrange" 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, 04/13 10:21, Daniel P. Berrange wrote: > 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. That's brillent, thanks a lot! Fam