libgfs2: Make check_sb and read_sb operate on gfs1
>From eb78d8bc0c745495cfbf48eacbdd2bc8c40687b4 Mon Sep 17 00:00:00 2001
From: Bob Peterson <rpeterso@redhat.com>
Date: Fri, 12 Aug 2011 14:46:22 -0500
Subject: [PATCH 04/56] libgfs2: Make check_sb and read_sb operate on gfs1
This patch adds "allow_gfs1" parameters to the read_sb and check_sb functions.
This will allow gfs2-utils to read and operate on gfs1 file systems in
follow-up patches.
@@ -672,8 +694,8 @@ extern int gfs2_next_rg_meta(struct rgrp_list *rgd, uint64_t *block,
extern int gfs2_next_rg_metatype(struct gfs2_sbd *sdp, struct rgrp_list *rgd,
uint64_t *block, uint32_t type, int first);
/* super.c */
-extern int check_sb(struct gfs2_sb *sb);
-extern int read_sb(struct gfs2_sbd *sdp);
+extern int check_sb(struct gfs2_sb *sb, int allow_gfs);
+extern int read_sb(struct gfs2_sbd *sdp, int allow_gfs);
extern int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane);
extern int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane);
extern int write_sb(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index 995e503..ee18850 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -20,9 +20,9 @@
* read and that the sizes of the various on-disk structures have not
* changed.
*
- * Returns: 0 on success, -1 on failure
+ * Returns: -1 on failure, 1 if this is gfs (gfs1), 2 if this is gfs2
*/
-int check_sb(struct gfs2_sb *sb)
+int check_sb(struct gfs2_sb *sb, int allow_gfs)
{
if (sb->sb_header.mh_magic != GFS2_MAGIC ||
sb->sb_header.mh_type != GFS2_METATYPE_SB) {
@@ -33,13 +33,16 @@ int check_sb(struct gfs2_sb *sb)
sb->sb_header.mh_type);
return -EINVAL;
}
- /* If format numbers match exactly, we're done. */
- if (sb->sb_fs_format != GFS2_FORMAT_FS ||
- sb->sb_multihost_format != GFS2_FORMAT_MULTI) {
+ if (sb->sb_fs_format == GFS_FORMAT_FS &&
+ sb->sb_header.mh_format == GFS_FORMAT_SB &&
+ sb->sb_multihost_format == GFS_FORMAT_MULTI) {
+ if (allow_gfs)
+ return 1;
+
log_crit("Old gfs1 file system detected.
");
return -EINVAL;
}
- return 0;
+ return 2;
}
@@ -51,31 +54,44 @@ int check_sb(struct gfs2_sb *sb)
* initializes various constants maintained in the super
* block
*
- * Returns: 0 on success, -1 on failure.
+ * allow_gfs - passed in as 1 if we're allowed to accept gfs1 file systems
+ *
+ * Returns: 0 on success, -1 on failure
+ * sdp->gfs1 will be set if this is gfs (gfs1)
*/
-int read_sb(struct gfs2_sbd *sdp)
+int read_sb(struct gfs2_sbd *sdp, int allow_gfs)
{
struct gfs2_buffer_head *bh;
uint64_t space = 0;
unsigned int x;
- int error;
+ int ret;
libgfs2: Make check_sb and read_sb operate on gfs1
From: Bob Peterson <rpeterso@redhat.com>
This patch adds "allow_gfs1" parameters to the read_sb and check_sb functions.
This will allow gfs2-utils to read and operate on gfs1 file systems in
follow-up patches.
@@ -673,8 +695,8 @@ extern int gfs2_next_rg_meta(struct rgrp_list *rgd, uint64_t *block,
extern int gfs2_next_rg_metatype(struct gfs2_sbd *sdp, struct rgrp_list *rgd,
uint64_t *block, uint32_t type, int first);
/* super.c */
-extern int check_sb(struct gfs2_sb *sb);
-extern int read_sb(struct gfs2_sbd *sdp);
+extern int check_sb(struct gfs2_sb *sb, int allow_gfs);
+extern int read_sb(struct gfs2_sbd *sdp, int allow_gfs);
extern int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane);
extern int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane);
extern int write_sb(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index f2dd171..7c9f395 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -18,9 +18,9 @@
* read and that the sizes of the various on-disk structures have not
* changed.
*
- * Returns: 0 on success, -1 on failure
+ * Returns: -1 on failure, 1 if this is gfs (gfs1), 2 if this is gfs2
*/
-int check_sb(struct gfs2_sb *sb)
+int check_sb(struct gfs2_sb *sb, int allow_gfs)
{
if (sb->sb_header.mh_magic != GFS2_MAGIC ||
sb->sb_header.mh_type != GFS2_METATYPE_SB) {
@@ -31,13 +31,16 @@ int check_sb(struct gfs2_sb *sb)
sb->sb_header.mh_type);
return -EINVAL;
}
- /* If format numbers match exactly, we're done. */
- if (sb->sb_fs_format != GFS2_FORMAT_FS ||
- sb->sb_multihost_format != GFS2_FORMAT_MULTI) {
+ if (sb->sb_fs_format == GFS_FORMAT_FS &&
+ sb->sb_header.mh_format == GFS_FORMAT_SB &&
+ sb->sb_multihost_format == GFS_FORMAT_MULTI) {
+ if (allow_gfs)
+ return 1;
+
log_crit("Old gfs1 file system detected.
");
return -EINVAL;
}
- return 0;
+ return 2;
}
@@ -49,31 +52,44 @@ int check_sb(struct gfs2_sb *sb)
* initializes various constants maintained in the super
* block
*
- * Returns: 0 on success, -1 on failure.
+ * allow_gfs - passed in as 1 if we're allowed to accept gfs1 file systems
+ *
+ * Returns: 0 on success, -1 on failure
+ * sdp->gfs1 will be set if this is gfs (gfs1)
*/
-int read_sb(struct gfs2_sbd *sdp)
+int read_sb(struct gfs2_sbd *sdp, int allow_gfs)
{
struct gfs2_buffer_head *bh;
uint64_t space = 0;
unsigned int x;
- int error;
+ int ret;