[Ocfs2-tools-commits] smushran commits r638 - in trunk: .
debugfs.ocfs2 extras fsck.ocfs2 libo2dlm libo2dlm/include
libocfs2 libocfs2/include listuuid mkfs.ocfs2 mount.ocfs2
mounted.ocfs2 ocfs2console/ocfs2interface sizetest tunefs.ocfs2
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Mon Mar 7 19:02:40 CST 2005
Author: smushran
Signed-off-by: mfasheh
Date: 2005-03-07 19:02:38 -0600 (Mon, 07 Mar 2005)
New Revision: 638
Added:
trunk/libo2dlm/Cscope.make
trunk/libocfs2/dlm.c
Modified:
trunk/Makefile
trunk/debugfs.ocfs2/Makefile
trunk/extras/Makefile
trunk/fsck.ocfs2/Makefile
trunk/libo2dlm/
trunk/libo2dlm/include/
trunk/libocfs2/Cscope.make
trunk/libocfs2/Makefile
trunk/libocfs2/checkhb.c
trunk/libocfs2/include/dlm.h
trunk/libocfs2/include/ocfs2.h
trunk/listuuid/Makefile
trunk/mkfs.ocfs2/Makefile
trunk/mount.ocfs2/Makefile
trunk/mounted.ocfs2/Makefile
trunk/mounted.ocfs2/mounted.c
trunk/ocfs2console/ocfs2interface/
trunk/ocfs2console/ocfs2interface/Makefile
trunk/sizetest/Makefile
trunk/tunefs.ocfs2/Makefile
Log:
libocfs depends on libo2dlm
updated all makefiles to reflect the change
user space cluster locking api implmented
ocfs2_check_heartbeats made aware of new hb scheme though the logic is still a work in progress
mounted uses the updated ocfs2_check_heartbeats
Signed-off-by: mfasheh
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -24,7 +24,7 @@
$(error could not detect architecture for tools)
endif
-SUBDIRS = libocfs2 libo2cb libo2dlm fsck.ocfs2 mkfs.ocfs2 mounted.ocfs2 tunefs.ocfs2 debugfs.ocfs2 clusterbo mount.ocfs2 listuuid sizetest extras patches
+SUBDIRS = libo2dlm libocfs2 libo2cb fsck.ocfs2 mkfs.ocfs2 mounted.ocfs2 tunefs.ocfs2 debugfs.ocfs2 clusterbo mount.ocfs2 listuuid sizetest extras patches
ifdef BUILD_OCFS2CDSL
SUBDIRS += ocfs2cdsl
Modified: trunk/debugfs.ocfs2/Makefile
===================================================================
--- trunk/debugfs.ocfs2/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/debugfs.ocfs2/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -5,9 +5,9 @@
SBIN_PROGRAMS = debugfs.ocfs2
DEFINES = -DG_DISABLE_DEPRECATED -DLINUX -DDEBUGOCFS -DDEBUG
-DEFINES += -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
+DEFINES += -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\" -DO2DLM_FLAT_INCLUDES
-INCLUDES = -Iinclude -I$(TOPDIR)/libocfs2/include
+INCLUDES = -Iinclude -I$(TOPDIR)/libocfs2/include -I$(TOPDIR)/libo2dlm/include
INCLUDES += $(GLIB_CFLAGS)
ifdef OCFS_DEBUG
Modified: trunk/extras/Makefile
===================================================================
--- trunk/extras/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/extras/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -13,11 +13,11 @@
UNINST_PROGRAMS = find_hardlinks find_dup_extents find_inode_paths set_random_bits
-INCLUDES = -I../libocfs2/include
+INCLUDES = -I../libocfs2/include -I$(TOPDIR)/libo2dlm/include
OPTIMIZE = -O2
-DEFINES += -DOCFS2_FLAT_INCLUDES
+DEFINES += -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES
CFLAGS += $(OPTIMIZE)
Modified: trunk/fsck.ocfs2/Makefile
===================================================================
--- trunk/fsck.ocfs2/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/fsck.ocfs2/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -4,7 +4,7 @@
SBIN_PROGRAMS = fsck.ocfs2
-INCLUDES = -Iinclude -I$(TOPDIR)/libocfs2/include
+INCLUDES = -Iinclude -I$(TOPDIR)/libocfs2/include -I$(TOPDIR)/libo2dlm/include
LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
@@ -17,7 +17,7 @@
CFLAGS := $(OPTS) -Wall -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations
-DEFINES = -DOCFS2_FLAT_INCLUDES
+DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES
CFILES = fsck.c \
dirblocks.c \
Property changes on: trunk/libo2dlm
___________________________________________________________________
Name: svn:ignore
+ cscope.*
o2dlm_err.et
libo2dlm.a
o2dlm_err.*
*.d
Added: trunk/libo2dlm/Cscope.make
===================================================================
--- trunk/libo2dlm/Cscope.make 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/libo2dlm/Cscope.make 2005-03-08 01:02:38 UTC (rev 638)
@@ -0,0 +1,10 @@
+.PHONY: cscope
+cscope:
+ rm -f cscope.*
+ echo "-k" >> cscope.files
+ echo "-I inc" >> cscope.files
+ find . -name '*.c' -print >>cscope.files
+ find . -name '*.h' -print >>cscope.files
+ find ../libocfs2/ -name '*.h' -print >>cscope.files
+ find ../libocfs2/ -name '*.c' -print >>cscope.files
+ cscope -b
Property changes on: trunk/libo2dlm/include
___________________________________________________________________
Name: svn:ignore
+ o2dlm_err.*
Modified: trunk/libocfs2/Cscope.make
===================================================================
--- trunk/libocfs2/Cscope.make 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/libocfs2/Cscope.make 2005-03-08 01:02:38 UTC (rev 638)
@@ -5,4 +5,6 @@
echo "-I include" >> cscope.files
find . -maxdepth 2 -name '*.c' -print >>cscope.files
find . -maxdepth 2 -name '*.h' -print >>cscope.files
+ find ../libo2dlm -name '*.c' >>cscope.files
+ find ../libo2dlm -name '*.h' >>cscope.files
cscope -b
Modified: trunk/libocfs2/Makefile
===================================================================
--- trunk/libocfs2/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/libocfs2/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -11,12 +11,15 @@
OPTS += -O2
endif
-INCLUDES = -Iinclude
+INCLUDES = -Iinclude -I$(TOPDIR)/libo2dlm/include
LIBRARIES = libocfs2.a
+LIBO2DLM_LIBS = -L$(TOPDIR)/libo2dlm -lo2dlm
+LIBO2DLM_DEPS = $(TOPDIR)/libo2dlm/libo2dlm.a
+
CFLAGS = $(OPTS) $(WARNINGS) -fPIC
-CPPFLAGS += -DOCFS2_FLAT_INCLUDES
+CPPFLAGS += -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES
ifneq ($(OCFS2_DEBUG_EXE),)
DEBUG_EXE_FILES = $(shell awk '/DEBUG_EXE/{if (k[FILENAME] == 0) {print FILENAME; k[FILENAME] = 1;}}' $(CFILES))
@@ -31,8 +34,8 @@
$(INCLUDES) $(DEFINES) \
-DDEBUG_EXE -o $@ -c $<
-debug_%: debug_%.o libocfs2.a
- $(LINK) $(COM_ERR_LIBS)
+debug_%: debug_%.o libocfs2.a $(LIBO2DLM_DEPS)
+ $(LINK) $(COM_ERR_LIBS) $(LIBO2DLM_LIBS)
endif
@@ -68,7 +71,8 @@
newdir.c \
extend_file.c \
namei.c \
- truncate.c
+ truncate.c \
+ dlm.c
HFILES = \
include/jfs_user.h \
@@ -102,7 +106,7 @@
ocfs2_err.c ocfs2_err.h: ocfs2_err.et
compile_et ocfs2_err.et
-libocfs2.a: $(OBJS)
+libocfs2.a: $(OBJS) $(LIBO2DLM_DEPS)
rm -f $@
$(AR) r $@ $^
$(RANLIB) $@
Modified: trunk/libocfs2/checkhb.c
===================================================================
--- trunk/libocfs2/checkhb.c 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/libocfs2/checkhb.c 2005-03-08 01:02:38 UTC (rev 638)
@@ -34,32 +34,64 @@
#include <linux/fd.h>
#include <string.h>
#include <sys/stat.h>
+#include <signal.h>
#include "ocfs2.h"
#include "ocfs2_fs.h"
#include "ocfs1_fs_compat.h"
-#warning checkbh DOES NOT WORK. It needs a rewrite.
-#if 0
+#define FATAL_ERROR(fmt, arg...) \
+ ({ fprintf(stderr, "ERROR at %s, %d: " fmt ". EXITING!!!\n", \
+ __FILE__, __LINE__, ##arg); \
+ raise (SIGTERM); \
+ exit(1); \
+ })
-typedef struct _ocfs2_fs {
- ocfs2_filesys *fs;
- char *dev_name;
- uint64_t hb_blkno;
- uint64_t *pub_times;
- int *live_node;
- struct list_head list;
-} ocfs2_fs;
+static void ocfs2_fill_nodes_list (char *buf, uint32_t len, struct list_head *node_list)
+{
+ 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 ;
+}
-void ocfs2_detect_live_nodes (ocfs2_fs *fs_blk, char *pub_buf, int first_time);
+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;
-errcode_t ocfs2_gather_times_v2(ocfs2_fs *fs_blk, struct list_head *node_list,
- int first_time);
+ slotmap_len = strlen(slotmap);
-errcode_t ocfs2_gather_times_v1(ocfs2_fs *fs_blk, struct list_head *node_list,
- int first_time);
+ ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, slotmap, slotmap_len,
+ NULL, &slotmap_blkno);
+ if (ret)
+ return ret;
+ 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);
+ }
+
+ return ret;
+}
+
/*
* ocfs2_check_heartbeat() check if the device is mounted on the
* cluster or not
@@ -84,15 +116,9 @@
* List of live nodes
*
*/
-#endif /* 0 */
-errcode_t ocfs2_check_heartbeat(char *device, int quick_detect,
- int *mount_flags, struct list_head *nodes_list,
- ocfs2_chb_notify notify, void *user_data)
+errcode_t ocfs2_check_heartbeat(char *device, int *mount_flags,
+ struct list_head *nodes_list)
{
- return OCFS2_ET_INTERNAL_FAILURE;
-}
-#if 0
-{
errcode_t ret = 0;
struct list_head dev_list;
struct list_head *pos1, *pos2, *pos3, *pos4;
@@ -112,7 +138,7 @@
INIT_LIST_HEAD(&(dev->node_list));
list_add(&(dev->list), &dev_list);
- ret = ocfs2_check_heartbeats(&dev_list, quick_detect, notify, user_data);
+ ret = ocfs2_check_heartbeats(&dev_list);
if (ret)
goto bail;
@@ -153,27 +179,15 @@
* ocfs2_check_heartbeats()
*
*/
-#endif /* 0 */
-errcode_t ocfs2_check_heartbeats(struct list_head *dev_list, int quick_detect,
- ocfs2_chb_notify notify, void *user_data)
+errcode_t ocfs2_check_heartbeats(struct list_head *dev_list)
{
- return OCFS2_ET_INTERNAL_FAILURE;
-}
-#if 0
-{
ocfs2_filesys *fs = NULL;
errcode_t ret = 0;
uint16_t num_nodes;
- int i;
struct list_head *pos;
ocfs2_devices *dev = NULL;
char *device= NULL;
- ocfs2_fs *fs_blk = NULL;
- int any_ocfs = 0;
- if (notify && !quick_detect)
- notify(OCFS2_CHB_START, "Checking heart beat on volume ", user_data);
-
list_for_each(pos, dev_list) {
dev = list_entry(pos, ocfs2_devices, list);
device = dev->dev_name;
@@ -189,17 +203,11 @@
fs = NULL;
ret = ocfs2_open(device, OCFS2_FLAG_RO, 0, 0, &fs);
if (ret) {
- if (ret == OCFS2_ET_OCFS_REV)
- dev->fs_type = 1;
- else {
- ret = 0;
- continue;
- }
+ ret = 0;
+ continue;
} else
dev->fs_type = 2;
- ret = 0;
-
/* get label/uuid for ocfs and ocfs2 */
if (dev->fs_type == 2) {
num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
@@ -215,279 +223,26 @@
dev->label[0] = '\0';
memset(dev->uuid, 0, sizeof(dev->uuid));
}
- }
-
- if (!quick_detect) {
- ret = ocfs2_malloc0(sizeof(ocfs2_fs), &fs_blk);
- if (ret)
- goto bail;
-
- ret = ocfs2_malloc0((num_nodes * sizeof(uint64_t)), &fs_blk->pub_times);
- if (ret)
- goto bail;
-
- ret = ocfs2_malloc0((num_nodes * sizeof(int)), &fs_blk->live_node);
- if (ret)
- goto bail;
-
- fs_blk->fs = fs;
- fs_blk->dev_name = dev->dev_name;
-
- dev->private = (void *)fs_blk;
-
- if (dev->fs_type == 2)
- ret = ocfs2_gather_times_v2(fs_blk, NULL, 1);
- else
- ret = ocfs2_gather_times_v1(fs_blk, NULL, 1);
- if (ret)
- goto bail;
- }
-
- any_ocfs = 1;
- }
-
- if (quick_detect)
- goto bail;
-
- if (!any_ocfs)
- goto bail;
-
- /* wait */
- for (i = 0; i < OCFS2_HBT_WAIT; ++i) {
- if (notify)
- notify(OCFS2_CHB_WAITING, ".", user_data);
- sleep(1);
- }
-
- list_for_each(pos, dev_list) {
- dev = list_entry(pos, ocfs2_devices, list);
-
- if (dev->fs_type < 1)
continue;
-
- fs_blk = (ocfs2_fs *) dev->private;
- fs = fs_blk->fs;
-
- if (dev->fs_type == 2) {
- num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
- ret = ocfs2_gather_times_v2(fs_blk, &dev->node_list, 0);
- } else {
- num_nodes = 32;
- ret = ocfs2_gather_times_v1(fs_blk, &dev->node_list, 0);
}
- if (ret)
- goto bail;
- /* fill mount_flags */
- for (i = 0; i < num_nodes; ++i) {
- if (fs_blk->live_node[i]) {
+ /* read slotmap to get nodes on which the volume is mounted */
+ ret = ocfs2_read_slotmap(fs, &dev->node_list);
+ if (ret) {
+ dev->errcode = ret;
+ ret = 0;
+ } else {
+ if (!list_empty(&(dev->node_list)))
dev->mount_flags |= OCFS2_MF_MOUNTED_CLUSTER;
- break;
- }
}
+ ocfs2_close(fs);
}
- if (notify)
- notify(OCFS2_CHB_COMPLETE,
- "\r \r",
- user_data);
-
bail:
- list_for_each(pos, dev_list) {
- dev = list_entry(pos, ocfs2_devices, list);
- if (dev->private) {
- fs_blk = (ocfs2_fs *) dev->private;
- if (fs_blk->fs)
- ocfs2_close(fs_blk->fs);
- ocfs2_free(&fs_blk->pub_times);
- ocfs2_free(&fs_blk->live_node);
- ocfs2_free(&fs_blk);
- dev->private = NULL;
- }
- }
-
return ret;
}
/*
- * ocfs2_detect_live_nodes()
- *
- */
-void ocfs2_detect_live_nodes (ocfs2_fs *fs_blk, char *pub_buf, int first_time)
-{
- char *p;
- ocfs_publish *publish;
- int i;
- uint16_t num_nodes;
- uint32_t blksz_bits;
- uint64_t *pub_times = fs_blk->pub_times;
- int *live_node = fs_blk->live_node;
-
- if (fs_blk->fs) {
- num_nodes = OCFS2_RAW_SB(fs_blk->fs->fs_super)->s_max_nodes;
- blksz_bits = OCFS2_RAW_SB(fs_blk->fs->fs_super)->s_blocksize_bits;
- } else {
- num_nodes = 32;
- blksz_bits = 9;
- }
-
- if (first_time) {
- p = (char *)pub_buf;
- for (i = 0; i < num_nodes; i++) {
- publish = (ocfs_publish *) p;
- pub_times[i] = publish->time;
- p += (1 << blksz_bits);
- }
- goto bail; /* exit */
- }
-
- p = (char *)pub_buf;
- for (i = 0; i < num_nodes; i++) {
- publish = (ocfs_publish *) p;
- if (pub_times[i] != publish->time) {
- pub_times[i] = publish->time;
- live_node[i] = 1;
- }
- p += (1 << blksz_bits);
- }
-
-bail:
- return ;
-}
-
-/*
- * ocfs2_gather_times_v2()
- *
- */
-errcode_t ocfs2_gather_times_v2(ocfs2_fs *fs_blk, struct list_head *node_list,
- int first_time)
-{
- ocfs2_filesys *fs = fs_blk->fs;
- char *hb = ocfs2_system_inodes[HEARTBEAT_SYSTEM_INODE].si_name;
- char *buf = NULL;
- int buflen = 0;
- errcode_t ret = 0;
- char *p;
- uint16_t num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
- uint32_t blksz_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
- ocfs_node_config_info *node;
- ocfs2_nodes *node_blk;
- int i;
-
- /* get the hb blkno */
- if (!fs_blk->hb_blkno) {
- ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, hb, strlen(hb),
- NULL, &(fs_blk->hb_blkno));
- if (ret)
- goto bail;
- }
-
- /* read hb file */
- ret = ocfs2_read_whole_file(fs, fs_blk->hb_blkno, &buf, &buflen);
- if (ret)
- goto bail;
-
- /* process publish times */
- p = buf + ((2 + 4 + num_nodes) << blksz_bits); /* start of publish */
- ocfs2_detect_live_nodes (fs_blk, p, first_time);
-
- /* fill node_names */
- if (!first_time && node_list) {
- p = buf + (2 << blksz_bits); /* start of node cfg */
- for (i = 0; i < num_nodes; ++i) {
- if (fs_blk->live_node[i]) {
- node = (ocfs_node_config_info *)p;
- ret = ocfs2_malloc0(sizeof(ocfs2_nodes), &node_blk);
- if (ret)
- goto bail;
- strncpy(node_blk->node_name, node->node_name,
- sizeof(node_blk->node_name));
- node_blk->node_num = i;
- list_add_tail(&(node_blk->list), node_list);
- }
- p += (1 << blksz_bits);
- }
- }
-
-bail:
- if (buflen && buf)
- ocfs2_free (&buf);
-
- return ret;
-}
-
-/*
- * ocfs2_gather_times_v1()
- *
- */
-errcode_t ocfs2_gather_times_v1(ocfs2_fs *fs_blk, struct list_head *node_list,
- int first_time)
-{
- int fd = -1;
- char *buf = NULL;
- int buflen = 0;
- errcode_t ret = 0;
- char *p;
- uint16_t num_nodes = 32; /* v1 numnodes */
- uint32_t blksz_bits = 9; /* v1 blksz is fixed at 512 bytes */
- ocfs1_disk_node_config_info *node;
- ocfs2_nodes *node_blk;
- int i;
-
- /* open device */
- fd = open(fs_blk->dev_name, O_RDONLY);
- if (fd == -1)
- goto bail;
-
- buflen = 2; /* node cfg hdr */
- buflen += num_nodes; /* node cfgs */
- buflen += 4; /* node cfg trailer */
- buflen += num_nodes; /* publish */
- buflen <<= blksz_bits; /* convert to bytes */
-
- /* alloc mem to read cfg+publish */
- ret = ocfs2_malloc0(buflen, &buf);
- if (ret)
- goto bail;
-
- /* read cfg+publish */
- if (pread(fd, buf, buflen, 4096) == -1)
- goto bail;
-
- /* process publish times */
- p = buf + ((2 + num_nodes + 4) << blksz_bits); /* start of publish */
- ocfs2_detect_live_nodes (fs_blk, p, first_time);
-
- /* fill node_names */
- if (!first_time && node_list) {
- p = buf + (2 << blksz_bits); /* start of node cfg */
- for (i = 0; i < num_nodes; ++i) {
- if (fs_blk->live_node[i]) {
- node = (ocfs1_disk_node_config_info *)p;
- ret = ocfs2_malloc0(sizeof(ocfs2_nodes), &node_blk);
- if (ret)
- goto bail;
- strncpy(node_blk->node_name, node->node_name,
- sizeof(node_blk->node_name));
- node_blk->node_num = i;
- list_add_tail(&(node_blk->list), node_list);
- }
- p += (1 << blksz_bits);
- }
- }
-
-bail:
- if (buf)
- ocfs2_free (&buf);
-
- if (fd != -1)
- close(fd);
-
- return ret;
-}
-#endif /* 0 */
-
-/*
* ocfs2_get_ocfs1_label()
*
*/
Added: trunk/libocfs2/dlm.c
===================================================================
--- trunk/libocfs2/dlm.c 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/libocfs2/dlm.c 2005-03-08 01:02:38 UTC (rev 638)
@@ -0,0 +1,309 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * dlm.c
+ *
+ * Interface the OCFS2 userspace library to the userspace DLM library
+ *
+ * Copyright (C) 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
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#define _XOPEN_SOURCE 600 /* Triggers magic in features.h */
+#define _LARGEFILE64_SOURCE
+
+#define __USE_MISC
+#include <string.h>
+#include <inttypes.h>
+
+#include "ocfs2.h"
+
+#define DEFAULT_DLMFS_PATH "/dev/ocfs2/dlm/"
+#define OCFS2_LOCK_ID_MAX_LEN 32
+#define OCFS2_LOCK_ID_PAD "000000"
+
+enum ocfs2_lock_type {
+ OCFS_TYPE_META = 0,
+ OCFS_TYPE_DATA,
+ OCFS_TYPE_SUPER,
+ OCFS_NUM_LOCK_TYPES
+};
+
+static char ocfs2_lock_type_char[OCFS_NUM_LOCK_TYPES] = {
+ [OCFS_TYPE_META] 'M',
+ [OCFS_TYPE_DATA] 'D',
+ [OCFS_TYPE_SUPER] 'S'
+};
+
+static void ocfs2_build_lock_name(ocfs2_filesys *fs, enum ocfs2_lock_type type,
+ uint64_t blkno, uint32_t generation,
+ char *lock_name)
+{
+ snprintf(lock_name, OCFS2_LOCK_ID_MAX_LEN, "%c%s%016llx%08x",
+ ocfs2_lock_type_char[type], OCFS2_LOCK_ID_PAD,
+ blkno, generation);
+
+ return ;
+}
+
+static errcode_t ocfs2_get_journal_blkno(ocfs2_filesys *fs, uint64_t *jrnl_blkno)
+{
+ ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
+ char sysfile[OCFS2_MAX_FILENAME_LENGTH];
+ int i;
+ errcode_t ret = 0;
+
+ for (i = 0; i < sb->s_max_nodes; ++i) {
+ snprintf (sysfile, sizeof(sysfile),
+ ocfs2_system_inodes[JOURNAL_SYSTEM_INODE].si_name, i);
+ ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, sysfile,
+ strlen(sysfile), NULL, &(jrnl_blkno[i]));
+ if (ret)
+ goto bail;
+ }
+
+bail:
+ return ret;
+}
+
+errcode_t ocfs2_lock_down_cluster(ocfs2_filesys *fs)
+{
+ ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
+ uint64_t jrnl_blkno[OCFS2_MAX_NODES];
+ ocfs2_cached_inode *ci;
+ errcode_t ret = 0;
+ int i;
+
+ ret = ocfs2_get_journal_blkno(fs, jrnl_blkno);
+ if (ret)
+ goto bail;
+
+ ret = ocfs2_super_lock(fs);
+ if (ret)
+ goto bail;
+
+ for (i = 0; i < sb->s_max_nodes; ++i) {
+ ret = ocfs2_read_cached_inode(fs, jrnl_blkno[i], &ci);
+ if (ret) {
+ ocfs2_super_unlock(fs);
+ goto bail;
+ }
+
+ ret = ocfs2_meta_lock(fs, ci, O2DLM_LEVEL_EXMODE, O2DLM_TRYLOCK);
+ if (ret) {
+ ocfs2_super_unlock(fs);
+ ocfs2_free_cached_inode(fs, ci);
+ goto bail;
+ }
+
+ ocfs2_meta_unlock(fs, ci);
+
+ ocfs2_free_cached_inode(fs, ci);
+ }
+
+bail:
+ return ret;
+}
+
+errcode_t ocfs2_release_cluster(ocfs2_filesys *fs)
+{
+ errcode_t ret = 0;
+
+ ret = ocfs2_super_unlock(fs);
+ if (ret)
+ goto bail;
+
+bail:
+ return ret;
+}
+
+errcode_t ocfs2_initialize_dlm(ocfs2_filesys *fs)
+{
+ struct o2dlm_ctxt *dlm_ctxt = NULL;
+ ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
+ errcode_t ret = 0;
+ char uuid[34];
+ char *p;
+ int i;
+
+ memset(uuid, 0, sizeof(uuid));
+ for (i = 0, p = uuid; i < 16; ++i, p += 2)
+ sprintf(p, "%02X", sb->s_uuid[i]);
+
+ ret = o2dlm_initialize(DEFAULT_DLMFS_PATH, uuid, &dlm_ctxt);
+ if (ret)
+ goto bail;
+
+ fs->fs_dlm_ctxt = dlm_ctxt;
+
+bail:
+ return ret;
+}
+
+errcode_t ocfs2_shutdown_dlm(ocfs2_filesys *fs)
+{
+ errcode_t ret;
+
+ ret = o2dlm_destroy(fs->fs_dlm_ctxt);
+ if (ret)
+ goto bail;
+
+ fs->fs_dlm_ctxt = NULL;
+
+bail:
+ return ret;
+}
+
+errcode_t ocfs2_super_lock(ocfs2_filesys *fs)
+{
+ char lock_name[OCFS2_LOCK_ID_MAX_LEN];
+ errcode_t ret;
+
+ ocfs2_build_lock_name(fs, OCFS_TYPE_SUPER, OCFS2_SUPER_BLOCK_BLKNO,
+ 0, lock_name);
+
+ ret = o2dlm_lock(fs->fs_dlm_ctxt, lock_name,
+ O2DLM_TRYLOCK, O2DLM_LEVEL_EXMODE);
+
+ return ret;
+}
+
+errcode_t ocfs2_super_unlock(ocfs2_filesys *fs)
+{
+ char lock_name[OCFS2_LOCK_ID_MAX_LEN];
+ errcode_t ret;
+
+ ocfs2_build_lock_name(fs, OCFS_TYPE_SUPER, OCFS2_SUPER_BLOCK_BLKNO,
+ 0, lock_name);
+
+ ret = o2dlm_unlock(fs->fs_dlm_ctxt, lock_name);
+
+ return ret;
+}
+
+errcode_t ocfs2_meta_lock(ocfs2_filesys *fs,
+ ocfs2_cached_inode *ci,
+ enum o2dlm_lock_level level,
+ int flags)
+{
+ char lock_name[OCFS2_LOCK_ID_MAX_LEN];
+ errcode_t ret;
+
+ ocfs2_build_lock_name(fs, OCFS_TYPE_META, ci->ci_blkno,
+ ci->ci_inode->i_generation, lock_name);
+
+ ret = o2dlm_lock(fs->fs_dlm_ctxt, lock_name, flags, level);
+
+ return ret;
+}
+
+errcode_t ocfs2_meta_unlock(ocfs2_filesys *fs,
+ ocfs2_cached_inode *ci)
+{
+ char lock_name[OCFS2_LOCK_ID_MAX_LEN];
+ errcode_t ret;
+
+ ocfs2_build_lock_name(fs, OCFS_TYPE_META, ci->ci_blkno,
+ ci->ci_inode->i_generation, lock_name);
+
+ ret = o2dlm_unlock(fs->fs_dlm_ctxt, lock_name);
+
+ return ret;
+
+}
+
+#ifdef DEBUG_EXE
+#include <getopt.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <libgen.h>
+
+static void print_usage(void)
+{
+ fprintf(stderr, "Usage: dlm <filename>\n");
+}
+
+extern int opterr, optind;
+extern char *optarg;
+
+int main(int argc, char *argv[])
+{
+ errcode_t ret;
+ int c;
+ char *filename;
+ ocfs2_filesys *fs = NULL;
+ char *progname;
+
+ initialize_ocfs_error_table();
+ initialize_o2dl_error_table();
+
+ if (argc < 2) {
+ print_usage();
+ exit(1);
+ }
+
+ filename = argv[1];
+ progname = basename(argv[0]);
+
+ ret = ocfs2_open(filename, OCFS2_FLAG_RO, 0, 0, &fs);
+ if (ret) {
+ com_err(progname, ret,
+ "while opening file \"%s\"", filename);
+ goto out;
+ }
+
+ ret = ocfs2_initialize_dlm(fs);
+ if (ret) {
+ com_err(progname, ret, "while initializing dlm");
+ goto out;
+ }
+
+ printf("DLM initialized\n");
+ ret = ocfs2_lock_down_cluster(fs);
+ if (ret) {
+ com_err(progname, ret, "while locking cluster");
+ goto out;
+ }
+
+ printf("Cluster is locked\nPress any key to continue...");
+ c = getchar();
+
+ ret = ocfs2_release_cluster(fs);
+ if (ret) {
+ com_err(progname, ret, "while releasing cluster");
+ goto out;
+ }
+
+ printf("Cluster released\n");
+
+out:
+ if (fs->fs_dlm_ctxt) {
+ ret = ocfs2_shutdown_dlm(fs);
+ if (ret)
+ com_err(progname, ret, "while shutting down dlm");
+ }
+
+ if (fs) {
+ ret = ocfs2_close(fs);
+ if (ret)
+ com_err(progname, ret,
+ "while closing file \"%s\"", filename);
+ }
+
+ return 0;
+}
+#endif /* DEBUG_EXE */
Modified: trunk/libocfs2/include/dlm.h
===================================================================
--- trunk/libocfs2/include/dlm.h 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/libocfs2/include/dlm.h 2005-03-08 01:02:38 UTC (rev 638)
@@ -27,22 +27,20 @@
#ifndef _DLM_H
#define _DLM_H
-#include "d2dlm.h"
+errcode_t ocfs2_lock_down_cluster(ocfs2_filesys *fs);
+errcode_t ocfs2_release_cluster(ocfs2_filesys *fs);
-errcode_t ocfs2_lock_down_cluster(ocfs2_filesys *sb);
-errcode_t ocfs2_release_cluster(ocfs2_filesys *sb);
+errcode_t ocfs2_initialize_dlm(ocfs2_filesys *fs);
+errcode_t ocfs2_shutdown_dlm(ocfs2_filesys *fs);
-errcode_t ocfs2_initialize_dlm(ocfs2_filesys *sb);
-errcode_t ocfs2_shutdown_dlm(ocfs2_filesys *sb);
+errcode_t ocfs2_super_lock(ocfs2_filesys *fs);
+errcode_t ocfs2_super_unlock(ocfs2_filesys *fs);
-errcode_t ocfs2_super_lock(ocfs2_filesys *sb);
-errcode_t ocfs2_super_unlock(ocfs2_filesys *sb);
-
-errcode_t ocfs2_meta_lock(ocfs2_filesys *sb,
+errcode_t ocfs2_meta_lock(ocfs2_filesys *fs,
ocfs2_cached_inode *inode,
enum o2dlm_lock_level level,
int flags);
-errcode_t ocfs2_meta_unlock(ocfs2_filesys *sb,
- ocfs2_cached_inode *inode);
+errcode_t ocfs2_meta_unlock(ocfs2_filesys *fs,
+ ocfs2_cached_inode *ci);
#endif /* _DLM_H */
Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/libocfs2/include/ocfs2.h 2005-03-08 01:02:38 UTC (rev 638)
@@ -39,6 +39,8 @@
#include <sys/stat.h>
#include <time.h>
+#include <limits.h>
+
#include <linux/types.h>
#include <et/com_err.h>
@@ -58,6 +60,8 @@
#include <ocfs2/ocfs2_fs.h>
#endif
+#include <o2dlm.h>
+
#define OCFS2_LIB_FEATURE_INCOMPAT_SUPP OCFS2_FEATURE_INCOMPAT_SUPP
#define OCFS2_LIB_FEATURE_RO_COMPAT_SUPP OCFS2_FEATURE_RO_COMPAT_SUPP
@@ -190,6 +194,8 @@
ocfs2_cached_inode **fs_eb_allocs;
ocfs2_cached_inode *fs_system_eb_alloc;
+ struct o2dlm_ctxt *fs_dlm_ctxt;
+
/* Reserved for the use of the calling application. */
void *fs_private;
};
@@ -217,9 +223,10 @@
uint8_t label[64];
uint8_t uuid[16];
int mount_flags;
- int fs_type; /* 0=unknown, 1=ocfs, 2=ocfs2 */
+ int fs_type; /* 0=unknown, 1=ocfs, 2=ocfs2 */
uint32_t maj_num; /* major number of the device */
uint32_t min_num; /* minor number of the device */
+ errcode_t errcode; /* error encountered reading device */
void *private;
struct list_head node_list;
};
@@ -428,12 +435,10 @@
errcode_t ocfs2_read_whole_file(ocfs2_filesys *fs, uint64_t blkno,
char **buf, int *len);
-errcode_t ocfs2_check_heartbeat(char *device, int quick_detect,
- int *mount_flags, struct list_head *nodes_list,
- ocfs2_chb_notify notify, void *user_data);
+errcode_t ocfs2_check_heartbeat(char *device, int *mount_flags,
+ struct list_head *nodes_list);
-errcode_t ocfs2_check_heartbeats(struct list_head *dev_list, int quick_detect,
- ocfs2_chb_notify notify, void *user_data);
+errcode_t ocfs2_check_heartbeats(struct list_head *dev_list);
errcode_t ocfs2_get_ocfs1_label(char *device, uint8_t *label, uint16_t label_len,
uint8_t *uuid, uint16_t uuid_len);
@@ -532,6 +537,23 @@
errcode_t ocfs2_file_read(ocfs2_cached_inode *ci, void *buf, uint32_t count,
uint64_t offset, uint32_t *got);
+errcode_t ocfs2_lock_down_cluster(ocfs2_filesys *fs);
+
+errcode_t ocfs2_release_cluster(ocfs2_filesys *fs);
+
+errcode_t ocfs2_initialize_dlm(ocfs2_filesys *fs);
+
+errcode_t ocfs2_shutdown_dlm(ocfs2_filesys *fs);
+
+errcode_t ocfs2_super_lock(ocfs2_filesys *fs);
+
+errcode_t ocfs2_super_unlock(ocfs2_filesys *fs);
+
+errcode_t ocfs2_meta_lock(ocfs2_filesys *fs, ocfs2_cached_inode *inode,
+ enum o2dlm_lock_level level, int flags);
+
+errcode_t ocfs2_meta_unlock(ocfs2_filesys *fs, ocfs2_cached_inode *ci);
+
/*
* ${foo}_to_${bar} is a floor function. blocks_to_clusters will
* returns the cluster that contains a block, not the number of clusters
Modified: trunk/listuuid/Makefile
===================================================================
--- trunk/listuuid/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/listuuid/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -5,10 +5,15 @@
SBIN_PROGRAMS = listuuid
INCLUDES = -Iinclude -I$(TOPDIR)/libocfs2/include \
- -I$(TOPDIR)/libocfs2cluster/include
+ -I$(TOPDIR)/libocfs2cluster/include \
+ -I$(TOPDIR)/libo2dlm/include
+
LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
+LIBO2DLM_LIBS = -L$(TOPDIR)/libo2dlm -lo2dlm
+LIBO2DLM_DEPS = $(TOPDIR)/libo2dlm/libo2dlm.a
+
ifdef OCFS_DEBUG
OPTS += -ggdb
else
@@ -18,7 +23,7 @@
CFLAGS := $(OPTS) -Wall -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations
-DEFINES = -DOCFS2_FLAT_INCLUDES
+DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES
CFILES = listuuid.c
@@ -30,7 +35,7 @@
dist-subdircreate:
$(TOPDIR)/mkinstalldirs $(DIST_DIR)/include
-listuuid: $(OBJS) $(LIBOCFS2_DEPS)
- $(LINK) $(LIBOCFS2_LIBS) $(COM_ERR_LIBS)
+listuuid: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS)
+ $(LINK) $(LIBOCFS2_LIBS) $(COM_ERR_LIBS) $(LIBO2DLM_LIBS)
include $(TOPDIR)/Postamble.make
Modified: trunk/mkfs.ocfs2/Makefile
===================================================================
--- trunk/mkfs.ocfs2/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/mkfs.ocfs2/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -19,8 +19,8 @@
LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
-INCLUDES = $(LIBOCFS2_CFLAGS) -I.
-DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
+INCLUDES = $(LIBOCFS2_CFLAGS) -I. -I$(TOPDIR)/libo2dlm/include
+DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\" -DO2DLM_FLAT_INCLUDES
CFILES = mkfs.c
OBJS = $(subst .c,.o,$(CFILES))
Modified: trunk/mount.ocfs2/Makefile
===================================================================
--- trunk/mount.ocfs2/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/mount.ocfs2/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -5,7 +5,7 @@
SBIN_PROGRAMS = mount.ocfs2
INCLUDES = -Iinclude -I$(TOPDIR)/libocfs2/include \
- -I$(TOPDIR)/libo2cb/include
+ -I$(TOPDIR)/libo2cb/include -I$(TOPDIR)/libo2dlm/include
LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
@@ -18,7 +18,7 @@
CFLAGS := $(OPTS) -Wall -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations
-DEFINES = -DOCFS2_FLAT_INCLUDES
+DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES
CFILES = mount.ocfs2.c
Modified: trunk/mounted.ocfs2/Makefile
===================================================================
--- trunk/mounted.ocfs2/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/mounted.ocfs2/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -6,28 +6,29 @@
-Wmissing-declarations
ifdef OCFS_DEBUG
-OPTS = -g
+OPTS = -O -ggdb
+else
+OPTS = -O2
endif
-CFLAGS = $(OPTS) $(WARNINGS)
+CFLAGS = $(OPTS) $(WARNINGS) -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES
LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
+LIBO2DLM_LIBS = -L$(TOPDIR)/libo2dlm -lo2dlm
+LIBO2DLM_DEPS = $(TOPDIR)/libo2dlm/libo2dlm.a
+
SBIN_PROGRAMS = mounted.ocfs2
-INCLUDES = -I$(TOPDIR)/libocfs2/include
+INCLUDES = -I$(TOPDIR)/libocfs2/include -I$(TOPDIR)/libo2dlm/include
-OPTIMIZE = -O2
-
-CFLAGS += $(OPTIMIZE)
-
CFILES = mounted.c
OBJS = $(subst .c,.o,$(CFILES))
DIST_FILES = $(CFILES)
-mounted.ocfs2: $(OBJS) $(LIBOCFS2_DEPS)
- $(LINK) $(LIBOCFS2_LIBS) $(COM_ERR_LIBS)
+mounted.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS)
+ $(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(COM_ERR_LIBS)
include $(TOPDIR)/Postamble.make
Modified: trunk/mounted.ocfs2/mounted.c
===================================================================
--- trunk/mounted.ocfs2/mounted.c 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/mounted.ocfs2/mounted.c 2005-03-08 01:02:38 UTC (rev 638)
@@ -36,7 +36,6 @@
#include <string.h>
#include <sys/stat.h>
-#define OCFS2_FLAT_INCLUDES 1
#include <ocfs2.h>
#include <ocfs2_fs.h>
#include <ocfs1_fs_compat.h>
@@ -51,99 +50,26 @@
" -d quick detect\n"
" -f full detect\n";
-errcode_t ocfs2_detect(char *device, int quick_detect);
-void ocfs2_print_quick_detect(struct list_head *dev_list);
-void ocfs2_print_full_detect(struct list_head *dev_list);
-void ocfs2_print_nodes(struct list_head *node_list);
-errcode_t ocfs2_partition_list (struct list_head *dev_list);
-int read_options(int argc, char **argv);
-void usage(char *progname);
-
-/*
- * main()
- *
- */
-int main(int argc, char **argv)
+static void ocfs2_print_nodes(struct list_head *node_list)
{
- errcode_t ret = 0;
-
- initialize_ocfs_error_table();
-
- ret = read_options(argc, argv);
- if (ret)
- goto bail;
-
- ret = ocfs2_detect(device, quick_detect);
-
-bail:
- return ret;
-}
-
-static void chb_notify(int state, char *progress, void *user_data)
-{
- fprintf(stdout, "%s", progress);
- fflush(stdout);
-}
-
-/*
- * ocfs2_detect()
- *
- */
-errcode_t ocfs2_detect(char *device, int quick_detect)
-{
- errcode_t ret = 0;
- struct list_head dev_list;
- struct list_head *pos1, *pos2, *pos3, *pos4;
ocfs2_nodes *node;
- ocfs2_devices *dev;
+ struct list_head *pos;
+ int begin = 1;
- INIT_LIST_HEAD(&(dev_list));
-
- if (device) {
- ret = ocfs2_malloc0(sizeof(ocfs2_devices), &dev);
- if (ret)
- goto bail;
- strncpy(dev->dev_name, device, sizeof(dev->dev_name));
- list_add(&(dev->list), &dev_list);
- } else {
- ret = ocfs2_partition_list(&dev_list);
- if (ret) {
- com_err(progname, ret, "while reading /proc/partitions");
- goto bail;
- }
+ 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);
}
- ret = ocfs2_check_heartbeats(&dev_list, quick_detect, chb_notify, NULL);
- if (ret) {
- com_err(progname, ret, "while detecting heartbeat");
- goto bail;
- }
-
- if (quick_detect)
- ocfs2_print_quick_detect(&dev_list);
- else
- ocfs2_print_full_detect(&dev_list);
-
-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);
- }
- list_del(&(dev->list));
- ocfs2_free(&dev);
- }
-
- return ret;
+ return ;
}
-/*
- * ocfs2_print_full_detect()
- *
- */
-void ocfs2_print_full_detect(struct list_head *dev_list)
+
+static void ocfs2_print_full_detect(struct list_head *dev_list)
{
ocfs2_devices *dev;
struct list_head *pos;
@@ -153,24 +79,27 @@
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"));
- if (list_empty(&(dev->node_list))) {
- printf("Not mounted\n");
- continue;
+
+ if (dev->errcode) {
+ fflush(stdout);
+ com_err("Unknown", dev->errcode, " ");
+ } else {
+ if (list_empty(&(dev->node_list))) {
+ printf("Not mounted\n");
+ continue;
+ }
+ ocfs2_print_nodes(&(dev->node_list));
+ printf("\n");
}
- ocfs2_print_nodes(&(dev->node_list));
- printf("\n");
}
return ;
}
-/*
- * ocfs2_print_quick_detect()
- *
- */
-void ocfs2_print_quick_detect(struct list_head *dev_list)
+static void ocfs2_print_quick_detect(struct list_head *dev_list)
{
ocfs2_devices *dev;
struct list_head *pos;
@@ -196,34 +125,8 @@
return ;
}
-/*
- * ocfs2_print_nodes()
- *
- */
-void ocfs2_print_nodes(struct list_head *node_list)
+static errcode_t ocfs2_partition_list (struct list_head *dev_list)
{
- ocfs2_nodes *node;
- struct list_head *pos;
- int begin = 1;
-
- list_for_each(pos, node_list) {
- node = list_entry(pos, ocfs2_nodes, list);
- if (begin) {
- printf("%s", node->node_name);
- begin = 0;
- } else
- printf(", %s", node->node_name);
- }
-
- return ;
-}
-
-/*
- * ocfs2_partition_list()
- *
- */
-errcode_t ocfs2_partition_list (struct list_head *dev_list)
-{
errcode_t ret = 0;
FILE *proc;
char line[256];
@@ -255,21 +158,15 @@
return ret;
}
-/*
- * usage()
- *
- */
-void usage(char *progname)
+
+static void usage(char *progname)
{
printf(usage_string, progname);
return ;
}
-/*
- * read_options()
- *
- */
-int read_options(int argc, char **argv)
+
+static int read_options(int argc, char **argv)
{
int ret = 0;
int c;
@@ -307,3 +204,72 @@
bail:
return ret;
}
+
+
+static errcode_t ocfs2_detect(char *device, int quick_detect)
+{
+ errcode_t ret = 0;
+ struct list_head dev_list;
+ struct list_head *pos1, *pos2, *pos3, *pos4;
+ ocfs2_nodes *node;
+ ocfs2_devices *dev;
+
+ INIT_LIST_HEAD(&(dev_list));
+
+ if (device) {
+ ret = ocfs2_malloc0(sizeof(ocfs2_devices), &dev);
+ if (ret)
+ goto bail;
+ strncpy(dev->dev_name, device, sizeof(dev->dev_name));
+ list_add(&(dev->list), &dev_list);
+ } else {
+ ret = ocfs2_partition_list(&dev_list);
+ if (ret) {
+ com_err(progname, ret, "while reading /proc/partitions");
+ goto bail;
+ }
+ }
+
+ ret = ocfs2_check_heartbeats(&dev_list);
+ if (ret) {
+ com_err(progname, ret, "while detecting heartbeat");
+ goto bail;
+ }
+
+ if (quick_detect)
+ ocfs2_print_quick_detect(&dev_list);
+ else
+ ocfs2_print_full_detect(&dev_list);
+
+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);
+ }
+ list_del(&(dev->list));
+ ocfs2_free(&dev);
+ }
+
+ return ret;
+}
+
+
+int main(int argc, char **argv)
+{
+ errcode_t ret = 0;
+
+ initialize_ocfs_error_table();
+ initialize_o2dl_error_table();
+
+ ret = read_options(argc, argv);
+ if (ret)
+ goto bail;
+
+ ret = ocfs2_detect(device, quick_detect);
+
+bail:
+ return ret;
+}
Property changes on: trunk/ocfs2console/ocfs2interface
___________________________________________________________________
Name: svn:ignore
+ *.d
ocfs2module.so
Modified: trunk/ocfs2console/ocfs2interface/Makefile
===================================================================
--- trunk/ocfs2console/ocfs2interface/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/ocfs2console/ocfs2interface/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -15,9 +15,13 @@
LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
-DEFINES = -DOCFS2_FLAT_INCLUDES -DG_DISABLE_DEPRECATED
-INCLUDES = $(LIBOCFS2_CFLAGS) $(PYTHON_INCLUDES) $(GLIB_CFLAGS)
+LIBO2DLM_CFLAGS = -I$(TOPDIR)/libo2dlm/include
+LIBO2DLM_LIBS = -L$(TOPDIR)/libo2dlm -lo2dlm
+LIBO2DLM_DEPS = $(TOPDIR)/libo2dlm/libo2dlm.a
+DEFINES = -DOCFS2_FLAT_INCLUDES -DG_DISABLE_DEPRECATED -DO2DLM_FLAT_INCLUDES
+INCLUDES = $(LIBOCFS2_CFLAGS) $(PYTHON_INCLUDES) $(GLIB_CFLAGS) $(LIBO2DLM_CFLAGS)
+
OPTIMIZE = -O2
OPTIMIZE = -O0
@@ -55,8 +59,8 @@
DIST_FILES = $(CFILES) $(HFILES) $(PYSRC)
-ocfs2module.so: $(OBJS) $(LIBOCFS2_DEPS)
- $(LINK) -shared $(LIBOCFS2_LIBS) $(COM_ERR_LIBS) $(GLIB_LIBS)
+ocfs2module.so: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS)
+ $(LINK) -shared $(LIBOCFS2_LIBS) $(COM_ERR_LIBS) $(GLIB_LIBS) $(LIBO2DLM_LIBS)
install-pylib:
$(SHELL) $(TOPDIR)/mkinstalldirs $(DESTDIR)$(pyexecdir)/ocfs2interface
Modified: trunk/sizetest/Makefile
===================================================================
--- trunk/sizetest/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/sizetest/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -15,8 +15,8 @@
SBIN_PROGRAMS = sizetest.ocfs2
-INCLUDES = -I$(TOPDIR)/libocfs2/include
-DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
+INCLUDES = -I$(TOPDIR)/libocfs2/include -I$(TOPDIR)/libo2dlm/include
+DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\" -DO2DLM_FLAT_INCLUDES
CFILES = sizetest.c
OBJS = $(subst .c,.o,$(CFILES))
Modified: trunk/tunefs.ocfs2/Makefile
===================================================================
--- trunk/tunefs.ocfs2/Makefile 2005-03-04 02:27:10 UTC (rev 637)
+++ trunk/tunefs.ocfs2/Makefile 2005-03-08 01:02:38 UTC (rev 638)
@@ -18,8 +18,8 @@
SBIN_PROGRAMS = tunefs.ocfs2
-INCLUDES = -I$(TOPDIR)/libocfs2/include $(GLIB_CFLAGS)
-DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
+INCLUDES = -I$(TOPDIR)/libocfs2/include $(GLIB_CFLAGS) -I$(TOPDIR)/libo2dlm/include
+DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\" -DO2DLM_FLAT_INCLUDES
#MANS = tunefs.ocfs2.8
More information about the Ocfs2-tools-commits
mailing list