diff options
author | Anuradha Talur <atalur@redhat.com> | 2016-04-29 19:42:37 +0530 |
---|---|---|
committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2016-04-29 18:24:13 -0700 |
commit | ae9d39890fc9a7bcd696cb441c4f3b2eb9677379 (patch) | |
tree | 0368897aa778a4d6f6191b35a09f8874fd50c46d | |
parent | 87de08fdb404492ee090a15fe75aedc17a5ac0b8 (diff) |
libglusterfs : packing functions for compound fops
Any xlator that wants to compound fops together can
use these apis to get the job done.
Change-Id: Ic40fceafecafe70173fd469060e834314826a92c
BUG: 1303829
Signed-off-by: Anuradha Talur <atalur@redhat.com>
Reviewed-on: http://review.gluster.org/13694
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Smoke: Gluster Build System <jenkins@build.gluster.com>
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
-rw-r--r-- | libglusterfs/src/Makefile.am | 3 | ||||
-rw-r--r-- | libglusterfs/src/compound-fop-utils.c | 72 |
2 files changed, 74 insertions, 1 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index fbe30da76f0..63feb380e66 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -31,7 +31,8 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \ strfd.c parse-utils.c $(CONTRIBDIR)/mount/mntent.c \ $(CONTRIBDIR)/libexecinfo/execinfo.c quota-common-utils.c rot-buffs.c \ $(CONTRIBDIR)/timer-wheel/timer-wheel.c \ - $(CONTRIBDIR)/timer-wheel/find_last_bit.c tw.c default-args.c locking.c + $(CONTRIBDIR)/timer-wheel/find_last_bit.c tw.c default-args.c locking.c \ + compound-fop-utils.c nodist_libglusterfs_la_SOURCES = y.tab.c graph.lex.c defaults.c nodist_libglusterfs_la_HEADERS = y.tab.h glusterfs-fops.h diff --git a/libglusterfs/src/compound-fop-utils.c b/libglusterfs/src/compound-fop-utils.c new file mode 100644 index 00000000000..16cd5c690e5 --- /dev/null +++ b/libglusterfs/src/compound-fop-utils.c @@ -0,0 +1,72 @@ +/* + 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. +*/ + +#include "defaults.h" +#include "default-args.h" +#include "mem-types.h" +#include "dict.h" + +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); + + if (!args) + return NULL; + + /* fop_enum can be used by xlators to see which fops are + * included as part of compound fop. This will help in checking + * for compatibility or support without going through the entire + * fop list packed. + */ + args->fop_enum = fop; + args->fop_length = length; + + args->enum_list = GF_CALLOC (length, sizeof (*args->enum_list), + gf_common_mt_int); + + if (!args->enum_list) + goto out; + + args->req_list = GF_CALLOC (length, sizeof (*args->req_list), + gf_mt_default_args_t); + + if (!args->req_list) + goto out; + + if (xdata) { + args->xdata = dict_copy_with_ref (xdata, args->xdata); + if (!args->xdata) + goto out; + } + + 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); + + 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) |