diff options
Diffstat (limited to 'xlators/debug')
| -rw-r--r-- | xlators/debug/error-gen/src/Makefile.am | 9 | ||||
| -rw-r--r-- | xlators/debug/error-gen/src/error-gen-mem-types.h | 20 | ||||
| -rw-r--r-- | xlators/debug/error-gen/src/error-gen.c | 1016 | ||||
| -rw-r--r-- | xlators/debug/error-gen/src/error-gen.h | 39 | ||||
| -rw-r--r-- | xlators/debug/io-stats/src/Makefile.am | 7 | ||||
| -rw-r--r-- | xlators/debug/io-stats/src/io-stats-mem-types.h | 23 | ||||
| -rw-r--r-- | xlators/debug/io-stats/src/io-stats.c | 2084 | ||||
| -rw-r--r-- | xlators/debug/trace/src/Makefile.am | 8 | ||||
| -rw-r--r-- | xlators/debug/trace/src/trace-mem-types.h | 21 | ||||
| -rw-r--r-- | xlators/debug/trace/src/trace.c | 3260 | ||||
| -rw-r--r-- | xlators/debug/trace/src/trace.h | 98 |
11 files changed, 4569 insertions, 2016 deletions
diff --git a/xlators/debug/error-gen/src/Makefile.am b/xlators/debug/error-gen/src/Makefile.am index f353b61e6..5075c59a8 100644 --- a/xlators/debug/error-gen/src/Makefile.am +++ b/xlators/debug/error-gen/src/Makefile.am @@ -2,15 +2,16 @@ xlator_LTLIBRARIES = error-gen.la xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/debug -error_gen_la_LDFLAGS = -module -avoidversion +error_gen_la_LDFLAGS = -module -avoid-version error_gen_la_SOURCES = error-gen.c error_gen_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la -noinst_HEADERS = error-gen.h +noinst_HEADERS = error-gen.h error-gen-mem-types.h -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) +AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src + +AM_CFLAGS = -Wall $(GF_CFLAGS) CLEANFILES = diff --git a/xlators/debug/error-gen/src/error-gen-mem-types.h b/xlators/debug/error-gen/src/error-gen-mem-types.h new file mode 100644 index 000000000..f02280535 --- /dev/null +++ b/xlators/debug/error-gen/src/error-gen-mem-types.h @@ -0,0 +1,20 @@ +/* + Copyright (c) 2008-2012 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 __ERROR_GEN_MEM_TYPES_H__ +#define __ERROR_GEN_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_error_gen_mem_types_ { + gf_error_gen_mt_eg_t = gf_common_mt_end + 1, + gf_error_gen_mt_end +}; +#endif diff --git a/xlators/debug/error-gen/src/error-gen.c b/xlators/debug/error-gen/src/error-gen.c index 84a420727..ec0874b35 100644 --- a/xlators/debug/error-gen/src/error-gen.c +++ b/xlators/debug/error-gen/src/error-gen.c @@ -1,22 +1,12 @@ /* - Copyright (c) 2008-2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ + Copyright (c) 2008-2012 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 _CONFIG_H #define _CONFIG_H #include "config.h" @@ -24,6 +14,7 @@ #include "xlator.h" #include "error-gen.h" +#include "statedump.h" sys_error_t error_no_list[] = { [GF_FOP_LOOKUP] = { .error_no_count = 4, @@ -91,9 +82,10 @@ sys_error_t error_no_list[] = { [GF_FOP_READ] = { .error_no_count = 5, .error_no = {EINVAL,EBADF,EFAULT,EISDIR, ENAMETOOLONG}}, - [GF_FOP_WRITE] = { .error_no_count = 5, + [GF_FOP_WRITE] = { .error_no_count = 7, .error_no = {EINVAL,EBADF,EFAULT,EISDIR, - ENAMETOOLONG}}, + ENAMETOOLONG,ENOSPC, + GF_ERROR_SHORT_WRITE}}, [GF_FOP_STATFS] = {.error_no_count = 10, .error_no = {EACCES,EBADF,EFAULT,EINTR, EIO,ENAMETOOLONG,ENOENT, @@ -113,6 +105,15 @@ sys_error_t error_no_list[] = { [GF_FOP_REMOVEXATTR] = { .error_no_count = 4, .error_no = {EACCES,EBADF,ENAMETOOLONG, EINTR}}, + [GF_FOP_FSETXATTR] = { .error_no_count = 4, + .error_no = {EACCES,EBADF,EINTR, + ENAMETOOLONG}}, + [GF_FOP_FGETXATTR] = { .error_no_count = 4, + .error_no = {EACCES,EBADF,ENAMETOOLONG, + EINTR}}, + [GF_FOP_FREMOVEXATTR] = { .error_no_count = 4, + .error_no = {EACCES,EBADF,ENAMETOOLONG, + EINTR}}, [GF_FOP_OPENDIR] = { .error_no_count = 8, .error_no = {EACCES,EEXIST,EFAULT, EISDIR,EMFILE, @@ -237,6 +238,8 @@ conv_errno_to_int (char **error_no) return EINTR; else if (!strcmp ((*error_no), "EFBIG")) return EFBIG; + else if (!strcmp((*error_no), "GF_ERROR_SHORT_WRITE")) + return GF_ERROR_SHORT_WRITE; else return EAGAIN; } @@ -286,6 +289,12 @@ get_fop_int (char **op_no_str) return GF_FOP_GETXATTR; else if (!strcmp ((*op_no_str), "removexattr")) return GF_FOP_REMOVEXATTR; + else if (!strcmp ((*op_no_str), "fsetxattr")) + return GF_FOP_FSETXATTR; + else if (!strcmp ((*op_no_str), "fgetxattr")) + return GF_FOP_FGETXATTR; + else if (!strcmp ((*op_no_str), "fremovexattr")) + return GF_FOP_FREMOVEXATTR; else if (!strcmp ((*op_no_str), "opendir")) return GF_FOP_OPENDIR; else if (!strcmp ((*op_no_str), "readdir")) @@ -362,7 +371,8 @@ error_gen (xlator_t *this, int op_no) rand_no = 0; ret = error_no_list[op_no].error_no[rand_no]; } - egp->failure_iter_no = 3 + (rand () % GF_UNIVERSAL_ANSWER); + if (egp->random_failure == _gf_true) + egp->failure_iter_no = 3 + (rand () % GF_UNIVERSAL_ANSWER); } return ret; } @@ -371,17 +381,17 @@ error_gen (xlator_t *this, int op_no) int error_gen_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, dict_t *dict, struct iatt *postparent) + struct iatt *buf, dict_t *xdata, struct iatt *postparent) { STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, - buf, dict, postparent); - return 0; + buf, xdata, postparent); + return 0; } int error_gen_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, - dict_t *xattr_req) + dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -396,36 +406,28 @@ error_gen_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); STACK_UNWIND_STRICT (lookup, frame, -1, op_errno, NULL, NULL, NULL, - NULL); - return 0; + NULL); + return 0; } STACK_WIND (frame, error_gen_lookup_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->lookup, - loc, xattr_req); - return 0; -} - - -int -error_gen_forget (xlator_t *this, inode_t *inode) -{ - return 0; + loc, xdata); + return 0; } int error_gen_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf) + int32_t op_ret, int32_t op_errno, struct iatt *buf, dict_t *xdata) { - STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, buf); - - return 0; + STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, buf, xdata); + return 0; } int -error_gen_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) +error_gen_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -439,32 +441,31 @@ error_gen_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (stat, frame, -1, op_errno, NULL); - return 0; + STACK_UNWIND_STRICT (stat, frame, -1, op_errno, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_stat_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->stat, - loc); - return 0; + loc, xdata); + return 0; } int error_gen_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *preop, struct iatt *postop) + struct iatt *preop, struct iatt *postop, dict_t *xdata) { - STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno, preop, postop); - - return 0; + STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno, preop, postop, xdata); + return 0; } int error_gen_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct iatt *stbuf, int32_t valid) + struct iatt *stbuf, int32_t valid, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -478,21 +479,21 @@ error_gen_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (setattr, frame, -1, op_errno, NULL, NULL); - return 0; + STACK_UNWIND_STRICT (setattr, frame, -1, op_errno, NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_setattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->setattr, - loc, stbuf, valid); - return 0; + loc, stbuf, valid, xdata); + return 0; } int error_gen_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iatt *stbuf, int32_t valid) + struct iatt *stbuf, int32_t valid, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -506,32 +507,32 @@ error_gen_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (fsetattr, frame, -1, op_errno, NULL, NULL); - return 0; + STACK_UNWIND_STRICT (fsetattr, frame, -1, op_errno, NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_setattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsetattr, - fd, stbuf, valid); - return 0; + fd, stbuf, valid, xdata); + return 0; } int error_gen_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf) + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, - prebuf, postbuf); - return 0; + prebuf, postbuf, xdata); + return 0; } int error_gen_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, - off_t offset) + off_t offset, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -546,32 +547,32 @@ error_gen_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); STACK_UNWIND_STRICT (truncate, frame, -1, op_errno, - NULL, NULL); - return 0; + NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_truncate_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->truncate, - loc, offset); - return 0; + loc, offset, xdata); + return 0; } int error_gen_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf) + struct iatt *postbuf, dict_t *xdata) { STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, - prebuf, postbuf); - return 0; + prebuf, postbuf, xdata); + return 0; } int error_gen_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, - off_t offset) + off_t offset, dict_t *xdata) { int op_errno = 0; eg_t *egp =NULL; @@ -586,31 +587,30 @@ error_gen_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); STACK_UNWIND_STRICT (ftruncate, frame, -1, op_errno, - NULL, NULL); - return 0; + NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_ftruncate_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->ftruncate, - fd, offset); - return 0; + fd, offset, xdata); + return 0; } int error_gen_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - STACK_UNWIND_STRICT (access, frame, op_ret, op_errno); - - return 0; + STACK_UNWIND_STRICT (access, frame, op_ret, op_errno, xdata); + return 0; } int error_gen_access (call_frame_t *frame, xlator_t *this, loc_t *loc, - int32_t mask) + int32_t mask, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -624,31 +624,31 @@ error_gen_access (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (access, frame, -1, op_errno); - return 0; + STACK_UNWIND_STRICT (access, frame, -1, op_errno, xdata); + return 0; } STACK_WIND (frame, error_gen_access_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->access, - loc, mask); - return 0; + loc, mask, xdata); + return 0; } int error_gen_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - const char *path, struct iatt *sbuf) + const char *path, struct iatt *sbuf, dict_t *xdata) { - STACK_UNWIND_STRICT (readlink, frame, op_ret, op_errno, path, sbuf); - return 0; + STACK_UNWIND_STRICT (readlink, frame, op_ret, op_errno, path, sbuf, xdata); + return 0; } int error_gen_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, - size_t size) + size_t size, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -662,15 +662,15 @@ error_gen_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (readlink, frame, -1, op_errno, NULL, NULL); - return 0; + STACK_UNWIND_STRICT (readlink, frame, -1, op_errno, NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_readlink_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readlink, - loc, size); - return 0; + loc, size, xdata); + return 0; } @@ -678,18 +678,18 @@ int error_gen_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, struct iatt *preparent, - struct iatt *postparent) + struct iatt *postparent, dict_t *xdata) { STACK_UNWIND_STRICT (mknod, frame, op_ret, op_errno, inode, buf, - preparent, postparent); - return 0; + preparent, postparent, xdata); + return 0; } int error_gen_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, - mode_t mode, dev_t rdev, dict_t *params) + mode_t mode, dev_t rdev, mode_t umask, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -704,15 +704,15 @@ error_gen_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); STACK_UNWIND_STRICT (mknod, frame, -1, op_errno, NULL, NULL, - NULL, NULL); - return 0; + NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_mknod_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mknod, - loc, mode, rdev, params); - return 0; + loc, mode, rdev, umask, xdata); + return 0; } @@ -720,17 +720,17 @@ int error_gen_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, struct iatt *preparent, - struct iatt *postparent) + struct iatt *postparent, dict_t *xdata) { STACK_UNWIND_STRICT (mkdir, frame, op_ret, op_errno, inode, buf, - preparent, postparent); - return 0; + preparent, postparent, xdata); + return 0; } int error_gen_mkdir (call_frame_t *frame, xlator_t *this, - loc_t *loc, mode_t mode, dict_t *params) + loc_t *loc, mode_t mode, mode_t umask, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -745,31 +745,32 @@ error_gen_mkdir (call_frame_t *frame, xlator_t *this, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); STACK_UNWIND_STRICT (mkdir, frame, -1, op_errno, NULL, NULL, - NULL, NULL); - return 0; + NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_mkdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mkdir, - loc, mode, params); - return 0; + loc, mode, umask, xdata); + return 0; } int error_gen_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, - preparent, postparent); - return 0; + preparent, postparent, xdata); + return 0; } int -error_gen_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) +error_gen_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, + dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -783,31 +784,34 @@ error_gen_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (unlink, frame, -1, op_errno, NULL, NULL); - return 0; + STACK_UNWIND_STRICT (unlink, frame, -1, op_errno, NULL, NULL, + xdata); + return 0; } STACK_WIND (frame, error_gen_unlink_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->unlink, - loc); - return 0; + loc, xflag, xdata); + return 0; } int error_gen_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { STACK_UNWIND_STRICT (rmdir, frame, op_ret, op_errno, - preparent, postparent); - return 0; + preparent, postparent, xdata); + return 0; } int -error_gen_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags) +error_gen_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, + dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -821,15 +825,15 @@ error_gen_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags) if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (rmdir, frame, -1, op_errno, NULL, NULL); - return 0; + STACK_UNWIND_STRICT (rmdir, frame, -1, op_errno, NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_rmdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->rmdir, - loc, flags); - return 0; + loc, flags, xdata); + return 0; } @@ -837,17 +841,17 @@ int error_gen_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, struct iatt *preparent, - struct iatt *postparent) + struct iatt *postparent, dict_t *xdata) { STACK_UNWIND_STRICT (symlink, frame, op_ret, op_errno, inode, buf, - preparent, postparent); - return 0; + preparent, postparent, xdata); + return 0; } int error_gen_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath, - loc_t *loc, dict_t *params) + loc_t *loc, mode_t umask, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -862,15 +866,15 @@ error_gen_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); STACK_UNWIND_STRICT (symlink, frame, -1, op_errno, NULL, NULL, - NULL, NULL); /* pre & post parent attr */ + NULL, NULL, NULL); /* pre & post parent attr */ return 0; } STACK_WIND (frame, error_gen_symlink_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->symlink, - linkpath, loc, params); - return 0; + linkpath, loc, umask, xdata); + return 0; } @@ -878,18 +882,19 @@ int error_gen_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iatt *buf, struct iatt *preoldparent, struct iatt *postoldparent, - struct iatt *prenewparent, struct iatt *postnewparent) + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t *xdata) { STACK_UNWIND_STRICT (rename, frame, op_ret, op_errno, buf, preoldparent, postoldparent, - prenewparent, postnewparent); - return 0; + prenewparent, postnewparent, xdata); + return 0; } int error_gen_rename (call_frame_t *frame, xlator_t *this, - loc_t *oldloc, loc_t *newloc) + loc_t *oldloc, loc_t *newloc, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -904,15 +909,15 @@ error_gen_rename (call_frame_t *frame, xlator_t *this, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); STACK_UNWIND_STRICT (rename, frame, -1, op_errno, NULL, - NULL, NULL, NULL, NULL); /* pre & post parent attr */ + NULL, NULL, NULL, NULL, NULL); return 0; } STACK_WIND (frame, error_gen_rename_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->rename, - oldloc, newloc); - return 0; + oldloc, newloc, xdata); + return 0; } @@ -920,17 +925,17 @@ int error_gen_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, struct iatt *preparent, - struct iatt *postparent) + struct iatt *postparent, dict_t *xdata) { STACK_UNWIND_STRICT (link, frame, op_ret, op_errno, inode, buf, - preparent, postparent); - return 0; + preparent, postparent, xdata); + return 0; } int error_gen_link (call_frame_t *frame, xlator_t *this, - loc_t *oldloc, loc_t *newloc) + loc_t *oldloc, loc_t *newloc, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -945,15 +950,15 @@ error_gen_link (call_frame_t *frame, xlator_t *this, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); STACK_UNWIND_STRICT (link, frame, -1, op_errno, NULL, NULL, - NULL, NULL); /* pre & post parent attr */ + NULL, NULL, NULL); return 0; } STACK_WIND (frame, error_gen_link_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->link, - oldloc, newloc); - return 0; + oldloc, newloc, xdata); + return 0; } @@ -961,17 +966,18 @@ int error_gen_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf, - preparent, postparent); - return 0; + preparent, postparent, xdata); + return 0; } int error_gen_create (call_frame_t *frame, xlator_t *this, loc_t *loc, - int32_t flags, mode_t mode, fd_t *fd, dict_t *params) + int32_t flags, mode_t mode, mode_t umask, fd_t *fd, + dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -986,30 +992,30 @@ error_gen_create (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); STACK_UNWIND_STRICT (create, frame, -1, op_errno, NULL, NULL, - NULL, NULL, NULL); /* pre & post attr */ + NULL, NULL, NULL, NULL); return 0; } STACK_WIND (frame, error_gen_create_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->create, - loc, flags, mode, fd, params); - return 0; + loc, flags, mode, umask, fd, xdata); + return 0; } int error_gen_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { - STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd); - return 0; + STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd, xdata); + return 0; } int error_gen_open (call_frame_t *frame, xlator_t *this, loc_t *loc, - int32_t flags, fd_t *fd, int32_t wbflags) + int32_t flags, fd_t *fd, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1023,15 +1029,15 @@ error_gen_open (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (open, frame, -1, op_errno, NULL); - return 0; + STACK_UNWIND_STRICT (open, frame, -1, op_errno, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_open_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->open, - loc, flags, fd, wbflags); - return 0; + loc, flags, fd, xdata); + return 0; } @@ -1039,17 +1045,17 @@ int error_gen_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iovec *vector, int32_t count, - struct iatt *stbuf, struct iobref *iobref) + struct iatt *stbuf, struct iobref *iobref, dict_t *xdata) { STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, - vector, count, stbuf, iobref); - return 0; + vector, count, stbuf, iobref, xdata); + return 0; } int error_gen_readv (call_frame_t *frame, xlator_t *this, - fd_t *fd, size_t size, off_t offset) + fd_t *fd, size_t size, off_t offset, uint32_t flags, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1064,33 +1070,33 @@ error_gen_readv (call_frame_t *frame, xlator_t *this, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); STACK_UNWIND_STRICT (readv, frame, -1, op_errno, NULL, 0, - NULL, NULL); - return 0; + NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_readv_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readv, - fd, size, offset); - return 0; + fd, size, offset, flags, xdata); + return 0; } int error_gen_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf) + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { - STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf); - return 0; + STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf, xdata); + return 0; } int error_gen_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector, int32_t count, - off_t off, struct iobref *iobref) + off_t off, uint32_t flags, struct iobref *iobref, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1102,31 +1108,47 @@ error_gen_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, if (enable) op_errno = error_gen (this, GF_FOP_WRITE); - if (op_errno) { - GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (writev, frame, -1, op_errno, NULL, NULL); + if (op_errno == GF_ERROR_SHORT_WRITE) { + struct iovec *shortvec; + + /* + * A short write error returns some value less than what was + * requested from a write. To simulate this, replace the vector + * with one half the size; + */ + shortvec = iov_dup(vector, 1); + shortvec->iov_len /= 2; + + STACK_WIND(frame, error_gen_writev_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->writev, fd, shortvec, count, + off, flags, iobref, xdata); + GF_FREE(shortvec); return 0; + } else if (op_errno) { + GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); + STACK_UNWIND_STRICT (writev, frame, -1, op_errno, NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_writev_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->writev, - fd, vector, count, off, iobref); - return 0; + fd, vector, count, off, flags, iobref, xdata); + return 0; } int error_gen_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno); - return 0; + STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno, xdata); + return 0; } int -error_gen_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) +error_gen_flush (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1140,15 +1162,15 @@ error_gen_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (flush, frame, -1, op_errno); - return 0; + STACK_UNWIND_STRICT (flush, frame, -1, op_errno, xdata); + return 0; } STACK_WIND (frame, error_gen_flush_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->flush, - fd); - return 0; + fd, xdata); + return 0; } @@ -1156,15 +1178,15 @@ int error_gen_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf) + struct iatt *postbuf, dict_t *xdata) { - STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, prebuf, postbuf); - return 0; + STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, prebuf, postbuf, xdata); + return 0; } int -error_gen_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) +error_gen_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1178,29 +1200,29 @@ error_gen_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (fsync, frame, -1, op_errno, NULL, NULL); - return 0; + STACK_UNWIND_STRICT (fsync, frame, -1, op_errno, NULL, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_fsync_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsync, - fd, flags); - return 0; + fd, flags, xdata); + return 0; } int error_gen_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf) + int32_t op_ret, int32_t op_errno, struct iatt *buf, dict_t *xdata) { - STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf); - return 0; + STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf, xdata); + return 0; } int -error_gen_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) +error_gen_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1214,29 +1236,29 @@ error_gen_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (fstat, frame, -1, op_errno, NULL); - return 0; + STACK_UNWIND_STRICT (fstat, frame, -1, op_errno, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_fstat_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fstat, - fd); - return 0; + fd, xdata); + return 0; } int error_gen_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { - STACK_UNWIND_STRICT (opendir, frame, op_ret, op_errno, fd); - return 0; + STACK_UNWIND_STRICT (opendir, frame, op_ret, op_errno, fd, xdata); + return 0; } int -error_gen_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd) +error_gen_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1250,29 +1272,29 @@ error_gen_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd) if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (opendir, frame, -1, op_errno, NULL); - return 0; + STACK_UNWIND_STRICT (opendir, frame, -1, op_errno, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_opendir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->opendir, - loc, fd); - return 0; + loc, fd, xdata); + return 0; } int error_gen_fsyncdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - STACK_UNWIND_STRICT (fsyncdir, frame, op_ret, op_errno); - return 0; + STACK_UNWIND_STRICT (fsyncdir, frame, op_ret, op_errno, xdata); + return 0; } int error_gen_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, - int32_t flags) + int32_t flags, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1286,30 +1308,29 @@ error_gen_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (fsyncdir, frame, -1, op_errno); - return 0; + STACK_UNWIND_STRICT (fsyncdir, frame, -1, op_errno, xdata); + return 0; } STACK_WIND (frame, error_gen_fsyncdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsyncdir, - fd, flags); - return 0; + fd, flags, xdata); + return 0; } int error_gen_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct statvfs *buf) + int32_t op_ret, int32_t op_errno, struct statvfs *buf, dict_t *xdata) { - STACK_UNWIND_STRICT (statfs, frame, op_ret, op_errno, buf); - - return 0; + STACK_UNWIND_STRICT (statfs, frame, op_ret, op_errno, buf, xdata); + return 0; } int -error_gen_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) +error_gen_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1323,31 +1344,30 @@ error_gen_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (statfs, frame, -1, op_errno, NULL); - return 0; + STACK_UNWIND_STRICT (statfs, frame, -1, op_errno, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_statfs_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->statfs, - loc); - return 0; + loc, xdata); + return 0; } int error_gen_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno); - - return 0; + STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata); + return 0; } int error_gen_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - dict_t *dict, int32_t flags) + dict_t *dict, int32_t flags, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1361,30 +1381,30 @@ error_gen_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (setxattr, frame, -1, op_errno); - return 0; + STACK_UNWIND_STRICT (setxattr, frame, -1, op_errno, xdata); + return 0; } STACK_WIND (frame, error_gen_setxattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->setxattr, - loc, dict, flags); - return 0; + loc, dict, flags, xdata); + return 0; } int error_gen_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) + int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata) { - STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict); - return 0; + STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict, xdata); + return 0; } int error_gen_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name) + const char *name, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1398,31 +1418,103 @@ error_gen_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (getxattr, frame, -1, op_errno, NULL); - return 0; + STACK_UNWIND_STRICT (getxattr, frame, -1, op_errno, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_getxattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->getxattr, - loc, name); - return 0; + loc, name, xdata); + return 0; +} + +int +error_gen_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, xdata); + return 0; } int -error_gen_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) +error_gen_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + dict_t *dict, int32_t flags, dict_t *xdata) { - STACK_UNWIND_STRICT (xattrop, frame, op_ret, op_errno, dict); + int op_errno = 0; + eg_t *egp = NULL; + int enable = 1; - return 0; + egp = this->private; + enable = egp->enable[GF_FOP_FSETXATTR]; + + if (enable) + op_errno = error_gen (this, GF_FOP_FSETXATTR); + + if (op_errno) { + GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); + STACK_UNWIND_STRICT (fsetxattr, frame, -1, op_errno, xdata); + return 0; + } + + STACK_WIND (frame, error_gen_fsetxattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fsetxattr, + fd, dict, flags, xdata); + return 0; +} + + +int +error_gen_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata) +{ + STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, dict, xdata); + return 0; +} + + +int +error_gen_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) +{ + int op_errno = 0; + eg_t *egp = NULL; + int enable = 1; + + egp = this->private; + enable = egp->enable[GF_FOP_FGETXATTR]; + + if (enable) + op_errno = error_gen (this, GF_FOP_FGETXATTR); + + if (op_errno) { + GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); + STACK_UNWIND_STRICT (fgetxattr, frame, -1, op_errno, NULL, xdata); + return 0; + } + + STACK_WIND (frame, error_gen_fgetxattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fgetxattr, + fd, name, xdata); + return 0; +} + + +int +error_gen_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata) +{ + STACK_UNWIND_STRICT (xattrop, frame, op_ret, op_errno, dict, xdata); + return 0; } int error_gen_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, - gf_xattrop_flags_t flags, dict_t *dict) + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1436,31 +1528,30 @@ error_gen_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (xattrop, frame, -1, op_errno, NULL); - return 0; + STACK_UNWIND_STRICT (xattrop, frame, -1, op_errno, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_xattrop_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->xattrop, - loc, flags, dict); - return 0; + loc, flags, dict, xdata); + return 0; } int error_gen_fxattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) + int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata) { - STACK_UNWIND_STRICT (fxattrop, frame, op_ret, op_errno, dict); - - return 0; + STACK_UNWIND_STRICT (fxattrop, frame, op_ret, op_errno, dict, xdata); + return 0; } int error_gen_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, - gf_xattrop_flags_t flags, dict_t *dict) + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1474,31 +1565,30 @@ error_gen_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (fxattrop, frame, -1, op_errno, NULL); - return 0; + STACK_UNWIND_STRICT (fxattrop, frame, -1, op_errno, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_fxattrop_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fxattrop, - fd, flags, dict); - return 0; + fd, flags, dict, xdata); + return 0; } int error_gen_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno); - - return 0; + STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno, xdata); + return 0; } int error_gen_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name) + const char *name, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1512,30 +1602,66 @@ error_gen_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (removexattr, frame, -1, op_errno); - return 0; + STACK_UNWIND_STRICT (removexattr, frame, -1, op_errno, xdata); + return 0; } STACK_WIND (frame, error_gen_removexattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->removexattr, - loc, name); - return 0; + loc, name, xdata); + return 0; +} + +int +error_gen_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + STACK_UNWIND_STRICT (fremovexattr, frame, op_ret, op_errno, xdata); + return 0; +} + + +int +error_gen_fremovexattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) +{ + int op_errno = 0; + eg_t *egp = NULL; + int enable = 1; + + egp = this->private; + enable = egp->enable[GF_FOP_FREMOVEXATTR]; + + if (enable) + op_errno = error_gen (this, GF_FOP_FREMOVEXATTR); + + if (op_errno) { + GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); + STACK_UNWIND_STRICT (fremovexattr, frame, -1, op_errno, xdata); + return 0; + } + + STACK_WIND (frame, error_gen_fremovexattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fremovexattr, + fd, name, xdata); + return 0; } int error_gen_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct gf_flock *lock) + int32_t op_ret, int32_t op_errno, struct gf_flock *lock, dict_t *xdata) { - STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, lock); - return 0; + STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, lock, xdata); + return 0; } int error_gen_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, - struct gf_flock *lock) + struct gf_flock *lock, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1549,32 +1675,31 @@ error_gen_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (lk, frame, -1, op_errno, NULL); - return 0; + STACK_UNWIND_STRICT (lk, frame, -1, op_errno, NULL, xdata); + return 0; } STACK_WIND (frame, error_gen_lk_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->lk, - fd, cmd, lock); - return 0; + fd, cmd, lock, xdata); + return 0; } int -error_gen_inodelk_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, int32_t op_errno) - +error_gen_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - STACK_UNWIND_STRICT (inodelk, frame, op_ret, op_errno); - return 0; + STACK_UNWIND_STRICT (inodelk, frame, op_ret, op_errno, xdata); + return 0; } int error_gen_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, loc_t *loc, int32_t cmd, - struct gf_flock *lock) + struct gf_flock *lock, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1588,32 +1713,31 @@ error_gen_inodelk (call_frame_t *frame, xlator_t *this, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (inodelk, frame, -1, op_errno); - return 0; + STACK_UNWIND_STRICT (inodelk, frame, -1, op_errno, xdata); + return 0; } STACK_WIND (frame, error_gen_inodelk_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->inodelk, - volume, loc, cmd, lock); - return 0; + volume, loc, cmd, lock, xdata); + return 0; } int -error_gen_finodelk_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, int32_t op_errno) - +error_gen_finodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - STACK_UNWIND_STRICT (finodelk, frame, op_ret, op_errno); - return 0; + STACK_UNWIND_STRICT (finodelk, frame, op_ret, op_errno, xdata); + return 0; } int error_gen_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, fd_t *fd, int32_t cmd, - struct gf_flock *lock) + struct gf_flock *lock, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1627,32 +1751,31 @@ error_gen_finodelk (call_frame_t *frame, xlator_t *this, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (finodelk, frame, -1, op_errno); - return 0; + STACK_UNWIND_STRICT (finodelk, frame, -1, op_errno, xdata); + return 0; } STACK_WIND (frame, error_gen_finodelk_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->finodelk, - volume, fd, cmd, lock); - return 0; + volume, fd, cmd, lock, xdata); + return 0; } int -error_gen_entrylk_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, int32_t op_errno) - +error_gen_entrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - STACK_UNWIND_STRICT (entrylk, frame, op_ret, op_errno); - return 0; + STACK_UNWIND_STRICT (entrylk, frame, op_ret, op_errno, xdata); + return 0; } int error_gen_entrylk (call_frame_t *frame, xlator_t *this, const char *volume, loc_t *loc, const char *basename, - entrylk_cmd cmd, entrylk_type type) + entrylk_cmd cmd, entrylk_type type, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1666,32 +1789,31 @@ error_gen_entrylk (call_frame_t *frame, xlator_t *this, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (entrylk, frame, -1, op_errno); - return 0; + STACK_UNWIND_STRICT (entrylk, frame, -1, op_errno, xdata); + return 0; } STACK_WIND (frame, error_gen_entrylk_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->entrylk, - volume, loc, basename, cmd, type); - return 0; + volume, loc, basename, cmd, type, xdata); + return 0; } int -error_gen_fentrylk_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, int32_t op_errno) - +error_gen_fentrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - STACK_UNWIND_STRICT (fentrylk, frame, op_ret, op_errno); - return 0; + STACK_UNWIND_STRICT (fentrylk, frame, op_ret, op_errno, xdata); + return 0; } int error_gen_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume, fd_t *fd, const char *basename, - entrylk_cmd cmd, entrylk_type type) + entrylk_cmd cmd, entrylk_type type, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1705,15 +1827,15 @@ error_gen_fentrylk (call_frame_t *frame, xlator_t *this, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (fentrylk, frame, -1, op_errno); - return 0; + STACK_UNWIND_STRICT (fentrylk, frame, -1, op_errno, xdata); + return 0; } STACK_WIND (frame, error_gen_fentrylk_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fentrylk, - volume, fd, basename, cmd, type); - return 0; + volume, fd, basename, cmd, type, xdata); + return 0; } @@ -1725,8 +1847,7 @@ error_gen_getspec_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, char *spec_data) { STACK_UNWIND_STRICT (getspec, frame, op_ret, op_errno, spec_data); - - return 0; + return 0; } @@ -1760,16 +1881,17 @@ error_gen_getspec (call_frame_t *frame, xlator_t *this, const char *key, int error_gen_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *entries) + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) { - STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, entries); + STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, entries, xdata); return 0; } int error_gen_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, - size_t size, off_t off) + size_t size, off_t off, dict_t *xdata) { int op_errno = 0; eg_t *egp = NULL; @@ -1783,30 +1905,31 @@ error_gen_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (readdir, frame, -1, op_errno, NULL); + STACK_UNWIND_STRICT (readdir, frame, -1, op_errno, NULL, xdata); return 0; } STACK_WIND (frame, error_gen_readdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readdir, - fd, size, off); + fd, size, off, xdata); return 0; } int error_gen_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *entries) + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) { - STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno, entries); + STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno, entries, xdata); return 0; } int error_gen_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t off) + off_t off, dict_t *dict) { int op_errno = 0; eg_t *egp = NULL; @@ -1820,44 +1943,153 @@ error_gen_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND_STRICT (readdirp, frame, -1, op_errno, NULL); + STACK_UNWIND_STRICT (readdirp, frame, -1, op_errno, NULL, NULL); return 0; } STACK_WIND (frame, error_gen_readdirp_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readdirp, - fd, size, off); + fd, size, off, dict); return 0; } +static void +error_gen_set_failure (eg_t *pvt, int percent) +{ + GF_ASSERT (pvt); -int -error_gen_closedir (xlator_t *this, fd_t *fd) + if (percent) + pvt->failure_iter_no = 100/percent; + else + pvt->failure_iter_no = 100/GF_FAILURE_DEFAULT; +} + +static void +error_gen_parse_fill_fops (eg_t *pvt, char *enable_fops) { - return 0; + char *op_no_str = NULL; + int op_no = -1; + int i = 0; + xlator_t *this = THIS; + char *saveptr = NULL; + + GF_ASSERT (pvt); + GF_ASSERT (this); + + for (i = 0; i < GF_FOP_MAXVALUE; i++) + pvt->enable[i] = 0; + + if (!enable_fops) { + gf_log (this->name, GF_LOG_WARNING, + "All fops are enabled."); + for (i = 0; i < GF_FOP_MAXVALUE; i++) + pvt->enable[i] = 1; + } else { + op_no_str = strtok_r (enable_fops, ",", &saveptr); + while (op_no_str) { + op_no = get_fop_int (&op_no_str); + if (op_no == -1) { + gf_log (this->name, GF_LOG_WARNING, + "Wrong option value %s", op_no_str); + } else + pvt->enable[op_no] = 1; + + op_no_str = strtok_r (NULL, ",", &saveptr); + } + } } +int32_t +error_gen_priv_dump (xlator_t *this) +{ + char key_prefix[GF_DUMP_MAX_BUF_LEN]; + int ret = -1; + eg_t *conf = NULL; -int -error_gen_close (xlator_t *this, fd_t *fd) + if (!this) + goto out; + + conf = this->private; + if (!conf) + goto out; + + ret = TRY_LOCK(&conf->lock); + if (ret != 0) { + return ret; + } + + gf_proc_dump_add_section("xlator.debug.error-gen.%s.priv", this->name); + gf_proc_dump_build_key(key_prefix,"xlator.debug.error-gen","%s.priv", + this->name); + + gf_proc_dump_write("op_count", "%d", conf->op_count); + gf_proc_dump_write("failure_iter_no", "%d", conf->failure_iter_no); + gf_proc_dump_write("error_no", "%s", conf->error_no); + gf_proc_dump_write("random_failure", "%d", conf->random_failure); + + UNLOCK(&conf->lock); +out: + return ret; +} + +int32_t +mem_acct_init (xlator_t *this) { - return 0; + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_error_gen_mt_end + 1); + + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" + " failed"); + return ret; + } + + return ret; } +int +reconfigure (xlator_t *this, dict_t *options) +{ + eg_t *pvt = NULL; + int32_t ret = 0; + char *error_enable_fops = NULL; + int32_t failure_percent_int = 0; + + if (!this || !this->private) + goto out; + + pvt = this->private; + + GF_OPTION_RECONF ("error-no", pvt->error_no, options, str, out); + + GF_OPTION_RECONF ("failure", failure_percent_int, options, int32, + out); + + GF_OPTION_RECONF ("enable", error_enable_fops, options, str, out); + + GF_OPTION_RECONF ("random-failure", pvt->random_failure, options, + bool, out); + + error_gen_parse_fill_fops (pvt, error_enable_fops); + error_gen_set_failure (pvt, failure_percent_int); + + ret = 0; +out: + gf_log (this->name, GF_LOG_DEBUG, "reconfigure returning %d", ret); + return ret; +} int init (xlator_t *this) { eg_t *pvt = NULL; - data_t *error_no = NULL; - data_t *failure_percent = NULL; - data_t *enable = NULL; int32_t ret = 0; char *error_enable_fops = NULL; - char *op_no_str = NULL; - int op_no = -1; - int i = 0; int32_t failure_percent_int = 0; if (!this->children || this->children->next) { @@ -1872,74 +2104,34 @@ init (xlator_t *this) "dangling volume. check volfile "); } - error_no = dict_get (this->options, "error-no"); - failure_percent = dict_get (this->options, "failure"); - enable = dict_get (this->options, "enable"); - - pvt = CALLOC (1, sizeof (eg_t)); + pvt = GF_CALLOC (1, sizeof (eg_t), gf_error_gen_mt_eg_t); if (!pvt) { - gf_log (this->name, GF_LOG_ERROR, - "out of memory."); ret = -1; goto out; } LOCK_INIT (&pvt->lock); - for (i = 0; i < GF_FOP_MAXVALUE; i++) - pvt->enable[i] = 0; - if (!error_no) { - gf_log (this->name, GF_LOG_DEBUG, - "error-no not specified."); - } else { - pvt->error_no = data_to_str (error_no); - } + GF_OPTION_INIT ("error-no", pvt->error_no, str, out); - if (!failure_percent) { - gf_log (this->name, GF_LOG_DEBUG, - "failure percent not specified."); - pvt->failure_iter_no = 100/GF_FAILURE_DEFAULT; - } else { - failure_percent_int = data_to_int32 (failure_percent); - if (failure_percent_int) - pvt->failure_iter_no = 100/failure_percent_int; - else - pvt->failure_iter_no = 100/GF_FAILURE_DEFAULT; - } + GF_OPTION_INIT ("failure", failure_percent_int, int32, out); + + GF_OPTION_INIT ("enable", error_enable_fops, str, out); + + GF_OPTION_INIT ("random-failure", pvt->random_failure, bool, out); + + + error_gen_parse_fill_fops (pvt, error_enable_fops); + error_gen_set_failure (pvt, failure_percent_int); - if (!enable) { - gf_log (this->name, GF_LOG_WARNING, - "All fops are enabled."); - for (i = 0; i < GF_FOP_MAXVALUE; i++) - pvt->enable[i] = 1; - } else { - error_enable_fops = data_to_str (enable); - op_no_str = error_enable_fops; - while ((*error_enable_fops) != '\0') { - error_enable_fops++; - if (((*error_enable_fops) == ',') || - ((*error_enable_fops) == '\0')) { - if ((*error_enable_fops) != '\0') { - (*error_enable_fops) = '\0'; - error_enable_fops++; - } - op_no = get_fop_int (&op_no_str); - if (op_no == -1) { - gf_log (this->name, GF_LOG_WARNING, - "Wrong option value %s", - op_no_str); - } else - pvt->enable[op_no] = 1; - op_no_str = error_enable_fops; - } - } - } this->private = pvt; /* Give some seed value here */ srand (time(NULL)); out: + if (ret) + GF_FREE (pvt); return ret; } @@ -1955,12 +2147,18 @@ fini (xlator_t *this) if (pvt) { LOCK_DESTROY (&pvt->lock); - FREE (pvt); + GF_FREE (pvt); gf_log (this->name, GF_LOG_DEBUG, "fini called"); } return; } +struct xlator_dumpops dumpops = { + .priv = error_gen_priv_dump, +}; + +struct xlator_fops cbks; + struct xlator_fops fops = { .lookup = error_gen_lookup, .stat = error_gen_stat, @@ -1983,6 +2181,9 @@ struct xlator_fops fops = { .setxattr = error_gen_setxattr, .getxattr = error_gen_getxattr, .removexattr = error_gen_removexattr, + .fsetxattr = error_gen_fsetxattr, + .fgetxattr = error_gen_fgetxattr, + .fremovexattr = error_gen_fremovexattr, .opendir = error_gen_opendir, .readdir = error_gen_readdir, .readdirp = error_gen_readdirp, @@ -2003,22 +2204,29 @@ struct xlator_fops fops = { .getspec = error_gen_getspec, }; -struct xlator_cbks cbks = { - .release = error_gen_close, - .releasedir = error_gen_closedir, -}; - struct volume_options options[] = { { .key = {"failure"}, - .type = GF_OPTION_TYPE_INT }, + .type = GF_OPTION_TYPE_INT, + .description = "Percentage failure of operations when enabled.", + }, + { .key = {"error-no"}, .value = {"ENOENT","ENOTDIR","ENAMETOOLONG","EACCES","EBADF", "EFAULT","ENOMEM","EINVAL","EIO","EEXIST","ENOSPC", "EPERM","EROFS","EBUSY","EISDIR","ENOTEMPTY","EMLINK" "ENODEV","EXDEV","EMFILE","ENFILE","ENOSYS","EINTR", - "EFBIG","EAGAIN"}, - .type = GF_OPTION_TYPE_STR }, + "EFBIG","EAGAIN","GF_ERROR_SHORT_WRITE"}, + .type = GF_OPTION_TYPE_STR, + }, + + { .key = {"random-failure"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + }, + { .key = {"enable"}, - .type = GF_OPTION_TYPE_STR }, + .type = GF_OPTION_TYPE_STR, + }, + { .key = {NULL} } }; diff --git a/xlators/debug/error-gen/src/error-gen.h b/xlators/debug/error-gen/src/error-gen.h index 1c902cf4f..d92c23062 100644 --- a/xlators/debug/error-gen/src/error-gen.h +++ b/xlators/debug/error-gen/src/error-gen.h @@ -1,22 +1,12 @@ /* - Copyright (c) 2008-2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ + Copyright (c) 2008-2012 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 _ERROR_GEN_H #define _ERROR_GEN_H @@ -25,13 +15,28 @@ #include "config.h" #endif +#include "error-gen-mem-types.h" + #define GF_FAILURE_DEFAULT 10 +/* + * Pseudo-errors refer to errors beyond the scope of traditional <-1, op_errno> + * returns. This facilitates the ability to return unexpected, but not -1 values + * and/or to inject operations that lead to implicit error conditions. The range + * for pseudo errors resides at a high value to avoid conflicts with the errno + * range. + */ +enum GF_PSEUDO_ERRORS { + GF_ERROR_SHORT_WRITE = 1000, /* short writev return value */ + GF_ERROR_MAX +}; + typedef struct { int enable[GF_FOP_MAXVALUE]; int op_count; int failure_iter_no; char *error_no; + gf_boolean_t random_failure; gf_lock_t lock; } eg_t; diff --git a/xlators/debug/io-stats/src/Makefile.am b/xlators/debug/io-stats/src/Makefile.am index b894e79c3..332d79015 100644 --- a/xlators/debug/io-stats/src/Makefile.am +++ b/xlators/debug/io-stats/src/Makefile.am @@ -2,14 +2,15 @@ xlator_LTLIBRARIES = io-stats.la xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/debug -io_stats_la_LDFLAGS = -module -avoidversion +io_stats_la_LDFLAGS = -module -avoid-version io_stats_la_SOURCES = io-stats.c io_stats_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la noinst_HEADERS = io-stats-mem-types.h -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) +AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src + +AM_CFLAGS = -Wall $(GF_CFLAGS) CLEANFILES = diff --git a/xlators/debug/io-stats/src/io-stats-mem-types.h b/xlators/debug/io-stats/src/io-stats-mem-types.h index 0c711029a..c30dfb17e 100644 --- a/xlators/debug/io-stats/src/io-stats-mem-types.h +++ b/xlators/debug/io-stats/src/io-stats-mem-types.h @@ -1,24 +1,13 @@ - /* - Copyright (c) 2008-2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 __IO_STATS_MEM_TYPES_H__ #define __IO_STATS_MEM_TYPES_H__ @@ -27,6 +16,8 @@ enum gf_io_stats_mem_types_ { gf_io_stats_mt_ios_conf = gf_common_mt_end + 1, gf_io_stats_mt_ios_fd, + gf_io_stats_mt_ios_stat, + gf_io_stats_mt_ios_stat_list, gf_io_stats_mt_end }; #endif diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c index 90f02b6ee..7fb697ae4 100644 --- a/xlators/debug/io-stats/src/io-stats.c +++ b/xlators/debug/io-stats/src/io-stats.c @@ -1,22 +1,12 @@ /* - Copyright (c) 2006-2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ + Copyright (c) 2006-2012 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 _CONFIG_H #define _CONFIG_H #include "config.h" @@ -43,6 +33,56 @@ #include "glusterfs.h" #include "xlator.h" #include "io-stats-mem-types.h" +#include <stdarg.h> +#include "defaults.h" +#include "logging.h" + +#define MAX_LIST_MEMBERS 100 + +typedef enum { + IOS_STATS_TYPE_NONE, + IOS_STATS_TYPE_OPEN, + IOS_STATS_TYPE_READ, + IOS_STATS_TYPE_WRITE, + IOS_STATS_TYPE_OPENDIR, + IOS_STATS_TYPE_READDIRP, + IOS_STATS_TYPE_READ_THROUGHPUT, + IOS_STATS_TYPE_WRITE_THROUGHPUT, + IOS_STATS_TYPE_MAX +}ios_stats_type_t; + +typedef enum { + IOS_STATS_THRU_READ, + IOS_STATS_THRU_WRITE, + IOS_STATS_THRU_MAX, +}ios_stats_thru_t; + +struct ios_stat_lat { + struct timeval time; + double throughput; +}; + +struct ios_stat { + gf_lock_t lock; + uuid_t gfid; + char *filename; + uint64_t counters [IOS_STATS_TYPE_MAX]; + struct ios_stat_lat thru_counters [IOS_STATS_THRU_MAX]; + int refcnt; +}; + +struct ios_stat_list { + struct list_head list; + struct ios_stat *iosstat; + double value; +}; + +struct ios_stat_head { + gf_lock_t lock; + double min_cnt; + uint64_t members; + struct ios_stat_list *iosstats; +}; struct ios_lat { double min; @@ -58,6 +98,9 @@ struct ios_global_stats { uint64_t fop_hits[GF_FOP_MAXVALUE]; struct timeval started_at; struct ios_lat latency[GF_FOP_MAXVALUE]; + uint64_t nr_opens; + uint64_t max_nr_opens; + struct timeval max_openfd_time; }; @@ -67,7 +110,10 @@ struct ios_conf { uint64_t increment; struct ios_global_stats incremental; gf_boolean_t dump_fd_stats; - int measure_latency; + gf_boolean_t count_fop_hits; + gf_boolean_t measure_latency; + struct ios_stat_head list[IOS_STATS_TYPE_MAX]; + struct ios_stat_head thru_list[IOS_STATS_THRU_MAX]; }; @@ -80,31 +126,60 @@ struct ios_fd { struct timeval opened_at; }; +typedef enum { + IOS_DUMP_TYPE_NONE = 0, + IOS_DUMP_TYPE_FILE = 1, + IOS_DUMP_TYPE_DICT = 2, + IOS_DUMP_TYPE_MAX = 3 +} ios_dump_type_t; + +struct ios_dump_args { + ios_dump_type_t type; + union { + FILE *logfp; + dict_t *dict; + } u; +}; + +typedef int (*block_dump_func) (xlator_t *, struct ios_dump_args*, + int , int , uint64_t ) ; struct ios_local { struct timeval wind_at; struct timeval unwind_at; }; +struct volume_options options[]; + +inline static int +is_fop_latency_started (call_frame_t *frame) +{ + GF_ASSERT (frame); + struct timeval epoch = {0,}; + return memcmp (&frame->begin, &epoch, sizeof (epoch)); +} + #define END_FOP_LATENCY(frame, op) \ do { \ struct ios_conf *conf = NULL; \ \ conf = this->private; \ - if (conf->measure_latency) { \ - gettimeofday (&frame->end, NULL); \ + if (conf && conf->measure_latency) { \ + gettimeofday (&frame->end, NULL); \ update_ios_latency (conf, frame, GF_FOP_##op); \ } \ } while (0) -#define START_FOP_LATENCY(frame) \ - do { \ - struct ios_conf *conf = NULL; \ - \ - conf = this->private; \ - if (conf->measure_latency) { \ - gettimeofday (&frame->begin, NULL); \ - } \ +#define START_FOP_LATENCY(frame) \ + do { \ + struct ios_conf *conf = NULL; \ + \ + conf = this->private; \ + if (conf && conf->measure_latency) { \ + gettimeofday (&frame->begin, NULL); \ + } else { \ + memset (&frame->begin, 0, sizeof (frame->begin));\ + } \ } while (0) @@ -113,14 +188,30 @@ struct ios_local { struct ios_conf *conf = NULL; \ \ conf = this->private; \ - LOCK (&conf->lock); \ - { \ - conf->cumulative.fop_hits[GF_FOP_##op]++; \ - conf->incremental.fop_hits[GF_FOP_##op]++; \ - } \ - UNLOCK (&conf->lock); \ + if (!conf) \ + break; \ + conf->cumulative.fop_hits[GF_FOP_##op]++; \ + conf->incremental.fop_hits[GF_FOP_##op]++; \ } while (0) +#define UPDATE_PROFILE_STATS(frame, op) \ + do { \ + struct ios_conf *conf = NULL; \ + \ + if (!is_fop_latency_started (frame)) \ + break; \ + conf = this->private; \ + LOCK (&conf->lock); \ + { \ + if (conf && conf->measure_latency && \ + conf->count_fop_hits) { \ + BUMP_FOP(op); \ + gettimeofday (&frame->end, NULL); \ + update_ios_latency (conf, frame, GF_FOP_##op);\ + } \ + } \ + UNLOCK (&conf->lock); \ + } while (0) #define BUMP_READ(fd, len) \ do { \ @@ -131,6 +222,8 @@ struct ios_local { conf = this->private; \ lb2 = log_base2 (len); \ ios_fd_ctx_get (fd, this, &iosfd); \ + if (!conf) \ + break; \ \ LOCK (&conf->lock); \ { \ @@ -157,6 +250,8 @@ struct ios_local { conf = this->private; \ lb2 = log_base2 (len); \ ios_fd_ctx_get (fd, this, &iosfd); \ + if (!conf) \ + break; \ \ LOCK (&conf->lock); \ { \ @@ -174,6 +269,58 @@ struct ios_local { } while (0) +#define BUMP_STATS(iosstat, type) \ + do { \ + struct ios_conf *conf = NULL; \ + uint64_t value = 0; \ + \ + conf = this->private; \ + \ + LOCK(&iosstat->lock); \ + { \ + iosstat->counters[type]++; \ + value = iosstat->counters[type]; \ + } \ + UNLOCK (&iosstat->lock); \ + ios_stat_add_to_list (&conf->list[type], \ + value, iosstat); \ + \ + } while (0) + + +#define BUMP_THROUGHPUT(iosstat, type) \ + do { \ + struct ios_conf *conf = NULL; \ + double elapsed; \ + struct timeval *begin, *end; \ + double throughput; \ + int flag = 0; \ + \ + begin = &frame->begin; \ + end = &frame->end; \ + \ + elapsed = (end->tv_sec - begin->tv_sec) * 1e6 \ + + (end->tv_usec - begin->tv_usec); \ + throughput = op_ret / elapsed; \ + \ + conf = this->private; \ + LOCK(&iosstat->lock); \ + { \ + if (iosstat->thru_counters[type].throughput \ + <= throughput) { \ + iosstat->thru_counters[type].throughput = \ + throughput; \ + gettimeofday (&iosstat-> \ + thru_counters[type].time, NULL); \ + flag = 1; \ + } \ + } \ + UNLOCK (&iosstat->lock); \ + if (flag) \ + ios_stat_add_to_list (&conf->thru_list[type], \ + throughput, iosstat); \ + } while (0) + int ios_fd_ctx_get (fd_t *fd, xlator_t *this, struct ios_fd **iosfd) { @@ -203,6 +350,183 @@ ios_fd_ctx_set (fd_t *fd, xlator_t *this, struct ios_fd *iosfd) return ret; } +int +ios_stat_ref (struct ios_stat *iosstat) +{ + LOCK (&iosstat->lock); + { + iosstat->refcnt++; + } + UNLOCK (&iosstat->lock); + + return iosstat->refcnt; +} + +int +ios_stat_unref (struct ios_stat *iosstat) +{ + int cleanup = 0; + LOCK (&iosstat->lock); + { + iosstat->refcnt--; + if (iosstat->refcnt == 0) { + if (iosstat->filename) { + GF_FREE (iosstat->filename); + iosstat->filename = NULL; + } + cleanup = 1; + } + } + UNLOCK (&iosstat->lock); + + if (cleanup) { + GF_FREE (iosstat); + iosstat = NULL; + } + + return 0; +} + +int +ios_inode_ctx_set (inode_t *inode, xlator_t *this, struct ios_stat *iosstat) +{ + uint64_t iosstat64 = 0; + int ret = 0; + + ios_stat_ref (iosstat); + iosstat64 = (unsigned long )iosstat; + ret = inode_ctx_put (inode, this, iosstat64); + return ret; +} + +int +ios_inode_ctx_get (inode_t *inode, xlator_t *this, struct ios_stat **iosstat) +{ + uint64_t iosstat64 = 0; + unsigned long iosstatlong = 0; + int ret = 0; + + ret = inode_ctx_get (inode, this, &iosstat64); + iosstatlong = iosstat64; + if (ret != -1) + *iosstat = (void *) iosstatlong; + + return ret; + +} + +int +ios_stat_add_to_list (struct ios_stat_head *list_head, uint64_t value, + struct ios_stat *iosstat) +{ + struct ios_stat_list *new = NULL; + struct ios_stat_list *entry = NULL; + struct ios_stat_list *t = NULL; + struct ios_stat_list *list_entry = NULL; + struct ios_stat_list *tmp = NULL; + struct ios_stat_list *last = NULL; + struct ios_stat *stat = NULL; + int cnt = 0; + int found = 0; + int reposition = 0; + double min_count = 0; + + LOCK (&list_head->lock); + { + + if (list_head->min_cnt == 0) + list_head->min_cnt = value; + if ((list_head->members == MAX_LIST_MEMBERS) && + (list_head->min_cnt > value)) + goto out; + + list_for_each_entry_safe (entry, t, + &list_head->iosstats->list, list) { + cnt++; + if (cnt == list_head->members) + last = entry; + + if (!uuid_compare (iosstat->gfid, + entry->iosstat->gfid)) { + list_entry = entry; + found = cnt; + entry->value = value; + if (!reposition) { + if (cnt == list_head->members) + list_head->min_cnt = value; + goto out; + } + break; + } else if (entry->value <= value && !reposition) { + reposition = cnt; + tmp = entry; + if (cnt == list_head->members - 1) + min_count = entry->value; + } + } + if (found) { + list_del (&list_entry->list); + list_add_tail (&list_entry->list, &tmp->list); + if (min_count) + list_head->min_cnt = min_count; + goto out; + } else if (list_head->members == MAX_LIST_MEMBERS && reposition) { + new = GF_CALLOC (1, sizeof (*new), + gf_io_stats_mt_ios_stat_list); + new->iosstat = iosstat; + new->value = value; + ios_stat_ref (iosstat); + list_add_tail (&new->list, &tmp->list); + stat = last->iosstat; + last->iosstat = NULL; + ios_stat_unref (stat); + list_del (&last->list); + GF_FREE (last); + if (reposition == MAX_LIST_MEMBERS) + list_head->min_cnt = value; + else if (min_count) { + list_head->min_cnt = min_count; + } + } else if (list_head->members < MAX_LIST_MEMBERS) { + new = GF_CALLOC (1, sizeof (*new), + gf_io_stats_mt_ios_stat_list); + new->iosstat = iosstat; + new->value = value; + ios_stat_ref (iosstat); + if (reposition) { + list_add_tail (&new->list, &tmp->list); + } else { + list_add_tail (&new->list, &entry->list); + } + list_head->members++; + if (list_head->min_cnt > value) + list_head->min_cnt = value; + } + } +out: + UNLOCK (&list_head->lock); + return 0; +} + +inline int +ios_stats_cleanup (xlator_t *this, inode_t *inode) +{ + + struct ios_stat *iosstat = NULL; + uint64_t iosstat64 = 0; + + inode_ctx_del (inode, this, &iosstat64); + if (!iosstat64) { + gf_log (this->name, GF_LOG_WARNING, + "could not get inode ctx"); + return 0; + } + iosstat = (void *) (long)iosstat64; + if (iosstat) { + ios_stat_unref (iosstat); + } + return 0; +} #define ios_log(this, logfp, fmt ...) \ do { \ @@ -210,66 +534,401 @@ ios_fd_ctx_set (fd_t *fd, xlator_t *this, struct ios_fd *iosfd) fprintf (logfp, fmt); \ fprintf (logfp, "\n"); \ } \ - gf_log (this->name, GF_LOG_NORMAL, fmt); \ + gf_log (this->name, GF_LOG_INFO, fmt); \ } while (0) +int +ios_dump_file_stats (struct ios_stat_head *list_head, xlator_t *this, FILE* logfp) +{ + struct ios_stat_list *entry = NULL; + + LOCK (&list_head->lock); + { + list_for_each_entry (entry, &list_head->iosstats->list, list) { + ios_log (this, logfp, "%-12.0f %s", + entry->value, entry->iosstat->filename); + } + } + UNLOCK (&list_head->lock); + return 0; +} int -io_stats_dump_global (xlator_t *this, struct ios_global_stats *stats, - struct timeval *now, int interval, FILE *logfp) +ios_dump_throughput_stats (struct ios_stat_head *list_head, xlator_t *this, + FILE* logfp, ios_stats_type_t type) +{ + struct ios_stat_list *entry = NULL; + struct timeval time = {0, }; + char timestr[256] = {0, }; + + LOCK (&list_head->lock); + { + list_for_each_entry (entry, &list_head->iosstats->list, list) { + gf_time_fmt (timestr, sizeof timestr, + entry->iosstat->thru_counters[type].time.tv_sec, + gf_timefmt_FT); + snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr), + ".%"GF_PRI_SUSECONDS, time.tv_usec); + + ios_log (this, logfp, "%s \t %-10.2f \t %s", + timestr, entry->value, entry->iosstat->filename); + } + } + UNLOCK (&list_head->lock); + return 0; +} + +int +io_stats_dump_global_to_logfp (xlator_t *this, struct ios_global_stats *stats, + struct timeval *now, int interval, FILE* logfp) { - int i = 0; + int i = 0; + int per_line = 0; + int index = 0; + struct ios_stat_head *list_head = NULL; + struct ios_conf *conf = NULL; + char timestr[256] = {0, }; + char str_header[128] = {0}; + char str_read[128] = {0}; + char str_write[128] = {0}; + + conf = this->private; if (interval == -1) - ios_log (this, logfp, "=== Cumulative stats ==="); + ios_log (this, logfp, "\n=== Cumulative stats ==="); else - ios_log (this, logfp, "=== Interval %d stats ===", + ios_log (this, logfp, "\n=== Interval %d stats ===", interval); - ios_log (this, logfp, " Duration : %"PRId64"secs", + ios_log (this, logfp, " Duration : %"PRId64" secs", (uint64_t) (now->tv_sec - stats->started_at.tv_sec)); ios_log (this, logfp, " BytesRead : %"PRId64, stats->data_read); - ios_log (this, logfp, " BytesWritten : %"PRId64, + ios_log (this, logfp, " BytesWritten : %"PRId64"\n", stats->data_written); + snprintf (str_header, sizeof (str_header), "%-12s %c", "Block Size", ':'); + snprintf (str_read, sizeof (str_read), "%-12s %c", "Read Count", ':'); + snprintf (str_write, sizeof (str_write), "%-12s %c", "Write Count", ':'); + index = 14; for (i = 0; i < 32; i++) { + if ((stats->block_count_read[i] == 0) && + (stats->block_count_write[i] == 0)) + continue; + per_line++; + + snprintf (str_header+index, sizeof (str_header)-index, + "%16dB+", (1<<i)); if (stats->block_count_read[i]) - ios_log (this, logfp, " Read %06db+ : %"PRId64, - (1 << i), stats->block_count_read[i]); + snprintf (str_read+index, sizeof (str_read)-index, + "%18"PRId64, stats->block_count_read[i]); + else snprintf (str_read+index, sizeof (str_read)-index, + "%18s", "0"); + if (stats->block_count_write[i]) + snprintf (str_write+index, sizeof (str_write)-index, + "%18"PRId64, stats->block_count_write[i]); + else snprintf (str_write+index, sizeof (str_write)-index, + "%18s", "0"); + + index += 18; + if (per_line == 3) { + ios_log (this, logfp, "%s", str_header); + ios_log (this, logfp, "%s", str_read); + ios_log (this, logfp, "%s\n", str_write); + + memset (str_header, 0, sizeof (str_header)); + memset (str_read, 0, sizeof (str_read)); + memset (str_write, 0, sizeof (str_write)); + + snprintf (str_header, sizeof (str_header), "%-12s %c", + "Block Size", ':'); + snprintf (str_read, sizeof (str_read), "%-12s %c", + "Read Count", ':'); + snprintf (str_write, sizeof (str_write), "%-12s %c", + "Write Count", ':'); + + index = 14; + per_line = 0; + } } - for (i = 0; i < 32; i++) { - if (stats->block_count_write[i]) - ios_log (this, logfp, "Write %06db+ : %"PRId64, - (1 << i), stats->block_count_write[i]); + if (per_line != 0) { + ios_log (this, logfp, "%s", str_header); + ios_log (this, logfp, "%s", str_read); + ios_log (this, logfp, "%s\n", str_write); } + ios_log (this, logfp, "%-13s %10s %14s %14s %14s", "Fop", + "Call Count", "Avg-Latency", "Min-Latency", + "Max-Latency"); + ios_log (this, logfp, "%-13s %10s %14s %14s %14s", "---", "----------", + "-----------", "-----------", "-----------"); + for (i = 0; i < GF_FOP_MAXVALUE; i++) { if (stats->fop_hits[i] && !stats->latency[i].avg) - ios_log (this, logfp, "%14s : %"PRId64, - gf_fop_list[i], stats->fop_hits[i]); + ios_log (this, logfp, "%-13s %10"PRId64" %11s " + "us %11s us %11s us", gf_fop_list[i], + stats->fop_hits[i], "0", "0", "0"); else if (stats->fop_hits[i] && stats->latency[i].avg) - ios_log (this, logfp, "%14s : %"PRId64 ", latency" - "(avg: %f, min: %f, max: %f)", - gf_fop_list[i], stats->fop_hits[i], - stats->latency[i].avg, stats->latency[i].min, - stats->latency[i].max); + ios_log (this, logfp, "%-13s %10"PRId64" %11.2lf us " + "%11.2lf us %11.2lf us", gf_fop_list[i], + stats->fop_hits[i], stats->latency[i].avg, + stats->latency[i].min, stats->latency[i].max); + } + ios_log (this, logfp, "------ ----- ----- ----- ----- ----- ----- ----- " + " ----- ----- ----- -----\n"); + + if (interval == -1) { + LOCK (&conf->lock); + { + gf_time_fmt (timestr, sizeof timestr, + conf->cumulative.max_openfd_time.tv_sec, + gf_timefmt_FT); + snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr), + ".%"GF_PRI_SUSECONDS, + conf->cumulative.max_openfd_time.tv_usec); + ios_log (this, logfp, "Current open fd's: %"PRId64 + " Max open fd's: %"PRId64" time %s", + conf->cumulative.nr_opens, + conf->cumulative.max_nr_opens, timestr); + } + UNLOCK (&conf->lock); + ios_log (this, logfp, "\n==========Open File Stats========"); + ios_log (this, logfp, "\nCOUNT: \t FILE NAME"); + list_head = &conf->list[IOS_STATS_TYPE_OPEN]; + ios_dump_file_stats (list_head, this, logfp); + + + ios_log (this, logfp, "\n==========Read File Stats========"); + ios_log (this, logfp, "\nCOUNT: \t FILE NAME"); + list_head = &conf->list[IOS_STATS_TYPE_READ]; + ios_dump_file_stats (list_head, this, logfp); + + ios_log (this, logfp, "\n==========Write File Stats========"); + ios_log (this, logfp, "\nCOUNT: \t FILE NAME"); + list_head = &conf->list[IOS_STATS_TYPE_WRITE]; + ios_dump_file_stats (list_head, this, logfp); + + ios_log (this, logfp, "\n==========Directory open stats========"); + ios_log (this, logfp, "\nCOUNT: \t DIRECTORY NAME"); + list_head = &conf->list[IOS_STATS_TYPE_OPENDIR]; + ios_dump_file_stats (list_head, this, logfp); + + ios_log (this, logfp, "\n========Directory readdirp Stats======="); + ios_log (this, logfp, "\nCOUNT: \t DIRECTORY NAME"); + list_head = &conf->list[IOS_STATS_TYPE_READDIRP]; + ios_dump_file_stats (list_head, this, logfp); + + ios_log (this, logfp, "\n========Read Throughput File Stats====="); + ios_log (this, logfp, "\nTIMESTAMP \t\t\t THROUGHPUT(KBPS)" + "\tFILE NAME"); + list_head = &conf->thru_list[IOS_STATS_THRU_READ]; + ios_dump_throughput_stats(list_head, this, logfp, IOS_STATS_THRU_READ); + + ios_log (this, logfp, "\n======Write Throughput File Stats======"); + ios_log (this, logfp, "\nTIMESTAMP \t\t\t THROUGHPUT(KBPS)" + "\tFILE NAME"); + list_head = &conf->thru_list[IOS_STATS_THRU_WRITE]; + ios_dump_throughput_stats (list_head, this, logfp, IOS_STATS_THRU_WRITE); } - return 0; } +int +io_stats_dump_global_to_dict (xlator_t *this, struct ios_global_stats *stats, + struct timeval *now, int interval, dict_t *dict) +{ + int ret = 0; + char key[256] = {0}; + uint64_t sec = 0; + int i = 0; + uint64_t count = 0; + + GF_ASSERT (stats); + GF_ASSERT (now); + GF_ASSERT (dict); + GF_ASSERT (this); + + if (interval == -1) + snprintf (key, sizeof (key), "cumulative"); + else + snprintf (key, sizeof (key), "interval"); + ret = dict_set_int32 (dict, key, interval); + if (ret) + gf_log (this->name, GF_LOG_ERROR, "failed to set " + "interval %d", interval); + + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "%d-duration", interval); + sec = (uint64_t) (now->tv_sec - stats->started_at.tv_sec); + ret = dict_set_uint64 (dict, key, sec); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to set " + "duration(%d) - %"PRId64, interval, sec); + goto out; + } + + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "%d-total-read", interval); + ret = dict_set_uint64 (dict, key, stats->data_read); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to set total " + "read(%d) - %"PRId64, interval, stats->data_read); + goto out; + } + + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "%d-total-write", interval); + ret = dict_set_uint64 (dict, key, stats->data_written); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to set total " + "write(%d) - %"PRId64, interval, stats->data_written); + goto out; + } + for (i = 0; i < 32; i++) { + if (stats->block_count_read[i]) { + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "%d-read-%d", interval, + (1 << i)); + count = stats->block_count_read[i]; + ret = dict_set_uint64 (dict, key, count); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to " + "set read-%db+, with: %"PRId64, + (1<<i), count); + goto out; + } + } + } + + for (i = 0; i < 32; i++) { + if (stats->block_count_write[i]) { + snprintf (key, sizeof (key), "%d-write-%d", interval, + (1<<i)); + count = stats->block_count_write[i]; + ret = dict_set_uint64 (dict, key, count); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to " + "set write-%db+, with: %"PRId64, + (1<<i), count); + goto out; + } + } + } + + for (i = 0; i < GF_FOP_MAXVALUE; i++) { + if (stats->fop_hits[i] == 0) + continue; + snprintf (key, sizeof (key), "%d-%d-hits", interval, i); + ret = dict_set_uint64 (dict, key, stats->fop_hits[i]); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to " + "set %s-fop-hits: %"PRIu64, gf_fop_list[i], + stats->fop_hits[i]); + goto out; + } + + if (stats->latency[i].avg == 0) + continue; + snprintf (key, sizeof (key), "%d-%d-avglatency", interval, i); + ret = dict_set_double (dict, key, stats->latency[i].avg); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to set %s " + "avglatency(%d) with %f", gf_fop_list[i], + interval, stats->latency[i].avg); + goto out; + } + snprintf (key, sizeof (key), "%d-%d-minlatency", interval, i); + ret = dict_set_double (dict, key, stats->latency[i].min); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to set %s " + "minlatency(%d) with %f", gf_fop_list[i], + interval, stats->latency[i].min); + goto out; + } + snprintf (key, sizeof (key), "%d-%d-maxlatency", interval, i); + ret = dict_set_double (dict, key, stats->latency[i].max); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to set %s " + "maxlatency(%d) with %f", gf_fop_list[i], + interval, stats->latency[i].max); + goto out; + } + } +out: + gf_log (this->name, GF_LOG_DEBUG, "returning %d", ret); + return ret; +} + +int +io_stats_dump_global (xlator_t *this, struct ios_global_stats *stats, + struct timeval *now, int interval, + struct ios_dump_args *args) +{ + int ret = -1; + + GF_ASSERT (args); + GF_ASSERT (now); + GF_ASSERT (stats); + GF_ASSERT (this); + + + + switch (args->type) { + case IOS_DUMP_TYPE_FILE: + ret = io_stats_dump_global_to_logfp (this, stats, now, + interval, args->u.logfp); + break; + case IOS_DUMP_TYPE_DICT: + ret = io_stats_dump_global_to_dict (this, stats, now, + interval, args->u.dict); + break; + default: + GF_ASSERT (0); + ret = -1; + break; + } + return ret; +} + +int +ios_dump_args_init (struct ios_dump_args *args, ios_dump_type_t type, + void *output) +{ + int ret = 0; + + GF_ASSERT (args); + GF_ASSERT (type > IOS_DUMP_TYPE_NONE && type < IOS_DUMP_TYPE_MAX); + GF_ASSERT (output); + + args->type = type; + switch (args->type) { + case IOS_DUMP_TYPE_FILE: + args->u.logfp = output; + break; + case IOS_DUMP_TYPE_DICT: + args->u.dict = output; + break; + default: + GF_ASSERT (0); + ret = -1; + } + + return ret; +} int -io_stats_dump (xlator_t *this, char *filename, inode_t *inode, - const char *path) +io_stats_dump (xlator_t *this, struct ios_dump_args *args) { struct ios_conf *conf = NULL; struct ios_global_stats cumulative = {0, }; struct ios_global_stats incremental = {0, }; int increment = 0; struct timeval now; - FILE *logfp = NULL; + + GF_ASSERT (this); + GF_ASSERT (args); + GF_ASSERT (args->type > IOS_DUMP_TYPE_NONE); + GF_ASSERT (args->type < IOS_DUMP_TYPE_MAX); conf = this->private; @@ -286,12 +945,9 @@ io_stats_dump (xlator_t *this, char *filename, inode_t *inode, } UNLOCK (&conf->lock); - logfp = fopen (filename, "w+"); - io_stats_dump_global (this, &cumulative, &now, -1, logfp); - io_stats_dump_global (this, &incremental, &now, increment, logfp); + io_stats_dump_global (this, &cumulative, &now, -1, args); + io_stats_dump_global (this, &incremental, &now, increment, args); - if (logfp) - fclose (logfp); return 0; } @@ -323,51 +979,70 @@ io_stats_dump_fd (xlator_t *this, struct ios_fd *iosfd) sec = now.tv_sec - iosfd->opened_at.tv_sec; usec = now.tv_usec - iosfd->opened_at.tv_usec; - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_INFO, "--- fd stats ---"); if (iosfd->filename) - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_INFO, " Filename : %s", iosfd->filename); if (sec) - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_INFO, " Lifetime : %"PRId64"secs, %"PRId64"usecs", sec, usec); if (iosfd->data_read) - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_INFO, " BytesRead : %"PRId64" bytes", iosfd->data_read); if (iosfd->data_written) - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_INFO, " BytesWritten : %"PRId64" bytes", iosfd->data_written); for (i = 0; i < 32; i++) { if (iosfd->block_count_read[i]) - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_INFO, " Read %06db+ : %"PRId64, (1 << i), iosfd->block_count_read[i]); } for (i = 0; i < 32; i++) { if (iosfd->block_count_write[i]) - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_INFO, "Write %06db+ : %"PRId64, (1 << i), iosfd->block_count_write[i]); } return 0; } +static void +update_ios_latency_stats (struct ios_global_stats *stats, double elapsed, + glusterfs_fop_t op) +{ + double avg; + + GF_ASSERT (stats); + + if (!stats->latency[op].min) + stats->latency[op].min = elapsed; + if (stats->latency[op].min > elapsed) + stats->latency[op].min = elapsed; + if (stats->latency[op].max < elapsed) + stats->latency[op].max = elapsed; + + avg = stats->latency[op].avg; + + stats->latency[op].avg = avg + (elapsed - avg) / stats->fop_hits[op]; +} + int update_ios_latency (struct ios_conf *conf, call_frame_t *frame, glusterfs_fop_t op) { double elapsed; struct timeval *begin, *end; - double avg; begin = &frame->begin; end = &frame->end; @@ -375,43 +1050,143 @@ update_ios_latency (struct ios_conf *conf, call_frame_t *frame, elapsed = (end->tv_sec - begin->tv_sec) * 1e6 + (end->tv_usec - begin->tv_usec); - /* Cumulative */ - if (!conf->cumulative.latency[op].min) - conf->cumulative.latency[op].min = elapsed; - if (conf->cumulative.latency[op].min > elapsed) - conf->cumulative.latency[op].min = elapsed; - if (conf->cumulative.latency[op].max < elapsed) - conf->cumulative.latency[op].max = elapsed; + update_ios_latency_stats (&conf->cumulative, elapsed, op); + update_ios_latency_stats (&conf->incremental, elapsed, op); - avg = conf->cumulative.latency[op].avg; - - conf->cumulative.latency[op].avg = - avg + (elapsed - avg) / conf->cumulative.fop_hits[op]; + return 0; +} - /* Incremental */ - if (!conf->incremental.latency[op].min) - conf->incremental.latency[op].min = elapsed; - if (conf->incremental.latency[op].min > elapsed) - conf->incremental.latency[op].min = elapsed; - if (conf->incremental.latency[op].max < elapsed) - conf->incremental.latency[op].max = elapsed; +int32_t +io_stats_dump_stats_to_dict (xlator_t *this, dict_t *resp, + ios_stats_type_t flags, int32_t list_cnt) +{ + struct ios_conf *conf = NULL; + int cnt = 0; + char key[256]; + struct ios_stat_head *list_head = NULL; + struct ios_stat_list *entry = NULL; + int ret = -1; + ios_stats_thru_t index = IOS_STATS_THRU_MAX; + char timestr[256] = {0, }; + char *dict_timestr = NULL; - avg = conf->incremental.latency[op].avg; + conf = this->private; - conf->incremental.latency[op].avg = - avg + (elapsed - avg) / conf->incremental.fop_hits[op]; + switch (flags) { + case IOS_STATS_TYPE_OPEN: + list_head = &conf->list[IOS_STATS_TYPE_OPEN]; + LOCK (&conf->lock); + { + ret = dict_set_uint64 (resp, "current-open", + conf->cumulative.nr_opens); + if (ret) + goto unlock; + ret = dict_set_uint64 (resp, "max-open", + conf->cumulative.max_nr_opens); + + gf_time_fmt (timestr, sizeof timestr, + conf->cumulative.max_openfd_time.tv_sec, + gf_timefmt_FT); + if (conf->cumulative.max_openfd_time.tv_sec) + snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr), + ".%"GF_PRI_SUSECONDS, + conf->cumulative.max_openfd_time.tv_usec); + + dict_timestr = gf_strdup (timestr); + if (!dict_timestr) + goto unlock; + ret = dict_set_dynstr (resp, "max-openfd-time", + dict_timestr); + if (ret) + goto unlock; + } + unlock: + UNLOCK (&conf->lock); + /* Do not proceed if we came here because of some error + * during the dict operation */ + if (ret) + goto out; + break; + case IOS_STATS_TYPE_READ: + list_head = &conf->list[IOS_STATS_TYPE_READ]; + break; + case IOS_STATS_TYPE_WRITE: + list_head = &conf->list[IOS_STATS_TYPE_WRITE]; + break; + case IOS_STATS_TYPE_OPENDIR: + list_head = &conf->list[IOS_STATS_TYPE_OPENDIR]; + break; + case IOS_STATS_TYPE_READDIRP: + list_head = &conf->list[IOS_STATS_TYPE_READDIRP]; + break; + case IOS_STATS_TYPE_READ_THROUGHPUT: + list_head = &conf->thru_list[IOS_STATS_THRU_READ]; + index = IOS_STATS_THRU_READ; + break; + case IOS_STATS_TYPE_WRITE_THROUGHPUT: + list_head = &conf->thru_list[IOS_STATS_THRU_WRITE]; + index = IOS_STATS_THRU_WRITE; + break; + + default: + goto out; + } + ret = dict_set_int32 (resp, "top-op", flags); + if (!list_cnt) + goto out; + LOCK (&list_head->lock); + { + list_for_each_entry (entry, &list_head->iosstats->list, list) { + + cnt++; + snprintf (key, 256, "%s-%d", "filename", cnt); + ret = dict_set_str (resp, key, entry->iosstat->filename); + if (ret) + goto unlock_list_head; + snprintf (key, 256, "%s-%d", "value",cnt); + ret = dict_set_uint64 (resp, key, entry->value); + if (ret) + goto unlock_list_head; + if (index != IOS_STATS_THRU_MAX) { + snprintf (key, 256, "%s-%d", "time-sec", cnt); + ret = dict_set_int32 (resp, key, + entry->iosstat->thru_counters[index].time.tv_sec); + if (ret) + goto unlock_list_head; + snprintf (key, 256, "%s-%d", "time-usec", cnt); + ret = dict_set_int32 (resp, key, + entry->iosstat->thru_counters[index].time.tv_usec); + if (ret) + goto unlock_list_head; + } + if (cnt == list_cnt) + break; - return 0; + } + } +unlock_list_head: + UNLOCK (&list_head->lock); + /* ret is !=0 if some dict operation in the above critical region + * failed. */ + if (ret) + goto out; + ret = dict_set_int32 (resp, "members", cnt); + out: + return ret; } int io_stats_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { struct ios_fd *iosfd = NULL; char *path = NULL; + struct ios_stat *iosstat = NULL; + struct ios_conf *conf = NULL; + + conf = this->private; path = frame->local; frame->local = NULL; @@ -434,22 +1209,44 @@ io_stats_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, gettimeofday (&iosfd->opened_at, NULL); ios_fd_ctx_set (fd, this, iosfd); + LOCK (&conf->lock); + { + conf->cumulative.nr_opens++; + if (conf->cumulative.nr_opens > conf->cumulative.max_nr_opens) { + conf->cumulative.max_nr_opens = conf->cumulative.nr_opens; + conf->cumulative.max_openfd_time = iosfd->opened_at; + } + } + UNLOCK (&conf->lock); + + iosstat = GF_CALLOC (1, sizeof (*iosstat), gf_io_stats_mt_ios_stat); + if (!iosstat) { + GF_FREE (path); + goto unwind; + } + iosstat->filename = gf_strdup (path); + uuid_copy (iosstat->gfid, buf->ia_gfid); + LOCK_INIT (&iosstat->lock); + ios_inode_ctx_set (fd->inode, this, iosstat); unwind: - END_FOP_LATENCY (frame, CREATE); + UPDATE_PROFILE_STATS (frame, CREATE); STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf, - preparent, postparent); + preparent, postparent, xdata); return 0; } int io_stats_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { struct ios_fd *iosfd = NULL; char *path = NULL; + struct ios_stat *iosstat = NULL; + struct ios_conf *conf = NULL; + conf = this->private; path = frame->local; frame->local = NULL; @@ -472,19 +1269,46 @@ io_stats_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ios_fd_ctx_set (fd, this, iosfd); + ios_inode_ctx_get (fd->inode, this, &iosstat); + if (!iosstat) { + iosstat = GF_CALLOC (1, sizeof (*iosstat), + gf_io_stats_mt_ios_stat); + if (iosstat) { + iosstat->filename = gf_strdup (path); + uuid_copy (iosstat->gfid, fd->inode->gfid); + LOCK_INIT (&iosstat->lock); + ios_inode_ctx_set (fd->inode, this, iosstat); + } + } + + LOCK (&conf->lock); + { + conf->cumulative.nr_opens++; + if (conf->cumulative.nr_opens > conf->cumulative.max_nr_opens) { + conf->cumulative.max_nr_opens = conf->cumulative.nr_opens; + conf->cumulative.max_openfd_time = iosfd->opened_at; + } + } + UNLOCK (&conf->lock); + if (iosstat) { + BUMP_STATS (iosstat, IOS_STATS_TYPE_OPEN); + iosstat = NULL; + } unwind: - END_FOP_LATENCY (frame, OPEN); - STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd); + UPDATE_PROFILE_STATS (frame, OPEN); + + STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd, xdata); return 0; + } int io_stats_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf) + int32_t op_ret, int32_t op_errno, struct iatt *buf, dict_t *xdata) { - END_FOP_LATENCY (frame, STAT); - STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, buf); + UPDATE_PROFILE_STATS (frame, STAT); + STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, buf, xdata); return 0; } @@ -493,10 +1317,11 @@ int io_stats_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iovec *vector, int32_t count, - struct iatt *buf, struct iobref *iobref) + struct iatt *buf, struct iobref *iobref, dict_t *xdata) { int len = 0; fd_t *fd = NULL; + struct ios_stat *iosstat = NULL; fd = frame->local; frame->local = NULL; @@ -506,21 +1331,46 @@ io_stats_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, BUMP_READ (fd, len); } - END_FOP_LATENCY (frame, READ); + UPDATE_PROFILE_STATS (frame, READ); + ios_inode_ctx_get (fd->inode, this, &iosstat); + + if (iosstat) { + BUMP_STATS (iosstat, IOS_STATS_TYPE_READ); + BUMP_THROUGHPUT (iosstat, IOS_STATS_THRU_READ); + iosstat = NULL; + } + STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, - vector, count, buf, iobref); + vector, count, buf, iobref, xdata); return 0; + } int io_stats_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf) -{ - END_FOP_LATENCY (frame, WRITE); - STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf); + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) +{ + struct ios_stat *iosstat = NULL; + inode_t *inode = NULL; + + UPDATE_PROFILE_STATS (frame, WRITE); + if (frame->local){ + inode = frame->local; + frame->local = NULL; + ios_inode_ctx_get (inode, this, &iosstat); + if (iosstat) { + BUMP_STATS (iosstat, IOS_STATS_TYPE_WRITE); + BUMP_THROUGHPUT (iosstat, IOS_STATS_THRU_WRITE); + inode = NULL; + iosstat = NULL; + } + } + + STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf, xdata); return 0; + } @@ -528,20 +1378,33 @@ io_stats_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int io_stats_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *buf) + int32_t op_ret, int32_t op_errno, gf_dirent_t *buf, dict_t *xdata) { - END_FOP_LATENCY (frame, READDIRP); - STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno, buf); + struct ios_stat *iosstat = NULL; + inode_t *inode = frame->local; + + frame->local = NULL; + + UPDATE_PROFILE_STATS (frame, READDIRP); + + ios_inode_ctx_get (inode, this, &iosstat); + + if (iosstat) { + BUMP_STATS (iosstat, IOS_STATS_TYPE_READDIRP); + iosstat = NULL; + } + + STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno, buf, xdata); return 0; } int io_stats_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *buf) + int32_t op_ret, int32_t op_errno, gf_dirent_t *buf, dict_t *xdata) { - END_FOP_LATENCY (frame, READDIR); - STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, buf); + UPDATE_PROFILE_STATS (frame, READDIR); + STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, buf, xdata); return 0; } @@ -549,10 +1412,10 @@ io_stats_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int io_stats_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf) + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { - END_FOP_LATENCY (frame, FSYNC); - STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, prebuf, postbuf); + UPDATE_PROFILE_STATS (frame, FSYNC); + STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, prebuf, postbuf, xdata); return 0; } @@ -560,10 +1423,10 @@ io_stats_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int io_stats_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *preop, struct iatt *postop) + struct iatt *preop, struct iatt *postop, dict_t *xdata) { - END_FOP_LATENCY (frame, SETATTR); - STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno, preop, postop); + UPDATE_PROFILE_STATS (frame, SETATTR); + STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno, preop, postop, xdata); return 0; } @@ -571,12 +1434,13 @@ io_stats_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int io_stats_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - END_FOP_LATENCY (frame, UNLINK); + UPDATE_PROFILE_STATS (frame, UNLINK); STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, - preparent, postparent); + preparent, postparent, xdata); return 0; + } @@ -584,12 +1448,12 @@ int io_stats_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iatt *buf, struct iatt *preoldparent, struct iatt *postoldparent, - struct iatt *prenewparent, struct iatt *postnewparent) + struct iatt *prenewparent, struct iatt *postnewparent, dict_t *xdata) { - END_FOP_LATENCY (frame, RENAME); + UPDATE_PROFILE_STATS (frame, RENAME); STACK_UNWIND_STRICT (rename, frame, op_ret, op_errno, buf, preoldparent, postoldparent, - prenewparent, postnewparent); + prenewparent, postnewparent, xdata); return 0; } @@ -597,10 +1461,10 @@ io_stats_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int io_stats_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, const char *buf, - struct iatt *sbuf) + struct iatt *sbuf, dict_t *xdata) { - END_FOP_LATENCY (frame, READLINK); - STACK_UNWIND_STRICT (readlink, frame, op_ret, op_errno, buf, sbuf); + UPDATE_PROFILE_STATS (frame, READLINK); + STACK_UNWIND_STRICT (readlink, frame, op_ret, op_errno, buf, sbuf, xdata); return 0; } @@ -609,10 +1473,10 @@ int io_stats_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, - dict_t *xattr, struct iatt *postparent) + dict_t *xdata, struct iatt *postparent) { - END_FOP_LATENCY (frame, LOOKUP); - STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf, xattr, + UPDATE_PROFILE_STATS (frame, LOOKUP); + STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf, xdata, postparent); return 0; } @@ -622,11 +1486,11 @@ int io_stats_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - END_FOP_LATENCY (frame, SYMLINK); + UPDATE_PROFILE_STATS (frame, SYMLINK); STACK_UNWIND_STRICT (symlink, frame, op_ret, op_errno, inode, buf, - preparent, postparent); + preparent, postparent, xdata); return 0; } @@ -635,11 +1499,11 @@ int io_stats_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - END_FOP_LATENCY (frame, MKNOD); + UPDATE_PROFILE_STATS (frame, MKNOD); STACK_UNWIND_STRICT (mknod, frame, op_ret, op_errno, inode, buf, - preparent, postparent); + preparent, postparent, xdata); return 0; } @@ -648,11 +1512,30 @@ int io_stats_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - END_FOP_LATENCY (frame, MKDIR); + struct ios_stat *iosstat = NULL; + char *path = frame->local; + + UPDATE_PROFILE_STATS (frame, MKDIR); + if (op_ret < 0) + goto unwind; + + iosstat = GF_CALLOC (1, sizeof (*iosstat), gf_io_stats_mt_ios_stat); + if (iosstat) { + LOCK_INIT (&iosstat->lock); + iosstat->filename = gf_strdup(path); + uuid_copy (iosstat->gfid, buf->ia_gfid); + ios_inode_ctx_set (inode, this, iosstat); + } + +unwind: + /* local is assigned with path */ + GF_FREE (frame->local); + frame->local = NULL; STACK_UNWIND_STRICT (mkdir, frame, op_ret, op_errno, inode, buf, - preparent, postparent); + preparent, postparent, xdata); return 0; } @@ -661,34 +1544,44 @@ int io_stats_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - END_FOP_LATENCY (frame, LINK); + UPDATE_PROFILE_STATS (frame, LINK); STACK_UNWIND_STRICT (link, frame, op_ret, op_errno, inode, buf, - preparent, postparent); + preparent, postparent, xdata); return 0; } int io_stats_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - END_FOP_LATENCY (frame, FLUSH); - STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno); + UPDATE_PROFILE_STATS (frame, FLUSH); + STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno, xdata); return 0; } int io_stats_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { - if (op_ret >= 0) - ios_fd_ctx_set (fd, this, 0); + struct ios_stat *iosstat = NULL; + int ret = -1; - END_FOP_LATENCY (frame, OPENDIR); - STACK_UNWIND_STRICT (opendir, frame, op_ret, op_errno, fd); + UPDATE_PROFILE_STATS (frame, OPENDIR); + if (op_ret < 0) + goto unwind; + + ios_fd_ctx_set (fd, this, 0); + + ret = ios_inode_ctx_get (fd->inode, this, &iosstat); + if (!ret) + BUMP_STATS (iosstat, IOS_STATS_TYPE_OPENDIR); + +unwind: + STACK_UNWIND_STRICT (opendir, frame, op_ret, op_errno, fd, xdata); return 0; } @@ -696,11 +1589,13 @@ io_stats_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int io_stats_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - END_FOP_LATENCY (frame, RMDIR); + + UPDATE_PROFILE_STATS (frame, RMDIR); + STACK_UNWIND_STRICT (rmdir, frame, op_ret, op_errno, - preparent, postparent); + preparent, postparent, xdata); return 0; } @@ -708,71 +1603,100 @@ io_stats_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int io_stats_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf) + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { - END_FOP_LATENCY (frame, TRUNCATE); + UPDATE_PROFILE_STATS (frame, TRUNCATE); STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, - prebuf, postbuf); + prebuf, postbuf, xdata); return 0; } int io_stats_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct statvfs *buf) + int32_t op_ret, int32_t op_errno, struct statvfs *buf, dict_t *xdata) { - END_FOP_LATENCY (frame, STATFS); - STACK_UNWIND_STRICT (statfs, frame, op_ret, op_errno, buf); + UPDATE_PROFILE_STATS (frame, STATFS); + STACK_UNWIND_STRICT (statfs, frame, op_ret, op_errno, buf, xdata); return 0; } int io_stats_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - END_FOP_LATENCY (frame, SETXATTR); - STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno); + UPDATE_PROFILE_STATS (frame, SETXATTR); + STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata); return 0; } int io_stats_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) + int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata) { - END_FOP_LATENCY (frame, GETXATTR); - STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict); + UPDATE_PROFILE_STATS (frame, GETXATTR); + STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict, xdata); return 0; } int io_stats_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - END_FOP_LATENCY (frame, REMOVEXATTR); - STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno); + UPDATE_PROFILE_STATS (frame, REMOVEXATTR); + STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno, xdata); + return 0; +} + +int +io_stats_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + UPDATE_PROFILE_STATS (frame, FSETXATTR); + STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, xdata); + return 0; +} + + +int +io_stats_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata) +{ + UPDATE_PROFILE_STATS (frame, FGETXATTR); + STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, dict, xdata); + return 0; +} + + +int +io_stats_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + UPDATE_PROFILE_STATS (frame, FREMOVEXATTR); + STACK_UNWIND_STRICT (fremovexattr, frame, op_ret, op_errno, xdata); return 0; } int io_stats_fsyncdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - END_FOP_LATENCY (frame, FSYNCDIR); - STACK_UNWIND_STRICT (fsyncdir, frame, op_ret, op_errno); + UPDATE_PROFILE_STATS (frame, FSYNCDIR); + STACK_UNWIND_STRICT (fsyncdir, frame, op_ret, op_errno, xdata); return 0; } int io_stats_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - END_FOP_LATENCY (frame, ACCESS); - STACK_UNWIND_STRICT (access, frame, op_ret, op_errno); + UPDATE_PROFILE_STATS (frame, ACCESS); + STACK_UNWIND_STRICT (access, frame, op_ret, op_errno, xdata); return 0; } @@ -780,376 +1704,364 @@ io_stats_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int io_stats_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf) + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { - END_FOP_LATENCY (frame, FTRUNCATE); + UPDATE_PROFILE_STATS (frame, FTRUNCATE); STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, - prebuf, postbuf); + prebuf, postbuf, xdata); return 0; } int io_stats_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf) + int32_t op_ret, int32_t op_errno, struct iatt *buf, dict_t *xdata) { - END_FOP_LATENCY (frame, FSTAT); - STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf); + UPDATE_PROFILE_STATS (frame, FSTAT); + STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf, xdata); return 0; } int +io_stats_fallocate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + UPDATE_PROFILE_STATS(frame, FALLOCATE); + STACK_UNWIND_STRICT(fallocate, frame, op_ret, op_errno, prebuf, postbuf, + xdata); + return 0; +} + + +int +io_stats_discard_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + UPDATE_PROFILE_STATS(frame, DISCARD); + STACK_UNWIND_STRICT(discard, frame, op_ret, op_errno, prebuf, postbuf, + xdata); + return 0; +} + +int +io_stats_zerofill_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + UPDATE_PROFILE_STATS(frame, ZEROFILL); + STACK_UNWIND_STRICT(zerofill, frame, op_ret, op_errno, prebuf, postbuf, + xdata); + return 0; +} + +int io_stats_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct gf_flock *lock) + int32_t op_ret, int32_t op_errno, struct gf_flock *lock, dict_t *xdata) { - END_FOP_LATENCY (frame, LK); - STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, lock); + UPDATE_PROFILE_STATS (frame, LK); + STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, lock, xdata); return 0; } int io_stats_entrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - END_FOP_LATENCY (frame, ENTRYLK); - STACK_UNWIND_STRICT (entrylk, frame, op_ret, op_errno); + UPDATE_PROFILE_STATS (frame, ENTRYLK); + STACK_UNWIND_STRICT (entrylk, frame, op_ret, op_errno, xdata); return 0; } int io_stats_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) + int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata) { - END_FOP_LATENCY (frame, XATTROP); - STACK_UNWIND_STRICT (xattrop, frame, op_ret, op_errno, dict); + UPDATE_PROFILE_STATS (frame, XATTROP); + STACK_UNWIND_STRICT (xattrop, frame, op_ret, op_errno, dict, xdata); return 0; } int io_stats_fxattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) + int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata) { - END_FOP_LATENCY (frame, FXATTROP); - STACK_UNWIND_STRICT (fxattrop, frame, op_ret, op_errno, dict); + UPDATE_PROFILE_STATS (frame, FXATTROP); + STACK_UNWIND_STRICT (fxattrop, frame, op_ret, op_errno, dict, xdata); return 0; } int io_stats_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - END_FOP_LATENCY (frame, INODELK); - STACK_UNWIND_STRICT (inodelk, frame, op_ret, op_errno); + UPDATE_PROFILE_STATS (frame, INODELK); + STACK_UNWIND_STRICT (inodelk, frame, op_ret, op_errno, xdata); return 0; } - int io_stats_entrylk (call_frame_t *frame, xlator_t *this, const char *volume, loc_t *loc, const char *basename, - entrylk_cmd cmd, entrylk_type type) + entrylk_cmd cmd, entrylk_type type, dict_t *xdata) { - BUMP_FOP (ENTRYLK); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_entrylk_cbk, FIRST_CHILD (this), FIRST_CHILD (this)->fops->entrylk, - volume, loc, basename, cmd, type); + volume, loc, basename, cmd, type, xdata); return 0; } int io_stats_inodelk (call_frame_t *frame, xlator_t *this, - const char *volume, loc_t *loc, int32_t cmd, struct gf_flock *flock) + const char *volume, loc_t *loc, int32_t cmd, struct gf_flock *flock, dict_t *xdata) { - BUMP_FOP (INODELK); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_inodelk_cbk, FIRST_CHILD (this), FIRST_CHILD (this)->fops->inodelk, - volume, loc, cmd, flock); + volume, loc, cmd, flock, xdata); return 0; } int io_stats_finodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - END_FOP_LATENCY (frame, FINODELK); - STACK_UNWIND_STRICT (finodelk, frame, op_ret, op_errno); + UPDATE_PROFILE_STATS (frame, FINODELK); + STACK_UNWIND_STRICT (finodelk, frame, op_ret, op_errno, xdata); return 0; } int -io_stats_finodelk (call_frame_t *frame, xlator_t *this, - const char *volume, fd_t *fd, int32_t cmd, struct gf_flock *flock) +io_stats_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, + fd_t *fd, int32_t cmd, struct gf_flock *flock, dict_t *xdata) { - BUMP_FOP (FINODELK); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_finodelk_cbk, FIRST_CHILD (this), FIRST_CHILD (this)->fops->finodelk, - volume, fd, cmd, flock); + volume, fd, cmd, flock, xdata); return 0; } int -io_stats_xattrop (call_frame_t *frame, xlator_t *this, - loc_t *loc, gf_xattrop_flags_t flags, dict_t *dict) +io_stats_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { - BUMP_FOP (XATTROP); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_xattrop_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->xattrop, - loc, flags, dict); - + loc, flags, dict, xdata); return 0; } int -io_stats_fxattrop (call_frame_t *frame, xlator_t *this, - fd_t *fd, gf_xattrop_flags_t flags, dict_t *dict) +io_stats_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { - BUMP_FOP (FXATTROP); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_fxattrop_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fxattrop, - fd, flags, dict); - + fd, flags, dict, xdata); return 0; } int io_stats_lookup (call_frame_t *frame, xlator_t *this, - loc_t *loc, dict_t *xattr_req) + loc_t *loc, dict_t *xdata) { - BUMP_FOP (LOOKUP); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_lookup_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->lookup, - loc, xattr_req); - + loc, xdata); return 0; } int -io_stats_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) +io_stats_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { - BUMP_FOP (STAT); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_stat_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->stat, - loc); - + loc, xdata); return 0; } int io_stats_readlink (call_frame_t *frame, xlator_t *this, - loc_t *loc, size_t size) + loc_t *loc, size_t size, dict_t *xdata) { - BUMP_FOP (READLINK); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_readlink_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readlink, - loc, size); - + loc, size, xdata); return 0; } int -io_stats_mknod (call_frame_t *frame, xlator_t *this, - loc_t *loc, mode_t mode, dev_t dev, dict_t *params) +io_stats_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, + mode_t mode, dev_t dev, mode_t umask, dict_t *xdata) { - BUMP_FOP (MKNOD); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_mknod_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mknod, - loc, mode, dev, params); - + loc, mode, dev, umask, xdata); return 0; } int io_stats_mkdir (call_frame_t *frame, xlator_t *this, - loc_t *loc, mode_t mode, dict_t *params) + loc_t *loc, mode_t mode, mode_t umask, dict_t *xdata) { - BUMP_FOP (MKDIR); + frame->local = gf_strdup (loc->path); START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_mkdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mkdir, - loc, mode, params); + loc, mode, umask, xdata); return 0; } int io_stats_unlink (call_frame_t *frame, xlator_t *this, - loc_t *loc) + loc_t *loc, int xflag, dict_t *xdata) { - BUMP_FOP (UNLINK); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_unlink_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->unlink, - loc); + loc, xflag, xdata); return 0; } int io_stats_rmdir (call_frame_t *frame, xlator_t *this, - loc_t *loc, int flags) + loc_t *loc, int flags, dict_t *xdata) { - BUMP_FOP (RMDIR); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_rmdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->rmdir, - loc, flags); - + loc, flags, xdata); return 0; } int -io_stats_symlink (call_frame_t *frame, xlator_t *this, - const char *linkpath, loc_t *loc, dict_t *params) +io_stats_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath, + loc_t *loc, mode_t umask, dict_t *xdata) { - BUMP_FOP (SYMLINK); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_symlink_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->symlink, - linkpath, loc, params); - + linkpath, loc, umask, xdata); return 0; } int io_stats_rename (call_frame_t *frame, xlator_t *this, - loc_t *oldloc, loc_t *newloc) + loc_t *oldloc, loc_t *newloc, dict_t *xdata) { - BUMP_FOP (RENAME); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_rename_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->rename, - oldloc, newloc); - + oldloc, newloc, xdata); return 0; } int io_stats_link (call_frame_t *frame, xlator_t *this, - loc_t *oldloc, loc_t *newloc) + loc_t *oldloc, loc_t *newloc, dict_t *xdata) { - BUMP_FOP (LINK); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_link_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->link, - oldloc, newloc); + oldloc, newloc, xdata); return 0; } int io_stats_setattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, struct iatt *stbuf, int32_t valid) + loc_t *loc, struct iatt *stbuf, int32_t valid, dict_t *xdata) { - BUMP_FOP (SETATTR); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_setattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->setattr, - loc, stbuf, valid); - + loc, stbuf, valid, xdata); return 0; } int io_stats_truncate (call_frame_t *frame, xlator_t *this, - loc_t *loc, off_t offset) + loc_t *loc, off_t offset, dict_t *xdata) { - BUMP_FOP (TRUNCATE); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_truncate_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->truncate, - loc, offset); - + loc, offset, xdata); return 0; } int -io_stats_open (call_frame_t *frame, xlator_t *this, - loc_t *loc, int32_t flags, fd_t *fd, int32_t wbflags) +io_stats_open (call_frame_t *frame, xlator_t *this, loc_t *loc, + int32_t flags, fd_t *fd, dict_t *xdata) { - BUMP_FOP (OPEN); - frame->local = gf_strdup (loc->path); START_FOP_LATENCY (frame); @@ -1157,7 +2069,7 @@ io_stats_open (call_frame_t *frame, xlator_t *this, STACK_WIND (frame, io_stats_open_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->open, - loc, flags, fd, wbflags); + loc, flags, fd, xdata); return 0; } @@ -1165,10 +2077,8 @@ io_stats_open (call_frame_t *frame, xlator_t *this, int io_stats_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, mode_t mode, - fd_t *fd, dict_t *params) + mode_t umask, fd_t *fd, dict_t *xdata) { - BUMP_FOP (CREATE); - frame->local = gf_strdup (loc->path); START_FOP_LATENCY (frame); @@ -1176,17 +2086,15 @@ io_stats_create (call_frame_t *frame, xlator_t *this, STACK_WIND (frame, io_stats_create_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->create, - loc, flags, mode, fd, params); + loc, flags, mode, umask, fd, xdata); return 0; } int io_stats_readv (call_frame_t *frame, xlator_t *this, - fd_t *fd, size_t size, off_t offset) + fd_t *fd, size_t size, off_t offset, uint32_t flags, dict_t *xdata) { - BUMP_FOP (READ); - frame->local = fd; START_FOP_LATENCY (frame); @@ -1194,7 +2102,7 @@ io_stats_readv (call_frame_t *frame, xlator_t *this, STACK_WIND (frame, io_stats_readv_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readv, - fd, size, offset); + fd, size, offset, flags, xdata); return 0; } @@ -1203,75 +2111,69 @@ int io_stats_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector, int32_t count, off_t offset, - struct iobref *iobref) + uint32_t flags, struct iobref *iobref, dict_t *xdata) { int len = 0; - + if (fd->inode) + frame->local = fd->inode; len = iov_length (vector, count); - BUMP_FOP (WRITE); BUMP_WRITE (fd, len); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_writev_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->writev, - fd, vector, count, offset, iobref); + fd, vector, count, offset, flags, iobref, xdata); return 0; + } int io_stats_statfs (call_frame_t *frame, xlator_t *this, - loc_t *loc) + loc_t *loc, dict_t *xdata) { - BUMP_FOP (STATFS); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_statfs_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->statfs, - loc); + loc, xdata); return 0; } int io_stats_flush (call_frame_t *frame, xlator_t *this, - fd_t *fd) + fd_t *fd, dict_t *xdata) { - BUMP_FOP (FLUSH); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_flush_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->flush, - fd); + fd, xdata); return 0; } int io_stats_fsync (call_frame_t *frame, xlator_t *this, - fd_t *fd, int32_t flags) + fd_t *fd, int32_t flags, dict_t *xdata) { - BUMP_FOP (FSYNC); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_fsync_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsync, - fd, flags); + fd, flags, xdata); return 0; } -void +int conditional_dump (dict_t *dict, char *key, data_t *value, void *data) { struct { @@ -1279,30 +2181,43 @@ conditional_dump (dict_t *dict, char *key, data_t *value, void *data) inode_t *inode; const char *path; } *stub; - xlator_t *this = NULL; - inode_t *inode = NULL; - const char *path = NULL; - char *filename = NULL; + xlator_t *this = NULL; + char *filename = NULL; + FILE *logfp = NULL; + struct ios_dump_args args = {0}; stub = data; this = stub->this; - inode = stub->inode; - path = stub->path; filename = alloca (value->len + 1); memset (filename, 0, value->len + 1); memcpy (filename, data_to_str (value), value->len); if (fnmatch ("*io*stat*dump", key, 0) == 0) { - io_stats_dump (this, filename, inode, path); + + if (!strncmp (filename, "", 1)) { + gf_log (this->name, GF_LOG_ERROR, "No filename given"); + return -1; + } + logfp = fopen (filename, "w+"); + if (!logfp) { + gf_log (this->name, GF_LOG_ERROR, "failed to open %s " + "for writing", filename); + return -1; + } + (void) ios_dump_args_init (&args, IOS_DUMP_TYPE_FILE, + logfp); + io_stats_dump (this, &args); + fclose (logfp); } + return 0; } int io_stats_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, - int32_t flags) + int32_t flags, dict_t *xdata) { struct { xlator_t *this; @@ -1310,8 +2225,6 @@ io_stats_setxattr (call_frame_t *frame, xlator_t *this, const char *path; } stub; - BUMP_FOP (SETXATTR); - stub.this = this; stub.inode = loc->inode; stub.path = loc->path; @@ -1323,186 +2236,244 @@ io_stats_setxattr (call_frame_t *frame, xlator_t *this, STACK_WIND (frame, io_stats_setxattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->setxattr, - loc, dict, flags); + loc, dict, flags, xdata); return 0; } int io_stats_getxattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, const char *name) + loc_t *loc, const char *name, dict_t *xdata) { - BUMP_FOP (GETXATTR); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_getxattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->getxattr, - loc, name); + loc, name, xdata); return 0; } int io_stats_removexattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, const char *name) + loc_t *loc, const char *name, dict_t *xdata) { - BUMP_FOP (REMOVEXATTR); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_removexattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->removexattr, - loc, name); + loc, name, xdata); + return 0; +} + + +int +io_stats_fsetxattr (call_frame_t *frame, xlator_t *this, + fd_t *fd, dict_t *dict, + int32_t flags, dict_t *xdata) +{ + START_FOP_LATENCY (frame); + STACK_WIND (frame, io_stats_fsetxattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fsetxattr, + fd, dict, flags, xdata); + return 0; +} + + +int +io_stats_fgetxattr (call_frame_t *frame, xlator_t *this, + fd_t *fd, const char *name, dict_t *xdata) +{ + START_FOP_LATENCY (frame); + + STACK_WIND (frame, io_stats_fgetxattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fgetxattr, + fd, name, xdata); + return 0; +} + + +int +io_stats_fremovexattr (call_frame_t *frame, xlator_t *this, + fd_t *fd, const char *name, dict_t *xdata) +{ + START_FOP_LATENCY (frame); + + STACK_WIND (frame, io_stats_fremovexattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fremovexattr, + fd, name, xdata); return 0; } int io_stats_opendir (call_frame_t *frame, xlator_t *this, - loc_t *loc, fd_t *fd) + loc_t *loc, fd_t *fd, dict_t *xdata) { - BUMP_FOP (OPENDIR); START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_opendir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->opendir, - loc, fd); + loc, fd, xdata); return 0; } int io_stats_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t offset) + off_t offset, dict_t *dict) { - BUMP_FOP (READDIRP); - + frame->local = fd->inode; START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_readdirp_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readdirp, - fd, size, offset); - + fd, size, offset, dict); return 0; } int io_stats_readdir (call_frame_t *frame, xlator_t *this, - fd_t *fd, size_t size, off_t offset) + fd_t *fd, size_t size, off_t offset, dict_t *xdata) { - BUMP_FOP (READDIR); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_readdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readdir, - fd, size, offset); - + fd, size, offset, xdata); return 0; } int io_stats_fsyncdir (call_frame_t *frame, xlator_t *this, - fd_t *fd, int32_t datasync) + fd_t *fd, int32_t datasync, dict_t *xdata) { - BUMP_FOP (FSYNCDIR); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_fsyncdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsyncdir, - fd, datasync); + fd, datasync, xdata); return 0; } int io_stats_access (call_frame_t *frame, xlator_t *this, - loc_t *loc, int32_t mask) + loc_t *loc, int32_t mask, dict_t *xdata) { - BUMP_FOP (ACCESS); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_access_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->access, - loc, mask); + loc, mask, xdata); return 0; } int io_stats_ftruncate (call_frame_t *frame, xlator_t *this, - fd_t *fd, off_t offset) + fd_t *fd, off_t offset, dict_t *xdata) { - BUMP_FOP (FTRUNCATE); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_ftruncate_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->ftruncate, - fd, offset); - + fd, offset, xdata); return 0; } int io_stats_fsetattr (call_frame_t *frame, xlator_t *this, - fd_t *fd, struct iatt *stbuf, int32_t valid) + fd_t *fd, struct iatt *stbuf, int32_t valid, dict_t *xdata) { - BUMP_FOP (FSETATTR); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_setattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsetattr, - fd, stbuf, valid); + fd, stbuf, valid, xdata); return 0; } int io_stats_fstat (call_frame_t *frame, xlator_t *this, - fd_t *fd) + fd_t *fd, dict_t *xdata) { - BUMP_FOP (FSTAT); - START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_fstat_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fstat, - fd); + fd, xdata); return 0; } int -io_stats_lk (call_frame_t *frame, xlator_t *this, - fd_t *fd, int32_t cmd, struct gf_flock *lock) +io_stats_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t mode, + off_t offset, size_t len, dict_t *xdata) { - BUMP_FOP (LK); + START_FOP_LATENCY(frame); + + STACK_WIND(frame, io_stats_fallocate_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fallocate, fd, mode, offset, len, + xdata); + + return 0; +} + +int +io_stats_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + size_t len, dict_t *xdata) +{ + START_FOP_LATENCY(frame); + + STACK_WIND(frame, io_stats_discard_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->discard, fd, offset, len, xdata); + + return 0; +} + +int +io_stats_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + size_t len, dict_t *xdata) +{ + START_FOP_LATENCY(frame); + + STACK_WIND(frame, io_stats_zerofill_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->zerofill, fd, offset, len, xdata); + + return 0; +} + + +int +io_stats_lk (call_frame_t *frame, xlator_t *this, + fd_t *fd, int32_t cmd, struct gf_flock *lock, dict_t *xdata) +{ START_FOP_LATENCY (frame); STACK_WIND (frame, io_stats_lk_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->lk, - fd, cmd, lock); + fd, cmd, lock, xdata); return 0; } @@ -1511,15 +2482,23 @@ int io_stats_release (xlator_t *this, fd_t *fd) { struct ios_fd *iosfd = NULL; + struct ios_conf *conf = NULL; BUMP_FOP (RELEASE); + conf = this->private; + + LOCK (&conf->lock); + { + conf->cumulative.nr_opens--; + } + UNLOCK (&conf->lock); + ios_fd_ctx_get (fd, this, &iosfd); if (iosfd) { io_stats_dump_fd (this, iosfd); - if (iosfd->filename) - GF_FREE (iosfd->filename); + GF_FREE (iosfd->filename); GF_FREE (iosfd); } @@ -1540,62 +2519,141 @@ int io_stats_forget (xlator_t *this, inode_t *inode) { BUMP_FOP (FORGET); + ios_stats_cleanup (this, inode); + return 0; +} + +static int +ios_init_top_stats (struct ios_conf *conf) +{ + int i = 0; + + GF_ASSERT (conf); + + for (i = 0; i <IOS_STATS_TYPE_MAX; i++) { + conf->list[i].iosstats = GF_CALLOC (1, + sizeof(*conf->list[i].iosstats), + gf_io_stats_mt_ios_stat); + + if (!conf->list[i].iosstats) + return -1; + + INIT_LIST_HEAD(&conf->list[i].iosstats->list); + LOCK_INIT (&conf->list[i].lock); + } + + for (i = 0; i < IOS_STATS_THRU_MAX; i ++) { + conf->thru_list[i].iosstats = GF_CALLOC (1, + sizeof (*conf->thru_list[i].iosstats), + gf_io_stats_mt_ios_stat); + + if (!conf->thru_list[i].iosstats) + return -1; + + INIT_LIST_HEAD(&conf->thru_list[i].iosstats->list); + LOCK_INIT (&conf->thru_list[i].lock); + } return 0; } +static void +ios_destroy_top_stats (struct ios_conf *conf) +{ + int i = 0; + struct ios_stat_head *list_head = NULL; + struct ios_stat_list *entry = NULL; + struct ios_stat_list *tmp = NULL; + struct ios_stat_list *list = NULL; + struct ios_stat *stat = NULL; + + GF_ASSERT (conf); + + LOCK (&conf->lock); + + conf->cumulative.nr_opens = 0; + conf->cumulative.max_nr_opens = 0; + conf->cumulative.max_openfd_time.tv_sec = 0; + conf->cumulative.max_openfd_time.tv_usec = 0; + + for (i = 0; i < IOS_STATS_TYPE_MAX; i++) { + list_head = &conf->list[i]; + if (!list_head) + continue; + list_for_each_entry_safe (entry, tmp, + &list_head->iosstats->list, list) { + list = entry; + stat = list->iosstat; + ios_stat_unref (stat); + list_del (&list->list); + GF_FREE (list); + list_head->members--; + } + } + + for (i = 0; i < IOS_STATS_THRU_MAX; i++) { + list_head = &conf->thru_list[i]; + if (!list_head) + continue; + list_for_each_entry_safe (entry, tmp, + &list_head->iosstats->list, list) { + list = entry; + stat = list->iosstat; + ios_stat_unref (stat); + list_del (&list->list); + GF_FREE (list); + list_head->members--; + } + } + + UNLOCK (&conf->lock); + + return; +} + int reconfigure (xlator_t *this, dict_t *options) { struct ios_conf *conf = NULL; - char *str = NULL; - int ret = 0; + int ret = -1; + char *sys_log_str = NULL; + int sys_log_level = -1; char *log_str = NULL; - glusterfs_ctx_t *ctx = NULL; + int log_level = -1; if (!this || !this->private) - return -1; + goto out; conf = this->private; - ret = dict_get_str (options, "dump-fd-stats", &str); - if (ret == 0) { - ret = gf_string2boolean (str, &conf->dump_fd_stats); - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "'dump-fd-stats' takes only boolean arguments"); - return -1; - } + GF_OPTION_RECONF ("dump-fd-stats", conf->dump_fd_stats, options, bool, + out); - if (conf->dump_fd_stats) { - gf_log (this->name, GF_LOG_DEBUG, - "enabling dump-fd-stats"); - } - } + GF_OPTION_RECONF ("count-fop-hits", conf->count_fop_hits, options, bool, + out); - ret = dict_get_str_boolean (options, "latency-measurement", 0); - if (ret != -1) { - if (conf->measure_latency != ret) { - gf_log (this->name, GF_LOG_DEBUG, - "changing latency measurement from %d to %d", - conf->measure_latency, ret); - } - conf->measure_latency = ret; + GF_OPTION_RECONF ("latency-measurement", conf->measure_latency, + options, bool, out); + + GF_OPTION_RECONF ("sys-log-level", sys_log_str, options, str, out); + if (sys_log_str) { + sys_log_level = glusterd_check_log_level (sys_log_str); + set_sys_log_level (sys_log_level); } - ctx = glusterfs_ctx_get (); - if (!ctx) - return -1; - ret = dict_get_str (options, "log-level", &log_str); - if (!ret) { - if (!is_gf_log_command(this, "trusted.glusterfs.set-log-level", log_str)) { - gf_log (this->name, GF_LOG_DEBUG, - "changing log-level to %s", log_str); - } + GF_OPTION_RECONF ("log-level", log_str, options, str, out); + if (log_str) { + log_level = glusterd_check_log_level (log_str); + gf_log_set_loglevel (log_level); } - return 0; + + ret = 0; +out: + gf_log (this->name, GF_LOG_DEBUG, "reconfigure returning %d", ret); + return ret; } + int32_t mem_acct_init (xlator_t *this) { @@ -1605,7 +2663,7 @@ mem_acct_init (xlator_t *this) return ret; ret = xlator_mem_acct_init (this, gf_io_stats_mt_end + 1); - + if (ret != 0) { gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" " failed"); @@ -1618,28 +2676,30 @@ mem_acct_init (xlator_t *this) int init (xlator_t *this) { - dict_t *options = NULL; struct ios_conf *conf = NULL; - char *str = NULL; - int ret = 0; + char *sys_log_str = NULL; + int sys_log_level = -1; char *log_str = NULL; + int log_level = -1; + int ret = -1; if (!this) return -1; - if (!this->children || this->children->next) { + if (!this->children) { gf_log (this->name, GF_LOG_ERROR, - "io_stats translator requires one subvolume"); + "io_stats translator requires atleast one subvolume"); return -1; } if (!this->parents) { - gf_log (this->name, GF_LOG_WARNING, + /* This is very much valid as io-stats currently is loaded + * on top of volumes on both client and server, hence this is + * not an warning message */ + gf_log (this->name, GF_LOG_DEBUG, "dangling volume. check volfile "); } - options = this->options; - conf = GF_CALLOC (1, sizeof(*conf), gf_io_stats_mt_ios_conf); if (!conf) { @@ -1653,40 +2713,33 @@ init (xlator_t *this) gettimeofday (&conf->cumulative.started_at, NULL); gettimeofday (&conf->incremental.started_at, NULL); - ret = dict_get_str (options, "dump-fd-stats", &str); - if (ret == 0) { - ret = gf_string2boolean (str, &conf->dump_fd_stats); - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "'dump-fd-stats' takes only boolean arguments"); - return -1; - } + ret = ios_init_top_stats (conf); + if (ret) + return -1; - if (conf->dump_fd_stats) { - gf_log (this->name, GF_LOG_DEBUG, - "enabling dump-fd-stats"); - } - } + GF_OPTION_INIT ("dump-fd-stats", conf->dump_fd_stats, bool, out); - ret = dict_get_str_boolean (options, "latency-measurement", 0); - if (ret != -1) { - conf->measure_latency = ret; - if (conf->measure_latency) - gf_log (this->name, GF_LOG_DEBUG, - "enabling latency measurement"); + GF_OPTION_INIT ("count-fop-hits", conf->count_fop_hits, bool, out); + + GF_OPTION_INIT ("latency-measurement", conf->measure_latency, + bool, out); + + GF_OPTION_INIT ("sys-log-level", sys_log_str, str, out); + if (sys_log_str) { + sys_log_level = glusterd_check_log_level (sys_log_str); + set_sys_log_level (sys_log_level); } - ret = dict_get_str (options, "log-level", &log_str); - if (!ret) { - if (!is_gf_log_command(this, "trusted.glusterfs.set-log-level", log_str)) { - gf_log (this->name, GF_LOG_DEBUG, - "changing log-level to %s", log_str); - } + GF_OPTION_INIT ("log-level", log_str, str, out); + if (log_str) { + log_level = glusterd_check_log_level (log_str); + gf_log_set_loglevel (log_level); } this->private = conf; - - return 0; + ret = 0; +out: + return ret; } @@ -1704,28 +2757,96 @@ fini (xlator_t *this) return; this->private = NULL; + ios_destroy_top_stats (conf); + GF_FREE(conf); - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_INFO, "io-stats translator unloaded"); return; } int -validate_options (xlator_t *this, dict_t *options, char **op_errstr) -{ - int ret = -1; - char *log_str = NULL; +notify (xlator_t *this, int32_t event, void *data, ...) +{ + int ret = 0; + struct ios_dump_args args = {0}; + dict_t *output = NULL; + dict_t *dict = NULL; + int32_t top_op = 0; + int32_t list_cnt = 0; + double throughput = 0; + double time = 0; + va_list ap; + + dict = data; + va_start (ap, data); + output = va_arg (ap, dict_t*); + va_end (ap); + switch (event) { + case GF_EVENT_TRANSLATOR_INFO: + ret = dict_get_str_boolean (dict, "clear-stats", _gf_false); + if (ret) { + ret = dict_set_int32 (output, "top-op", top_op); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "Failed to set top-op in dict"); + goto out; + } + ios_destroy_top_stats (this->private); + ret = ios_init_top_stats (this->private); + if (ret) + gf_log (this->name, GF_LOG_ERROR, + "Failed to reset top stats"); + ret = dict_set_int32 (output, "stats-cleared", + ret ? 0 : 1); + if (ret) + gf_log (this->name, GF_LOG_ERROR, + "Failed to set stats-cleared" + " in dict"); + goto out; + } - ret = dict_get_str (options, "log-level", &log_str); - if (ret) - return 0; - ret = glusterd_check_log_level(log_str); - if (ret == -1) - *op_errstr = gf_strdup ("Invalid log level. possible option are" - " DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE"); - else - ret = 0; + ret = dict_get_int32 (dict, "top-op", &top_op); + if (!ret) { + ret = dict_get_int32 (dict, "list-cnt", &list_cnt); + if (top_op > IOS_STATS_TYPE_NONE && + top_op < IOS_STATS_TYPE_MAX) + ret = io_stats_dump_stats_to_dict (this, output, + top_op, list_cnt); + if (top_op == IOS_STATS_TYPE_READ_THROUGHPUT || + top_op == IOS_STATS_TYPE_WRITE_THROUGHPUT) { + ret = dict_get_double (dict, "throughput", + &throughput); + if (!ret) { + ret = dict_get_double (dict, "time", + &time); + if (ret) + goto out; + ret = dict_set_double (output, + "throughput", throughput); + if (ret) + goto out; + ret = dict_set_double (output, "time", + time); + if (ret) + goto out; + } + ret = 0; + + } + } else { + (void) ios_dump_args_init (&args, IOS_DUMP_TYPE_DICT, + output); + ret = io_stats_dump (this, &args); + } + break; + default: + default_notify (this, event, data); + break; + + } +out: return ret; } @@ -1749,6 +2870,9 @@ struct xlator_fops fops = { .setxattr = io_stats_setxattr, .getxattr = io_stats_getxattr, .removexattr = io_stats_removexattr, + .fsetxattr = io_stats_fsetxattr, + .fgetxattr = io_stats_fgetxattr, + .fremovexattr = io_stats_fremovexattr, .opendir = io_stats_opendir, .readdir = io_stats_readdir, .readdirp = io_stats_readdirp, @@ -1766,6 +2890,9 @@ struct xlator_fops fops = { .fxattrop = io_stats_fxattrop, .setattr = io_stats_setattr, .fsetattr = io_stats_fsetattr, + .fallocate = io_stats_fallocate, + .discard = io_stats_discard, + .zerofill = io_stats_zerofill, }; struct xlator_cbks cbks = { @@ -1777,12 +2904,47 @@ struct xlator_cbks cbks = { struct volume_options options[] = { { .key = {"dump-fd-stats"}, .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "If on stats related to file-operations would be " + "tracked inside GlusterFS data-structures." }, { .key = { "latency-measurement" }, .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "If on stats related to the latency of each operation " + "would be tracked inside GlusterFS data-structures. " + }, + { .key = {"count-fop-hits"}, + .type = GF_OPTION_TYPE_BOOL, }, { .key = {"log-level"}, .type = GF_OPTION_TYPE_STR, + .value = { "DEBUG", "WARNING", "ERROR", "INFO", + "CRITICAL", "NONE", "TRACE"} + }, + + /* These are synthetic entries to assist validation of CLI's * + * volume set command */ + { .key = {"client-log-level"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "INFO", + .description = "Changes the log-level of the clients", + .value = { "DEBUG", "WARNING", "ERROR", "INFO", + "CRITICAL", "NONE", "TRACE"} + }, + { .key = {"sys-log-level"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "CRITICAL", + .description = "Gluster's syslog log-level", + .value = { "WARNING", "ERROR", "INFO", "CRITICAL"} + }, + { .key = {"brick-log-level"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "INFO", + .description = "Changes the log-level of the bricks", + .value = { "DEBUG", "WARNING", "ERROR", "INFO", + "CRITICAL", "NONE", "TRACE"} }, { .key = {NULL} }, + }; diff --git a/xlators/debug/trace/src/Makefile.am b/xlators/debug/trace/src/Makefile.am index 0f1679a04..7b2597b4d 100644 --- a/xlators/debug/trace/src/Makefile.am +++ b/xlators/debug/trace/src/Makefile.am @@ -2,13 +2,15 @@ xlator_LTLIBRARIES = trace.la xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/debug -trace_la_LDFLAGS = -module -avoidversion +trace_la_LDFLAGS = -module -avoid-version trace_la_SOURCES = trace.c trace_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) +noinst_HEADERS = trace.h trace-mem-types.h +AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src + +AM_CFLAGS = -Wall $(GF_CFLAGS) CLEANFILES = diff --git a/xlators/debug/trace/src/trace-mem-types.h b/xlators/debug/trace/src/trace-mem-types.h new file mode 100644 index 000000000..9fa7d97c2 --- /dev/null +++ b/xlators/debug/trace/src/trace-mem-types.h @@ -0,0 +1,21 @@ +/* + Copyright (c) 2006-2012 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 __TRACE_MEM_TYPES_H__ +#define __TRACE_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_trace_mem_types_ { + gf_trace_mt_trace_conf_t = gf_common_mt_end + 1, + gf_trace_mt_end +}; +#endif diff --git a/xlators/debug/trace/src/trace.c b/xlators/debug/trace/src/trace.c index a562e813e..c9d839356 100644 --- a/xlators/debug/trace/src/trace.c +++ b/xlators/debug/trace/src/trace.c @@ -1,26 +1,15 @@ /* - Copyright (c) 2006-2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2006-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif +#include "trace.h" +#include "trace-mem-types.h" /** * xlators/debug/trace : @@ -29,1209 +18,1445 @@ * Very helpful translator for debugging. */ -#include <time.h> -#include <errno.h> -#include "glusterfs.h" -#include "xlator.h" -#include "common-utils.h" - -#define ERR_EINVAL_NORETURN(cond) \ - do \ - { \ - if ((cond)) \ - { \ - gf_log ("ERROR", GF_LOG_ERROR, \ - "%s: %s: (%s) is true", \ - __FILE__, __FUNCTION__, #cond); \ - } \ - } while (0) - - -typedef struct trace_private { - int32_t debug_flag; -} trace_private_t; - - -struct { - char *name; - int enabled; -} trace_fop_names[GF_FOP_MAXVALUE]; - -int trace_log_level = GF_LOG_NORMAL; - -static char * -trace_stat_to_str (struct iatt *stbuf) +int +dump_history_trace (circular_buffer_t *cb, void *data) { - char *statstr = NULL; - char atime_buf[256] = {0,}; - char mtime_buf[256] = {0,}; - char ctime_buf[256] = {0,}; - int asprint_ret_value = 0; - uint64_t ia_time = 0; + char *string = NULL; + struct tm *tm = NULL; + char timestr[256] = {0,}; - ia_time = stbuf->ia_atime; - strftime (atime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); + string = (char *)cb->data; + tm = localtime (&cb->tv.tv_sec); - ia_time = stbuf->ia_mtime; - strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = stbuf->ia_ctime; - strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - asprint_ret_value = gf_asprintf (&statstr, - "ia_ino=%"PRIu64 - ", st_mode=%o, ia_nlink=%"GF_PRI_NLINK", " - "ia_uid=%d, ia_gid=%d, ia_size=%"PRId64", ia_blocks=%"PRId64 - ", ia_atime=%s, ia_mtime=%s, ia_ctime=%s", - stbuf->ia_ino, - st_mode_from_ia (stbuf->ia_prot, stbuf->ia_type), - stbuf->ia_nlink, stbuf->ia_uid, - stbuf->ia_gid, stbuf->ia_size, - stbuf->ia_blocks, atime_buf, - mtime_buf, ctime_buf); + /* Since we are continuing with adding entries to the buffer even when + gettimeofday () fails, it's safe to check tm and then dump the time + at which the entry was added to the buffer */ + if (tm) { + strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); + snprintf (timestr + strlen (timestr), 256 - strlen (timestr), + ".%"GF_PRI_SUSECONDS, cb->tv.tv_usec); + gf_proc_dump_write ("TIME", "%s", timestr); + } - if (asprint_ret_value < 0) - statstr = NULL; + gf_proc_dump_write ("FOP", "%s\n", string); - return statstr; + return 0; } - int trace_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - char *statstr = NULL; - char *preparentstr = NULL; - char *postparentstr = NULL; + char statstr[4096] = {0, }; + char preparentstr[4096] = {0, }; + char postparentstr[4096] = {0, }; + trace_conf_t *conf = NULL; + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_CREATE].enabled) { + char string[4096] = {0,}; if (op_ret >= 0) { - statstr = trace_stat_to_str (buf); - preparentstr = trace_stat_to_str (preparent); - postparentstr = trace_stat_to_str (postparent); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, fd=%p, ino=%"PRIu64" " - "*stbuf {%s}, *preparent {%s}, *postparent = " - "{%s})", - frame->root->unique, op_ret, fd, inode->ino, - statstr, preparentstr, postparentstr); - - if (statstr) - GF_FREE (statstr); - if (preparentstr) - GF_FREE (preparentstr); - if (postparentstr) - GF_FREE (postparentstr); + trace_stat_to_str (buf, statstr); + trace_stat_to_str (preparent, preparentstr); + trace_stat_to_str (postparent, postparentstr); + + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s (op_ret=%d, fd=%p" + "*stbuf {%s}, *preparent {%s}, " + "*postparent = {%s})", + frame->root->unique, + uuid_utoa (inode->gfid), op_ret, fd, + statstr, preparentstr, postparentstr); + + /* for 'release' log */ + fd_ctx_set (fd, this, 0); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, op_errno=%d)", + frame->root->unique, op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf, - preparent, postparent); +out: + TRACE_STACK_UNWIND (create, frame, op_ret, op_errno, fd, inode, buf, + preparent, postparent, xdata); return 0; } - int trace_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { + trace_conf_t *conf = NULL; + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_OPEN].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d, *fd=%p)", - frame->root->unique, op_ret, op_errno, fd); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d, " + "*fd=%p", frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno, + fd); + + LOG_ELEMENT (conf, string); } - STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd); +out: + /* for 'release' log */ + if (op_ret >= 0) + fd_ctx_set (fd, this, 0); + + TRACE_STACK_UNWIND (open, frame, op_ret, op_errno, fd, xdata); return 0; } - int trace_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf) + int32_t op_ret, int32_t op_errno, struct iatt *buf, + dict_t *xdata) { - uint64_t ia_time = 0; - char atime_buf[256]; - char mtime_buf[256]; - char ctime_buf[256]; - - if (trace_fop_names[GF_FOP_STAT].enabled) { - if (op_ret >= 0) { - ia_time = buf->ia_atime; - strftime (atime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); + char statstr[4096] = {0, }; + trace_conf_t *conf = NULL; - ia_time = buf->ia_mtime; - strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); + conf = this->private; - ia_time = buf->ia_ctime; - strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, buf {" - "ia_ino=%"PRIu64", st_mode=%o, ia_nlink=%"GF_PRI_NLINK", " - "ia_uid=%d, ia_gid=%d, ia_rdev=%"PRIu64", ia_size=%"PRId64 - ", ia_blksize=%"GF_PRI_BLKSIZE", ia_blocks=%"PRId64", " - "ia_atime=%s, ia_mtime=%s, ia_ctime=%s})", - frame->root->unique, op_ret, buf->ia_ino, - st_mode_from_ia (buf->ia_prot, buf->ia_type), - buf->ia_nlink, buf->ia_uid, buf->ia_gid, - buf->ia_rdev, buf->ia_size, buf->ia_blksize, - buf->ia_blocks, atime_buf, mtime_buf, ctime_buf); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_STAT].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (buf, statstr); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d buf=%s", + frame->root->unique, + uuid_utoa (frame->local), op_ret, + statstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d)", + frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, buf); +out: + TRACE_STACK_UNWIND (stat, frame, op_ret, op_errno, buf, xdata); return 0; } - int trace_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iovec *vector, - int32_t count, struct iatt *buf, struct iobref *iobref) + int32_t count, struct iatt *buf, struct iobref *iobref, + dict_t *xdata) { - uint64_t ia_time = 0; - char atime_buf[256]; - char mtime_buf[256]; - char ctime_buf[256]; + char statstr[4096] = {0, }; + trace_conf_t *conf = NULL; + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_READ].enabled) { + char string[4096] = {0,}; if (op_ret >= 0) { - ia_time = buf->ia_atime; - strftime (atime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = buf->ia_mtime; - strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = buf->ia_ctime; - strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d, *buf {" - "ia_ino=%"PRIu64", st_mode=%o, ia_nlink=%"GF_PRI_NLINK", " - "ia_uid=%d, ia_gid=%d, ia_rdev=%"PRIu64", " - "ia_size=%"PRId64", ia_blksize=%"GF_PRI_BLKSIZE", " - "ia_blocks=%"PRId64", ia_atime=%s, ia_mtime=%s, ia_ctime=%s})", - frame->root->unique, op_ret, op_errno, buf->ia_ino, - st_mode_from_ia (buf->ia_prot, buf->ia_type), - buf->ia_nlink, buf->ia_uid, buf->ia_gid, - buf->ia_rdev, buf->ia_size, buf->ia_blksize, buf->ia_blocks, - atime_buf, mtime_buf, ctime_buf); + trace_stat_to_str (buf, statstr); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d buf=%s", + frame->root->unique, + uuid_utoa (frame->local), op_ret, + statstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d)", + frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector, count, - buf, iobref); +out: + TRACE_STACK_UNWIND (readv, frame, op_ret, op_errno, vector, count, + buf, iobref, xdata); return 0; } - int trace_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf) + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { - char *preopstr = NULL; - char *postopstr = NULL; + char preopstr[4096] = {0, }; + char postopstr[4096] = {0, }; + trace_conf_t *conf = NULL; + + conf = this->private; + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_WRITE].enabled) { + char string[4096] = {0,}; if (op_ret >= 0) { - preopstr = trace_stat_to_str (prebuf); - postopstr = trace_stat_to_str (postbuf); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, ino = %"PRIu64 - ", *prebuf = {%s}, *postbuf = {%s})", - frame->root->unique, op_ret, postbuf->ia_ino, - preopstr, postopstr); - - if (preopstr) - GF_FREE (preopstr); - - if (postopstr) - GF_FREE (postopstr); + trace_stat_to_str (prebuf, preopstr); + trace_stat_to_str (postbuf, postopstr); + + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, " + "*prebuf = {%s}, *postbuf = {%s})", + frame->root->unique, op_ret, + preopstr, postopstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d", frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf); +out: + TRACE_STACK_UNWIND (writev, frame, op_ret, op_errno, prebuf, postbuf, + xdata); return 0; } - - int trace_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *buf) + int32_t op_ret, int32_t op_errno, gf_dirent_t *buf, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_READDIR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64" :(op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64" : gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, uuid_utoa (frame->local), + op_ret, op_errno); - STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, buf); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (readdir, frame, op_ret, op_errno, buf, xdata); return 0; } - int trace_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *buf) + int32_t op_ret, int32_t op_errno, gf_dirent_t *buf, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_READDIRP].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64" :(op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64" : gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, uuid_utoa (frame->local), + op_ret, op_errno); - STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno, buf); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (readdirp, frame, op_ret, op_errno, buf, xdata); return 0; } - int trace_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf) + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { - char *preopstr = NULL; - char *postopstr = NULL; + char preopstr[4096] = {0, }; + char postopstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (trace_fop_names[GF_FOP_FSYNC].enabled) { - if (op_ret >= 0) { - preopstr = trace_stat_to_str (prebuf); - postopstr = trace_stat_to_str (postbuf); + conf = this->private; - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, ino = %"PRIu64 - ", *prebuf = {%s}, *postbuf = {%s}", - frame->root->unique, op_ret, postbuf->ia_ino, - preopstr, postopstr); - - if (preopstr) - GF_FREE (preopstr); - - if (postopstr) - GF_FREE (postopstr); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FSYNC].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (prebuf, preopstr); + trace_stat_to_str (postbuf, postopstr); + + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, " + "*prebuf = {%s}, *postbuf = {%s}", + frame->root->unique, op_ret, + preopstr, postopstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d", frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); + } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, prebuf, postbuf); +out: + TRACE_STACK_UNWIND (fsync, frame, op_ret, op_errno, prebuf, postbuf, + xdata); return 0; } - int trace_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost) + struct iatt *statpre, struct iatt *statpost, dict_t *xdata) { - uint64_t ia_time = 0; - char atime_pre[256] = {0,}; - char mtime_pre[256] = {0,}; - char ctime_pre[256] = {0,}; - char atime_post[256] = {0,}; - char mtime_post[256] = {0,}; - char ctime_post[256] = {0,}; - - if (trace_fop_names[GF_FOP_SETATTR].enabled) { - if (op_ret >= 0) { - ia_time = statpre->ia_atime; - strftime (atime_pre, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = statpre->ia_mtime; - strftime (mtime_pre, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = statpre->ia_ctime; - strftime (ctime_pre, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); + char preopstr[4096] = {0, }; + char postopstr[4096] = {0, }; + trace_conf_t *conf = NULL; - ia_time = statpost->ia_atime; - strftime (atime_post, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = statpost->ia_mtime; - strftime (mtime_post, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = statpost->ia_ctime; - strftime (ctime_post, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); + conf = this->private; - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *statpre " - "{ia_ino=%"PRIu64", st_mode=%o, ia_uid=%d, " - "ia_gid=%d, ia_atime=%s, ia_mtime=%s, " - "ia_ctime=%s}, *statpost {ia_ino=%"PRIu64", " - "st_mode=%o, ia_uid=%d, ia_gid=%d, ia_atime=%s," - " ia_mtime=%s, ia_ctime=%s})", - frame->root->unique, op_ret, statpre->ia_ino, - st_mode_from_ia (statpre->ia_prot, statpre->ia_type), - statpre->ia_uid, - statpre->ia_gid, atime_pre, mtime_pre, - ctime_pre, statpost->ia_ino, - st_mode_from_ia (statpost->ia_prot, statpost->ia_type), - statpost->ia_uid, statpost->ia_gid, atime_post, - mtime_post, ctime_post); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_SETATTR].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (statpre, preopstr); + trace_stat_to_str (statpost, postopstr); + + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, " + "*prebuf = {%s}, *postbuf = {%s})", + frame->root->unique, op_ret, + preopstr, postopstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d)", frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno, statpre, statpost); +out: + TRACE_STACK_UNWIND (setattr, frame, op_ret, op_errno, statpre, + statpost, xdata); return 0; } - int trace_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost) + struct iatt *statpre, struct iatt *statpost, dict_t *xdata) { - uint64_t ia_time = 0; - char atime_pre[256] = {0,}; - char mtime_pre[256] = {0,}; - char ctime_pre[256] = {0,}; - char atime_post[256] = {0,}; - char mtime_post[256] = {0,}; - char ctime_post[256] = {0,}; + char preopstr[4096] = {0, }; + char postopstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (trace_fop_names[GF_FOP_FSETATTR].enabled) { - if (op_ret >= 0) { - ia_time = statpre->ia_atime; - strftime (atime_pre, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = statpre->ia_mtime; - strftime (mtime_pre, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = statpre->ia_ctime; - strftime (ctime_pre, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); + conf = this->private; - ia_time = statpost->ia_atime; - strftime (atime_post, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = statpost->ia_mtime; - strftime (mtime_post, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = statpost->ia_ctime; - strftime (ctime_post, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *statpre " - "{ia_ino=%"PRIu64", st_mode=%o, ia_uid=%d, " - "ia_gid=%d, ia_atime=%s, ia_mtime=%s, " - "ia_ctime=%s}, *statpost {ia_ino=%"PRIu64", " - "st_mode=%o, ia_uid=%d, ia_gid=%d, ia_atime=%s," - " ia_mtime=%s, ia_ctime=%s})", - frame->root->unique, op_ret, statpre->ia_ino, - st_mode_from_ia (statpre->ia_prot, statpre->ia_type), - statpre->ia_uid, - statpre->ia_gid, atime_pre, mtime_pre, - ctime_pre, statpost->ia_ino, - st_mode_from_ia (statpost->ia_prot, statpost->ia_type), - statpost->ia_uid, statpost->ia_gid, atime_post, - mtime_post, ctime_post); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FSETATTR].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (statpre, preopstr); + trace_stat_to_str (statpost, postopstr); + + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, " + "*prebuf = {%s}, *postbuf = {%s})", + frame->root->unique, op_ret, + preopstr, postopstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d)", + frame->root->unique, uuid_utoa (frame->local), + op_ret, op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (fsetattr, frame, op_ret, op_errno, - statpre, statpost); +out: + TRACE_STACK_UNWIND (fsetattr, frame, op_ret, op_errno, + statpre, statpost, xdata); return 0; } - int trace_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - char *preparentstr = NULL; - char *postparentstr = NULL; + char preparentstr[4096] = {0, }; + char postparentstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (trace_fop_names[GF_FOP_UNLINK].enabled) { - if (op_ret >= 0) { - preparentstr = trace_stat_to_str (preparent); - postparentstr = trace_stat_to_str (postparent); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *preparent = {%s}, " - "*postparent = {%s})", - frame->root->unique, op_ret, preparentstr, - postparentstr); + conf = this->private; - if (preparentstr) - GF_FREE (preparentstr); - - if (postparentstr) - GF_FREE (postparentstr); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_UNLINK].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (preparent, preparentstr); + trace_stat_to_str (postparent, postparentstr); + + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + " *preparent = {%s}, " + "*postparent = {%s})", + frame->root->unique, + uuid_utoa (frame->local), + op_ret, preparentstr, + postparentstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d)", + frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, - preparent, postparent); +out: + TRACE_STACK_UNWIND (unlink, frame, op_ret, op_errno, + preparent, postparent, xdata); return 0; } - int trace_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iatt *buf, struct iatt *preoldparent, struct iatt *postoldparent, - struct iatt *prenewparent, struct iatt *postnewparent) + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t *xdata) { - char *statstr = NULL; - char *preoldparentstr = NULL; - char *postoldparentstr = NULL; - char *prenewparentstr = NULL; - char *postnewparentstr = NULL; - - if (trace_fop_names[GF_FOP_RENAME].enabled) { - if (op_ret >= 0) { - statstr = trace_stat_to_str (buf); - preoldparentstr = trace_stat_to_str (preoldparent); - postoldparentstr = trace_stat_to_str (postoldparent); - - prenewparentstr = trace_stat_to_str (prenewparent); - postnewparentstr = trace_stat_to_str (postnewparent); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *stbuf = {%s}, " - "*preoldparent = {%s}, *postoldparent = {%s}" - " *prenewparent = {%s}, *postnewparent = {%s})", - frame->root->unique, op_ret, statstr, - preoldparentstr, postoldparentstr, - prenewparentstr, postnewparentstr); - - if (preoldparentstr) - GF_FREE (preoldparentstr); - - if (postoldparentstr) - GF_FREE (postoldparentstr); + char statstr[4096] = {0, }; + char preoldparentstr[4096] = {0, }; + char postoldparentstr[4096] = {0, }; + char prenewparentstr[4096] = {0, }; + char postnewparentstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (prenewparentstr) - GF_FREE (prenewparentstr); + conf = this->private; - if (postnewparentstr) - GF_FREE (postnewparentstr); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_RENAME].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (buf, statstr); + trace_stat_to_str (preoldparent, preoldparentstr); + trace_stat_to_str (postoldparent, postoldparentstr); + trace_stat_to_str (prenewparent, prenewparentstr); + trace_stat_to_str (postnewparent, postnewparentstr); + + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, " + "*stbuf = {%s}, *preoldparent = {%s}," + " *postoldparent = {%s}" + " *prenewparent = {%s}, " + "*postnewparent = {%s})", + frame->root->unique, op_ret, statstr, + preoldparentstr, postoldparentstr, + prenewparentstr, postnewparentstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d", frame->root->unique, + uuid_utoa (frame->local), + op_ret, op_errno); + } - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d, buf {ia_ino=%"PRIu64"})", - frame->root->unique, op_ret, op_errno, - (buf? buf->ia_ino : 0)); + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (rename, frame, op_ret, op_errno, buf, - preoldparent, postoldparent, - prenewparent, postnewparent); +out: + TRACE_STACK_UNWIND (rename, frame, op_ret, op_errno, buf, + preoldparent, postoldparent, + prenewparent, postnewparent, xdata); return 0; } - int trace_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - const char *buf, struct iatt *stbuf) + const char *buf, struct iatt *stbuf, dict_t *xdata) { - char *statstr = NULL; + char statstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (trace_fop_names[GF_FOP_READLINK].enabled) { + conf = this->private; + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_READLINK].enabled) { + char string[4096] = {0,}; if (op_ret == 0) { - statstr = trace_stat_to_str (stbuf); - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d, buf=%s, " - "stbuf = { %s })", - frame->root->unique, op_ret, op_errno, buf, - statstr); - } else - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d", - frame->root->unique, op_ret, op_errno); + trace_stat_to_str (stbuf, statstr); + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, op_errno=%d," + "buf=%s, stbuf = { %s })", + frame->root->unique, op_ret, op_errno, + buf, statstr); + } else { + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); + } - if (statstr) - GF_FREE (statstr); + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (readlink, frame, op_ret, op_errno, buf, stbuf); +out: + TRACE_STACK_UNWIND (readlink, frame, op_ret, op_errno, buf, stbuf, + xdata); return 0; } - int trace_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, - dict_t *xattr, struct iatt *postparent) + dict_t *xdata, struct iatt *postparent) { - char *statstr = NULL; - char *postparentstr = NULL; + char statstr[4096] = {0, }; + char postparentstr[4096] = {0, }; + trace_conf_t *conf = NULL; + + conf = this->private; + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_LOOKUP].enabled) { - if (op_ret >= 0) { - statstr = trace_stat_to_str (buf); - postparentstr = trace_stat_to_str (postparent); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, ino=%"PRIu64", " - "*buf {%s}, *postparent {%s}", - frame->root->unique, op_ret, inode->ino, - statstr, postparentstr); - - if (statstr) - GF_FREE (statstr); - if (postparentstr) - GF_FREE (postparentstr); + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (buf, statstr); + trace_stat_to_str (postparent, postparentstr); + /* print buf->ia_gfid instead of inode->gfid, + * since if the inode is not yet linked to the + * inode table (fresh lookup) then null gfid + * will be printed. + */ + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s (op_ret=%d " + "*buf {%s}, *postparent {%s}", + frame->root->unique, + uuid_utoa (buf->ia_gfid), + op_ret, statstr, postparentstr); + + /* For 'forget' */ + inode_ctx_put (inode, this, 0); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d)", + frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf, - xattr, postparent); +out: + TRACE_STACK_UNWIND (lookup, frame, op_ret, op_errno, inode, buf, + xdata, postparent); return 0; } - int trace_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - char *statstr = NULL; - char *preparentstr = NULL; - char *postparentstr = NULL; - - if (trace_fop_names[GF_FOP_SYMLINK].enabled) { - if (op_ret >= 0) { - statstr = trace_stat_to_str (buf); - preparentstr = trace_stat_to_str (preparent); - postparentstr = trace_stat_to_str (postparent); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, ino=%"PRIu64", " - "*stbuf = {%s}, *preparent = {%s}, " - "*postparent = {%s})", - frame->root->unique, op_ret, inode->ino, - statstr, preparentstr, postparentstr); + char statstr[4096] = {0, }; + char preparentstr[4096] = {0, }; + char postparentstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (statstr) - GF_FREE (statstr); - - if (preparentstr) - GF_FREE (preparentstr); - - if (postparentstr) - GF_FREE (postparentstr); + conf = this->private; + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_SYMLINK].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (buf, statstr); + trace_stat_to_str (preparent, preparentstr); + trace_stat_to_str (postparent, postparentstr); + + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s (op_ret=%d " + "*stbuf = {%s}, *preparent = {%s}, " + "*postparent = {%s})", + frame->root->unique, + uuid_utoa (inode->gfid), + op_ret, statstr, preparentstr, + postparentstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": op_ret=%d, op_errno=%d", + frame->root->unique, op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (symlink, frame, op_ret, op_errno, inode, buf, - preparent, postparent); +out: + TRACE_STACK_UNWIND (symlink, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); return 0; } - int trace_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - char *statstr = NULL; - char *preparentstr = NULL; - char *postparentstr = NULL; - - if (trace_fop_names[GF_FOP_MKNOD].enabled) { - if (op_ret >= 0) { - statstr = trace_stat_to_str (buf); - preparentstr = trace_stat_to_str (preparent); - postparentstr = trace_stat_to_str (postparent); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, ino=%"PRIu64", " - "*stbuf = {%s}, *preparent = {%s}, " - "*postparent = {%s})", - frame->root->unique, op_ret, inode->ino, - statstr, preparentstr, postparentstr); + char statstr[4096] = {0, }; + char preparentstr[4096] = {0, }; + char postparentstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (statstr) - GF_FREE (statstr); + conf = this->private; - if (preparentstr) - GF_FREE (preparentstr); - - if (postparentstr) - GF_FREE (postparentstr); + if (!conf->log_file && !conf->log_history) + goto out; + char string[4096] = {0,}; + if (trace_fop_names[GF_FOP_MKNOD].enabled) { + if (op_ret == 0) { + trace_stat_to_str (buf, statstr); + trace_stat_to_str (preparent, preparentstr); + trace_stat_to_str (postparent, postparentstr); + + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s (op_ret=%d " + "*stbuf = {%s}, *preparent = {%s}, " + "*postparent = {%s})", + frame->root->unique, + uuid_utoa (inode->gfid), + op_ret, statstr, preparentstr, + postparentstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, op_errno=%d)", + frame->root->unique, op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (mknod, frame, op_ret, op_errno, inode, buf, - preparent, postparent); +out: + TRACE_STACK_UNWIND (mknod, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); return 0; } - int trace_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - char *statstr = NULL; - char *preparentstr = NULL; - char *postparentstr = NULL; + char statstr[4096] = {0, }; + char preparentstr[4096] = {0, }; + char postparentstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (trace_fop_names[GF_FOP_MKDIR].enabled) { - if (op_ret >= 0) { - statstr = trace_stat_to_str (buf); - preparentstr = trace_stat_to_str (preparent); - postparentstr = trace_stat_to_str (postparent); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, ino = %"PRIu64 - ", *stbuf = {%s}, *prebuf = {%s}, " - "*postbuf = {%s} )", - frame->root->unique, op_ret, buf->ia_ino, - statstr, preparentstr, postparentstr); - - if (statstr) - GF_FREE (statstr); - - if (preparentstr) - GF_FREE (preparentstr); + conf = this->private; - if (postparentstr) - GF_FREE (postparentstr); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_MKDIR].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (buf, statstr); + trace_stat_to_str (preparent, preparentstr); + trace_stat_to_str (postparent, postparentstr); + + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s (op_ret=%d " + ", *stbuf = {%s}, *prebuf = {%s}, " + "*postbuf = {%s} )", + frame->root->unique, + uuid_utoa (inode->gfid), + op_ret, statstr, preparentstr, + postparentstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, op_errno=%d)", + frame->root->unique, op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (mkdir, frame, op_ret, op_errno, inode, buf, - preparent, postparent); +out: + TRACE_STACK_UNWIND (mkdir, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); return 0; } - int trace_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - char *statstr = NULL; - char *preparentstr = NULL; - char *postparentstr = NULL; + char statstr[4096] = {0, }; + char preparentstr[4096] = {0, }; + char postparentstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (trace_fop_names[GF_FOP_LINK].enabled) { - if (op_ret >= 0) { - statstr = trace_stat_to_str (buf); - preparentstr = trace_stat_to_str (preparent); - postparentstr = trace_stat_to_str (postparent); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, ino = %"PRIu64 - ", *stbuf = {%s}, *prebuf = {%s}, " - "*postbuf = {%s})", - frame->root->unique, op_ret, buf->ia_ino, - statstr, preparentstr, postparentstr); - - if (statstr) - GF_FREE (statstr); + conf = this->private; - if (preparentstr) - GF_FREE (preparentstr); - - if (postparentstr) - GF_FREE (postparentstr); + if (!conf->log_file && !conf->log_history) + goto out; + char string[4096] = {0,}; + if (trace_fop_names[GF_FOP_LINK].enabled) { + if (op_ret == 0) { + trace_stat_to_str (buf, statstr); + trace_stat_to_str (preparent, preparentstr); + trace_stat_to_str (postparent, postparentstr); + + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, " + "*stbuf = {%s}, *prebuf = {%s}," + " *postbuf = {%s})", + frame->root->unique, op_ret, + statstr, preparentstr, postparentstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), + op_ret, op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (link, frame, op_ret, op_errno, inode, buf, - preparent, postparent); +out: + TRACE_STACK_UNWIND (link, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); return 0; } - int trace_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + char string[4096] = {0,}; if (trace_fop_names[GF_FOP_FLUSH].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, uuid_utoa (frame->local), + op_ret, op_errno); - STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (flush, frame, op_ret, op_errno, xdata); return 0; } - int trace_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + char string[4096] = {0,}; if (trace_fop_names[GF_FOP_OPENDIR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d, fd=%p)", - frame->root->unique, op_ret, op_errno, fd); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d," + " fd=%p", + frame->root->unique, uuid_utoa (frame->local), + op_ret, op_errno, fd); + + LOG_ELEMENT (conf, string); } +out: + /* for 'releasedir' log */ + if (op_ret >= 0) + fd_ctx_set (fd, this, 0); - STACK_UNWIND_STRICT (opendir, frame, op_ret, op_errno, fd); + TRACE_STACK_UNWIND (opendir, frame, op_ret, op_errno, fd, xdata); return 0; } - int trace_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - char *preparentstr = NULL; - char *postparentstr = NULL; - - if (trace_fop_names[GF_FOP_RMDIR].enabled) { - if (op_ret >= 0) { - preparentstr = trace_stat_to_str (preparent); - postparentstr = trace_stat_to_str (postparent); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *prebuf = {%s}, " - "*postbuf = {%s}", - frame->root->unique, op_ret, preparentstr, - postparentstr); + char preparentstr[4096] = {0, }; + char postparentstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (preparentstr) - GF_FREE (preparentstr); + conf = this->private; - if (postparentstr) - GF_FREE (postparentstr); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_RMDIR].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (preparent, preparentstr); + trace_stat_to_str (postparent, postparentstr); + + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "*prebuf={%s}, *postbuf={%s}", + frame->root->unique, + uuid_utoa (frame->local), + op_ret, preparentstr, postparentstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d", frame->root->unique, + uuid_utoa (frame->local), + op_ret, op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (rmdir, frame, op_ret, op_errno, - preparent, postparent); +out: + TRACE_STACK_UNWIND (rmdir, frame, op_ret, op_errno, + preparent, postparent, xdata); return 0; } - int trace_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf) + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { - char *preopstr = NULL; - char *postopstr = NULL; - - if (trace_fop_names[GF_FOP_TRUNCATE].enabled) { - if (op_ret >= 0) { - preopstr = trace_stat_to_str (prebuf); - postopstr = trace_stat_to_str (postbuf); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *prebuf = {%s}, " - "*postbuf = {%s} )", - frame->root->unique, op_ret, preopstr, - postopstr); + char preopstr[4096] = {0, }; + char postopstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (preopstr) - GF_FREE (preopstr); + conf = this->private; - if (postopstr) - GF_FREE (postopstr); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_TRUNCATE].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (prebuf, preopstr); + trace_stat_to_str (postbuf, postopstr); + + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, " + "*prebuf = {%s}, *postbuf = {%s} )", + frame->root->unique, op_ret, + preopstr, postopstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d", frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, prebuf, postbuf); +out: + TRACE_STACK_UNWIND (truncate, frame, op_ret, op_errno, prebuf, + postbuf, xdata); return 0; } - int trace_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct statvfs *buf) + int32_t op_ret, int32_t op_errno, struct statvfs *buf, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_STATFS].enabled) { - if (op_ret >= 0) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": ({f_bsize=%lu, f_frsize=%lu, f_blocks=%"GF_PRI_FSBLK - ", f_bfree=%"GF_PRI_FSBLK", f_bavail=%"GF_PRI_FSBLK", " - "f_files=%"GF_PRI_FSBLK", f_ffree=%"GF_PRI_FSBLK", f_favail=%" - GF_PRI_FSBLK", f_fsid=%lu, f_flag=%lu, f_namemax=%lu}) => ret=%d", - frame->root->unique, buf->f_bsize, buf->f_frsize, buf->f_blocks, - buf->f_bfree, buf->f_bavail, buf->f_files, buf->f_ffree, - buf->f_favail, buf->f_fsid, buf->f_flag, buf->f_namemax, op_ret); + char string[4096] = {0,}; + if (op_ret == 0) { + snprintf (string, sizeof (string), + "%"PRId64": ({f_bsize=%lu, " + "f_frsize=%lu, " + "f_blocks=%"GF_PRI_FSBLK + ", f_bfree=%"GF_PRI_FSBLK", " + "f_bavail=%"GF_PRI_FSBLK", " + "f_files=%"GF_PRI_FSBLK", " + "f_ffree=%"GF_PRI_FSBLK", " + "f_favail=%"GF_PRI_FSBLK", " + "f_fsid=%lu, f_flag=%lu, " + "f_namemax=%lu}) => ret=%d", + frame->root->unique, buf->f_bsize, + buf->f_frsize, buf->f_blocks, + buf->f_bfree, buf->f_bavail, + buf->f_files, buf->f_ffree, + buf->f_favail, buf->f_fsid, + buf->f_flag, buf->f_namemax, op_ret); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": (op_ret=%d, " + "op_errno=%d)", + frame->root->unique, op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (statfs, frame, op_ret, op_errno, buf); +out: + TRACE_STACK_UNWIND (statfs, frame, op_ret, op_errno, buf, xdata); return 0; } - int trace_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_SETXATTR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); - STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (setxattr, frame, op_ret, op_errno, xdata); return 0; } - int trace_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_GETXATTR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d, dict=%p)", - frame->root->unique, op_ret, op_errno, dict); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d," + " dict=%p", frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno, + dict); + + LOG_ELEMENT (conf, string); } +out: + TRACE_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict, xdata); + + return 0; +} + +int +trace_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + trace_conf_t *conf = NULL; + + conf = this->private; - STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FSETXATTR].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (fsetxattr, frame, op_ret, op_errno, xdata); return 0; } +int +trace_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) +{ + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FGETXATTR].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d," + " dict=%p", frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno, + dict); + + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (fgetxattr, frame, op_ret, op_errno, dict, xdata); + + return 0; +} int trace_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_REMOVEXATTR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno); - STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (removexattr, frame, op_ret, op_errno, xdata); return 0; } - int trace_fsyncdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_FSYNCDIR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno); - STACK_UNWIND_STRICT (fsyncdir, frame, op_ret, op_errno); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (fsyncdir, frame, op_ret, op_errno, xdata); return 0; } - int trace_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_ACCESS].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d)", frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno); - STACK_UNWIND_STRICT (access, frame, op_ret, op_errno); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (access, frame, op_ret, op_errno, xdata); return 0; } - int trace_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf) + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { - char *prebufstr = NULL; - char *postbufstr = NULL; - - if (trace_fop_names[GF_FOP_FTRUNCATE].enabled) { - if (op_ret >= 0) { - prebufstr = trace_stat_to_str (prebuf); - postbufstr = trace_stat_to_str (postbuf); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *prebuf = {%s}, " - "*postbuf = {%s} )", - frame->root->unique, op_ret, - prebufstr, postbufstr); - - if (prebufstr) - GF_FREE (prebufstr); + char prebufstr[4096] = {0, }; + char postbufstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (postbufstr) - GF_FREE (postbufstr); + conf = this->private; + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FTRUNCATE].enabled) { + char string[4096] = {0,}; + if (op_ret == 0) { + trace_stat_to_str (prebuf, prebufstr); + trace_stat_to_str (postbuf, postbufstr); + + snprintf (string, sizeof (string), + "%"PRId64": op_ret=%d, " + "*prebuf = {%s}, *postbuf = {%s} )", + frame->root->unique, op_ret, + prebufstr, postbufstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d", frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, prebuf, postbuf); +out: + TRACE_STACK_UNWIND (ftruncate, frame, op_ret, op_errno, prebuf, postbuf, + xdata); return 0; } - int trace_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf) + int32_t op_ret, int32_t op_errno, struct iatt *buf, dict_t *xdata) { - uint64_t ia_time = 0; - char atime_buf[256] = {0, }; - char mtime_buf[256] = {0, }; - char ctime_buf[256] = {0, }; + char statstr[4096] = {0, }; + trace_conf_t *conf = NULL; - if (trace_fop_names[GF_FOP_FSTAT].enabled) { - if (op_ret >= 0) { - ia_time = buf->ia_atime; - strftime (atime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); + conf = this->private; - ia_time = buf->ia_mtime; - strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - ia_time = buf->ia_ctime; - strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", - localtime ((time_t *)&ia_time)); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *buf {" - "ia_ino=%"PRIu64", st_mode=%o, ia_nlink=%"GF_PRI_NLINK", " - "ia_uid=%d, ia_gid=%d, ia_rdev=%"PRIu64", ia_size=%"PRId64", " - "ia_blksize=%"GF_PRI_BLKSIZE", ia_blocks=%"PRId64", ia_atime=%s, " - "ia_mtime=%s, ia_ctime=%s})", - frame->root->unique, op_ret, buf->ia_ino, - st_mode_from_ia (buf->ia_prot, buf->ia_type), - buf->ia_nlink, buf->ia_uid, buf->ia_gid, - buf->ia_rdev, buf->ia_size, buf->ia_blksize, - buf->ia_blocks, atime_buf, mtime_buf, ctime_buf); + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FSTAT].enabled) { + char string[4096] = {0.}; + if (op_ret == 0) { + trace_stat_to_str (buf, statstr); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d " + "buf=%s", frame->root->unique, + uuid_utoa (frame->local), op_ret, + statstr); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d", frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); } + LOG_ELEMENT (conf, string); } - - STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf); +out: + TRACE_STACK_UNWIND (fstat, frame, op_ret, op_errno, buf, xdata); return 0; } - int trace_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct gf_flock *lock) + int32_t op_ret, int32_t op_errno, struct gf_flock *lock, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_LK].enabled) { - if (op_ret >= 0) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, {l_type=%d, l_whence=%d, " - "l_start=%"PRId64", l_len=%"PRId64", l_pid=%u})", - frame->root->unique, op_ret, lock->l_type, lock->l_whence, - lock->l_start, lock->l_len, lock->l_pid); + char string[4096] = {0,}; + if (op_ret == 0) { + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "{l_type=%d, l_whence=%d, " + "l_start=%"PRId64", " + "l_len=%"PRId64", l_pid=%u})", + frame->root->unique, + uuid_utoa (frame->local), + op_ret, lock->l_type, lock->l_whence, + lock->l_start, lock->l_len, + lock->l_pid); } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, " + "op_errno=%d)", frame->root->unique, + uuid_utoa (frame->local), op_ret, + op_errno); } - } - STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, lock); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (lk, frame, op_ret, op_errno, lock, xdata); return 0; } - - int trace_entrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_ENTRYLK].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": op_ret=%d, op_errno=%d", - frame->root->unique, op_ret, op_errno); - } + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno); - STACK_UNWIND_STRICT (entrylk, frame, op_ret, op_errno); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (entrylk, frame, op_ret, op_errno, xdata); return 0; } +int +trace_fentrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FENTRYLK].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno); + + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (fentrylk, frame, op_ret, op_errno, xdata); + return 0; +} int trace_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_XATTROP].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno); - STACK_UNWIND_STRICT (xattrop, frame, op_ret, op_errno, dict); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (xattrop, frame, op_ret, op_errno, dict, xdata); return 0; } - int trace_fxattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_FXATTROP].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno); - STACK_UNWIND_STRICT (fxattrop, frame, op_ret, op_errno, dict); + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (fxattrop, frame, op_ret, op_errno, dict, xdata); return 0; } - int trace_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) + int32_t op_ret, int32_t op_errno, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_INODELK].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": op_ret=%d, op_errno=%d", - frame->root->unique, op_ret, op_errno); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local),op_ret, op_errno); + + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (inodelk, frame, op_ret, op_errno, xdata); + return 0; +} + +int +trace_finodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FINODELK].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d, op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno); + + LOG_ELEMENT (conf, string); + } +out: + TRACE_STACK_UNWIND (finodelk, frame, op_ret, op_errno, xdata); + return 0; +} + +int +trace_rchecksum_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + uint32_t weak_checksum, uint8_t *strong_checksum, + dict_t *xdata) +{ + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_RCHECKSUM].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s op_ret=%d op_errno=%d", + frame->root->unique, + uuid_utoa (frame->local), op_ret, op_errno); + + LOG_ELEMENT (conf, string); } - STACK_UNWIND_STRICT (inodelk, frame, op_ret, op_errno); +out: + TRACE_STACK_UNWIND (rchecksum, frame, op_ret, op_errno, weak_checksum, + strong_checksum, xdata); + return 0; } +/* *_cbk section over <----------> fop section start */ int trace_entrylk (call_frame_t *frame, xlator_t *this, const char *volume, loc_t *loc, const char *basename, - entrylk_cmd cmd, entrylk_type type) + entrylk_cmd cmd, entrylk_type type, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_ENTRYLK].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": volume=%s, (loc= {path=%s, ino=%"PRIu64"} basename=%s, cmd=%s, type=%s)", - frame->root->unique, volume, loc->path, loc->inode->ino, basename, - ((cmd == ENTRYLK_LOCK) ? "ENTRYLK_LOCK" : "ENTRYLK_UNLOCK"), - ((type == ENTRYLK_RDLCK) ? "ENTRYLK_RDLCK" : "ENTRYLK_WRLCK")); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s volume=%s, (path=%s " + "basename=%s, cmd=%s, type=%s)", + frame->root->unique, + uuid_utoa (loc->inode->gfid), + volume, loc->path, basename, + ((cmd == ENTRYLK_LOCK) ? "ENTRYLK_LOCK" : + "ENTRYLK_UNLOCK"), + ((type == ENTRYLK_RDLCK) ? "ENTRYLK_RDLCK" : + "ENTRYLK_WRLCK")); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_entrylk_cbk, FIRST_CHILD (this), FIRST_CHILD (this)->fops->entrylk, - volume, loc, basename, cmd, type); + volume, loc, basename, cmd, type, xdata); return 0; } - int trace_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, - loc_t *loc, int32_t cmd, struct gf_flock *flock) + loc_t *loc, int32_t cmd, struct gf_flock *flock, dict_t *xdata) { - char *cmd_str = NULL; - char *type_str = NULL; + char *cmd_str = NULL; + char *type_str = NULL; + trace_conf_t *conf = NULL; + + conf = this->private; + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_INODELK].enabled) { + char string[4096] = {0,}; switch (cmd) { #if F_GETLK != F_GETLK64 case F_GETLK64: @@ -1274,45 +1499,43 @@ trace_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, break; } - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": volume=%s, (loc {path=%s, ino=%"PRIu64"}, " - "cmd=%s, type=%s, start=%llu, len=%llu, pid=%llu)", - frame->root->unique, volume, loc->path, loc->inode->ino, - cmd_str, type_str, (unsigned long long) flock->l_start, - (unsigned long long) flock->l_len, - (unsigned long long) flock->l_pid); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s volume=%s, (path=%s " + "cmd=%s, type=%s, start=%llu, len=%llu, " + "pid=%llu)", frame->root->unique, + uuid_utoa (loc->inode->gfid), volume, + loc->path, cmd_str, type_str, + (unsigned long long)flock->l_start, + (unsigned long long) flock->l_len, + (unsigned long long) flock->l_pid); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_inodelk_cbk, FIRST_CHILD (this), FIRST_CHILD (this)->fops->inodelk, - volume, loc, cmd, flock); + volume, loc, cmd, flock, xdata); return 0; } - -int -trace_finodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - if (trace_fop_names[GF_FOP_FINODELK].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": op_ret=%d, op_errno=%d", - frame->root->unique, op_ret, op_errno); - } - - STACK_UNWIND_STRICT (finodelk, frame, op_ret, op_errno); - return 0; -} - - int trace_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, - fd_t *fd, int32_t cmd, struct gf_flock *flock) + fd_t *fd, int32_t cmd, struct gf_flock *flock, dict_t *xdata) { - char *cmd_str = NULL, *type_str = NULL; + char *cmd_str = NULL; + char *type_str = NULL; + trace_conf_t *conf = NULL; + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_FINODELK].enabled) { + char string[4096] = {0,}; switch (cmd) { #if F_GETLK != F_GETLK64 case F_GETLK64: @@ -1355,275 +1578,456 @@ trace_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, break; } - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": volume=%s, (fd =%p, ino=%"PRIu64"}, " - "cmd=%s, type=%s, start=%llu, len=%llu, pid=%llu)", - frame->root->unique, volume, fd, fd->inode->ino, - cmd_str, type_str, (unsigned long long) flock->l_start, - (unsigned long long) flock->l_len, - (unsigned long long) flock->l_pid); - } + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s volume=%s, (fd =%p " + "cmd=%s, type=%s, start=%llu, len=%llu, " + "pid=%llu)", frame->root->unique, + uuid_utoa (fd->inode->gfid), volume, fd, + cmd_str, type_str, + (unsigned long long) flock->l_start, + (unsigned long long) flock->l_len, + (unsigned long long) flock->l_pid); + + frame->local = fd->inode->gfid; + LOG_ELEMENT (conf, string); + } +out: STACK_WIND (frame, trace_finodelk_cbk, FIRST_CHILD (this), FIRST_CHILD (this)->fops->finodelk, - volume, fd, cmd, flock); + volume, fd, cmd, flock, xdata); return 0; } - int trace_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, - gf_xattrop_flags_t flags, dict_t *dict) + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_XATTROP].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (path=%s, ino=%"PRIu64" flags=%d)", - frame->root->unique, loc->path, loc->inode->ino, flags); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s (path=%s flags=%d)", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + flags); + + frame->local = loc->inode->gfid; + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_xattrop_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->xattrop, - loc, flags, dict); + loc, flags, dict, xdata); return 0; } - int trace_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, - gf_xattrop_flags_t flags, dict_t *dict) + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_FXATTROP].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (fd=%p, flags=%d)", - frame->root->unique, fd, flags); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p, flags=%d", + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd, flags); + + frame->local = fd->inode->gfid; + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_fxattrop_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fxattrop, - fd, flags, dict); + fd, flags, dict, xdata); return 0; } - int trace_lookup (call_frame_t *frame, xlator_t *this, - loc_t *loc, dict_t *xattr_req) + loc_t *loc, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_LOOKUP].enabled) { + char string[4096] = {0,}; /* TODO: print all the keys mentioned in xattr_req */ - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"})", - frame->root->unique, loc->path, - loc->inode->ino); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_lookup_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->lookup, - loc, xattr_req); + loc, xdata); return 0; } - int -trace_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) +trace_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_STAT].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"})", - frame->root->unique, loc->path, loc->inode->ino); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_stat_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->stat, - loc); + loc, xdata); return 0; } - int -trace_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size) +trace_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_READLINK].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, size=%"GF_PRI_SIZET")", - frame->root->unique, loc->path, loc->inode->ino, size); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s, " + "size=%"GF_PRI_SIZET")", frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + size); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_readlink_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readlink, - loc, size); + loc, size, xdata); return 0; } - int trace_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, - mode_t mode, dev_t dev, dict_t *params) + mode_t mode, dev_t dev, mode_t umask, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_MKNOD].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, mode=%d, dev=%"GF_PRI_DEV")", - frame->root->unique, loc->path, loc->inode->ino, mode, dev); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s mode=%d " + "umask=0%o, dev=%"GF_PRI_DEV")", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + mode, umask, dev); + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_mknod_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mknod, - loc, mode, dev, params); + loc, mode, dev, umask, xdata); return 0; } - int trace_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - dict_t *params) + mode_t umask, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_MKDIR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (path=%s, ino=%"PRIu64", mode=%d)", - frame->root->unique, loc->path, - ((loc->inode)? loc->inode->ino : 0), mode); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s mode=%d" + " umask=0%o", frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + mode, umask); + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_mkdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mkdir, - loc, mode, params); + loc, mode, umask, xdata); return 0; } - int -trace_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) +trace_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_UNLINK].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"})", - frame->root->unique, loc->path, loc->inode->ino); - } + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s flag=%d", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + xflag); + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); + } +out: STACK_WIND (frame, trace_unlink_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->unlink, - loc); + loc, xflag, xdata); return 0; } - int -trace_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags) +trace_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_RMDIR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, flags=%d)", - frame->root->unique, loc->path, loc->inode->ino, flags); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s flags=%d", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + flags); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_rmdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->rmdir, - loc, flags); + loc, flags, xdata); return 0; } - int trace_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath, - loc_t *loc, dict_t *params) + loc_t *loc, mode_t umask, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_SYMLINK].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (linkpath=%s, loc {path=%s, ino=%"PRIu64"})", - frame->root->unique, linkpath, loc->path, - ((loc->inode)? loc->inode->ino : 0)); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s linkpath=%s, path=%s" + " umask=0%o", frame->root->unique, + uuid_utoa (loc->inode->gfid), linkpath, + loc->path, umask); + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_symlink_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->symlink, - linkpath, loc, params); + linkpath, loc, umask, xdata); return 0; } - int -trace_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc) +trace_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) { + char oldgfid[50] = {0,}; + char newgfid[50] = {0,}; + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_RENAME].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (oldloc {path=%s, ino=%"PRIu64"}, " - "newloc{path=%s, ino=%"PRIu64"})", - frame->root->unique, oldloc->path, oldloc->ino, - newloc->path, newloc->ino); + char string[4096] = {0,}; + if (newloc->inode) + uuid_utoa_r (newloc->inode->gfid, newgfid); + else + strcpy (newgfid, "0"); + + uuid_utoa_r (oldloc->inode->gfid, oldgfid); + + snprintf (string, sizeof (string), + "%"PRId64": oldgfid=%s oldpath=%s --> " + "newgfid=%s newpath=%s", + frame->root->unique, oldgfid, + oldloc->path, newgfid, newloc->path); + + frame->local = oldloc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_rename_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->rename, - oldloc, newloc); + oldloc, newloc, xdata); return 0; } - int -trace_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc) +trace_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) { + char oldgfid[50] = {0,}; + char newgfid[50] = {0,}; + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_LINK].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (oldloc {path=%s, ino=%"PRIu64"}, " - "newloc {path=%s, ino=%"PRIu64"})", - frame->root->unique, oldloc->path, oldloc->inode->ino, - newloc->path, newloc->inode->ino); + char string[4096] = {0,}; + if (newloc->inode) + uuid_utoa_r (newloc->inode->gfid, newgfid); + else + strcpy (newgfid, "0"); + + uuid_utoa_r (oldloc->inode->gfid, oldgfid); + + snprintf (string, sizeof (string), + "%"PRId64": oldgfid=%s oldpath=%s --> " + "newgfid=%s newpath=%s", frame->root->unique, + oldgfid, oldloc->path, newgfid, + newloc->path); + + frame->local = oldloc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_link_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->link, - oldloc, newloc); + oldloc, newloc, xdata); return 0; } - int trace_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct iatt *stbuf, int32_t valid) + struct iatt *stbuf, int32_t valid, dict_t *xdata) { - uint64_t ia_time = 0; - char actime_str[256] = {0,}; - char modtime_str[256] = {0,}; + uint64_t ia_time = 0; + char actime_str[256] = {0,}; + char modtime_str[256] = {0,}; + trace_conf_t *conf = NULL; + + conf = this->private; + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_SETATTR].enabled) { + char string[4096] = {0,}; if (valid & GF_SET_ATTR_MODE) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}," - " mode=%o)", frame->root->unique, loc->path, - loc->inode->ino, - st_mode_from_ia (stbuf->ia_prot, stbuf->ia_type)); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s mode=%o)", + frame->root->unique, + uuid_utoa (loc->inode->gfid), + loc->path, + st_mode_from_ia (stbuf->ia_prot, + stbuf->ia_type)); + + LOG_ELEMENT (conf, string); + memset (string, 0 , sizeof (string)); } if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}," - " uid=%o, gid=%o)", - frame->root->unique, loc->path, loc->inode->ino, - stbuf->ia_uid, stbuf->ia_gid); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s uid=%o," + " gid=%o", frame->root->unique, + uuid_utoa (loc->inode->gfid), + loc->path, stbuf->ia_uid, + stbuf->ia_gid); + + LOG_ELEMENT (conf, string); + memset (string, 0 , sizeof (string)); } if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { @@ -1635,44 +2039,64 @@ trace_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, strftime (modtime_str, 256, "[%b %d %H:%M:%S]", localtime ((time_t *)&ia_time)); - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, " - "*stbuf=%p {ia_atime=%s, ia_mtime=%s})", - frame->root->unique, loc->path, loc->inode->ino, - stbuf, actime_str, modtime_str); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s " + "ia_atime=%s, ia_mtime=%s", + frame->root->unique, + uuid_utoa (loc->inode->gfid), + loc->path, actime_str, modtime_str); + + LOG_ELEMENT (conf, string); + memset (string, 0 , sizeof (string)); } + frame->local = loc->inode->gfid; } +out: STACK_WIND (frame, trace_setattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->setattr, - loc, stbuf, valid); + loc, stbuf, valid, xdata); return 0; } - int trace_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iatt *stbuf, int32_t valid) + struct iatt *stbuf, int32_t valid, dict_t *xdata) { - uint64_t ia_time = 0; - char actime_str[256] = {0,}; - char modtime_str[256] = {0,}; + uint64_t ia_time = 0; + char actime_str[256] = {0,}; + char modtime_str[256] = {0,}; + trace_conf_t *conf = NULL; + + conf = this->private; + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_FSETATTR].enabled) { + char string[4096] = {0,}; if (valid & GF_SET_ATTR_MODE) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (*fd=%p, mode=%o)", - frame->root->unique, fd, - st_mode_from_ia (stbuf->ia_prot, stbuf->ia_type)); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p, mode=%o", + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd, + st_mode_from_ia (stbuf->ia_prot, + stbuf->ia_type)); + + LOG_ELEMENT (conf, string); + memset (string, 0, sizeof (string)); } if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (*fd=%p, uid=%o, gid=%o)", - frame->root->unique, fd, - stbuf->ia_uid, stbuf->ia_gid); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p, uid=%o, " + "gid=%o", frame->root->unique, + uuid_utoa (fd->inode->gfid), + fd, stbuf->ia_uid, stbuf->ia_gid); + + LOG_ELEMENT (conf, string); + memset (string, 0, sizeof (string)); } if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { @@ -1684,372 +2108,816 @@ trace_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, strftime (modtime_str, 256, "[%b %d %H:%M:%S]", localtime ((time_t *)&ia_time)); - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (*fd=%p" - "*stbuf=%p {ia_atime=%s, ia_mtime=%s})", - frame->root->unique, fd, stbuf, actime_str, - modtime_str); + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p " + "ia_atime=%s, ia_mtime=%s", + frame->root->unique, + uuid_utoa (fd->inode->gfid), + fd, actime_str, modtime_str); + + LOG_ELEMENT (conf, string); + memset (string, 0, sizeof (string)); } + frame->local = fd->inode->gfid; } +out: STACK_WIND (frame, trace_fsetattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsetattr, - fd, stbuf, valid); + fd, stbuf, valid, xdata); return 0; } - int trace_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, - off_t offset) + off_t offset, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_TRUNCATE].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, offset=%"PRId64")", - frame->root->unique, loc->path, loc->inode->ino, offset); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s, " + "offset=%"PRId64"", frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + offset); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_truncate_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->truncate, - loc, offset); + loc, offset, xdata); return 0; } - int trace_open (call_frame_t *frame, xlator_t *this, loc_t *loc, - int32_t flags, fd_t *fd, int32_t wbflags) + int32_t flags, fd_t *fd, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_OPEN].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, flags=%d, " - "fd=%p, wbflags=%d)", - frame->root->unique, loc->path, loc->inode->ino, flags, - fd, wbflags); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s flags=%d fd=%p", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + flags, fd); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_open_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->open, - loc, flags, fd, wbflags); + loc, flags, fd, xdata); return 0; } - int trace_create (call_frame_t *frame, xlator_t *this, loc_t *loc, - int32_t flags, mode_t mode, fd_t *fd, dict_t *params) + int32_t flags, mode_t mode, mode_t umask, fd_t *fd, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_CREATE].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, flags=0%o mode=0%o)", - frame->root->unique, loc->path, loc->inode->ino, flags, mode); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s, fd=%p, " + "flags=0%o mode=0%o umask=0%o", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + fd, flags, mode, umask); + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_create_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->create, - loc, flags, mode, fd, params); + loc, flags, mode, umask, fd, xdata); return 0; } - int trace_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, - size_t size, off_t offset) + size_t size, off_t offset, uint32_t flags, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_READ].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (*fd=%p, size=%"GF_PRI_SIZET", offset=%"PRId64")", - frame->root->unique, fd, size, offset); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p, size=%" + GF_PRI_SIZET"offset=%"PRId64" flags=0%x)", + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd, size, + offset, flags); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_readv_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readv, - fd, size, offset); + fd, size, offset, flags, xdata); return 0; } - int trace_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector, int32_t count, - off_t offset, struct iobref *iobref) + off_t offset, uint32_t flags, struct iobref *iobref, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_WRITE].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (*fd=%p, *vector=%p, count=%d, offset=%"PRId64")", - frame->root->unique, fd, vector, count, offset); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p, count=%d, " + " offset=%"PRId64" flags=0%x)", + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd, count, + offset, flags); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_writev_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->writev, - fd, vector, count, offset, iobref); + fd, vector, count, offset, flags, iobref, xdata); return 0; } - int -trace_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) +trace_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_STATFS].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"})", - frame->root->unique, loc->path, - ((loc->inode)? loc->inode->ino : 0)); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s", + frame->root->unique, (loc->inode)? + uuid_utoa (loc->inode->gfid):"0", loc->path); + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_statfs_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->statfs, - loc); + loc, xdata); return 0; } - int -trace_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) +trace_flush (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_FLUSH].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (*fd=%p)", - frame->root->unique, fd); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p", + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_flush_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->flush, - fd); + fd, xdata); return 0; } - int -trace_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) +trace_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_FSYNC].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (flags=%d, *fd=%p)", - frame->root->unique, flags, fd); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s flags=%d fd=%p", + frame->root->unique, + uuid_utoa (fd->inode->gfid), flags, fd); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_fsync_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsync, - fd, flags); + fd, flags, xdata); return 0; } - int trace_setxattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, dict_t *dict, int32_t flags) + loc_t *loc, dict_t *dict, int32_t flags, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_SETXATTR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, dict=%p, flags=%d)", - frame->root->unique, loc->path, - ((loc->inode)? loc->inode->ino : 0), dict, flags); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s flags=%d", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + flags); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_setxattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->setxattr, - loc, dict, flags); + loc, dict, flags, xdata); return 0; } - int trace_getxattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, const char *name) + loc_t *loc, const char *name, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_GETXATTR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}), name=%s", - frame->root->unique, loc->path, - ((loc->inode)? loc->inode->ino : 0), name); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s name=%s", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + name); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_getxattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->getxattr, - loc, name); + loc, name, xdata); return 0; } - int trace_removexattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, const char *name) + loc_t *loc, const char *name, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_REMOVEXATTR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, name=%s)", - frame->root->unique, loc->path, - ((loc->inode)? loc->inode->ino : 0), name); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s name=%s", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, + name); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_removexattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->removexattr, - loc, name); + loc, name, xdata); return 0; } - int -trace_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd) +trace_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_OPENDIR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64":( loc {path=%s, ino=%"PRIu64"}, fd=%p)", - frame->root->unique, loc->path, loc->inode->ino, fd); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s fd=%p", + frame->root->unique, + uuid_utoa (loc->inode->gfid), loc->path, fd); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_opendir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->opendir, - loc, fd); + loc, fd, xdata); return 0; } int trace_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t offset) + off_t offset, dict_t *dict) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_READDIRP].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (fd=%p, size=%"GF_PRI_SIZET", offset=%"PRId64")", - frame->root->unique, fd, size, offset); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p, size=%"GF_PRI_SIZET + ", offset=%"PRId64" dict=%p", + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd, size, + offset, dict); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_readdirp_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readdirp, - fd, size, offset); + fd, size, offset, dict); return 0; } - int trace_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, - size_t size, off_t offset) + size_t size, off_t offset, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_READDIR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (fd=%p, size=%"GF_PRI_SIZET", offset=%"PRId64")", - frame->root->unique, fd, size, offset); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p, size=%"GF_PRI_SIZET + ", offset=%"PRId64, + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd, size, + offset); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_readdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readdir, - fd, size, offset); + fd, size, offset, xdata); return 0; } - int trace_fsyncdir (call_frame_t *frame, xlator_t *this, - fd_t *fd, int32_t datasync) + fd_t *fd, int32_t datasync, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_FSYNCDIR].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (datasync=%d, *fd=%p)", - frame->root->unique, datasync, fd); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s datasync=%d fd=%p", + frame->root->unique, + uuid_utoa (fd->inode->gfid), datasync, fd); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_fsyncdir_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsyncdir, - fd, datasync); + fd, datasync, xdata); return 0; } - int -trace_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask) +trace_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask, + dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_ACCESS].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (*loc {path=%s, ino=%"PRIu64"}, mask=0%o)", - frame->root->unique, loc->path, - ((loc->inode)? loc->inode->ino : 0), mask); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s path=%s mask=0%o", + frame->root->unique, + uuid_utoa (loc->inode->gfid), + loc->path, mask); + + frame->local = loc->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_access_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->access, - loc, mask); + loc, mask, xdata); return 0; } +int32_t +trace_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + int32_t len, dict_t *xdata) +{ + + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_RCHECKSUM].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s offset=%"PRId64 + "len=%u fd=%p", frame->root->unique, + uuid_utoa (fd->inode->gfid), offset, len, fd); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); + } + +out: + STACK_WIND (frame, trace_rchecksum_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->rchecksum, + fd, offset, len, xdata); + + return 0; + +} + +int32_t +trace_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume, + fd_t *fd, const char *basename, entrylk_cmd cmd, + entrylk_type type, dict_t *xdata) +{ + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FENTRYLK].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s volume=%s, (fd=%p " + "basename=%s, cmd=%s, type=%s)", + frame->root->unique, + uuid_utoa (fd->inode->gfid), volume, fd, + basename, + ((cmd == ENTRYLK_LOCK) ? "ENTRYLK_LOCK" : + "ENTRYLK_UNLOCK"), + ((type == ENTRYLK_RDLCK) ? "ENTRYLK_RDLCK" : + "ENTRYLK_WRLCK")); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); + } + +out: + STACK_WIND (frame, trace_fentrylk_cbk, + FIRST_CHILD (this), + FIRST_CHILD (this)->fops->fentrylk, + volume, fd, basename, cmd, type, xdata); + return 0; + +} + +int32_t +trace_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) +{ + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FGETXATTR].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p name=%s", + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd, name); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); + } + +out: + STACK_WIND (frame, trace_fgetxattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fgetxattr, + fd, name, xdata); + return 0; +} + +int32_t +trace_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + dict_t *dict, int32_t flags, dict_t *xdata) +{ + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_FSETXATTR].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p flags=%d", + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd, flags); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); + } + +out: + STACK_WIND (frame, trace_fsetxattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fsetxattr, + fd, dict, flags, xdata); + return 0; +} int trace_ftruncate (call_frame_t *frame, xlator_t *this, - fd_t *fd, off_t offset) + fd_t *fd, off_t offset, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_FTRUNCATE].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (offset=%"PRId64", *fd=%p)", - frame->root->unique, offset, fd); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s offset=%"PRId64" fd=%p", + frame->root->unique, + uuid_utoa (fd->inode->gfid), offset, fd); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_ftruncate_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->ftruncate, - fd, offset); + fd, offset, xdata); return 0; } - int -trace_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) +trace_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_FSTAT].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (*fd=%p)", - frame->root->unique, fd); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p", + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_fstat_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fstat, - fd); + fd, xdata); return 0; } - int trace_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, - int32_t cmd, struct gf_flock *lock) + int32_t cmd, struct gf_flock *lock, dict_t *xdata) { + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; if (trace_fop_names[GF_FOP_LK].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (*fd=%p, cmd=%d, lock {l_type=%d, l_whence=%d, " - "l_start=%"PRId64", l_len=%"PRId64", l_pid=%u})", - frame->root->unique, fd, cmd, lock->l_type, lock->l_whence, - lock->l_start, lock->l_len, lock->l_pid); + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "%"PRId64": gfid=%s fd=%p, cmd=%d, " + "lock {l_type=%d, " + "l_whence=%d, l_start=%"PRId64", " + "l_len=%"PRId64", l_pid=%u})", + frame->root->unique, + uuid_utoa (fd->inode->gfid), fd, cmd, + lock->l_type, lock->l_whence, + lock->l_start, lock->l_len, lock->l_pid); + + frame->local = fd->inode->gfid; + + LOG_ELEMENT (conf, string); } +out: STACK_WIND (frame, trace_lk_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->lk, - fd, cmd, lock); + fd, cmd, lock, xdata); + return 0; +} + +int32_t +trace_forget (xlator_t *this, inode_t *inode) +{ + trace_conf_t *conf = NULL; + + conf = this->private; + /* If user want to understand when a lookup happens, + he should know about 'forget' too */ + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_LOOKUP].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "gfid=%s", uuid_utoa (inode->gfid)); + + LOG_ELEMENT (conf, string); + } + +out: + return 0; +} + +int32_t +trace_releasedir (xlator_t *this, fd_t *fd) +{ + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_OPENDIR].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "gfid=%s fd=%p", + uuid_utoa (fd->inode->gfid), fd); + + LOG_ELEMENT (conf, string); + } + +out: return 0; } +int32_t +trace_release (xlator_t *this, fd_t *fd) +{ + trace_conf_t *conf = NULL; + + conf = this->private; + + if (!conf->log_file && !conf->log_history) + goto out; + if (trace_fop_names[GF_FOP_OPEN].enabled || + trace_fop_names[GF_FOP_CREATE].enabled) { + char string[4096] = {0,}; + snprintf (string, sizeof (string), + "gfid=%s fd=%p", + uuid_utoa (fd->inode->gfid), fd); + + LOG_ELEMENT (conf, string); + } + +out: + return 0; +} void @@ -2061,7 +2929,6 @@ enable_all_calls (int enabled) trace_fop_names[i].enabled = enabled; } - void enable_call (const char *name, int enabled) { @@ -2089,6 +2956,105 @@ process_call_list (const char *list, int include) } } +int32_t +trace_dump_history (xlator_t *this) +{ + int ret = -1; + char key_prefix[GF_DUMP_MAX_BUF_LEN] = {0,}; + trace_conf_t *conf = NULL; + + GF_VALIDATE_OR_GOTO ("trace", this, out); + GF_VALIDATE_OR_GOTO (this->name, this->history, out); + + conf = this->private; + // Is it ok to return silently if log-history option his off? + if (conf && conf->log_history == _gf_true) { + gf_proc_dump_build_key (key_prefix, "xlator.debug.trace", + "history"); + gf_proc_dump_add_section (key_prefix); + eh_dump (this->history, NULL, dump_history_trace); + } + ret = 0; + +out: + return ret; +} + +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_trace_mt_end + 1); + + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" + " failed"); + return ret; + } + + return ret; +} + +int +reconfigure (xlator_t *this, dict_t *options) +{ + int32_t ret = -1; + trace_conf_t *conf = NULL; + char *includes = NULL, *excludes = NULL; + + GF_VALIDATE_OR_GOTO ("quick-read", this, out); + GF_VALIDATE_OR_GOTO (this->name, this->private, out); + GF_VALIDATE_OR_GOTO (this->name, options, out); + + conf = this->private; + + includes = data_to_str (dict_get (options, "include-ops")); + excludes = data_to_str (dict_get (options, "exclude-ops")); + + { + int i; + for (i = 0; i < GF_FOP_MAXVALUE; i++) { + if (gf_fop_list[i]) + strncpy (trace_fop_names[i].name, + gf_fop_list[i], + strlen (gf_fop_list[i])); + else + strncpy (trace_fop_names[i].name, ":O", + strlen (":O")); + trace_fop_names[i].enabled = 1; + } + } + + if (includes && excludes) { + gf_log (this->name, + GF_LOG_ERROR, + "must specify only one of 'include-ops' and " + "'exclude-ops'"); + goto out; + } + + if (includes) + process_call_list (includes, 1); + if (excludes) + process_call_list (excludes, 0); + + /* Should resizing of the event-history be allowed in reconfigure? + * for which a new event_history might have to be allocated and the + * older history has to be freed. + */ + GF_OPTION_RECONF ("log-file", conf->log_file, options, bool, out); + + GF_OPTION_RECONF ("log-history", conf->log_history, options, bool, out); + + ret = 0; + +out: + return ret; +} int32_t init (xlator_t *this) @@ -2096,6 +3062,10 @@ init (xlator_t *this) dict_t *options = NULL; char *includes = NULL, *excludes = NULL; char *forced_loglevel = NULL; + eh_t *history = NULL; + int ret = -1; + size_t history_size = TRACE_DEFAULT_HISTORY_SIZE; + trace_conf_t *conf = NULL; if (!this) return -1; @@ -2110,6 +3080,12 @@ init (xlator_t *this) "dangling volume. check volfile "); } + conf = GF_CALLOC (1, sizeof (trace_conf_t), gf_trace_mt_trace_conf_t); + if (!conf) { + gf_log (this->name, GF_LOG_ERROR, "cannot allocate " + "xl->private"); + return -1; + } options = this->options; includes = data_to_str (dict_get (options, "include-ops")); @@ -2118,8 +3094,13 @@ init (xlator_t *this) { int i; for (i = 0; i < GF_FOP_MAXVALUE; i++) { - trace_fop_names[i].name = (gf_fop_list[i] ? - gf_fop_list[i] : ":O"); + if (gf_fop_list[i]) + strncpy (trace_fop_names[i].name, + gf_fop_list[i], + strlen (gf_fop_list[i])); + else + strncpy (trace_fop_names[i].name, ":O", + strlen (":O")); trace_fop_names[i].enabled = 1; } } @@ -2127,40 +3108,78 @@ init (xlator_t *this) if (includes && excludes) { gf_log (this->name, GF_LOG_ERROR, - "must specify only one of 'include-ops' and 'exclude-ops'"); + "must specify only one of 'include-ops' and " + "'exclude-ops'"); return -1; } + if (includes) process_call_list (includes, 1); if (excludes) process_call_list (excludes, 0); + + GF_OPTION_INIT ("history-size", conf->history_size, size, out); + + gf_log (this->name, GF_LOG_INFO, "history size %"GF_PRI_SIZET, + history_size); + + GF_OPTION_INIT ("log-file", conf->log_file, bool, out); + + gf_log (this->name, GF_LOG_INFO, "logging to file %s", + (conf->log_file == _gf_true)?"enabled":"disabled"); + + GF_OPTION_INIT ("log-history", conf->log_history, bool, out); + + gf_log (this->name, GF_LOG_DEBUG, "logging to history %s", + (conf->log_history == _gf_true)?"enabled":"disabled"); + + history = eh_new (history_size, _gf_false, NULL); + if (!history) { + gf_log (this->name, GF_LOG_ERROR, "event history cannot be " + "initialized"); + return -1; + } + + this->history = history; + + conf->trace_log_level = GF_LOG_INFO; + if (dict_get (options, "force-log-level")) { forced_loglevel = data_to_str (dict_get (options, - "force-log-level")); + "force-log-level")); if (!forced_loglevel) goto setloglevel; - if (strcmp (forced_loglevel, "NORMAL") == 0) - trace_log_level = GF_LOG_NORMAL; + if (strcmp (forced_loglevel, "INFO") == 0) + conf->trace_log_level = GF_LOG_INFO; else if (strcmp (forced_loglevel, "TRACE") == 0) - trace_log_level = GF_LOG_TRACE; + conf->trace_log_level = GF_LOG_TRACE; else if (strcmp (forced_loglevel, "ERROR") == 0) - trace_log_level = GF_LOG_ERROR; + conf->trace_log_level = GF_LOG_ERROR; else if (strcmp (forced_loglevel, "DEBUG") == 0) - trace_log_level = GF_LOG_DEBUG; + conf->trace_log_level = GF_LOG_DEBUG; else if (strcmp (forced_loglevel, "WARNING") == 0) - trace_log_level = GF_LOG_WARNING; + conf->trace_log_level = GF_LOG_WARNING; else if (strcmp (forced_loglevel, "CRITICAL") == 0) - trace_log_level = GF_LOG_CRITICAL; + conf->trace_log_level = GF_LOG_CRITICAL; else if (strcmp (forced_loglevel, "NONE") == 0) - trace_log_level = GF_LOG_NONE; + conf->trace_log_level = GF_LOG_NONE; } setloglevel: - gf_log_set_loglevel (trace_log_level); + gf_log_set_loglevel (conf->trace_log_level); + this->private = conf; + ret = 0; +out: + if (ret == -1) { + if (history) + GF_FREE (history); + if (conf) + GF_FREE (conf); + } - return 0; + return ret; } void @@ -2169,7 +3188,10 @@ fini (xlator_t *this) if (!this) return; - gf_log (this->name, GF_LOG_NORMAL, + if (this->history) + eh_destroy (this->history); + + gf_log (this->name, GF_LOG_INFO, "trace translator unloaded"); return; } @@ -2193,6 +3215,8 @@ struct xlator_fops fops = { .fsync = trace_fsync, .setxattr = trace_setxattr, .getxattr = trace_getxattr, + .fsetxattr = trace_fsetxattr, + .fgetxattr = trace_fgetxattr, .removexattr = trace_removexattr, .opendir = trace_opendir, .readdir = trace_readdir, @@ -2206,15 +3230,19 @@ struct xlator_fops fops = { .inodelk = trace_inodelk, .finodelk = trace_finodelk, .entrylk = trace_entrylk, + .fentrylk = trace_fentrylk, .lookup = trace_lookup, + .rchecksum = trace_rchecksum, .xattrop = trace_xattrop, .fxattrop = trace_fxattrop, .setattr = trace_setattr, .fsetattr = trace_fsetattr, }; - struct xlator_cbks cbks = { + .release = trace_release, + .releasedir = trace_releasedir, + .forget = trace_forget, }; struct volume_options options[] = { @@ -2226,5 +3254,21 @@ struct volume_options options[] = { .type = GF_OPTION_TYPE_STR /*.value = { ""} */ }, + { .key = {"history-size"}, + .type = GF_OPTION_TYPE_SIZET, + .default_value = "1024", + }, + { .key = {"log-file"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "no", + }, + { .key = {"log-history"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "no", + }, { .key = {NULL} }, }; + +struct xlator_dumpops dumpops = { + .history = trace_dump_history +}; diff --git a/xlators/debug/trace/src/trace.h b/xlators/debug/trace/src/trace.h new file mode 100644 index 000000000..045eefb36 --- /dev/null +++ b/xlators/debug/trace/src/trace.h @@ -0,0 +1,98 @@ +/* + Copyright (c) 2006-2012 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 _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include <time.h> +#include <errno.h> +#include "glusterfs.h" +#include "xlator.h" +#include "common-utils.h" +#include "event-history.h" +#include "logging.h" +#include "circ-buff.h" +#include "statedump.h" +#include "options.h" + +#define TRACE_DEFAULT_HISTORY_SIZE 1024 + +typedef struct { + /* Since the longest fop name is fremovexattr i.e 12 characters, array size + * is kept 24, i.e double of the maximum. + */ + char name[24]; + int enabled; +} trace_fop_name_t; + +trace_fop_name_t trace_fop_names[GF_FOP_MAXVALUE]; + +typedef struct { + gf_boolean_t log_file; + gf_boolean_t log_history; + size_t history_size; + int trace_log_level; +} trace_conf_t; + +#define TRACE_STACK_UNWIND(op, frame, params ...) \ + do { \ + frame->local = NULL; \ + STACK_UNWIND_STRICT (op, frame, params); \ + } while (0); + +#define LOG_ELEMENT(_conf, _string) \ + do { \ + if (_conf) { \ + if ((_conf->log_history) == _gf_true) \ + gf_log_eh ("%s", _string); \ + if ((_conf->log_file) == _gf_true) \ + gf_log (THIS->name, _conf->trace_log_level, \ + "%s", _string); \ + } \ + } while (0); + +#define trace_stat_to_str(buf, statstr) \ + do { \ + char atime_buf[256] = {0,}; \ + char mtime_buf[256] = {0,}; \ + char ctime_buf[256] = {0,}; \ + uint64_t ia_time = 0; \ + \ + if (!buf) \ + break; \ + \ + ia_time = buf->ia_atime; \ + strftime (atime_buf, 256, "[%b %d %H:%M:%S]", \ + localtime ((time_t *)&ia_time)); \ + \ + ia_time = buf->ia_mtime; \ + strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", \ + localtime ((time_t *)&ia_time)); \ + \ + ia_time = buf->ia_ctime; \ + strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", \ + localtime ((time_t *)&ia_time)); \ + \ + snprintf (statstr, sizeof (statstr), \ + "gfid=%s ino=%"PRIu64", mode=%o, " \ + "nlink=%"GF_PRI_NLINK", uid=%u, " \ + "gid=%u, size=%"PRIu64", " \ + "blocks=%"PRIu64", atime=%s, " \ + "mtime=%s, ctime=%s", \ + uuid_utoa (buf->ia_gfid), buf->ia_ino, \ + st_mode_from_ia (buf->ia_prot, \ + buf->ia_type), \ + buf->ia_nlink, buf->ia_uid, \ + buf->ia_gid, buf->ia_size, \ + buf->ia_blocks, atime_buf, \ + mtime_buf, ctime_buf); \ + } while (0); |
