Message ID | 1460690887-32751-7-git-send-email-famz@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Fri, Apr 15, 2016 at 11:27:56AM +0800, Fam Zheng wrote: > Signed-off-by: Fam Zheng <famz@redhat.com> > --- > block/gluster.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) The Gluster changes look good to me. Reviewed-by: Niels de Vos <ndevos@redhat.com> > > diff --git a/block/gluster.c b/block/gluster.c > index 51e154c..c23e944 100644 > --- a/block/gluster.c > +++ b/block/gluster.c > @@ -672,6 +672,32 @@ static void qemu_gluster_close(BlockDriverState *bs) > glfs_fini(s->glfs); > } > > +static int qemu_gluster_lockf(BlockDriverState *bs, BdrvLockfCmd cmd) > +{ > + 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); > + 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 +739,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 +767,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 +795,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 +823,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 > >
diff --git a/block/gluster.c b/block/gluster.c index 51e154c..c23e944 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -672,6 +672,32 @@ static void qemu_gluster_close(BlockDriverState *bs) glfs_fini(s->glfs); } +static int qemu_gluster_lockf(BlockDriverState *bs, BdrvLockfCmd cmd) +{ + 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); + 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 +739,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 +767,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 +795,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 +823,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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)