blobstore: use common return path in blob_resize()
A future commit may need to release a lock before returning. This refactors blob_resize() to always return at end of the function using an out label and goto. Signed-off-by: Mike Gerdts <mgerdts@nvidia.com> Change-Id: I671fbdbe0e3b766c264c45589dad3a864ba1f192 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15982 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com> Community-CI: Mellanox Build Bot
This commit is contained in:
parent
316cf9ef99
commit
c1544908e0
@ -1971,6 +1971,7 @@ blob_resize(struct spdk_blob *blob, uint64_t sz)
|
|||||||
uint32_t *ep_tmp;
|
uint32_t *ep_tmp;
|
||||||
uint64_t new_num_ep = 0, current_num_ep = 0;
|
uint64_t new_num_ep = 0, current_num_ep = 0;
|
||||||
struct spdk_blob_store *bs;
|
struct spdk_blob_store *bs;
|
||||||
|
int rc;
|
||||||
|
|
||||||
bs = blob->bs;
|
bs = blob->bs;
|
||||||
|
|
||||||
@ -2001,14 +2002,16 @@ blob_resize(struct spdk_blob *blob, uint64_t sz)
|
|||||||
/* Check first that we have enough clusters and md pages before we start claiming them. */
|
/* Check first that we have enough clusters and md pages before we start claiming them. */
|
||||||
if (sz > num_clusters && spdk_blob_is_thin_provisioned(blob) == false) {
|
if (sz > num_clusters && spdk_blob_is_thin_provisioned(blob) == false) {
|
||||||
if ((sz - num_clusters) > bs->num_free_clusters) {
|
if ((sz - num_clusters) > bs->num_free_clusters) {
|
||||||
return -ENOSPC;
|
rc = -ENOSPC;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
lfmd = 0;
|
lfmd = 0;
|
||||||
for (i = current_num_ep; i < new_num_ep ; i++) {
|
for (i = current_num_ep; i < new_num_ep ; i++) {
|
||||||
lfmd = spdk_bit_array_find_first_clear(blob->bs->used_md_pages, lfmd);
|
lfmd = spdk_bit_array_find_first_clear(blob->bs->used_md_pages, lfmd);
|
||||||
if (lfmd == UINT32_MAX) {
|
if (lfmd == UINT32_MAX) {
|
||||||
/* No more free md pages. Cannot satisfy the request */
|
/* No more free md pages. Cannot satisfy the request */
|
||||||
return -ENOSPC;
|
rc = -ENOSPC;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2019,7 +2022,8 @@ blob_resize(struct spdk_blob *blob, uint64_t sz)
|
|||||||
*/
|
*/
|
||||||
tmp = realloc(blob->active.clusters, sizeof(*blob->active.clusters) * sz);
|
tmp = realloc(blob->active.clusters, sizeof(*blob->active.clusters) * sz);
|
||||||
if (sz > 0 && tmp == NULL) {
|
if (sz > 0 && tmp == NULL) {
|
||||||
return -ENOMEM;
|
rc = -ENOMEM;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
memset(tmp + blob->active.cluster_array_size, 0,
|
memset(tmp + blob->active.cluster_array_size, 0,
|
||||||
sizeof(*blob->active.clusters) * (sz - blob->active.cluster_array_size));
|
sizeof(*blob->active.clusters) * (sz - blob->active.cluster_array_size));
|
||||||
@ -2030,7 +2034,8 @@ blob_resize(struct spdk_blob *blob, uint64_t sz)
|
|||||||
if (new_num_ep > current_num_ep && blob->use_extent_table) {
|
if (new_num_ep > current_num_ep && blob->use_extent_table) {
|
||||||
ep_tmp = realloc(blob->active.extent_pages, sizeof(*blob->active.extent_pages) * new_num_ep);
|
ep_tmp = realloc(blob->active.extent_pages, sizeof(*blob->active.extent_pages) * new_num_ep);
|
||||||
if (new_num_ep > 0 && ep_tmp == NULL) {
|
if (new_num_ep > 0 && ep_tmp == NULL) {
|
||||||
return -ENOMEM;
|
rc = -ENOMEM;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
memset(ep_tmp + blob->active.extent_pages_array_size, 0,
|
memset(ep_tmp + blob->active.extent_pages_array_size, 0,
|
||||||
sizeof(*blob->active.extent_pages) * (new_num_ep - blob->active.extent_pages_array_size));
|
sizeof(*blob->active.extent_pages) * (new_num_ep - blob->active.extent_pages_array_size));
|
||||||
@ -2055,7 +2060,9 @@ blob_resize(struct spdk_blob *blob, uint64_t sz)
|
|||||||
blob->active.num_clusters = sz;
|
blob->active.num_clusters = sz;
|
||||||
blob->active.num_extent_pages = new_num_ep;
|
blob->active.num_extent_pages = new_num_ep;
|
||||||
|
|
||||||
return 0;
|
rc = 0;
|
||||||
|
out:
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user