From 074413c5561c7fc930f01ffed0be24378b2e8ef9 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Wed, 11 Sep 2019 04:54:06 -0400 Subject: [PATCH] lib/blob: update buf and buf_sz when serializing extent_rle Originally serializing extent_rle was always done as last step. There was no need to update the buffer pointer, since it went unused. Next patches in series expand serialization to new descriptors, so here the assumption is removed and buf/buf_sz is updated. Signed-off-by: Tomasz Zawadzki Change-Id: I7ccfb500d64e4276359cc98c5587c6301272d728 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/468232 Reviewed-by: Ben Walker Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- lib/blob/blobstore.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 433e20a14a..d217ad5090 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -675,7 +675,7 @@ _spdk_blob_serialize_xattr(const struct spdk_xattr *xattr, static void _spdk_blob_serialize_extent_rle(const struct spdk_blob *blob, uint64_t start_cluster, uint64_t *next_cluster, - uint8_t *buf, size_t buf_sz) + uint8_t **buf, size_t *buf_sz) { struct spdk_blob_md_descriptor_extent_rle *desc_extent_rle; size_t cur_sz; @@ -684,12 +684,12 @@ _spdk_blob_serialize_extent_rle(const struct spdk_blob *blob, /* The buffer must have room for at least one extent */ cur_sz = sizeof(struct spdk_blob_md_descriptor) + sizeof(desc_extent_rle->extents[0]); - if (buf_sz < cur_sz) { + if (*buf_sz < cur_sz) { *next_cluster = start_cluster; return; } - desc_extent_rle = (struct spdk_blob_md_descriptor_extent_rle *)buf; + desc_extent_rle = (struct spdk_blob_md_descriptor_extent_rle *)*buf; desc_extent_rle->type = SPDK_MD_DESCRIPTOR_TYPE_EXTENT_RLE; lba_per_cluster = _spdk_bs_cluster_to_lba(blob->bs, 1); @@ -711,7 +711,7 @@ _spdk_blob_serialize_extent_rle(const struct spdk_blob *blob, cur_sz += sizeof(desc_extent_rle->extents[extent_idx]); - if (buf_sz < cur_sz) { + if (*buf_sz < cur_sz) { /* If we ran out of buffer space, return */ *next_cluster = i; goto finish; @@ -729,6 +729,8 @@ _spdk_blob_serialize_extent_rle(const struct spdk_blob *blob, finish: desc_extent_rle->length = sizeof(desc_extent_rle->extents[0]) * extent_idx; + *buf_sz -= sizeof(struct spdk_blob_md_descriptor) + desc_extent_rle->length; + *buf += sizeof(struct spdk_blob_md_descriptor) + desc_extent_rle->length; return; } @@ -745,7 +747,7 @@ _spdk_blob_serialize_extents_rle(const struct spdk_blob *blob, last_cluster = 0; while (last_cluster < blob->active.num_clusters) { - _spdk_blob_serialize_extent_rle(blob, last_cluster, &last_cluster, *buf, *remaining_sz); + _spdk_blob_serialize_extent_rle(blob, last_cluster, &last_cluster, buf, remaining_sz); if (last_cluster == blob->active.num_clusters) { break;