lib/blob: make sizes of cluster array consistent

Fixed size of check in _spdk_bs_snapshot_newblob_open_cpl().

Rest are just to make all consistent and more error prone.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I5a23a7795f1e598c1cfd6d17ce37b367f2f34df8
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/479960
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Tomasz Zawadzki 2020-01-10 06:51:11 -05:00
parent 4b8db27b2a
commit eba7f9f5ea

View File

@ -351,7 +351,7 @@ _spdk_blob_mark_clean(struct spdk_blob *blob)
if (!clusters) { if (!clusters) {
return -ENOMEM; return -ENOMEM;
} }
memcpy(clusters, blob->active.clusters, blob->active.num_clusters * sizeof(*clusters)); memcpy(clusters, blob->active.clusters, blob->active.num_clusters * sizeof(*blob->active.clusters));
} }
if (blob->active.num_pages) { if (blob->active.num_pages) {
@ -502,7 +502,7 @@ _spdk_blob_parse_page(const struct spdk_blob_md_page *page, struct spdk_blob *bl
if (cluster_count == 0) { if (cluster_count == 0) {
return -EINVAL; return -EINVAL;
} }
tmp = realloc(blob->active.clusters, cluster_count * sizeof(uint64_t)); tmp = realloc(blob->active.clusters, cluster_count * sizeof(*blob->active.clusters));
if (tmp == NULL) { if (tmp == NULL) {
return -ENOMEM; return -ENOMEM;
} }
@ -1144,7 +1144,7 @@ _spdk_blob_persist_clear_clusters_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int
void *tmp; void *tmp;
/* scan-build really can't figure reallocs, workaround it */ /* scan-build really can't figure reallocs, workaround it */
tmp = realloc(blob->active.clusters, sizeof(uint64_t) * blob->active.num_clusters); tmp = realloc(blob->active.clusters, sizeof(*blob->active.clusters) * blob->active.num_clusters);
assert(tmp != NULL); assert(tmp != NULL);
blob->active.clusters = tmp; blob->active.clusters = tmp;
#endif #endif
@ -1383,12 +1383,12 @@ _spdk_blob_resize(struct spdk_blob *blob, uint64_t sz)
/* Expand the cluster array if necessary. /* Expand the cluster array if necessary.
* We only shrink the array when persisting. * We only shrink the array when persisting.
*/ */
tmp = realloc(blob->active.clusters, sizeof(uint64_t) * sz); tmp = realloc(blob->active.clusters, sizeof(*blob->active.clusters) * sz);
if (sz > 0 && tmp == NULL) { if (sz > 0 && tmp == NULL) {
return -ENOMEM; return -ENOMEM;
} }
memset(tmp + blob->active.cluster_array_size, 0, memset(tmp + blob->active.cluster_array_size, 0,
sizeof(uint64_t) * (sz - blob->active.cluster_array_size)); sizeof(*blob->active.clusters) * (sz - blob->active.cluster_array_size));
blob->active.clusters = tmp; blob->active.clusters = tmp;
blob->active.cluster_array_size = sz; blob->active.cluster_array_size = sz;
} }
@ -4630,7 +4630,7 @@ _spdk_bs_snapshot_newblob_open_cpl(void *cb_arg, struct spdk_blob *_blob, int bs
ctx->new.blob = newblob; ctx->new.blob = newblob;
assert(spdk_blob_is_thin_provisioned(newblob)); assert(spdk_blob_is_thin_provisioned(newblob));
assert(spdk_mem_all_zero(newblob->active.clusters, assert(spdk_mem_all_zero(newblob->active.clusters,
newblob->active.num_clusters * sizeof(newblob->active.clusters))); newblob->active.num_clusters * sizeof(*newblob->active.clusters)));
_spdk_blob_freeze_io(origblob, _spdk_bs_snapshot_freeze_cpl, ctx); _spdk_blob_freeze_io(origblob, _spdk_bs_snapshot_freeze_cpl, ctx);
} }