[Ocfs2-tools-commits] khackel commits r441 -
branches/dlm-glue/dlmtools
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Nov 30 19:54:49 CST 2004
Author: khackel
Date: 2004-11-30 19:54:47 -0600 (Tue, 30 Nov 2004)
New Revision: 441
Modified:
branches/dlm-glue/dlmtools/mount.ocfs2.c
Log:
actually does all the local and remote group creation and addition properly, does raw lookups of heartbeat on the device to find live nodes
Modified: branches/dlm-glue/dlmtools/mount.ocfs2.c
===================================================================
--- branches/dlm-glue/dlmtools/mount.ocfs2.c 2004-12-01 00:57:42 UTC (rev 440)
+++ branches/dlm-glue/dlmtools/mount.ocfs2.c 2004-12-01 01:54:47 UTC (rev 441)
@@ -80,6 +80,7 @@
int create_remote_group(char *group_name, __u16 node);
int get_node_map(__u16 group_num, char *bitmap);
+int get_raw_node_map(__u16 groupnum, char *groupdev, __u32 block_bits, __u32 num_blocks, __u64 start_block, char *bitmap);
int get_ocfs2_disk_hb_params(char *group_dev, __u32 *block_bits, __u32 *cluster_bits,
__u64 *start_block, __u32 *num_clusters);
int activate_group(char *group_name, char *group_dev, __u16 group_num,
@@ -372,8 +373,10 @@
printf("device=%s hbuuid=%s hbdev=%s\n", device, hbuuid, hbdev);
ret = add_me_to_group(hbuuid, hbdev);
- if (ret < 0)
+ if (ret < 0) {
+ printf("eeek! something bad happened in add_me_to_group: ret=%d\n", (int)ret);
goto bail;
+ }
args = malloc(strlen(hbuuid) + strlen("group=") + 1);
if (!args)
@@ -457,9 +460,18 @@
} else {
printf("have not yet found myself (%u) in nodemap...\n", my_nodenum);
}
- sleep(1);
+ /* TODO: set this to the default hb interval. 2 seconds right now */
+ sleep(2);
}
+ /* now that we see ourself heartbeating, take a look
+ * at ALL of the nodes that seem to be heartbeating
+ * on this device. add them here and have them add
+ * me there... */
+ ret = get_raw_node_map(groupnum, groupdev, block_bits, num_blocks, start_block, (char *)pre_nodemap);
+ if (ret < 0)
+ return ret;
+
again:
/* go create this group and add this node on every other node I see */
start = 0;
@@ -469,8 +481,16 @@
break;
}
if (next != my_nodenum) {
+ /* add remote node here... */
+ ret = add_to_local_group(groupname, groupnum, next);
+ if (ret != -EEXIST && ret != 0)
+ return ret;
+
+ /* ...and add this node there */
ret = create_remote_group(groupname, next);
if (ret != 0 && ret != -EEXIST) {
+ printf("create_remote_group: node=%u returned %d!\n",
+ next, ret);
break;
}
}
@@ -479,16 +499,23 @@
if (ret != 0 && ret != -EEXIST)
return ret;
+ printf("done creating remote groups\n");
+
/* grab the nodemap again and look for changes */
- ret = get_node_map(groupnum, (char *)post_nodemap);
+ ret = get_raw_node_map(groupnum, groupdev, block_bits, num_blocks, start_block, (char *)post_nodemap);
if (ret < 0)
return ret;
+
+ printf("checking raw node map again.....\n");
if (memcmp(pre_nodemap, post_nodemap, sizeof(pre_nodemap)) == 0) {
/* nothing changed. we are DONE! */
+ printf("woot. nothing changed. all done\n");
return 0;
}
+ printf("something changed\n");
+
/* something changed */
for (i=0; i<8; i++) {
post_nodemap[i] &= ~pre_nodemap[i];
@@ -499,6 +526,8 @@
/* keep going while there are still nodes to contact */
if (ocfs2_find_next_bit_set((unsigned long *)pre_nodemap, NM_MAX_NODES, 0) < NM_MAX_NODES)
goto again;
+
+ printf("ah nothing left to care about ... leaving\n");
return 0;
}
@@ -769,20 +798,132 @@
return ret;
}
+
+int get_raw_node_map(__u16 groupnum, char *groupdev, __u32 block_bits, __u32 num_blocks, __u64 start_block, char *bitmap)
+{
+ int i;
+ int ret = -EINVAL;
+ char *buf = NULL, *tmpbuf;
+ hb_disk_heartbeat_block *times = NULL;
+
+ errcode_t err;
+ io_channel *channel;
+
+
+ printf("getting raw node map...\n");
+
+ times = malloc(sizeof(hb_disk_heartbeat_block) * NM_MAX_NODES);
+ if (!times) {
+ ret = -ENOMEM;
+ goto done;
+ }
+
+ err = io_open(groupdev, OCFS2_FLAG_RO, &channel);
+ if (err) {
+ ret = -EINVAL;
+ goto done;
+ }
+
+ err = io_set_blksize(channel, 1 << block_bits);
+ if (err) {
+ ret = -EINVAL;
+ goto done;
+ }
+
+ err = ocfs2_malloc_blocks(channel, (int)NM_MAX_NODES, &buf);
+ if (err) {
+ ret = -ENOMEM;
+ goto done;
+ }
+
+ err = io_read_block(channel, start_block, (int)NM_MAX_NODES, buf);
+ if (err) {
+ ret = -EIO;
+ if (err == OCFS2_ET_SHORT_READ)
+ ret = -EINVAL;
+ goto done;
+ }
+
+ tmpbuf = buf;
+ for (i=0; i<NM_MAX_NODES; i++) {
+ times[i].time = ((hb_disk_heartbeat_block *)tmpbuf)->time;
+ tmpbuf += (1 << block_bits);
+ }
+
+ /* TODO: how long? */
+ sleep(4);
+
+ err = io_read_block(channel, start_block, (int)NM_MAX_NODES, buf);
+ if (err) {
+ ret = -EIO;
+ if (err == OCFS2_ET_SHORT_READ)
+ ret = -EINVAL;
+ goto done;
+ }
+
+ tmpbuf = buf;
+ for (i=0; i<NM_MAX_NODES; i++) {
+ printf("node: %d: before=%llu, after=%llu\n", i, times[i].time, ((hb_disk_heartbeat_block *)tmpbuf)->time);
+ if (times[i].time != ((hb_disk_heartbeat_block *)tmpbuf)->time) {
+ printf(" >>>>> aha node %d seems to be up!\n", i);
+ ocfs2_set_bit(i, bitmap);
+ }
+ tmpbuf += (1 << block_bits);
+ }
+
+ ret = 0;
+done:
+
+ if (buf)
+ ocfs2_free(&buf);
+ io_close(channel);
+ if (times)
+ free(times);
+ return ret;
+}
+
int create_remote_group(char *group_name, __u16 node)
{
int ret, fd = -1, remote_node = -1;
gsd_ioc ioc;
char fname[100];
+ DIR *dir = NULL;
+ struct dirent *de = NULL;
+
+ printf("create_remote_group: name=%s, remote node=%u\n", group_name, node);
+
+ /* NOTE: this is a bit of a hack. we actually normally would not
+ * know which "global" node corresponds to this "group relative" node.
+ * but for now, they directly match up. */
+ // sprintf(fname, "/proc/cluster/nm/%s/%03u", group_name, node);
- sprintf(fname, "/proc/cluster/nm/%s/%03u", group_name, node);
+ dir = opendir("/proc/cluster/nm");
+ if (!dir) {
+ ret = -EINVAL;
+ goto leave;
+ }
+ fname[0]=0;
+ while ((de = readdir(dir)) != NULL) {
+ if (de->d_ino - NM_NODE_INODE_START == node) {
+ sprintf(fname, "/proc/cluster/nm/%s", de->d_name);
+ break;
+ }
+ }
+ closedir(dir);
+ if (!fname[0]) {
+ ret = -EINVAL;
+ goto leave;
+ }
+ printf("found file %s corresponding to node %u\n", fname, node);
+
/* open a file descriptor to the node we want to talk to */
remote_node = open(fname, O_RDONLY);
if (remote_node == -1) {
ret = -errno;
goto leave;
}
+ printf("fd for remote node=%d\n", remote_node);
/* TODO: move this over to a transaction file on the inode, eliminate the ioctl */
fd = open("/proc/cluster/net", O_RDONLY);
@@ -791,6 +932,8 @@
goto leave;
}
+ printf("fd for net ioctl file=%d\n", fd);
+
/* call an ioctl to create the group over there */
memset(&ioc, 0, sizeof(gsd_ioc));
ioc.fd = remote_node;
@@ -801,6 +944,7 @@
goto leave;
}
ret = ioc.status;
+ printf("create group ioctl returned ret=%d\n", ret);
if (ret != 0 && ret != -EEXIST)
goto leave;
@@ -815,6 +959,7 @@
goto leave;
}
ret = ioc.status;
+ printf("add node ioctl returned ret=%d\n", ret);
leave:
if (fd != -1)
More information about the Ocfs2-tools-commits
mailing list