diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 04b7db1e4..f853cb01f 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -590,12 +590,63 @@ _spdk_blob_serialize_flags(const struct spdk_blob_data *blob, *buf_sz -= sizeof(*desc); } +static int +_spdk_blob_serialize_xattrs(const struct spdk_blob_data *blob, + const struct spdk_xattr_tailq *xattrs, + struct spdk_blob_md_page **pages, + struct spdk_blob_md_page *cur_page, + uint32_t *page_count, uint8_t **buf, + size_t *remaining_sz) +{ + const struct spdk_xattr *xattr; + int rc; + + TAILQ_FOREACH(xattr, xattrs, link) { + size_t required_sz = 0; + + rc = _spdk_blob_serialize_xattr(xattr, + *buf, *remaining_sz, + &required_sz); + if (rc < 0) { + /* Need to add a new page to the chain */ + rc = _spdk_blob_serialize_add_page(blob, pages, page_count, + &cur_page); + if (rc < 0) { + spdk_dma_free(*pages); + *pages = NULL; + *page_count = 0; + return rc; + } + + *buf = (uint8_t *)cur_page->descriptors; + *remaining_sz = sizeof(cur_page->descriptors); + + /* Try again */ + required_sz = 0; + rc = _spdk_blob_serialize_xattr(xattr, + *buf, *remaining_sz, + &required_sz); + + if (rc < 0) { + spdk_dma_free(*pages); + *pages = NULL; + *page_count = 0; + return -1; + } + } + + *remaining_sz -= required_sz; + *buf += required_sz; + } + + return 0; +} + static int _spdk_blob_serialize(const struct spdk_blob_data *blob, struct spdk_blob_md_page **pages, uint32_t *page_count) { struct spdk_blob_md_page *cur_page; - const struct spdk_xattr *xattr; int rc; uint8_t *buf; size_t remaining_sz; @@ -623,43 +674,11 @@ _spdk_blob_serialize(const struct spdk_blob_data *blob, struct spdk_blob_md_page buf += sizeof(struct spdk_blob_md_descriptor_flags); /* Serialize xattrs */ - TAILQ_FOREACH(xattr, &blob->xattrs, link) { - size_t required_sz = 0; - rc = _spdk_blob_serialize_xattr(xattr, - buf, remaining_sz, - &required_sz); - if (rc < 0) { - /* Need to add a new page to the chain */ - rc = _spdk_blob_serialize_add_page(blob, pages, page_count, - &cur_page); - if (rc < 0) { - spdk_dma_free(*pages); - *pages = NULL; - *page_count = 0; - return rc; - } - - buf = (uint8_t *)cur_page->descriptors; - remaining_sz = sizeof(cur_page->descriptors); - - /* Try again */ - required_sz = 0; - rc = _spdk_blob_serialize_xattr(xattr, - buf, remaining_sz, - &required_sz); - - if (rc < 0) { - spdk_dma_free(*pages); - *pages = NULL; - *page_count = 0; - return -1; - } - } - - remaining_sz -= required_sz; - buf += required_sz; + rc = _spdk_blob_serialize_xattrs(blob, &blob->xattrs, + pages, cur_page, page_count, &buf, &remaining_sz); + if (rc < 0) { + return rc; } - /* Serialize extents */ last_cluster = 0; while (last_cluster < blob->active.num_clusters) { diff --git a/lib/blob/blobstore.h b/lib/blob/blobstore.h index eb2a8cbd6..c6d98cfcb 100644 --- a/lib/blob/blobstore.h +++ b/lib/blob/blobstore.h @@ -138,7 +138,7 @@ struct spdk_blob_data { /* TODO: The xattrs are mutable, but we don't want to be * copying them unecessarily. Figure this out. */ - TAILQ_HEAD(, spdk_xattr) xattrs; + TAILQ_HEAD(spdk_xattr_tailq, spdk_xattr) xattrs; TAILQ_ENTRY(spdk_blob_data) link; };