[Ocfs2-tools-commits] smushran commits r777 - in trunk: libo2cb
libo2cb/include libocfs2 libocfs2/include mount.ocfs2
mounted.ocfs2 o2cb_ctl
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Apr 1 17:15:10 CST 2005
Author: smushran
Date: 2005-04-01 17:15:08 -0600 (Fri, 01 Apr 2005)
New Revision: 777
Added:
trunk/libo2cb/Cscope.make
trunk/o2cb_ctl/Cscope.make
Modified:
trunk/libo2cb/include/o2cb.h
trunk/libo2cb/o2cb_abi.c
trunk/libo2cb/o2cb_err.et
trunk/libocfs2/checkhb.c
trunk/libocfs2/include/ocfs2.h
trunk/mount.ocfs2/Cscope.make
trunk/mounted.ocfs2/Cscope.make
trunk/mounted.ocfs2/mounted.c
trunk/o2cb_ctl/
Log:
add api to list nodes in o2cb
mounted.c uses o2cb to get list of nodes in the cluster
Added: trunk/libo2cb/Cscope.make
===================================================================
--- trunk/libo2cb/Cscope.make 2005-03-31 02:26:54 UTC (rev 776)
+++ trunk/libo2cb/Cscope.make 2005-04-01 23:15:08 UTC (rev 777)
@@ -0,0 +1,12 @@
+.PHONY: cscope
+cscope:
+ rm -f cscope.*
+ echo "-k" >> cscope.files
+ echo "-I inc" >> cscope.files
+ find . -maxdepth 2 -name '*.c' -print >>cscope.files
+ find . -maxdepth 2 -name '*.h' -print >>cscope.files
+ find ../libocfs2/ -maxdepth 2 -name '*.c' -print >>cscope.files
+ find ../libocfs2/ -maxdepth 2 -name '*.h' -print >>cscope.files
+ find ../libo2dlm/ -maxdepth 2 -name '*.c' -print >>cscope.files
+ find ../libo2dlm/ -maxdepth 2 -name '*.h' -print >>cscope.files
+ cscope -b
Modified: trunk/libo2cb/include/o2cb.h
===================================================================
--- trunk/libo2cb/include/o2cb.h 2005-03-31 02:26:54 UTC (rev 776)
+++ trunk/libo2cb/include/o2cb.h 2005-04-01 23:15:08 UTC (rev 777)
@@ -56,6 +56,9 @@
errcode_t o2cb_list_clusters(char ***clusters);
void o2cb_free_cluster_list(char **clusters);
+errcode_t o2cb_list_nodes(char *cluster_name, char ***nodes);
+void o2cb_free_nodes_list(char **nodes);
+
errcode_t o2cb_create_heartbeat_region_disk(const char *cluster_name,
const char *region_name,
const char *device_name,
@@ -65,5 +68,8 @@
errcode_t o2cb_remove_heartbeat_region_disk(const char *cluster_name,
const char *region_name);
+errcode_t o2cb_get_node_num(const char *cluster_name,
+ const char *node_name,
+ uint16_t *node_num);
#endif /* _O2CB_H */
Modified: trunk/libo2cb/o2cb_abi.c
===================================================================
--- trunk/libo2cb/o2cb_abi.c 2005-03-31 02:26:54 UTC (rev 776)
+++ trunk/libo2cb/o2cb_abi.c 2005-04-01 23:15:08 UTC (rev 777)
@@ -572,18 +572,18 @@
return err;
}
-errcode_t o2cb_list_clusters(char ***clusters)
+static errcode_t o2cb_list_dir(char *path, char ***objs)
{
errcode_t ret;
int count;
DIR *dir;
struct dirent *dirent;
- struct clist {
- struct clist *next;
- char *cluster;
+ struct dlist {
+ struct dlist *next;
+ char *name;
} *tmp, *list;
- dir = opendir(O2CB_FORMAT_CLUSTER_DIR);
+ dir = opendir(path);
if (!dir) {
switch (errno) {
default:
@@ -611,12 +611,12 @@
count = 0;
list = NULL;
while ((dirent = readdir(dir)) != NULL) {
- tmp = malloc(sizeof(struct clist));
+ tmp = malloc(sizeof(struct dlist));
if (!tmp)
goto out_free_list;
- tmp->cluster = strdup(dirent->d_name);
- if (!tmp->cluster) {
+ tmp->name = strdup(dirent->d_name);
+ if (!tmp->name) {
free(tmp);
goto out_free_list;
}
@@ -626,17 +626,17 @@
count++;
}
- *clusters = malloc(sizeof(char *) * (count + 1));
- if (!*clusters)
+ *objs = malloc(sizeof(char *) * (count + 1));
+ if (!*objs)
goto out_free_list;
tmp = list;
count = 0;
for (tmp = list, count = 0; tmp; tmp = tmp->next, count++) {
- (*clusters)[count] = tmp->cluster;
- tmp->cluster = NULL;
+ (*objs)[count] = tmp->name;
+ tmp->name = NULL;
}
- (*clusters)[count] = NULL;
+ (*objs)[count] = NULL;
ret = 0;
@@ -645,8 +645,8 @@
tmp = list;
list = list->next;
- if (tmp->cluster)
- free(tmp->cluster);
+ if (tmp->name)
+ free(tmp->name);
free(tmp);
}
@@ -656,13 +656,59 @@
return ret;
}
-void o2cb_free_cluster_list(char **clusters)
+static void o2cb_free_dir_list(char **objs)
{
int i;
- for (i = 0; clusters[i]; i++) {
- free(clusters[i]);
- }
+ for (i = 0; objs[i]; i++)
+ free(objs[i]);
- free(clusters);
+ free(objs);
}
+
+errcode_t o2cb_list_clusters(char ***clusters)
+{
+ return o2cb_list_dir(O2CB_FORMAT_CLUSTER_DIR, clusters);
+}
+
+void o2cb_free_cluster_list(char **clusters)
+{
+ o2cb_free_dir_list(clusters);
+}
+
+errcode_t o2cb_list_nodes(char *cluster_name, char ***nodes)
+{
+ char path[PATH_MAX];
+ errcode_t ret;
+
+ ret = snprintf(path, PATH_MAX - 1, O2CB_FORMAT_NODE_DIR,
+ cluster_name);
+ if ((ret <= 0) || (ret == (PATH_MAX - 1)))
+ return O2CB_ET_INTERNAL_FAILURE;
+
+ return o2cb_list_dir(path, nodes);
+}
+
+void o2cb_free_nodes_list(char **nodes)
+{
+ o2cb_free_dir_list(nodes);
+}
+
+errcode_t o2cb_get_node_num(const char *cluster_name, const char *node_name,
+ uint16_t *node_num)
+{
+ char val[30];
+ char *p;
+ errcode_t ret;
+
+ ret = o2cb_get_node_attribute(cluster_name, node_name,
+ "num", val, sizeof(val));
+ if (ret)
+ return ret;
+
+ *node_num = strtoul(val, &p, 0);
+ if (!p || (*p && *p != '\n'))
+ return O2CB_ET_INVALID_NODE_NUM;
+
+ return 0;
+}
Modified: trunk/libo2cb/o2cb_err.et
===================================================================
--- trunk/libo2cb/o2cb_err.et 2005-03-31 02:26:54 UTC (rev 776)
+++ trunk/libo2cb/o2cb_err.et 2005-04-01 23:15:08 UTC (rev 777)
@@ -63,4 +63,7 @@
ec O2CB_ET_CONFIGURATION_ERROR,
"Configuration error discovered"
+ec O2CB_ET_INVALID_NODE_NUM,
+ "Node number is invalid"
+
end
Modified: trunk/libocfs2/checkhb.c
===================================================================
--- trunk/libocfs2/checkhb.c 2005-03-31 02:26:54 UTC (rev 776)
+++ trunk/libocfs2/checkhb.c 2005-04-01 23:15:08 UTC (rev 777)
@@ -40,40 +40,17 @@
#include "ocfs2_fs.h"
#include "ocfs1_fs_compat.h"
-#define FATAL_ERROR(fmt, arg...) \
- ({ fprintf(stderr, "ERROR at %s, %d: " fmt ". EXITING!!!\n", \
- __FILE__, __LINE__, ##arg); \
- raise (SIGTERM); \
- exit(1); \
- })
-
-static void ocfs2_fill_nodes_list (char *buf, uint32_t len, struct list_head *node_list)
+static errcode_t ocfs2_read_slotmap (ocfs2_filesys *fs, uint8_t *node_nums)
{
- int16_t *slots = (int16_t *)buf;
- uint32_t i;
- uint32_t num_slots = (len / sizeof(uint16_t));
- ocfs2_nodes *node_blk;
-
- for (i = 0; i < num_slots; ++i) {
- if (slots[i] == -1)
- break;
- if (ocfs2_malloc0(sizeof(ocfs2_nodes), &node_blk))
- FATAL_ERROR("out of memory");
- node_blk->node_num = slots[i];
- list_add_tail(&(node_blk->list), node_list);
- }
-
- return ;
-}
-
-static errcode_t ocfs2_read_slotmap (ocfs2_filesys *fs, struct list_head *node_list)
-{
errcode_t ret = 0;
char *slotbuf = NULL;
int slotbuf_len;
char *slotmap = ocfs2_system_inodes[SLOT_MAP_SYSTEM_INODE].si_name;
uint32_t slotmap_len;
uint64_t slotmap_blkno;
+ int16_t *slots;
+ int i, j;
+ uint32_t num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
slotmap_len = strlen(slotmap);
@@ -82,29 +59,24 @@
if (ret)
return ret;
- ret = ocfs2_read_whole_file(fs, slotmap_blkno,
- &slotbuf, &slotbuf_len);
+ ret = ocfs2_read_whole_file(fs, slotmap_blkno, &slotbuf, &slotbuf_len);
if (!ret) {
- ocfs2_fill_nodes_list(slotbuf, slotbuf_len, node_list);
- ocfs2_free(&slotbuf);
+ slots = (int16_t *)slotbuf;
+ for (i = 0, j = 0; i < num_nodes; ++i)
+ if (slots[i] != -1)
+ node_nums[j++] = (uint8_t)slots[i];
}
+ if (slotbuf)
+ ocfs2_free(&slotbuf);
+
return ret;
}
/*
- * ocfs2_check_heartbeat() check if the device is mounted on the
- * cluster or not
+ * ocfs2_check_heartbeats() check if the list of ocfs2 devices are
+ * mounted on the cluster or not
*
- * notify ==>
- * Called for every step of progress (because this takes a few
- * seconds). Can be NULL. States are:
- * OCFS2_CHB_START
- * OCFS2_CHB_WAITING (N times)
- * OCFS2_CHB_COMPLETE
- * user_data ==>
- * User data pointer for the notify function.
- *
* Return:
* mounted_flags set to ==>
* OCFS2_MF_MOUNTED if mounted locally
@@ -112,73 +84,7 @@
* OCFS2_MF_READONLY
* OCFS2_MF_SWAP
* OCFS2_MF_MOUNTED_CLUSTER if mounted on cluster
- * nodes_list set to ==>
- * List of live nodes
- *
*/
-errcode_t ocfs2_check_heartbeat(char *device, int *mount_flags,
- struct list_head *nodes_list)
-{
- errcode_t ret = 0;
- struct list_head dev_list;
- struct list_head *pos1, *pos2, *pos3, *pos4;
- ocfs2_devices *dev;
- ocfs2_nodes *node;
-
- INIT_LIST_HEAD(&dev_list);
-
- if (!device)
- goto bail;
-
- ret = ocfs2_malloc0(sizeof(ocfs2_devices), &dev);
- if (ret)
- goto bail;
- strncpy(dev->dev_name, device, sizeof(dev->dev_name));
- dev->mount_flags = 0;
- INIT_LIST_HEAD(&(dev->node_list));
- list_add(&(dev->list), &dev_list);
-
- ret = ocfs2_check_heartbeats(&dev_list);
- if (ret)
- goto bail;
-
- list_for_each_safe(pos1, pos2, &(dev_list)) {
- dev = list_entry(pos1, ocfs2_devices, list);
- *mount_flags = dev->mount_flags;
- list_for_each_safe(pos3, pos4, &(dev->node_list)) {
- node = list_entry(pos3, ocfs2_nodes, list);
- if (nodes_list) {
- list_add_tail(&node->list, nodes_list);
- } else {
- list_del(&(node->list));
- ocfs2_free(&node);
- }
- }
- list_del(&(dev->list));
- ocfs2_free(&dev);
- break;
- }
-
-bail:
- if (ret) {
- list_for_each_safe(pos1, pos2, &(dev_list)) {
- dev = list_entry(pos1, ocfs2_devices, list);
- list_for_each_safe(pos3, pos4, &(dev->node_list)) {
- node = list_entry(pos3, ocfs2_nodes, list);
- list_del(&(node->list));
- ocfs2_free(&node);
- }
- list_del(&(dev->list));
- ocfs2_free(&dev);
- }
- }
- return ret;
-}
-
-/*
- * ocfs2_check_heartbeats()
- *
- */
errcode_t ocfs2_check_heartbeats(struct list_head *dev_list)
{
ocfs2_filesys *fs = NULL;
@@ -192,13 +98,6 @@
dev = list_entry(pos, ocfs2_devices, list);
device = dev->dev_name;
- INIT_LIST_HEAD(&(dev->node_list));
-
- /* is it locally mounted */
- ret = ocfs2_check_mount_point(device, &dev->mount_flags, NULL, 0);
- if (ret)
- goto bail;
-
/* open fs */
fs = NULL;
ret = ocfs2_open(device, OCFS2_FLAG_RO, 0, 0, &fs);
@@ -208,31 +107,32 @@
} else
dev->fs_type = 2;
- /* get label/uuid for ocfs and ocfs2 */
- if (dev->fs_type == 2) {
- num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
- memcpy(dev->label, OCFS2_RAW_SB(fs->fs_super)->s_label,
- sizeof(dev->label));
- memcpy(dev->uuid, OCFS2_RAW_SB(fs->fs_super)->s_uuid,
- sizeof(dev->uuid));
- } else {
- num_nodes = 32;
- if (ocfs2_get_ocfs1_label(dev->dev_name,
- dev->label, sizeof(dev->label),
- dev->uuid, sizeof(dev->uuid))) {
- dev->label[0] = '\0';
- memset(dev->uuid, 0, sizeof(dev->uuid));
- }
- continue;
- }
+ /* is it locally mounted */
+ ret = ocfs2_check_mount_point(device, &dev->mount_flags, NULL, 0);
+ if (ret)
+ goto bail;
+ /* get label/uuid for ocfs2 */
+ num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
+ memcpy(dev->label, OCFS2_RAW_SB(fs->fs_super)->s_label,
+ sizeof(dev->label));
+ memcpy(dev->uuid, OCFS2_RAW_SB(fs->fs_super)->s_uuid,
+ sizeof(dev->uuid));
+
+ ret = ocfs2_malloc((sizeof(uint8_t) * num_nodes), &dev->node_nums);
+ if (ret)
+ goto bail;
+
+ memset(dev->node_nums, OCFS2_MAX_NODES,
+ (sizeof(uint8_t) * num_nodes));
+
/* read slotmap to get nodes on which the volume is mounted */
- ret = ocfs2_read_slotmap(fs, &dev->node_list);
+ ret = ocfs2_read_slotmap(fs, dev->node_nums);
if (ret) {
dev->errcode = ret;
ret = 0;
} else {
- if (!list_empty(&(dev->node_list)))
+ if (dev->node_nums[0] != OCFS2_MAX_NODES)
dev->mount_flags |= OCFS2_MF_MOUNTED_CLUSTER;
}
ocfs2_close(fs);
Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h 2005-03-31 02:26:54 UTC (rev 776)
+++ trunk/libocfs2/include/ocfs2.h 2005-04-01 23:15:08 UTC (rev 777)
@@ -210,15 +210,6 @@
ocfs2_bitmap *ci_chains;
};
-/* FIXME: this is totally bogus now. Userspace needs to change
- * its heartbeat checking */
-#define MAX_NODE_NAME_LENGTH 32
-struct _ocfs2_nodes {
- struct list_head list;
- char node_name[MAX_NODE_NAME_LENGTH+1];
- uint16_t node_num;
-};
-
struct _ocfs2_devices {
struct list_head list;
char dev_name[100];
@@ -230,7 +221,7 @@
uint32_t min_num; /* minor number of the device */
errcode_t errcode; /* error encountered reading device */
void *private;
- struct list_head node_list;
+ uint8_t *node_nums;
};
errcode_t ocfs2_malloc(unsigned long size, void *ptr);
Modified: trunk/mount.ocfs2/Cscope.make
===================================================================
--- trunk/mount.ocfs2/Cscope.make 2005-03-31 02:26:54 UTC (rev 776)
+++ trunk/mount.ocfs2/Cscope.make 2005-04-01 23:15:08 UTC (rev 777)
@@ -7,4 +7,8 @@
find . -maxdepth 2 -name '*.h' -print >>cscope.files
find ../libocfs2/ -maxdepth 2 -name '*.c' -print >>cscope.files
find ../libocfs2/ -maxdepth 2 -name '*.h' -print >>cscope.files
+ find ../libo2cb/ -maxdepth 2 -name '*.c' -print >>cscope.files
+ find ../libo2cb/ -maxdepth 2 -name '*.h' -print >>cscope.files
+ find ../libo2dlm/ -maxdepth 2 -name '*.c' -print >>cscope.files
+ find ../libo2dlm/ -maxdepth 2 -name '*.h' -print >>cscope.files
cscope -b
Modified: trunk/mounted.ocfs2/Cscope.make
===================================================================
--- trunk/mounted.ocfs2/Cscope.make 2005-03-31 02:26:54 UTC (rev 776)
+++ trunk/mounted.ocfs2/Cscope.make 2005-04-01 23:15:08 UTC (rev 777)
@@ -7,4 +7,6 @@
find . -maxdepth 2 -name '*.h' -print >>cscope.files
find ../libocfs2/ -maxdepth 2 -name '*.c' -print >>cscope.files
find ../libocfs2/ -maxdepth 2 -name '*.h' -print >>cscope.files
+ find ../libo2cb/ -maxdepth 2 -name '*.c' -print >>cscope.files
+ find ../libo2cb/ -maxdepth 2 -name '*.h' -print >>cscope.files
cscope -b
Modified: trunk/mounted.ocfs2/mounted.c
===================================================================
--- trunk/mounted.ocfs2/mounted.c 2005-03-31 02:26:54 UTC (rev 776)
+++ trunk/mounted.ocfs2/mounted.c 2005-04-01 23:15:08 UTC (rev 777)
@@ -2,9 +2,8 @@
* mounted.c
*
* ocfs2 mount detect utility
- * Detects both ocfs and ocfs2 volumes
*
- * Copyright (C) 2004 Oracle. All rights reserved.
+ * Copyright (C) 2004, 2005 Oracle. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -21,7 +20,6 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 021110-1307, USA.
*
- * Authors: Sunil Mushran
*/
#define _LARGEFILE64_SOURCE
@@ -50,19 +48,20 @@
" -d quick detect\n"
" -f full detect\n";
-static void ocfs2_print_nodes(struct list_head *node_list)
+static void ocfs2_print_nodes(uint8_t *nums, char **names)
{
- ocfs2_nodes *node;
- struct list_head *pos;
- int begin = 1;
+ int i = 0;
+ uint8_t n;
- list_for_each(pos, node_list) {
- node = list_entry(pos, ocfs2_nodes, list);
- if (begin) {
- printf("%d", node->node_num);
- begin = 0;
- } else
- printf(", %d", node->node_num);
+ while (nums[i] != OCFS2_MAX_NODES) {
+ if (i)
+ printf(", ");
+ n = nums[i];
+ if (names && names[n] && *(names[n]))
+ printf("%s", names[n]);
+ else
+ printf("%d", n);
+ ++i;
}
return ;
@@ -73,28 +72,59 @@
{
ocfs2_devices *dev;
struct list_head *pos;
+ char **node_names = NULL;
+ char **cluster_names = NULL;
+ char *nodes[OCFS2_MAX_NODES];
+ char value[10];
+ int i = 0;
+ uint16_t num;
+ memset(nodes, 0, sizeof(nodes));
+
+ o2cb_list_clusters(&cluster_names);
+
+ if (cluster_names && *cluster_names) {
+ o2cb_list_nodes(*cluster_names, &node_names);
+
+ /* sort the names according to the node number */
+ while(node_names && node_names[i] && *(node_names[i])) {
+ if (o2cb_get_node_num(*cluster_names, node_names[i],
+ &num))
+ break;
+ if (num >= OCFS2_MAX_NODES)
+ break;
+ nodes[num] = node_names[i];
+ ++i;
+ }
+ }
+
printf("%-20s %-5s %s\n", "Device", "FS", "Nodes");
list_for_each(pos, dev_list) {
dev = list_entry(pos, ocfs2_devices, list);
if (dev->fs_type == 0)
continue;
- printf("%-20s %-5s ", dev->dev_name,
- (dev->fs_type == 2 ? "ocfs2" : "ocfs"));
+ printf("%-20s %-5s ", dev->dev_name, "ocfs2");
if (dev->errcode) {
fflush(stdout);
com_err("Unknown", dev->errcode, " ");
} else {
- if (list_empty(&(dev->node_list))) {
+ if (dev->node_nums[0] == OCFS2_MAX_NODES) {
printf("Not mounted\n");
continue;
}
- ocfs2_print_nodes(&(dev->node_list));
+ ocfs2_print_nodes(dev->node_nums, nodes);
printf("\n");
}
}
+
+ if (node_names)
+ o2cb_free_nodes_list(node_names);
+
+ if (cluster_names)
+ o2cb_free_cluster_list(cluster_names);
+
return ;
}
@@ -210,8 +240,7 @@
{
errcode_t ret = 0;
struct list_head dev_list;
- struct list_head *pos1, *pos2, *pos3, *pos4;
- ocfs2_nodes *node;
+ struct list_head *pos1, *pos2;
ocfs2_devices *dev;
INIT_LIST_HEAD(&(dev_list));
@@ -244,11 +273,8 @@
bail:
list_for_each_safe(pos1, pos2, &(dev_list)) {
dev = list_entry(pos1, ocfs2_devices, list);
- list_for_each_safe(pos3, pos4, &(dev->node_list)) {
- node = list_entry(pos3, ocfs2_nodes, list);
- list_del(&(node->list));
- ocfs2_free(&node);
- }
+ if (dev->node_nums)
+ ocfs2_free(&dev->node_nums);
list_del(&(dev->list));
ocfs2_free(&dev);
}
Property changes on: trunk/o2cb_ctl
___________________________________________________________________
Name: svn:ignore
- .*.sw?
*.d
clusterbo
o2cb_ctl
o2cb_ctl.8
+ .*.sw?
*.d
clusterbo
o2cb_ctl
o2cb_ctl.8
cscope.*
Added: trunk/o2cb_ctl/Cscope.make
===================================================================
--- trunk/o2cb_ctl/Cscope.make 2005-03-31 02:26:54 UTC (rev 776)
+++ trunk/o2cb_ctl/Cscope.make 2005-04-01 23:15:08 UTC (rev 777)
@@ -0,0 +1,14 @@
+.PHONY: cscope
+cscope:
+ rm -f cscope.*
+ echo "-k" >> cscope.files
+ echo "-I inc" >> cscope.files
+ find . -maxdepth 2 -name '*.c' -print >>cscope.files
+ find . -maxdepth 2 -name '*.h' -print >>cscope.files
+ find ../libocfs2/ -maxdepth 2 -name '*.c' -print >>cscope.files
+ find ../libocfs2/ -maxdepth 2 -name '*.h' -print >>cscope.files
+ find ../libo2cb/ -maxdepth 2 -name '*.c' -print >>cscope.files
+ find ../libo2cb/ -maxdepth 2 -name '*.h' -print >>cscope.files
+ find ../libo2dlm/ -maxdepth 2 -name '*.c' -print >>cscope.files
+ find ../libo2dlm/ -maxdepth 2 -name '*.h' -print >>cscope.files
+ cscope -b
More information about the Ocfs2-tools-commits
mailing list