root/crmd/attrd.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. log_attrd_error
  2. update_attrd_helper
  3. update_attrd
  4. update_attrd_remote_node_removed
  5. update_attrd_clear_failures

   1 /*
   2  * Copyright (C) 2006-2017 Andrew Beekhof <andrew@beekhof.net>
   3  *
   4  * This source code is licensed under the GNU Lesser General Public License
   5  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   6  */
   7 
   8 #include <crm_internal.h>
   9 
  10 #include <crm/crm.h>
  11 #include <crm/attrd.h>
  12 #include <crm/msg_xml.h>
  13 
  14 #include <crmd_fsa.h>
  15 #include <crmd_utils.h>
  16 #include <crmd_messages.h>
  17 
  18 crm_ipc_t *attrd_ipc = NULL;
  19 
  20 static void
  21 log_attrd_error(const char *host, const char *name, const char *value,
     /* [previous][next][first][last][top][bottom][index][help] */
  22                 gboolean is_remote, char command, int rc)
  23 {
  24     const char *display_command; /* for commands without name/value */
  25     const char *node_type = (is_remote? "Pacemaker Remote" : "cluster");
  26     gboolean shutting_down = is_set(fsa_input_register, R_SHUTDOWN);
  27     const char *when = (shutting_down? " at shutdown" : "");
  28 
  29     switch (command) {
  30         case 'R':
  31             display_command = "refresh";
  32             break;
  33         case 'C':
  34             display_command = "purge";
  35             break;
  36         default:
  37             display_command = NULL;
  38     }
  39 
  40     if (display_command) {
  41         crm_err("Could not request %s of %s node %s%s: %s (%d)",
  42                 display_command, node_type, host, when, pcmk_strerror(rc), rc);
  43     } else {
  44         crm_err("Could not request update of %s=%s for %s node %s%s: %s (%d)",
  45                 name, value, node_type, host, when, pcmk_strerror(rc), rc);
  46     }
  47 
  48     /* If we can't request shutdown via attribute, fast-track it */
  49     if ((command == 'U') && shutting_down) {
  50         register_fsa_input(C_FSA_INTERNAL, I_FAIL, NULL);
  51     }
  52 }
  53 
  54 static void
  55 update_attrd_helper(const char *host, const char *name, const char *value,
     /* [previous][next][first][last][top][bottom][index][help] */
  56                     const char *interval, const char *user_name,
  57                     gboolean is_remote_node, char command)
  58 {
  59     int rc;
  60     int max = 5;
  61     int attrd_opts = attrd_opt_none;
  62 
  63     if (is_remote_node) {
  64         attrd_opts |= attrd_opt_remote;
  65     }
  66 
  67     if (attrd_ipc == NULL) {
  68         attrd_ipc = crm_ipc_new(T_ATTRD, 0);
  69     }
  70 
  71     do {
  72         if (crm_ipc_connected(attrd_ipc) == FALSE) {
  73             crm_ipc_close(attrd_ipc);
  74             crm_info("Connecting to attribute manager ... %d retries remaining",
  75                      max);
  76             if (crm_ipc_connect(attrd_ipc) == FALSE) {
  77                 crm_perror(LOG_INFO, "Connection to attribute manager failed");
  78             }
  79         }
  80 
  81         if (command) {
  82             rc = attrd_update_delegate(attrd_ipc, command, host, name, value,
  83                                        XML_CIB_TAG_STATUS, NULL, NULL,
  84                                        user_name, attrd_opts);
  85         } else {
  86             /* (ab)using name/value as resource/operation */
  87             rc = attrd_clear_delegate(attrd_ipc, host, name, value, interval,
  88                                       user_name, attrd_opts);
  89         }
  90 
  91         if (rc == pcmk_ok) {
  92             break;
  93 
  94         } else if (rc != -EAGAIN && rc != -EALREADY) {
  95             crm_info("Disconnecting from attribute manager: %s (%d)",
  96                      pcmk_strerror(rc), rc);
  97             crm_ipc_close(attrd_ipc);
  98         }
  99 
 100         sleep(5 - max);
 101 
 102     } while (max--);
 103 
 104     if (rc != pcmk_ok) {
 105         log_attrd_error(host, name, value, is_remote_node, command, rc);
 106     }
 107 }
 108 
 109 void
 110 update_attrd(const char *host, const char *name, const char *value,
     /* [previous][next][first][last][top][bottom][index][help] */
 111              const char *user_name, gboolean is_remote_node)
 112 {
 113     update_attrd_helper(host, name, value, NULL, user_name, is_remote_node,
 114                         'U');
 115 }
 116 
 117 void
 118 update_attrd_remote_node_removed(const char *host, const char *user_name)
     /* [previous][next][first][last][top][bottom][index][help] */
 119 {
 120     crm_trace("Asking attrd to purge Pacemaker Remote node %s", host);
 121     update_attrd_helper(host, NULL, NULL, NULL, user_name, TRUE, 'C');
 122 }
 123 
 124 void
 125 update_attrd_clear_failures(const char *host, const char *rsc, const char *op,
     /* [previous][next][first][last][top][bottom][index][help] */
 126                             const char *interval, gboolean is_remote_node)
 127 {
 128     crm_info("Asking attrd to clear failure of %s %s for %s on %s node %s",
 129              (op? op : "all operations"),
 130              (interval? interval : "at all intervals"),
 131              rsc, (is_remote_node? "Pacemaker Remote" : "cluster"), host);
 132     update_attrd_helper(host, rsc, op, interval, NULL, is_remote_node, 0);
 133 }

/* [previous][next][first][last][top][bottom][index][help] */