"Fossies" - the Fresh Open Source Software Archive

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

    1 /*
    2   Copyright (c) 2006-2012 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/globals.h>
   12 #include <glusterfs/run.h>
   13 #include "glusterd.h"
   14 #include "glusterd-utils.h"
   15 #include "glusterd-volgen.h"
   16 #include "glusterd-scrub-svc.h"
   17 #include "glusterd-svc-helper.h"
   18 
   19 char *scrub_svc_name = "scrub";
   20 
   21 void
   22 glusterd_scrubsvc_build(glusterd_svc_t *svc)
   23 {
   24     svc->manager = glusterd_scrubsvc_manager;
   25     svc->start = glusterd_scrubsvc_start;
   26     svc->stop = glusterd_scrubsvc_stop;
   27 }
   28 
   29 int
   30 glusterd_scrubsvc_init(glusterd_svc_t *svc)
   31 {
   32     return glusterd_svc_init(svc, scrub_svc_name);
   33 }
   34 
   35 static int
   36 glusterd_scrubsvc_create_volfile()
   37 {
   38     char filepath[PATH_MAX] = {
   39         0,
   40     };
   41     int ret = -1;
   42     glusterd_conf_t *conf = NULL;
   43     xlator_t *this = NULL;
   44 
   45     this = THIS;
   46     conf = this->private;
   47     GF_ASSERT(conf);
   48 
   49     glusterd_svc_build_volfile_path(scrub_svc_name, conf->workdir, filepath,
   50                                     sizeof(filepath));
   51 
   52     ret = glusterd_create_global_volfile(build_scrub_graph, filepath, NULL);
   53     if (ret) {
   54         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
   55                "Failed to create volfile");
   56         goto out;
   57     }
   58 
   59 out:
   60     gf_msg_debug(this->name, 0, "Returning %d", ret);
   61 
   62     return ret;
   63 }
   64 
   65 int
   66 glusterd_scrubsvc_manager(glusterd_svc_t *svc, void *data, int flags)
   67 {
   68     int ret = -EINVAL;
   69 
   70     if (!svc->inited) {
   71         ret = glusterd_scrubsvc_init(svc);
   72         if (ret) {
   73             gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SCRUB_INIT_FAIL,
   74                    "Failed to init "
   75                    "scrub service");
   76             goto out;
   77         } else {
   78             svc->inited = _gf_true;
   79             gf_msg_debug(THIS->name, 0,
   80                          "scrub service "
   81                          "initialized");
   82         }
   83     }
   84 
   85     if (glusterd_should_i_stop_bitd()) {
   86         ret = svc->stop(svc, SIGTERM);
   87     } else {
   88         ret = glusterd_scrubsvc_create_volfile();
   89         if (ret)
   90             goto out;
   91 
   92         ret = svc->stop(svc, SIGKILL);
   93         if (ret)
   94             goto out;
   95 
   96         ret = svc->start(svc, flags);
   97         if (ret)
   98             goto out;
   99 
  100         ret = glusterd_conn_connect(&(svc->conn));
  101         if (ret)
  102             goto out;
  103     }
  104 
  105 out:
  106     if (ret)
  107         gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name);
  108     gf_msg_debug(THIS->name, 0, "Returning %d", ret);
  109 
  110     return ret;
  111 }
  112 
  113 int
  114 glusterd_scrubsvc_start(glusterd_svc_t *svc, int flags)
  115 {
  116     int ret = -1;
  117     dict_t *cmdict = NULL;
  118 
  119     cmdict = dict_new();
  120     if (!cmdict)
  121         goto error_return;
  122 
  123     ret = dict_set_str(cmdict, "cmdarg0", "--global-timer-wheel");
  124     if (ret)
  125         goto dealloc_dict;
  126 
  127     ret = glusterd_svc_start(svc, flags, cmdict);
  128 
  129 dealloc_dict:
  130     dict_unref(cmdict);
  131 error_return:
  132     return ret;
  133 }
  134 
  135 int
  136 glusterd_scrubsvc_stop(glusterd_svc_t *svc, int sig)
  137 {
  138     return glusterd_svc_stop(svc, sig);
  139 }
  140 
  141 int
  142 glusterd_scrubsvc_reconfigure()
  143 {
  144     int ret = -1;
  145     xlator_t *this = NULL;
  146     glusterd_conf_t *priv = NULL;
  147     gf_boolean_t identical = _gf_false;
  148 
  149     this = THIS;
  150     GF_VALIDATE_OR_GOTO("glusterd", this, out);
  151 
  152     priv = this->private;
  153     GF_VALIDATE_OR_GOTO(this->name, priv, out);
  154 
  155     if (glusterd_should_i_stop_bitd())
  156         goto manager;
  157 
  158     /*
  159      * Check both OLD and NEW volfiles, if they are SAME by size
  160      * and cksum i.e. "character-by-character". If YES, then
  161      * NOTHING has been changed, just return.
  162      */
  163     ret = glusterd_svc_check_volfile_identical(priv->scrub_svc.name,
  164                                                build_scrub_graph, &identical);
  165     if (ret)
  166         goto out;
  167 
  168     if (identical) {
  169         ret = 0;
  170         goto out;
  171     }
  172 
  173     /*
  174      * They are not identical. Find out if the topology is changed
  175      * OR just the volume options. If just the options which got
  176      * changed, then inform the xlator to reconfigure the options.
  177      */
  178     identical = _gf_false; /* RESET the FLAG */
  179     ret = glusterd_svc_check_topology_identical(priv->scrub_svc.name,
  180                                                 build_scrub_graph, &identical);
  181     if (ret)
  182         goto out;
  183 
  184     /* Topology is not changed, but just the options. But write the
  185      * options to scrub volfile, so that scrub will be reconfigured.
  186      */
  187     if (identical) {
  188         ret = glusterd_scrubsvc_create_volfile();
  189         if (ret == 0) { /* Only if above PASSES */
  190             ret = glusterd_fetchspec_notify(THIS);
  191         }
  192         goto out;
  193     }
  194 
  195 manager:
  196     /*
  197      * scrub volfile's topology has been changed. scrub server needs
  198      * to be RESTARTED to ACT on the changed volfile.
  199      */
  200     ret = priv->scrub_svc.manager(&(priv->scrub_svc), NULL, PROC_START_NO_WAIT);
  201 
  202 out:
  203     gf_msg_debug(this ? this->name : "glusterd", 0, "Returning %d", ret);
  204     return ret;
  205 }