diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index f28e6e946..e1ea395eb 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: apt update run: sudo apt update - name: dpkg / rpm prep (debug) diff --git a/.github/workflows/controlplane-recipes.yml b/.github/workflows/controlplane-recipes.yml index 2bd778307..55a0a493b 100644 --- a/.github/workflows/controlplane-recipes.yml +++ b/.github/workflows/controlplane-recipes.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: ./code @@ -65,7 +65,7 @@ jobs: # Checkout holon repo - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 00pauln00/holon #ref: @@ -111,7 +111,7 @@ jobs: if: failure() - name: Archive the test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.prepare_artifact_filename.outputs.ARTIFACT_NAME }} path: /home/runner/work/niovad/niovad/holon_log diff --git a/.github/workflows/golang-apps-recipes.yml b/.github/workflows/golang-apps-recipes.yml index 0fd7b265f..54e26ecbd 100644 --- a/.github/workflows/golang-apps-recipes.yml +++ b/.github/workflows/golang-apps-recipes.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: ./code @@ -59,7 +59,7 @@ jobs: cp ./code/scripts/covid_app_recipe.txt ./code/scripts/foodpalaceapp_recipe.txt /home/runner/work/niovad/niovad/build_dir/ - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 00pauln00/holon #ref: @@ -129,7 +129,7 @@ jobs: if: failure() - name: Archive the test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.prepare_artifact_filename.outputs.ARTIFACT_NAME }} path: /home/runner/work/niovad/niovad/holon_log diff --git a/.github/workflows/lease_recipes.yml b/.github/workflows/lease_recipes.yml index 8f3478237..9b5e40b01 100644 --- a/.github/workflows/lease_recipes.yml +++ b/.github/workflows/lease_recipes.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: ./code @@ -64,7 +64,7 @@ jobs: # Checkout holon repo - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 00pauln00/holon #ref: @@ -104,7 +104,7 @@ jobs: if: failure() - name: Archive the test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.prepare_artifact_filename.outputs.ARTIFACT_NAME }} path: /home/runner/work/niovad/niovad/holon_log diff --git a/.github/workflows/lease_stale_recipes.yml b/.github/workflows/lease_stale_recipes.yml index 8222a10ef..79e36e8ec 100644 --- a/.github/workflows/lease_stale_recipes.yml +++ b/.github/workflows/lease_stale_recipes.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: ./code @@ -64,7 +64,7 @@ jobs: # Checkout holon repo - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 00pauln00/holon #ref: @@ -93,7 +93,7 @@ jobs: if: failure() - name: Archive the test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.prepare_artifact_filename.outputs.ARTIFACT_NAME }} path: /home/runner/work/niovad/niovad/holon_log diff --git a/.github/workflows/niova-basic-recipes.yml b/.github/workflows/niova-basic-recipes.yml index 630e023f1..49878c10f 100644 --- a/.github/workflows/niova-basic-recipes.yml +++ b/.github/workflows/niova-basic-recipes.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: ./code @@ -57,7 +57,7 @@ jobs: run: cp ./code/scripts/basic_recipes_with_sync.txt /home/runner/work/niovad/niovad/build_dir/ - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 00pauln00/holon #ref: @@ -98,7 +98,7 @@ jobs: if: failure() - name: Archive the test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.prepare_artifact_filename.outputs.ARTIFACT_NAME }} path: /home/runner/work/niovad/niovad/holon_log diff --git a/.github/workflows/niova-bulk-recovery.yml b/.github/workflows/niova-bulk-recovery.yml index c73af6ec7..f1006caca 100644 --- a/.github/workflows/niova-bulk-recovery.yml +++ b/.github/workflows/niova-bulk-recovery.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: ./code @@ -55,7 +55,7 @@ jobs: cp ./code/scripts/bulk_recovery_recipes.txt /home/runner/work/niovad/niovad/build_dir/ - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 00pauln00/holon #ref: @@ -107,7 +107,7 @@ jobs: if: failure() - name: Archive the test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.prepare_artifact_filename.outputs.ARTIFACT_NAME }} path: /home/runner/work/niovad/niovad/holon_log diff --git a/.github/workflows/niova-coalesced-wr.yml b/.github/workflows/niova-coalesced-wr.yml index 1b57a0a73..9d4ea2eee 100644 --- a/.github/workflows/niova-coalesced-wr.yml +++ b/.github/workflows/niova-coalesced-wr.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: ./code @@ -55,7 +55,7 @@ jobs: cp ./code/scripts/coalesced_wr_recipes_with_sync.txt /home/runner/work/niovad/niovad/build_dir/ - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 00pauln00/holon #ref: @@ -100,7 +100,7 @@ jobs: if: failure() - name: Archive the test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.prepare_artifact_filename.outputs.ARTIFACT_NAME }} path: /home/runner/work/niovad/niovad/holon_log diff --git a/.github/workflows/niova-fail-over.yml b/.github/workflows/niova-fail-over.yml index 4c7d3c70e..c725d2628 100644 --- a/.github/workflows/niova-fail-over.yml +++ b/.github/workflows/niova-fail-over.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: ./code @@ -45,7 +45,7 @@ jobs: cp ./code/scripts/failover_recipes.txt /home/runner/work/niovad/niovad/build_dir/ - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 00pauln00/holon #ref: @@ -77,7 +77,7 @@ jobs: if: failure() - name: Archive the test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.prepare_artifact_filename.outputs.ARTIFACT_NAME }} path: /home/runner/work/niovad/niovad/holon_log diff --git a/.github/workflows/niova-prevote.yml b/.github/workflows/niova-prevote.yml index 9d3d4e7f8..e3de11e6e 100644 --- a/.github/workflows/niova-prevote.yml +++ b/.github/workflows/niova-prevote.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: ./code @@ -54,7 +54,7 @@ jobs: cp ./code/scripts/prevote_recipes.txt /home/runner/work/niovad/niovad/build_dir/ - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 00pauln00/holon #ref: @@ -83,7 +83,7 @@ jobs: if: failure() - name: Archive the test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.prepare_artifact_filename.outputs.ARTIFACT_NAME }} path: /home/runner/work/niovad/niovad/holon_log diff --git a/.github/workflows/niova-rebuild.yml b/.github/workflows/niova-rebuild.yml index b53ba122b..676dd3113 100644 --- a/.github/workflows/niova-rebuild.yml +++ b/.github/workflows/niova-rebuild.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: ./code @@ -45,7 +45,7 @@ jobs: cp ./code/scripts/rebuild_recipes.txt /home/runner/work/niovad/niovad/build_dir/ - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 00pauln00/holon #ref: @@ -77,7 +77,7 @@ jobs: if: failure() - name: Archive the test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.prepare_artifact_filename.outputs.ARTIFACT_NAME }} path: /home/runner/work/niovad/niovad/holon_log diff --git a/src/buffer.c b/src/buffer.c index c7b8fe3d0..afbffd0a5 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -418,7 +418,10 @@ buffer_set_destroy(struct buffer_set *bs) buffer_item_user_cache_revoke(bi); CIRCLEQ_REMOVE(&bs->bs_free_list, bi, bi_lentry); - free(bi->bi_iov.iov_base); + + if (!bs->bs_use_alt_source_buf) + free(bi->bi_iov.iov_base); + free(bi); bs->bs_num_bufs--; @@ -449,11 +452,18 @@ buffer_set_destroy(struct buffer_set *bs) } int -buffer_set_init(struct buffer_set *bs, size_t nbufs, size_t buf_size, - enum buffer_set_opts opts) +buffer_set_initx(struct buffer_set_args *bsa) { buffer_page_size_set(); + if (!bsa) + return -EINVAL; + + enum buffer_set_opts opts = bsa->bsa_opts; + struct buffer_set *bs = bsa->bsa_set; + size_t buf_size = bsa->bsa_buf_size; + size_t nbufs = bsa->bsa_nbufs; + if (!bs || !buf_size || bs->bs_init) return -EINVAL; @@ -464,6 +474,22 @@ buffer_set_init(struct buffer_set *bs, size_t nbufs, size_t buf_size, CIRCLEQ_INIT(&bs->bs_free_list); CIRCLEQ_INIT(&bs->bs_inuse_list); + if (opts & BUFSET_OPT_ALT_SOURCE_BUF) + { + if (bsa->bsa_alt_source == NULL) + return -EINVAL; + + if (bsa->bsa_alt_source_size < (nbufs * buf_size)) + return -EOVERFLOW; + + bsa->bsa_alt_source_used = 0; + + bs->bs_alt_source_buf = bsa->bsa_alt_source; + bs->bs_alt_source_buf_size = bsa->bsa_alt_source_size; + + bs->bs_use_alt_source_buf = 1; + } + if (opts & BUFSET_OPT_USER_CACHE) { bs->bs_allow_user_cache = 1; @@ -500,6 +526,13 @@ buffer_set_init(struct buffer_set *bs, size_t nbufs, size_t buf_size, FATAL_IF(bi->bi_iov.iov_base == NULL, "niova_posix_memalign()"); } + else if (bs->bs_use_alt_source_buf) + { + bi->bi_iov.iov_base = + ((char *)bs->bs_alt_source_buf) + bsa->bsa_alt_source_used; + + bsa->bsa_alt_source_used += buf_size; + } else { bi->bi_iov.iov_base = malloc(buf_size); @@ -547,6 +580,20 @@ buffer_set_init(struct buffer_set *bs, size_t nbufs, size_t buf_size, return error; } +int +buffer_set_init(struct buffer_set *bs, size_t nbufs, size_t buf_size, + enum buffer_set_opts opts) +{ + struct buffer_set_args bsa = { + .bsa_set = bs, + .bsa_nbufs = nbufs, + .bsa_buf_size = buf_size, + .bsa_opts = opts, + }; + + return buffer_set_initx(&bsa); +} + int buffer_set_apply_name(struct buffer_set *bs, const char *name) { diff --git a/src/include/buffer.h b/src/include/buffer.h index cfaabd2b9..d4d577019 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -22,6 +22,7 @@ enum buffer_set_opts BUFSET_OPT_LREG = (1 << 2), BUFSET_OPT_MEMALIGN_L2 = (1 << 3), BUFSET_OPT_MEMALIGN_SECTOR = (1 << 4), + BUFSET_OPT_ALT_SOURCE_BUF = (1 << 5), BUFSET_OPT_MEMALIGN = BUFSET_OPT_MEMALIGN_SECTOR, }; @@ -48,24 +49,38 @@ SLIST_HEAD(buffer_user_slist, buffer_item); #define BUFFER_SET_NAME_MAX 32 +struct buffer_set_args +{ + struct buffer_set *bsa_set; + size_t bsa_nbufs; + size_t bsa_buf_size; + void *bsa_alt_source; + size_t bsa_alt_source_size; + size_t bsa_alt_source_used; + enum buffer_set_opts bsa_opts; +}; + struct buffer_set { - char bs_name[BUFFER_SET_NAME_MAX + 1]; - size_t bs_num_bufs; - ssize_t bs_num_allocated; - ssize_t bs_num_user_cached; - ssize_t bs_num_pndg_alloc; - size_t bs_item_size; - size_t bs_max_allocated; - size_t bs_total_alloc; - uint8_t bs_init:1; - uint8_t bs_serialize:1; - uint8_t bs_ctl_interface:1; - uint8_t bs_allow_user_cache:1; - struct buffer_list bs_free_list; - struct buffer_list bs_inuse_list; - pthread_mutex_t bs_mutex; - struct lreg_node bs_lrn; + char bs_name[BUFFER_SET_NAME_MAX + 1]; + size_t bs_num_bufs; + ssize_t bs_num_allocated; + ssize_t bs_num_user_cached; + ssize_t bs_num_pndg_alloc; + size_t bs_item_size; + size_t bs_max_allocated; + size_t bs_total_alloc; + uint8_t bs_init:1; + uint8_t bs_serialize:1; + uint8_t bs_ctl_interface:1; + uint8_t bs_allow_user_cache:1; + uint8_t bs_use_alt_source_buf:1; + void *bs_alt_source_buf; + size_t bs_alt_source_buf_size; + struct buffer_list bs_free_list; + struct buffer_list bs_inuse_list; + pthread_mutex_t bs_mutex; + struct lreg_node bs_lrn; }; size_t @@ -111,6 +126,9 @@ int buffer_set_init(struct buffer_set *bs, size_t nbufs, size_t buf_size, enum buffer_set_opts opts); +int +buffer_set_initx(struct buffer_set_args *bsa); + static inline ssize_t buffer_user_list_total_bytes(const struct buffer_user_slist *bus, size_t *nitems) diff --git a/test/buffer-test.c b/test/buffer-test.c index ce810e10e..9c38ed70d 100644 --- a/test/buffer-test.c +++ b/test/buffer-test.c @@ -222,6 +222,56 @@ buffer_user_cache_test(void) NIOVA_ASSERT(items[0] == bi); // callback should not have been issued } +static void +buffer_initx_test(void) +{ + size_t size = 1024UL*1024UL; + void *base = malloc(size); + NIOVA_ASSERT(base != NULL); + + struct buffer_set bs = {0}; + + enum buffer_set_opts opts = BUFSET_OPT_ALT_SOURCE_BUF; + + struct buffer_set_args bsa = + { + .bsa_set = &bs, + .bsa_opts = opts, + .bsa_nbufs = 1024UL, + .bsa_buf_size = 1024UL, + .bsa_alt_source = NULL, + .bsa_alt_source_size = size, + }; + + int rc = buffer_set_initx(&bsa); + NIOVA_ASSERT(rc == -EINVAL); + + bsa.bsa_alt_source = base; + bsa.bsa_alt_source_size -= 1; + + rc = buffer_set_initx(&bsa); + NIOVA_ASSERT(rc == -EOVERFLOW); + + bsa.bsa_alt_source_size += 1; + + rc = buffer_set_initx(&bsa); + NIOVA_ASSERT(rc == 0); + + NIOVA_ASSERT(bsa.bsa_alt_source_used == size); + + struct buffer_item *bi = buffer_set_allocate_item(&bs); + NIOVA_ASSERT(bi && bi->bi_iov.iov_len == 1024UL); + NIOVA_ASSERT(((uintptr_t)bi->bi_iov.iov_base >= (uintptr_t)base) && + ((uintptr_t)bi->bi_iov.iov_base < (((uintptr_t)base) + size))); + + buffer_set_release_item(bi); + + rc = buffer_set_destroy(&bs); + NIOVA_ASSERT(rc == 0); + + free(base); +} + int main(void) { @@ -232,6 +282,8 @@ main(void) buffer_test(false, true); + buffer_initx_test(); + buffer_user_cache_test(); return 0;