Ejemplo n.º 1
0
/**
 * Write the hostname to disk.
 *
 * \param[in] hostname  Hostname to write
 *
 * \return 0 if successful, a negative error code otherwise
 */
int
adm_hostname_save(const char *hostname)
{
  char path[OS_PATH_MAX];
  FILE *file;
  char tmp[EXA_MAXSIZE_HOSTNAME + 1 + 1]; /* +2 for \n and \0 */
  int err = 0, err2;

  exalog_trace("saving hostname to %s", path);

  exa_env_make_path(path, sizeof(path), exa_env_cachedir(), HOSTNAME_FILENAME);

  if (os_snprintf(tmp, sizeof(tmp), "%s\n", hostname) >= sizeof(tmp))
    return -EINVAL;

  file = fopen(path, "wt");
  if (file == NULL)
    return -errno;

  if (fputs(tmp, file) == EOF)
    err = -EIO;

  err2 = fclose(file);

  if (err)
    return err;

  if (err2)
    return err2;

  return 0;
}
Ejemplo n.º 2
0
/**
 * Delete the hostname file.
 * Succeeds also if the hostname file doesn't exist.
 *
 * \return 0 if successful, a negative error code otherwise
 */
int
adm_hostname_delete_file(void)
{
  char path[OS_PATH_MAX];

  exa_env_make_path(path, sizeof(path), exa_env_cachedir(), HOSTNAME_FILENAME);

  exalog_trace("deleting %s", path);
  if (unlink(path) < 0 && errno != ENOENT)
    return -errno;

  return 0;
}
Ejemplo n.º 3
0
static void handle_start_control(md_msg_control_start_t *start)
{
    int ret;

    if (!md_srv_com_is_agentx_alive())
    {
	char node_id_str[32];
	char master_agentx_port_str[EXA_MAXSIZE_LINE + 1];
	os_snprintf(node_id_str, sizeof(node_id_str), "%u", start->node_id);
	os_snprintf(master_agentx_port_str, sizeof(master_agentx_port_str), "%d",
                    start->master_agentx_port);

        /* XXX No use for a block here */
	{
            char agentx_path[OS_PATH_MAX];
	    char *const argv[] =
		{
                    agentx_path,
		    node_id_str,
		    start->node_name,
		    start->master_agentx_host,
		    master_agentx_port_str,
		    NULL
		};

            exa_env_make_path(agentx_path, sizeof(agentx_path), exa_env_sbindir(), "exa_agentx");
	    ret = exa_system(argv);
	}
	if (ret != EXA_SUCCESS)
	{
	    exalog_error("Error spawning exa_agentx(%d).", ret);
	    md_messaging_ack_control(ret);
	    return;
	}

	/* wait a bit to get the first alive message from agentx
	 * TODO : not robust enough, replace with a timeouted lock */
	os_sleep(MD_HEARTBEAT_TIMEOUT_SECONDS);

	if (!md_srv_com_is_agentx_alive())
	{
	    exalog_error("Error spawning exa_agentx(%d).", -MD_ERR_AGENTX_NOT_ALIVE);
	    md_messaging_ack_control(-MD_ERR_AGENTX_NOT_ALIVE);
	    return;
	}
    }
    md_messaging_ack_control(EXA_SUCCESS);
}
Ejemplo n.º 4
0
int rdev_remove_broken_disks_file(void)
{
    int err;
    char path[OS_PATH_MAX];

    if (broken_disks != NULL)
        return -EBUSY;

    err = exa_env_make_path(path, sizeof(path), exa_env_cachedir(), "broken_disks");
    if (err != 0)
        return err;

    if(unlink(path) != 0)
        return -errno;

    return 0;
}
Ejemplo n.º 5
0
/**
 * Read our hostname from disk.
 *
 * XXX Should probably store the cluster uuid within hostname file
 *     and check this uuid matches the one in the cluster config ?
 *
 * \param[out] hostname  Hostname read
 *
 * \return 0 if successful, a negative error code otherwise (most notably,
 *         -ENOENT if the hostname file does not exist)
 */
