Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 331630
b: refs/heads/master
c: 6a52325
h: refs/heads/master
v: v3
  • Loading branch information
Alex Elder committed Oct 1, 2012
1 parent b0b28d2 commit d94d2b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 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: d2bb24e506596ad0c10e4a7f4b2fca88cc75c0bc
refs/heads/master: 6a52325f61760c6a7d7f3ea9736029bc9f63e7f3
41 changes: 22 additions & 19 deletions trunk/drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,46 +506,51 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
if (snap_count > size / sizeof (header->snapc->snaps[0]))
return -EINVAL;

size = sizeof (struct ceph_snap_context);
size += snap_count * sizeof (header->snapc->snaps[0]);
header->snapc = kmalloc(size, GFP_KERNEL);
if (!header->snapc)
memset(header, 0, sizeof (*header));

size = sizeof (ondisk->block_name) + 1;
header->object_prefix = kmalloc(size, GFP_KERNEL);
if (!header->object_prefix)
return -ENOMEM;
memcpy(header->object_prefix, ondisk->block_name, size - 1);
header->object_prefix[size - 1] = '\0';

if (snap_count) {
header->snap_names_len = le64_to_cpu(ondisk->snap_names_len);
BUG_ON(header->snap_names_len > (u64) SIZE_MAX);
header->snap_names = kmalloc(header->snap_names_len,
GFP_KERNEL);
if (!header->snap_names)
goto err_snapc;
goto out_err;

size = snap_count * sizeof (*header->snap_sizes);
header->snap_sizes = kmalloc(size, GFP_KERNEL);
if (!header->snap_sizes)
goto err_names;
goto out_err;
} else {
WARN_ON(ondisk->snap_names_len);
header->snap_names_len = 0;
header->snap_names = NULL;
header->snap_sizes = NULL;
}

size = sizeof (ondisk->block_name) + 1;
header->object_prefix = kmalloc(size, GFP_KERNEL);
if (!header->object_prefix)
goto err_sizes;
memcpy(header->object_prefix, ondisk->block_name, size - 1);
header->object_prefix[size - 1] = '\0';

header->image_size = le64_to_cpu(ondisk->image_size);
header->obj_order = ondisk->options.order;
header->crypt_type = ondisk->options.crypt_type;
header->comp_type = ondisk->options.comp_type;
header->total_snaps = snap_count;

/* Set up the snapshot context */

size = sizeof (struct ceph_snap_context);
size += snap_count * sizeof (header->snapc->snaps[0]);
header->snapc = kzalloc(size, GFP_KERNEL);
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;
header->total_snaps = snap_count;

if (snap_count && allocated_snaps == snap_count) {
int i;
Expand All @@ -564,16 +569,14 @@ static int rbd_header_from_disk(struct rbd_image_header *header,

return 0;

err_sizes:
out_err:
kfree(header->snap_sizes);
header->snap_sizes = NULL;
err_names:
kfree(header->snap_names);
header->snap_names = NULL;
header->snap_names_len = 0;
err_snapc:
kfree(header->snapc);
header->snapc = NULL;
kfree(header->object_prefix);
header->object_prefix = NULL;

return -ENOMEM;
}
Expand Down

0 comments on commit d94d2b2

Please sign in to comment.