@@ -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,
Signed-off-by: Fam Zheng <famz@redhat.com> --- block/gluster.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)