cluster: RHEL6 - dlm_controld: full check for member changes
by David Teigland
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: d5ba0b947a8995b83df94c08497c451e4ad867ee
Parent: 867534832d5cc642a3c0692c2599cd01d38026e5
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Sep 28 11:33:50 2011 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Sep 28 11:33:50 2011 -0500
dlm_controld: full check for member changes
cman members are queried in response to a callback,
and members sometimes leave and rejoin between queries
(e.g. when they leave and rejoin before corosync
detects they left.)
This means that simply checking if a node is a member
in consecutive queries sometimes misses events. We
need to compare the incarnation numbers of members
from consecutive queries to avoid this.
bz 663397
Signed-off-by: David Teigland <teigland(a)redhat.com>
---
group/dlm_controld/member_cman.c | 79 ++++++++++++++++++++++++++++++++++++--
1 files changed, 75 insertions(+), 4 deletions(-)
diff --git a/group/dlm_controld/member_cman.c b/group/dlm_controld/member_cman.c
index c6b7cc7..2b115d5 100644
--- a/group/dlm_controld/member_cman.c
+++ b/group/dlm_controld/member_cman.c
@@ -9,6 +9,7 @@ static cman_node_t old_nodes[MAX_NODES];
static int old_node_count;
static cman_node_t cman_nodes[MAX_NODES];
static int cman_node_count;
+static uint32_t cluster_ringid_seq;
void kick_node_from_cluster(int nodeid)
{
@@ -22,6 +23,17 @@ void kick_node_from_cluster(int nodeid)
}
}
+static cman_node_t *get_node(cman_node_t *node_list, int count, int nodeid)
+{
+ int i;
+
+ for (i = 0; i < count; i++) {
+ if (node_list[i].cn_nodeid == nodeid)
+ return &node_list[i];
+ }
+ return NULL;
+}
+
static int is_member(cman_node_t *node_list, int count, int nodeid)
{
int i;
@@ -69,11 +81,21 @@ char *nodeid2name(int nodeid)
static void statechange(void)
{
+ cman_cluster_t info;
+ cman_node_t *old;
int i, j, rv;
struct cman_node_address addrs[MAX_NODE_ADDRESSES];
int num_addrs;
struct cman_node_address *addrptr = addrs;
+ rv = cman_get_cluster(ch, &info);
+ if (rv < 0) {
+ log_error("cman_get_cluster error %d %d", rv, errno);
+ /* keep going, this is just informational */
+ memset(&info, 0, sizeof(info));
+ }
+ cluster_ringid_seq = info.ci_generation;
+
cluster_quorate = cman_is_quorate(ch);
old_node_count = cman_node_count;
@@ -99,8 +121,8 @@ static void statechange(void)
if (old_nodes[i].cn_member &&
!is_cluster_member(old_nodes[i].cn_nodeid)) {
- log_debug("cluster node %d removed",
- old_nodes[i].cn_nodeid);
+ log_debug("cluster node %d removed seq %u",
+ old_nodes[i].cn_nodeid, cluster_ringid_seq);
node_history_cluster_remove(old_nodes[i].cn_nodeid);
@@ -112,6 +134,9 @@ static void statechange(void)
if (cman_nodes[i].cn_member &&
!is_old_member(cman_nodes[i].cn_nodeid)) {
+ log_debug("cluster node %d added seq %u",
+ cman_nodes[i].cn_nodeid, cluster_ringid_seq);
+
rv = cman_get_node_addrs(ch, cman_nodes[i].cn_nodeid,
MAX_NODE_ADDRESSES,
&num_addrs, addrs);
@@ -121,8 +146,54 @@ static void statechange(void)
addrptr = &cman_nodes[i].cn_address;
}
- log_debug("cluster node %d added",
- cman_nodes[i].cn_nodeid);
+ node_history_cluster_add(cman_nodes[i].cn_nodeid);
+
+ for (j = 0; j < num_addrs; j++) {
+ add_configfs_node(cman_nodes[i].cn_nodeid,
+ addrptr[j].cna_address,
+ addrptr[j].cna_addrlen,
+ (cman_nodes[i].cn_nodeid ==
+ our_nodeid));
+ }
+ } else {
+ /* look for any nodes that were members of both
+ * old and new but have a new incarnation number
+ * from old to new, indicating they left and rejoined
+ * in between */
+
+ old = get_node(old_nodes, old_node_count, cman_nodes[i].cn_nodeid);
+
+ if (!old)
+ continue;
+ if (cman_nodes[i].cn_incarnation == old->cn_incarnation)
+ continue;
+
+ log_debug("cluster node %d removed and added seq %u "
+ "old %u new %u",
+ cman_nodes[i].cn_nodeid, cluster_ringid_seq,
+ old->cn_incarnation,
+ cman_nodes[i].cn_incarnation);
+
+ /*
+ * remove (copied from above)
+ */
+
+ node_history_cluster_remove(old_nodes[i].cn_nodeid);
+
+ del_configfs_node(old_nodes[i].cn_nodeid);
+
+ /*
+ * add (copied from above)
+ */
+
+ rv = cman_get_node_addrs(ch, cman_nodes[i].cn_nodeid,
+ MAX_NODE_ADDRESSES,
+ &num_addrs, addrs);
+ if (rv < 0) {
+ log_debug("cman_get_node_addrs failed, falling back to single-homed. ");
+ num_addrs = 1;
+ addrptr = &cman_nodes[i].cn_address;
+ }
node_history_cluster_add(cman_nodes[i].cn_nodeid);
12 years, 7 months
cluster: RHEL6 - fenced: full check for member changes
by David Teigland
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 867534832d5cc642a3c0692c2599cd01d38026e5
Parent: c1421b402bbc86aae0940c05fa5684e46ac93c9c
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Sep 28 11:03:32 2011 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Sep 28 11:03:32 2011 -0500
fenced: full check for member changes
cman members are queried in response to a callback,
and members sometimes leave and rejoin between queries
(e.g. when they leave and rejoin before corosync
detects they left.)
This means that simply checking if a node is a member
in consecutive queries sometimes misses events. We
need to compare the incarnation numbers of members
from consecutive queries to avoid this.
bz 663397
Signed-off-by: David Teigland <teigland(a)redhat.com>
---
fence/fenced/member_cman.c | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/fence/fenced/member_cman.c b/fence/fenced/member_cman.c
index 0919b8e..ee879be 100644
--- a/fence/fenced/member_cman.c
+++ b/fence/fenced/member_cman.c
@@ -33,6 +33,17 @@ void kick_node_from_cluster(int nodeid)
}
}
+static cman_node_t *get_node(cman_node_t *node_list, int count, int nodeid)
+{
+ int i;
+
+ for (i = 0; i < count; i++) {
+ if (node_list[i].cn_nodeid == nodeid)
+ return &node_list[i];
+ }
+ return NULL;
+}
+
static int is_member(cman_node_t *node_list, int count, int nodeid)
{
int i;
@@ -149,6 +160,7 @@ int name_to_nodeid(char *name)
static void update_cluster(void)
{
cman_cluster_t info;
+ cman_node_t *old;
int quorate = cluster_quorate;
int removed = 0, added = 0;
int i, rv;
@@ -197,6 +209,30 @@ static void update_cluster(void)
node_history_cluster_add(cman_nodes[i].cn_nodeid);
added++;
+ } else {
+ /* look for any nodes that were members of both
+ * old and new but have a new incarnation number
+ * from old to new, indicating they left and rejoined
+ * in between */
+
+ old = get_node(old_nodes, old_node_count, cman_nodes[i].cn_nodeid);
+
+ if (!old)
+ continue;
+ if (cman_nodes[i].cn_incarnation == old->cn_incarnation)
+ continue;
+
+ log_debug("cluster node %d removed and added seq %u "
+ "old %u new %u",
+ cman_nodes[i].cn_nodeid, cluster_ringid_seq,
+ old->cn_incarnation,
+ cman_nodes[i].cn_incarnation);
+
+ node_history_cluster_remove(cman_nodes[i].cn_nodeid);
+ removed++;
+
+ node_history_cluster_add(cman_nodes[i].cn_nodeid);
+ added++;
}
}
12 years, 7 months
cluster: RHEL58 - gfs2_edit: Add compression to savemeta and restoremeta
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 0ef78df8e40c238e3b5734bfc45c43c77bb5252a
Parent: a9d8ba2cb7c5ac54569be83c9215c4c7f2ea1ca8
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed May 4 18:21:07 2011 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Sep 29 12:38:00 2011 +0100
gfs2_edit: Add compression to savemeta and restoremeta
This patch adds the ability to output gzip-compressed data with savemeta and
makes it the default behaviour. It also adds a -z <0-9> option to allow the
level of compression to be controlled, 0 meaning no compression and 9 being the
default. restoremeta can now restore from a gzip-compressed or raw metadata
file without any extra options.
The file opening, closing and writing code from savemeta has been moved into
savemeta{open,close,write} functions to abstract away compressed and
non-compressed file output.
Adds a dependency on zlib.
rhbz#702296
Signed-off-by: Andrew Price <anprice(a)redhat.com>
Reviewed-by: Steven Whitehouse <swhiteho(a)redhat.com>
---
gfs2/edit/Makefile | 2 +-
gfs2/edit/hexedit.c | 49 ++++++++--
gfs2/edit/hexedit.h | 2 +-
gfs2/edit/savemeta.c | 246 ++++++++++++++++++++++++++++++++++++++------------
gfs2/man/gfs2_edit.8 | 42 +++++----
5 files changed, 251 insertions(+), 90 deletions(-)
diff --git a/gfs2/edit/Makefile b/gfs2/edit/Makefile
index 6121791..aac03da 100644
--- a/gfs2/edit/Makefile
+++ b/gfs2/edit/Makefile
@@ -41,7 +41,7 @@ endif
all: gfs2_edit
gfs2_edit: ${SOURCE} hexedit.h extended.h gfs2hex.h ${LIBS}/libgfs2.a
- ${CC} ${CFLAGS} ${INCLUDE} -L${LIBS} ${LDFLAGS} ${SOURCE} ${LOADLIBES} ${LDLIBS} -lncurses -o $@ -lgfs2
+ ${CC} ${CFLAGS} ${INCLUDE} -L${LIBS} ${LDFLAGS} ${SOURCE} ${LOADLIBES} ${LDLIBS} -lncurses -lz -o $@ -lgfs2
install: all
if [ ! -d ${sbindir} ]; then \
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 6604376..3cc05f4 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -53,6 +53,7 @@ struct gfs2_log_header *llh;
struct gfs2_log_descriptor *lld;
int pgnum;
int details = 0;
+long int gziplevel = 9;
const char *prog_name;
@@ -3307,7 +3308,7 @@ static void dump_journal(const char *journal)
/* ------------------------------------------------------------------------ */
static void usage(void)
{
- fprintf(stderr,"\nFormat is: gfs2_edit [-c 1] [-V] [-x] [-h] [identify] [-p structures|blocks][blocktype][blockalloc [val]][blockbits][blockrg][find sb|rg|rb|di|in|lf|jd|lh|ld|ea|ed|lb|13|qc][field <f>[val]] /dev/device\n\n");
+ fprintf(stderr,"\nFormat is: gfs2_edit [-c 1] [-V] [-x] [-h] [identify] [-z <0-9>] [-p structures|blocks][blocktype][blockalloc [val]][blockbits][blockrg][find sb|rg|rb|di|in|lf|jd|lh|ld|ea|ed|lb|13|qc][field <f>[val]] /dev/device\n\n");
fprintf(stderr,"If only the device is specified, it enters into hexedit mode.\n");
fprintf(stderr,"identify - prints out only the block type, not the details.\n");
fprintf(stderr,"printsavedmeta - prints out the saved metadata blocks from a savemeta file.\n");
@@ -3348,6 +3349,8 @@ static void usage(void)
fprintf(stderr,"-p <b> find sb|rg|rb|di|in|lf|jd|lh|ld|ea|ed|lb|"
"13|qc - find block of given type after block <b>\n");
fprintf(stderr," <b> specifies the starting block for search\n");
+ fprintf(stderr,"-z 1 use gzip compression level 1 for savemeta (default 9)\n");
+ fprintf(stderr,"-z 0 do not use compression\n");
fprintf(stderr,"-s specifies a starting block such as root, rindex, quota, inum.\n");
fprintf(stderr,"-x print in hexmode.\n");
fprintf(stderr,"-h prints this help.\n\n");
@@ -3374,10 +3377,33 @@ static void usage(void)
fprintf(stderr," gfs2_edit -p quota find di /dev/x/y\n");
fprintf(stderr," To set the Resource Group flags for rg #7 to 3.\n");
fprintf(stderr," gfs2_edit rgflags 7 3 /dev/sdc2\n");
- fprintf(stderr," To save off all metadata for /dev/vg/lv:\n");
- fprintf(stderr," gfs2_edit savemeta /dev/vg/lv /tmp/metasave\n");
+ fprintf(stderr," To save off all metadata for /dev/vg/lv without compression:\n");
+ fprintf(stderr," gfs2_edit savemeta -z 0 /dev/vg/lv /tmp/metasave\n");
}/* usage */
+/**
+ * getgziplevel - Process the -z parameter to savemeta operations
+ * argv - argv
+ * i - a pointer to the argv index at which to begin processing
+ * The index pointed to by i will be incremented past the -z option if found
+ */
+static void getgziplevel(char *argv[], int *i)
+{
+ char *endptr;
+ (*i)++;
+ if (!strcasecmp(argv[*i], "-z")) {
+ (*i)++;
+ errno = 0;
+ gziplevel = strtol(argv[*i], &endptr, 10);
+ if (errno || endptr == argv[*i] || gziplevel < 0 || gziplevel > 9) {
+ fprintf(stderr, "Compression level out of range: %s\n", argv[*i]);
+ exit(-1);
+ }
+ } else {
+ (*i)--;
+ }
+}
+
/* ------------------------------------------------------------------------ */
/* parameterpass1 - pre-processing for command-line parameters */
/* ------------------------------------------------------------------------ */
@@ -3571,13 +3597,16 @@ static void process_parameters(int argc, char *argv[], int pass)
exit(EXIT_SUCCESS);
}
}
- else if (!strcasecmp(argv[i], "savemeta"))
- savemeta(argv[i+2], 0);
- else if (!strcasecmp(argv[i], "savemetaslow"))
- savemeta(argv[i+2], 1);
- else if (!strcasecmp(argv[i], "savergs"))
- savemeta(argv[i+2], 2);
- else if (isdigit(argv[i][0])) { /* decimal addr */
+ else if (!strcasecmp(argv[i], "savemeta")) {
+ getgziplevel(argv, &i);
+ savemeta(argv[i+2], 0, gziplevel);
+ } else if (!strcasecmp(argv[i], "savemetaslow")) {
+ getgziplevel(argv, &i);
+ savemeta(argv[i+2], 1, gziplevel);
+ } else if (!strcasecmp(argv[i], "savergs")) {
+ getgziplevel(argv, &i);
+ savemeta(argv[i+2], 2, gziplevel);
+ } else if (isdigit(argv[i][0])) { /* decimal addr */
sscanf(argv[i], "%"SCNd64, &temp_blk);
push_block(temp_blk);
} else {
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index 81637bc..8732c27 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -365,7 +365,7 @@ extern void gfs_log_header_in(struct gfs_log_header *head,
struct gfs2_buffer_head *bh);
extern void gfs_log_header_print(struct gfs_log_header *lh);
extern void gfs_dinode_in(struct gfs_dinode *di, struct gfs2_buffer_head *bh);
-extern void savemeta(char *out_fn, int saveoption);
+extern void savemeta(char *out_fn, int saveoption, int gziplevel);
extern void restoremeta(const char *in_fn, const char *out_device,
uint64_t printblocksonly);
extern int display(int identify_only);
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 1ca5b42..c868edd 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -29,6 +29,7 @@
#include <linux_endian.h>
#include <sys/time.h>
#include <linux/gfs2_ondisk.h>
+#include <zlib.h>
#include "osi_list.h"
#include "gfs2hex.h"
@@ -45,6 +46,13 @@ struct saved_metablock {
char buf[BUFSIZE];
};
+struct metafd {
+ int fd;
+ gzFile gzfd;
+ const char *filename;
+ int gziplevel;
+};
+
struct saved_metablock *savedata;
uint64_t last_fs_block, last_reported_block, blks_saved, total_out, pct;
uint64_t journal_blocks[MAX_JOURNALS_SAVED];
@@ -205,7 +213,97 @@ static void warm_fuzzy_stuff(uint64_t wfsblock, int force)
}
}
-static int save_block(int fd, int out_fd, uint64_t blk)
+/**
+ * Open a file and prepare it for writing by savemeta()
+ * out_fn: the path to the file, which will be truncated if it exists
+ * gziplevel: 0 - do not compress the file,
+ * 1-9 - use gzip compression level 1-9
+ * Returns a struct metafd containing the opened file descriptor
+ */
+static struct metafd savemetaopen(char *out_fn, int gziplevel)
+{
+ struct metafd mfd = {-1, NULL, NULL, gziplevel};
+ char gzmode[3] = "w9";
+ char dft_fn[] = DFT_SAVE_FILE;
+
+ if (!out_fn) {
+ out_fn = dft_fn;
+ mfd.fd = mkstemp(out_fn);
+ } else {
+ mfd.fd = open(out_fn, O_RDWR | O_CREAT, 0644);
+ }
+ mfd.filename = out_fn;
+
+ if (mfd.fd < 0) {
+ fprintf(stderr, "Can't open %s: %s\n", out_fn, strerror(errno));
+ exit(1);
+ }
+
+ if (ftruncate(mfd.fd, 0)) {
+ fprintf(stderr, "Can't truncate %s: %s\n", out_fn, strerror(errno));
+ exit(1);
+ }
+
+ if (gziplevel > 0) {
+ gzmode[1] = '0' + gziplevel;
+ mfd.gzfd = gzdopen(mfd.fd, gzmode);
+ if (!mfd.gzfd) {
+ fprintf(stderr, "gzdopen error: %s\n", strerror(errno));
+ exit(1);
+ }
+ }
+
+ return mfd;
+}
+
+/**
+ * Write nbyte bytes from buf to a file opened with savemetaopen()
+ * mfd: the file descriptor opened using savemetaopen()
+ * buf: the buffer to write data from
+ * nbyte: the number of bytes to write
+ * Returns the number of bytes written from buf or -1 on error
+ */
+static ssize_t savemetawrite(struct metafd *mfd, const void *buf, size_t nbyte)
+{
+ ssize_t ret;
+ int gzerr;
+ const char *gzerrmsg;
+
+ if (mfd->gziplevel == 0) {
+ return write(mfd->fd, buf, nbyte);
+ }
+
+ ret = gzwrite(mfd->gzfd, buf, nbyte);
+ if (ret != nbyte) {
+ gzerrmsg = gzerror(mfd->gzfd, &gzerr);
+ if (gzerr != Z_ERRNO) {
+ fprintf(stderr, "Error: zlib: %s\n", gzerrmsg);
+ }
+ }
+ return ret;
+}
+
+/**
+ * Closes a file descriptor previously opened using savemetaopen()
+ * mfd: the file descriptor previously opened using savemetaopen()
+ * Returns 0 on success or -1 on error
+ */
+static int savemetaclose(struct metafd *mfd)
+{
+ int gzret;
+ if (mfd->gziplevel > 0) {
+ gzret = gzclose(mfd->gzfd);
+ if (gzret == Z_STREAM_ERROR) {
+ fprintf(stderr, "gzclose: file is not valid\n");
+ return -1;
+ } else if (gzret == Z_ERRNO) {
+ return -1;
+ }
+ }
+ return close(mfd->fd);
+}
+
+static int save_block(int fd, struct metafd *mfd, uint64_t blk)
{
int blktype, blklen, outsz;
uint16_t trailing0;
@@ -240,11 +338,34 @@ static int save_block(int fd, int out_fd, uint64_t blk)
p--;
}
savedata->blk = cpu_to_be64(blk);
- do_write(out_fd, &savedata->blk, sizeof(savedata->blk));
+ if (savemetawrite(mfd, &savedata->blk, sizeof(savedata->blk)) !=
+ sizeof(savedata->blk)) {
+ fprintf(stderr, "write error: %s from %s:%d: "
+ "block %lld (0x%llx)\n", strerror(errno),
+ __FUNCTION__, __LINE__,
+ (unsigned long long)savedata->blk,
+ (unsigned long long)savedata->blk);
+ exit(-1);
+ }
outsz = blklen - trailing0;
savedata->siglen = cpu_to_be16(outsz);
- do_write(out_fd, &savedata->siglen, sizeof(savedata->siglen));
- do_write(out_fd, savedata->buf, outsz);
+ if (savemetawrite(mfd, &savedata->siglen, sizeof(savedata->siglen)) !=
+ sizeof(savedata->siglen)) {
+ fprintf(stderr, "write error: %s from %s:%d: "
+ "block %lld (0x%llx)\n", strerror(errno),
+ __FUNCTION__, __LINE__,
+ (unsigned long long)savedata->blk,
+ (unsigned long long)savedata->blk);
+ exit(-1);
+ }
+ if (savemetawrite(mfd, savedata->buf, outsz) != outsz) {
+ fprintf(stderr, "write error: %s from %s:%d: "
+ "block %lld (0x%llx)\n", strerror(errno),
+ __FUNCTION__, __LINE__,
+ (unsigned long long)savedata->blk,
+ (unsigned long long)savedata->blk);
+ exit(-1);
+ }
total_out += sizeof(savedata->blk) + sizeof(savedata->siglen) + outsz;
blks_saved++;
brelse(savebh);
@@ -254,7 +375,7 @@ static int save_block(int fd, int out_fd, uint64_t blk)
/*
* save_ea_block - save off an extended attribute block
*/
-static void save_ea_block(int out_fd, struct gfs2_buffer_head *metabh)
+static void save_ea_block(struct metafd *mfd, struct gfs2_buffer_head *metabh)
{
int i, e, ea_len = sbd.bsize;
struct gfs2_ea_header ea;
@@ -272,7 +393,7 @@ static void save_ea_block(int out_fd, struct gfs2_buffer_head *metabh)
b = (uint64_t *)(metabh->b_data);
b += charoff + i;
blk = be64_to_cpu(*b);
- save_block(sbd.device_fd, out_fd, blk);
+ save_block(sbd.device_fd, mfd, blk);
}
if (!ea.ea_rec_len)
break;
@@ -283,7 +404,7 @@ static void save_ea_block(int out_fd, struct gfs2_buffer_head *metabh)
/*
* save_indirect_blocks - save all indirect blocks for the given buffer
*/
-static void save_indirect_blocks(int out_fd, osi_list_t *cur_list,
+static void save_indirect_blocks(struct metafd *mfd, osi_list_t *cur_list,
struct gfs2_buffer_head *mybh, int height, int hgt)
{
uint64_t old_block = 0, indir_block;
@@ -303,10 +424,10 @@ static void save_indirect_blocks(int out_fd, osi_list_t *cur_list,
if (indir_block == old_block)
continue;
old_block = indir_block;
- blktype = save_block(sbd.device_fd, out_fd, indir_block);
+ blktype = save_block(sbd.device_fd, mfd, indir_block);
if (blktype == GFS2_METATYPE_EA) {
nbh = bread(&sbd, indir_block);
- save_ea_block(out_fd, nbh);
+ save_ea_block(mfd, nbh);
brelse(nbh);
}
if (height != hgt) { /* If not at max height */
@@ -322,7 +443,7 @@ static void save_indirect_blocks(int out_fd, osi_list_t *cur_list,
/*
* save_inode_data - save off important data associated with an inode
*
- * out_fd - destination file descriptor
+ * mfd - destination file descriptor
* block - block number of the inode to save the data for
*
* For user files, we don't want anything except all the indirect block
@@ -334,7 +455,7 @@ static void save_indirect_blocks(int out_fd, osi_list_t *cur_list,
* For file system journals, the "data" is a mixture of metadata and
* journaled data. We want all the metadata and none of the user data.
*/
-static void save_inode_data(int out_fd)
+static void save_inode_data(struct metafd *mfd)
{
uint32_t height;
struct gfs2_inode *inode;
@@ -371,7 +492,7 @@ static void save_inode_data(int out_fd)
for (tmp = prev_list->next; tmp != prev_list; tmp = tmp->next){
mybh = osi_list_entry(tmp, struct gfs2_buffer_head,
b_altlist);
- save_indirect_blocks(out_fd, cur_list, mybh,
+ save_indirect_blocks(mfd, cur_list, mybh,
height, i);
} /* for blocks at that height */
} /* for height */
@@ -399,7 +520,7 @@ static void save_inode_data(int out_fd)
old_leaf = leaf_no;
mybh = bread(&sbd, leaf_no);
if (gfs2_check_meta(mybh, GFS2_METATYPE_LF) == 0)
- save_block(sbd.device_fd, out_fd, leaf_no);
+ save_block(sbd.device_fd, mfd, leaf_no);
brelse(mybh);
}
}
@@ -408,17 +529,17 @@ static void save_inode_data(int out_fd)
struct gfs2_buffer_head *lbh;
lbh = bread(&sbd, inode->i_di.di_eattr);
- save_block(sbd.device_fd, out_fd, inode->i_di.di_eattr);
+ save_block(sbd.device_fd, mfd, inode->i_di.di_eattr);
gfs2_meta_header_in(&mh, lbh);
if (mh.mh_magic == GFS2_MAGIC &&
mh.mh_type == GFS2_METATYPE_EA)
- save_ea_block(out_fd, lbh);
+ save_ea_block(mfd, lbh);
else if (mh.mh_magic == GFS2_MAGIC &&
mh.mh_type == GFS2_METATYPE_IN)
- save_indirect_blocks(out_fd, cur_list, lbh, 2, 2);
+ save_indirect_blocks(mfd, cur_list, lbh, 2, 2);
else {
if (mh.mh_magic == GFS2_MAGIC) /* if it's metadata */
- save_block(sbd.device_fd, out_fd,
+ save_block(sbd.device_fd, mfd,
inode->i_di.di_eattr);
fprintf(stderr,
"\nWarning: corrupt extended "
@@ -518,32 +639,21 @@ static int next_rg_freemeta(struct gfs2_sbd *sdp, struct rgrp_list *rgd,
return 0;
}
-void savemeta(char *out_fn, int saveoption)
+void savemeta(char *out_fn, int saveoption, int gziplevel)
{
- int out_fd;
int slow;
osi_list_t *tmp;
int rgcount;
uint64_t jindex_block;
struct gfs2_buffer_head *lbh;
struct rgrp_list *last_rgd, *prev_rgd;
+ struct metafd mfd;
slow = (saveoption == 1);
sbd.md.journals = 1;
- if (!out_fn) {
- out_fn = strdup(DFT_SAVE_FILE);
- if (!out_fn)
- die("Can't allocate memory for the operation.\n");
- out_fd = mkstemp(out_fn);
- } else
- out_fd = open(out_fn, O_RDWR | O_CREAT, 0644);
-
- if (out_fd < 0)
- die("Can't open %s: %s\n", out_fn, strerror(errno));
-
- if (ftruncate(out_fd, 0))
- die("Can't truncate %s: %s\n", out_fn, strerror(errno));
+ mfd = savemetaopen(out_fn, gziplevel);
+
savedata = malloc(sizeof(struct saved_metablock));
if (!savedata)
die("Can't allocate memory for the operation.\n");
@@ -628,15 +738,15 @@ void savemeta(char *out_fn, int saveoption)
get_journal_inode_blocks();
if (!slow) {
/* Save off the superblock */
- save_block(sbd.device_fd, out_fd, 0x10 * (4096 / sbd.bsize));
+ save_block(sbd.device_fd, &mfd, 0x10 * (4096 / sbd.bsize));
/* If this is gfs1, save off the rindex because it's not
part of the file system as it is in gfs2. */
if (gfs1) {
int j;
block = sbd1->sb_rindex_di.no_addr;
- save_block(sbd.device_fd, out_fd, block);
- save_inode_data(out_fd);
+ save_block(sbd.device_fd, &mfd, block);
+ save_inode_data(&mfd);
/* In GFS1, journals aren't part of the RG space */
for (j = 0; j < journals_found; j++) {
log_debug("Saving journal #%d\n", j + 1);
@@ -644,7 +754,7 @@ void savemeta(char *out_fn, int saveoption)
block < journal_blocks[j] +
gfs1_journal_size;
block++)
- save_block(sbd.device_fd, out_fd, block);
+ save_block(sbd.device_fd, &mfd, block);
}
}
/* Walk through the resource groups saving everything within */
@@ -666,7 +776,7 @@ void savemeta(char *out_fn, int saveoption)
for (block = rgd->ri.ri_addr;
block < rgd->ri.ri_data0; block++) {
warm_fuzzy_stuff(block, FALSE);
- save_block(sbd.device_fd, out_fd, block);
+ save_block(sbd.device_fd, &mfd, block);
}
/* Save off the other metadata: inodes, etc. */
if (saveoption != 2) {
@@ -675,9 +785,9 @@ void savemeta(char *out_fn, int saveoption)
while (!gfs2_next_rg_meta(rgd, &block, first)){
warm_fuzzy_stuff(block, FALSE);
blktype = save_block(sbd.device_fd,
- out_fd, block);
+ &mfd, block);
if (blktype == GFS2_METATYPE_DI)
- save_inode_data(out_fd);
+ save_inode_data(&mfd);
first = 0;
}
/* Save off the free/unlinked meta blocks too.
@@ -686,7 +796,7 @@ void savemeta(char *out_fn, int saveoption)
while (!next_rg_freemeta(&sbd, rgd, &block,
first)) {
blktype = save_block(sbd.device_fd,
- out_fd, block);
+ &mfd, block);
first = 0;
}
}
@@ -695,7 +805,7 @@ void savemeta(char *out_fn, int saveoption)
}
if (slow) {
for (block = 0; block < last_fs_block; block++) {
- save_block(sbd.device_fd, out_fd, block);
+ save_block(sbd.device_fd, &mfd, block);
}
}
/* Clean up */
@@ -703,28 +813,33 @@ void savemeta(char *out_fn, int saveoption)
/* so we tell the user that we've processed everything. */
block = last_fs_block;
warm_fuzzy_stuff(block, TRUE);
- printf("\nMetadata saved to file %s.\n", out_fn);
+ printf("\nMetadata saved to file %s ", mfd.filename);
+ if (mfd.gziplevel) {
+ printf("(gzipped, level %d).\n", mfd.gziplevel);
+ } else {
+ printf("(uncompressed).\n");
+ }
free(savedata);
- close(out_fd);
+ savemetaclose(&mfd);
close(sbd.device_fd);
exit(0);
}
-static int restore_data(int fd, int in_fd, int printblocksonly,
+static int restore_data(int fd, gzFile *gzin_fd, int printblocksonly,
int find_highblk)
{
size_t rs;
uint64_t buf64, writes = 0, highest_valid_block = 0;
uint16_t buf16;
- int first = 1, pos;
+ int first = 1, pos, gzerr;
char rdbuf[256];
char gfs_superblock_id[8] = {0x01, 0x16, 0x19, 0x70,
0x00, 0x00, 0x00, 0x01};
if (!printblocksonly)
do_lseek(fd, 0);
- do_lseek(in_fd, 0);
- rs = read(in_fd, rdbuf, sizeof(rdbuf));
+ gzseek(gzin_fd, 0, SEEK_SET);
+ rs = gzread(gzin_fd, rdbuf, sizeof(rdbuf));
if (rs != sizeof(rdbuf)) {
fprintf(stderr, "Error: File is too small.\n");
return -1;
@@ -738,14 +853,20 @@ static int restore_data(int fd, int in_fd, int printblocksonly,
}
if (pos == sizeof(rdbuf) - sizeof(uint64_t) - sizeof(uint16_t))
pos = 0;
- do_lseek(in_fd, pos);
+ if (gzseek(gzin_fd, pos, SEEK_SET) != pos) {
+ fprintf(stderr, "bad seek: %s from %s:%d: "
+ "offset %lld (0x%llx)\n", strerror(errno),
+ __FUNCTION__, __LINE__, (unsigned long long)pos,
+ (unsigned long long)pos);
+ exit(-1);
+ }
blks_saved = total_out = 0;
last_fs_block = 0;
while (TRUE) {
struct gfs2_buffer_head dummy_bh;
memset(savedata, 0, sizeof(struct saved_metablock));
- rs = read(in_fd, &buf64, sizeof(uint64_t));
+ rs = gzread(gzin_fd, &buf64, sizeof(uint64_t));
if (!rs)
break;
if (rs != sizeof(uint64_t)) {
@@ -764,7 +885,15 @@ static int restore_data(int fd, int in_fd, int printblocksonly,
savedata->blk);
return -1;
}
- rs = read(in_fd, &buf16, sizeof(uint16_t));
+ if (gzread(gzin_fd, &buf16, sizeof(uint16_t)) !=
+ sizeof(uint16_t)) {
+ fprintf(stderr, "read error: %s from %s:%d: "
+ "block %lld (0x%llx)\n",
+ gzerror(gzin_fd, &gzerr), __FUNCTION__, __LINE__,
+ (unsigned long long)savedata->blk,
+ (unsigned long long)savedata->blk);
+ exit(-1);
+ }
savedata->siglen = be16_to_cpu(buf16);
if (savedata->siglen > sizeof(savedata->buf)) {
fprintf(stderr, "\nBad record length: %d for block #%"
@@ -773,11 +902,11 @@ static int restore_data(int fd, int in_fd, int printblocksonly,
return -1;
}
if (savedata->siglen &&
- read(in_fd, savedata->buf, savedata->siglen) !=
+ gzread(gzin_fd, savedata->buf, savedata->siglen) !=
savedata->siglen) {
fprintf(stderr, "read error: %s from %s:%d: "
"block %lld (0x%llx)\n",
- strerror(errno), __FUNCTION__, __LINE__,
+ gzerror(gzin_fd, &gzerr), __FUNCTION__, __LINE__,
(unsigned long long)savedata->blk,
(unsigned long long)savedata->blk);
exit(-1);
@@ -883,15 +1012,16 @@ static void complain(const char *complaint)
void restoremeta(const char *in_fn, const char *out_device,
uint64_t printblocksonly)
{
- int in_fd, error;
+ int error;
+ gzFile gzfd;
termlines = 0;
if (!in_fn)
complain("No source file specified.");
if (!printblocksonly && !out_device)
complain("No destination file system specified.");
- in_fd = open(in_fn, O_RDONLY);
- if (in_fd < 0)
+ gzfd = gzopen(in_fn, "rb");
+ if (!gzfd)
die("Can't open source file %s: %s\n",
in_fn, strerror(errno));
@@ -908,13 +1038,13 @@ void restoremeta(const char *in_fn, const char *out_device,
die("Can't allocate memory for the restore operation.\n");
blks_saved = 0;
- restore_data(sbd.device_fd, in_fd, printblocksonly, 1);
- error = restore_data(sbd.device_fd, in_fd, printblocksonly, 0);
+ restore_data(sbd.device_fd, gzfd, printblocksonly, 1);
+ error = restore_data(sbd.device_fd, gzfd, printblocksonly, 0);
printf("File %s %s %s.\n", in_fn,
(printblocksonly ? "print" : "restore"),
(error ? "error" : "successful"));
free(savedata);
- close(in_fd);
+ gzclose(gzfd);
if (!printblocksonly)
close(sbd.device_fd);
diff --git a/gfs2/man/gfs2_edit.8 b/gfs2/man/gfs2_edit.8
index d133956..cade7c8 100644
--- a/gfs2/man/gfs2_edit.8
+++ b/gfs2/man/gfs2_edit.8
@@ -140,7 +140,9 @@ Print program version information only.
.TP
\fB-x\fP
Print in hex mode.
-
+.TP
+\fB-z <0-9>\fP
+Compress metadata with gzip compression level 1 to 9 (default 9). 0 means no compression at all.
.TP
\fBrg\fP \fI<rg>\fR \fI<device>\fR
Print the contents of Resource Group \fI<rg>\fR on \fI<device>\fR.
@@ -171,35 +173,35 @@ that may be contained in the files. This option works quickly by
using the system bitmap blocks in the resource groups to determine the
location of all the metadata. If there is corruption
in the bitmaps, resource groups or rindex file, this method may fail and
-you may need to use the savemetaslow option.
-The destination file is not compressed. You may want to compress it
-with a program such as bzip2 before sending it for analysis.
+you may need to use the savemetaslow option. The destination file is
+compressed using gzip unless -z 0 is specified.
.TP
\fBsavemetaslow\fP \fI<device>\fR \fI<filename>\fR
Save off GFS2 metadata, as with the savemeta option, examining every
block in the file system for metadata. This option is less prone to failure
due to file system corruption than the savemeta option, but it is
-extremely slow.
+extremely slow. The destination file is compressed using gzip unless
+-z 0 is specified.
.TP
\fBsavergs\fP \fI<device>\fR \fI<filename>\fR
Save off only the GFS2 resource group metadata for the file system on the
-specified device to a file given by <filename>.
+specified device to a file given by <filename>. The destination file is
+compressed using gzip unless -z 0 is specified.
.TP
\fBrestoremeta\fP \fI<filename>\fR \fI<dest device>\fR
-Take a file created with the savemeta option and restores its
-contents on top of the specified destination device. \fBWARNING\fP:
-When you use this option, the file system and all data on the
-destination device is destroyed. Since only metadata (but no data)
-is restored, every file in the resulting file system is likely to be
-corrupt. The ONLY purpose of this option is to examine and debug file
-system problems by restoring and examining the state of the saved metadata.
-If the destination file system is the same size or larger than the source
-file system where the metadata was saved, the resulting file system
-will be the same size as the source. If the destination device is
-smaller than the source file system, gfs2_edit will restore as much as
-it can, then quit, leaving you with a file system that probably will not
-mount, but from which you might still be able to figure out what is
-wrong with the source file system.
+Take a compressed or uncompressed file created with the savemeta option and
+restores its contents on top of the specified destination device.
+\fBWARNING\fP: When you use this option, the file system and all data on the
+destination device is destroyed. Since only metadata (but no data) is
+restored, every file in the resulting file system is likely to be corrupt. The
+ONLY purpose of this option is to examine and debug file system problems by
+restoring and examining the state of the saved metadata. If the destination
+file system is the same size or larger than the source file system where the
+metadata was saved, the resulting file system will be the same size as the
+source. If the destination device is smaller than the source file system,
+gfs2_edit will restore as much as it can, then quit, leaving you with a file
+system that probably will not mount, but from which you might still be able to
+figure out what is wrong with the source file system.
.SH INTERACTIVE MODE
If you specify a device on the gfs2_edit command line and you specify
12 years, 7 months
gfs2-utils: master - gfs_controld: track membership changes
by David Teigland
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: 6d523768ac2689a8f860b73fdd822ed212f4bbc7
Parent: 8ac1662541ff772291118c57950b1199cc095a94
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Sep 28 14:28:51 2011 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Sep 28 14:28:51 2011 -0500
gfs_controld: track membership changes
Was using the wrong flag (CURRENT) to ask libquorum
for callbacks on all membership changes (CHANGES),
so they weren't being sent.
Signed-off-by: David Teigland <teigland(a)redhat.com>
---
group/gfs_controld/member_cman.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/group/gfs_controld/member_cman.c b/group/gfs_controld/member_cman.c
index 6d0e743..07fb982 100644
--- a/group/gfs_controld/member_cman.c
+++ b/group/gfs_controld/member_cman.c
@@ -103,7 +103,7 @@ int setup_cluster(void)
goto fail;
}
- err = quorum_trackstart(qh, CS_TRACK_CURRENT);
+ err = quorum_trackstart(qh, CS_TRACK_CHANGES);
if (err != CS_OK) {
log_error("quorum trackstart error %d", err);
goto fail;
12 years, 7 months
fence: master - fenced: track membership changes
by David Teigland
Gitweb: http://git.fedorahosted.org/git/fence.git?p=fence.git;a=commitdiff;h=de5a...
Commit: de5a4789c95777a10e9bd4d878c608257afa1d3e
Parent: 73c0f58f071d713bd3b634ffcfb1d02feba84fcc
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Sep 28 14:27:28 2011 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Sep 28 14:27:28 2011 -0500
fenced: track membership changes
Was using the wrong flag (CURRENT) to ask libquorum
for callbacks on all membership changes (CHANGES),
so they weren't being sent.
Signed-off-by: David Teigland <teigland(a)redhat.com>
---
fence/fenced/member_cman.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/fence/fenced/member_cman.c b/fence/fenced/member_cman.c
index cf32818..f0a9da4 100644
--- a/fence/fenced/member_cman.c
+++ b/fence/fenced/member_cman.c
@@ -151,7 +151,7 @@ int setup_cluster(void)
goto fail;
}
- err = quorum_trackstart(qh, CS_TRACK_CURRENT);
+ err = quorum_trackstart(qh, CS_TRACK_CHANGES);
if (err != CS_OK) {
log_error("quorum trackstart error %d", err);
goto fail;
12 years, 7 months
dlm: master - dlm_controld: track membership changes
by David Teigland
Gitweb: http://git.fedorahosted.org/git/dlm.git?p=dlm.git;a=commitdiff;h=e5292116...
Commit: e529211682418a8e33feafc9f703cff87e23aeba
Parent: 3f508eb876cd683658a9220c6c3a643dca7c3fe7
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Sep 28 14:10:11 2011 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Sep 28 14:16:48 2011 -0500
dlm_controld: track membership changes
Was using the wrong flag (CURRENT) to ask libquorum
for callbacks on all membership changes (CHANGES),
so they weren't being sent.
Also add some additional logging.
Signed-off-by: David Teigland <teigland(a)redhat.com>
---
group/dlm_controld/dlm_daemon.h | 1 +
group/dlm_controld/main.c | 1 +
group/dlm_controld/member_cman.c | 13 ++++++++++---
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/group/dlm_controld/dlm_daemon.h b/group/dlm_controld/dlm_daemon.h
index cb98b3d..6ac1651 100644
--- a/group/dlm_controld/dlm_daemon.h
+++ b/group/dlm_controld/dlm_daemon.h
@@ -81,6 +81,7 @@ extern int plock_fd;
extern int plock_ci;
extern struct list_head lockspaces;
extern int cluster_quorate;
+extern uint32_t cluster_ringid_seq;
extern int our_nodeid;
extern uint32_t control_minor;
extern uint32_t monitor_minor;
diff --git a/group/dlm_controld/main.c b/group/dlm_controld/main.c
index 2f023ee..0f6f13a 100644
--- a/group/dlm_controld/main.c
+++ b/group/dlm_controld/main.c
@@ -1246,6 +1246,7 @@ int plock_ci;
struct list_head lockspaces;
int cluster_quorate;
int our_nodeid;
+uint32_t cluster_ringid_seq;
uint32_t control_minor;
uint32_t monitor_minor;
uint32_t plock_minor;
diff --git a/group/dlm_controld/member_cman.c b/group/dlm_controld/member_cman.c
index b7fa8c3..a62ec36 100644
--- a/group/dlm_controld/member_cman.c
+++ b/group/dlm_controld/member_cman.c
@@ -42,7 +42,12 @@ static void quorum_callback(quorum_handle_t h, uint32_t quorate,
cs_error_t err;
int i, j, num_addrs;
+
cluster_quorate = quorate;
+ cluster_ringid_seq = (uint32_t)ring_seq;
+
+ log_debug("cluster quorum %u seq %u nodes %u",
+ cluster_quorate, cluster_ringid_seq, node_list_entries);
old_node_count = quorum_node_count;
memcpy(&old_nodes, &quorum_nodes, sizeof(old_nodes));
@@ -55,7 +60,8 @@ static void quorum_callback(quorum_handle_t h, uint32_t quorate,
for (i = 0; i < old_node_count; i++) {
if (!is_cluster_member(old_nodes[i])) {
- log_debug("cluster node %u removed", old_nodes[i]);
+ log_debug("cluster node %u removed seq %u",
+ old_nodes[i], cluster_ringid_seq);
node_history_cluster_remove(old_nodes[i]);
del_configfs_node(old_nodes[i]);
}
@@ -63,7 +69,8 @@ static void quorum_callback(quorum_handle_t h, uint32_t quorate,
for (i = 0; i < quorum_node_count; i++) {
if (!is_old_member(quorum_nodes[i])) {
- log_debug("cluster node %u added", quorum_nodes[i]);
+ log_debug("cluster node %u added seq %u",
+ quorum_nodes[i], cluster_ringid_seq);
node_history_cluster_add(quorum_nodes[i]);
err = corosync_cfg_get_node_addrs(ch, quorum_nodes[i],
@@ -127,7 +134,7 @@ int setup_cluster(void)
goto fail;
}
- err = quorum_trackstart(qh, CS_TRACK_CURRENT);
+ err = quorum_trackstart(qh, CS_TRACK_CHANGES);
if (err != CS_OK) {
log_error("quorum trackstart error %d", err);
goto fail;
12 years, 7 months
cluster: RHEL58 - libgfs2 limit major/minor numbers to 255
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: a9d8ba2cb7c5ac54569be83c9215c4c7f2ea1ca8
Parent: c4e83e3a01a31074800ba527c961f565247dd73f
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Thu Jul 7 11:12:00 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Wed Sep 28 09:20:30 2011 -0500
libgfs2 limit major/minor numbers to 255
This patch uses the macros for the major/minor numbers so that
the values are not limited to 255.
rhbz#714739
---
gfs2/libgfs2/misc.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 98ffb60..3ff1dc4 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -593,8 +593,8 @@ char *mp2fsname(char *mp)
return NULL;
memset(device_id, 0, sizeof(device_id));
- sprintf(device_id, "%u:%u", (uint32_t)MAJOR(statbuf.st_dev),
- (uint32_t)MINOR(statbuf.st_dev));
+ sprintf(device_id, "%i:%i", major(statbuf.st_dev),
+ minor(statbuf.st_dev));
d = opendir(SYS_BASE);
if (!d)
12 years, 7 months
gfs2-utils: master - mkfs: remove duplicated code to ask yes/no question
by cmaiolino
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: 8ac1662541ff772291118c57950b1199cc095a94
Parent: f768a73ba0657ae3d0d69eac3acd40c4f567c76a
Author: Carlos Maiolino <cmaiolino(a)redhat.com>
AuthorDate: Tue Sep 27 11:00:31 2011 -0300
Committer: Carlos Maiolino <cmaiolino(a)redhat.com>
CommitterDate: Tue Sep 27 15:23:17 2011 -0300
mkfs: remove duplicated code to ask yes/no question
This patch takes advantage of the are_you_sure() function
to ask a yes/no question within verify_bsize() function
---
gfs2/mkfs/main_mkfs.c | 9 +--------
1 files changed, 1 insertions(+), 8 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 8802ef7..0bd1410 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -350,14 +350,7 @@ static void verify_bsize(struct gfs2_sbd *sdp)
if (sdp->override)
return;
- printf( _("\nAre you sure you want to proceed? [y/n] "));
- if(!fgets(input, 32, stdin))
- die( _("unable to read from stdin\n"));
-
- if (input[0] != 'y')
- die( _("aborted\n"));
- else
- printf("\n");
+ are_you_sure();
}
}
12 years, 7 months
gfs2-utils: master - mkfs: Remove unneeded open/close fd test from are_you_sure()
by cmaiolino
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: f768a73ba0657ae3d0d69eac3acd40c4f567c76a
Parent: 7c04f8dd38116d9be206af538ee8a6fc1d9e39f9
Author: Carlos Maiolino <cmaiolino(a)redhat.com>
AuthorDate: Tue Sep 27 10:57:37 2011 -0300
Committer: Carlos Maiolino <cmaiolino(a)redhat.com>
CommitterDate: Tue Sep 27 15:23:17 2011 -0300
mkfs: Remove unneeded open/close fd test from are_you_sure()
are_you_sure() function should not make an open/close
test on the underlying device. The pourpose of this
function is just to ask a yes/no question to the user.
If we need a function to do this test, we should create
a new function with its specific pourpose.
This patch also fix a call to are_you_sure() function and
move the are_you_sure() function to the begining of the
file, allowing it to be used in another part of the code
---
gfs2/mkfs/main_mkfs.c | 75 ++++++++++++++++++++++--------------------------
1 files changed, 34 insertions(+), 41 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index cc678fe..8802ef7 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -289,6 +289,39 @@ static void test_locking(char *lockproto, char *locktable)
}
}
+/**
+ * are_you_sure - protect lusers from themselves
+ * @sdp: the command line
+ *
+ */
+
+static void are_you_sure(void)
+{
+ char *line = NULL;
+ size_t len = 0;
+ int ret = -1;
+ int res = 0;
+
+ do{
+ printf( _("Are you sure you want to proceed? [y/n]"));
+ ret = getline(&line, &len, stdin);
+ res = rpmatch(line);
+
+ if (res > 0){
+ free(line);
+ return;
+ }
+ if (!res){
+ printf("\n");
+ die( _("aborted\n"));
+ }
+
+ }while(ret >= 0);
+
+ if(line)
+ free(line);
+}
+
static void verify_bsize(struct gfs2_sbd *sdp)
{
unsigned int x;
@@ -448,46 +481,6 @@ fail:
exit(execv(args[0], args));
}
-/**
- * are_you_sure - protect lusers from themselves
- * @sdp: the command line
- *
- */
-
-static void are_you_sure(struct gfs2_sbd *sdp)
-{
- char *line = NULL;
- size_t len = 0;
- int fd;
- int ret = -1;
- int res = 0;
-
- fd = open(sdp->device_name, O_RDONLY|O_CLOEXEC);
- if (fd < 0)
- die( _("Error: device %s not found.\n"), sdp->device_name);
- printf( _("This will destroy any data on %s.\n"), sdp->device_name);
- check_dev_content(sdp->device_name);
- close(fd);
-
- do{
- printf( _("Are you sure you want to proceed? [y/n]"));
- ret = getline(&line, &len, stdin);
- res = rpmatch(line);
-
- if (res > 0){
- free(line);
- return;
- }
- if (!res){
- printf("\n");
- die( _("aborted\n"));
- }
-
- }while(ret >= 0);
-
- if(line)
- free(line);
-}
/**
* print_results - print out summary information
@@ -576,7 +569,7 @@ void main_mkfs(int argc, char *argv[])
}
if (!sdp->override)
- are_you_sure(sdp);
+ are_you_sure();
if (!S_ISREG(st_buf.st_mode) && device_topology(sdp)) {
fprintf(stderr, _("Device topology error\n"));
12 years, 7 months
gfs2-utils: master - mkfs: Use rpmatch() to yes/no questions
by cmaiolino
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: 7c04f8dd38116d9be206af538ee8a6fc1d9e39f9
Parent: bda17315a280e3d8e6fc5136c331a55b1d4af43b
Author: Carlos Maiolino <cmaiolino(a)redhat.com>
AuthorDate: Tue Sep 27 10:35:50 2011 -0300
Committer: Carlos Maiolino <cmaiolino(a)redhat.com>
CommitterDate: Tue Sep 27 15:23:07 2011 -0300
mkfs: Use rpmatch() to yes/no questions
This patch changes the are_you_sure() function
to make use of rpmatch() to identify the user's
answer in the language set in the i18n
Also add 2 another translatable strings
---
gfs2/mkfs/main_mkfs.c | 34 ++++++++++++++++++++++++----------
1 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 4751f19..cc678fe 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -78,7 +78,7 @@ static int discard_blocks(struct gfs2_sbd *sdp)
range[0] = 0;
range[1] = sdp->device.length * sdp->bsize;
if (sdp->debug)
- printf("Issuing discard ioctl: range: %llu - %llu...",
+ printf(_("Issuing discard ioctl: range: %llu - %llu..."),
(unsigned long long)range[0],
(unsigned long long)range[1]);
if (ioctl(sdp->device_fd, BLKDISCARD, &range) < 0) {
@@ -87,7 +87,7 @@ static int discard_blocks(struct gfs2_sbd *sdp)
return errno;
}
if (sdp->debug)
- printf("Successful.\n");
+ printf(_("Successful.\n"));
return 0;
}
@@ -456,8 +456,11 @@ fail:
static void are_you_sure(struct gfs2_sbd *sdp)
{
- char input[32];
+ char *line = NULL;
+ size_t len = 0;
int fd;
+ int ret = -1;
+ int res = 0;
fd = open(sdp->device_name, O_RDONLY|O_CLOEXEC);
if (fd < 0)
@@ -465,14 +468,25 @@ static void are_you_sure(struct gfs2_sbd *sdp)
printf( _("This will destroy any data on %s.\n"), sdp->device_name);
check_dev_content(sdp->device_name);
close(fd);
- printf( _("\nAre you sure you want to proceed? [y/n] "));
- if(!fgets(input, 32, stdin))
- die( _("unable to read from stdin\n"));
+
+ do{
+ printf( _("Are you sure you want to proceed? [y/n]"));
+ ret = getline(&line, &len, stdin);
+ res = rpmatch(line);
+
+ if (res > 0){
+ free(line);
+ return;
+ }
+ if (!res){
+ printf("\n");
+ die( _("aborted\n"));
+ }
+
+ }while(ret >= 0);
- if (input[0] != 'y')
- die( _("aborted\n"));
- else
- printf("\n");
+ if(line)
+ free(line);
}
/**
12 years, 7 months