Skip to content

Commit cfbf637

Browse files
Alex ElderSage Weil
authored andcommitted
rbd: use rwsem to protect header updates
Updating an image header needs to be protected to ensure it's done consistently. However distinct headers can be updated concurrently without a problem. Instead of using the global control lock to serialize headder updates, just rely on the header semaphore. (It's already used, this just moves it out to cover a broader section of the code.) That leaves the control mutex protecting only the creation of rbd clients, so rename it. This resolves: http://tracker.ceph.com/issues/5222 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
1 parent 1ba0f1e commit cfbf637

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ enum rbd_dev_flags {
372372
RBD_DEV_FLAG_REMOVING, /* this mapping is being removed */
373373
};
374374

375-
static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */
375+
static DEFINE_MUTEX(client_mutex); /* Serialize client creation */
376376

377377
static LIST_HEAD(rbd_dev_list); /* devices */
378378
static DEFINE_SPINLOCK(rbd_dev_list_lock);
@@ -516,7 +516,7 @@ static const struct block_device_operations rbd_bd_ops = {
516516

517517
/*
518518
* Initialize an rbd client instance. Success or not, this function
519-
* consumes ceph_opts. Caller holds ctl_mutex.
519+
* consumes ceph_opts. Caller holds client_mutex.
520520
*/
521521
static struct rbd_client *rbd_client_create(struct ceph_options *ceph_opts)
522522
{
@@ -673,13 +673,13 @@ static struct rbd_client *rbd_get_client(struct ceph_options *ceph_opts)
673673
{
674674
struct rbd_client *rbdc;
675675

676-
mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
676+
mutex_lock_nested(&client_mutex, SINGLE_DEPTH_NESTING);
677677
rbdc = rbd_client_find(ceph_opts);
678678
if (rbdc) /* using an existing client */
679679
ceph_destroy_options(ceph_opts);
680680
else
681681
rbdc = rbd_client_create(ceph_opts);
682-
mutex_unlock(&ctl_mutex);
682+
mutex_unlock(&client_mutex);
683683

684684
return rbdc;
685685
}
@@ -833,7 +833,6 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev,
833833

834834
/* We won't fail any more, fill in the header */
835835

836-
down_write(&rbd_dev->header_rwsem);
837836
if (first_time) {
838837
header->object_prefix = object_prefix;
839838
header->obj_order = ondisk->options.order;
@@ -862,8 +861,6 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev,
862861
if (rbd_dev->mapping.size != header->image_size)
863862
rbd_dev->mapping.size = header->image_size;
864863

865-
up_write(&rbd_dev->header_rwsem);
866-
867864
return 0;
868865
out_2big:
869866
ret = -EIO;
@@ -3333,7 +3330,7 @@ static int rbd_dev_refresh(struct rbd_device *rbd_dev)
33333330
int ret;
33343331

33353332
rbd_assert(rbd_image_format_valid(rbd_dev->image_format));
3336-
mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
3333+
down_write(&rbd_dev->header_rwsem);
33373334
mapping_size = rbd_dev->mapping.size;
33383335
if (rbd_dev->image_format == 1)
33393336
ret = rbd_dev_v1_header_info(rbd_dev);
@@ -3343,7 +3340,8 @@ static int rbd_dev_refresh(struct rbd_device *rbd_dev)
33433340
/* If it's a mapped snapshot, validate its EXISTS flag */
33443341

33453342
rbd_exists_validate(rbd_dev);
3346-
mutex_unlock(&ctl_mutex);
3343+
up_write(&rbd_dev->header_rwsem);
3344+
33473345
if (mapping_size != rbd_dev->mapping.size) {
33483346
sector_t size;
33493347

@@ -4272,16 +4270,14 @@ static int rbd_dev_v2_header_info(struct rbd_device *rbd_dev)
42724270
bool first_time = rbd_dev->header.object_prefix == NULL;
42734271
int ret;
42744272

4275-
down_write(&rbd_dev->header_rwsem);
4276-
42774273
ret = rbd_dev_v2_image_size(rbd_dev);
42784274
if (ret)
4279-
goto out;
4275+
return ret;
42804276

42814277
if (first_time) {
42824278
ret = rbd_dev_v2_header_onetime(rbd_dev);
42834279
if (ret)
4284-
goto out;
4280+
return ret;
42854281
}
42864282

42874283
/*
@@ -4296,7 +4292,7 @@ static int rbd_dev_v2_header_info(struct rbd_device *rbd_dev)
42964292

42974293
ret = rbd_dev_v2_parent_info(rbd_dev);
42984294
if (ret)
4299-
goto out;
4295+
return ret;
43004296

43014297
/*
43024298
* Print a warning if this is the initial probe and
@@ -4317,8 +4313,6 @@ static int rbd_dev_v2_header_info(struct rbd_device *rbd_dev)
43174313

43184314
ret = rbd_dev_v2_snap_context(rbd_dev);
43194315
dout("rbd_dev_v2_snap_context returned %d\n", ret);
4320-
out:
4321-
up_write(&rbd_dev->header_rwsem);
43224316

43234317
return ret;
43244318
}

0 commit comments

Comments
 (0)