diff options
Diffstat (limited to 'api')
| -rw-r--r-- | api/src/gfapi-messages.h | 3 | ||||
| -rw-r--r-- | api/src/gfapi.aliases | 1 | ||||
| -rw-r--r-- | api/src/gfapi.map | 4 | ||||
| -rw-r--r-- | api/src/glfs.c | 64 | ||||
| -rw-r--r-- | api/src/glfs.h | 17 | 
5 files changed, 85 insertions, 4 deletions
diff --git a/api/src/gfapi-messages.h b/api/src/gfapi-messages.h index 5deef15e3ae..6e131b5a295 100644 --- a/api/src/gfapi-messages.h +++ b/api/src/gfapi-messages.h @@ -40,7 +40,7 @@   */  #define GLFS_GFAPI_BASE             GLFS_MSGID_COMP_API -#define GLFS_NUM_MESSAGES           48 +#define GLFS_NUM_MESSAGES           49  #define GLFS_MSGID_END              (GLFS_GFAPI_BASE + GLFS_NUM_MESSAGES + 1)  /* Messages with message IDs */  #define glfs_msg_start_x GLFS_GFAPI_BASE, "Invalid: Start of messages" @@ -94,6 +94,7 @@  #define API_MSG_ALLOC_FAILED                    (GLFS_GFAPI_BASE + 46)  #define API_MSG_CREATE_HANDLE_FAILED            (GLFS_GFAPI_BASE + 47)  #define API_MSG_INODE_LINK_FAILED               (GLFS_GFAPI_BASE + 48) +#define API_MSG_STATEDUMP_FAILED                (GLFS_GFAPI_BASE + 49)  /*------------*/  #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages" diff --git a/api/src/gfapi.aliases b/api/src/gfapi.aliases index 83bfd1b6f85..d1bf2b22faa 100644 --- a/api/src/gfapi.aliases +++ b/api/src/gfapi.aliases @@ -156,3 +156,4 @@ _pub_glfs_upcall_inode_get_oldpobject _glfs_upcall_inode_get_oldpobject$GFAPI_3.  _pub_glfs_upcall_inode_get_oldpstat _glfs_upcall_inode_get_oldpstat$GFAPI_3.7.16  _pub_glfs_realpath _glfs_realpath$GFAPI_3.7.17 +_pub_glfs_sysrq _glfs_sysrq$GFAPI_3.10.0 diff --git a/api/src/gfapi.map b/api/src/gfapi.map index 0567add0d73..48a6d90e922 100644 --- a/api/src/gfapi.map +++ b/api/src/gfapi.map @@ -194,3 +194,7 @@ GFAPI_3.7.17 {  		glfs_realpath;  } GFAPI_3.7.16; +GFAPI_3.10.0 { +	global: +		glfs_sysrq; +} GFAPI_3.7.17; diff --git a/api/src/glfs.c b/api/src/glfs.c index 4559707c4e1..4aa9711c29f 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 @@ -1453,3 +1454,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); diff --git a/api/src/glfs.h b/api/src/glfs.h index 730cff51f5a..397bb878434 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -773,6 +773,23 @@ void glfs_free (void *ptr) __THROW          GFAPI_PUBLIC(glfs_free, 3.7.16);  /* + * glfs_sysrq: send a system request to the @fs instance + * + * Different commands for @sysrq are possible, the defines for these are listed + * below the function definition. + * + * This function always returns success if the @sysrq is recognized. The return + * value does not way anythin about the result of the @sysrq execution. Not all + * @sysrq command will be able to return a success/failure status. + */ +int glfs_sysrq (glfs_t *fs, char sysrq) __THROW +        GFAPI_PUBLIC(glfs_sysrq, 3.10.0); + +#define GLFS_SYSRQ_HELP 'h' /* log a message with supported sysrq commands */ +#define GLFS_SYSRQ_STATEDUMP 's' /* create a statedump */ + + +/*   * Nobody needs this call at all yet except for the test script.   */  int glfs_ipc (glfs_fd_t *fd, int cmd) __THROW  | 
