[Ocfs2-tools-commits] smushran commits r1300 - in trunk:
debugfs.ocfs2 libocfs2 libocfs2/include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Feb 15 15:09:39 PST 2007
Author: smushran
Date: 2007-02-15 15:09:37 -0800 (Thu, 15 Feb 2007)
New Revision: 1300
Modified:
trunk/debugfs.ocfs2/commands.c
trunk/libocfs2/backup_super.c
trunk/libocfs2/include/ocfs2.h
trunk/libocfs2/ocfs2_err.et
trunk/libocfs2/openfs.c
Log:
debugfs: stats dumps backup superblock
The stats command has been enhanced to dump a specific backup superblock.
Signed-off-by: mfasheh
Modified: trunk/debugfs.ocfs2/commands.c
===================================================================
--- trunk/debugfs.ocfs2/commands.c 2007-02-15 22:20:21 UTC (rev 1299)
+++ trunk/debugfs.ocfs2/commands.c 2007-02-15 23:09:37 UTC (rev 1300)
@@ -845,24 +845,60 @@
*/
static void do_stats (char **args)
{
- char *opts = args[1];
FILE *out;
+ errcode_t ret;
struct ocfs2_dinode *in;
struct ocfs2_super_block *sb;
+ int c, argc;
+ int sb_num = 0;
+ int only_super = 0;
+ char *ptr = NULL;
+ char *stats_usage = "usage: stats [-h] [-s backup#]";
+ char *buf = gbls.blockbuf;
if (check_device_open())
goto bail;
+ for (argc = 0; (args[argc]); ++argc);
+ optind = 0;
+
+ while ((c = getopt(argc, args, "hs:")) != -1) {
+ switch (c) {
+ case 'h':
+ only_super = 1;
+ break;
+ case 's':
+ sb_num = strtoul(optarg, &ptr, 0);
+ if (!ptr || *ptr) {
+ fprintf(stderr, "%s\n", stats_usage);
+ goto bail;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (!sb_num)
+ in = gbls.fs->fs_super;
+ else {
+ ret = ocfs2_read_backup_super(gbls.fs, sb_num, buf);
+ if (ret) {
+ com_err(gbls.cmd, ret, "while reading backup "
+ "superblock");
+ goto bail;
+ }
+ in = (struct ocfs2_dinode *)buf;
+ }
+
+ sb = OCFS2_RAW_SB(in);
+
out = open_pager(gbls.interactive);
- in = gbls.fs->fs_super;
- sb = OCFS2_RAW_SB(gbls.fs->fs_super);
dump_super_block(out, sb);
-
- if (!opts || strcmp(opts, "-h"))
+ if (!only_super)
dump_inode(out, in);
+ close_pager(out);
- close_pager (out);
-
bail:
return ;
}
Modified: trunk/libocfs2/backup_super.c
===================================================================
--- trunk/libocfs2/backup_super.c 2007-02-15 22:20:21 UTC (rev 1299)
+++ trunk/libocfs2/backup_super.c 2007-02-15 23:09:37 UTC (rev 1300)
@@ -163,3 +163,19 @@
bail:
return ret;
}
+
+errcode_t ocfs2_read_backup_super(ocfs2_filesys *fs, int backup, char *sbbuf)
+{
+ int numsb;
+ uint64_t blocks[OCFS2_MAX_BACKUP_SUPERBLOCKS];
+
+ if (!OCFS2_HAS_COMPAT_FEATURE(OCFS2_RAW_SB(fs->fs_super),
+ OCFS2_FEATURE_COMPAT_BACKUP_SB))
+ return OCFS2_ET_NO_BACKUP_SUPER;
+
+ numsb = ocfs2_get_backup_super_offset(fs, blocks, ARRAY_SIZE(blocks));
+ if (backup < 1 || backup > numsb)
+ return OCFS2_ET_NO_BACKUP_SUPER;
+
+ return ocfs2_read_super(fs, blocks[backup], sbbuf);
+}
Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h 2007-02-15 22:20:21 UTC (rev 1299)
+++ trunk/libocfs2/include/ocfs2.h 2007-02-15 23:09:37 UTC (rev 1300)
@@ -265,6 +265,7 @@
errcode_t io_write_block(io_channel *channel, int64_t blkno, int count,
const char *data);
+errcode_t ocfs2_read_super(ocfs2_filesys *fs, uint64_t superblock, char *sb);
errcode_t ocfs2_write_super(ocfs2_filesys *fs);
int ocfs2_mount_local(ocfs2_filesys *fs);
errcode_t ocfs2_open(const char *name, int flags,
@@ -637,6 +638,8 @@
errcode_t ocfs2_refresh_backup_super(ocfs2_filesys *fs,
uint64_t *blocks, size_t len);
+errcode_t ocfs2_read_backup_super(ocfs2_filesys *fs, int backup, char *sbbuf);
+
/*
* ${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/libocfs2/ocfs2_err.et
===================================================================
--- trunk/libocfs2/ocfs2_err.et 2007-02-15 22:20:21 UTC (rev 1299)
+++ trunk/libocfs2/ocfs2_err.et 2007-02-15 23:09:37 UTC (rev 1300)
@@ -3,7 +3,7 @@
#
# Error codes for the OCFS2 userspace library.
#
-# Copyright (C) 2004 Oracle. All rights reserved.
+# Copyright (C) 2004, 2007 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
@@ -162,4 +162,7 @@
ec OCFS2_ET_NO_IONICE,
"Can't find ionice"
+ec OCFS2_ET_NO_BACKUP_SUPER,
+ "Backup superblock not found"
+
end
Modified: trunk/libocfs2/openfs.c
===================================================================
--- trunk/libocfs2/openfs.c 2007-02-15 22:20:21 UTC (rev 1299)
+++ trunk/libocfs2/openfs.c 2007-02-15 23:09:37 UTC (rev 1300)
@@ -71,7 +71,7 @@
return ret;
}
-static errcode_t ocfs2_read_super(ocfs2_filesys *fs, int superblock)
+errcode_t ocfs2_read_super(ocfs2_filesys *fs, uint64_t superblock, char *sb)
{
errcode_t ret;
char *blk;
@@ -92,8 +92,14 @@
goto out_blk;
ocfs2_swap_inode_to_cpu(di);
- fs->fs_super = di;
+ if (!sb)
+ fs->fs_super = di;
+ else {
+ memcpy(sb, blk, fs->fs_blocksize);
+ ocfs2_free(&blk);
+ }
+
return 0;
out_blk:
@@ -215,18 +221,19 @@
if (!block_size)
goto out;
io_set_blksize(fs->fs_io, block_size);
- ret = ocfs2_read_super(fs, superblock);
+ ret = ocfs2_read_super(fs, (uint64_t)superblock, NULL);
} else {
superblock = OCFS2_SUPER_BLOCK_BLKNO;
if (block_size) {
io_set_blksize(fs->fs_io, block_size);
- ret = ocfs2_read_super(fs, superblock);
+ ret = ocfs2_read_super(fs, (uint64_t)superblock, NULL);
} else {
for (block_size = io_get_blksize(fs->fs_io);
block_size <= OCFS2_MAX_BLOCKSIZE;
block_size <<= 1) {
io_set_blksize(fs->fs_io, block_size);
- ret = ocfs2_read_super(fs, superblock);
+ ret = ocfs2_read_super(fs, (uint64_t)superblock,
+ NULL);
if (ret == OCFS2_ET_BAD_MAGIC)
continue;
break;
More information about the Ocfs2-tools-commits
mailing list