Skip to content

Commit

Permalink
Merge remote branch 'origin/wip-librbd-locking'
Browse files Browse the repository at this point in the history
Conflicts:
	qa/workunits/rbd/copy.sh

Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
jdurgin committed Sep 18, 2012
2 parents 55673ba + 0cfac6d commit f530659
Show file tree
Hide file tree
Showing 29 changed files with 1,193 additions and 720 deletions.
33 changes: 33 additions & 0 deletions doc/man/8/rbd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ Parameters
to use with the map command. If not specified, the default keyring
locations will be searched.

.. option:: --shared tag

Option for `lock add` that allows multiple clients to lock the
same image if they use the same tag. The tag is an arbitrary
string. This is useful for situations where an image must
be open from more than one client at once, like during
live migration of a virtual machine, or for use underneath
a clustered filesystem.


Commands
========
Expand Down Expand Up @@ -182,6 +191,22 @@ Commands
:command:`showmapped`
Show the rbd images that are mapped via the rbd kernel module.

:command:`lock` list [*image-name*]
Show locks held on the image. The first column is the locker
to use with the `lock remove` command.

:command:`lock` add [*image-name*] [*lock-id*]
Lock an image. The lock-id is an arbitrary name for the user's
convenience. By default, this is an exclusive lock, meaning it
will fail if the image is already locked. The --shared option
changes this behavior. Note that locking does not affect
any operation other than adding a lock. It does not
protect an image from being deleted.

:command:`lock` remove [*image-name*] [*lock-id*] [*locker*]
Release a lock on an image. The lock id and locker are
as output by lock ls.

Image name
==========

Expand Down Expand Up @@ -250,6 +275,14 @@ import it as the desired format::
rbd export mypool/myimage@snap /tmp/img
rbd import --format 2 /tmp/img mypool/myimage2

To lock an image for exclusive use::

rbd lock add mypool/myimage mylockid

To release a lock::

rbd lock remove mypool/myimage mylockid client.2485


