"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.c" (16 Sep 2020, 4135 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-shd-svc-helper.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2    Copyright (c) 2016 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 "glusterd.h"
   12 #include "glusterd-utils.h"
   13 #include "glusterd-shd-svc-helper.h"
   14 #include "glusterd-messages.h"
   15 #include "glusterd-volgen.h"
   16 
   17 void
   18 glusterd_svc_build_shd_socket_filepath(glusterd_volinfo_t *volinfo, char *path,
   19                                        int path_len)
   20 {
   21     char sockfilepath[PATH_MAX] = {
   22         0,
   23     };
   24     char rundir[PATH_MAX] = {
   25         0,
   26     };
   27     int32_t len = 0;
   28     glusterd_conf_t *priv = THIS->private;
   29 
   30     if (!priv)
   31         return;
   32 
   33     GLUSTERD_GET_SHD_RUNDIR(rundir, volinfo, priv);
   34     len = snprintf(sockfilepath, sizeof(sockfilepath), "%s/run-%s", rundir,
   35                    uuid_utoa(MY_UUID));
   36     if ((len < 0) || (len >= sizeof(sockfilepath))) {
   37         sockfilepath[0] = 0;
   38     }
   39 
   40     glusterd_set_socket_filepath(sockfilepath, path, path_len);
   41 }
   42 
   43 void
   44 glusterd_svc_build_shd_pidfile(glusterd_volinfo_t *volinfo, char *path,
   45                                int path_len)
   46 {
   47     char rundir[PATH_MAX] = {
   48         0,
   49     };
   50     glusterd_conf_t *priv = THIS->private;
   51 
   52     if (!priv)
   53         return;
   54 
   55     GLUSTERD_GET_SHD_RUNDIR(rundir, volinfo, priv);
   56 
   57     snprintf(path, path_len, "%s/%s-shd.pid", rundir, volinfo->volname);
   58 }
   59 
   60 void
   61 glusterd_svc_build_shd_volfile_path(glusterd_volinfo_t *volinfo, char *path,
   62                                     int path_len)
   63 {
   64     char workdir[PATH_MAX] = {
   65         0,
   66     };
   67     glusterd_conf_t *priv = THIS->private;
   68 
   69     if (!priv)
   70         return;
   71 
   72     GLUSTERD_GET_VOLUME_DIR(workdir, volinfo, priv);
   73 
   74     snprintf(path, path_len, "%s/%s-shd.vol", workdir, volinfo->volname);
   75 }
   76 
   77 void
   78 glusterd_shd_svcproc_cleanup(glusterd_shdsvc_t *shd)
   79 {
   80     glusterd_svc_proc_t *svc_proc = NULL;
   81     glusterd_svc_t *svc = NULL;
   82     glusterd_conf_t *conf = NULL;
   83     gf_boolean_t need_unref = _gf_false;
   84     rpc_clnt_t *rpc = NULL;
   85 
   86     conf = THIS->private;
   87     if (!conf)
   88         return;
   89 
   90     GF_VALIDATE_OR_GOTO(THIS->name, conf, out);
   91     GF_VALIDATE_OR_GOTO(THIS->name, shd, out);
   92 
   93     svc = &shd->svc;
   94     shd->attached = _gf_false;
   95 
   96     if (svc->conn.rpc) {
   97         rpc_clnt_unref(svc->conn.rpc);
   98         svc->conn.rpc = NULL;
   99     }
  100 
  101     pthread_mutex_lock(&conf->attach_lock);
  102     {
  103         svc_proc = svc->svc_proc;
  104         svc->svc_proc = NULL;
  105         svc->inited = _gf_false;
  106         cds_list_del_init(&svc->mux_svc);
  107         glusterd_unlink_file(svc->proc.pidfile);
  108 
  109         if (svc_proc && cds_list_empty(&svc_proc->svcs)) {
  110             cds_list_del_init(&svc_proc->svc_proc_list);
  111             /* We cannot free svc_proc list from here. Because
  112              * if there are pending events on the rpc, it will
  113              * try to access the corresponding svc_proc, so unrefing
  114              * rpc request and then cleaning up the memory is carried
  115              * from the notify function upon RPC_CLNT_DESTROY destroy.
  116              */
  117             need_unref = _gf_true;
  118             rpc = svc_proc->rpc;
  119             svc_proc->rpc = NULL;
  120         }
  121     }
  122     pthread_mutex_unlock(&conf->attach_lock);
  123     /*rpc unref has to be performed outside the lock*/
  124     if (need_unref && rpc)
  125         rpc_clnt_unref(rpc);
  126 out:
  127     return;
  128 }
  129 
  130 int
  131 glusterd_svc_set_shd_pidfile(glusterd_volinfo_t *volinfo, dict_t *dict)
  132 {
  133     int ret = -1;
  134     glusterd_svc_t *svc = NULL;
  135     xlator_t *this = NULL;
  136 
  137     this = THIS;
  138     GF_VALIDATE_OR_GOTO("glusterd", this, out);
  139     GF_VALIDATE_OR_GOTO(this->name, volinfo, out);
  140     GF_VALIDATE_OR_GOTO(this->name, dict, out);
  141 
  142     svc = &(volinfo->shd.svc);
  143 
  144     ret = dict_set_dynstr_with_alloc(dict, "pidfile", svc->proc.pidfile);
  145     if (ret) {
  146         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED,
  147                "Failed to set pidfile %s in dict", svc->proc.pidfile);
  148         goto out;
  149     }
  150     ret = 0;
  151 out:
  152     return ret;
  153 }