"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/mgmt/glusterd/src/glusterd-statedump.c" (16 Sep 2020, 8414 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "glusterd-statedump.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2    Copyright (c) 2014 Red Hat, Inc. <http://www.redhat.com>
    3    This file is part of GlusterFS.
    4 
    5    This file is licensed to you under your choice of the GNU Lesser
    6    General Public License, version 3 or any later version (LGPLv3 or
    7    later), or the GNU General Public License, version 2 (GPLv2), in all
    8    cases as published by the Free Software Foundation.
    9 */
   10 
   11 #include <glusterfs/statedump.h>
   12 #include "glusterd.h"
   13 #include "glusterd-shd-svc.h"
   14 #include "glusterd-quotad-svc.h"
   15 #include "glusterd-locks.h"
   16 #include "glusterd-messages.h"
   17 
   18 static void
   19 glusterd_dump_peer(glusterd_peerinfo_t *peerinfo, char *input_key, int index,
   20                    gf_boolean_t xpeers)
   21 {
   22     char subkey[GF_DUMP_MAX_BUF_LEN + 11] = "";
   23     char key[GF_DUMP_MAX_BUF_LEN] = "";
   24 
   25     strncpy(key, input_key, sizeof(key) - 1);
   26 
   27     snprintf(subkey, sizeof(subkey), "%s%d", key, index);
   28 
   29     gf_proc_dump_build_key(key, subkey, "uuid");
   30     gf_proc_dump_write(key, "%s", uuid_utoa(peerinfo->uuid));
   31 
   32     gf_proc_dump_build_key(key, subkey, "hostname");
   33     gf_proc_dump_write(key, "%s", peerinfo->hostname);
   34 
   35     gf_proc_dump_build_key(key, subkey, "port");
   36     gf_proc_dump_write(key, "%d", peerinfo->port);
   37 
   38     gf_proc_dump_build_key(key, subkey, "state");
   39     gf_proc_dump_write(key, "%d", peerinfo->state.state);
   40 
   41     gf_proc_dump_build_key(key, subkey, "quorum-action");
   42     gf_proc_dump_write(key, "%d", peerinfo->quorum_action);
   43 
   44     gf_proc_dump_build_key(key, subkey, "quorum-contrib");
   45     gf_proc_dump_write(key, "%d", peerinfo->quorum_contrib);
   46 
   47     gf_proc_dump_build_key(key, subkey, "detaching");
   48     gf_proc_dump_write(key, "%d", peerinfo->detaching);
   49 
   50     gf_proc_dump_build_key(key, subkey, "locked");
   51     gf_proc_dump_write(key, "%d", peerinfo->locked);
   52 }
   53 
   54 static void
   55 glusterd_dump_peer_rpcstat(glusterd_peerinfo_t *peerinfo, char *input_key,
   56                            int index)
   57 {
   58     rpc_clnt_connection_t *conn = NULL;
   59     int ret = -1;
   60     rpc_clnt_t *rpc = NULL;
   61     char rpcsvc_peername[RPCSVC_PEER_STRLEN] = "";
   62     char subkey[GF_DUMP_MAX_BUF_LEN + 11] = "";
   63     char key[GF_DUMP_MAX_BUF_LEN] = "";
   64 
   65     strncpy(key, input_key, sizeof(key) - 1);
   66 
   67     /* Dump the rpc connection statistics */
   68     rpc = peerinfo->rpc;
   69     if (rpc) {
   70         conn = &rpc->conn;
   71         snprintf(subkey, sizeof(subkey), "%s%d", key, index);
   72         ret = rpcsvc_transport_peername(conn->trans, (char *)&rpcsvc_peername,
   73                                         sizeof(rpcsvc_peername));
   74         if (!ret) {
   75             gf_proc_dump_build_key(key, subkey, "rpc.peername");
   76             gf_proc_dump_write(key, "%s", rpcsvc_peername);
   77         }
   78         gf_proc_dump_build_key(key, subkey, "rpc.connected");
   79         gf_proc_dump_write(key, "%d", conn->connected);
   80 
   81         gf_proc_dump_build_key(key, subkey, "rpc.total-bytes-read");
   82         gf_proc_dump_write(key, "%" PRIu64, conn->trans->total_bytes_read);
   83 
   84         gf_proc_dump_build_key(key, subkey, "rpc.total-bytes-written");
   85         gf_proc_dump_write(key, "%" PRIu64, conn->trans->total_bytes_write);
   86 
   87         gf_proc_dump_build_key(key, subkey, "rpc.ping_msgs_sent");
   88         gf_proc_dump_write(key, "%" PRIu64, conn->pingcnt);
   89 
   90         gf_proc_dump_build_key(key, subkey, "rpc.msgs_sent");
   91         gf_proc_dump_write(key, "%" PRIu64, conn->msgcnt);
   92     }
   93 }
   94 
   95 static void
   96 glusterd_dump_client_details(glusterd_conf_t *conf)
   97 {
   98     rpc_transport_t *xprt = NULL;
   99     char key[GF_DUMP_MAX_BUF_LEN] = "";
  100     char subkey[50] = "";
  101     int index = 1;
  102 
  103     pthread_mutex_lock(&conf->xprt_lock);
  104     {
  105         list_for_each_entry(xprt, &conf->xprt_list, list)
  106         {
  107             snprintf(subkey, sizeof(subkey), "glusterd.client%d", index);
  108 
  109             gf_proc_dump_build_key(key, subkey, "identifier");
  110             gf_proc_dump_write(key, "%s", xprt->peerinfo.identifier);
  111 
  112             gf_proc_dump_build_key(key, subkey, "volname");
  113             gf_proc_dump_write(key, "%s", xprt->peerinfo.volname);
  114 
  115             gf_proc_dump_build_key(key, subkey, "max-op-version");
  116             gf_proc_dump_write(key, "%u", xprt->peerinfo.max_op_version);
  117 
  118             gf_proc_dump_build_key(key, subkey, "min-op-version");
  119             gf_proc_dump_write(key, "%u", xprt->peerinfo.min_op_version);
  120             index++;
  121         }
  122     }
  123     pthread_mutex_unlock(&conf->xprt_lock);
  124 }
  125 
  126 /* The following function is just for dumping mgmt_v3_lock dictionary, any other
  127  * dict passed to this API will not work */
  128 
  129 static void
  130 glusterd_dict_mgmt_v3_lock_statedump(dict_t *dict)
  131 {
  132     int ret = 0;
  133     int dumplen = 0;
  134     data_pair_t *trav = NULL;
  135     char key[GF_DUMP_MAX_BUF_LEN] = "";
  136     char dump[64 * 1024] = "";
  137 
  138     if (!dict) {
  139         gf_msg_callingfn("glusterd", GF_LOG_WARNING, EINVAL, GD_MSG_DICT_EMPTY,
  140                          "dict NULL");
  141         goto out;
  142     }
  143     for (trav = dict->members_list; trav; trav = trav->next) {
  144         if (strstr(trav->key, "debug.last-success-bt") != NULL) {
  145             ret = snprintf(&dump[dumplen], sizeof(dump) - dumplen, "\n\t%s:%s",
  146                            trav->key, trav->value->data);
  147         } else {
  148             ret = snprintf(
  149                 &dump[dumplen], sizeof(dump) - dumplen, "\n\t%s:%s", trav->key,
  150                 uuid_utoa(((glusterd_mgmt_v3_lock_obj *)(trav->value->data))
  151                               ->lock_owner));
  152         }
  153         if ((ret == -1) || !ret)
  154             return;
  155         dumplen += ret;
  156     }
  157 
  158     if (dumplen) {
  159         gf_proc_dump_build_key(key, "glusterd", "mgmt_v3_lock");
  160         gf_proc_dump_write(key, "%s", dump);
  161     }
  162 
  163 out:
  164     return;
  165 }
  166 
  167 int
  168 glusterd_dump_priv(xlator_t *this)
  169 {
  170     glusterd_conf_t *priv = NULL;
  171     char key[GF_DUMP_MAX_BUF_LEN] = "";
  172     int port = 0;
  173     struct pmap_registry *pmap = NULL;
  174 
  175     GF_VALIDATE_OR_GOTO("glusterd", this, out);
  176 
  177     priv = this->private;
  178     if (!priv)
  179         return 0;
  180 
  181     gf_proc_dump_build_key(key, "xlator.glusterd", "priv");
  182     gf_proc_dump_add_section("%s", key);
  183 
  184     pthread_mutex_lock(&priv->mutex);
  185     {
  186         gf_proc_dump_build_key(key, "glusterd", "my-uuid");
  187         gf_proc_dump_write(key, "%s", uuid_utoa(priv->uuid));
  188 
  189         gf_proc_dump_build_key(key, "glusterd", "working-directory");
  190         gf_proc_dump_write(key, "%s", priv->workdir);
  191 
  192         gf_proc_dump_build_key(key, "glusterd", "max-op-version");
  193         gf_proc_dump_write(key, "%d", GD_OP_VERSION_MAX);
  194 
  195         gf_proc_dump_build_key(key, "glusterd", "min-op-version");
  196         gf_proc_dump_write(key, "%d", GD_OP_VERSION_MIN);
  197 
  198         gf_proc_dump_build_key(key, "glusterd", "current-op-version");
  199         gf_proc_dump_write(key, "%d", priv->op_version);
  200 
  201         gf_proc_dump_build_key(key, "glusterd", "ping-timeout");
  202         gf_proc_dump_write(key, "%d", priv->ping_timeout);
  203 #ifdef BUILD_GNFS
  204         gf_proc_dump_build_key(key, "glusterd", "nfs.online");
  205         gf_proc_dump_write(key, "%d", priv->nfs_svc.online);
  206 #endif
  207         gf_proc_dump_build_key(key, "glusterd", "quotad.online");
  208         gf_proc_dump_write(key, "%d", priv->quotad_svc.online);
  209 
  210         gf_proc_dump_build_key(key, "glusterd", "bitd.online");
  211         gf_proc_dump_write(key, "%d", priv->bitd_svc.online);
  212 
  213         gf_proc_dump_build_key(key, "glusterd", "scrub.online");
  214         gf_proc_dump_write(key, "%d", priv->scrub_svc.online);
  215 
  216         /* Dump peer details */
  217         GLUSTERD_DUMP_PEERS(&priv->peers, uuid_list, _gf_false);
  218 
  219         /* Dump pmap data structure from base port to last alloc */
  220         pmap = priv->pmap;
  221         if (pmap) {
  222             for (port = pmap->base_port; port <= pmap->last_alloc; port++) {
  223                 gf_proc_dump_build_key(key, "glusterd", "pmap_port");
  224                 gf_proc_dump_write(key, "%d", port);
  225                 gf_proc_dump_build_key(key, "glusterd", "pmap[%d].type", port);
  226                 gf_proc_dump_write(key, "%d", pmap->ports[port].type);
  227                 gf_proc_dump_build_key(key, "glusterd", "pmap[%d].brickname",
  228                                        port);
  229                 gf_proc_dump_write(key, "%s", pmap->ports[port].brickname);
  230             }
  231         }
  232         /* Dump client details */
  233         glusterd_dump_client_details(priv);
  234 
  235         /* Dump mgmt_v3_lock from the dictionary if any */
  236         glusterd_dict_mgmt_v3_lock_statedump(priv->mgmt_v3_lock);
  237         dict_dump_to_statedump(priv->opts, "options", "glusterd");
  238     }
  239     pthread_mutex_unlock(&priv->mutex);
  240 
  241 out:
  242     return 0;
  243 }