Availability
============
Expand Down
44 changes: 43 additions & 1 deletion man/rbd.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "RBD" "8" "August 29, 2012" "dev" "Ceph"
.TH "RBD" "8" "September 07, 2012" "dev" "Ceph"
.SH NAME
rbd \- manage rados block device (RBD) images
.
Expand Down Expand Up @@ -111,6 +111,16 @@ Specifies a keyring file containing a secret for the specified user
to use with the map command. If not specified, the default keyring
locations will be searched.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-shared tag
Option for \fIlock add\fP that allows multiple clients to lock the
same image if they use the same tag. The tag is an arbitrary
string. This is useful for situations where an image must
be open from more than one client at once, like during
live migration of a virtual machine, or for use underneath
a clustered filesystem.
.UNINDENT
.SH COMMANDS
.INDENT 0.0
.TP
Expand Down Expand Up @@ -207,6 +217,22 @@ Unmaps the block device that was mapped via the rbd kernel module.
.TP
.B \fBshowmapped\fP
Show the rbd images that are mapped via the rbd kernel module.
.TP
.B \fBlock\fP list [\fIimage\-name\fP]
Show locks held on the image. The first column is the locker
to use with the \fIlock remove\fP command.
.TP
.B \fBlock\fP add [\fIimage\-name\fP] [\fIlock\-id\fP]
Lock an image. The lock\-id is an arbitrary name for the user\(aqs
convenience. By default, this is an exclusive lock, meaning it
will fail if the image is already locked. The \-\-shared option
changes this behavior. Note that locking does not affect
any operation other than adding a lock. It does not
protect an image from being deleted.
.TP
.B \fBlock\fP remove [\fIimage\-name\fP] [\fIlock\-id\fP] [\fIlocker\fP]
Release a lock on an image. The lock id and locker are
as output by lock ls.
.UNINDENT
.SH IMAGE NAME
.sp
Expand Down Expand Up @@ -323,6 +349,22 @@ rbd export mypool/myimage@snap /tmp/img
rbd import \-\-format 2 /tmp/img mypool/myimage2
.ft P
.fi
.sp
To lock an image for exclusive use:
.sp
.nf
.ft C
rbd lock add mypool/myimage mylockid
.ft P
.fi
.sp
To release a lock:
.sp
.nf
.ft C
rbd lock remove mypool/myimage mylockid client.2485
.ft P
.fi
.SH AVAILABILITY
.sp
\fBrbd\fP is part of the Ceph distributed file system. Please refer to
Expand Down
33 changes: 29 additions & 4 deletions qa/workunits/rbd/copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ test_remove() {
rbd ls | wc -l | grep "^0$"
}

test_locking() {
echo "testing locking..."
remove_images

rbd create -s 1 test1
rbd lock list test1 | wc -l | grep '^0$'
rbd lock add test1 id
rbd lock list test1 | grep ' 1 '
LOCKER=$(rbd lock list test1 | tail -n 1 | cut -f 1)
rbd lock remove test1 id $LOCKER
rbd lock list test1 | wc -l | grep '^0$'

rbd lock add test1 id --shared tag
rbd lock list test1 | grep ' 1 '
rbd lock add test1 id --shared tag
rbd lock list test1 | grep ' 2 '
rbd lock add test1 id2 --shared tag
rbd lock list test1 | grep ' 3 '
LOCKER=$(rbd lock list test1 | tail -n 1 | cut -f 1)
ID=$(rbd lock list test1 | tail -n 1 | cut -f 2)
rbd lock remove test1 $ID $LOCKER
# locks don't prevent you from removing an image,
# just from taking a lock
rbd rm test1
}

test_pool_image_args() {
echo "testing pool and image args..."
remove_images
Expand Down Expand Up @@ -198,10 +224,9 @@ test_ls
test_remove
RBD_CREATE_ARGS=""
test_others
# wait for watch to timeout so we can remove old images
# TODO: remove this once #2476 is fixed
sleep 30
RBD_CREATE_ARGS="--new-format"
test_locking
RBD_CREATE_ARGS="--format 2"
test_others
test_locking

echo OK
10 changes: 8 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ librbd_la_SOURCES = \
librbd/internal.cc \
librbd/LibrbdWriteback.cc \
librbd/WatchCtx.cc \
osdc/ObjectCacher.cc
osdc/ObjectCacher.cc \
cls/lock/cls_lock_client.cc \
cls/lock/cls_lock_types.cc \
cls/lock/cls_lock_ops.cc
librbd_la_CFLAGS = ${AM_CFLAGS}
librbd_la_CXXFLAGS = ${AM_CXXFLAGS}
librbd_la_LIBADD = librados.la
Expand Down Expand Up @@ -773,7 +776,10 @@ bin_DEBUGPROGRAMS += test_librbd_fsx

test_cls_rbd_SOURCES = test/rbd/test_cls_rbd.cc \
test/rados-api/test.cc \
librbd/cls_rbd_client.cc
librbd/cls_rbd_client.cc \
cls/lock/cls_lock_client.cc \
cls/lock/cls_lock_types.cc \
cls/lock/cls_lock_ops.cc
test_cls_rbd_LDADD = librados.la ${UNITTEST_STATIC_LDADD}
test_cls_rbd_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
bin_DEBUGPROGRAMS += test_cls_rbd
Expand Down
7 changes: 4 additions & 3 deletions src/cls/lock/cls_lock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ static int break_lock(cls_method_context_t hctx,
}


/**
/**
* Retrieve lock info: lockers, tag, exclusive
*
* Input:
Expand Down Expand Up @@ -400,7 +400,7 @@ static int get_info(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
}


/**
/**
* Retrieve a list of locks for this object
*
* Input:
Expand All @@ -410,7 +410,8 @@ static int get_info(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
* @param out contains encoded cls_list_locks_reply
*
* @return 0 on success, -errno on failure.
*/static int list_locks(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
*/
static int list_locks(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
{
CLS_LOG(20, "list_locks");

Expand Down
Loading

0 comments on commit f530659

Please sign in to comment.