All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: Fam Zheng <famz@redhat.com>
Cc: qemu-devel@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	Max Reitz <mreitz@redhat.com>, Jeff Cody <jcody@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Eric Blake <eblake@redhat.com>, John Snow <jsnow@redhat.com>,
	qemu-block@nongnu.org, berrange@redhat.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH for-2.7 00/15] block: Lock images when opening
Date: Thu, 14 Apr 2016 08:04:08 +0300	[thread overview]
Message-ID: <570F24C8.9020501@openvz.org> (raw)
In-Reply-To: <20160414023627.GD31467@ad.usersys.redhat.com>

On 04/14/2016 05:36 AM, Fam Zheng wrote:
> On Wed, 04/13 13:18, Denis V. Lunev wrote:
>> On 04/13/2016 12:09 PM, Fam Zheng wrote:
>>> Too many troubles have been caused by two processes writing to the same image
>>> unexpectedly. This series introduces automatical image locking into QEMU to
>>> avoid such tragedy. With this, the user won't be able to open the image from
>>> two processes (e.g. using qemu-img when the image is attached to the guest).
>>>
>>> Underneath is the fcntl syscall that locks the local file, similar to what is
>>> already used in libvirt virtlockd.  Also because of that, we cannot directly
>>> apply fcntl lock on the image file itself, instead we open and lock
>>> "/var/tmp/.qemu-$sha1.lock", where $sha1 is derived from the image's full path
>>> as in realpath(3). This mechanism should be equally useful for the single host
>>> case, and it doesn't conflict with virtlockd when managed by libvirt.
>>>
>>> The alternative file locking API on Linux, flock(2), cannot protect host NFS
>>> mount points, so it's not used.
>>>
>>> Gluster locking is also implemented wrapping glfs_posix_lock in patch 6. It's
>>> only lightly tested.
>>>
>>> All other drivers that don't implement .bdrv_lockf are always permissive and
>>> does no checking.
>>>
>>> In the future, the intention is that image format drivers that introduce
>>> locking mechanisms could also fit into this API.
>>>
>>> The first 6 patches define the internal and external interfaces, and implement
>>> the image locking.
>>>
>>> Patch 7 adds an option in qemu-io to allow disabling the lock, for testing
>>> purpose.
>>>
>>> Patches 8 - 14 fixes the potential failures of test cases where multiple
>>> processes may open the image concurrently.
>>>
>>> Finally the default behavior is switched to on in patch 15.
>>>
>>> Fam Zheng (15):
>>>    block: Add BDRV_O_NO_LOCK
>>>    qapi: Add lock-image in blockdev-add options
>>>    blockdev: Add and parse "lock-image" option for block devices
>>>    block: Introduce image file locking interface
>>>    raw-posix: Implement .bdrv_lockf
>>>    gluster: Implement .bdrv_lockf
>>>    qemu-io: Add "-L" option for BDRV_O_NO_LOCK
>>>    qemu-iotests: 140: Disable image lock for qemu-io access
>>>    qemu-iotests: 046: Move version detection out from verify_io
>>>    qemu-iotests: Fix lock-image for shared disk in test case 091
>>>    qemu-iotests: Disable image lock when checking test image
>>>    qemu-iotests: 051: Disable image lock in the command line
>>>    ahci-test: Specify "lock-image=off" in CLI
>>>    ide-test: Specify "lock-image=off" in command lines
>>>    block: Turn on image locking by default
>>>
>>>   block.c                       | 25 +++++++++++
>>>   block/gluster.c               | 34 +++++++++++++++
>>>   block/raw-posix.c             | 97 +++++++++++++++++++++++++++++++++++++++++++
>>>   blockdev.c                    |  8 ++++
>>>   include/block/block.h         |  9 ++++
>>>   include/block/block_int.h     |  5 +++
>>>   qapi/block-core.json          |  6 ++-
>>>   qemu-io.c                     | 22 +++++++++-
>>>   tests/ahci-test.c             | 16 +++++--
>>>   tests/ide-test.c              |  5 ++-
>>>   tests/qemu-iotests/030        |  2 +-
>>>   tests/qemu-iotests/046        | 22 +++++-----
>>>   tests/qemu-iotests/051        |  2 +-
>>>   tests/qemu-iotests/051.out    | 10 ++---
>>>   tests/qemu-iotests/051.pc.out | 10 ++---
>>>   tests/qemu-iotests/091        |  4 +-
>>>   tests/qemu-iotests/140        |  2 +-
>>>   17 files changed, 245 insertions(+), 34 deletions(-)
>>>
>> First of all, I like the approach as we have discussed :) Then,
>> in general, I support Daniel with the point that
>> the locking should be done on the image file
>> directly.
>>
>> Also, it looks like this will break migration with the shared storage.
>> For me it seems that we will have lock the image from both ends
> There should already be state handling logic between source and destinition
> ends, I'll take a look and see if we can add lock/unlock calls there to keep it
> working.
>
> Fam
unfortunately no. If the lock will be on the image file,
we will have get it on the target node on QEMU start
and re-acquire it in bdrv_invalidate_cache.

 From my POW you should not get the lock if
