diff options
Diffstat (limited to 'libglusterfs')
| -rw-r--r-- | libglusterfs/src/Makefile.am | 3 | ||||
| -rw-r--r-- | libglusterfs/src/compound-fop-utils.c | 104 | ||||
| -rw-r--r-- | libglusterfs/src/compound-fop-utils.h | 35 | ||||
| -rw-r--r-- | libglusterfs/src/default-args.c | 12 | ||||
| -rw-r--r-- | libglusterfs/src/default-args.h | 2 | 
5 files changed, 132 insertions, 24 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index a288e703ed4..e086ecec89f 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -52,7 +52,8 @@ libglusterfs_la_HEADERS = common-utils.h defaults.h default-args.h \  	glfs-message-id.h template-component-messages.h strfd.h \  	syncop-utils.h parse-utils.h libglusterfs-messages.h tw.h \  	lvm-defaults.h quota-common-utils.h rot-buffs.h \ -	compat-uuid.h upcall-utils.h throttle-tbf.h events.h +	compat-uuid.h upcall-utils.h throttle-tbf.h events.h\ +	compound-fop-utils.h  libglusterfs_ladir = $(includedir)/glusterfs 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) diff --git a/libglusterfs/src/compound-fop-utils.h b/libglusterfs/src/compound-fop-utils.h new file mode 100644 index 00000000000..bfd0649aef2 --- /dev/null +++ b/libglusterfs/src/compound-fop-utils.h @@ -0,0 +1,35 @@ +/* +  Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com> +  This file is part of GlusterFS. + +  This file is licensed to you under your choice of the GNU Lesser +  General Public License, version 3 or any later version (LGPLv3 or +  later), or the GNU General Public License, version 2 (GPLv2), in all +  cases as published by the Free Software Foundation. +*/ + +#ifndef __COMPOUND_FOP_UTILS_H__ +#define __COMPOUND_FOP_UTILS_H__ + +#include "defaults.h" +#include "default-args.h" +#include "mem-types.h" +#include "dict.h" + +#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) + +compound_args_t* +compound_fop_alloc (int length, glusterfs_compound_fop_t fop, dict_t *xdata); + +void +compound_args_cleanup (compound_args_t *args); + +void +compound_args_cbk_cleanup (compound_args_cbk_t *args_cbk); + +compound_args_cbk_t* +compound_args_cbk_alloc (int length, dict_t *xdata); +#endif /* __COMPOUND_FOP_UTILS_H__ */ diff --git a/libglusterfs/src/default-args.c b/libglusterfs/src/default-args.c index 2e51bf21f84..f40de2dae68 100644 --- a/libglusterfs/src/default-args.c +++ b/libglusterfs/src/default-args.c @@ -1576,11 +1576,9 @@ args_wipe (default_args_t *args)          if (!args)                  return; -        if (&args->loc) -                loc_wipe (&args->loc); +        loc_wipe (&args->loc); -        if (&args->loc2) -                loc_wipe (&args->loc2); +        loc_wipe (&args->loc2);          if (args->fd)                  fd_unref (args->fd); @@ -1603,3 +1601,9 @@ args_wipe (default_args_t *args)  	GF_FREE ((char *)args->volume);  } + +void +args_cbk_init (default_args_cbk_t *args_cbk) +{ +        INIT_LIST_HEAD (&args_cbk->entries); +} diff --git a/libglusterfs/src/default-args.h b/libglusterfs/src/default-args.h index 93426ca43b6..a2201dd4703 100644 --- a/libglusterfs/src/default-args.h +++ b/libglusterfs/src/default-args.h @@ -479,4 +479,6 @@ args_getactivelk_cbk_store (default_args_cbk_t *args,  int  args_setactivelk_store (default_args_t *args, loc_t *loc,                            lock_migration_info_t *locklist, dict_t *xdata); +void +args_cbk_init (default_args_cbk_t *args_cbk);  #endif /* _DEFAULT_ARGS_H */  | 
