summaryrefslogtreecommitdiffstats
path: root/api/src/glfs.c
diff options
context:
space:
mode:
authorNiels de Vos <ndevos@redhat.com>2017-01-06 12:49:32 +0100
committerShyamsundar Ranganathan <srangana@redhat.com>2017-01-19 10:44:22 -0800
commitd93a6691538270aefe7703e8f8d7c822f53528e5 (patch)
treeb07a719b7e9cc2ca8cb5e3fb054d8e9d8fea3cdb /api/src/glfs.c
parent89cf743118ab6554c7f210754e51c4921cbb60c7 (diff)
gfapi: add API to trigger events for debugging and troubleshooting
Introduce glfs_sysrq() as a generic API for triggering debug and troubleshoot events. This interface will be used by the feature to get statedumps for applications using libgfapi. The current events that can be requested through this API are: - 'h'elp: log a mesage with all supported events - 's'tatedump: trigger a statedump for the passed glfs_t In future, this API can be used by a CLI to trigger statedumps from storage servers. At the moment it is limited to take statedumps, but it is extensible to set the log-level, clear caches, force reconnects and much more. BUG: 1169302 Change-Id: I18858359a3957870cea5139c79efe1365a15a992 Original-author: Poornima G <pgurusid@redhat.com> Signed-off-by: Niels de Vos <ndevos@redhat.com> Reviewed-on: http://review.gluster.org/16414 Reviewed-by: Prashanth Pai <ppai@redhat.com> Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'api/src/glfs.c')
-rw-r--r--api/src/glfs.c64
1 files changed, 61 insertions, 3 deletions
diff --git a/api/src/glfs.c b/api/src/glfs.c
index 4375774a853..94a12c0be31 100644
--- a/api/src/glfs.c
+++ b/api/src/glfs.c
@@ -40,12 +40,13 @@
#include "common-utils.h"
#include "syncop.h"
#include "call-stub.h"
-#include "gfapi-messages.h"
+#include "hashfn.h"
+#include "rpc-clnt.h"
+#include "statedump.h"
+#include "gfapi-messages.h"
#include "glfs.h"
#include "glfs-internal.h"
-#include "hashfn.h"
-#include "rpc-clnt.h"
static gf_boolean_t
@@ -1462,3 +1463,60 @@ pub_glfs_upcall_inode_get_oldpstat (struct glfs_upcall_inode *arg)
return &arg->oldp_buf;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_oldpstat, 3.7.16);
+
+
+/* definitions of the GLFS_SYSRQ_* chars are in glfs.h */
+static struct glfs_sysrq_help {
+ char sysrq;
+ char *msg;
+} glfs_sysrq_help[] = {
+ { GLFS_SYSRQ_HELP, "(H)elp" },
+ { GLFS_SYSRQ_STATEDUMP, "(S)tatedump" },
+ { 0, NULL }
+};
+
+int
+pub_glfs_sysrq (struct glfs *fs, char sysrq)
+{
+ glusterfs_ctx_t *ctx = NULL;
+ int ret = 0;
+
+ if (!fs || !fs->ctx) {
+ ret = -1;
+ errno = EINVAL;
+ goto out;
+ }
+
+ ctx = fs->ctx;
+
+ switch (sysrq) {
+ case GLFS_SYSRQ_HELP:
+ {
+ char msg[1024]; /* help text should not exceed 1024 chars */
+ struct glfs_sysrq_help *usage;
+
+ msg[0] = '\0';
+ for (usage = glfs_sysrq_help; usage->sysrq; usage++) {
+ strncat (msg, usage->msg, 1024);
+ strncat (msg, " ", 1024);
+ }
+
+ /* not really an 'error', but make sure it gets logged */
+ gf_log ("glfs", GF_LOG_ERROR, "available events: %s", msg);
+
+ break;
+ }
+ case GLFS_SYSRQ_STATEDUMP:
+ gf_proc_dump_info (SIGUSR1, ctx);
+ break;
+ default:
+ gf_msg ("glfs", GF_LOG_ERROR, ENOTSUP, API_MSG_INVALID_ENTRY,
+ "'%c' is not a valid sysrq", sysrq);
+ errno = ENOTSUP;
+ ret = -1;
+ }
+out:
+ return ret;
+}
+
+GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_sysrq, 3.10.0);