diff options
author | Anuradha Talur <atalur@redhat.com> | 2016-08-29 16:41:09 +0530 |
---|---|---|
committer | Raghavendra G <rgowdapp@redhat.com> | 2016-08-30 23:50:40 -0700 |
commit | 7cbc10037ecc873d60c3a970d00faf2819019525 (patch) | |
tree | 35026d258fa4bb9aad89f7a504954bb566ffa4fc /libglusterfs/src/compound-fop-utils.c | |
parent | fe929224c47d5c82da5650e9e1041645a8d7f244 (diff) |
compound fops: Some fixes to compound fops framework
Change-Id: I808fd5f9f002a35bff94d310c5d61a781e49570b
BUG: 1360169
Signed-off-by: Anuradha Talur <atalur@redhat.com>
Reviewed-on: http://review.gluster.org/15010
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
Diffstat (limited to 'libglusterfs/src/compound-fop-utils.c')
-rw-r--r-- | libglusterfs/src/compound-fop-utils.c | 104 |
1 files changed, 85 insertions, 19 deletions
diff --git a/libglusterfs/src/compound-fop-utils.c b/libglusterfs/src/compound-fop-utils.c index 16cd5c690e5..03d7b5ba459 100644 --- a/libglusterfs/src/compound-fop-utils.c +++ b/libglusterfs/src/compound-fop-utils.c @@ -13,12 +13,94 @@ #include "mem-types.h" #include "dict.h" +void +compound_args_cleanup (compound_args_t *args) +{ + int i; + + if (!args) + return; + + if (args->xdata) + dict_unref (args->xdata); + + if (args->req_list) { + for (i = 0; i < args->fop_length; i++) { + args_wipe (&args->req_list[i]); + } + } + + GF_FREE (args->enum_list); + GF_FREE (args->req_list); + GF_FREE (args); +} + +void +compound_args_cbk_cleanup (compound_args_cbk_t *args_cbk) +{ + int i; + + if (!args_cbk) + return; + + if (args_cbk->xdata) + dict_unref (args_cbk->xdata); + + if (args_cbk->rsp_list) { + for (i = 0; i < args_cbk->fop_length; i++) { + args_cbk_wipe (&args_cbk->rsp_list[i]); + } + } + + GF_FREE (args_cbk->rsp_list); + GF_FREE (args_cbk->enum_list); + GF_FREE (args_cbk); +} + +compound_args_cbk_t* +compound_args_cbk_alloc (int length, dict_t *xdata) +{ + int i = 0; + compound_args_cbk_t *args_cbk = NULL; + + args_cbk = GF_CALLOC (1, sizeof (*args_cbk), gf_mt_compound_rsp_t); + if (!args_cbk) + return NULL; + + args_cbk->fop_length = length; + + args_cbk->rsp_list = GF_CALLOC (length, sizeof (*args_cbk->rsp_list), + gf_mt_default_args_cbk_t); + if (!args_cbk->rsp_list) + goto out; + + for (i = 0; i < length; i++) { + args_cbk_init (&args_cbk->rsp_list[i]); + } + + args_cbk->enum_list = GF_CALLOC (length, sizeof (*args_cbk->enum_list), + gf_common_mt_int); + if (!args_cbk->enum_list) + goto out; + + if (xdata) { + args_cbk->xdata = dict_copy_with_ref (xdata, NULL); + if (!args_cbk->xdata) + goto out; + } + + return args_cbk; +out: + compound_args_cbk_cleanup (args_cbk); + return NULL; +} + compound_args_t* compound_fop_alloc (int length, glusterfs_compound_fop_t fop, dict_t *xdata) { compound_args_t *args = NULL; - args = GF_CALLOC (1, sizeof (args), gf_mt_compound_req_t); + args = GF_CALLOC (1, sizeof (*args), gf_mt_compound_req_t); if (!args) return NULL; @@ -29,7 +111,7 @@ compound_fop_alloc (int length, glusterfs_compound_fop_t fop, dict_t *xdata) * fop list packed. */ args->fop_enum = fop; - args->fop_length = length; + args->fop_length = length; args->enum_list = GF_CALLOC (length, sizeof (*args->enum_list), gf_common_mt_int); @@ -51,22 +133,6 @@ compound_fop_alloc (int length, glusterfs_compound_fop_t fop, dict_t *xdata) return args; out: - if (args->xdata) - dict_unref (args->xdata); - - if (args->req_list) - GF_FREE (args->req_list); - - if (args->enum_list) - GF_FREE (args->enum_list); - - if (args) - GF_FREE (args); - + compound_args_cleanup (args); return NULL; } - -#define COMPOUND_PACK_ARGS(fop, fop_enum, args, counter, params ...) do { \ - args->enum_list[counter] = fop_enum; \ - args_##fop##_store (&args->req_list[counter], params); \ -} while (0) |