Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 373502
b: refs/heads/master
c: 468521c
h: refs/heads/master
v: v3
  • Loading branch information
Alex Elder authored and Sage Weil committed May 2, 2013
1 parent 5323fca commit b3dbe55
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c0cd10db4685a76397f32bed246e861705642576
refs/heads/master: 468521c1b1450d8e9bda22df9455deaa4feed00f
65 changes: 39 additions & 26 deletions trunk/drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,35 @@ static void rbd_client_release(struct kref *kref)
kfree(rbdc);
}

/* Caller has to fill in snapc->seq and snapc->snaps[0..snap_count-1] */

static struct ceph_snap_context *rbd_snap_context_create(u32 snap_count)
{
struct ceph_snap_context *snapc;
size_t size;

size = sizeof (struct ceph_snap_context);
size += snap_count * sizeof (snapc->snaps[0]);
snapc = kzalloc(size, GFP_KERNEL);
if (!snapc)
return NULL;

atomic_set(&snapc->nref, 1);
snapc->num_snaps = snap_count;

return snapc;
}

static inline void rbd_snap_context_get(struct ceph_snap_context *snapc)
{
(void)ceph_get_snap_context(snapc);
}

static inline void rbd_snap_context_put(struct ceph_snap_context *snapc)
{
ceph_put_snap_context(snapc);
}

/*
* Drop reference to ceph client node. If it's not referenced anymore, release
* it.
Expand Down Expand Up @@ -789,18 +818,13 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
/* Allocate and fill in the snapshot context */

header->image_size = le64_to_cpu(ondisk->image_size);
size = sizeof (struct ceph_snap_context);
size += snap_count * sizeof (header->snapc->snaps[0]);
header->snapc = kzalloc(size, GFP_KERNEL);

header->snapc = rbd_snap_context_create(snap_count);
if (!header->snapc)
goto out_err;

atomic_set(&header->snapc->nref, 1);
header->snapc->seq = le64_to_cpu(ondisk->snap_seq);
header->snapc->num_snaps = snap_count;
for (i = 0; i < snap_count; i++)
header->snapc->snaps[i] =
le64_to_cpu(ondisk->snaps[i].id);
header->snapc->snaps[i] = le64_to_cpu(ondisk->snaps[i].id);

return 0;

Expand Down Expand Up @@ -870,7 +894,7 @@ static void rbd_header_free(struct rbd_image_header *header)
header->snap_sizes = NULL;
kfree(header->snap_names);
header->snap_names = NULL;
ceph_put_snap_context(header->snapc);
rbd_snap_context_put(header->snapc);
header->snapc = NULL;
}

Expand Down Expand Up @@ -1720,21 +1744,15 @@ static struct rbd_img_request *rbd_img_request_create(
bool child_request)
{
struct rbd_img_request *img_request;
struct ceph_snap_context *snapc = NULL;

img_request = kmalloc(sizeof (*img_request), GFP_ATOMIC);
if (!img_request)
return NULL;

if (write_request) {
down_read(&rbd_dev->header_rwsem);
snapc = ceph_get_snap_context(rbd_dev->header.snapc);
rbd_snap_context_get(rbd_dev->header.snapc);
up_read(&rbd_dev->header_rwsem);
if (WARN_ON(!snapc)) {
kfree(img_request);
return NULL; /* Shouldn't happen */
}

}

img_request->rq = NULL;
Expand All @@ -1744,7 +1762,7 @@ static struct rbd_img_request *rbd_img_request_create(
img_request->flags = 0;
if (write_request) {
img_request_write_set(img_request);
img_request->snapc = snapc;
img_request->snapc = rbd_dev->header.snapc;
} else {
img_request->snap_id = rbd_dev->spec->snap_id;
}
Expand Down Expand Up @@ -1785,7 +1803,7 @@ static void rbd_img_request_destroy(struct kref *kref)
rbd_assert(img_request->obj_request_count == 0);

if (img_request_write_test(img_request))
ceph_put_snap_context(img_request->snapc);
rbd_snap_context_put(img_request->snapc);

if (img_request_child_test(img_request))
rbd_obj_request_put(img_request->obj_request);
Expand Down Expand Up @@ -3049,7 +3067,7 @@ static int rbd_dev_v1_refresh(struct rbd_device *rbd_dev, u64 *hver)
kfree(rbd_dev->header.snap_sizes);
kfree(rbd_dev->header.snap_names);
/* osd requests may still refer to snapc */
ceph_put_snap_context(rbd_dev->header.snapc);
rbd_snap_context_put(rbd_dev->header.snapc);

if (hver)
*hver = h.obj_version;
Expand Down Expand Up @@ -3889,19 +3907,14 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev, u64 *ver)
}
if (!ceph_has_room(&p, end, snap_count * sizeof (__le64)))
goto out;
ret = 0;

size = sizeof (struct ceph_snap_context) +
snap_count * sizeof (snapc->snaps[0]);
snapc = kmalloc(size, GFP_KERNEL);
snapc = rbd_snap_context_create(snap_count);
if (!snapc) {
ret = -ENOMEM;
goto out;
}
ret = 0;

atomic_set(&snapc->nref, 1);
snapc->seq = seq;
snapc->num_snaps = snap_count;
for (i = 0; i < snap_count; i++)
snapc->snaps[i] = ceph_decode_64(&p);

Expand Down

0 comments on commit b3dbe55

Please sign in to comment.