gfs2-utils: RHEL7 - libgfs2: Refactor block allocation functions
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=81226a0b...
Commit: 81226a0bb89b5b926dd47481c2314202783812c0
Parent: cd71fe5817f52f598fa2b5254a39417199e57014
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed Jan 22 21:33:51 2014 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 16:55:32 2014 +0100
libgfs2: Refactor block allocation functions
Split the part of blk_alloc_in_rg which finds a free block out into a
separate find_free_block function. This will allow callers to have more
control over where blocks are allocated in future.
Also combine the old blk_alloc_i and lgfs2_dinode_alloc and meta_alloc
functions into a single block_alloc function which now acts as a backing
function for lgfs2_dinode_alloc and meta_alloc, which is renamed
lgfs2_meta_alloc. An exit() call from blk_alloc_i has been pushed down
into its callers and replaced with error returns where possible.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/fsck/metawalk.c | 7 ++-
gfs2/libgfs2/fs_ops.c | 119 +++++++++++++++++++++++------------------------
gfs2/libgfs2/gfs1.c | 6 ++-
gfs2/libgfs2/libgfs2.h | 2 +-
4 files changed, 70 insertions(+), 64 deletions(-)
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index 6c0e02b..3190681 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -1973,7 +1973,12 @@ int write_new_leaf(struct gfs2_inode *dip, int start_lindex, int num_copies,
}
/* allocate and write out a new leaf block */
- *bn = meta_alloc(dip);
+ if (lgfs2_meta_alloc(dip, bn)) {
+ log_err( _("Error: allocation failed while fixing directory leaf "
+ "pointers.\n"));
+ free(padbuf);
+ return -1;
+ }
fsck_blockmap_set(dip, *bn, _("directory leaf"), gfs2_leaf_blk);
log_err(_("A new directory leaf was allocated at block %lld "
"(0x%llx) to fill the %d (0x%x) pointer gap %s the existing "
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 9889e22..f59f014 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -112,24 +112,16 @@ void inode_put(struct gfs2_inode **ip_in)
*ip_in = NULL; /* make sure the memory isn't accessed again */
}
-static int blk_alloc_in_rg(struct gfs2_sbd *sdp, unsigned state, struct rgrp_tree *rgd, uint64_t *blkno)
+static uint64_t find_free_block(struct rgrp_tree *rgd)
{
- unsigned int release = 0;
- unsigned int bm;
- int error = -1;
+ unsigned bm;
+ uint64_t blkno = 0;
if (rgd == NULL || rgd->rg.rg_free == 0) {
errno = ENOSPC;
- return -1;
- }
-
- if (rgd->bh[0] == NULL) {
- if (gfs2_rgrp_read(sdp, rgd))
- return -1;
- release = 1;
+ return 0;
}
- *blkno = 0;
for (bm = 0; bm < rgd->ri.ri_length; bm++) {
unsigned long blk = 0;
struct gfs2_bitmap *bits = &rgd->bits[bm];
@@ -137,17 +129,20 @@ static int blk_alloc_in_rg(struct gfs2_sbd *sdp, unsigned state, struct rgrp_tre
blk = gfs2_bitfit((unsigned char *)rgd->bh[bm]->b_data + bits->bi_offset,
bits->bi_len, blk, GFS2_BLKST_FREE);
if (blk != BFITNOENT) {
- *blkno = blk + (bits->bi_start * GFS2_NBBY) + rgd->ri.ri_data0;
+ blkno = blk + (bits->bi_start * GFS2_NBBY) + rgd->ri.ri_data0;
break;
}
}
+ return blkno;
+}
- if (*blkno == 0)
- goto out;
+static int blk_alloc_in_rg(struct gfs2_sbd *sdp, unsigned state, struct rgrp_tree *rgd, uint64_t blkno)
+{
+ if (blkno == 0)
+ return -1;
- error = gfs2_set_bitmap(sdp, *blkno, state);
- if (error)
- goto out;
+ if (gfs2_set_bitmap(sdp, blkno, state))
+ return -1;
if (state == GFS2_BLKST_DINODE)
rgd->rg.rg_dinodes++;
@@ -159,50 +154,22 @@ static int blk_alloc_in_rg(struct gfs2_sbd *sdp, unsigned state, struct rgrp_tre
gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]);
sdp->blks_alloced++;
-out:
- if (release)
- gfs2_rgrp_relse(rgd);
- return error;
-}
-
-/**
- * Do not use this function, it's only here until we can kill it.
- * Use blk_alloc_in_rg directly instead.
- */
-static uint64_t blk_alloc_i(struct gfs2_sbd *sdp, unsigned int type)
-{
- int ret;
- uint64_t blkno = 0;
- struct osi_node *n = NULL;
- for (n = osi_first(&sdp->rgtree); n; n = osi_next(n)) {
- if (((struct rgrp_tree *)n)->rg.rg_free)
- break;
- }
- ret = blk_alloc_in_rg(sdp, type, (struct rgrp_tree *)n, &blkno);
- if (ret != 0) /* Do what the old blk_alloc_i did */
- exit(1);
- return blkno;
-}
-
-uint64_t meta_alloc(struct gfs2_inode *ip)
-{
- uint64_t x;
- x = blk_alloc_i(ip->i_sbd, GFS2_BLKST_USED);
- ip->i_di.di_goal_meta = x;
- bmodified(ip->i_bh);
- return x;
+ return 0;
}
/**
- * Allocate a dinode block in a bitmap. In order to plan ahead we look for a
- * resource group with blksreq free blocks but only allocate the one dinode block.
+ * Allocate a block in a bitmap. In order to plan ahead we look for a
+ * resource group with blksreq free blocks but only allocate the one block.
* Returns 0 on success with the allocated block number in *blkno or non-zero otherwise.
*/
-int lgfs2_dinode_alloc(struct gfs2_sbd *sdp, const uint64_t blksreq, uint64_t *blkno)
+static int block_alloc(struct gfs2_sbd *sdp, const uint64_t blksreq, int state, uint64_t *blkno)
{
int ret;
+ int release = 0;
struct rgrp_tree *rgt = NULL;
struct osi_node *n = NULL;
+ uint64_t bn = 0;
+
for (n = osi_first(&sdp->rgtree); n; n = osi_next(n)) {
rgt = (struct rgrp_tree *)n;
if (rgt->rg.rg_free >= blksreq)
@@ -211,10 +178,35 @@ int lgfs2_dinode_alloc(struct gfs2_sbd *sdp, const uint64_t blksreq, uint64_t *b
if (rgt == NULL)
return -1;
- ret = blk_alloc_in_rg(sdp, GFS2_BLKST_DINODE, rgt, blkno);
+ if (rgt->bh[0] == NULL) {
+ if (gfs2_rgrp_read(sdp, rgt))
+ return -1;
+ release = 1;
+ }
+
+ bn = find_free_block(rgt);
+ ret = blk_alloc_in_rg(sdp, state, rgt, bn);
+ if (release)
+ gfs2_rgrp_relse(rgt);
+ *blkno = bn;
+ return ret;
+}
+
+int lgfs2_dinode_alloc(struct gfs2_sbd *sdp, const uint64_t blksreq, uint64_t *blkno)
+{
+ int ret = block_alloc(sdp, blksreq, GFS2_BLKST_DINODE, blkno);
if (ret == 0)
sdp->dinodes_alloced++;
+ return ret;
+}
+int lgfs2_meta_alloc(struct gfs2_inode *ip, uint64_t *blkno)
+{
+ int ret = block_alloc(ip->i_sbd, 1, GFS2_BLKST_USED, blkno);
+ if (ret == 0) {
+ ip->i_di.di_goal_meta = *blkno;
+ bmodified(ip->i_bh);
+ }
return ret;
}
@@ -245,10 +237,11 @@ void unstuff_dinode(struct gfs2_inode *ip)
int isdir = S_ISDIR(ip->i_di.di_mode) || is_gfs_dir(&ip->i_di);
if (ip->i_di.di_size) {
+ if (lgfs2_meta_alloc(ip, &block))
+ exit(1);
if (isdir) {
struct gfs2_meta_header mh;
- block = meta_alloc(ip);
bh = bget(sdp, block);
mh.mh_magic = GFS2_MAGIC;
mh.mh_type = GFS2_METATYPE_JD;
@@ -261,7 +254,6 @@ void unstuff_dinode(struct gfs2_inode *ip)
brelse(bh);
} else {
- block = meta_alloc(ip);
bh = bget(sdp, block);
buffer_copy_tail(sdp, bh, 0,
@@ -325,7 +317,8 @@ void build_height(struct gfs2_inode *ip, int height)
if (new_block) {
struct gfs2_meta_header mh;
- block = meta_alloc(ip);
+ if (lgfs2_meta_alloc(ip, &block))
+ exit(1);
bh = bget(sdp, block);
mh.mh_magic = GFS2_MAGIC;
mh.mh_type = GFS2_METATYPE_IN;
@@ -377,7 +370,8 @@ void lookup_block(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
if (!create)
return;
- *block = meta_alloc(ip);
+ if (lgfs2_meta_alloc(ip, block))
+ return;
*ptr = cpu_to_be64(*block);
bmodified(bh);
ip->i_di.di_blocks++;
@@ -853,7 +847,8 @@ void dir_split_leaf(struct gfs2_inode *dip, uint32_t start, uint64_t leaf_no,
int x, moved = FALSE;
int count;
- bn = meta_alloc(dip);
+ if (lgfs2_meta_alloc(dip, &bn))
+ exit(1);
nbh = bget(dip->i_sbd, bn);
{
struct gfs2_meta_header mh;
@@ -1119,7 +1114,8 @@ restart:
} else {
struct gfs2_meta_header mh;
- bn = meta_alloc(dip);
+ if (lgfs2_meta_alloc(dip, &bn))
+ exit(1);
nbh = bget(dip->i_sbd, bn);
mh.mh_magic = GFS2_MAGIC;
mh.mh_type = GFS2_METATYPE_LF;
@@ -1170,7 +1166,8 @@ static void dir_make_exhash(struct gfs2_inode *dip)
uint32_t x;
uint64_t *lp, bn;
- bn = meta_alloc(dip);
+ if (lgfs2_meta_alloc(dip, &bn))
+ exit(1);
bh = bget(sdp, bn);
{
struct gfs2_meta_header mh;
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index aee845a..c00d7be 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -57,7 +57,11 @@ void gfs1_lookup_block(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
if (!create)
return;
- *block = meta_alloc(ip);
+ if (lgfs2_meta_alloc(ip, block)) {
+ *block = 0;
+ return;
+ }
+
*ptr = cpu_to_be64(*block);
bmodified(bh);
ip->i_di.di_blocks++;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 9abe3b2..d044bc6 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -448,7 +448,7 @@ extern struct gfs2_inode *is_system_inode(struct gfs2_sbd *sdp,
uint64_t block);
extern void inode_put(struct gfs2_inode **ip);
extern uint64_t data_alloc(struct gfs2_inode *ip);
-extern uint64_t meta_alloc(struct gfs2_inode *ip);
+extern int lgfs2_meta_alloc(struct gfs2_inode *ip, uint64_t *blkno);
extern int lgfs2_dinode_alloc(struct gfs2_sbd *sdp, const uint64_t blksreq, uint64_t *blkno);
extern int gfs2_readi(struct gfs2_inode *ip, void *buf, uint64_t offset,
unsigned int size);
9 years, 8 months
gfs2-utils: RHEL7 - gfs2-utils: Clean up unused functions
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=cd71fe58...
Commit: cd71fe5817f52f598fa2b5254a39417199e57014
Parent: 60ae6e5ffe35497c342135fc85022b968ff0adbb
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon Jan 27 12:27:50 2014 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 16:52:09 2014 +0100
gfs2-utils: Clean up unused functions
Remove unused functions, some of which call exit() from libgfs2.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/fsck/Makefile.am | 4 +-
gfs2/fsck/eattr.c | 63 ------------------------------------------------
gfs2/fsck/eattr.h | 18 -------------
gfs2/fsck/pass2.c | 1 -
gfs2/libgfs2/fs_ops.c | 18 -------------
gfs2/libgfs2/gfs1.c | 14 ----------
gfs2/libgfs2/libgfs2.h | 4 ---
gfs2/libgfs2/misc.c | 28 ---------------------
8 files changed, 2 insertions(+), 148 deletions(-)
diff --git a/gfs2/fsck/Makefile.am b/gfs2/fsck/Makefile.am
index b92c745..92d56f3 100644
--- a/gfs2/fsck/Makefile.am
+++ b/gfs2/fsck/Makefile.am
@@ -10,10 +10,10 @@ sbindir := $(shell rpl=0; test '$(exec_prefix):$(sbindir)' = /usr:/usr/sbin \
sbin_PROGRAMS = fsck.gfs2
-noinst_HEADERS = eattr.h fsck.h fs_recovery.h \
+noinst_HEADERS = fsck.h fs_recovery.h \
inode_hash.h link.h lost_n_found.h metawalk.h util.h
-fsck_gfs2_SOURCES = eattr.c fs_recovery.c initialize.c \
+fsck_gfs2_SOURCES = fs_recovery.c initialize.c \
inode_hash.c link.c lost_n_found.c main.c metawalk.c \
pass1b.c pass1.c pass1c.c pass2.c pass3.c pass4.c \
pass5.c rgrepair.c util.c
diff --git a/gfs2/fsck/eattr.c b/gfs2/fsck/eattr.c
deleted file mode 100644
index 3f95d93..0000000
--- a/gfs2/fsck/eattr.c
+++ /dev/null
@@ -1,63 +0,0 @@
-#include "clusterautoconfig.h"
-
-#include <stdint.h>
-#include <string.h>
-#include <libintl.h>
-#define _(String) gettext(String)
-
-#include "libgfs2.h"
-#include "fsck.h"
-#include "metawalk.h"
-#include "eattr.h"
-
-int clear_eattr_entry (struct gfs2_inode *ip,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev,
- void *private)
-{
- struct gfs2_sbd *sdp = ip->i_sbd;
-
- if (!ea_hdr->ea_name_len){
- /* Skip this entry for now */
- return 1;
- }
-
- if (!GFS2_EATYPE_VALID(ea_hdr->ea_type) &&
- ((ea_hdr_prev) || (!ea_hdr_prev && ea_hdr->ea_type))){
- /* Skip invalid entry */
- return 1;
- }
-
- if (ea_hdr->ea_num_ptrs){
- uint32_t avail_size;
- int max_ptrs;
-
- avail_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header);
- max_ptrs = (be32_to_cpu(ea_hdr->ea_data_len)+avail_size-1)/avail_size;
-
- if (max_ptrs > ea_hdr->ea_num_ptrs) {
- return 1;
- } else {
- log_debug( _(" Pointers Required: %d\n"
- " Pointers Reported: %d\n"),
- max_ptrs, ea_hdr->ea_num_ptrs);
- }
-
-
- }
- return 0;
-}
-
-int clear_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev, void *private)
-{
- uint64_t block = be64_to_cpu(*ea_data_ptr);
-
- return delete_eattr_leaf(ip, block, 0, &leaf_bh, private);
-}
-
-
-
diff --git a/gfs2/fsck/eattr.h b/gfs2/fsck/eattr.h
deleted file mode 100644
index f4264b0..0000000
--- a/gfs2/fsck/eattr.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef _EATTR_H
-#define _EATTR_H
-
-int clear_eattr_indir(struct gfs2_inode *ip, uint64_t block, uint64_t parent,
- struct gfs2_buffer_head **bh, void *private);
-int clear_eattr_leaf(struct gfs2_inode *ip, uint64_t block, uint64_t parent,
- struct gfs2_buffer_head **bh, void *private);
-int clear_eattr_entry (struct gfs2_inode *ip,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev,
- void *private);
-int clear_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev, void *private);
-
-#endif /* _EATTR_H */
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 26f7d48..d3b56fc 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -12,7 +12,6 @@
#include "libgfs2.h"
#include "fsck.h"
#include "util.h"
-#include "eattr.h"
#include "metawalk.h"
#include "link.h"
#include "lost_n_found.h"
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 7d4d118..9889e22 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -841,24 +841,6 @@ void gfs2_get_leaf_nr(struct gfs2_inode *dip, uint32_t lindex,
*leaf_out = be64_to_cpu(leaf_no);
}
-void gfs2_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx, uint64_t leaf_out)
-{
- uint64_t leaf_no;
- int count;
-
- if (dip->i_sbd->gfs1) {
- gfs_put_leaf_nr(dip, inx, leaf_out);
- return;
- }
- leaf_no = cpu_to_be64(leaf_out);
- count = gfs2_writei(dip, (char *)&leaf_no, inx * sizeof(uint64_t),
- sizeof(uint64_t));
- if (count != sizeof(uint64_t)) {
- fprintf(stderr, "gfs2_put_leaf_nr: Bad internal write.\n");
- exit(1);
- }
-}
-
void dir_split_leaf(struct gfs2_inode *dip, uint32_t start, uint64_t leaf_no,
struct gfs2_buffer_head *obh)
{
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index 00e18e6..aee845a 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -385,17 +385,3 @@ void gfs_rgrp_out(struct gfs_rgrp *rgrp, struct gfs2_buffer_head *rbh)
memcpy(str->rg_reserved, rgrp->rg_reserved, 64);
bmodified(rbh);
}
-
-void gfs_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx, uint64_t leaf_out)
-{
- uint64_t leaf_no;
- int count;
-
- leaf_no = cpu_to_be64(leaf_out);
- count = gfs1_writei(dip, (char *)&leaf_no, inx * sizeof(uint64_t),
- sizeof(uint64_t));
- if (count != sizeof(uint64_t)) {
- fprintf(stderr, "gfs_put_leaf_nr: Bad internal write.\n");
- exit(1);
- }
-}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 9c20946..9abe3b2 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -481,7 +481,6 @@ extern void block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
uint64_t *dblock, uint32_t *extlen, int prealloc);
extern void gfs2_get_leaf_nr(struct gfs2_inode *dip, uint32_t index,
uint64_t *leaf_out);
-extern void gfs2_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx, uint64_t leaf_out);
extern void dir_split_leaf(struct gfs2_inode *dip, uint32_t start,
uint64_t leaf_no, struct gfs2_buffer_head *obh);
extern void gfs2_free_block(struct gfs2_sbd *sdp, uint64_t block);
@@ -670,8 +669,6 @@ extern struct gfs2_inode *lgfs2_gfs_inode_read(struct gfs2_sbd *sdp,
extern void gfs_jindex_in(struct gfs_jindex *jindex, char *buf);
extern void gfs_rgrp_in(struct gfs_rgrp *rg, struct gfs2_buffer_head *bh);
extern void gfs_rgrp_out(struct gfs_rgrp *rg, struct gfs2_buffer_head *bh);
-extern void gfs_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx,
- uint64_t leaf_out);
/* gfs2_log.c */
@@ -721,7 +718,6 @@ extern int find_gfs2_meta(struct gfs2_sbd *sdp);
extern int dir_exists(const char *dir);
extern int mount_gfs2_meta(struct gfs2_sbd *sdp);
extern void cleanup_metafs(struct gfs2_sbd *sdp);
-extern int set_sysfs(const char *fsname, const char *filename, const char *val);
extern int is_fsname(char *name);
/* recovery.c */
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 063e9ab..4cdd6e0 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -22,7 +22,6 @@
#include "libgfs2.h"
#define PAGE_SIZE (4096)
-#define SYS_BASE "/sys/fs/gfs2" /* FIXME: Look in /proc/mounts to find this */
#define DIV_RU(x, y) (((x) + (y) - 1) / (y))
int metafs_interrupted = 0;
@@ -276,30 +275,3 @@ void cleanup_metafs(struct gfs2_sbd *sdp)
sigaction(SIGUSR2, &sa, NULL);
metafs_interrupted = 0;
}
-
-int set_sysfs(const char *fsname, const char *filename, const char *val)
-{
- char path[PATH_MAX];
- int fd, rv, len;
-
- len = strlen(val) + 1;
- if (len > PAGE_SIZE) {
- errno = EINVAL;
- return -1;
- }
-
- memset(path, 0, PATH_MAX);
- snprintf(path, PATH_MAX - 1, "%s/%s/%s", SYS_BASE, fsname, filename);
-
- fd = open(path, O_WRONLY);
- if (fd < 0)
- return -1;
-
- rv = write(fd, val, len);
- if (rv != len) {
- close(fd);
- return -1;
- }
- close(fd);
- return 0;
-}
9 years, 8 months
gfs2-utils: RHEL7 - libgfs2: Improve and simplify blk_alloc_in_rg
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=60ae6e5f...
Commit: 60ae6e5ffe35497c342135fc85022b968ff0adbb
Parent: a39cee5cbde4b204ccd25cfa96a09696e6f6dc6a
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed Jan 22 18:04:08 2014 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 16:08:54 2014 +0100
libgfs2: Improve and simplify blk_alloc_in_rg
This function included naive implementations of gfs2_setbit and
gfs2_bitfit so these have been replaced with calls to those functions.
The 'type' parameter has been replaced with 'state' and the type
defines removed in favour of the GFS2_BLKST_* values. As these were the
same for both meta and data block allocations, data_alloc() has been
removed and its callers updated to use meta_alloc().
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/fs_ops.c | 117 ++++++++++++++----------------------------------
gfs2/libgfs2/gfs1.c | 7 +---
2 files changed, 35 insertions(+), 89 deletions(-)
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 6582d60..7d4d118 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -14,10 +14,6 @@
#include <linux/types.h>
#include "libgfs2.h"
-#define DATA (1)
-#define META (2)
-#define DINODE (3)
-
static __inline__ uint64_t *metapointer(struct gfs2_buffer_head *bh,
unsigned int height,
struct metapath *mp)
@@ -116,88 +112,57 @@ void inode_put(struct gfs2_inode **ip_in)
*ip_in = NULL; /* make sure the memory isn't accessed again */
}
-static int blk_alloc_in_rg(struct gfs2_sbd *sdp, unsigned int type, struct rgrp_tree *rl, uint64_t *blkno)
+static int blk_alloc_in_rg(struct gfs2_sbd *sdp, unsigned state, struct rgrp_tree *rgd, uint64_t *blkno)
{
- struct gfs2_rindex *ri;
- struct gfs2_rgrp *rg;
- unsigned int block, bn = 0, x = 0, y = 0;
- unsigned int state;
unsigned int release = 0;
- struct gfs2_buffer_head *bh;
+ unsigned int bm;
+ int error = -1;
- if (rl == NULL || rl->rg.rg_free == 0) {
+ if (rgd == NULL || rgd->rg.rg_free == 0) {
errno = ENOSPC;
return -1;
}
- if (rl->bh[0] == NULL) {
- if (gfs2_rgrp_read(sdp, rl) != 0)
+ if (rgd->bh[0] == NULL) {
+ if (gfs2_rgrp_read(sdp, rgd))
return -1;
release = 1;
}
- ri = &rl->ri;
- rg = &rl->rg;
- for (block = 0; block < ri->ri_length; block++) {
- bh = rl->bh[block];
- x = (block) ? sizeof(struct gfs2_meta_header) : sizeof(struct gfs2_rgrp);
-
- for (; x < sdp->bsize; x++)
- for (y = 0; y < GFS2_NBBY; y++) {
- state = (bh->b_data[x] >> (GFS2_BIT_SIZE * y)) & 0x03;
- if (state == GFS2_BLKST_FREE)
- goto found;
- bn++;
- }
- }
+ *blkno = 0;
+ for (bm = 0; bm < rgd->ri.ri_length; bm++) {
+ unsigned long blk = 0;
+ struct gfs2_bitmap *bits = &rgd->bits[bm];
- fprintf(stderr, "allocation is broken (1): %"PRIu64" %u\n",
- (uint64_t)rl->ri.ri_addr, rl->rg.rg_free);
- goto out_err;
-
-found:
- if (bn >= ri->ri_bitbytes * GFS2_NBBY) {
- fprintf(stderr, "allocation is broken (2): bn: %u %u rgrp: %"PRIu64
- " (0x%" PRIx64 ") Free:%u\n",
- bn, ri->ri_bitbytes * GFS2_NBBY, (uint64_t)rl->ri.ri_addr,
- (uint64_t)rl->ri.ri_addr, rl->rg.rg_free);
- goto out_err;
+ blk = gfs2_bitfit((unsigned char *)rgd->bh[bm]->b_data + bits->bi_offset,
+ bits->bi_len, blk, GFS2_BLKST_FREE);
+ if (blk != BFITNOENT) {
+ *blkno = blk + (bits->bi_start * GFS2_NBBY) + rgd->ri.ri_data0;
+ break;
+ }
}
- switch (type) {
- case DATA:
- case META:
- state = GFS2_BLKST_USED;
- break;
- case DINODE:
- state = GFS2_BLKST_DINODE;
- rg->rg_dinodes++;
- break;
- default:
- fprintf(stderr, "bad state\n");
- goto out_err;
- }
+ if (*blkno == 0)
+ goto out;
- bh->b_data[x] &= ~(0x03 << (GFS2_BIT_SIZE * y));
- bh->b_data[x] |= state << (GFS2_BIT_SIZE * y);
- rg->rg_free--;
+ error = gfs2_set_bitmap(sdp, *blkno, state);
+ if (error)
+ goto out;
- bmodified(bh);
+ if (state == GFS2_BLKST_DINODE)
+ rgd->rg.rg_dinodes++;
+
+ rgd->rg.rg_free--;
if (sdp->gfs1)
- gfs_rgrp_out((struct gfs_rgrp *)rg, rl->bh[0]);
+ gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bh[0]);
else
- gfs2_rgrp_out_bh(rg, rl->bh[0]);
+ gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]);
sdp->blks_alloced++;
- *blkno = ri->ri_data0 + bn;
- if (release)
- gfs2_rgrp_relse(rl);
- return 0;
-out_err:
+out:
if (release)
- gfs2_rgrp_relse(rl);
- return -1;
-
+ gfs2_rgrp_relse(rgd);
+ return error;
}
/**
@@ -219,19 +184,10 @@ static uint64_t blk_alloc_i(struct gfs2_sbd *sdp, unsigned int type)
return blkno;
}
-uint64_t data_alloc(struct gfs2_inode *ip)
-{
- uint64_t x;
- x = blk_alloc_i(ip->i_sbd, DATA);
- ip->i_di.di_goal_data = x;
- bmodified(ip->i_bh);
- return x;
-}
-
uint64_t meta_alloc(struct gfs2_inode *ip)
{
uint64_t x;
- x = blk_alloc_i(ip->i_sbd, META);
+ x = blk_alloc_i(ip->i_sbd, GFS2_BLKST_USED);
ip->i_di.di_goal_meta = x;
bmodified(ip->i_bh);
return x;
@@ -255,7 +211,7 @@ int lgfs2_dinode_alloc(struct gfs2_sbd *sdp, const uint64_t blksreq, uint64_t *b
if (rgt == NULL)
return -1;
- ret = blk_alloc_in_rg(sdp, DINODE, rgt, blkno);
+ ret = blk_alloc_in_rg(sdp, GFS2_BLKST_DINODE, rgt, blkno);
if (ret == 0)
sdp->dinodes_alloced++;
@@ -305,7 +261,7 @@ void unstuff_dinode(struct gfs2_inode *ip)
brelse(bh);
} else {
- block = data_alloc(ip);
+ block = meta_alloc(ip);
bh = bget(sdp, block);
buffer_copy_tail(sdp, bh, 0,
@@ -421,12 +377,7 @@ void lookup_block(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
if (!create)
return;
- if (height == ip->i_di.di_height - 1&&
- !(S_ISDIR(ip->i_di.di_mode)))
- *block = data_alloc(ip);
- else
- *block = meta_alloc(ip);
-
+ *block = meta_alloc(ip);
*ptr = cpu_to_be64(*block);
bmodified(bh);
ip->i_di.di_blocks++;
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index 619542c..00e18e6 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -57,12 +57,7 @@ void gfs1_lookup_block(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
if (!create)
return;
- if (height == ip->i_di.di_height - 1&&
- !(S_ISDIR(ip->i_di.di_mode)))
- *block = data_alloc(ip);
- else
- *block = meta_alloc(ip);
-
+ *block = meta_alloc(ip);
*ptr = cpu_to_be64(*block);
bmodified(bh);
ip->i_di.di_blocks++;
9 years, 8 months
gfs2-utils: RHEL7 - libgfs2: Rework find_metapath
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=a39cee5c...
Commit: a39cee5cbde4b204ccd25cfa96a09696e6f6dc6a
Parent: 7c83804fa24110527704094ae99625702b5a594e
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed Jan 22 02:42:43 2014 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 16:08:54 2014 +0100
libgfs2: Rework find_metapath
Rework find_metapath to receive a pointer to a metapath structure
instead of allocating memory and exiting on allocation failure. Also
simplify some other aspects of the function and update its callers.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/fs_ops.c | 41 +++++++++++++++--------------------------
gfs2/libgfs2/gfs1.c | 17 +++++++----------
gfs2/libgfs2/libgfs2.h | 2 +-
3 files changed, 23 insertions(+), 37 deletions(-)
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 1790421..6582d60 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -393,24 +393,16 @@ void build_height(struct gfs2_inode *ip, int height)
}
}
-struct metapath *find_metapath(struct gfs2_inode *ip, uint64_t block)
+void find_metapath(struct gfs2_inode *ip, uint64_t block, struct metapath *mp)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
- struct metapath *mp;
- uint64_t b = block;
- unsigned int i;
+ const uint32_t inptrs = ip->i_sbd->sd_inptrs;
+ unsigned int i = ip->i_di.di_height;
- mp = calloc(1, sizeof(struct metapath));
- if (mp == NULL) {
- fprintf(stderr, "Out of memory in %s\n", __FUNCTION__);
- exit(-1);
- }
- for (i = ip->i_di.di_height; i--;) {
- mp->mp_list[i] = b % sdp->sd_inptrs;
- b /= sdp->sd_inptrs;
+ memset(mp, 0, sizeof(struct metapath));
+ while (i--) {
+ mp->mp_list[i] = block % inptrs;
+ block /= inptrs;
}
-
- return mp;
}
void lookup_block(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
@@ -448,7 +440,7 @@ void block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
{
struct gfs2_sbd *sdp = ip->i_sbd;
struct gfs2_buffer_head *bh;
- struct metapath *mp;
+ struct metapath mp;
int create = *new;
unsigned int bsize;
unsigned int height;
@@ -479,17 +471,17 @@ void block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
build_height(ip, height);
}
- mp = find_metapath(ip, lblock);
+ find_metapath(ip, lblock, &mp);
end_of_metadata = ip->i_di.di_height - 1;
bh = ip->i_bh;
for (x = 0; x < end_of_metadata; x++) {
- lookup_block(ip, bh, x, mp, create, new, dblock);
+ lookup_block(ip, bh, x, &mp, create, new, dblock);
if (bh != ip->i_bh)
brelse(bh);
if (!*dblock)
- goto out;
+ return;
if (*new) {
struct gfs2_meta_header mh;
@@ -507,7 +499,7 @@ void block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
}
if (!prealloc)
- lookup_block(ip, bh, end_of_metadata, mp, create, new, dblock);
+ lookup_block(ip, bh, end_of_metadata, &mp, create, new, dblock);
if (extlen && *dblock) {
*extlen = 1;
@@ -519,8 +511,8 @@ void block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
nptrs = (end_of_metadata) ? sdp->sd_inptrs : sdp->sd_diptrs;
- while (++mp->mp_list[end_of_metadata] < nptrs) {
- lookup_block(ip, bh, end_of_metadata, mp, FALSE, &tmp_new,
+ while (++mp.mp_list[end_of_metadata] < nptrs) {
+ lookup_block(ip, bh, end_of_metadata, &mp, FALSE, &tmp_new,
&tmp_dblock);
if (*dblock + *extlen != tmp_dblock)
@@ -533,9 +525,6 @@ void block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
if (bh != ip->i_bh)
brelse(bh);
-
- out:
- free(mp);
}
static void
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index 89fb898..619542c 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -76,7 +76,7 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
{
struct gfs2_sbd *sdp = ip->i_sbd;
struct gfs2_buffer_head *bh;
- struct metapath *mp;
+ struct metapath mp;
int create = *new;
unsigned int bsize;
unsigned int height;
@@ -107,17 +107,17 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
build_height(ip, height);
}
- mp = find_metapath(ip, lblock);
+ find_metapath(ip, lblock, &mp);
end_of_metadata = ip->i_di.di_height - 1;
bh = ip->i_bh;
for (x = 0; x < end_of_metadata; x++) {
- gfs1_lookup_block(ip, bh, x, mp, create, new, dblock);
+ gfs1_lookup_block(ip, bh, x, &mp, create, new, dblock);
if (bh != ip->i_bh)
brelse(bh);
if (!*dblock)
- goto out;
+ return;
if (*new) {
struct gfs2_meta_header mh;
@@ -136,7 +136,7 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
}
if (!prealloc)
- gfs1_lookup_block(ip, bh, end_of_metadata, mp, create, new,
+ gfs1_lookup_block(ip, bh, end_of_metadata, &mp, create, new,
dblock);
if (extlen && *dblock) {
@@ -149,8 +149,8 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
nptrs = (end_of_metadata) ? sdp->sd_inptrs : sdp->sd_diptrs;
- while (++mp->mp_list[end_of_metadata] < nptrs) {
- gfs1_lookup_block(ip, bh, end_of_metadata, mp,
+ while (++mp.mp_list[end_of_metadata] < nptrs) {
+ gfs1_lookup_block(ip, bh, end_of_metadata, &mp,
FALSE, &tmp_new,
&tmp_dblock);
@@ -164,9 +164,6 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
if (bh != ip->i_bh)
brelse(bh);
-
- out:
- free(mp);
}
int gfs1_writei(struct gfs2_inode *ip, char *buf, uint64_t offset,
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index ce05491..9c20946 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -437,7 +437,7 @@ extern void build_rgrps(struct gfs2_sbd *sdp, int write);
#define IS_LEAF (1)
#define IS_DINODE (2)
-extern struct metapath *find_metapath(struct gfs2_inode *ip, uint64_t block);
+extern void find_metapath(struct gfs2_inode *ip, uint64_t block, struct metapath *mp);
extern void lookup_block(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
unsigned int height, struct metapath *mp,
int create, int *new, uint64_t *block);
9 years, 8 months
gfs2-utils: RHEL7 - libgfs2: Remove sdp and j arguments from write_journal
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=7c83804f...
Commit: 7c83804fa24110527704094ae99625702b5a594e
Parent: cdec90ab7cdce6077cba2f3ee015d18a61dff550
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Tue Jan 14 15:41:53 2014 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 16:08:54 2014 +0100
libgfs2: Remove sdp and j arguments from write_journal
write_journal accepts an sdp argument which it only used to look up the
current journal (using j as the index) and the bsize. Replace these
arguments with the journal inode itself and the block size.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/convert/gfs2_convert.c | 2 +-
gfs2/fsck/fs_recovery.c | 2 +-
gfs2/libgfs2/libgfs2.h | 3 +--
gfs2/libgfs2/structures.c | 21 +++++++--------------
4 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index eacc565..69b4b8b 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2024,7 +2024,7 @@ static int conv_build_jindex(struct gfs2_sbd *sdp)
sprintf(name, "journal%u", j);
sdp->md.journal[j] = createi(sdp->md.jiinode, name, S_IFREG |
0600, GFS2_DIF_SYSTEM);
- write_journal(sdp, j,
+ write_journal(sdp->md.journal[j], sdp->bsize,
sdp->jsize << 20 >> sdp->sd_sb.sb_bsize_shift);
inode_put(&sdp->md.journal[j]);
printf(_("done.\n"));
diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index 41d575a..54a8c5f 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -552,7 +552,7 @@ out:
log_info( _("jid=%u: Failed\n"), j);
reinit:
if (query( _("Do you want to clear the journal instead? (y/n)")))
- error = write_journal(sdp, j,
+ error = write_journal(sdp->md.journal[j], sdp->bsize,
sdp->md.journal[j]->i_di.di_size /
sdp->sd_sb.sb_bsize);
else
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 813aa97..ce05491 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -496,8 +496,7 @@ extern int gfs2_dirent_next(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,
extern void build_height(struct gfs2_inode *ip, int height);
extern void unstuff_dinode(struct gfs2_inode *ip);
extern unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size);
-extern int write_journal(struct gfs2_sbd *sdp, unsigned int j,
- unsigned int blocks);
+extern int write_journal(struct gfs2_inode *jnl, unsigned bsize, unsigned blocks);
/* gfs1.c - GFS1 backward compatibility structures and functions */
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 2c1939a..2cc9a98 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -140,7 +140,7 @@ out_buf:
return err;
}
-int write_journal(struct gfs2_sbd *sdp, unsigned int j, unsigned int blocks)
+int write_journal(struct gfs2_inode *jnl, unsigned bsize, unsigned int blocks)
{
struct gfs2_log_header lh;
unsigned int x;
@@ -150,9 +150,8 @@ int write_journal(struct gfs2_sbd *sdp, unsigned int j, unsigned int blocks)
/* Build the height up so our journal blocks will be contiguous and */
/* not broken up by indirect block pages. */
- height = calc_tree_height(sdp->md.journal[j],
- (blocks + 1) * sdp->bsize);
- build_height(sdp->md.journal[j], height);
+ height = calc_tree_height(jnl, (blocks + 1) * bsize);
+ build_height(jnl, height);
memset(&lh, 0, sizeof(struct gfs2_log_header));
lh.lh_header.mh_magic = GFS2_MAGIC;
@@ -161,20 +160,18 @@ int write_journal(struct gfs2_sbd *sdp, unsigned int j, unsigned int blocks)
lh.lh_flags = GFS2_LOG_HEAD_UNMOUNT;
for (x = 0; x < blocks; x++) {
- struct gfs2_buffer_head *bh = get_file_buf(sdp->md.journal[j],
- x, TRUE);
+ struct gfs2_buffer_head *bh = get_file_buf(jnl, x, TRUE);
if (!bh)
return -1;
bmodified(bh);
brelse(bh);
}
for (x = 0; x < blocks; x++) {
- struct gfs2_buffer_head *bh = get_file_buf(sdp->md.journal[j],
- x, FALSE);
+ struct gfs2_buffer_head *bh = get_file_buf(jnl, x, FALSE);
if (!bh)
return -1;
- memset(bh->b_data, 0, sdp->bsize);
+ memset(bh->b_data, 0, bsize);
lh.lh_sequence = seq;
lh.lh_blkno = x;
gfs2_log_header_out(&lh, bh);
@@ -188,10 +185,6 @@ int write_journal(struct gfs2_sbd *sdp, unsigned int j, unsigned int blocks)
seq = 0;
}
- if (sdp->debug) {
- printf("\nJournal %u:\n", j);
- gfs2_dinode_print(&sdp->md.journal[j]->i_di);
- }
return 0;
}
@@ -206,7 +199,7 @@ int build_journal(struct gfs2_sbd *sdp, int j, struct gfs2_inode *jindex)
if (sdp->md.journal[j] == NULL) {
return errno;
}
- ret = write_journal(sdp, j,
+ ret = write_journal(sdp->md.journal[j], sdp->bsize,
sdp->jsize << 20 >> sdp->sd_sb.sb_bsize_shift);
return ret;
}
9 years, 8 months
gfs2-utils: RHEL7 - libgfs2: Remove sdp argument from compute_heightsize
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=cdec90ab...
Commit: cdec90ab7cdce6077cba2f3ee015d18a61dff550
Parent: 4669c966e7afa6719fad227d1f077edbaf126d36
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Tue Jan 14 15:30:31 2014 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 16:08:54 2014 +0100
libgfs2: Remove sdp argument from compute_heightsize
compute_heightsize only uses the bsize member of sdp so just accept a
bsize argument instead.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/convert/gfs2_convert.c | 8 ++++----
gfs2/libgfs2/libgfs2.h | 2 +-
gfs2/libgfs2/misc.c | 8 ++++----
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index e3343d0..eacc565 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1629,13 +1629,13 @@ static int init(struct gfs2_sbd *sbp)
sizeof(uint64_t);
sbp->sd_jbsize = sbp->bsize - sizeof(struct gfs2_meta_header);
brelse(bh);
- if (compute_heightsize(sbp, sbp->sd_heightsize, &sbp->sd_max_height,
+ if (compute_heightsize(sbp->bsize, sbp->sd_heightsize, &sbp->sd_max_height,
sbp->bsize, sbp->sd_diptrs, sbp->sd_inptrs)) {
log_crit(_("Error: Bad constants (1)\n"));
exit(-1);
}
- if (compute_heightsize(sbp, sbp->sd_jheightsize, &sbp->sd_max_jheight,
+ if (compute_heightsize(sbp->bsize, sbp->sd_jheightsize, &sbp->sd_max_jheight,
sbp->sd_jbsize, sbp->sd_diptrs, sbp->sd_inptrs)) {
log_crit(_("Error: Bad constants (1)\n"));
exit(-1);
@@ -1646,13 +1646,13 @@ static int init(struct gfs2_sbd *sbp)
gfs2_inptrs = (sbp->bsize - sizeof(struct gfs2_meta_header)) /
sizeof(uint64_t); /* How many ptrs can we fit on a block? */
memset(gfs2_heightsize, 0, sizeof(gfs2_heightsize));
- if (compute_heightsize(sbp, gfs2_heightsize, &gfs2_max_height,
+ if (compute_heightsize(sbp->bsize, gfs2_heightsize, &gfs2_max_height,
sbp->bsize, sbp->sd_diptrs, gfs2_inptrs)) {
log_crit(_("Error: Bad constants (1)\n"));
exit(-1);
}
memset(gfs2_jheightsize, 0, sizeof(gfs2_jheightsize));
- if (compute_heightsize(sbp, gfs2_jheightsize, &gfs2_max_jheight,
+ if (compute_heightsize(sbp->bsize, gfs2_jheightsize, &gfs2_max_jheight,
sbp->sd_jbsize, sbp->sd_diptrs, gfs2_inptrs)) {
log_crit(_("Error: Bad constants (1)\n"));
exit(-1);
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 6710e72..813aa97 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -712,7 +712,7 @@ extern void decrease_verbosity(void);
extern int metafs_interrupted;
-extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
+extern int compute_heightsize(unsigned bsize, uint64_t *heightsize,
uint32_t *maxheight, uint32_t bsize1, int diptrs, int inptrs);
extern int compute_constants(struct gfs2_sbd *sdp);
extern int lgfs2_open_mnt(const char *path, int dirflags, int *dirfd, int devflags, int *devfd, struct mntent **mnt);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index d707687..063e9ab 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -27,10 +27,10 @@
int metafs_interrupted = 0;
-int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
+int compute_heightsize(unsigned bsize, uint64_t *heightsize,
uint32_t *maxheight, uint32_t bsize1, int diptrs, int inptrs)
{
- heightsize[0] = sdp->bsize - sizeof(struct gfs2_dinode);
+ heightsize[0] = bsize - sizeof(struct gfs2_dinode);
heightsize[1] = bsize1 * diptrs;
for (*maxheight = 2;; (*maxheight)++) {
uint64_t space, d;
@@ -90,11 +90,11 @@ int compute_constants(struct gfs2_sbd *sdp)
sdp->sd_max_dirres = hash_blocks + ind_blocks + leaf_blocks;
- if (compute_heightsize(sdp, sdp->sd_heightsize, &sdp->sd_max_height,
+ if (compute_heightsize(sdp->bsize, sdp->sd_heightsize, &sdp->sd_max_height,
sdp->bsize, sdp->sd_diptrs, sdp->sd_inptrs)) {
return -1;
}
- if (compute_heightsize(sdp, sdp->sd_jheightsize, &sdp->sd_max_jheight,
+ if (compute_heightsize(sdp->bsize, sdp->sd_jheightsize, &sdp->sd_max_jheight,
sdp->sd_jbsize, sdp->sd_diptrs, sdp->sd_inptrs)) {
return -1;
}
9 years, 8 months
gfs2-utils: RHEL7 - gfs2_edit: Add "journals" option to print journal info
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=4669c966...
Commit: 4669c966e7afa6719fad227d1f077edbaf126d36
Parent: fa0b88b4be4b6e98c175b4ac9678b4504de2287f
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Fri Aug 30 08:02:15 2013 -0500
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 16:08:53 2014 +0100
gfs2_edit: Add "journals" option to print journal info
This patch adds a keyword "journals" to gfs2_edit. Its purpose is
to print information about the GFS2 journals: location, size, and
whether they're clean, dirty or damaged.
---
gfs2/edit/extended.c | 45 +++++++++++++++++++++++++++++++++++++++------
gfs2/edit/hexedit.c | 27 +++++++++++++++++++++++----
gfs2/edit/hexedit.h | 8 ++++++++
3 files changed, 70 insertions(+), 10 deletions(-)
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 328e35c..793ef6b 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -439,7 +439,7 @@ static void gfs_jindex_print(struct gfs_jindex *ji)
pv(ji, ji_pad, "%u", "0x%x");
}
-static int print_jindex(struct gfs2_inode *dij)
+static int print_gfs_jindex(struct gfs2_inode *dij)
{
int error, start_line;
struct gfs_jindex ji;
@@ -479,6 +479,35 @@ static int print_jindex(struct gfs2_inode *dij)
return error;
}
+static int print_gfs2_jindex(void)
+{
+ int d, error;
+ struct gfs2_log_header head;
+ struct gfs2_inode *ip;
+
+ for (d = 0; d < indirect->ii[0].dirents; d++) {
+ if (strncmp(indirect->ii[0].dirent[d].filename, "journal", 7))
+ continue;
+ ip = lgfs2_inode_read(&sbd, indirect->ii[0].dirent[d].block);
+ print_gfs2("%s: 0x%-5x %dMB ",
+ indirect->ii[0].dirent[d].filename,
+ indirect->ii[0].dirent[d].block,
+ ip->i_di.di_size / 1048576);
+ error = gfs2_find_jhead(ip, &head);
+ if (error) {
+ print_gfs2("corrupt.");
+ } else {
+ if (head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)
+ print_gfs2("clean.");
+ else
+ print_gfs2("dirty.");
+ }
+ eol(0);
+ inode_put(&ip);
+ }
+ return 0;
+}
+
static int parse_rindex(struct gfs2_inode *dip, int print_rindex)
{
int error, start_line;
@@ -630,8 +659,13 @@ int display_extended(void)
parse_rindex(tmp_inode, TRUE);
inode_put(&tmp_inode);
brelse(tmp_bh);
- }
- else if (has_indirect_blocks() && !indirect_blocks &&
+ } else if (block_is_journals()) {
+ if (sbd.gfs1)
+ block = sbd1->sb_jindex_di.no_addr;
+ else
+ block = masterblock("jindex");
+ print_gfs2_jindex();
+ } else if (has_indirect_blocks() && !indirect_blocks &&
!display_leaf(indirect))
return -1;
else if (display_indirect(indirect, indirect_blocks, 0, 0) == 0)
@@ -647,13 +681,12 @@ int display_extended(void)
parse_rindex(tmp_inode, FALSE);
inode_put(&tmp_inode);
brelse(tmp_bh);
- }
- else if (block_is_jindex()) {
+ } else if (block_is_jindex()) {
tmp_bh = bread(&sbd, block);
tmp_inode = lgfs2_inode_get(&sbd, tmp_bh);
if (tmp_inode == NULL)
return -1;
- print_jindex(tmp_inode);
+ print_gfs_jindex(tmp_inode);
inode_put(&tmp_inode);
brelse(tmp_bh);
}
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 1738652..cf57ec8 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -609,6 +609,8 @@ int display_block_type(int from_restore)
}
if (block == RGLIST_DUMMY_BLOCK)
print_gfs2("RG List ");
+ else if (block == JOURNALS_DUMMY_BLOCK)
+ print_gfs2("Journal Status: ");
else
print_gfs2("%lld (0x%llx)", block, block);
if (termlines) {
@@ -622,6 +624,9 @@ int display_block_type(int from_restore)
ret_type = GFS2_METATYPE_RG;
struct_len = sbd.gfs1 ? sizeof(struct gfs_rgrp) :
sizeof(struct gfs2_rgrp);
+ } else if (block == JOURNALS_DUMMY_BLOCK) {
+ ret_type = GFS2_METATYPE_DI;
+ struct_len = 0;
} else {
ret_type = get_block_type(bh);
switch (ret_type) {
@@ -794,6 +799,8 @@ int display_block_type(int from_restore)
print_gfs2("-------------- Master directory -----------------");
else if (!sbd.gfs1 && block == RGLIST_DUMMY_BLOCK)
print_gfs2("------------------ RG List ----------------------");
+ else if (!sbd.gfs1 && block == JOURNALS_DUMMY_BLOCK)
+ print_gfs2("-------------------- Journal List --------------------");
else {
if (sbd.gfs1) {
if (block == sbd1->sb_rindex_di.no_addr)
@@ -1232,6 +1239,7 @@ static int block_has_extended_info(void)
if (has_indirect_blocks() ||
block_is_rindex() ||
block_is_rgtree() ||
+ block_is_journals() ||
block_is_jindex() ||
block_is_inum_file() ||
block_is_statfs_file() ||
@@ -1351,6 +1359,11 @@ int display(int identify_only)
blk = sbd1->sb_rindex_di.no_addr;
else
blk = masterblock("rindex");
+ } else if (block == JOURNALS_DUMMY_BLOCK) {
+ if (sbd.gfs1)
+ blk = sbd1->sb_jindex_di.no_addr;
+ else
+ blk = masterblock("jindex");
} else
blk = block;
if (termlines) {
@@ -1417,6 +1430,7 @@ int display(int identify_only)
else if (gfs2_struct_type == GFS2_METATYPE_LF) { /* directory leaf */
do_leaf_extended(bh->b_data, indirect);
}
+
last_entry_onscreen[dmode] = 0;
if (dmode == EXTENDED_MODE && !block_has_extended_info())
dmode = HEX_MODE;
@@ -1432,9 +1446,10 @@ int display(int identify_only)
if (dmode == HEX_MODE) /* if hex display mode */
hexdump(dev_offset, (gfs2_struct_type == GFS2_METATYPE_DI)?
struct_len + di.di_size:sbd.bsize);
- else if (dmode == GFS2_MODE) /* if structure display */
- display_gfs2(); /* display the gfs2 structure */
- else
+ else if (dmode == GFS2_MODE) { /* if structure display */
+ if (block != JOURNALS_DUMMY_BLOCK)
+ display_gfs2(); /* display the gfs2 structure */
+ } else
display_extended(); /* display extended blocks */
/* No else here because display_extended can switch back to hex mode */
if (termlines)
@@ -1765,6 +1780,8 @@ uint64_t check_keywords(const char *kword)
rgnum = atoi(kword + 3);
blk = get_rg_addr(rgnum);
+ } else if (!strncmp(kword, "journals", 8)) {
+ blk = JOURNALS_DUMMY_BLOCK;
} else if (!strncmp(kword, "journal", 7) && isdigit(kword[7])) {
uint64_t j_size;
@@ -1800,7 +1817,8 @@ static uint64_t goto_block(void)
temp_blk = block + delta;
}
- if (temp_blk == RGLIST_DUMMY_BLOCK || temp_blk < max_block) {
+ if (temp_blk == RGLIST_DUMMY_BLOCK ||
+ temp_blk == JOURNALS_DUMMY_BLOCK || temp_blk < max_block) {
offset = 0;
block = temp_blk;
push_block(block);
@@ -2850,6 +2868,7 @@ static void usage(void)
fprintf(stderr," master - prints the master directory.\n");
fprintf(stderr," root - prints the root directory.\n");
fprintf(stderr," jindex - prints the journal index directory.\n");
+ fprintf(stderr," journals - prints the journal status.\n");
fprintf(stderr," per_node - prints the per_node directory.\n");
fprintf(stderr," inum - prints the inum file.\n");
fprintf(stderr," statfs - prints the statfs file.\n");
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index ebe3855..7615242 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -25,6 +25,7 @@ enum dsp_mode { HEX_MODE = 0, GFS2_MODE = 1, EXTENDED_MODE = 2, INIT_MODE = 3 };
print_it(" "#member, fmt, fmt2, struct->member); \
} while (FALSE);
#define RGLIST_DUMMY_BLOCK -2
+#define JOURNALS_DUMMY_BLOCK -3
extern struct gfs2_sb sb;
extern uint64_t block;
@@ -118,6 +119,13 @@ static inline int block_is_rgtree(void)
return FALSE;
}
+static inline int block_is_journals(void)
+{
+ if (block == JOURNALS_DUMMY_BLOCK)
+ return TRUE;
+ return FALSE;
+}
+
#define SCREEN_HEIGHT (16)
#define SCREEN_WIDTH (16)
9 years, 8 months
gfs2-utils: RHEL7 - gfs2_lockcapture: Fixed header to use absolute path and modified some options
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=fa0b88b4...
Commit: fa0b88b4be4b6e98c175b4ac9678b4504de2287f
Parent: 59535d92b7c979bd25716d81564b1de133634134
Author: Shane Bradley <sbradley(a)redhat.com>
AuthorDate: Tue Aug 20 09:05:45 2013 -0400
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 16:06:48 2014 +0100
gfs2_lockcapture: Fixed header to use absolute path and modified some options
Fix the header to use absolute path. The "-o" has been modified
so that it takes a path that will be used to create the root directory of where
the data will be written and will be location of the tarball that is
created. Added undocumented(private) "-m" option that will capture the required
data and additional data that is not captured by default because sometimes it
can cause hangs to occur in certain situations. Removed the data capture of the
command "lsof" cause it might cause hangs when capturing lockdumps cause of
symlink lookup.
Signed-off-by: Shane Bradley <sbradley(a)redhat.com>
---
gfs2/man/gfs2_lockcapture.8 | 2 +-
gfs2/scripts/gfs2_lockcapture | 189 ++++++++++++++++++++++------------------
2 files changed, 105 insertions(+), 86 deletions(-)
diff --git a/gfs2/man/gfs2_lockcapture.8 b/gfs2/man/gfs2_lockcapture.8
index 231207e..7d51ccb 100644
--- a/gfs2/man/gfs2_lockcapture.8
+++ b/gfs2/man/gfs2_lockcapture.8
@@ -38,7 +38,7 @@ Prints information about the mounted GFS2 file systems.
The gathering of process information will be disabled.
.TP
\fB-o \fI<output directory>, \fB--path_to_output_dir\fR=\fI<output directory>\fP
-The directory where all the collect data will stored.
+The directory where all the collect data will be stored.
.TP
\fB-r \fI<number of runs>, \fB--num_of_runs\fR=\fI<number of runs>\fP
The number of runs capturing the lockdump data. The default is 3 runs.
diff --git a/gfs2/scripts/gfs2_lockcapture b/gfs2/scripts/gfs2_lockcapture
index 81a0aeb..8839818 100644
--- a/gfs2/scripts/gfs2_lockcapture
+++ b/gfs2/scripts/gfs2_lockcapture
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
"""
The script "gfs2_lockcapture" will capture locking information from GFS2 file
systems and DLM.
@@ -13,7 +13,7 @@ import os
import os.path
import logging
import logging.handlers
-from optparse import OptionParser, Option
+from optparse import OptionParser, Option, SUPPRESS_HELP
import time
import platform
import shutil
@@ -34,7 +34,7 @@ import tarfile
sure only 1 instance of this script is running at any time.
@type PATH_TO_PID_FILENAME: String
"""
-VERSION_NUMBER = "0.9-7"
+VERSION_NUMBER = "0.9-8"
MAIN_LOGGER_NAME = "%s" %(os.path.basename(sys.argv[0]))
PATH_TO_DEBUG_DIR="/sys/kernel/debug"
PATH_TO_PID_FILENAME = "/var/run/%s.pid" %(os.path.basename(sys.argv[0]))
@@ -190,12 +190,11 @@ def runCommand(command, listOfCommandOptions, standardOut=subprocess.PIPE, stand
commandOptionString = ""
for option in listOfCommandOptions:
commandOptionString += "%s " %(option)
- message = "An error occurred running the command: $ %s %s\n" %(command, commandOptionString)
- if (len(stdout) > 0):
- message += stdout
- message += "\n"
- if (len(stderr) > 0):
- message += stderr
+ message = "An error occurred running the command: $ %s %s" %(command, commandOptionString)
+ if (len(stdout.rstrip()) > 0):
+ message += "\n%s" %(stdout.rstrip())
+ if (len(stderr.rstrip()) > 0):
+ message += "\n%s" %(stderr.rstrip())
logging.getLogger(MAIN_LOGGER_NAME).error(message)
return False
@@ -232,12 +231,11 @@ def runCommandOutput(command, listOfCommandOptions, standardOut=subprocess.PIPE,
commandOptionString = ""
for option in listOfCommandOptions:
commandOptionString += "%s " %(option)
- message = "An error occurred running the command: $ %s %s\n" %(command, commandOptionString)
- if (len(stdout) > 0):
- message += stdout
- message += "\n"
- if (len(stderr) > 0):
- message += stderr
+ message = "An error occurred running the command: $ %s %s" %(command, commandOptionString)
+ if (len(stdout.rstrip()) > 0):
+ message += "\n%s" %(stdout.rstrip())
+ if (len(stderr.rstrip()) > 0):
+ message += "\n%s" %(stderr.rstrip())
logging.getLogger(MAIN_LOGGER_NAME).error(message)
return None
return stdout.strip().rstrip()
@@ -790,12 +788,11 @@ def getLabelMapForMountedFilesystems(clusterName, listOfMountedFilesystems):
# #####################################################################
# Gather output from command functions
# #####################################################################
-def gatherGeneralInformation(pathToDSTDir):
+def gatherHostData(pathToDSTDir):
"""
This function will gather general information about the cluster and write
the results to a file. The following data will be captured: hostname, date,
- uname -a, uptime, contents of /proc/mounts, and ps h -AL -o tid,s,cmd.
-
+ uname -a, uptime.
@param pathToDSTDir: This is the path to directory where the files will be
written to.
@@ -811,19 +808,16 @@ def gatherGeneralInformation(pathToDSTDir):
systemString += "UPTIME=%s" %(stdout)
writeToFile(os.path.join(pathToDSTDir, "hostinformation.txt"), systemString, createFile=True)
- # Copy misc files
- pathToSrcFile = "/proc/mounts"
- copyFile(pathToSrcFile, os.path.join(pathToDSTDir, pathToSrcFile.strip("/")))
- pathToSrcFile = "/proc/slabinfo"
- copyFile(pathToSrcFile, os.path.join(pathToDSTDir, pathToSrcFile.strip("/")))
+def gatherDiagnosticData(pathToDSTDir):
+ """
+ This function will gather general information about the cluster and write (or
+ copy) the results to a file.
- # Copy the DLM hash table sizes:
- pathToHashTableFiles = ["/sys/kernel/config/dlm/cluster/lkbtbl_size", "/sys/kernel/config/dlm/cluster/dirtbl_size",
- "/sys/kernel/config/dlm/cluster/rsbtbl_size"]
- for pathToSrcFile in pathToHashTableFiles:
- if (os.path.exists(pathToSrcFile)):
- copyFile(pathToSrcFile, os.path.join(pathToDSTDir, pathToSrcFile.strip("/")))
+ @param pathToDSTDir: This is the path to directory where the files will be
+ written to.
+ @type pathToDSTDir: String
+ """
# Get "ps -eo user,pid,%cpu,%mem,vsz,rss,tty,stat,start,time,comm,wchan" data.
# Get " ps h -AL -o tid,s,cmd
command = "ps"
@@ -837,6 +831,28 @@ def gatherGeneralInformation(pathToDSTDir):
message = "There was an error writing the command output for %s to the file %s." %(command, pathToCommandOutput)
logging.getLogger(MAIN_LOGGER_NAME).error(message)
+ # Copy misc files
+ pathToSrcFile = "/proc/mounts"
+ copyFile(pathToSrcFile, os.path.join(pathToDSTDir, pathToSrcFile.strip("/")))
+ pathToSrcFile = "/proc/slabinfo"
+ copyFile(pathToSrcFile, os.path.join(pathToDSTDir, pathToSrcFile.strip("/")))
+
+ # Copy the DLM hash table sizes:
+ pathToHashTableFiles = ["/sys/kernel/config/dlm/cluster/lkbtbl_size", "/sys/kernel/config/dlm/cluster/dirtbl_size",
+ "/sys/kernel/config/dlm/cluster/rsbtbl_size"]
+ for pathToSrcFile in pathToHashTableFiles:
+ if (os.path.exists(pathToSrcFile)):
+ copyFile(pathToSrcFile, os.path.join(pathToDSTDir, pathToSrcFile.strip("/")))
+
+def gatherOptionalDiagnosticData(pathToDSTDir):
+ """
+ This function will gather optional information about the cluster and write
+ the results to a file.
+
+ @param pathToDSTDir: This is the path to directory where the files will be
+ written to.
+ @type pathToDSTDir: String
+ """
# Get df -h ouput
command = "df"
pathToCommandOutput = os.path.join(pathToDSTDir, "df-h.cmd")
@@ -848,17 +864,6 @@ def gatherGeneralInformation(pathToDSTDir):
message = "There was an error writing the command output for %s to the file %s." %(command, pathToCommandOutput)
logging.getLogger(MAIN_LOGGER_NAME).error(message)
- # Get lsof ouput
- command = "lsof"
- pathToCommandOutput = os.path.join(pathToDSTDir, "lsof.cmd")
- try:
- fout = open(pathToCommandOutput, "w")
- runCommand(command, [], standardOut=fout)
- fout.close()
- except IOError:
- message = "There was an error writing the command output for %s to the file %s." %(command, pathToCommandOutput)
- logging.getLogger(MAIN_LOGGER_NAME).error(message)
-
# Write the status of all the nodes in the cluster out.
if (runCommand("which", ["cman_tool"])):
command = "cman_tool"
@@ -1089,13 +1094,18 @@ def __getOptions(version) :
dest="disableProcessGather",
help="the gathering of process information will be disabled",
default=False)
+ cmdParser.add_option("-m", "--diagnostic_data",
+ action="store_true",
+ dest="enableDiagnosticData",
+ help=SUPPRESS_HELP,
+ default=False)
cmdParser.add_option("-o", "--path_to_output_dir",
action="store",
dest="pathToOutputDir",
help="the directory where all the collect data will be stored",
type="string",
metavar="<output directory>",
- default="")
+ default="/tmp")
cmdParser.add_option("-r", "--num_of_runs",
action="store",
dest="numberOfRuns",
@@ -1154,15 +1164,13 @@ class OptionParserExtended(OptionParser):
examplesMessage += "\nIt will do 3 runs of gathering the lockdump information in 10 second intervals for only the"
examplesMessage += "\nGFS2 filesystems with the names myGFS2vol2,myGFS2vol1. Then it will archive and compress"
- examplesMessage += "\nthe data collected in the output directory:"
- examplesMessage += "\n/tmp/cluster42-gfs2_lockcapture and all the questions will be answered with yes.\n"
- examplesMessage += "\n# %s -r 3 -s 10 -n myGFS2vol2,myGFS2vol1 -o /tmp/cluster42-gfs2_lockcapture -y\n" %(self.__commandName)
+ examplesMessage += "\nthe data collected in the output directory /tmp and all the questions will be answered with yes.\n"
+ examplesMessage += "\n# %s -r 3 -s 10 -n myGFS2vol2,myGFS2vol1 -o /tmp -y\n" %(self.__commandName)
examplesMessage += "\nIt will do 2 runs of gathering the lockdump information in 25 second intervals for all the"
examplesMessage += "\nmounted GFS2 filesystems. The gathering process data will be disabled. Then it will archive and compress"
- examplesMessage += "\nthe data collected in the output directory:"
- examplesMessage += "\n/tmp/cluster42-gfs2_lockcapture and all the questions will be answered with yes.\n"
- examplesMessage += "\n# %s -r 2 -s 25 -P -o /tmp/cluster42-gfs2_lockcapture\n" %(self.__commandName)
+ examplesMessage += "\nthe data collected in the output directory: /tmp and all the questions will be answered with yes.\n"
+ examplesMessage += "\n# %s -r 2 -s 25 -P -o /tmp\n" %(self.__commandName)
OptionParser.print_help(self)
print examplesMessage
@@ -1264,7 +1272,7 @@ if __name__ == "__main__":
message = "Debugging has been enabled."
logging.getLogger(MAIN_LOGGER_NAME).debug(message)
if (cmdLineOpts.disableLoggingToConsole):
- logging.disable(logging.CRITICAL)
+ streamHandler.setLevel(logging.CRITICAL)
# #######################################################################
# Check to see if pid file exists and error if it does.
# #######################################################################
@@ -1305,7 +1313,7 @@ if __name__ == "__main__":
# #######################################################################
# Verify they want to continue because this script will trigger sysrq events.
# #######################################################################
- if (not cmdLineOpts.disableQuestions):
+ if (not cmdLineOpts.disableQuestions and not cmdLineOpts.disableProcessGather):
valid = {"yes":True, "y":True, "no":False, "n":False}
question = "This script will trigger a sysrq -t event or collect the data for each pid directory located in /proc for each run. Are you sure you want to continue?"
prompt = " [y/n] "
@@ -1326,14 +1334,11 @@ if __name__ == "__main__":
# Create the output directory to verify it can be created before
# proceeding unless it is already created from a previous run data needs
# to be analyzed. Probably could add more debugging on if file or dir.
- # #######################################################################
- pathToOutputDir = cmdLineOpts.pathToOutputDir
- if (not len(pathToOutputDir) > 0):
- pathToOutputDir = "%s" %(os.path.join("/tmp", "%s-%s" %(time.strftime("%Y-%m-%d_%H%M%S"), os.path.basename(sys.argv[0]))))
- # #######################################################################
+
# Backup any existing directory with same name as current output
# directory.
# #######################################################################
+ pathToOutputDir = "%s" %(os.path.join(cmdLineOpts.pathToOutputDir, "%s-%s" %(os.path.basename(sys.argv[0]), time.strftime("%Y-%m-%d"))))
if (backupOutputDirectory(pathToOutputDir)):
message = "This directory that will be used to capture all the data: %s" %(pathToOutputDir)
logging.getLogger(MAIN_LOGGER_NAME).info(message)
@@ -1388,38 +1393,13 @@ if __name__ == "__main__":
logging.getLogger(MAIN_LOGGER_NAME).status(message)
# Gather various bits of data from the clusternode.
- message = "Pass (%d/%d): Gathering general information about the host." %(i, cmdLineOpts.numberOfRuns)
+ message = "Pass (%d/%d): Gathering simple data about the host." %(i, cmdLineOpts.numberOfRuns)
logging.getLogger(MAIN_LOGGER_NAME).debug(message)
- gatherGeneralInformation(pathToOutputRunDir)
+ gatherHostData(pathToOutputRunDir)
# Write the clusternode name and id to the general information file.
writeToFile(os.path.join(pathToOutputRunDir, "hostinformation.txt"),
"NODE_NAME=%s\nNODE_ID=%d" %(clusternode.getClusterNodeName(), clusternode.getClusterNodeID()),
appendToFile=True, createFile=True)
-
- # Going to sleep for 2 seconds, so that TIMESTAMP should be in the
- # past in the logs so that capturing sysrq data will be guaranteed.
- time.sleep(2)
-
- # If enabled then gather the process data.
- if (not cmdLineOpts.disableProcessGather):
- # Gather the backtraces for all the pids, by grabbing the /proc/<pid
- # number> or triggering sysrq events to capture task bask traces
- # from log.
- # Gather the data in the /proc/<pid> directory if the file
- # </proc/<pid>/stack exists. If file exists we will not trigger
- # sysrq events.
-
- # Should I gather anyhow and only capture sysrq if needed.
- pathToPidData = "/proc"
- if (isProcPidStackEnabled(pathToPidData)):
- message = "Pass (%d/%d): Triggering the capture of all pid directories in %s." %(i, cmdLineOpts.numberOfRuns, pathToPidData)
- logging.getLogger(MAIN_LOGGER_NAME).debug(message)
- gatherPidData(pathToPidData, os.path.join(pathToOutputRunDir, pathToPidData.strip("/")))
- else:
- message = "Pass (%d/%d): Triggering the sysrq events for the host since stack was not captured in pid directory." %(i, cmdLineOpts.numberOfRuns)
- logging.getLogger(MAIN_LOGGER_NAME).debug(message)
- triggerSysRQEvents()
-
# #######################################################################
# Gather the DLM data and lock-dumps
# #######################################################################
@@ -1444,16 +1424,55 @@ if __name__ == "__main__":
logging.getLogger(MAIN_LOGGER_NAME).debug(message)
if(gatherGFS2LockDumps(pathToOutputRunDir, clusternode.getMountedGFS2FilesystemNames())):
exitCode = 0
+ # If enabled then gather the process data. This will be included even if -R option is enabled.
+ if (not cmdLineOpts.disableProcessGather):
+ # Gather the backtraces for all the pids, by grabbing the /proc/<pid
+ # number> or triggering sysrq events to capture task bask traces
+ # from log.
+ # Gather the data in the /proc/<pid> directory if the file
+ # </proc/<pid>/stack exists. If file exists we will not trigger
+ # sysrq events.
+
+ # Should I gather anyhow and only capture sysrq if needed.
+ pathToPidData = "/proc"
+ if (isProcPidStackEnabled(pathToPidData)):
+ message = "Pass (%d/%d): Triggering the capture of all pid directories in %s." %(i, cmdLineOpts.numberOfRuns, pathToPidData)
+ logging.getLogger(MAIN_LOGGER_NAME).debug(message)
+ gatherPidData(pathToPidData, os.path.join(pathToOutputRunDir, pathToPidData.strip("/")))
+ else:
+ message = "Pass (%d/%d): Triggering the sysrq events for the host since stack was not captured in pid directory." %(i, cmdLineOpts.numberOfRuns)
+ logging.getLogger(MAIN_LOGGER_NAME).debug(message)
+ triggerSysRQEvents()
+
# Gather log files
message = "Pass (%d/%d): Gathering the log files for the host." %(i, cmdLineOpts.numberOfRuns)
logging.getLogger(MAIN_LOGGER_NAME).debug(message)
gatherLogs(os.path.join(pathToOutputRunDir, "logs"))
+
+ # Gather diagnostic data
+ message = "Pass (%d/%d): Gathering diagnostic data about the host." %(i, cmdLineOpts.numberOfRuns)
+ logging.getLogger(MAIN_LOGGER_NAME).debug(message)
+ gatherDiagnosticData(pathToOutputRunDir)
+ if (cmdLineOpts.enableDiagnosticData):
+ # Gather diagnostic data
+ message = "Pass (%d/%d): Gathering optional diagnostic data about the host." %(i, cmdLineOpts.numberOfRuns)
+ logging.getLogger(MAIN_LOGGER_NAME).debug(message)
+ gatherOptionalDiagnosticData(pathToOutputRunDir)
+
+ # #######################################################################
+ # Sleep for X seconds between runs
+ # #######################################################################
# Sleep between each run if secondsToSleep is greater than or equal
- # to 0 and current run is not the last run.
- if ((cmdLineOpts.secondsToSleep >= 0) and (i < (cmdLineOpts.numberOfRuns))):
- message = "The script will sleep for %d seconds between each run of capturing the lockdump data." %(cmdLineOpts.secondsToSleep)
+ # to 0 and current run is not the last run. Add 2 seconds to each sleep so
+ # that we know that there is a timestamp difference in logs between runs.
+ # The minimal sleep is 2 seconds.
+ secondsToSleep = cmdLineOpts.secondsToSleep + 2
+ if (secondsToSleep < 2):
+ secondsToSleep = 2
+ if (i < cmdLineOpts.numberOfRuns):
+ message = "The script will sleep for %d seconds between each run of capturing the lockdump data." %(secondsToSleep)
logging.getLogger(MAIN_LOGGER_NAME).info(message)
- time.sleep(cmdLineOpts.secondsToSleep)
+ time.sleep(secondsToSleep)
# Remove the handler:
logging.getLogger(MAIN_LOGGER_NAME).removeHandler(currentRunFileHandler)
9 years, 8 months
gfs2-utils: master - gfs2-utils tests: Build unit tests with consistent cpp flags
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=54c5ee8e...
Commit: 54c5ee8ee1b5bf008400d1c86af3a44f15eb4970
Parent: 5e925868971f0128fdc7d0dc29031a6770787790
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon Sep 8 12:03:40 2014 +0200
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon Sep 8 11:31:51 2014 +0100
gfs2-utils tests: Build unit tests with consistent cpp flags
The check_rgrp unit test was failing on ARM and s390 due to struct
gfs2_sbd having a different alignment from libgfs2. This was due to the
unit tests being built with different options to libgfs2. Fix up the
unit test CPPFLAGS to make sure the alignment is consistent.
Also bump the test timeout for check_rgrp to make sure it completes on
slower build machines.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
tests/Makefile.am | 6 ++++++
tests/check_rgrp.c | 2 +-
2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 70e77ef..b912dfa 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,16 +15,22 @@ UNIT_CFLAGS = \
UNIT_LDADD = \
$(top_builddir)/gfs2/libgfs2/libgfs2.la \
@check_LIBS@
+UNIT_CPPFLAGS = \
+ -D_FILE_OFFSET_BITS=64 \
+ -D_LARGEFILE64_SOURCE \
+ -D_GNU_SOURCE
check_PROGRAMS = $(UNIT_TESTS)
check_meta_SOURCES = $(UNIT_SOURCES) check_meta.c
check_meta_CFLAGS = $(UNIT_CFLAGS)
check_meta_LDADD = $(UNIT_LDADD)
+check_meta_CPPFLAGS = $(UNIT_CPPFLAGS)
check_rgrp_SOURCES = $(UNIT_SOURCES) check_rgrp.c
check_rgrp_CFLAGS = $(UNIT_CFLAGS)
check_rgrp_LDADD = $(UNIT_LDADD)
+check_rgrp_CPPFLAGS = $(UNIT_CPPFLAGS)
endif
# The `:;' works around a Bash 3.2 bug when the output is not writable.
diff --git a/tests/check_rgrp.c b/tests/check_rgrp.c
index d113846..e5fca8d 100644
--- a/tests/check_rgrp.c
+++ b/tests/check_rgrp.c
@@ -125,7 +125,7 @@ static Suite * libgfs2_suite(void)
tcase_add_test(tc_rgrp, test_rbm_find_good);
tcase_add_test(tc_rgrp, test_rbm_find_bad);
tcase_add_test(tc_rgrp, test_rbm_find_lastblock);
- tcase_set_timeout(tc_rgrp, 60);
+ tcase_set_timeout(tc_rgrp, 120);
suite_add_tcase(s, tc_rgrp);
return s;
9 years, 9 months
gfs2-utils: 3.1.7 annotated tag has been created
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=f9665328...
Commit: f96653286fd30b31da6119f1f136b168592c2948
Parent: 0000000000000000000000000000000000000000
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: 2014-09-05 15:27 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: 2014-09-05 15:27 +0000
annotated tag: 3.1.7 has been created
at f96653286fd30b31da6119f1f136b168592c2948 (tag)
tagging 5e925868971f0128fdc7d0dc29031a6770787790 (commit)
replaces 3.1.6
Version 3.1.7
Abhi Das (3):
libgfs2: patch to update gfs1 superblock correctly
gfs2-utils: check and fix bad dinode pointers in gfs1 sb
fsck.gfs2: fix corner case sb_seg_size correction for single journal fs
Andrew Price (79):
gfs2_grow: Don't try to open an empty string
gfs2-utils tests: Switch to autotest
fsck.gfs2: Allocate enough space for the block map
libgfs2: Move the BLOCKMAP_* macros into fsck.gfs2
libgfs2: Add sd_heightsize bounds checking in read_sb
fsck.gfs2: Fix block size validation
gfs2l: Build with -D_FILE_OFFSET_BITS=64
libgfs2: Add lgfs2_open_mnt* functions
Switch is_pathname_mounted callers to lgfs2_open_mnt*
libgfs2: Remove is_pathname_mounted
libgfs2: Remove sdp argument from compute_heightsize
libgfs2: Remove sdp and j arguments from write_journal
libgfs2: Rework find_metapath
libgfs2: Improve and simplify blk_alloc_in_rg
mkfs.gfs2 tests: Enable debug output
libgfs2: Refactor block allocation functions
gfs2-utils: Clean up unused functions
libgfs2: Remove exit call from build_rgrps
gfs2_edit: Convert fssize to bytes before reporting fs size
gfs2-utils: Remove duplicate definitions of gfs1 structs
libgfs2: Superblock building and writing improvements
gfs2-utils: Ensure sb_uuid uses are guarded
libgfs2: Add support for new leaf hint fields
mkfs.gfs2: Remove a dead structure
libgfs2: Remove another exit() call
gfs2-utils: Fix up some errors reported by clang
gfs2_edit: Use the metadata description in get_block_type
gfs2_edit: More static analysis fixes
gfs2-utils: Fail to configure if flex is not found
mkfs.gfs2: Make dev a member of mkfs_opts
libgfs2: Add lgfs2_space_for_data()
libgfs2: Don't try to read more than IOV_MAX iovecs
mkfs.gfs2: Fix the resource group layout strategy, again
libgfs2: Don't call gfs2_blk2rgrpd in gfs2_set_bitmap
libgfs2: Add abstractions for rgrp tree traversal
libgfs2: Split out the rindex calculation from lgfs2_rgrp_append
libgfs2: Consolidate rgrp_tree and bitstruct allocations
libgfs2: Add a lgfs2_rindex_read_fd() function
libgfs2: Const-ify the 'ri' argument to gfs2_rindex_out
libgfs2: Fix off-by-one in lgfs2_rgrps_plan
libgfs2: Stick to the (rgrp) plan in lgfs2_rindex_entry_new
gfs2_grow: Migrate to the new resource group API
gfs2_grow: Add stripe alignment
fsck.gfs2: Log to syslog on start and exit
gfs2-utils: Expressly expunge 'expert mode'
libgfs2: Remove UI fields from struct gfs2_sbd
libgfs2: Remove debug field from gfs2_sbd
libgfs2: Remove logging API
gfs2_edit: Add a savemeta file metadata header
gfs2_edit: savemeta and restoremeta improvements
gfs2_edit: Fix parsing the savemeta -z option
gfs2-utils: Fix two logic errors
gfs2_edit: Ensure all leaf blocks in per_node are saved
gfs2-utils tests: Add small-block savemeta tests
libgfs2: Zero de_inum.no_addr when deleting dirents
libgfs2: Keep a pointer to the sbd in lgfs2_rgrps_t
libgfs2: Move bitmap buffers inside struct gfs2_bitmap
libgfs2: Fix an impossible loop condition in gfs2_rgrp_read
libgfs2: Introduce struct lgfs2_rbm
libgfs2: Move struct _lgfs2_rgrps into rgrp.h
libgfs2: Add functions for finding free extents
tests: Add unit tests for the new extent search functions
libgfs2: Ignore an empty rgrp plan if a length is specified
libgfs2: Add back-pointer to rgrps in lgfs2_rgrp_t
libgfs2: Const-ify the parameters of print functions
libgfs2: Allow init_dinode to accept a preallocated bh
libgfs2: Add extent allocation functions
libgfs2: Add support for allocating entire rgrp headers
libgfs2: Write file metadata sequentially
libgfs2: Fix alignment in lgfs2_rgsize_for_data
libgfs2: Handle non-zero bitmaps in lgfs2_rgrp_write
libgfs2: Add a speedier journal data block writing function
libgfs2: Create jindex directory separately from journals
mkfs.gfs2: Improve journal creation performance
mkfs.gfs2: Don't search the bitmaps to allocate journals
gfs2l: Fix uninitialised string warning
gfs2-utils: Remove target.mk files
gfs2-utils: Update translation template
libgfs2: Move unused gfs2_bmap into fsck.gfs2
Bob Peterson (14):
fsck.gfs2: Add ability to detect journal inode indirect block corruption
gfs2_tool: catch interrupts while the metafs is mounted
gfs2_edit: Add "journals" option to print journal info
fsck.gfs2: Check and repair per_node contents such as quota_changeX
gfs2_edit: Separate out the journal-related functions to journal.c
gfs2_edit: Add more intelligence to journal dumps
gfs2_edit: Report referencing block address in the new journal code
gfs2_edit: Improve log descriptor reference code
gfs2_edit: mark log headers with the unmounted flag
gfs2_edit: print LB (log descriptor continuation blocks) for GFS2
gfs2_edit: Print block types with log descriptors
fsck.gfs2: time each of the passes
fsck.gfs2: Issue read-ahead for dinodes in each bitmap
fsck.gfs2: File read-ahead
Shane Bradley (1):
gfs2_lockcapture: Fixed header to use absolute path and modified some options
9 years, 9 months