BDRV_O_INACTIVE is set.

Den

  reply	other threads:[~2016-04-14  5:18 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-13  9:09 [Qemu-devel] [PATCH for-2.7 00/15] block: Lock images when opening Fam Zheng
2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 01/15] block: Add BDRV_O_NO_LOCK Fam Zheng
2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 02/15] qapi: Add lock-image in blockdev-add options Fam Zheng
2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 03/15] blockdev: Add and parse "lock-image" option for block devices Fam Zheng
2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 04/15] block: Introduce image file locking interface Fam Zheng
2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 05/15] raw-posix: Implement .bdrv_lockf Fam Zheng
2016-04-13  9:21   ` Daniel P. Berrange
2016-04-14  2:24     ` Fam Zheng
2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 06/15] gluster: " Fam Zheng
2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 07/15] qemu-io: Add "-L" option for BDRV_O_NO_LOCK Fam Zheng
2016-04-14  7:06   ` Denis V. Lunev
2016-04-14  8:15     ` Fam Zheng
2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 08/15] qemu-iotests: 140: Disable image lock for qemu-io access Fam Zheng
2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 09/15] qemu-iotests: 046: Move version detection out from verify_io Fam Zheng
2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 10/15] qemu-iotests: Fix lock-image for shared disk in test case 091 Fam Zheng
2016-04-13  9:10 ` [Qemu-devel] [PATCH for-2.7 11/15] qemu-iotests: Disable image lock when checking test image Fam Zheng
2016-04-13  9:10 ` [Qemu-devel] [PATCH for-2.7 12/15] qemu-iotests: 051: Disable image lock in the command line Fam Zheng
2016-04-13  9:10 ` [Qemu-devel] [PATCH for-2.7 13/15] ahci-test: Specify "lock-image=off" in CLI Fam Zheng
2016-04-13  9:10 ` [Qemu-devel] [PATCH for-2.7 14/15] ide-test: Specify "lock-image=off" in command lines Fam Zheng
2016-04-13  9:10 ` [Qemu-devel] [PATCH for-2.7 15/15] block: Turn on image locking by default Fam Zheng
2016-04-13  9:19 ` [Qemu-devel] [PATCH for-2.7 00/15] block: Lock images when opening Daniel P. Berrange
2016-04-14  2:31   ` Fam Zheng
2016-04-13 10:18 ` Denis V. Lunev
2016-04-14  2:36   ` Fam Zheng
2016-04-14  5:04     ` Denis V. Lunev [this message]
2016-04-14  5:46       ` Fam Zheng
2016-04-14  6:14         ` Denis V. Lunev
2016-04-14  6:23           ` Fam Zheng
2016-04-14  6:41             ` Denis V. Lunev
2016-04-17 19:15 ` Richard W.M. Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=570F24C8.9020501@openvz.org \
    --to=den@openvz.org \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.