>From b41b13ad098be6fb94ecfe44c1acb9a90d2e376c Mon Sep 17 00:00:00 2001
From: Bob Peterson <rpeterso@redhat.com>
Date: Mon, 8 Aug 2011 11:23:47 -0500
Subject: [PATCH 05/56] libgfs2: move gfs1 structures to libgfs2
This patch moves a number of gfs1-specific structures from gfs2_edit to
libgfs2 so other utils can reference them.
It also changes function rindex_read so it can operate on gfs1 or gfs2
rindex files.
-struct gfs_jindex {
- uint64_t ji_addr; /* starting block of the journal */
- uint32_t ji_nsegment; /* number (quantity) of segments in journal */
- uint32_t ji_pad;
-
- char ji_reserved[64];
-};
-
-struct gfs_log_descriptor {
- struct gfs2_meta_header ld_header;
-
- uint32_t ld_type; /* GFS_LOG_DESC_... Type of this log chunk */
- uint32_t ld_length; /* Number of buffers in this chunk */
- uint32_t ld_data1; /* descriptor-specific field */
- uint32_t ld_data2; /* descriptor-specific field */
- char ld_reserved[64];
-};
-
-struct gfs_log_header {
- struct gfs2_meta_header lh_header;
-
- uint32_t lh_flags; /* GFS_LOG_HEAD_... */
- uint32_t lh_pad;
-
- uint64_t lh_first; /* Block number of first header in this trans */
- uint64_t lh_sequence; /* Sequence number of this transaction */
-
- uint64_t lh_tail; /* Block number of log tail */
- uint64_t lh_last_dump; /* Block number of last dump */
-
- char lh_reserved[64];
-};
-
-struct gfs_rindex {
- uint64_t ri_addr; /* block # of 1st block (header) in rgrp */
- uint32_t ri_length; /* # fs blocks containing rgrp header & bitmap */
- uint32_t ri_pad;
-
- uint64_t ri_data1; /* block # of first data/meta block in rgrp */
- uint32_t ri_data; /* number (qty) of data/meta blocks in rgrp */
-
- uint32_t ri_bitbytes; /* total # bytes used by block alloc bitmap */
-
- char ri_reserved[64];
-};
-
-struct gfs_rgrp {
- struct gfs2_meta_header rg_header;
-
- uint32_t rg_flags; /* ?? */
-
- uint32_t rg_free; /* Number (qty) of free data blocks */
-
- /* Dinodes are USEDMETA, but are handled separately from other METAs */
- uint32_t rg_useddi; /* Number (qty) of dinodes (used or free) */
- uint32_t rg_freedi; /* Number (qty) of unused (free) dinodes */
- struct gfs2_inum rg_freedi_list; /* 1st block in chain of free dinodes */
-
- /* These META statistics do not include dinodes (used or free) */
- uint32_t rg_usedmeta; /* Number (qty) of used metadata blocks */
- uint32_t rg_freemeta; /* Number (qty) of unused metadata blocks */
-
- char rg_reserved[64];
-};
-
struct gfs2_dirents {
uint64_t block;
struct gfs2_dirent dirent;
@@ -189,35 +103,6 @@ struct blkstack_info {
struct metapath mp;
};
-struct gfs_sb {
- /* Order is important; need to be able to read old superblocks
- in order to support on-disk version upgrades */
- struct gfs2_meta_header sb_header;
-
- uint32_t sb_fs_format; /* GFS_FORMAT_FS (on-disk version) */
- uint32_t sb_multihost_format; /* GFS_FORMAT_MULTI */
- uint32_t sb_flags; /* ?? */
-
- uint32_t sb_bsize; /* fundamental FS block size in bytes */
- uint32_t sb_bsize_shift; /* log2(sb_bsize) */
- uint32_t sb_seg_size; /* Journal segment size in FS blocks */
-
- /* These special inodes do not appear in any on-disk directory. */
- struct gfs2_inum sb_jindex_di; /* journal index inode */
- struct gfs2_inum sb_rindex_di; /* resource group index inode */
- struct gfs2_inum sb_root_di; /* root directory inode */
-
- /* Default inter-node locking protocol (lock module) and namespace */
- char sb_lockproto[GFS2_LOCKNAME_LEN]; /* lock protocol name */
- char sb_locktable[GFS2_LOCKNAME_LEN]; /* unique name for this FS */
-
- /* More special inodes */
- struct gfs2_inum sb_quota_di; /* quota inode */
- struct gfs2_inum sb_license_di; /* license inode */
-
- char sb_reserved[96];
-};
-
extern struct blkstack_info blockstack[BLOCK_STACK_SIZE];
extern struct iinfo *indirect; /* more than the most indirect
pointers possible for any given 4K block */
@@ -226,17 +111,6 @@ extern int indirect_blocks; /* count of indirect blocks */
extern enum dsp_mode dmode;
/* ------------------------------------------------------------------------ */
-/* risize - size of one rindex entry, whether gfs1 or gfs2 */
-/* ------------------------------------------------------------------------ */
-static inline int risize(void)
-{
- if (sbd.gfs1)
- return sizeof(struct gfs_rindex);
- else
- return sizeof(struct gfs2_rindex);
-}
-
-/* ------------------------------------------------------------------------ */
/* block_is_rglist - there's no such block as the rglist. This is a */
/* special case meant to parse the rindex and follow the */
/* blocks to the real rgs. */
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 82c39f1..254a8e6 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -568,6 +568,100 @@ struct gfs_dinode {
char di_reserved[56];
};
+struct gfs_sb {
+ /* Order is important; need to be able to read old superblocks
+ in order to support on-disk version upgrades */
+ struct gfs2_meta_header sb_header;
+
+ uint32_t sb_fs_format; /* GFS_FORMAT_FS (on-disk version) */
+ uint32_t sb_multihost_format; /* GFS_FORMAT_MULTI */
+ uint32_t sb_flags; /* ?? */
+
+ uint32_t sb_bsize; /* fundamental FS block size in bytes */
+ uint32_t sb_bsize_shift; /* log2(sb_bsize) */
+ uint32_t sb_seg_size; /* Journal segment size in FS blocks */
+
+ /* These special inodes do not appear in any on-disk directory. */
+ struct gfs2_inum sb_jindex_di; /* journal index inode */
+ struct gfs2_inum sb_rindex_di; /* resource group index inode */
+ struct gfs2_inum sb_root_di; /* root directory inode */
+
+ /* Default inter-node locking protocol (lock module) and namespace */
+ char sb_lockproto[GFS2_LOCKNAME_LEN]; /* lock protocol name */
+ char sb_locktable[GFS2_LOCKNAME_LEN]; /* unique name for this FS */
+
+ /* More special inodes */
+ struct gfs2_inum sb_quota_di; /* quota inode */
+ struct gfs2_inum sb_license_di; /* license inode */
+
+ char sb_reserved[96];
+};
+
+struct gfs_rgrp {
+ struct gfs2_meta_header rg_header;
+
+ uint32_t rg_flags; /* ?? */
+
+ uint32_t rg_free; /* Number (qty) of free data blocks */
+
+ /* Dinodes are USEDMETA, but are handled separately from other METAs */
+ uint32_t rg_useddi; /* Number (qty) of dinodes (used or free) */
+ uint32_t rg_freedi; /* Number (qty) of unused (free) dinodes */
+ struct gfs2_inum rg_freedi_list; /* 1st block in chain of free dinodes */
+
+ /* These META statistics do not include dinodes (used or free) */
+ uint32_t rg_usedmeta; /* Number (qty) of used metadata blocks */
+ uint32_t rg_freemeta; /* Number (qty) of unused metadata blocks */
+
+ char rg_reserved[64];
+};
+
+struct gfs_log_header {
+ struct gfs2_meta_header lh_header;
+
+ uint32_t lh_flags; /* GFS_LOG_HEAD_... */
+ uint32_t lh_pad;
+
+ uint64_t lh_first; /* Block number of first header in this trans */
+ uint64_t lh_sequence; /* Sequence number of this transaction */
+
+ uint64_t lh_tail; /* Block number of log tail */
+ uint64_t lh_last_dump; /* Block number of last dump */
+
+ char lh_reserved[64];
+};
+
+struct gfs_rindex {
+ uint64_t ri_addr; /* block # of 1st block (header) in rgrp */
+ uint32_t ri_length; /* # fs blocks containing rgrp header & bitmap */
+ uint32_t ri_pad;
+
+ uint64_t ri_data1; /* block # of first data/meta block in rgrp */
+ uint32_t ri_data; /* number (qty) of data/meta blocks in rgrp */
+
+ uint32_t ri_bitbytes; /* total # bytes used by block alloc bitmap */
+
+ char ri_reserved[64];
+};
+
+struct gfs_jindex {
+ uint64_t ji_addr; /* starting block of the journal */
+ uint32_t ji_nsegment; /* number (quantity) of segments in journal */
+ uint32_t ji_pad;
+
+ char ji_reserved[64];
+};
+
+struct gfs_log_descriptor {
+ struct gfs2_meta_header ld_header;
+
+ uint32_t ld_type; /* GFS_LOG_DESC_... Type of this log chunk */
+ uint32_t ld_length; /* Number of buffers in this chunk */
+ uint32_t ld_data1; /* descriptor-specific field */
+ uint32_t ld_data2; /* descriptor-specific field */
+ char ld_reserved[64];
+};
+
extern void gfs1_lookup_block(struct gfs2_inode *ip,
struct gfs2_buffer_head *bh,
unsigned int height, struct metapath *mp,
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index ee18850..9e8d079 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -145,7 +145,10 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
{
unsigned int rg;
int error;
- struct gfs2_rindex buf;
+ union {
+ struct gfs_rindex bufgfs1;
+ struct gfs2_rindex bufgfs2;
+ } buf;
struct rgrp_list *rgd, *prev_rgd;
uint64_t prev_length = 0;
@@ -157,8 +160,14 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
for (rg = 0; ; rg++) {
if (fd > 0)
error = read(fd, &buf, sizeof(struct gfs2_rindex));
+ else if (sdp->gfs1)
+ error = gfs1_readi(sdp->md.riinode,
+ (char *)&buf.bufgfs1,
+ rg * sizeof(struct gfs2_rindex),
+ sizeof(struct gfs2_rindex));
else
- error = gfs2_readi(sdp->md.riinode, (char *)&buf,
+ error = gfs2_readi(sdp->md.riinode,
+ (char *)&buf.bufgfs2,
rg * sizeof(struct gfs2_rindex),
sizeof(struct gfs2_rindex));
if (!error)
@@ -174,23 +183,27 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
memset(rgd, 0, sizeof(struct rgrp_list));
osi_list_add_prev(&rgd->list, &sdp->rglist);
rgd->start = rgd->ri.ri_addr;
if (prev_rgd) {
/* If rg addresses go backwards, it's not sane
(or it's converted from gfs1). */
- if (prev_rgd->start >= rgd->start)
- *sane = 0;
- /* If rg lengths are not consistent, it's not sane
- (or it's converted from gfs1). The first RG will
- be a different length due to space allocated for
- the superblock, so we can't detect this until
- we check rgrp 3, when we can compare the distance
- between rgrp 1 and rgrp 2. */
- if (rg > 2 && prev_length &&
- prev_length != rgd->start - prev_rgd->start)
- *sane = 0;
+ if (!sdp->gfs1) {
+ if (prev_rgd->start >= rgd->start)
+ *sane = 0;
+ /* If rg lengths are not consistent, it's not
+ sane (or it's converted from gfs1). The
+ first RG will be a different length due to
+ space allocated for the superblock, so we
+ can't detect this until we check rgrp 3,
+ when we can compare the distance between
+ rgrp 1 and rgrp 2. */
+ if (rg > 2 && prev_length &&
+ prev_length != rgd->start -
+ prev_rgd->start)
+ *sane = 0;
+ }
prev_length = rgd->start - prev_rgd->start;
prev_rgd->length = prev_length;
}
--
1.7.4.4
01-20-2012, 02:09 PM
libgfs2: move gfs1 structures to libgfs2
From: Bob Peterson <rpeterso@redhat.com>
This patch moves a number of gfs1-specific structures from gfs2_edit to
libgfs2 so other utils can reference them.
It also changes function rindex_read so it can operate on gfs1 or gfs2
rindex files.
-struct gfs_jindex {
- uint64_t ji_addr; /* starting block of the journal */
- uint32_t ji_nsegment; /* number (quantity) of segments in journal */
- uint32_t ji_pad;
-
- char ji_reserved[64];
-};
-
-struct gfs_log_descriptor {
- struct gfs2_meta_header ld_header;
-
- uint32_t ld_type; /* GFS_LOG_DESC_... Type of this log chunk */
- uint32_t ld_length; /* Number of buffers in this chunk */
- uint32_t ld_data1; /* descriptor-specific field */
- uint32_t ld_data2; /* descriptor-specific field */
- char ld_reserved[64];
-};
-
-struct gfs_log_header {
- struct gfs2_meta_header lh_header;
-
- uint32_t lh_flags; /* GFS_LOG_HEAD_... */
- uint32_t lh_pad;
-
- uint64_t lh_first; /* Block number of first header in this trans */
- uint64_t lh_sequence; /* Sequence number of this transaction */
-
- uint64_t lh_tail; /* Block number of log tail */
- uint64_t lh_last_dump; /* Block number of last dump */
-
- char lh_reserved[64];
-};
-
-struct gfs_rindex {
- uint64_t ri_addr; /* block # of 1st block (header) in rgrp */
- uint32_t ri_length; /* # fs blocks containing rgrp header & bitmap */
- uint32_t ri_pad;
-
- uint64_t ri_data1; /* block # of first data/meta block in rgrp */
- uint32_t ri_data; /* number (qty) of data/meta blocks in rgrp */
-
- uint32_t ri_bitbytes; /* total # bytes used by block alloc bitmap */
-
- char ri_reserved[64];
-};
-
-struct gfs_rgrp {
- struct gfs2_meta_header rg_header;
-
- uint32_t rg_flags; /* ?? */
-
- uint32_t rg_free; /* Number (qty) of free data blocks */
-
- /* Dinodes are USEDMETA, but are handled separately from other METAs */
- uint32_t rg_useddi; /* Number (qty) of dinodes (used or free) */
- uint32_t rg_freedi; /* Number (qty) of unused (free) dinodes */
- struct gfs2_inum rg_freedi_list; /* 1st block in chain of free dinodes */
-
- /* These META statistics do not include dinodes (used or free) */
- uint32_t rg_usedmeta; /* Number (qty) of used metadata blocks */
- uint32_t rg_freemeta; /* Number (qty) of unused metadata blocks */
-
- char rg_reserved[64];
-};
-
struct gfs2_dirents {
uint64_t block;
struct gfs2_dirent dirent;
@@ -189,35 +103,6 @@ struct blkstack_info {
struct metapath mp;
};
-struct gfs_sb {
- /* Order is important; need to be able to read old superblocks
- in order to support on-disk version upgrades */
- struct gfs2_meta_header sb_header;
-
- uint32_t sb_fs_format; /* GFS_FORMAT_FS (on-disk version) */
- uint32_t sb_multihost_format; /* GFS_FORMAT_MULTI */
- uint32_t sb_flags; /* ?? */
-
- uint32_t sb_bsize; /* fundamental FS block size in bytes */
- uint32_t sb_bsize_shift; /* log2(sb_bsize) */
- uint32_t sb_seg_size; /* Journal segment size in FS blocks */
-
- /* These special inodes do not appear in any on-disk directory. */
- struct gfs2_inum sb_jindex_di; /* journal index inode */
- struct gfs2_inum sb_rindex_di; /* resource group index inode */
- struct gfs2_inum sb_root_di; /* root directory inode */
-
- /* Default inter-node locking protocol (lock module) and namespace */
- char sb_lockproto[GFS2_LOCKNAME_LEN]; /* lock protocol name */
- char sb_locktable[GFS2_LOCKNAME_LEN]; /* unique name for this FS */
-
- /* More special inodes */
- struct gfs2_inum sb_quota_di; /* quota inode */
- struct gfs2_inum sb_license_di; /* license inode */
-
- char sb_reserved[96];
-};
-
extern struct blkstack_info blockstack[BLOCK_STACK_SIZE];
extern struct iinfo *indirect; /* more than the most indirect
pointers possible for any given 4K block */
@@ -226,17 +111,6 @@ extern int indirect_blocks; /* count of indirect blocks */
extern enum dsp_mode dmode;
/* ------------------------------------------------------------------------ */
-/* risize - size of one rindex entry, whether gfs1 or gfs2 */
-/* ------------------------------------------------------------------------ */
-static inline int risize(void)
-{
- if (sbd.gfs1)
- return sizeof(struct gfs_rindex);
- else
- return sizeof(struct gfs2_rindex);
-}
-
-/* ------------------------------------------------------------------------ */
/* block_is_rglist - there's no such block as the rglist. This is a */
/* special case meant to parse the rindex and follow the */
/* blocks to the real rgs. */
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 6db9d6c..c7d5977 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -564,6 +564,100 @@ struct gfs_dinode {
char di_reserved[56];
};
+struct gfs_sb {
+ /* Order is important; need to be able to read old superblocks
+ in order to support on-disk version upgrades */
+ struct gfs2_meta_header sb_header;
+
+ uint32_t sb_fs_format; /* GFS_FORMAT_FS (on-disk version) */
+ uint32_t sb_multihost_format; /* GFS_FORMAT_MULTI */
+ uint32_t sb_flags; /* ?? */
+
+ uint32_t sb_bsize; /* fundamental FS block size in bytes */
+ uint32_t sb_bsize_shift; /* log2(sb_bsize) */
+ uint32_t sb_seg_size; /* Journal segment size in FS blocks */
+
+ /* These special inodes do not appear in any on-disk directory. */
+ struct gfs2_inum sb_jindex_di; /* journal index inode */
+ struct gfs2_inum sb_rindex_di; /* resource group index inode */
+ struct gfs2_inum sb_root_di; /* root directory inode */
+
+ /* Default inter-node locking protocol (lock module) and namespace */
+ char sb_lockproto[GFS2_LOCKNAME_LEN]; /* lock protocol name */
+ char sb_locktable[GFS2_LOCKNAME_LEN]; /* unique name for this FS */
+
+ /* More special inodes */
+ struct gfs2_inum sb_quota_di; /* quota inode */
+ struct gfs2_inum sb_license_di; /* license inode */
+
+ char sb_reserved[96];
+};
+
+struct gfs_rgrp {
+ struct gfs2_meta_header rg_header;
+
+ uint32_t rg_flags; /* ?? */
+
+ uint32_t rg_free; /* Number (qty) of free data blocks */
+
+ /* Dinodes are USEDMETA, but are handled separately from other METAs */
+ uint32_t rg_useddi; /* Number (qty) of dinodes (used or free) */
+ uint32_t rg_freedi; /* Number (qty) of unused (free) dinodes */
+ struct gfs2_inum rg_freedi_list; /* 1st block in chain of free dinodes */
+
+ /* These META statistics do not include dinodes (used or free) */
+ uint32_t rg_usedmeta; /* Number (qty) of used metadata blocks */
+ uint32_t rg_freemeta; /* Number (qty) of unused metadata blocks */
+
+ char rg_reserved[64];
+};
+
+struct gfs_log_header {
+ struct gfs2_meta_header lh_header;
+
+ uint32_t lh_flags; /* GFS_LOG_HEAD_... */
+ uint32_t lh_pad;
+
+ uint64_t lh_first; /* Block number of first header in this trans */
+ uint64_t lh_sequence; /* Sequence number of this transaction */
+
+ uint64_t lh_tail; /* Block number of log tail */
+ uint64_t lh_last_dump; /* Block number of last dump */
+
+ char lh_reserved[64];
+};
+
+struct gfs_rindex {
+ uint64_t ri_addr; /* block # of 1st block (header) in rgrp */
+ uint32_t ri_length; /* # fs blocks containing rgrp header & bitmap */
+ uint32_t ri_pad;
+
+ uint64_t ri_data1; /* block # of first data/meta block in rgrp */
+ uint32_t ri_data; /* number (qty) of data/meta blocks in rgrp */
+
+ uint32_t ri_bitbytes; /* total # bytes used by block alloc bitmap */
+
+ char ri_reserved[64];
+};
+
+struct gfs_jindex {
+ uint64_t ji_addr; /* starting block of the journal */
+ uint32_t ji_nsegment; /* number (quantity) of segments in journal */
+ uint32_t ji_pad;
+
+ char ji_reserved[64];
+};
+
+struct gfs_log_descriptor {
+ struct gfs2_meta_header ld_header;
+
+ uint32_t ld_type; /* GFS_LOG_DESC_... Type of this log chunk */
+ uint32_t ld_length; /* Number of buffers in this chunk */
+ uint32_t ld_data1; /* descriptor-specific field */
+ uint32_t ld_data2; /* descriptor-specific field */
+ char ld_reserved[64];
+};
+
extern void gfs1_lookup_block(struct gfs2_inode *ip,
struct gfs2_buffer_head *bh,
unsigned int height, struct metapath *mp,
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index 7c9f395..d902ba2 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -143,7 +143,10 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
{
unsigned int rg;
int error;
- struct gfs2_rindex buf;
+ union {
+ struct gfs_rindex bufgfs1;
+ struct gfs2_rindex bufgfs2;
+ } buf;
struct rgrp_list *rgd, *prev_rgd;
uint64_t prev_length = 0;
@@ -155,8 +158,14 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
for (rg = 0; ; rg++) {
if (fd > 0)
error = read(fd, &buf, sizeof(struct gfs2_rindex));
+ else if (sdp->gfs1)
+ error = gfs1_readi(sdp->md.riinode,
+ (char *)&buf.bufgfs1,
+ rg * sizeof(struct gfs2_rindex),
+ sizeof(struct gfs2_rindex));
else
- error = gfs2_readi(sdp->md.riinode, (char *)&buf,
+ error = gfs2_readi(sdp->md.riinode,
+ (char *)&buf.bufgfs2,
rg * sizeof(struct gfs2_rindex),
sizeof(struct gfs2_rindex));
if (!error)
@@ -172,23 +181,27 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
memset(rgd, 0, sizeof(struct rgrp_list));
osi_list_add_prev(&rgd->list, &sdp->rglist);
rgd->start = rgd->ri.ri_addr;
if (prev_rgd) {
/* If rg addresses go backwards, it's not sane
(or it's converted from gfs1). */
- if (prev_rgd->start >= rgd->start)
- *sane = 0;
- /* If rg lengths are not consistent, it's not sane
- (or it's converted from gfs1). The first RG will
- be a different length due to space allocated for
- the superblock, so we can't detect this until
- we check rgrp 3, when we can compare the distance
- between rgrp 1 and rgrp 2. */
- if (rg > 2 && prev_length &&
- prev_length != rgd->start - prev_rgd->start)
- *sane = 0;
+ if (!sdp->gfs1) {
+ if (prev_rgd->start >= rgd->start)
+ *sane = 0;
+ /* If rg lengths are not consistent, it's not
+ sane (or it's converted from gfs1). The
+ first RG will be a different length due to
+ space allocated for the superblock, so we
+ can't detect this until we check rgrp 3,
+ when we can compare the distance between
+ rgrp 1 and rgrp 2. */
+ if (rg > 2 && prev_length &&
+ prev_length != rgd->start -
+ prev_rgd->start)
+ *sane = 0;
+ }
prev_length = rgd->start - prev_rgd->start;
prev_rgd->length = prev_length;
}
--
1.7.7.5