int
adm_hostname_load(char *hostname)
{
  char path[OS_PATH_MAX];
  FILE *file;
  char tmp[EXA_MAXSIZE_LINE + 1];
  size_t len;
  int err = 0, err2;

  exalog_trace("loading hostname from %s", path);

  exa_env_make_path(path, sizeof(path), exa_env_cachedir(), HOSTNAME_FILENAME);

  file = fopen(path, "rt");
  if (file == NULL)
    return -errno;

  if (fgets(tmp, sizeof(tmp) - 1, file) == NULL)
    err = -EIO;

  err2 = fclose(file);

  if (err)
    return err;

  if (err2)
    return err2;

  /* Eat up all whitespace at the end of the line */
  len = strlen(tmp);
  while (len > 0 && isspace(tmp[len - 1]))
  {
    tmp[len - 1] = '\0';
    len--;
  }

  if (len == 0 || len > EXA_MAXSIZE_HOSTNAME)
    return -EINVAL;

  strlcpy(hostname, tmp, len + 1);

  exalog_trace("hostname read: '%s'", hostname);

  return 0;
}
Ejemplo n.º 6
0
static void
cluster_get_license(int thr_nb, void *dummy, cl_error_desc_t *err_desc)
{
    char *buffer;
    char path[OS_PATH_MAX];

    exalog_debug("getlicense");

    exa_env_make_path(path, sizeof(path), exa_env_cachedir(), ADM_LICENSE_FILE);

    buffer = adm_file_read_to_str(path, err_desc);
    if (buffer == NULL)
        return;

    send_payload_str(buffer);

    os_free(buffer);

    set_success(err_desc);
}
Ejemplo n.º 7
0
/**
 * Initialize the RDEV service:
 * - start exa_rdev kernel module,
 * - allocate and initialize aligned buffers to read/writes superblocks.
 */
static int
rdev_init(int thr_nb)
{
  char path[OS_PATH_MAX];
  int err = 0;

  if (os_kmod_load("exa_rdev") != 0)
  {
    exalog_error("Failed to load kernel module 'exa_rdev'");
    return -ADMIND_ERR_MODULESTART;
  }

  /* Load the broken disks table */
  err = exa_env_make_path(path, sizeof(path), exa_env_cachedir(), "broken_disks");
  if (err != 0)
      return err;

  err = broken_disk_table_load(&broken_disks, path, true /* open_read_write */);
  if (err != 0)
  {
      exalog_error("Failed loading the broken disk table: %s (%d)",
                    exa_error_msg(err), err);
      return err;
  }

  /* Initialize the rdev module */
  err = exa_rdev_static_init(RDEV_STATIC_CREATE);
  if (err != 0)
  {
    exalog_error("Failed initializing rdev statics: %s (%d)", exa_error_msg(err), err);
    goto cleanup_broken;
  }

  exa_rdev_fd = exa_rdev_init();
  if (exa_rdev_fd <= 0)
  {
    err = exa_rdev_fd;
    exalog_error("Failed initializing rdev: %s (%d)", exa_error_msg(err), err);
    goto cleanup_broken;
  }

  mh = examsgInit(EXAMSG_RDEV_ID);
  if (!mh)
  {
      exalog_error("Failed initializing messaging for disk checking thread");
      err = -ENOMEM;
      goto cleanup_rdev_fd;
  }

  COMPILE_TIME_ASSERT(RDEV_SUPERBLOCK_SIZE <= SECTORS_TO_BYTES(RDEV_RESERVED_AREA_IN_SECTORS));

  rdev_check_buffer = os_aligned_malloc(RDEV_SUPERBLOCK_SIZE, 4096, NULL);
  if (!rdev_check_buffer)
  {
      exalog_error("Failed allocating disk checking buffer");
      err = -ENOMEM;
      goto cleanup_mh;
  }

  /* make sure the check thread will not quit */
  quit = false;

  /* launch the rdev checking thread */
  if (!exathread_create_named(&rdev_check_id, MIN_THREAD_STACK_SIZE,
                              disk_checking_thread, mh, "rdev_check"))
  {
      exalog_error("Failed creating disk checking thread");
      err = -EXA_ERR_DEFAULT;
      goto cleanup_rdev_check_buffer;
  }

  rdev_check_id_started = true;

  return EXA_SUCCESS;

cleanup_rdev_check_buffer:
    os_aligned_free(rdev_check_buffer);
    rdev_check_buffer = NULL;
cleanup_mh:
    examsgExit(mh);
    mh = NULL;
cleanup_rdev_fd:
    close(exa_rdev_fd);
    exa_rdev_fd = -1;
cleanup_broken:
    broken_disk_table_unload(&broken_disks);
    return err;
}