|
|
903fa7 |
commit 37cf0257bf6298df38ca74ee8577bac5a40e6598
|
|
|
903fa7 |
Author: Andrew Price <anprice@redhat.com>
|
|
|
903fa7 |
Date: Thu Feb 6 04:25:27 2014 +0000
|
|
|
903fa7 |
|
|
|
903fa7 |
libgfs2: Superblock building and writing improvements
|
|
|
903fa7 |
|
|
|
903fa7 |
build_sb was creating the sb, setting its fields from an sdp and then
|
|
|
903fa7 |
writing it, and also zeroing the gap before the sb on the device in a
|
|
|
903fa7 |
block-by-block way using buffer_heads.
|
|
|
903fa7 |
|
|
|
903fa7 |
This patch splits the build_sb function into lgfs2_sb_init and
|
|
|
903fa7 |
lgfs2_sb_write which operate on gfs2_sb structures instead of gfs2_sbds.
|
|
|
903fa7 |
lgfs2_sb_write now uses pwritev to zero the initial blocks and write the
|
|
|
903fa7 |
sb to an fd.
|
|
|
903fa7 |
|
|
|
903fa7 |
get_random_bytes has been moved into structures.c and made static as
|
|
|
903fa7 |
only lgfs2_sb_init now uses it.
|
|
|
903fa7 |
|
|
|
903fa7 |
Resolves: rhbz#1063842
|
|
|
903fa7 |
|
|
|
903fa7 |
Signed-off-by: Andrew Price <anprice@redhat.com>
|
|
|
903fa7 |
|
|
|
903fa7 |
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
|
|
|
903fa7 |
index 719ba9c..ce056a7 100644
|
|
|
903fa7 |
--- a/gfs2/convert/gfs2_convert.c
|
|
|
903fa7 |
+++ b/gfs2/convert/gfs2_convert.c
|
|
|
903fa7 |
@@ -2374,7 +2374,8 @@ int main(int argc, char **argv)
|
|
|
903fa7 |
bh = bread(&sb2, sb2.sb_addr);
|
|
|
903fa7 |
sb2.sd_sb.sb_fs_format = GFS2_FORMAT_FS;
|
|
|
903fa7 |
sb2.sd_sb.sb_multihost_format = GFS2_FORMAT_MULTI;
|
|
|
903fa7 |
- gfs2_sb_out(&sb2.sd_sb, bh);
|
|
|
903fa7 |
+ gfs2_sb_out(&sb2.sd_sb, bh->b_data);
|
|
|
903fa7 |
+ bmodified(bh);
|
|
|
903fa7 |
brelse(bh);
|
|
|
903fa7 |
|
|
|
903fa7 |
error = fsync(sb2.device_fd);
|
|
|
903fa7 |
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
|
|
|
903fa7 |
index f0d9789..36f6600 100644
|
|
|
903fa7 |
--- a/gfs2/edit/hexedit.c
|
|
|
903fa7 |
+++ b/gfs2/edit/hexedit.c
|
|
|
903fa7 |
@@ -2132,7 +2132,8 @@ static void process_field(const char *field, const char *nstr)
|
|
|
903fa7 |
gfs2_sb_assigns(&lsb, field, nstr);
|
|
|
903fa7 |
else
|
|
|
903fa7 |
gfs2_sb_assignval(&lsb, field, newval);
|
|
|
903fa7 |
- gfs2_sb_out(&lsb, rbh);
|
|
|
903fa7 |
+ gfs2_sb_out(&lsb, rbh->b_data);
|
|
|
903fa7 |
+ bmodified(rbh);
|
|
|
903fa7 |
if (!termlines)
|
|
|
903fa7 |
gfs2_sb_printval(&lsb, field);
|
|
|
903fa7 |
} else {
|
|
|
903fa7 |
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
|
|
|
903fa7 |
index 5758607..0f33aa6 100644
|
|
|
903fa7 |
--- a/gfs2/fsck/initialize.c
|
|
|
903fa7 |
+++ b/gfs2/fsck/initialize.c
|
|
|
903fa7 |
@@ -60,7 +60,7 @@ static int block_mounters(struct gfs2_sbd *sdp, int block_em)
|
|
|
903fa7 |
}
|
|
|
903fa7 |
}
|
|
|
903fa7 |
|
|
|
903fa7 |
- if (write_sb(sdp)) {
|
|
|
903fa7 |
+ if (lgfs2_sb_write(&sdp->sd_sb, sdp->device_fd, sdp->bsize)) {
|
|
|
903fa7 |
stack;
|
|
|
903fa7 |
return -1;
|
|
|
903fa7 |
}
|
|
|
903fa7 |
@@ -1130,7 +1130,6 @@ static int sb_repair(struct gfs2_sbd *sdp)
|
|
|
903fa7 |
{
|
|
|
903fa7 |
uint64_t half;
|
|
|
903fa7 |
uint32_t known_bsize = 0;
|
|
|
903fa7 |
- unsigned char uuid[16];
|
|
|
903fa7 |
int error = 0;
|
|
|
903fa7 |
|
|
|
903fa7 |
memset(&fix_md, 0, sizeof(fix_md));
|
|
|
903fa7 |
@@ -1205,9 +1204,8 @@ static int sb_repair(struct gfs2_sbd *sdp)
|
|
|
903fa7 |
}
|
|
|
903fa7 |
}
|
|
|
903fa7 |
/* Step 3 - Rebuild the lock protocol and file system table name */
|
|
|
903fa7 |
- strcpy(sdp->lockproto, GFS2_DEFAULT_LOCKPROTO);
|
|
|
903fa7 |
- strcpy(sdp->locktable, "unknown");
|
|
|
903fa7 |
if (query(_("Okay to fix the GFS2 superblock? (y/n)"))) {
|
|
|
903fa7 |
+ struct gfs2_sb sb;
|
|
|
903fa7 |
log_info(_("Found system master directory at: 0x%llx\n"),
|
|
|
903fa7 |
sdp->sd_sb.sb_master_dir.no_addr);
|
|
|
903fa7 |
sdp->master_dir = lgfs2_inode_read(sdp,
|
|
|
903fa7 |
@@ -1226,8 +1224,12 @@ static int sb_repair(struct gfs2_sbd *sdp)
|
|
|
903fa7 |
log_crit(_("Error reading root inode: %s\n"), strerror(errno));
|
|
|
903fa7 |
return -1;
|
|
|
903fa7 |
}
|
|
|
903fa7 |
- get_random_bytes(uuid, sizeof(uuid));
|
|
|
903fa7 |
- build_sb(sdp, uuid);
|
|
|
903fa7 |
+ lgfs2_sb_init(&sb, sdp->bsize);
|
|
|
903fa7 |
+ strcpy(sb.sb_lockproto, GFS2_DEFAULT_LOCKPROTO);
|
|
|
903fa7 |
+ strcpy(sb.sb_locktable, "unknown");
|
|
|
903fa7 |
+ sb.sb_master_dir = sdp->master_dir->i_di.di_num;
|
|
|
903fa7 |
+ sb.sb_root_dir = sdp->md.rooti->i_di.di_num;
|
|
|
903fa7 |
+ lgfs2_sb_write(&sb, sdp->device_fd, sdp->bsize);
|
|
|
903fa7 |
inode_put(&sdp->md.rooti);
|
|
|
903fa7 |
inode_put(&sdp->master_dir);
|
|
|
903fa7 |
sb_fixed = 1;
|
|
|
903fa7 |
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
|
|
|
903fa7 |
index e785017..6710e72 100644
|
|
|
903fa7 |
--- a/gfs2/libgfs2/libgfs2.h
|
|
|
903fa7 |
+++ b/gfs2/libgfs2/libgfs2.h
|
|
|
903fa7 |
@@ -724,7 +724,6 @@ extern int mount_gfs2_meta(struct gfs2_sbd *sdp);
|
|
|
903fa7 |
extern void cleanup_metafs(struct gfs2_sbd *sdp);
|
|
|
903fa7 |
extern int set_sysfs(const char *fsname, const char *filename, const char *val);
|
|
|
903fa7 |
extern int is_fsname(char *name);
|
|
|
903fa7 |
-extern void get_random_bytes(void *buf, int nbytes);
|
|
|
903fa7 |
|
|
|
903fa7 |
/* recovery.c */
|
|
|
903fa7 |
extern void gfs2_replay_incr_blk(struct gfs2_inode *ip, unsigned int *blk);
|
|
|
903fa7 |
@@ -758,7 +757,8 @@ static inline unsigned int rgrp_size(struct rgrp_tree *rgrp)
|
|
|
903fa7 |
|
|
|
903fa7 |
/* structures.c */
|
|
|
903fa7 |
extern int build_master(struct gfs2_sbd *sdp);
|
|
|
903fa7 |
-extern void build_sb(struct gfs2_sbd *sdp, const unsigned char *uuid);
|
|
|
903fa7 |
+extern void lgfs2_sb_init(struct gfs2_sb *sb, unsigned bsize);
|
|
|
903fa7 |
+extern int lgfs2_sb_write(const struct gfs2_sb *sb, int fd, const unsigned bsize);
|
|
|
903fa7 |
extern int build_journal(struct gfs2_sbd *sdp, int j,
|
|
|
903fa7 |
struct gfs2_inode *jindex);
|
|
|
903fa7 |
extern int build_jindex(struct gfs2_sbd *sdp);
|
|
|
903fa7 |
@@ -794,14 +794,14 @@ extern void print_it(const char *label, const char *fmt, const char *fmt2, ...)
|
|
|
903fa7 |
/* Translation functions */
|
|
|
903fa7 |
|
|
|
903fa7 |
extern void gfs2_inum_in(struct gfs2_inum *no, char *buf);
|
|
|
903fa7 |
-extern void gfs2_inum_out(struct gfs2_inum *no, char *buf);
|
|
|
903fa7 |
+extern void gfs2_inum_out(const struct gfs2_inum *no, char *buf);
|
|
|
903fa7 |
extern void gfs2_meta_header_in(struct gfs2_meta_header *mh,
|
|
|
903fa7 |
struct gfs2_buffer_head *bh);
|
|
|
903fa7 |
extern void gfs2_meta_header_out(const struct gfs2_meta_header *mh, char *buf);
|
|
|
903fa7 |
extern void gfs2_meta_header_out_bh(const struct gfs2_meta_header *mh,
|
|
|
903fa7 |
struct gfs2_buffer_head *bh);
|
|
|
903fa7 |
extern void gfs2_sb_in(struct gfs2_sb *sb, struct gfs2_buffer_head *bh);
|
|
|
903fa7 |
-extern void gfs2_sb_out(struct gfs2_sb *sb, struct gfs2_buffer_head *bh);
|
|
|
903fa7 |
+extern void gfs2_sb_out(const struct gfs2_sb *sb, char *buf);
|
|
|
903fa7 |
extern void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf);
|
|
|
903fa7 |
extern void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf);
|
|
|
903fa7 |
extern void gfs2_rgrp_in(struct gfs2_rgrp *rg, struct gfs2_buffer_head *bh);
|
|
|
903fa7 |
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
|
|
|
903fa7 |
index c4ed722..d707687 100644
|
|
|
903fa7 |
--- a/gfs2/libgfs2/misc.c
|
|
|
903fa7 |
+++ b/gfs2/libgfs2/misc.c
|
|
|
903fa7 |
@@ -17,7 +17,6 @@
|
|
|
903fa7 |
#include <dirent.h>
|
|
|
903fa7 |
#include <sys/sysmacros.h>
|
|
|
903fa7 |
#include <mntent.h>
|
|
|
903fa7 |
-#include <sys/time.h>
|
|
|
903fa7 |
#include <signal.h>
|
|
|
903fa7 |
|
|
|
903fa7 |
#include "libgfs2.h"
|
|
|
903fa7 |
@@ -304,47 +303,3 @@ int set_sysfs(const char *fsname, const char *filename, const char *val)
|
|
|
903fa7 |
close(fd);
|
|
|
903fa7 |
return 0;
|
|
|
903fa7 |
}
|
|
|
903fa7 |
-
|
|
|
903fa7 |
-/*
|
|
|
903fa7 |
- * get_random_bytes - Generate a series of random bytes using /dev/urandom.
|
|
|
903fa7 |
- *
|
|
|
903fa7 |
- * Modified from original code in gen_uuid.c in e2fsprogs/lib
|
|
|
903fa7 |
- */
|
|
|
903fa7 |
-void get_random_bytes(void *buf, int nbytes)
|
|
|
903fa7 |
-{
|
|
|
903fa7 |
- int i, n = nbytes, fd;
|
|
|
903fa7 |
- int lose_counter = 0;
|
|
|
903fa7 |
- unsigned char *cp = (unsigned char *) buf;
|
|
|
903fa7 |
- struct timeval tv;
|
|
|
903fa7 |
-
|
|
|
903fa7 |
- gettimeofday(&tv, 0);
|
|
|
903fa7 |
- fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
|
|
903fa7 |
- srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
|
|
|
903fa7 |
- /* Crank the random number generator a few times */
|
|
|
903fa7 |
- gettimeofday(&tv, 0);
|
|
|
903fa7 |
- for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
|
|
|
903fa7 |
- rand();
|
|
|
903fa7 |
- if (fd >= 0) {
|
|
|
903fa7 |
- while (n > 0) {
|
|
|
903fa7 |
- i = read(fd, cp, n);
|
|
|
903fa7 |
- if (i <= 0) {
|
|
|
903fa7 |
- if (lose_counter++ > 16)
|
|
|
903fa7 |
- break;
|
|
|
903fa7 |
- continue;
|
|
|
903fa7 |
- }
|
|
|
903fa7 |
- n -= i;
|
|
|
903fa7 |
- cp += i;
|
|
|
903fa7 |
- lose_counter = 0;
|
|
|
903fa7 |
- }
|
|
|
903fa7 |
- close(fd);
|
|
|
903fa7 |
- }
|
|
|
903fa7 |
-
|
|
|
903fa7 |
- /*
|
|
|
903fa7 |
- * We do this all the time, but this is the only source of
|
|
|
903fa7 |
- * randomness if /dev/random/urandom is out to lunch.
|
|
|
903fa7 |
- */
|
|
|
903fa7 |
- for (cp = buf, i = 0; i < nbytes; i++)
|
|
|
903fa7 |
- *cp++ ^= (rand() >> 7) & 0xFF;
|
|
|
903fa7 |
-
|
|
|
903fa7 |
- return;
|
|
|
903fa7 |
-}
|
|
|
903fa7 |
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
|
|
|
903fa7 |
index 4baacc7..43618bc 100644
|
|
|
903fa7 |
--- a/gfs2/libgfs2/ondisk.c
|
|
|
903fa7 |
+++ b/gfs2/libgfs2/ondisk.c
|
|
|
903fa7 |
@@ -48,7 +48,7 @@ void gfs2_inum_in(struct gfs2_inum *no, char *buf)
|
|
|
903fa7 |
CPIN_64(no, str, no_addr);
|
|
|
903fa7 |
}
|
|
|
903fa7 |
|
|
|
903fa7 |
-void gfs2_inum_out(struct gfs2_inum *no, char *buf)
|
|
|
903fa7 |
+void gfs2_inum_out(const struct gfs2_inum *no, char *buf)
|
|
|
903fa7 |
{
|
|
|
903fa7 |
struct gfs2_inum *str = (struct gfs2_inum *)buf;
|
|
|
903fa7 |
|
|
|
903fa7 |
@@ -124,11 +124,11 @@ void gfs2_sb_in(struct gfs2_sb *sb, struct gfs2_buffer_head *bh)
|
|
|
903fa7 |
#endif
|
|
|
903fa7 |
}
|
|
|
903fa7 |
|
|
|
903fa7 |
-void gfs2_sb_out(struct gfs2_sb *sb, struct gfs2_buffer_head *bh)
|
|
|
903fa7 |
+void gfs2_sb_out(const struct gfs2_sb *sb, char *buf)
|
|
|
903fa7 |
{
|
|
|
903fa7 |
- struct gfs2_sb *str = (struct gfs2_sb *)bh->b_data;
|
|
|
903fa7 |
+ struct gfs2_sb *str = (struct gfs2_sb *)buf;
|
|
|
903fa7 |
|
|
|
903fa7 |
- gfs2_meta_header_out_bh(&sb->sb_header, bh);
|
|
|
903fa7 |
+ gfs2_meta_header_out(&sb->sb_header, buf);
|
|
|
903fa7 |
|
|
|
903fa7 |
CPOUT_32(sb, str, sb_fs_format);
|
|
|
903fa7 |
CPOUT_32(sb, str, sb_multihost_format);
|
|
|
903fa7 |
@@ -144,7 +144,6 @@ void gfs2_sb_out(struct gfs2_sb *sb, struct gfs2_buffer_head *bh)
|
|
|
903fa7 |
#ifdef GFS2_HAS_UUID
|
|
|
903fa7 |
memcpy(str->sb_uuid, sb->sb_uuid, 16);
|
|
|
903fa7 |
#endif
|
|
|
903fa7 |
- bmodified(bh);
|
|
|
903fa7 |
}
|
|
|
903fa7 |
|
|
|
903fa7 |
const char *str_uuid(const unsigned char *uuid)
|
|
|
903fa7 |
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
|
|
|
903fa7 |
index e888f1e..2c1939a 100644
|
|
|
903fa7 |
--- a/gfs2/libgfs2/structures.c
|
|
|
903fa7 |
+++ b/gfs2/libgfs2/structures.c
|
|
|
903fa7 |
@@ -11,6 +11,7 @@
|
|
|
903fa7 |
#include <unistd.h>
|
|
|
903fa7 |
#include <errno.h>
|
|
|
903fa7 |
#include <linux/types.h>
|
|
|
903fa7 |
+#include <sys/time.h>
|
|
|
903fa7 |
|
|
|
903fa7 |
#include "libgfs2.h"
|
|
|
903fa7 |
|
|
|
903fa7 |
@@ -41,43 +42,102 @@ int build_master(struct gfs2_sbd *sdp)
|
|
|
903fa7 |
return 0;
|
|
|
903fa7 |
}
|
|
|
903fa7 |
|
|
|
903fa7 |
-void build_sb(struct gfs2_sbd *sdp, const unsigned char *uuid)
|
|
|
903fa7 |
+#ifdef GFS2_HAS_UUID
|
|
|
903fa7 |
+/**
|
|
|
903fa7 |
+ * Generate a series of random bytes using /dev/urandom.
|
|
|
903fa7 |
+ * Modified from original code in gen_uuid.c in e2fsprogs/lib
|
|
|
903fa7 |
+ */
|
|
|
903fa7 |
+static void get_random_bytes(void *buf, int nbytes)
|
|
|
903fa7 |
{
|
|
|
903fa7 |
- unsigned int x;
|
|
|
903fa7 |
- struct gfs2_buffer_head *bh;
|
|
|
903fa7 |
- struct gfs2_sb sb;
|
|
|
903fa7 |
-
|
|
|
903fa7 |
- /* Zero out the beginning of the device up to the superblock */
|
|
|
903fa7 |
- for (x = 0; x < sdp->sb_addr; x++) {
|
|
|
903fa7 |
- bh = bget(sdp, x);
|
|
|
903fa7 |
- memset(bh->b_data, 0, sdp->bsize);
|
|
|
903fa7 |
- bmodified(bh);
|
|
|
903fa7 |
- brelse(bh);
|
|
|
903fa7 |
+ int i, n = nbytes, fd;
|
|
|
903fa7 |
+ int lose_counter = 0;
|
|
|
903fa7 |
+ unsigned char *cp = (unsigned char *) buf;
|
|
|
903fa7 |
+ struct timeval tv;
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+ gettimeofday(&tv, 0);
|
|
|
903fa7 |
+ fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
|
|
903fa7 |
+ srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
|
|
|
903fa7 |
+ /* Crank the random number generator a few times */
|
|
|
903fa7 |
+ gettimeofday(&tv, 0);
|
|
|
903fa7 |
+ for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
|
|
|
903fa7 |
+ rand();
|
|
|
903fa7 |
+ if (fd >= 0) {
|
|
|
903fa7 |
+ while (n > 0) {
|
|
|
903fa7 |
+ i = read(fd, cp, n);
|
|
|
903fa7 |
+ if (i <= 0) {
|
|
|
903fa7 |
+ if (lose_counter++ > 16)
|
|
|
903fa7 |
+ break;
|
|
|
903fa7 |
+ continue;
|
|
|
903fa7 |
+ }
|
|
|
903fa7 |
+ n -= i;
|
|
|
903fa7 |
+ cp += i;
|
|
|
903fa7 |
+ lose_counter = 0;
|
|
|
903fa7 |
+ }
|
|
|
903fa7 |
+ close(fd);
|
|
|
903fa7 |
}
|
|
|
903fa7 |
|
|
|
903fa7 |
- memset(&sb, 0, sizeof(struct gfs2_sb));
|
|
|
903fa7 |
- sb.sb_header.mh_magic = GFS2_MAGIC;
|
|
|
903fa7 |
- sb.sb_header.mh_type = GFS2_METATYPE_SB;
|
|
|
903fa7 |
- sb.sb_header.mh_format = GFS2_FORMAT_SB;
|
|
|
903fa7 |
- sb.sb_fs_format = GFS2_FORMAT_FS;
|
|
|
903fa7 |
- sb.sb_multihost_format = GFS2_FORMAT_MULTI;
|
|
|
903fa7 |
- sb.sb_bsize = sdp->bsize;
|
|
|
903fa7 |
- sb.sb_bsize_shift = ffs(sdp->bsize) - 1;
|
|
|
903fa7 |
- sb.sb_master_dir = sdp->master_dir->i_di.di_num;
|
|
|
903fa7 |
- sb.sb_root_dir = sdp->md.rooti->i_di.di_num;
|
|
|
903fa7 |
- strcpy(sb.sb_lockproto, sdp->lockproto);
|
|
|
903fa7 |
- strcpy(sb.sb_locktable, sdp->locktable);
|
|
|
903fa7 |
+ /*
|
|
|
903fa7 |
+ * We do this all the time, but this is the only source of
|
|
|
903fa7 |
+ * randomness if /dev/random/urandom is out to lunch.
|
|
|
903fa7 |
+ */
|
|
|
903fa7 |
+ for (cp = buf, i = 0; i < nbytes; i++)
|
|
|
903fa7 |
+ *cp++ ^= (rand() >> 7) & 0xFF;
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+ return;
|
|
|
903fa7 |
+}
|
|
|
903fa7 |
+#endif
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+/**
|
|
|
903fa7 |
+ * Initialise a gfs2_sb structure with sensible defaults.
|
|
|
903fa7 |
+ */
|
|
|
903fa7 |
+void lgfs2_sb_init(struct gfs2_sb *sb, unsigned bsize)
|
|
|
903fa7 |
+{
|
|
|
903fa7 |
+ memset(sb, 0, sizeof(struct gfs2_sb));
|
|
|
903fa7 |
+ sb->sb_header.mh_magic = GFS2_MAGIC;
|
|
|
903fa7 |
+ sb->sb_header.mh_type = GFS2_METATYPE_SB;
|
|
|
903fa7 |
+ sb->sb_header.mh_format = GFS2_FORMAT_SB;
|
|
|
903fa7 |
+ sb->sb_fs_format = GFS2_FORMAT_FS;
|
|
|
903fa7 |
+ sb->sb_multihost_format = GFS2_FORMAT_MULTI;
|
|
|
903fa7 |
+ sb->sb_bsize = bsize;
|
|
|
903fa7 |
+ sb->sb_bsize_shift = ffs(bsize) - 1;
|
|
|
903fa7 |
#ifdef GFS2_HAS_UUID
|
|
|
903fa7 |
- memcpy(sb.sb_uuid, uuid, sizeof(sb.sb_uuid));
|
|
|
903fa7 |
+ get_random_bytes(&sb->sb_uuid, sizeof(sb->sb_uuid));
|
|
|
903fa7 |
#endif
|
|
|
903fa7 |
- bh = bget(sdp, sdp->sb_addr);
|
|
|
903fa7 |
- gfs2_sb_out(&sb, bh);
|
|
|
903fa7 |
- brelse(bh);
|
|
|
903fa7 |
+}
|
|
|
903fa7 |
|
|
|
903fa7 |
- if (sdp->debug) {
|
|
|
903fa7 |
- printf("\nSuper Block:\n");
|
|
|
903fa7 |
- gfs2_sb_print(&sb);
|
|
|
903fa7 |
+int lgfs2_sb_write(const struct gfs2_sb *sb, int fd, const unsigned bsize)
|
|
|
903fa7 |
+{
|
|
|
903fa7 |
+ int i, err = -1;
|
|
|
903fa7 |
+ struct iovec *iov;
|
|
|
903fa7 |
+ const size_t sb_addr = GFS2_SB_ADDR * GFS2_BASIC_BLOCK / bsize;
|
|
|
903fa7 |
+ const size_t len = sb_addr + 1;
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+ /* We only need 2 blocks: one for zeroing and a second for the superblock */
|
|
|
903fa7 |
+ char *buf = calloc(2, bsize);
|
|
|
903fa7 |
+ if (buf == NULL)
|
|
|
903fa7 |
+ return -1;
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+ iov = malloc(len * sizeof(*iov));
|
|
|
903fa7 |
+ if (iov == NULL)
|
|
|
903fa7 |
+ goto out_buf;
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+ for (i = 0; i < len; i++) {
|
|
|
903fa7 |
+ iov[i].iov_base = buf;
|
|
|
903fa7 |
+ iov[i].iov_len = bsize;
|
|
|
903fa7 |
}
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+ gfs2_sb_out(sb, buf + bsize);
|
|
|
903fa7 |
+ iov[sb_addr].iov_base = buf + bsize;
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+ if (pwritev(fd, iov, len, 0) < (len * bsize))
|
|
|
903fa7 |
+ goto out_iov;
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+ err = 0;
|
|
|
903fa7 |
+out_iov:
|
|
|
903fa7 |
+ free(iov);
|
|
|
903fa7 |
+out_buf:
|
|
|
903fa7 |
+ free(buf);
|
|
|
903fa7 |
+ return err;
|
|
|
903fa7 |
}
|
|
|
903fa7 |
|
|
|
903fa7 |
int write_journal(struct gfs2_sbd *sdp, unsigned int j, unsigned int blocks)
|
|
|
903fa7 |
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
|
|
|
903fa7 |
index d074236..b956366 100644
|
|
|
903fa7 |
--- a/gfs2/libgfs2/super.c
|
|
|
903fa7 |
+++ b/gfs2/libgfs2/super.c
|
|
|
903fa7 |
@@ -309,15 +309,3 @@ int gfs1_ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int quiet)
|
|
|
903fa7 |
|
|
|
903fa7 |
return __ri_update(sdp, fd, rgcount, &sane, quiet);
|
|
|
903fa7 |
}
|
|
|
903fa7 |
-
|
|
|
903fa7 |
-int write_sb(struct gfs2_sbd *sbp)
|
|
|
903fa7 |
-{
|
|
|
903fa7 |
- struct gfs2_buffer_head *bh;
|
|
|
903fa7 |
-
|
|
|
903fa7 |
- bh = bread(sbp, GFS2_SB_ADDR >> sbp->sd_fsb2bb_shift);
|
|
|
903fa7 |
- gfs2_sb_out(&sbp->sd_sb, bh);
|
|
|
903fa7 |
- brelse(bh);
|
|
|
903fa7 |
- fsync(sbp->device_fd); /* make sure the change gets to disk ASAP */
|
|
|
903fa7 |
- return 0;
|
|
|
903fa7 |
-}
|
|
|
903fa7 |
-
|
|
|
903fa7 |
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
|
|
|
903fa7 |
index 0d84064..8bd396a 100644
|
|
|
903fa7 |
--- a/gfs2/mkfs/main_mkfs.c
|
|
|
903fa7 |
+++ b/gfs2/mkfs/main_mkfs.c
|
|
|
903fa7 |
@@ -569,8 +569,8 @@ static void print_results(struct gfs2_sbd *sdp, uint64_t real_device_size,
|
|
|
903fa7 |
(unsigned long long)sdp->fssize, _("blocks"));
|
|
|
903fa7 |
printf("%-27s%u\n", _("Journals:"), sdp->md.journals);
|
|
|
903fa7 |
printf("%-27s%llu\n", _("Resource groups:"), (unsigned long long)sdp->rgrps);
|
|
|
903fa7 |
- printf("%-27s\"%s\"\n", _("Locking protocol:"), sdp->lockproto);
|
|
|
903fa7 |
- printf("%-27s\"%s\"\n", _("Lock table:"), sdp->locktable);
|
|
|
903fa7 |
+ printf("%-27s\"%s\"\n", _("Locking protocol:"), opts->lockproto);
|
|
|
903fa7 |
+ printf("%-27s\"%s\"\n", _("Lock table:"), opts->locktable);
|
|
|
903fa7 |
/* Translators: "UUID" = universally unique identifier. */
|
|
|
903fa7 |
printf("%-27s%s\n", _("UUID:"), str_uuid(uuid));
|
|
|
903fa7 |
}
|
|
|
903fa7 |
@@ -701,8 +701,6 @@ static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct mkfs_d
|
|
|
903fa7 |
/* TODO: Check if the fssize is too small, somehow */
|
|
|
903fa7 |
sdp->device.length = opts->fssize;
|
|
|
903fa7 |
}
|
|
|
903fa7 |
- strcpy(sdp->lockproto, opts->lockproto);
|
|
|
903fa7 |
- strcpy(sdp->locktable, opts->locktable);
|
|
|
903fa7 |
}
|
|
|
903fa7 |
|
|
|
903fa7 |
static int probe_contents(struct mkfs_dev *dev)
|
|
|
903fa7 |
@@ -791,11 +789,11 @@ static void open_dev(const char *path, struct mkfs_dev *dev)
|
|
|
903fa7 |
void main_mkfs(int argc, char *argv[])
|
|
|
903fa7 |
{
|
|
|
903fa7 |
struct gfs2_sbd sbd;
|
|
|
903fa7 |
+ struct gfs2_sb sb;
|
|
|
903fa7 |
struct mkfs_opts opts;
|
|
|
903fa7 |
struct mkfs_dev dev;
|
|
|
903fa7 |
lgfs2_rgrps_t rgs;
|
|
|
903fa7 |
int error;
|
|
|
903fa7 |
- unsigned char uuid[16];
|
|
|
903fa7 |
unsigned bsize;
|
|
|
903fa7 |
|
|
|
903fa7 |
opts_init(&opts);
|
|
|
903fa7 |
@@ -810,15 +808,16 @@ void main_mkfs(int argc, char *argv[])
|
|
|
903fa7 |
}
|
|
|
903fa7 |
|
|
|
903fa7 |
sbd_init(&sbd, &opts, &dev, bsize);
|
|
|
903fa7 |
+ lgfs2_sb_init(&sb, bsize);
|
|
|
903fa7 |
if (opts.debug) {
|
|
|
903fa7 |
printf(_("File system options:\n"));
|
|
|
903fa7 |
printf(" bsize = %u\n", sbd.bsize);
|
|
|
903fa7 |
printf(" qcsize = %u\n", sbd.qcsize);
|
|
|
903fa7 |
printf(" jsize = %u\n", sbd.jsize);
|
|
|
903fa7 |
printf(" journals = %u\n", sbd.md.journals);
|
|
|
903fa7 |
- printf(" proto = %s\n", sbd.lockproto);
|
|
|
903fa7 |
+ printf(" proto = %s\n", opts.lockproto);
|
|
|
903fa7 |
+ printf(" table = %s\n", opts.locktable);
|
|
|
903fa7 |
printf(" rgsize = %u\n", sbd.rgsize);
|
|
|
903fa7 |
- printf(" table = %s\n", sbd.locktable);
|
|
|
903fa7 |
printf(" fssize = %"PRIu64"\n", opts.fssize);
|
|
|
903fa7 |
printf(" sunit = %lu\n", opts.sunit);
|
|
|
903fa7 |
printf(" swidth = %lu\n", opts.swidth);
|
|
|
903fa7 |
@@ -838,8 +837,13 @@ void main_mkfs(int argc, char *argv[])
|
|
|
903fa7 |
exit(1);
|
|
|
903fa7 |
}
|
|
|
903fa7 |
sbd.rgtree.osi_node = lgfs2_rgrps_root(rgs); // Temporary
|
|
|
903fa7 |
+
|
|
|
903fa7 |
build_root(&sbd;;
|
|
|
903fa7 |
+ sb.sb_root_dir = sbd.md.rooti->i_di.di_num;
|
|
|
903fa7 |
+
|
|
|
903fa7 |
build_master(&sbd;;
|
|
|
903fa7 |
+ sb.sb_master_dir = sbd.master_dir->i_di.di_num;
|
|
|
903fa7 |
+
|
|
|
903fa7 |
error = build_jindex(&sbd;;
|
|
|
903fa7 |
if (error) {
|
|
|
903fa7 |
fprintf(stderr, _("Error building '%s': %s\n"), "jindex", strerror(errno));
|
|
|
903fa7 |
@@ -872,8 +876,9 @@ void main_mkfs(int argc, char *argv[])
|
|
|
903fa7 |
fprintf(stderr, _("Error building '%s': %s\n"), "quota", strerror(errno));
|
|
|
903fa7 |
exit(EXIT_FAILURE);
|
|
|
903fa7 |
}
|
|
|
903fa7 |
- get_random_bytes(uuid, sizeof(uuid));
|
|
|
903fa7 |
- build_sb(&sbd, uuid);
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+ strcpy(sb.sb_lockproto, opts.lockproto);
|
|
|
903fa7 |
+ strcpy(sb.sb_locktable, opts.locktable);
|
|
|
903fa7 |
|
|
|
903fa7 |
do_init_inum(&sbd;;
|
|
|
903fa7 |
do_init_statfs(&sbd;;
|
|
|
903fa7 |
@@ -884,6 +889,13 @@ void main_mkfs(int argc, char *argv[])
|
|
|
903fa7 |
inode_put(&sbd.md.statfs);
|
|
|
903fa7 |
|
|
|
903fa7 |
gfs2_rgrp_free(&sbd.rgtree);
|
|
|
903fa7 |
+
|
|
|
903fa7 |
+ error = lgfs2_sb_write(&sb, dev.fd, sbd.bsize);
|
|
|
903fa7 |
+ if (error) {
|
|
|
903fa7 |
+ perror(_("Failed to write superblock\n"));
|
|
|
903fa7 |
+ exit(EXIT_FAILURE);
|
|
|
903fa7 |
+ }
|
|
|
903fa7 |
+
|
|
|
903fa7 |
error = fsync(dev.fd);
|
|
|
903fa7 |
if (error){
|
|
|
903fa7 |
perror(opts.device);
|
|
|
903fa7 |
@@ -897,5 +909,5 @@ void main_mkfs(int argc, char *argv[])
|
|
|
903fa7 |
}
|
|
|
903fa7 |
|
|
|
903fa7 |
if (!opts.quiet)
|
|
|
903fa7 |
- print_results(&sbd, dev.size, &opts, uuid);
|
|
|
903fa7 |
+ print_results(&sbd, dev.size, &opts, sb.sb_uuid);
|
|
|
903fa7 |
}
|