forked from pool/ocfs2-tools
451 lines
11 KiB
Diff
451 lines
11 KiB
Diff
|
From 40b1211091b62a4884d1625fc04d476a07489ca3 Mon Sep 17 00:00:00 2001
|
||
|
From: Goldwyn Rodrigues <rgoldwyn@suse.com>
|
||
|
Date: Mon, 19 Aug 2013 08:38:59 -0500
|
||
|
Subject: [PATCH 2/7] libo2cb: Remove rest of controld functions
|
||
|
|
||
|
---
|
||
|
libo2cb/o2cb_abi.c | 388 +----------------------------------------------------
|
||
|
1 file changed, 2 insertions(+), 386 deletions(-)
|
||
|
|
||
|
Index: ocfs2-tools-1.8.2+git.1361836695.ff84eb5/libo2cb/o2cb_abi.c
|
||
|
===================================================================
|
||
|
--- ocfs2-tools-1.8.2+git.1361836695.ff84eb5.orig/libo2cb/o2cb_abi.c 2013-08-23 22:50:22.129878132 -0500
|
||
|
+++ ocfs2-tools-1.8.2+git.1361836695.ff84eb5/libo2cb/o2cb_abi.c 2013-08-23 22:52:20.143277130 -0500
|
||
|
@@ -46,7 +46,6 @@
|
||
|
#define CLUSTER_STACK_FILE "/sys/fs/ocfs2/cluster_stack"
|
||
|
#define LOCKING_PROTOCOL_FILE "/sys/fs/ocfs2/max_locking_protocol"
|
||
|
#define OCFS2_STACK_LABEL_LEN 4
|
||
|
-#define CONTROL_DEVICE "/dev/misc/ocfs2_control"
|
||
|
|
||
|
static errcode_t o2cb_validate_cluster_name(struct o2cb_cluster_desc *desc);
|
||
|
static errcode_t o2cb_validate_cluster_flags(struct o2cb_cluster_desc *desc,
|
||
|
@@ -106,8 +105,6 @@ static struct o2cb_stack user_stack = {
|
||
|
};
|
||
|
|
||
|
static struct o2cb_stack *current_stack;
|
||
|
-static int control_daemon_fd = -1;
|
||
|
-static int control_device_fd = -1;
|
||
|
|
||
|
static char *configfs_path;
|
||
|
|
||
|
@@ -1349,27 +1346,6 @@ static errcode_t classic_complete_group_
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
-static errcode_t user_parse_status(char **args, int *error, char **error_msg)
|
||
|
-{
|
||
|
- errcode_t err = O2CB_ET_IO;
|
||
|
- long result;
|
||
|
- char *ptr = NULL;
|
||
|
-
|
||
|
- result = strtol(args[0], &ptr, 10);
|
||
|
- if (ptr && *ptr != '\0') {
|
||
|
- /* fprintf(stderr, "Invalid error code string: %s", args[0]); */
|
||
|
- } else if ((result == LONG_MIN) || (result == LONG_MAX) ||
|
||
|
- (result < INT_MIN) || (result > INT_MAX)) {
|
||
|
- /* fprintf(stderr, "Error code %ld out of range", err); */
|
||
|
- } else {
|
||
|
- *error_msg = args[1];
|
||
|
- *error = result;
|
||
|
- err = 0;
|
||
|
- }
|
||
|
-
|
||
|
- return err;
|
||
|
-}
|
||
|
-
|
||
|
static errcode_t user_begin_group_join(struct o2cb_cluster_desc *cluster,
|
||
|
struct o2cb_region_desc *region)
|
||
|
{
|
||
|
@@ -1386,90 +1362,7 @@ static errcode_t user_complete_group_joi
|
||
|
static errcode_t user_group_leave(struct o2cb_cluster_desc *cluster,
|
||
|
struct o2cb_region_desc *region)
|
||
|
{
|
||
|
- errcode_t err = O2CB_ET_SERVICE_UNAVAILABLE;
|
||
|
- int rc;
|
||
|
- int error;
|
||
|
- char *error_msg;
|
||
|
- client_message message;
|
||
|
- char *argv[OCFS2_CONTROLD_MAXARGS + 1];
|
||
|
- char buf[OCFS2_CONTROLD_MAXLINE];
|
||
|
-
|
||
|
- if (control_daemon_fd != -1) {
|
||
|
- /* fprintf(stderr, "Join in progress!\n"); */
|
||
|
- err = O2CB_ET_INTERNAL_FAILURE;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- rc = ocfs2_client_connect();
|
||
|
- if (rc < 0) {
|
||
|
- /* fprintf(stderr, "Unable to connect to ocfs2_controld: %s\n",
|
||
|
- strerror(-rc)); */
|
||
|
- switch (rc) {
|
||
|
- case -EACCES:
|
||
|
- case -EPERM:
|
||
|
- err = O2CB_ET_PERMISSION_DENIED;
|
||
|
- break;
|
||
|
-
|
||
|
- default:
|
||
|
- err = O2CB_ET_SERVICE_UNAVAILABLE;
|
||
|
- break;
|
||
|
- }
|
||
|
- goto out;
|
||
|
- }
|
||
|
- control_daemon_fd = rc;
|
||
|
-
|
||
|
- rc = send_message(control_daemon_fd, CM_UNMOUNT, OCFS2_FS_NAME,
|
||
|
- region->r_name, region->r_service);
|
||
|
- if (rc) {
|
||
|
- /* fprintf(stderr, "Unable to send UNMOUNT message: %s\n",
|
||
|
- strerror(-rc)); */
|
||
|
- err = O2CB_ET_IO;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- rc = receive_message(control_daemon_fd, buf, &message, argv);
|
||
|
- if (rc < 0) {
|
||
|
- /* fprintf(stderr, "Error reading from daemon: %s\n",
|
||
|
- strerror(-rc)); */
|
||
|
- err = O2CB_ET_IO;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- switch (message) {
|
||
|
- case CM_STATUS:
|
||
|
- err = user_parse_status(argv, &error, &error_msg);
|
||
|
- if (err) {
|
||
|
- /* fprintf(stderr, "Bad status message: %s\n",
|
||
|
- strerror(-rc)); */
|
||
|
- goto out;
|
||
|
- }
|
||
|
- if (error) {
|
||
|
- /* fprintf(stderr,
|
||
|
- "Error %d from daemon: %s\n",
|
||
|
- error, error_msg); */
|
||
|
- err = O2CB_ET_CONFIGURATION_ERROR;
|
||
|
- goto out;
|
||
|
- }
|
||
|
- break;
|
||
|
-
|
||
|
- default:
|
||
|
- /* fprintf(stderr,
|
||
|
- "Unexpected message %s from daemon\n",
|
||
|
- message_to_string(message)); */
|
||
|
- err = O2CB_ET_INTERNAL_FAILURE;
|
||
|
- goto out;
|
||
|
- break;
|
||
|
- }
|
||
|
-
|
||
|
- err = 0;
|
||
|
-
|
||
|
-out:
|
||
|
- if (control_daemon_fd != -1) {
|
||
|
- close(control_daemon_fd);
|
||
|
- control_daemon_fd = -1;
|
||
|
- }
|
||
|
-
|
||
|
- return err;
|
||
|
+ return 0;
|
||
|
}
|
||
|
|
||
|
static errcode_t o2cb_validate_cluster_flags(struct o2cb_cluster_desc *desc,
|
||
|
@@ -1818,52 +1711,7 @@ static errcode_t classic_list_clusters(c
|
||
|
|
||
|
static errcode_t user_list_clusters(char ***clusters)
|
||
|
{
|
||
|
- errcode_t err = O2CB_ET_SERVICE_UNAVAILABLE;
|
||
|
- int rc, fd = -1;
|
||
|
- char buf[OCFS2_CONTROLD_MAXLINE];
|
||
|
-
|
||
|
- rc = ocfs2_client_connect();
|
||
|
- if (rc < 0) {
|
||
|
- /* fprintf(stderr, "Unable to connect to ocfs2_controld: %s\n",
|
||
|
- strerror(-rc)); */
|
||
|
- switch (rc) {
|
||
|
- case -EACCES:
|
||
|
- case -EPERM:
|
||
|
- err = O2CB_ET_PERMISSION_DENIED;
|
||
|
- break;
|
||
|
-
|
||
|
- default:
|
||
|
- err = O2CB_ET_SERVICE_UNAVAILABLE;
|
||
|
- break;
|
||
|
- }
|
||
|
- goto out;
|
||
|
- }
|
||
|
- fd = rc;
|
||
|
-
|
||
|
- rc = send_message(fd, CM_LISTCLUSTERS);
|
||
|
- if (rc) {
|
||
|
- /* fprintf(stderr,
|
||
|
- "Unable to send LISTCLUSTERS message: %s\n",
|
||
|
- strerror(-rc)); */
|
||
|
- err = O2CB_ET_IO;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- rc = receive_list(fd, buf, clusters);
|
||
|
- if (rc) {
|
||
|
- /* fprintf(stderr, "Error reading from daemon: %s\n",
|
||
|
- strerror(-rc)); */
|
||
|
- err = O2CB_ET_IO;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- err = 0;
|
||
|
-
|
||
|
-out:
|
||
|
- if (fd != -1)
|
||
|
- close(fd);
|
||
|
-
|
||
|
- return err;
|
||
|
+ return 0;
|
||
|
}
|
||
|
|
||
|
errcode_t o2cb_list_clusters(char ***clusters)
|
||
|
@@ -1991,83 +1839,6 @@ errcode_t o2cb_set_heartbeat_mode(char *
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
-static errcode_t dump_list_to_string(char **dump_list, char **debug)
|
||
|
-{
|
||
|
- int i;
|
||
|
- size_t len, count = 0;
|
||
|
- char *ptr;
|
||
|
-
|
||
|
- for (i = 0; dump_list[i]; i++)
|
||
|
- count += strlen(dump_list[i]);
|
||
|
-
|
||
|
- *debug = malloc(sizeof(char) * (count + 1));
|
||
|
- if (!*debug)
|
||
|
- return O2CB_ET_NO_MEMORY;
|
||
|
-
|
||
|
- ptr = *debug;
|
||
|
- ptr[count] = '\0';
|
||
|
- for (i = 0; dump_list[i]; i++) {
|
||
|
- len = strlen(dump_list[i]);
|
||
|
- memcpy(ptr, dump_list[i], len);
|
||
|
- ptr += len;
|
||
|
- }
|
||
|
-
|
||
|
- return 0;
|
||
|
-}
|
||
|
-
|
||
|
-errcode_t o2cb_control_daemon_debug(char **debug)
|
||
|
-{
|
||
|
- errcode_t err = O2CB_ET_SERVICE_UNAVAILABLE;
|
||
|
- int rc, fd = -1;
|
||
|
- char buf[OCFS2_CONTROLD_MAXLINE];
|
||
|
- char **dump_list = NULL;
|
||
|
-
|
||
|
- rc = ocfs2_client_connect();
|
||
|
- if (rc < 0) {
|
||
|
- /* fprintf(stderr, "Unable to connect to ocfs2_controld: %s\n",
|
||
|
- strerror(-rc)); */
|
||
|
- switch (rc) {
|
||
|
- case -EACCES:
|
||
|
- case -EPERM:
|
||
|
- err = O2CB_ET_PERMISSION_DENIED;
|
||
|
- break;
|
||
|
-
|
||
|
- default:
|
||
|
- err = O2CB_ET_SERVICE_UNAVAILABLE;
|
||
|
- break;
|
||
|
- }
|
||
|
- goto out;
|
||
|
- }
|
||
|
- fd = rc;
|
||
|
-
|
||
|
- rc = send_message(fd, CM_DUMP);
|
||
|
- if (rc) {
|
||
|
- /* fprintf(stderr,
|
||
|
- "Unable to send DUMP message: %s\n",
|
||
|
- strerror(-rc)); */
|
||
|
- err = O2CB_ET_IO;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- rc = receive_list(fd, buf, &dump_list);
|
||
|
- if (rc) {
|
||
|
- /* fprintf(stderr, "Error reading from daemon: %s\n",
|
||
|
- strerror(-rc)); */
|
||
|
- err = O2CB_ET_IO;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- err = dump_list_to_string(dump_list, debug);
|
||
|
- o2cb_free_dir_list(dump_list);
|
||
|
-
|
||
|
-out:
|
||
|
- if (fd != -1)
|
||
|
- close(fd);
|
||
|
-
|
||
|
- return err;
|
||
|
-}
|
||
|
-
|
||
|
-
|
||
|
errcode_t o2cb_get_hb_thread_pid (const char *cluster_name, const char *region_name,
|
||
|
pid_t *pid)
|
||
|
{
|
||
|
@@ -2171,161 +1942,6 @@ errcode_t o2cb_get_node_local(const char
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
-/*
|
||
|
- * The handshake is pretty simple. We need to read all supported control
|
||
|
- * device protocols from the kernel. Once we've read them, we can write
|
||
|
- * the protocol we want to use. After that, we're good to go.
|
||
|
- *
|
||
|
- * Right now, we will just allow the T01 protocol and not write any
|
||
|
- * code to handle multiples. We'll add that later if and when it is
|
||
|
- * necessary.
|
||
|
- *
|
||
|
- * The versions read from the kernel are all 4 characers including the
|
||
|
- * newline.
|
||
|
- */
|
||
|
-#define OCFS2_CONTROL_PROTO "T01\n"
|
||
|
-#define OCFS2_CONTROL_PROTO_LEN 4
|
||
|
-#define OCFS2_CONTROL_MESSAGE_SETNODE_OP "SETN"
|
||
|
-#define OCFS2_CONTROL_MESSAGE_SETNODE_TOTAL_LEN 14
|
||
|
-#define OCFS2_CONTROL_MESSAGE_SETVERSION_OP "SETV"
|
||
|
-#define OCFS2_CONTROL_MESSAGE_SETVERSION_TOTAL_LEN 11
|
||
|
-#define OCFS2_CONTROL_MESSAGE_DOWN_OP "DOWN"
|
||
|
-#define OCFS2_CONTROL_MESSAGE_DOWN_TOTAL_LEN 47
|
||
|
-#define OCFS2_CONTROL_MESSAGE_NODENUM_LEN 8
|
||
|
-static errcode_t o2cb_control_handshake(unsigned int this_node,
|
||
|
- struct ocfs2_protocol_version *proto)
|
||
|
-{
|
||
|
- errcode_t err = 0;
|
||
|
- int found = 0;
|
||
|
- size_t ret;
|
||
|
- char buf[OCFS2_CONTROL_MESSAGE_SETNODE_TOTAL_LEN + 1];
|
||
|
-
|
||
|
- if (control_device_fd == -1) {
|
||
|
- err = O2CB_ET_INTERNAL_FAILURE;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- buf[OCFS2_CONTROL_PROTO_LEN] = '\0';
|
||
|
- while (1)
|
||
|
- {
|
||
|
- ret = read(control_device_fd, buf, OCFS2_CONTROL_PROTO_LEN);
|
||
|
- if (ret == OCFS2_CONTROL_PROTO_LEN) {
|
||
|
- if (!found && !strcmp(buf,
|
||
|
- OCFS2_CONTROL_PROTO))
|
||
|
- found = 1;
|
||
|
- continue;
|
||
|
- }
|
||
|
-
|
||
|
- if (ret != 0)
|
||
|
- err = O2CB_ET_IO;
|
||
|
- else if (!found)
|
||
|
- err = O2CB_ET_SERVICE_HANDSHAKE_UNAVAILABLE; /* no match */
|
||
|
- break;
|
||
|
- }
|
||
|
-
|
||
|
- if (err)
|
||
|
- goto out;
|
||
|
-
|
||
|
- ret = write(control_device_fd, OCFS2_CONTROL_PROTO,
|
||
|
- OCFS2_CONTROL_PROTO_LEN);
|
||
|
- if (ret != OCFS2_CONTROL_PROTO_LEN) {
|
||
|
- err = O2CB_ET_IO;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- snprintf(buf, OCFS2_CONTROL_MESSAGE_SETNODE_TOTAL_LEN + 1,
|
||
|
- OCFS2_CONTROL_MESSAGE_SETNODE_OP " %08X\n", this_node);
|
||
|
- ret = write(control_device_fd, buf,
|
||
|
- OCFS2_CONTROL_MESSAGE_SETNODE_TOTAL_LEN);
|
||
|
- if (ret != OCFS2_CONTROL_MESSAGE_SETNODE_TOTAL_LEN)
|
||
|
- err = O2CB_ET_IO;
|
||
|
-
|
||
|
- snprintf(buf, OCFS2_CONTROL_MESSAGE_SETVERSION_TOTAL_LEN + 1,
|
||
|
- OCFS2_CONTROL_MESSAGE_SETVERSION_OP " %02X %02X\n",
|
||
|
- proto->pv_major, proto->pv_minor);
|
||
|
- ret = write(control_device_fd, buf,
|
||
|
- OCFS2_CONTROL_MESSAGE_SETVERSION_TOTAL_LEN);
|
||
|
- if (ret != OCFS2_CONTROL_MESSAGE_SETVERSION_TOTAL_LEN)
|
||
|
- err = O2CB_ET_IO;
|
||
|
-
|
||
|
-out:
|
||
|
- return err;
|
||
|
-}
|
||
|
-
|
||
|
-errcode_t o2cb_control_open(unsigned int this_node,
|
||
|
- struct ocfs2_protocol_version *proto)
|
||
|
-{
|
||
|
- errcode_t err = 0;
|
||
|
- int rc;
|
||
|
-
|
||
|
- if (!current_stack) {
|
||
|
- err = O2CB_ET_SERVICE_UNAVAILABLE;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- if (control_device_fd != -1)
|
||
|
- goto out;
|
||
|
-
|
||
|
- rc = open(CONTROL_DEVICE, O_RDWR);
|
||
|
- if (rc < 0) {
|
||
|
- switch (errno) {
|
||
|
- default:
|
||
|
- err = O2CB_ET_INTERNAL_FAILURE;
|
||
|
- break;
|
||
|
-
|
||
|
- case ENOTDIR:
|
||
|
- case ENOENT:
|
||
|
- case EISDIR:
|
||
|
- err = O2CB_ET_SERVICE_DEV_UNAVAILABLE;
|
||
|
- break;
|
||
|
-
|
||
|
- case EACCES:
|
||
|
- case EPERM:
|
||
|
- case EROFS:
|
||
|
- err = O2CB_ET_PERMISSION_DENIED;
|
||
|
- break;
|
||
|
- }
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- control_device_fd = rc;
|
||
|
-
|
||
|
- err = o2cb_control_handshake(this_node, proto);
|
||
|
- if (err) {
|
||
|
- close(control_device_fd);
|
||
|
- control_device_fd = -1;
|
||
|
- }
|
||
|
-
|
||
|
-out:
|
||
|
- return err;
|
||
|
-}
|
||
|
-
|
||
|
-void o2cb_control_close(void)
|
||
|
-{
|
||
|
- if (control_device_fd != -1) {
|
||
|
- close(control_device_fd);
|
||
|
- control_device_fd = -1;
|
||
|
- }
|
||
|
-}
|
||
|
-
|
||
|
-errcode_t o2cb_control_node_down(const char *uuid, unsigned int nodeid)
|
||
|
-{
|
||
|
- errcode_t err = 0;
|
||
|
- size_t ret;
|
||
|
- char buf[OCFS2_CONTROL_MESSAGE_DOWN_TOTAL_LEN + 1];
|
||
|
-
|
||
|
- if (control_device_fd == -1)
|
||
|
- return O2CB_ET_INTERNAL_FAILURE;
|
||
|
-
|
||
|
- snprintf(buf, OCFS2_CONTROL_MESSAGE_DOWN_TOTAL_LEN + 1,
|
||
|
- "DOWN %.32s %08X\n", uuid, nodeid);
|
||
|
- ret = write(control_device_fd, buf,
|
||
|
- OCFS2_CONTROL_MESSAGE_DOWN_TOTAL_LEN);
|
||
|
- if (ret != OCFS2_CONTROL_MESSAGE_DOWN_TOTAL_LEN)
|
||
|
- err = O2CB_ET_IO;
|
||
|
-
|
||
|
- return err;
|
||
|
-}
|
||
|
|
||
|
errcode_t o2cb_get_hb_ctl_path(char *buf, int count)
|
||
|
{
|