Commit 28cb775d authored by Alex Elder's avatar Alex Elder

rbd: return earlier in rbd_header_from_disk()

The only caller of rbd_header_from_disk() is rbd_read_header().
It passes as allocated_snaps the number of snapshots it will
have received from the server for the snapshot context that
rbd_header_from_disk() is to interpret.  The first time through
it provides 0--mainly to extract the number of snapshots from
the snapshot context header--so that it can allocate an
appropriately-sized buffer to receive the entire snapshot
context from the server in a second request.

rbd_header_from_disk() will not fill in the array of snapshot ids
unless the number in the snapshot matches the number the caller
had allocated.

This patch adjusts that logic a little further to be more efficient.
rbd_read_header() doesn't even examine the snapshot context unless
the snapshot count (stored in header->total_snaps) matches the
number of snapshots allocated.  So rbd_header_from_disk() doesn't
need to allocate or fill in the snapshot context field at all in
that case.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent 6a52325f
...@@ -540,7 +540,14 @@ static int rbd_header_from_disk(struct rbd_image_header *header, ...@@ -540,7 +540,14 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
header->comp_type = ondisk->options.comp_type; header->comp_type = ondisk->options.comp_type;
header->total_snaps = snap_count; header->total_snaps = snap_count;
/* Set up the snapshot context */ /*
* If the number of snapshot ids provided by the caller
* doesn't match the number in the entire context there's
* no point in going further. Caller will try again after
* getting an updated snapshot context from the server.
*/
if (allocated_snaps != snap_count)
return 0;
size = sizeof (struct ceph_snap_context); size = sizeof (struct ceph_snap_context);
size += snap_count * sizeof (header->snapc->snaps[0]); size += snap_count * sizeof (header->snapc->snaps[0]);
...@@ -552,8 +559,10 @@ static int rbd_header_from_disk(struct rbd_image_header *header, ...@@ -552,8 +559,10 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
header->snapc->seq = le64_to_cpu(ondisk->snap_seq); header->snapc->seq = le64_to_cpu(ondisk->snap_seq);
header->snapc->num_snaps = snap_count; header->snapc->num_snaps = snap_count;
if (snap_count && allocated_snaps == snap_count) { /* Fill in the snapshot information */
int i;
if (snap_count) {
u32 i;
for (i = 0; i < snap_count; i++) { for (i = 0; i < snap_count; i++) {
header->snapc->snaps[i] = header->snapc->snaps[i] =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment