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.
/* 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;
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;
}
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)
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;
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;
}
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);
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;
}
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);