[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH for-2.7 06/15] gluster: Implement .bdrv_lockf
From: |
Fam Zheng |
Subject: |
[Qemu-devel] [PATCH for-2.7 06/15] gluster: Implement .bdrv_lockf |
Date: |
Wed, 13 Apr 2016 17:09:55 +0800 |
Signed-off-by: Fam Zheng <address@hidden>
---
block/gluster.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/block/gluster.c b/block/gluster.c
index 51e154c..e76ec87 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -672,6 +672,36 @@ static void qemu_gluster_close(BlockDriverState *bs)
glfs_fini(s->glfs);
}
+static int qemu_gluster_lockf(BlockDriverState *bs, BdrvLockfCmd cmd,
+ Error **errp)
+{
+ BDRVGlusterState *s = bs->opaque;
+ int ret;
+ struct flock fl = (struct flock) {
+ .l_start = 0,
+ .l_whence = SEEK_SET,
+ .l_len = 0,
+ };
+ switch (cmd) {
+ case BDRV_LOCKF_RWLOCK:
+ fl.l_type = F_WRLCK;
+ break;
+ case BDRV_LOCKF_ROLOCK:
+ fl.l_type = F_RDLCK;
+ break;
+ case BDRV_LOCKF_UNLOCK:
+ fl.l_type = F_UNLCK;
+ break;
+ default:
+ abort();
+ }
+ ret = glfs_posix_lock(s->fd, F_SETLK, &fl);
+ if (ret == -1) {
+ error_setg_errno(errp, errno, "Failed to lock image");
+ }
+ return ret == -1 ? -errno : 0;
+}
+
static int qemu_gluster_has_zero_init(BlockDriverState *bs)
{
/* GlusterFS volume could be backed by a block device */
@@ -713,6 +743,7 @@ static BlockDriver bdrv_gluster = {
.bdrv_co_readv = qemu_gluster_co_readv,
.bdrv_co_writev = qemu_gluster_co_writev,
.bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk,
+ .bdrv_lockf = qemu_gluster_lockf,
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_co_discard = qemu_gluster_co_discard,
@@ -740,6 +771,7 @@ static BlockDriver bdrv_gluster_tcp = {
.bdrv_co_readv = qemu_gluster_co_readv,
.bdrv_co_writev = qemu_gluster_co_writev,
.bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk,
+ .bdrv_lockf = qemu_gluster_lockf,
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_co_discard = qemu_gluster_co_discard,
@@ -767,6 +799,7 @@ static BlockDriver bdrv_gluster_unix = {
.bdrv_co_readv = qemu_gluster_co_readv,
.bdrv_co_writev = qemu_gluster_co_writev,
.bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk,
+ .bdrv_lockf = qemu_gluster_lockf,
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_co_discard = qemu_gluster_co_discard,
@@ -794,6 +827,7 @@ static BlockDriver bdrv_gluster_rdma = {
.bdrv_co_readv = qemu_gluster_co_readv,
.bdrv_co_writev = qemu_gluster_co_writev,
.bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk,
+ .bdrv_lockf = qemu_gluster_lockf,
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_co_discard = qemu_gluster_co_discard,
--
2.8.0
- [Qemu-devel] [PATCH for-2.7 01/15] block: Add BDRV_O_NO_LOCK, (continued)
- [Qemu-devel] [PATCH for-2.7 01/15] block: Add BDRV_O_NO_LOCK, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 02/15] qapi: Add lock-image in blockdev-add options, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 03/15] blockdev: Add and parse "lock-image" option for block devices, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 04/15] block: Introduce image file locking interface, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 05/15] raw-posix: Implement .bdrv_lockf, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 07/15] qemu-io: Add "-L" option for BDRV_O_NO_LOCK, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 06/15] gluster: Implement .bdrv_lockf,
Fam Zheng <=
- [Qemu-devel] [PATCH for-2.7 08/15] qemu-iotests: 140: Disable image lock for qemu-io access, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 09/15] qemu-iotests: 046: Move version detection out from verify_io, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 11/15] qemu-iotests: Disable image lock when checking test image, Fam Zheng, 2016/04/13
- [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
- [Qemu-devel] [PATCH for-2.7 13/15] ahci-test: Specify "lock-image=off" in CLI, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 15/15] block: Turn on image locking by default, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 12/15] qemu-iotests: 051: Disable image lock in the command line, Fam Zheng, 2016/04/13
- [Qemu-devel] [PATCH for-2.7 14/15] ide-test: Specify "lock-image=off" in command lines, Fam Zheng, 2016/04/13
- Re: [Qemu-devel] [PATCH for-2.7 00/15] block: Lock images when opening, Daniel P. Berrange, 2016/04/13