cluster: RHEL57 - gfs2_edit: Fix memory leak in savemeta option
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: ff658f227fa956f1f8e68d37ae49579960358cbd
Parent: 45b63600a8cc8836f48f580192ced51d0e2f3f7b
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Mon Dec 13 10:58:28 2010 -0600
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Wed Feb 2 14:36:09 2011 -0600
gfs2_edit: Fix memory leak in savemeta option
The savemeta option of gfs2_edit was not releasing its buffers
after they were used, so they kept accumulating in memory.
In large file systems, it was nearly impossible to save the metadata
because it would run out of memory and start swapping to disk.
rhbz#656371
---
gfs2/edit/savemeta.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index fbc1f4f..7c28ae9 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -46,7 +46,6 @@ struct saved_metablock {
};
struct saved_metablock *savedata;
-struct gfs2_buffer_head *savebh;
uint64_t last_fs_block, last_reported_block, blks_saved, total_out, pct;
uint64_t journal_blocks[MAX_JOURNALS_SAVED];
uint64_t gfs1_journal_size = 0; /* in blocks */
@@ -212,6 +211,7 @@ static int save_block(int fd, int out_fd, uint64_t blk)
int blktype, blklen, outsz;
uint16_t trailing0;
char *p;
+ struct gfs2_buffer_head *savebh;
if (blk > last_fs_block) {
fprintf(stderr, "\nWarning: bad block pointer '0x%llx' "
@@ -230,8 +230,10 @@ static int save_block(int fd, int out_fd, uint64_t blk)
inode, not the block within the inode "blk". They may or may not
be the same thing. */
if (get_gfs_struct_info(savebh, &blktype, &blklen) &&
- !block_is_systemfile())
+ !block_is_systemfile()) {
+ brelse(savebh);
return 0; /* Not metadata, and not system file, so skip it */
+ }
trailing0 = 0;
p = &savedata->buf[blklen - 1];
while (*p=='\0' && trailing0 < sbd.bsize) {
@@ -246,6 +248,7 @@ static int save_block(int fd, int out_fd, uint64_t blk)
do_write(out_fd, savedata->buf, outsz);
total_out += sizeof(savedata->blk) + sizeof(savedata->siglen) + outsz;
blks_saved++;
+ brelse(savebh);
return blktype;
}
13 years, 4 months
cluster: RHEL57 - gfs2_edit: give meaningful feedback for savemeta and restoremeta
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 45b63600a8cc8836f48f580192ced51d0e2f3f7b
Parent: 125c3caa0be6df210106eb451ba42801a9db5ceb
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Mon Dec 13 10:54:00 2010 -0600
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Wed Feb 2 14:36:09 2011 -0600
gfs2_edit: give meaningful feedback for savemeta and restoremeta
This patch gives the gfs2_edit "savemeta" and "restoremeta" options
a better way of giving meaningful progress feedback and size
information to the user.
rhbz#656371
---
gfs2/edit/savemeta.c | 120 ++++++++++++++++++++++++++------------------------
1 files changed, 63 insertions(+), 57 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index fbda237..fbc1f4f 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -73,6 +73,25 @@ static int block_is_systemfile(void)
block_is_per_node() || block_is_in_per_node();
}
+/**
+ * anthropomorphize - make a uint64_t number more human
+ */
+static const char *anthropomorphize(unsigned long long inhuman_value)
+{
+ const char *symbols = " KMGTPE";
+ int i;
+ unsigned long long val = inhuman_value, remainder;
+ static char out_val[32];
+
+ memset(out_val, 0, sizeof(out_val));
+ for (i = 0; i < 6 && val > 1024; i++) {
+ remainder = val % 1024;
+ val /= 1024;
+ }
+ sprintf(out_val, "%llu.%llu%c", val, remainder, symbols[i]);
+ return out_val;
+}
+
/*
* get_gfs_struct_info - get block type and structure length
*
@@ -162,7 +181,7 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,
/* checking every block kills performance. We only report */
/* every second because we don't need 100 extra messages in */
/* logs made from verbose mode. */
-static void warm_fuzzy_stuff(uint64_t wfsblock, int force, int save)
+static void warm_fuzzy_stuff(uint64_t wfsblock, int force)
{
static struct timeval tv;
static uint32_t seconds = 0;
@@ -177,22 +196,10 @@ static void warm_fuzzy_stuff(uint64_t wfsblock, int force, int save)
seconds = tv.tv_sec;
if (last_fs_block) {
printf("\r");
- if (save) {
- percent = (wfsblock * 100) / last_fs_block;
- printf("%" PRIu64 " metadata blocks (%"
- PRIu64 "%%) processed, ", wfsblock,
- percent);
- }
- if (total_out < 1024 * 1024)
- printf("%" PRIu64 " metadata blocks (%"
- PRIu64 "KB) %s. ",
- blks_saved, total_out / 1024,
- save?"saved":"restored");
- else
- printf("%" PRIu64 " metadata blocks (%"
- PRIu64 "MB) %s. ",
- blks_saved, total_out / (1024*1024),
- save?"saved":"restored");
+ percent = (wfsblock * 100) / last_fs_block;
+ printf("%" PRIu64 " metadata blocks (%"
+ PRIu64 "%%) processed, ", wfsblock,
+ percent);
if (force)
printf("\n");
fflush(stdout);
@@ -504,6 +511,7 @@ void savemeta(char *out_fn, int saveoption)
int rgcount;
uint64_t jindex_block;
struct gfs2_buffer_head *lbh;
+ struct rgrp_list *last_rgd, *prev_rgd;
slow = (saveoption == 1);
sbd.md.journals = 1;
@@ -558,8 +566,8 @@ void savemeta(char *out_fn, int saveoption)
}
}
last_fs_block = lseek(sbd.device_fd, 0, SEEK_END) / sbd.bsize;
- printf("There are %" PRIu64 " blocks of %u bytes.\n",
- last_fs_block, sbd.bsize);
+ printf("There are %" PRIu64 " blocks of %u bytes in the destination "
+ "device.\n", last_fs_block, sbd.bsize);
if (!slow) {
if (gfs1) {
sbd.md.riinode = inode_read(&sbd,
@@ -582,6 +590,7 @@ void savemeta(char *out_fn, int saveoption)
}
if (!slow) {
int sane;
+ uint64_t fssize;
printf("Reading resource groups...");
fflush(stdout);
@@ -589,7 +598,16 @@ void savemeta(char *out_fn, int saveoption)
slow = gfs1_ri_update(&sbd, 0, &rgcount, 0);
else
slow = ri_update(&sbd, 0, &rgcount, &sane);
- printf("Done.\n\n");
+ last_rgd = osi_list_entry(sbd.rglist.prev,
+ struct rgrp_list, list);
+ prev_rgd = osi_list_entry(last_rgd->list.prev,
+ struct rgrp_list, list);
+ fssize = last_rgd->ri.ri_addr +
+ (last_rgd->ri.ri_addr - prev_rgd->ri.ri_addr);
+ last_fs_block = fssize;
+ fssize *= sbd.bsize;
+ printf("Done. File system size: %s\n\n",
+ anthropomorphize(fssize));
fflush(stdout);
}
get_journal_inode_blocks();
@@ -632,7 +650,7 @@ void savemeta(char *out_fn, int saveoption)
/* Save off the rg and bitmaps */
for (block = rgd->ri.ri_addr;
block < rgd->ri.ri_data0; block++) {
- warm_fuzzy_stuff(block, FALSE, TRUE);
+ warm_fuzzy_stuff(block, FALSE);
save_block(sbd.device_fd, out_fd, block);
}
/* Save off the other metadata: inodes, etc. */
@@ -640,7 +658,7 @@ void savemeta(char *out_fn, int saveoption)
int blktype;
while (!gfs2_next_rg_meta(rgd, &block, first)){
- warm_fuzzy_stuff(block, FALSE, TRUE);
+ warm_fuzzy_stuff(block, FALSE);
blktype = save_block(sbd.device_fd,
out_fd, block);
if (blktype == GFS2_METATYPE_DI)
@@ -669,7 +687,7 @@ void savemeta(char *out_fn, int saveoption)
/* There may be a gap between end of file system and end of device */
/* so we tell the user that we've processed everything. */
block = last_fs_block;
- warm_fuzzy_stuff(block, TRUE, TRUE);
+ warm_fuzzy_stuff(block, TRUE);
printf("\nMetadata saved to file %s.\n", out_fn);
free(savedata);
close(out_fd);
@@ -677,24 +695,8 @@ void savemeta(char *out_fn, int saveoption)
exit(0);
}
-/**
- * anthropomorphize - make a uint64_t number more human
- */
-static const char *anthropomorphize(unsigned long long inhuman_value)
-{
- const char *symbols = " KMGTPE";
- int i;
- unsigned long long val = inhuman_value;
- static char out_val[32];
-
- memset(out_val, 0, sizeof(out_val));
- for (i = 0; i < 6 && val > 1024; i++)
- val /= 1024;
- sprintf(out_val, "%llu%c", val, symbols[i]);
- return out_val;
-}
-
-static int restore_data(int fd, int in_fd, int printblocksonly)
+static int restore_data(int fd, int in_fd, int printblocksonly,
+ int find_highblk)
{
size_t rs;
uint64_t buf64, writes = 0, highest_valid_block = 0;
@@ -773,24 +775,23 @@ static int restore_data(int fd, int in_fd, int printblocksonly)
gfs2_sb_in(&sbd.sd_sb, &dummy_bh);
sbd1 = (struct gfs_sb *)&sbd.sd_sb;
if (sbd1->sb_fs_format == GFS_FORMAT_FS &&
- sbd1->sb_header.mh_type ==
- GFS_METATYPE_SB &&
- sbd1->sb_header.mh_format ==
- GFS_FORMAT_SB &&
- sbd1->sb_multihost_format ==
- GFS_FORMAT_MULTI) {
+ sbd1->sb_header.mh_type == GFS_METATYPE_SB &&
+ sbd1->sb_header.mh_format == GFS_FORMAT_SB &&
+ sbd1->sb_multihost_format == GFS_FORMAT_MULTI) {
gfs1 = TRUE;
} else if (check_sb(&sbd.sd_sb)) {
fprintf(stderr,"Error: Invalid superblock data.\n");
return -1;
}
sbd.bsize = sbd.sd_sb.sb_bsize;
- if (!printblocksonly) {
+ if (find_highblk)
+ ;
+ else if (!printblocksonly) {
last_fs_block =
lseek(fd, 0, SEEK_END) / sbd.bsize;
printf("There are %" PRIu64 " blocks of " \
"%u bytes in the destination" \
- " file system.\n\n",
+ " device.\n\n",
last_fs_block, sbd.bsize);
} else {
printf("This is %s metadata\n", gfs1 ?
@@ -800,10 +801,12 @@ static int restore_data(int fd, int in_fd, int printblocksonly)
}
bh = &dummy_bh;
bh->b_data = savedata->buf;
- if (printblocksonly) {
+ if (savedata->blk > highest_valid_block)
+ highest_valid_block = savedata->blk;
+ if (find_highblk)
+ ;
+ else if (printblocksonly) {
block = savedata->blk;
- if (block > highest_valid_block)
- highest_valid_block = block;
if (printblocksonly > 1 && printblocksonly == block) {
block_in_mem = block;
display(0);
@@ -814,7 +817,7 @@ static int restore_data(int fd, int in_fd, int printblocksonly)
display_block_type(TRUE);
}
} else {
- warm_fuzzy_stuff(savedata->blk, FALSE, FALSE);
+ warm_fuzzy_stuff(savedata->blk, FALSE);
if (savedata->blk >= last_fs_block) {
printf("\nOut of space on the destination "
"device; quitting.\n");
@@ -843,13 +846,15 @@ static int restore_data(int fd, int in_fd, int printblocksonly)
}
blks_saved++;
}
- if (!printblocksonly)
- warm_fuzzy_stuff(savedata->blk, TRUE, FALSE);
- else
+ if (!printblocksonly && !find_highblk)
+ warm_fuzzy_stuff(last_fs_block, TRUE);
+ if (find_highblk) {
printf("File system size: %lld (0x%llx) blocks, aka %sB\n",
(unsigned long long)highest_valid_block,
(unsigned long long)highest_valid_block,
anthropomorphize(highest_valid_block * sbd.bsize));
+ last_fs_block = highest_valid_block;
+ }
return 0;
}
@@ -888,7 +893,8 @@ void restoremeta(const char *in_fn, const char *out_device,
die("Can't allocate memory for the restore operation.\n");
blks_saved = 0;
- error = restore_data(sbd.device_fd, in_fd, printblocksonly);
+ restore_data(sbd.device_fd, in_fd, printblocksonly, 1);
+ error = restore_data(sbd.device_fd, in_fd, printblocksonly, 0);
printf("File %s %s %s.\n", in_fn,
(printblocksonly ? "print" : "restore"),
(error ? "error" : "successful"));
13 years, 4 months
cluster: RHEL57 - gfs2_edit: tiny (stuffed) files had user data saved with savemeta
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 125c3caa0be6df210106eb451ba42801a9db5ceb
Parent: 958040b30a788f48c0451ca589db4018b4a325af
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Mon Dec 13 10:52:25 2010 -0600
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Wed Feb 2 14:36:09 2011 -0600
gfs2_edit: tiny (stuffed) files had user data saved with savemeta
The gfs2_edit savemeta option was saving the entire block for dinodes.
That's okay for average files where you need to save indirect block
pointers. It's okay for directories where you need to save the
directory block pointers. It's okay for system files where you want
to save statfs data or inum data and such. But it's not okay with
stuffed user files because they contain user data. This patch checks
for this special dinode condition and saves only the dinode
structure.
rhbz#656371
---
gfs2/edit/savemeta.c | 51 +++++++++++++++++++++++++++++++------------------
1 files changed, 32 insertions(+), 19 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 273178f..fbda237 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -55,6 +55,24 @@ int journals_found = 0;
extern void read_superblock(void);
uint64_t masterblock(const char *fn);
+static int block_is_a_journal(void)
+{
+ int j;
+
+ for (j = 0; j < journals_found; j++)
+ if (block == journal_blocks[j])
+ return TRUE;
+ return FALSE;
+}
+
+static int block_is_systemfile(void)
+{
+ return block_is_jindex() || block_is_inum_file() ||
+ block_is_statfs_file() || block_is_quota_file() ||
+ block_is_rindex() || block_is_a_journal() ||
+ block_is_per_node() || block_is_in_per_node();
+}
+
/*
* get_gfs_struct_info - get block type and structure length
*
@@ -68,6 +86,7 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,
int *gstruct_len)
{
struct gfs2_meta_header mh;
+ struct gfs2_inode *inode;
*block_type = 0;
*gstruct_len = sbd.bsize;
@@ -89,7 +108,19 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,
*gstruct_len = sbd.bsize;
break;
case GFS2_METATYPE_DI: /* 4 (disk inode) */
- *gstruct_len = sbd.bsize; /*sizeof(struct gfs_dinode);*/
+ if (gfs1)
+ inode = inode_get(&sbd, lbh);
+ else
+ inode = gfs_inode_get(&sbd, lbh);
+ if (inode->i_di.di_flags & GFS2_DIF_EXHASH &&
+ (S_ISDIR(inode->i_di.di_mode) ||
+ (gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR)))
+ *gstruct_len = sbd.bsize;
+ else if (!inode->i_di.di_height && !block_is_systemfile() &&
+ !S_ISDIR(inode->i_di.di_mode))
+ *gstruct_len = sizeof(struct gfs2_dinode);
+ else
+ *gstruct_len = sbd.bsize;
break;
case GFS2_METATYPE_IN: /* 5 (indir inode blklst) */
*gstruct_len = sbd.bsize; /*sizeof(struct gfs_indirect);*/
@@ -169,24 +200,6 @@ static void warm_fuzzy_stuff(uint64_t wfsblock, int force, int save)
}
}
-static int block_is_a_journal(void)
-{
- int j;
-
- for (j = 0; j < journals_found; j++)
- if (block == journal_blocks[j])
- return TRUE;
- return FALSE;
-}
-
-static int block_is_systemfile(void)
-{
- return block_is_jindex() || block_is_inum_file() ||
- block_is_statfs_file() || block_is_quota_file() ||
- block_is_rindex() || block_is_a_journal() ||
- block_is_per_node() || block_is_in_per_node();
-}
-
static int save_block(int fd, int out_fd, uint64_t blk)
{
int blktype, blklen, outsz;
13 years, 4 months
cluster: RHEL57 - gfs2_edit: negative block numbers don't jump a negative amount
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 958040b30a788f48c0451ca589db4018b4a325af
Parent: 7c8b325db69186d61a44a0f38c46278ea000b2a6
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Mon Dec 13 10:46:17 2010 -0600
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Wed Feb 2 14:36:09 2011 -0600
gfs2_edit: negative block numbers don't jump a negative amount
This patch fixes a bug whereby entering a negative block number
in the block address was not jumping the appropriate amount.
rhbz#656371
---
gfs2/edit/hexedit.c | 17 +++++------------
1 files changed, 5 insertions(+), 12 deletions(-)
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 196b324..1c3fafe 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -2242,26 +2242,19 @@ uint64_t check_keywords(const char *kword)
static uint64_t goto_block(void)
{
char string[256];
- int ch;
+ int ch, delta;
memset(string, 0, sizeof(string));
sprintf(string,"%"PRId64, block);
if (bobgets(string, 1, 7, 16, &ch)) {
if (isalnum(string[0]) || string[0] == '/')
temp_blk = check_keywords(string);
- else if (string[0] == '+') {
- if (string[1] == '0' && string[2] == 'x')
- sscanf(string, "%"SCNx64, &temp_blk);
- else
- sscanf(string, "%" PRIu64, &temp_blk);
- temp_blk += block;
- }
- else if (string[0] == '-') {
+ else if (string[0] == '+' || string[0] == '-') {
if (string[1] == '0' && string[2] == 'x')
- sscanf(string, "%"SCNx64, &temp_blk);
+ sscanf(string, "%x", &delta);
else
- sscanf(string, "%" PRIu64, &temp_blk);
- temp_blk -= block;
+ sscanf(string, "%d", &delta);
+ temp_blk = block + delta;
}
if (temp_blk == RGLIST_DUMMY_BLOCK || temp_blk < max_block) {
13 years, 4 months
cluster: RHEL57 - gfs2_edit: print hex numbers in lower-case
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 7c8b325db69186d61a44a0f38c46278ea000b2a6
Parent: c9c57f5f0409743435e171c57cc7e59bd0b09cac
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Mon Dec 13 10:45:03 2010 -0600
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Wed Feb 2 14:36:08 2011 -0600
gfs2_edit: print hex numbers in lower-case
This patch changes the gfs2_edit output so it always prints hex
numbers in lower-case so they match debug output from the debugfs
and dmesg.
rhbz#656371
---
gfs2/edit/hexedit.c | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index c7d1849..196b324 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -358,7 +358,7 @@ static int bobgets(char string[],int x,int y,int sz,int *ch)
break;
default:
move(0,70);
- printw("%08X",*ch);
+ printw("%08x",*ch);
// ignore all other characters
break;
} // end switch on non-printable character
@@ -494,7 +494,7 @@ int display_block_type(int from_restore)
else
print_gfs2(" ");
if (!from_restore) {
- print_gfs2("of %" PRIu64 " (0x%" PRIX64 ")", max_block,
+ print_gfs2("of %" PRIu64 " (0x%" PRIx64 ")", max_block,
max_block);
if (termlines)
move(line, 55);
@@ -670,7 +670,7 @@ static int hexdump(uint64_t startaddr, int len)
uint64_t l;
const char *lpBuffer = bh->b_data;
- strcpy(edit_fmt,"%02X");
+ strcpy(edit_fmt,"%02x");
pointer = (unsigned char *)lpBuffer + offset;
ptr2 = (unsigned char *)lpBuffer + offset;
l = offset;
@@ -687,9 +687,9 @@ static int hexdump(uint64_t startaddr, int len)
COLORS_OFFSETS; /* cyan for offsets */
}
if (startaddr < 0xffffffff)
- print_gfs2("%.8"PRIX64, startaddr + l);
+ print_gfs2("%.8"PRIx64, startaddr + l);
else
- print_gfs2("%.16"PRIX64, startaddr + l);
+ print_gfs2("%.16"PRIx64, startaddr + l);
if (termlines) {
if (l < struct_len)
COLORS_NORMAL; /* normal part of structure */
@@ -742,9 +742,9 @@ static int hexdump(uint64_t startaddr, int len)
i == edit_col[dmode]) {
COLORS_HIGHLIGHT; /* in the structure */
memset(estring,0,3);
- sprintf(estring,"%02X",*pointer);
+ sprintf(estring,"%02x",*pointer);
}
- print_gfs2("%02X",*pointer);
+ print_gfs2("%02x",*pointer);
if (termlines && line == edit_row[dmode] + 3 &&
i == edit_col[dmode]) {
if (l < struct_len + offset)
@@ -2892,7 +2892,7 @@ static void interactive_mode(void)
break;
default:
move(termlines - 1, 0);
- printw("Keystroke not understood: 0x%03X",ch);
+ printw("Keystroke not understood: 0x%03x",ch);
refresh();
usleep(50000);
break;
@@ -2933,7 +2933,7 @@ void gfs_log_header_in(struct gfs_log_header *head,
void gfs_log_header_print(struct gfs_log_header *lh)
{
gfs2_meta_header_print(&lh->lh_header);
- pv(lh, lh_flags, "%u", "0x%.8X");
+ pv(lh, lh_flags, "%u", "0x%.8x");
pv(lh, lh_pad, "%u", "%x");
pv((unsigned long long)lh, lh_first, "%llu", "%llx");
pv((unsigned long long)lh, lh_sequence, "%llu", "%llx");
13 years, 4 months
cluster: RHEL57 - gfs2_edit: better printing of directory leaf information
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: c9c57f5f0409743435e171c57cc7e59bd0b09cac
Parent: 3575517393317423b10a9717fc5157261993625d
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Mon Dec 13 10:42:38 2010 -0600
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Wed Feb 2 14:36:08 2011 -0600
gfs2_edit: better printing of directory leaf information
This patch gives gfs2_edit the ability to better parse out and print
directory information for exhash directories several levels deep.
rhbz#656371
---
gfs2/edit/gfs2hex.c | 13 ++++-
gfs2/edit/gfs2hex.h | 2 +-
gfs2/edit/hexedit.c | 135 +++++++++++++++++++++++++++++++--------------------
gfs2/edit/hexedit.h | 4 ++
4 files changed, 99 insertions(+), 55 deletions(-)
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index 2934877..1505783 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -425,17 +425,25 @@ int do_indirect_extended(char *buf, struct iinfo *iinf, int hgt)
**
** Output(s):
**
-** Returns:
+** Returns: next leaf block, if any, in a chain of leaf blocks
**
*******************************************************************************
******************************************************************************/
-void do_leaf_extended(char *dlebuf, struct iinfo *indir)
+uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir)
{
int x, i;
struct gfs2_dirent de;
+ struct gfs2_leaf leaf;
+ struct gfs2_buffer_head tbh; /* kludge */
x = 0;
memset(indir, 0, sizeof(*indir));
+ tbh.b_data = dlebuf;
+ gfs2_leaf_in(&leaf, &tbh);
+ indir->ii[0].lf_depth = leaf.lf_depth;
+ indir->ii[0].lf_entries = leaf.lf_entries;
+ indir->ii[0].lf_dirent_format = leaf.lf_dirent_format;
+ indir->ii[0].lf_next = leaf.lf_next;
/* Directory Entries: */
for (i = sizeof(struct gfs2_leaf); i < sbd.bsize;
i += de.de_rec_len) {
@@ -456,6 +464,7 @@ void do_leaf_extended(char *dlebuf, struct iinfo *indir)
if (de.de_rec_len <= sizeof(struct gfs2_dirent))
break;
}
+ return leaf.lf_next;
}
diff --git a/gfs2/edit/gfs2hex.h b/gfs2/edit/gfs2hex.h
index ebe6b0e..7b98d44 100644
--- a/gfs2/edit/gfs2hex.h
+++ b/gfs2/edit/gfs2hex.h
@@ -21,7 +21,7 @@ int edit_gfs2(void);
void do_dinode_extended(struct gfs2_dinode *di, struct gfs2_buffer_head *lbh);
void print_gfs2(const char *fmt, ...);
int do_indirect_extended(char *diebuf, struct iinfo *iinf, int hgt);
-void do_leaf_extended(char *dlebuf, struct iinfo *indir);
+uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir);
void eol(int col);
#endif /* __GFS2HEX_DOT_H__ */
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 8919cef..c7d1849 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -95,6 +95,9 @@ extern void restoremeta(const char *in_fn, const char *out_device,
} \
} while(0)
+static int display_indirect(struct iinfo *ind, int indblocks, int level,
+ uint64_t startoff);
+
static int gfs2_dinode_printval(struct gfs2_dinode *dip, const char *strfield)
{
checkprint(strfield, dip, di_mode);
@@ -1267,7 +1270,11 @@ static int display_leaf(struct iinfo *ind)
if (gfs2_struct_type == GFS2_METATYPE_SB)
print_gfs2("The superblock has 2 directories");
else
- print_gfs2("This directory block contains %d directory entries.",
+ print_gfs2("Directory block: lf_depth:%d, lf_entries:%d,"
+ "fmt:%d next=0x%llx (%d dirents).",
+ ind->ii[0].lf_depth, ind->ii[0].lf_entries,
+ ind->ii[0].lf_dirent_format,
+ ind->ii[0].lf_next,
ind->ii[0].dirents);
start_line = line;
@@ -1276,7 +1283,7 @@ static int display_leaf(struct iinfo *ind)
+ start_row[dmode])
break;
total_dirents++;
- if (ind->ii[0].dirents > 1) {
+ if (ind->ii[0].dirents >= 1) {
eol(5);
if (termlines) {
if (edit_row[dmode] >=0 &&
@@ -1370,9 +1377,76 @@ static int get_height(void)
}
/* ------------------------------------------------------------------------ */
+/* print_block_details */
+/* ------------------------------------------------------------------------ */
+static void print_block_details(struct iinfo *ind, int level, int cur_height,
+ int pndx, uint64_t file_offset)
+{
+ struct iinfo *more_indir;
+ int more_ind;
+ char *tmpbuf;
+ uint64_t thisblk;
+
+ thisblk = ind->ii[pndx].block;
+ more_indir = malloc(sizeof(struct iinfo));
+ if (!more_indir) {
+ fprintf(stderr, "Out of memory in function "
+ "display_indirect\n");
+ return;
+ }
+ tmpbuf = malloc(sbd.bsize);
+ if (!tmpbuf) {
+ fprintf(stderr, "Out of memory in function "
+ "display_indirect\n");
+ return;
+ }
+ while (thisblk) {
+ lseek(sbd.device_fd, thisblk * sbd.bsize, SEEK_SET);
+ /* read in the desired block */
+ if (read(sbd.device_fd, tmpbuf, sbd.bsize) != sbd.bsize) {
+ fprintf(stderr, "bad read: %s from %s:%d: block %lld "
+ "(0x%llx)\n", strerror(errno), __FUNCTION__,
+ __LINE__,
+ (unsigned long long)ind->ii[pndx].block,
+ (unsigned long long)ind->ii[pndx].block);
+ exit(-1);
+ }
+ thisblk = 0;
+ memset(more_indir, 0, sizeof(struct iinfo));
+ if (S_ISDIR(di.di_mode) && level == di.di_height) {
+ thisblk = do_leaf_extended(tmpbuf, more_indir);
+ display_leaf(more_indir);
+ } else {
+ int x;
+
+ for (x = 0; x < 512; x++) {
+ memcpy(&more_indir->ii[x].mp,
+ &ind->ii[pndx].mp,
+ sizeof(struct metapath));
+ more_indir->ii[x].mp.mp_list[cur_height+1] = x;
+ }
+ more_ind = do_indirect_extended(tmpbuf, more_indir,
+ cur_height + 1);
+ display_indirect(more_indir, more_ind, level + 1,
+ file_offset);
+ }
+ if (thisblk) {
+ eol(0);
+ if (termlines)
+ move(line,9);
+ print_gfs2("Continuation block 0x%llx / %lld",
+ thisblk, thisblk);
+ }
+ }
+ free(tmpbuf);
+ free(more_indir);
+}
+
+/* ------------------------------------------------------------------------ */
/* display_indirect */
/* ------------------------------------------------------------------------ */
-static int display_indirect(struct iinfo *ind, int indblocks, int level, uint64_t startoff)
+static int display_indirect(struct iinfo *ind, int indblocks, int level,
+ uint64_t startoff)
{
int start_line, total_dirents;
int cur_height = -1, pndx;
@@ -1388,8 +1462,7 @@ static int display_indirect(struct iinfo *ind, int indblocks, int level, uint64_
else
print_gfs2("This inode contains %d indirect blocks",
indblocks);
- }
- else
+ } else
print_gfs2("This indirect block contains %d indirect blocks",
indblocks);
}
@@ -1417,6 +1490,8 @@ static int display_indirect(struct iinfo *ind, int indblocks, int level, uint64_
pndx++) {
uint64_t file_offset;
+ if (pndx && ind->ii[pndx].block == ind->ii[pndx - 1].block)
+ continue;
print_entry_ndx = pndx;
if (termlines) {
if (edit_row[dmode] >= 0 &&
@@ -1470,53 +1545,9 @@ static int display_indirect(struct iinfo *ind, int indblocks, int level, uint64_
file_offset = 0;
if (dinode_valid() && !termlines &&
((level + 1 < di.di_height) ||
- (S_ISDIR(di.di_mode) && !level))) {
- struct iinfo *more_indir;
- int more_ind;
- char *tmpbuf;
-
- more_indir = malloc(sizeof(struct iinfo));
- tmpbuf = malloc(sbd.bsize);
- if (tmpbuf) {
- lseek(sbd.device_fd,
- ind->ii[pndx].block * sbd.bsize,
- SEEK_SET);
- /* read in the desired block */
- if (read(sbd.device_fd, tmpbuf, sbd.bsize) !=
- sbd.bsize) {
- fprintf(stderr, "bad read: %s from %s:"
- "%d: block %lld (0x%llx)\n",
- strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)ind->ii[pndx].block,
- (unsigned long long)ind->ii[pndx].block);
- exit(-1);
- }
- memset(more_indir, 0, sizeof(struct iinfo));
- if (S_ISDIR(di.di_mode)) {
- do_leaf_extended(tmpbuf, more_indir);
- display_leaf(more_indir);
- } else {
- int x;
-
- for (x = 0; x < 512; x++) {
- memcpy(&more_indir->ii[x].mp,
- &ind->ii[pndx].mp,
- sizeof(struct metapath));
- more_indir->ii[x].
- mp.mp_list[cur_height+1] =
- x;
- }
- more_ind = do_indirect_extended(tmpbuf,
- more_indir,
- cur_height + 1);
- display_indirect(more_indir,
- more_ind, level + 1,
- file_offset);
- }
- free(tmpbuf);
- }
- free(more_indir);
+ (S_ISDIR(di.di_mode) && level <= di.di_height))) {
+ print_block_details(ind, level, cur_height, pndx,
+ file_offset);
}
print_entry_ndx = pndx; /* restore after recursion */
eol(0);
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index d78779d..15aa112 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -202,6 +202,10 @@ struct indirect_info {
int height;
uint64_t block;
uint32_t dirents;
+ uint16_t lf_depth;
+ uint16_t lf_entries;
+ uint32_t lf_dirent_format;
+ uint64_t lf_next;
struct metapath mp;
struct gfs2_dirents dirent[64];
};
13 years, 4 months
cluster: STABLE31 - build: allow dbus notification code to be disabled
by Lon Hohberger
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 5d044c3b62d51c688257faecd69bbf3112d7728f
Parent: e7aa9a1ed52b7225a11e4865ed00594c15149bcf
Author: Fabio M. Di Nitto <fdinitto(a)redhat.com>
AuthorDate: Wed Feb 2 10:34:58 2011 +0100
Committer: Lon Hohberger <lhh(a)redhat.com>
CommitterDate: Wed Feb 2 15:36:34 2011 -0500
build: allow dbus notification code to be disabled
default is to build with dbus support
Signed-off-by: Fabio M. Di Nitto <fdinitto(a)redhat.com>
Signed-off-by: Lon Hohberger <lhh(a)redhat.com>
---
configure | 7 +++++++
make/defines.mk.input | 1 +
rgmanager/src/daemons/Makefile | 6 +++++-
3 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/configure b/configure
index 7e1aca7..9c7a773 100755
--- a/configure
+++ b/configure
@@ -73,6 +73,7 @@ my %options = (
confdir => \$confdir,
conffile => \$conffile,
enable_contrib => \$enable_contrib,
+ disable_dbus => \$disable_dbus,
somajor => \$somajor,
sominor => \$sominor,
release_version => \$release_version,
@@ -144,6 +145,7 @@ my $err = &GetOptions (\%options,
'sominor=s',
'release_version=s',
'enable_contrib',
+ 'disable_dbus',
'without_common',
'without_config',
'without_cman',
@@ -219,6 +221,7 @@ if ($help || !$err) {
print "--ldapincdir=\tthe base directory for ldap include files. (Default: {incdir})\n";
print "--ldaplibdir=\tthe base directory for ldap libraries. (Default: {libdir})\n";
print "--enable_contrib\tEnable build of community contributed code/tools. (Default: no)\n";
+ print "--disable_dbus\tDisable built-in support for dbus notifications. (Default: no)\n";
print "--without_common\tDisable common building (Default: enabled)\n";
print "--without_config\tDisable config building (Default: enabled)\n";
print "--without_cman\tDisable cman building (Default: enabled)\n";
@@ -504,6 +507,9 @@ if (!$conffile) {
if (!$enable_contrib) {
$enable_contrib="";
}
+if (!$disable_dbus) {
+ $disable_dbus="";
+}
if (!$without_common) {
$without_common="";
}
@@ -598,6 +604,7 @@ while (<IFILE>) {
$_ =~ s/\@CONFDIR\@/$confdir/;
$_ =~ s/\@CONFFILE\@/$conffile/;
$_ =~ s/\@ENABLE_CONTRIB\@/$enable_contrib/;
+ $_ =~ s/\@DISABLE_DBUS\@/$disable_dbus/;
$_ =~ s/\@DISABLE_COMMON\@/$without_common/;
$_ =~ s/\@DISABLE_CONFIG\@/$without_config/;
$_ =~ s/\@DISABLE_CMAN\@/$without_cman/;
diff --git a/make/defines.mk.input b/make/defines.mk.input
index 3751cf5..ee5f852 100644
--- a/make/defines.mk.input
+++ b/make/defines.mk.input
@@ -58,6 +58,7 @@ ldaplibdir ?= @LDAPLIBDIR@
zlibincdir ?= @ZLIBINCDIR@
zliblibdir ?= @ZLIBLIBDIR@
contrib_code ?= @ENABLE_CONTRIB@
+disable_dbus ?= @DISABLE_DBUS@
without_common ?= @DISABLE_COMMON@
without_config ?= @DISABLE_CONFIG@
without_cman ?= @DISABLE_CMAN@
diff --git a/rgmanager/src/daemons/Makefile b/rgmanager/src/daemons/Makefile
index 9619990..7218c53 100644
--- a/rgmanager/src/daemons/Makefile
+++ b/rgmanager/src/daemons/Makefile
@@ -47,7 +47,6 @@ CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${dlmincdir} -I${logtincdir}
CFLAGS += `xml2-config --cflags` -I${slangincdir}
CFLAGS += -I$(S)/../../include
CFLAGS += -I${incdir}
-CFLAGS += `pkg-config --cflags dbus-1`
NOCCS_CFLAGS += -DNO_CCS
@@ -61,7 +60,12 @@ DLM_LDFLAGS += -L${dlmlibdir} -ldlm
XML2_LDFLAGS += `xml2-config --libs`
SLANG_LDFLAGS += -L${slanglibdir} -lslang
EXTRA_LDFLAGS += -lpthread
+
+# dbus support for notifications
+ifndef disable_dbus
+CFLAGS += -DDBUS `pkg-config --cflags dbus-1`
DBUS_LDFLAGS += `pkg-config --libs dbus-1`
+endif
LDDEPS += ../clulib/libclulib.a
13 years, 4 months
cluster: STABLE31 - rgmanager: Match fenced's option to disable DBus
by Lon Hohberger
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: e7aa9a1ed52b7225a11e4865ed00594c15149bcf
Parent: 7e86355c80c5a44755e8989bbbd855b03d0d613e
Author: Lon Hohberger <lhh(a)redhat.com>
AuthorDate: Wed Feb 2 14:21:29 2011 -0500
Committer: Lon Hohberger <lhh(a)redhat.com>
CommitterDate: Wed Feb 2 15:36:34 2011 -0500
rgmanager: Match fenced's option to disable DBus
Signed-off-by: Lon Hohberger <lhh(a)redhat.com>
---
rgmanager/man/rgmanager.8 | 2 +-
rgmanager/src/daemons/main.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/rgmanager/man/rgmanager.8 b/rgmanager/man/rgmanager.8
index a4e2c73..2b018d2 100644
--- a/rgmanager/man/rgmanager.8
+++ b/rgmanager/man/rgmanager.8
@@ -371,7 +371,7 @@ will leave the virtual machine running.
Run in the foreground (do not fork).
.IP \-d
Enable debug-level logging.
-.IP \-D
+.IP \-q
Disable DBus signals which are normally sent when services change state.
.IP \-w
Disable internal process monitoring (for debugging).
diff --git a/rgmanager/src/daemons/main.c b/rgmanager/src/daemons/main.c
index dad379a..02cd2dc 100644
--- a/rgmanager/src/daemons/main.c
+++ b/rgmanager/src/daemons/main.c
@@ -951,7 +951,7 @@ main(int argc, char **argv)
pthread_t th;
cman_handle_t clu = NULL;
- while ((rv = getopt(argc, argv, "wfdND")) != EOF) {
+ while ((rv = getopt(argc, argv, "wfdNq")) != EOF) {
switch (rv) {
case 'w':
wd = 0;
@@ -965,7 +965,7 @@ main(int argc, char **argv)
case 'f':
foreground = 1;
break;
- case 'D':
+ case 'q':
rgm_dbus_notify = 0;
break;
default:
13 years, 4 months
cluster: STABLE31 - rgmanager: minor dbus cleanups
by Lon Hohberger
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 7e86355c80c5a44755e8989bbbd855b03d0d613e
Parent: 2bb7321cbf54fe39f561a2ba172d0b6e17da926f
Author: Lon Hohberger <lhh(a)redhat.com>
AuthorDate: Wed Feb 2 14:15:32 2011 -0500
Committer: Lon Hohberger <lhh(a)redhat.com>
CommitterDate: Wed Feb 2 15:36:34 2011 -0500
rgmanager: minor dbus cleanups
Signed-off-by: Lon Hohberger <lhh(a)redhat.com>
---
rgmanager/src/daemons/update-dbus.c | 31 +++++++++++++++++++++----------
1 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/rgmanager/src/daemons/update-dbus.c b/rgmanager/src/daemons/update-dbus.c
index c9bbf40..f465d1d 100644
--- a/rgmanager/src/daemons/update-dbus.c
+++ b/rgmanager/src/daemons/update-dbus.c
@@ -47,7 +47,7 @@ rgm_dbus_init(void)
dbc = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
if (!dbc) {
- logt_print(LOG_ERR,
+ logt_print(LOG_DEBUG,
"DBus Failed to initialize: dbus_bus_get: %s\n",
err.message);
dbus_error_free(&err);
@@ -72,7 +72,7 @@ rgm_dbus_init(void)
#ifdef DBUS
static int
-_rgm_dbus_release(int err)
+_rgm_dbus_release(void)
{
pthread_t t;
@@ -83,7 +83,7 @@ _rgm_dbus_release(int err)
* to wake up, so just have it poll XXX */
/* if the thread left because the dbus connection died,
- this block is avoided since the thread exits */
+ this block is avoided */
if (th) {
t = th;
th = 0;
@@ -94,15 +94,13 @@ _rgm_dbus_release(int err)
dbus_connection_unref(db);
db = NULL;
- if (err)
- logt_print(LOG_ERR, "DBus Connection Lost\n");
- else
- logt_print(LOG_DEBUG, "DBus Released\n");
+ logt_print(LOG_DEBUG, "DBus Released\n");
return 0;
}
#endif
+/* Clean shutdown (e.g. when exiting */
int
rgm_dbus_release(void)
#ifdef DBUS
@@ -110,7 +108,7 @@ rgm_dbus_release(void)
int ret;
pthread_mutex_lock(&mu);
- ret = _rgm_dbus_release(0);
+ ret = _rgm_dbus_release();
pthread_mutex_unlock(&mu);
return ret;
}
@@ -122,6 +120,9 @@ rgm_dbus_release(void)
#ifdef DBUS
+/* Auto-flush thread. Since sending only guarantees queueing,
+ * we need this thread to push things out over dbus in the
+ * background */
static void *
_dbus_auto_flush(void *arg)
{
@@ -154,8 +155,15 @@ _rgm_dbus_notify(const char *svcname,
pthread_mutex_lock(&mu);
+ /* Check to ensure the connection is still valid. If it
+ * isn't, clean up and shut down the dbus connection.
+ *
+ * The main rgmanager thread will periodically try to
+ * reinitialize the dbus notification subsystem unless
+ * the administrator ran rgmanager with the -D command
+ * line option.
+ */
if (dbus_connection_get_is_connected(db) != TRUE) {
- _rgm_dbus_release(1);
goto out_unlock;
}
@@ -192,6 +200,9 @@ out_free:
}
+/*
+ * view-formation callback function
+ */
int32_t
rgm_dbus_update(char *key, uint64_t view, void *data, uint32_t size)
{
@@ -242,7 +253,7 @@ rgm_dbus_update(char *key, uint64_t view, void *data, uint32_t size)
if (ret < 0) {
logt_print(LOG_ERR, "Error sending update for %s; "
- "notifications disabled\n", key);
+ "DBus notifications disabled\n", key);
rgm_dbus_release();
}
13 years, 4 months
cluster: STABLE31 - rgmanager: Retry dbus if we get disconnected
by Lon Hohberger
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 2bb7321cbf54fe39f561a2ba172d0b6e17da926f
Parent: 09aa67a2d768fc0f1e4185ca198398ec809c13b5
Author: Lon Hohberger <lhh(a)redhat.com>
AuthorDate: Wed Feb 2 13:48:10 2011 -0500
Committer: Lon Hohberger <lhh(a)redhat.com>
CommitterDate: Wed Feb 2 15:36:34 2011 -0500
rgmanager: Retry dbus if we get disconnected
Signed-off-by: Lon Hohberger <lhh(a)redhat.com>
---
rgmanager/src/daemons/main.c | 9 ++++-
rgmanager/src/daemons/update-dbus.c | 60 ++++++++++++++++++++++++-----------
2 files changed, 48 insertions(+), 21 deletions(-)
diff --git a/rgmanager/src/daemons/main.c b/rgmanager/src/daemons/main.c
index 1929072..dad379a 100644
--- a/rgmanager/src/daemons/main.c
+++ b/rgmanager/src/daemons/main.c
@@ -684,6 +684,8 @@ event_loop(msgctx_t *localctx, msgctx_t *clusterctx)
dump_internal_state("/var/lib/cluster/rgmanager-dump");
}
+ rgm_dbus_init();
+
while (running && (tv.tv_sec || tv.tv_usec)) {
FD_ZERO(&rfds);
max = -1;
@@ -1035,8 +1037,11 @@ main(int argc, char **argv)
configure_rgmanager(-1, debug, &cluster_timeout);
logt_print(LOG_NOTICE, "Resource Group Manager Starting\n");
- if (rgm_dbus_notify && rgm_dbus_init() != 0)
- logt_print(LOG_NOTICE, "Failed to initialize DBus\n");
+ if (rgm_dbus_notify && rgm_dbus_init() != 0) {
+ rgm_dbus_notify = 0;
+ logt_print(LOG_NOTICE, "Failed to initialize DBus; "
+ "notifications disabled\n");
+ }
if (init_resource_groups(0, do_init) != 0) {
logt_print(LOG_CRIT, "#8: Couldn't initialize services\n");
diff --git a/rgmanager/src/daemons/update-dbus.c b/rgmanager/src/daemons/update-dbus.c
index a3fb5e7..c9bbf40 100644
--- a/rgmanager/src/daemons/update-dbus.c
+++ b/rgmanager/src/daemons/update-dbus.c
@@ -21,8 +21,6 @@
static DBusConnection *db = NULL;
static pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER;
static pthread_t th = 0;
-static char _err[512];
-static int err_set = 0;
#endif
/* Set this to the desired value prior to calling rgm_dbus_init() */
@@ -39,20 +37,29 @@ rgm_dbus_init(void)
if (!rgm_dbus_notify)
return 0;
+ pthread_mutex_lock(&mu);
+ if (db) {
+ pthread_mutex_unlock(&mu);
+ return 0;
+ }
+
dbus_error_init(&err);
- dbc = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+ dbc = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
if (!dbc) {
- snprintf(_err, sizeof(_err),
- "dbus_bus_get: %s", err.message);
- err_set = 1;
+ logt_print(LOG_ERR,
+ "DBus Failed to initialize: dbus_bus_get: %s\n",
+ err.message);
dbus_error_free(&err);
+ pthread_mutex_unlock(&mu);
return -1;
}
dbus_connection_set_exit_on_disconnect(dbc, FALSE);
db = dbc;
+ pthread_mutex_unlock(&mu);
+ logt_print(LOG_DEBUG, "DBus Notifications Initialized\n");
return 0;
}
#else
@@ -63,9 +70,9 @@ rgm_dbus_init(void)
#endif
-int
-rgm_dbus_release(void)
#ifdef DBUS
+static int
+_rgm_dbus_release(int err)
{
pthread_t t;
@@ -74,17 +81,39 @@ rgm_dbus_release(void)
/* tell thread to exit - not sure how to tell dbus
* to wake up, so just have it poll XXX */
+
+ /* if the thread left because the dbus connection died,
+ this block is avoided since the thread exits */
if (th) {
t = th;
th = 0;
pthread_join(t, NULL);
}
+ dbus_connection_close(db);
dbus_connection_unref(db);
db = NULL;
+ if (err)
+ logt_print(LOG_ERR, "DBus Connection Lost\n");
+ else
+ logt_print(LOG_DEBUG, "DBus Released\n");
return 0;
}
+#endif
+
+
+int
+rgm_dbus_release(void)
+#ifdef DBUS
+{
+ int ret;
+
+ pthread_mutex_lock(&mu);
+ ret = _rgm_dbus_release(0);
+ pthread_mutex_unlock(&mu);
+ return ret;
+}
#else
{
return 0;
@@ -98,14 +127,12 @@ _dbus_auto_flush(void *arg)
{
/* DBus connection functions are thread safe */
dbus_connection_ref(db);
-
while (dbus_connection_read_write(db, 500)) {
if (!th)
break;
}
dbus_connection_unref(db);
-
th = 0;
return NULL;
}
@@ -121,11 +148,6 @@ _rgm_dbus_notify(const char *svcname,
DBusMessage *msg = NULL;
int ret = -1;
- if (err_set) {
- fprintf(stderr, "%s\n", _err);
- err_set = 0;
- }
-
if (!db) {
goto out_free;
}
@@ -133,9 +155,7 @@ _rgm_dbus_notify(const char *svcname,
pthread_mutex_lock(&mu);
if (dbus_connection_get_is_connected(db) != TRUE) {
- err_set = 1;
- snprintf(_err, sizeof(_err), "DBus connection lost");
- rgm_dbus_release();
+ _rgm_dbus_release(1);
goto out_unlock;
}
@@ -184,6 +204,8 @@ rgm_dbus_update(char *key, uint64_t view, void *data, uint32_t size)
if (!rgm_dbus_notify)
goto out_free;
+ if (!db)
+ goto out_free;
if (view == 1)
goto out_free;
if (size != (sizeof(*st)))
@@ -209,6 +231,7 @@ rgm_dbus_update(char *key, uint64_t view, void *data, uint32_t size)
if (!last)
last = "(none)";
+ flags[0] = 0;
rg_flags_str(flags, sizeof(flags), st->rs_flags, (char *)" ");
if (flags[0] == 0)
snprintf(flags, sizeof(flags), "(none)");
@@ -221,7 +244,6 @@ rgm_dbus_update(char *key, uint64_t view, void *data, uint32_t size)
logt_print(LOG_ERR, "Error sending update for %s; "
"notifications disabled\n", key);
rgm_dbus_release();
- rgm_dbus_notify = 0;
}
out_free:
13 years, 4 months