All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.7 00/15] block: Lock images when opening
@ 2016-04-13  9:09 Fam Zheng
  2016-04-13  9:09 ` [Qemu-devel] [PATCH for-2.7 01/15] block: Add BDRV_O_NO_LOCK Fam Zheng
                   ` (17 more replies)
  0 siblings, 18 replies; 30+ messages in thread
From: Fam Zheng @ 2016-04-13  9:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Max Reitz, Jeff Cody, Markus Armbruster, Eric Blake,
	John Snow, qemu-block, berrange, pbonzini, den

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(-)

-- 
2.8.0

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2016-04-17 19:16 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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.