[Ocfs-tools-commits] smushran commits r224 - in trunk: . format
fsck mounted mounted/inc
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Jan 11 17:36:14 CST 2005
Author: smushran
Date: 2005-01-11 17:36:11 -0600 (Tue, 11 Jan 2005)
New Revision: 224
Added:
trunk/mounted/
trunk/mounted/Cscope.make
trunk/mounted/Makefile
trunk/mounted/checkhb.c
trunk/mounted/inc/
trunk/mounted/inc/kernel-list.h
trunk/mounted/inc/mounted.h
trunk/mounted/mounted.c
Modified:
trunk/Makefile
trunk/configure.in
trunk/format/Makefile
trunk/fsck/utils.c
Log:
new mounted.ocfs checked in
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2004-10-25 20:36:12 UTC (rev 223)
+++ trunk/Makefile 2005-01-11 23:36:11 UTC (rev 224)
@@ -22,7 +22,7 @@
$(error could not detect architecture for tools)
endif
-SUBDIRS = libocfs debugocfs format fsck bugfix load_ocfs ocfs_uid_gen
+SUBDIRS = libocfs debugocfs format fsck load_ocfs ocfs_uid_gen mounted
ifdef BUILD_OCFSTOOL
SUBDIRS += ocfstool
Modified: trunk/configure.in
===================================================================
--- trunk/configure.in 2004-10-25 20:36:12 UTC (rev 223)
+++ trunk/configure.in 2005-01-11 23:36:11 UTC (rev 224)
@@ -7,8 +7,8 @@
# Adjust these for the software version.
MAJOR_VERSION=1
MINOR_VERSION=1
-MICRO_VERSION=4
-EXTRA_VERSION=BETA3
+MICRO_VERSION=5
+EXTRA_VERSION=BETA1
# Adjust this only to bump the RPM packaging version
RPM_VERSION=1
Modified: trunk/format/Makefile
===================================================================
--- trunk/format/Makefile 2004-10-25 20:36:12 UTC (rev 223)
+++ trunk/format/Makefile 2005-01-11 23:36:11 UTC (rev 224)
@@ -11,7 +11,7 @@
CFLAGS = $(OPTS) -fno-strict-aliasing $(WARNINGS) -pthread $(GLIB_CFLAGS)
-SBIN_PROGRAMS = mkfs.ocfs mounted.ocfs tuneocfs
+SBIN_PROGRAMS = mkfs.ocfs tuneocfs
INCLUDES = -I$(TOPDIR)/libocfs/Common/inc -I$(TOPDIR)/libocfs/Linux/inc -Iinc -I$(TOPDIR)/libocfs
DEFINES = -DLINUX -DUSERSPACE_TOOL -DFORMAT_OCFS
@@ -59,8 +59,8 @@
mkfs.ocfs: format.o frmtport.o journal.o system.o $(TOPDIR)/libocfs/libocfs.a
$(LINK) -L$(TOPDIR)/libocfs -locfs
-mounted.ocfs: mounted.o frmtport.o $(TOPDIR)/libocfs/libocfs.a
- $(LINK) -L$(TOPDIR)/libocfs -locfs
+#mounted.ocfs: mounted.o frmtport.o $(TOPDIR)/libocfs/libocfs.a
+# $(LINK) -L$(TOPDIR)/libocfs -locfs
tuneocfs: tune.o frmtport.o $(TOPDIR)/libocfs/libocfs.a
$(LINK) -L$(TOPDIR)/libocfs -locfs
Modified: trunk/fsck/utils.c
===================================================================
--- trunk/fsck/utils.c 2004-10-25 20:36:12 UTC (rev 223)
+++ trunk/fsck/utils.c 2005-01-11 23:36:11 UTC (rev 224)
@@ -1627,7 +1627,7 @@
}
}
-bail:
+//bail:
return 0;
} /* fix_num_del */
Property changes on: trunk/mounted
___________________________________________________________________
Name: svn:ignore
+ mounted.ocfs
cscope*
stamp-md5
Added: trunk/mounted/Cscope.make
===================================================================
--- trunk/mounted/Cscope.make 2004-10-25 20:36:12 UTC (rev 223)
+++ trunk/mounted/Cscope.make 2005-01-11 23:36:11 UTC (rev 224)
@@ -0,0 +1,9 @@
+.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 ../libocfs -name '*.h' -print >>cscope.files
+ cscope -b
Added: trunk/mounted/Makefile
===================================================================
--- trunk/mounted/Makefile 2004-10-25 20:36:12 UTC (rev 223)
+++ trunk/mounted/Makefile 2005-01-11 23:36:11 UTC (rev 224)
@@ -0,0 +1,51 @@
+TOPDIR = ..
+
+include $(TOPDIR)/Preamble.make
+
+WARNINGS = -Wall -Wstrict-prototypes -Wno-format -Wmissing-prototypes \
+ -Wmissing-declarations
+
+ifdef OCFS_DEBUG
+OPTS = -ggdb -O0
+else
+OPTS = -O2
+endif
+
+CFLAGS = $(OPTS) -fno-strict-aliasing $(WARNINGS) -pthread $(GLIB_CFLAGS)
+
+SBIN_PROGRAMS = mounted.ocfs
+
+INCLUDES = -I$(TOPDIR)/libocfs/Common/inc -I$(TOPDIR)/libocfs/Linux/inc -Iinc -I$(TOPDIR)/libocfs
+DEFINES = -DLINUX -DUSERSPACE_TOOL
+
+ifeq ($(OCFS_PROCESSOR),x86_64)
+ CFLAGS += -m64
+endif
+ifeq ($(OCFS_PROCESSOR),ia64)
+endif
+ifeq ($(OCFS_PROCESSOR),i686)
+ DEFINES += -D__ILP32__
+endif
+ifeq ($(OCFS_PROCESSOR),s390x)
+ DEFINES += -D__LP64__
+endif
+
+VERSION_FILES = mounted.c checkhb.c inc/kernel-list.h inc/mounted.h
+VERSION_SRC = mounted.c
+VERSION_PREFIX = OCFS
+
+DIST_RULES = dist-incdir
+
+MANS =
+
+INSTALL_RULES = install-sbin-links install-man-links
+
+DIST_FILES = $(VERSION_FILES) $(VERSION_SRC)
+
+mounted.ocfs: mounted.o checkhb.o
+ $(LINK)
+
+dist-incdir:
+ $(TOPDIR)/mkinstalldirs $(DIST_DIR)/inc
+
+include $(TOPDIR)/Postamble.make
Added: trunk/mounted/checkhb.c
===================================================================
--- trunk/mounted/checkhb.c 2004-10-25 20:36:12 UTC (rev 223)
+++ trunk/mounted/checkhb.c 2005-01-11 23:36:11 UTC (rev 224)
@@ -0,0 +1,241 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * checkhb.c
+ *
+ * ocfs check heartbeat function
+ *
+ * Copyright (C) 2004 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 as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ * Authors: Sunil Mushran
+ */
+
+#include <mounted.h>
+
+/*
+ * ocfs_detect_live_nodes()
+ *
+ */
+static void ocfs_detect_live_nodes(ocfs_devices *dev, char *pub_buf,
+ int first_time)
+{
+ char *p;
+ ocfs_publish *publish;
+ int i;
+ uint16_t num_nodes = 32;
+ uint32_t blksz_bits = 9;
+ uint64_t *pub_times = dev->pub_times;
+
+ 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] = 1;
+ else
+ pub_times[i] = 0;
+ p += (1 << blksz_bits);
+ }
+
+bail:
+ return ;
+}
+
+/*
+ * ocfs_gather_times()
+ *
+ */
+static void ocfs_gather_times(ocfs_devices *dev, struct list_head *node_list,
+ int first_time)
+{
+ int fd;
+ char *buf = NULL;
+ int buflen = 0;
+ char *p;
+ ocfs_disk_node_config_info *node;
+ ocfs_nodes *node_blk;
+ int i;
+ uint16_t num_nodes = 32;
+ int blksz_bits = 9;
+
+ /* open device */
+ if ((fd = open(dev->device, O_RDONLY)) == -1)
+ FATAL_ERROR("%s", strerror(errno));
+
+ 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 */
+ if ((buf = malloc(buflen)) == NULL)
+ FATAL_ERROR("out of memory");
+
+ /* read cfg+publish */
+ if (pread(fd, buf, buflen, 4096) == -1)
+ FATAL_ERROR("%s", strerror(errno));
+
+ /* process publish times */
+ p = buf + ((2 + num_nodes + 4) << blksz_bits); /* start of publish */
+ ocfs_detect_live_nodes (dev, 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 (dev->pub_times[i]) {
+ node = (ocfs_disk_node_config_info *)p;
+ if (!(node_blk = malloc(sizeof(ocfs_nodes))))
+ FATAL_ERROR("out of memory");
+
+ 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);
+ }
+ }
+
+ safefree(buf);
+ close(fd);
+
+ return ;
+}
+
+/*
+ * ocfs_check_heartbeat() check if the device is 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.
+ *
+ */
+int ocfs_check_heartbeat(struct list_head *dev_list, int quick_detect,
+ int *any_ocfs, ocfs_chb_notify notify, void *user_data)
+{
+ int fd = -1;
+ int i;
+ struct list_head *pos;
+ ocfs_devices *dev = NULL;
+ char *device= NULL;
+ char *buf = NULL;
+ ocfs_vol_disk_hdr *volhdr;
+
+ *any_ocfs = 0;
+ list_for_each(pos, dev_list) {
+ dev = list_entry(pos, ocfs_devices, list);
+ device = dev->device;
+
+ INIT_LIST_HEAD(&(dev->node_list));
+
+ dev->fs_type = 0;
+
+ /* open fs */
+ fd = open(device, O_RDONLY);
+ if (fd < 0) {
+ continue;
+ }
+
+ if ((buf = malloc(1024)) == NULL)
+ FATAL_ERROR("out of memory");
+
+ /* read the first two blocks */
+ if (pread(fd, buf, 1024, 0) == -1) {
+ safefree(buf);
+ safeclose(fd);
+ continue;
+ }
+
+ /* close device */
+ safeclose(fd);
+
+ volhdr = (ocfs_vol_disk_hdr *)buf;
+ if (memcmp(volhdr->signature, OCFS_VOLUME_SIGNATURE,
+ strlen(OCFS_VOLUME_SIGNATURE))) {
+ safefree(buf);
+ continue;
+ }
+
+ dev->fs_type = 1;
+ dev->buf = buf;
+
+ if (!quick_detect) {
+ if ((dev->pub_times = malloc(32 * sizeof(uint64_t))) == NULL)
+ FATAL_ERROR("out of memory");
+
+ ocfs_gather_times(dev, NULL, 1);
+ }
+
+ *any_ocfs = 1;
+ }
+
+ if (quick_detect)
+ goto bail;
+
+ if (!*any_ocfs)
+ goto bail;
+
+ /* wait */
+ if (notify)
+ notify(OCFS2_CHB_START, "Checking heart beat on volume ", user_data);
+
+ 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, ocfs_devices, list);
+
+ if (!dev->fs_type)
+ continue;
+
+ ocfs_gather_times(dev, &dev->node_list, 0);
+ }
+
+ if (notify)
+ notify(OCFS2_CHB_COMPLETE,
+ "\r \r",
+ user_data);
+
+bail:
+ list_for_each(pos, dev_list) {
+ dev = list_entry(pos, ocfs_devices, list);
+ safefree(dev->pub_times);
+ }
+
+ return 0;
+}
Added: trunk/mounted/inc/kernel-list.h
===================================================================
--- trunk/mounted/inc/kernel-list.h 2004-10-25 20:36:12 UTC (rev 223)
+++ trunk/mounted/inc/kernel-list.h 2005-01-11 23:36:11 UTC (rev 224)
@@ -0,0 +1,116 @@
+#ifndef _LINUX_LIST_H
+#define _LINUX_LIST_H
+
+/*
+ * Simple doubly linked list implementation.
+ *
+ * Some of the internal functions ("__xxx") are useful when
+ * manipulating whole lists rather than single entries, as
+ * sometimes we already know the next/prev entries and we can
+ * generate better code by using them directly rather than
+ * using the generic single-entry routines.
+ */
+
+struct list_head {
+ struct list_head *next, *prev;
+};
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define LIST_HEAD(name) \
+ struct list_head name = { &name, &name }
+
+#define INIT_LIST_HEAD(ptr) do { \
+ (ptr)->next = (ptr); (ptr)->prev = (ptr); \
+} while (0)
+
+#if (!defined(__GNUC__) && !defined(__WATCOMC__))
+#define __inline__
+#endif
+
+/*
+ * Insert a new entry between two known consecutive entries.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static __inline__ void __list_add(struct list_head * new,
+ struct list_head * prev,
+ struct list_head * next)
+{
+ next->prev = new;
+ new->next = next;
+ new->prev = prev;
+ prev->next = new;
+}
+
+/*
+ * Insert a new entry after the specified head..
+ */
+static __inline__ void list_add(struct list_head *new, struct list_head *head)
+{
+ __list_add(new, head, head->next);
+}
+
+/*
+ * Insert a new entry at the tail
+ */
+static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
+{
+ __list_add(new, head->prev, head);
+}
+
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static __inline__ void __list_del(struct list_head * prev,
+ struct list_head * next)
+{
+ next->prev = prev;
+ prev->next = next;
+}
+
+static __inline__ void list_del(struct list_head *entry)
+{
+ __list_del(entry->prev, entry->next);
+}
+
+static __inline__ int list_empty(struct list_head *head)
+{
+ return head->next == head;
+}
+
+/*
+ * Splice in "list" into "head"
+ */
+static __inline__ void list_splice(struct list_head *list, struct list_head *head)
+{
+ struct list_head *first = list->next;
+
+ if (first != list) {
+ struct list_head *last = list->prev;
+ struct list_head *at = head->next;
+
+ first->prev = head;
+ head->next = first;
+
+ last->next = at;
+ at->prev = last;
+ }
+}
+
+#define list_entry(ptr, type, member) \
+ ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+
+#define list_for_each(pos, head) \
+ for (pos = (head)->next; pos != (head); pos = pos->next)
+
+#define list_for_each_safe(pos, n, head) \
+ for (pos = (head)->next, n = pos->next; pos != (head); \
+ pos = n, n = pos->next)
+
+#endif
Added: trunk/mounted/inc/mounted.h
===================================================================
--- trunk/mounted/inc/mounted.h 2004-10-25 20:36:12 UTC (rev 223)
+++ trunk/mounted/inc/mounted.h 2005-01-11 23:36:11 UTC (rev 224)
@@ -0,0 +1,79 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * mounted.h
+ *
+ * Function prototypes for related 'C' file.
+ *
+ * Copyright (C) 2004 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 as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ * Authors: Sunil Mushran
+ */
+
+#ifndef __MOUNTED_H__
+#define __MOUNTED_H__
+
+#define _LARGEFILE64_SOURCE
+#define _GNU_SOURCE /* Because libc really doesn't want us using O_DIRECT? */
+#include <stdint.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <kernel-list.h>
+
+#include <libocfs.h>
+#include <bindraw.h>
+
+#define FATAL_ERROR(fmt, arg...) ({ fprintf(stderr, "ERROR at %s, %d: " fmt ". Exiting.\n", \
+ __FILE__, __LINE__, ##arg); \
+ raise (SIGTERM); \
+ exit(1); \
+ })
+
+#define MAX_NODE_NAME_LENGTH 32
+typedef struct _ocfs_nodes {
+ struct list_head list;
+ char node_name[MAX_NODE_NAME_LENGTH+1];
+ uint16_t node_num;
+} ocfs_nodes;
+
+typedef struct _ocfs_devices {
+ struct list_head list;
+ char device[255];
+ int fs_type; /* 1 if ocfs, 0 otherwise */
+ char *buf;
+ uint64_t *pub_times;
+ struct list_head node_list;
+} ocfs_devices;
+
+#define OCFS2_HBT_WAIT 10
+
+/* check_heartbeats progress states */
+#define OCFS2_CHB_START 1
+#define OCFS2_CHB_WAITING 2
+#define OCFS2_CHB_COMPLETE 3
+
+#define safefree(a) do { if(a) { free(a); (a) = NULL; } }while(0)
+#define safeclose(a) do { if((a) != -1) { close(a); (a) = -1; } }while(0)
+
+typedef void (*ocfs_chb_notify)(int state, char *progress, void *data);
+
+int ocfs_check_heartbeat(struct list_head *dev_list, int quick_detect,
+ int *any_ocfs, ocfs_chb_notify notify, void *user_data);
+
+#endif
Added: trunk/mounted/mounted.c
===================================================================
--- trunk/mounted/mounted.c 2004-10-25 20:36:12 UTC (rev 223)
+++ trunk/mounted/mounted.c 2005-01-11 23:36:11 UTC (rev 224)
@@ -0,0 +1,310 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * mounted.c
+ *
+ * ocfs mount detect utility
+ *
+ * Copyright (C) 2004 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 as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ * Authors: Sunil Mushran
+ */
+
+#include <mounted.h>
+
+int quick_detect = 0;
+char *device = NULL;
+char *progname = NULL;
+
+char *usage_string =
+"usage: %s [-d] [-f] [device]\n"
+" -d quick detect\n"
+" -f full detect\n";
+
+/*
+ * version()
+ *
+ */
+static void version(char *progname)
+{
+ printf("%s %s %s (build %s)\n", progname,
+ OCFS_BUILD_VERSION,
+ OCFS_BUILD_DATE,
+ OCFS_BUILD_MD5);
+ return;
+}
+
+/*
+ * usage()
+ *
+ */
+static void usage(char *progname)
+{
+ printf(usage_string, progname);
+ return ;
+}
+
+
+/*
+ * ocfs_partition_list()
+ *
+ */
+static int ocfs_partition_list (struct list_head *dev_list)
+{
+ int ret = -1;
+ FILE *proc;
+ char line[256];
+ char name[256];
+ ocfs_devices *dev;
+
+ if (!(proc = fopen ("/proc/partitions", "r")))
+ goto bail;
+
+ while (fgets (line, sizeof(line), proc) != NULL) {
+ if (sscanf(line, "%*d %*d %*d %99[^ \t\n]", name) != 1)
+ continue;
+
+ if (!(dev = malloc(sizeof(ocfs_devices))))
+ FATAL_ERROR("out of memory");
+
+ snprintf(dev->device, sizeof(dev->device), "/dev/%s", name);
+ list_add_tail(&(dev->list), dev_list);
+ }
+
+ ret = 0;
+bail:
+ if (proc)
+ fclose(proc);
+
+ return ret;
+}
+
+/*
+ * ocfs_print_nodes()
+ *
+ */
+static void ocfs_print_nodes(struct list_head *node_list)
+{
+ ocfs_nodes *node;
+ struct list_head *pos;
+ int begin = 1;
+
+ list_for_each(pos, node_list) {
+ node = list_entry(pos, ocfs_nodes, list);
+ if (begin) {
+ printf("%s", node->node_name);
+ begin = 0;
+ } else
+ printf(", %s", node->node_name);
+ }
+
+ return ;
+}
+
+
+/*
+ * ocfs_print_full_detect()
+ *
+ */
+static void ocfs_print_full_detect(struct list_head *dev_list)
+{
+ ocfs_devices *dev;
+ struct list_head *pos;
+
+ printf("%-20s %-5s %s\n", "Device", "FS", "Nodes");
+ list_for_each(pos, dev_list) {
+ dev = list_entry(pos, ocfs_devices, list);
+ if (dev->fs_type == 0)
+ continue;
+ printf("%-20s %-5s ", dev->device, "ocfs");
+
+ if (list_empty(&(dev->node_list))) {
+ printf("Not mounted\n");
+ continue;
+ }
+ ocfs_print_nodes(&(dev->node_list));
+ printf("\n");
+ }
+ return ;
+}
+
+
+/*
+ * ocfs_print_quick_detect()
+ *
+ */
+static void ocfs_print_quick_detect(struct list_head *dev_list)
+{
+ ocfs_devices *dev;
+ struct list_head *pos;
+ char uuid[40];
+ char *p;
+ int i;
+ ocfs_vol_label *vol_label;
+
+ printf("%-20s %-5s %-32s %-s\n", "Device", "FS", "GUID", "Label");
+ list_for_each(pos, dev_list) {
+ dev = list_entry(pos, ocfs_devices, list);
+ if (dev->fs_type == 0)
+ continue;
+
+ vol_label = (ocfs_vol_label *) (dev->buf + 512);
+ memset(uuid, 0, sizeof(uuid));
+ for (i = 0, p = uuid; i < MAX_VOL_ID_LENGTH; i++, p += 2)
+ sprintf(p, "%02X", vol_label->vol_id[i]);
+
+ printf("%-20s %-5s %-32s %-s\n", dev->device, "ocfs",
+ uuid, vol_label->label);
+ }
+
+ return ;
+}
+
+/*
+ * read_options()
+ *
+ */
+static int read_options(int argc, char **argv)
+{
+ int ret = 0;
+ int c;
+
+ progname = basename(argv[0]);
+
+ if (argc < 2) {
+ version(progname);
+ usage(progname);
+ ret = 1;
+ goto bail;
+ }
+
+ while(1) {
+ c = getopt(argc, argv, "df");
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'd': /* quick detect*/
+ quick_detect = 1;
+ break;
+
+ case 'f': /* full detect*/
+ quick_detect = 0;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (!ret && optind < argc && argv[optind])
+ device = argv[optind];
+
+bail:
+ return ret;
+}
+
+/*
+ * chb_notify()
+ *
+ */
+static void chb_notify(int state, char *progress, void *user_data)
+{
+ fprintf(stdout, "%s", progress);
+ fflush(stdout);
+}
+
+/*
+ * ocfs_detect()
+ *
+ */
+static int ocfs_detect(char *device, int quick_detect)
+{
+ int ret = -1;
+ struct list_head dev_list;
+ struct list_head *pos1, *pos2, *pos3, *pos4;
+ ocfs_nodes *node;
+ ocfs_devices *dev;
+ int any_ocfs = 0;
+
+ INIT_LIST_HEAD(&(dev_list));
+
+ if (device) {
+ if (!(dev = malloc(sizeof(ocfs_devices))))
+ FATAL_ERROR("out of memory");
+ strncpy(dev->device, device, sizeof(dev->device));
+ list_add(&(dev->list), &dev_list);
+ } else {
+ ret = ocfs_partition_list(&dev_list);
+ if (ret) {
+ fprintf(stderr, "%s: unable to read /proc/partitions\n",
+ progname);
+ goto bail;
+ }
+ }
+
+ ret = ocfs_check_heartbeat(&dev_list, quick_detect, &any_ocfs,
+ chb_notify, NULL);
+ if (ret) {
+ fprintf(stderr, "%s: error while detecting heartbeat\n",
+ progname);
+ goto bail;
+ }
+
+ if (any_ocfs) {
+ if (quick_detect)
+ ocfs_print_quick_detect(&dev_list);
+ else
+ ocfs_print_full_detect(&dev_list);
+ } else
+ fprintf(stdout, "%s: No ocfs volumes detected\n", progname);
+
+ ret = 0;
+
+bail:
+ list_for_each_safe(pos1, pos2, &(dev_list)) {
+ dev = list_entry(pos1, ocfs_devices, list);
+ list_for_each_safe(pos3, pos4, &(dev->node_list)) {
+ node = list_entry(pos3, ocfs_nodes, list);
+ list_del(&(node->list));
+ safefree(node);
+ }
+ list_del(&(dev->list));
+ safefree(dev);
+ }
+
+ return ret;
+}
+
+/*
+ * main()
+ *
+ */
+int main(int argc, char **argv)
+{
+ int ret = 0;
+
+ ret = read_options(argc, argv);
+ if (ret)
+ goto bail;
+
+ ret = ocfs_detect(device, quick_detect);
+
+bail:
+ return ret;
+}
More information about the Ocfs-tools-commits
mailing list