[Ocfs-tools-commits]
smushran commits r159 - in trunk/ocfs2/debugfs.ocfs2: . include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Jul 16 18:49:41 CDT 2004
Author: smushran
Date: 2004-07-16 17:49:39 -0500 (Fri, 16 Jul 2004)
New Revision: 159
Added:
trunk/ocfs2/debugfs.ocfs2/bindraw.c
trunk/ocfs2/debugfs.ocfs2/include/bindraw.h
Modified:
trunk/ocfs2/debugfs.ocfs2/Makefile
trunk/ocfs2/debugfs.ocfs2/commands.c
trunk/ocfs2/debugfs.ocfs2/dump.c
trunk/ocfs2/debugfs.ocfs2/include/commands.h
trunk/ocfs2/debugfs.ocfs2/include/main.h
trunk/ocfs2/debugfs.ocfs2/journal.c
trunk/ocfs2/debugfs.ocfs2/main.c
trunk/ocfs2/debugfs.ocfs2/readfs.c
trunk/ocfs2/debugfs.ocfs2/utils.c
Log:
device bound to raw to enable o_direct
Modified: trunk/ocfs2/debugfs.ocfs2/Makefile
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/Makefile 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/Makefile 2004-07-16 22:49:39 UTC (rev 159)
@@ -11,8 +11,8 @@
CFLAGS += -Wall -O2
-CFILES = main.c commands.c dump.c readfs.c utils.c journal.c
-HFILES = include/main.h include/commands.h include/dump.h include/readfs.h include/utils.h include/journal.h
+CFILES = main.c commands.c dump.c readfs.c utils.c journal.c bindraw.c
+HFILES = include/main.h include/commands.h include/dump.h include/readfs.h include/utils.h include/journal.h include/bindraw.h
OBJS = $(subst .c,.o,$(CFILES))
Added: trunk/ocfs2/debugfs.ocfs2/bindraw.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/bindraw.c 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/bindraw.c 2004-07-16 22:49:39 UTC (rev 159)
@@ -0,0 +1,163 @@
+
+/*
+ * bindraw.c
+ *
+ * Binds device to first available raw device
+ *
+ * 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 <main.h>
+#include <commands.h>
+#include <readfs.h>
+#include <utils.h>
+#include <journal.h>
+#include <dump.h>
+#include <bindraw.h>
+
+/*
+ * bind_raw()
+ *
+ */
+int bind_raw (char *blk_dev, int *raw_minor, char *raw_dev, int rdlen)
+{
+ int fd = 0;
+ int i;
+ struct raw_config_request rcs;
+ struct stat statbuf;
+ int ret = -1;
+
+ memset(&statbuf, 0, sizeof(struct stat));
+ if (stat(blk_dev, &statbuf) == -1)
+ DBGFS_FATAL("%s", strerror(errno));
+
+ if (MAJOR(statbuf.st_rdev) == 0) {
+ printf("Invalid device %s\n", blk_dev);
+ goto bail;
+ }
+
+ if (strstr(blk_dev, "/dev/raw")) {
+ strncpy(raw_dev, blk_dev, rdlen-1);
+ raw_dev[rdlen-1] = '\0';
+ }
+ else {
+ if ((fd = open("/dev/rawctl", O_RDWR)) == -1)
+ DBGFS_FATAL("Error opening /dev/rawctl.\n%s\n", strerror(errno));
+
+ for (i = 1; i < 255; ++i) {
+ memset(&rcs, 0, sizeof(struct raw_config_request));
+ rcs.raw_minor = i;
+ if (ioctl(fd, RAW_GETBIND, &rcs) == -1)
+ continue;
+ if (rcs.block_major == 0)
+ break;
+ }
+
+ if (i >= 255) {
+ printf ("unable to find a free raw device /dev/raw/rawXX\n");
+ goto bail;
+ }
+
+ *raw_minor = i;
+ snprintf(raw_dev, rdlen, "/dev/raw/raw%d", i);
+
+ rcs.raw_minor = i;
+ rcs.block_major = (__u64)MAJOR(statbuf.st_rdev);
+ rcs.block_minor = (__u64)MINOR(statbuf.st_rdev);
+ if (ioctl(fd, RAW_SETBIND, &rcs) == -1) {
+ printf ("Error binding to raw: %s\n", strerror(errno));
+ *raw_minor = 0;
+ raw_dev[0] = '\0';
+ goto bail;
+ }
+ }
+
+ ret = 0;
+bail:
+ if (fd)
+ close(fd);
+
+ return ret;
+} /* bind_raw */
+
+/*
+ * unbind_raw()
+ *
+ */
+void unbind_raw(int raw_minor)
+{
+ int fd = 0;
+ struct raw_config_request rcs;
+
+ if (raw_minor == 0)
+ goto bail;
+
+ if ((fd = open("/dev/rawctl", O_RDWR)) == -1)
+ DBGFS_FATAL("%s", strerror(errno));
+
+ rcs.raw_minor = raw_minor;
+ rcs.block_major = 0;
+ rcs.block_minor = 0;
+ if (ioctl(fd, RAW_SETBIND, &rcs) == -1) {
+ printf("Error unbinding from raw: %s\n", strerror(errno));
+ goto bail;
+ }
+
+bail:
+ if (fd)
+ close(fd);
+ return ;
+} /* unbind_raw */
+
+/*
+ * signal_message()
+ *
+ */
+static void signal_message (int sig)
+{
+#define LINE1 "Abnormal termination!\n"
+#define LINE2 "There may be bound raw devices left lying around, please clean them up\n"
+#define LINE3 "using the raw(8) command.\n"
+
+ write(2, LINE1, sizeof(LINE1) - 1);
+ write(2, LINE2, sizeof(LINE2) - 1);
+ write(2, LINE3, sizeof(LINE3) - 1);
+
+ signal(sig, SIG_DFL);
+
+ raise(sig);
+
+ return ;
+} /* signal_message */
+
+/*
+ * init_raw_cleanup_message()
+ *
+ */
+void init_raw_cleanup_message(void)
+{
+ signal (SIGHUP, signal_message);
+ signal (SIGQUIT, signal_message);
+ signal (SIGABRT, signal_message);
+ signal (SIGBUS, signal_message);
+ signal (SIGSEGV, signal_message);
+
+ return ;
+} /* init_raw_cleanup_message */
Modified: trunk/ocfs2/debugfs.ocfs2/commands.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/commands.c 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/commands.c 2004-07-16 22:49:39 UTC (rev 159)
@@ -29,6 +29,7 @@
#include <utils.h>
#include <journal.h>
#include <dump.h>
+#include <bindraw.h>
typedef void (*PrintFunc) (void *buf);
typedef gboolean (*WriteFunc) (char **data, void *buf);
@@ -72,6 +73,7 @@
dbgfs_gbls gbls = {
.device = NULL,
+ .raw_minor = 0,
.dev_fd = -1,
.blksz_bits = 0,
.clstrsz_bits = 0,
@@ -175,6 +177,7 @@
char *dev = args[1];
ocfs2_super_block *sb;
__u32 len;
+ char raw_dev[255];
if (gbls.device)
do_close (NULL);
@@ -184,13 +187,18 @@
goto bail;
}
- gbls.dev_fd = open (dev, allow_write ? O_RDONLY : O_RDWR);
+ if (bind_raw (dev, &gbls.raw_minor, raw_dev, sizeof(raw_dev)))
+ goto bail;
+
+ printf ("Bound %s to %s\n", dev, raw_dev);
+
+ gbls.dev_fd = open (raw_dev, allow_write ? O_RDONLY : O_RDWR);
if (gbls.dev_fd == -1) {
printf ("could not open device %s\n", dev);
goto bail;
}
- gbls.device = g_strdup (dev);
+ gbls.device = g_strdup (raw_dev);
if (read_super_block (gbls.dev_fd, (char **)&gbls.superblk) != -1)
gbls.curdir = g_strdup ("/");
@@ -209,7 +217,7 @@
/* read root inode */
len = 1 << gbls.blksz_bits;
- if (!(gbls.rootin = malloc(len)))
+ if (!(gbls.rootin = memalign(512, len)))
DBGFS_FATAL("%s", strerror(errno));
if ((pread64(gbls.dev_fd, (char *)gbls.rootin, len,
(gbls.root_blkno << gbls.blksz_bits))) == -1)
@@ -217,7 +225,7 @@
/* read sysdir inode */
len = 1 << gbls.blksz_bits;
- if (!(gbls.sysdirin = malloc(len)))
+ if (!(gbls.sysdirin = memalign(512, len)))
DBGFS_FATAL("%s", strerror(errno));
if ((pread64(gbls.dev_fd, (char *)gbls.sysdirin, len,
(gbls.sysdir_blkno << gbls.blksz_bits))) == -1)
@@ -242,6 +250,9 @@
close (gbls.dev_fd);
gbls.dev_fd = -1;
+ unbind_raw(gbls.raw_minor);
+ gbls.raw_minor = 0;
+
g_free (gbls.curdir);
gbls.curdir = NULL;
@@ -283,7 +294,7 @@
}
len = 1 << gbls.blksz_bits;
- if (!(buf = malloc(len)))
+ if (!(buf = memalign(512, len)))
DBGFS_FATAL("%s", strerror(errno));
if (opts) {
@@ -482,7 +493,7 @@
}
buflen = 1 << gbls.blksz_bits;
- if (!(buf = malloc(buflen)))
+ if (!(buf = memalign(512, buflen)))
DBGFS_FATAL("%s", strerror(errno));
if (opts) {
@@ -671,3 +682,22 @@
safefree (logbuf);
return ;
} /* do_journal */
+
+
+/*
+ * handle_signal()
+ *
+ */
+void handle_signal (int sig)
+{
+ switch (sig) {
+ case SIGTERM:
+ case SIGINT:
+ if (gbls.device)
+ do_close (NULL);
+ exit(1);
+ }
+
+ return ;
+} /* handle_signal */
+
Modified: trunk/ocfs2/debugfs.ocfs2/dump.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/dump.c 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/dump.c 2004-07-16 22:49:39 UTC (rev 159)
@@ -29,6 +29,7 @@
#include <utils.h>
#include <journal.h>
#include <dump.h>
+#include <bindraw.h>
extern dbgfs_gbls gbls;
Added: trunk/ocfs2/debugfs.ocfs2/include/bindraw.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/bindraw.h 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/include/bindraw.h 2004-07-16 22:49:39 UTC (rev 159)
@@ -0,0 +1,34 @@
+
+/*
+ * bindraw.h
+ *
+ * Declarations, prototypes, etc.
+ *
+ * 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 _BINDRAW_H_
+#define _BINDRAW_H_
+
+int bind_raw(char *blk_dev, int *raw_minor, char *raw_dev, int rdlen);
+void unbind_raw(int raw_minor);
+void init_raw_cleanup_message(void);
+
+#endif
Modified: trunk/ocfs2/debugfs.ocfs2/include/commands.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/commands.h 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/include/commands.h 2004-07-16 22:49:39 UTC (rev 159)
@@ -27,5 +27,6 @@
#define __COMMANDS_H__
void do_command (char *cmd);
+void handle_signal (int sig);
#endif /* __COMMANDS_H__ */
Modified: trunk/ocfs2/debugfs.ocfs2/include/main.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/main.h 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/include/main.h 2004-07-16 22:49:39 UTC (rev 159)
@@ -44,6 +44,8 @@
#include <arpa/inet.h>
#include <netinet/in.h>
#include <signal.h>
+#include <sys/raw.h>
+#include <linux/kdev_t.h>
#include <glib.h>
@@ -64,7 +66,8 @@
typedef struct _dbgfs_glbs {
char *device;
- int dev_fd;
+ int raw_minor;
+ int dev_fd;
__u32 blksz_bits;
__u32 clstrsz_bits;
__u64 root_blkno;
@@ -77,6 +80,8 @@
ocfs2_dinode *sysdirin;
} dbgfs_gbls;
+void *memalign(size_t boundary, size_t size);
+
#define safefree(_p) do {if (_p) { free(_p); (_p) = NULL; } } while (0)
#define DBGFS_FATAL(fmt, arg...) ({ fprintf(stderr, "ERROR at %s, %d: " fmt ". EXITING!!!\n", \
Modified: trunk/ocfs2/debugfs.ocfs2/journal.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/journal.c 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/journal.c 2004-07-16 22:49:39 UTC (rev 159)
@@ -29,6 +29,7 @@
#include <utils.h>
#include <journal.h>
#include <dump.h>
+#include <bindraw.h>
extern dbgfs_gbls gbls;
Modified: trunk/ocfs2/debugfs.ocfs2/main.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/main.c 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/main.c 2004-07-16 22:49:39 UTC (rev 159)
@@ -29,6 +29,7 @@
#include <utils.h>
#include <journal.h>
#include <dump.h>
+#include <bindraw.h>
#define PROMPT "debugfs: "
@@ -89,6 +90,19 @@
char *arg;
gboolean seen_device = FALSE;
+#define INSTALL_SIGNAL(sig) \
+ do { \
+ if (signal(sig, handle_signal) == SIG_ERR) { \
+ printf("Could not set " #sig "\n"); \
+ goto bail; \
+ } \
+ } while (0)
+
+ INSTALL_SIGNAL(SIGTERM);
+ INSTALL_SIGNAL(SIGINT);
+
+ init_raw_cleanup_message();
+
for (i = 1; i < argc; i++) {
arg = argv[i];
if ((strcmp (arg, "--write") == 0) ||
@@ -133,5 +147,6 @@
}
}
+bail:
return 0;
} /* main */
Modified: trunk/ocfs2/debugfs.ocfs2/readfs.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/readfs.c 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/readfs.c 2004-07-16 22:49:39 UTC (rev 159)
@@ -29,6 +29,7 @@
#include <utils.h>
#include <journal.h>
#include <dump.h>
+#include <bindraw.h>
extern dbgfs_gbls gbls;
@@ -46,7 +47,7 @@
__u32 buflen;
buflen = 1 << bits;
- if (!(*buf = malloc(buflen)))
+ if (!(*buf = memalign(512, buflen)))
DBGFS_FATAL("%s", strerror(errno));
if ((pread64(fd, *buf, buflen, 0)) == -1)
@@ -68,7 +69,7 @@
for (bits = 9; bits < 13; bits++) {
if (!*buf) {
buflen = 1 << bits;
- if (!(*buf = malloc(buflen)))
+ if (!(*buf = memalign(512, buflen)))
DBGFS_FATAL("%s", strerror(errno));
}
@@ -139,7 +140,7 @@
add_extent_rec (arr, rec);
else {
buflen = 1 << gbls.blksz_bits;
- if (!(buf = malloc(buflen)))
+ if (!(buf = memalign(512, buflen)))
DBGFS_FATAL("%s", strerror(errno));
off = (__u64)rec->e_blkno << gbls.blksz_bits;
@@ -207,7 +208,7 @@
if ((foff + len) > size)
len = size - foff;
- if (!(buf = malloc (len)))
+ if (!(buf = memalign(512, len)))
DBGFS_FATAL("%s", strerror(errno));
if ((pread64(fd, buf, len, off)) == -1)
@@ -303,7 +304,7 @@
arr = g_array_new(0, 1, sizeof(ocfs2_extent_rec));
buflen = 1 << gbls.blksz_bits;
- if (!(inode_buf = malloc(buflen)))
+ if (!(inode_buf = memalign(512, buflen)))
DBGFS_FATAL("%s", strerror(errno));
if ((read_inode (fd, blknum, inode_buf, buflen)) == -1) {
@@ -324,7 +325,7 @@
}
}
- if (!(newbuf = malloc (newlen)))
+ if (!(newbuf = memalign(512, newlen)))
DBGFS_FATAL("%s", strerror(errno));
p = newbuf;
Modified: trunk/ocfs2/debugfs.ocfs2/utils.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/utils.c 2004-07-15 23:56:59 UTC (rev 158)
+++ trunk/ocfs2/debugfs.ocfs2/utils.c 2004-07-16 22:49:39 UTC (rev 159)
@@ -29,6 +29,7 @@
#include <utils.h>
#include <journal.h>
#include <dump.h>
+#include <bindraw.h>
/*
* add_extent_rec()
More information about the Ocfs-tools-commits
mailing list