From fd9c608193b3318a543f25f75af7b888d85c4405 Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Tue, 15 Sep 2009 04:43:29 +0000 Subject: libglusterfs:Acquire lock before accessing fdtable contents during statedump. Hold lock while dumping fdtable. Dump only inode ino instead of the complete inode. Signed-off-by: Anand V. Avati BUG: 213 (Support for process state dump) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=213 --- libglusterfs/src/fd.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'libglusterfs/src/fd.c') diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c index 62536fc5524..5b2d32bffb2 100644 --- a/libglusterfs/src/fd.c +++ b/libglusterfs/src/fd.c @@ -692,7 +692,6 @@ void fd_dump (fd_t *fd, char *prefix) { char key[GF_DUMP_MAX_BUF_LEN]; - inode_t *inode = NULL; if (!fd) return; @@ -704,9 +703,10 @@ fd_dump (fd_t *fd, char *prefix) gf_proc_dump_write(key, "%d", fd->refcount); gf_proc_dump_build_key(key, prefix, "flags"); gf_proc_dump_write(key, "%d", fd->flags); - gf_proc_dump_build_key(key, prefix, "inode"); - gf_proc_dump_add_section(key); - inode_dump(inode, key, NULL); + if (fd->inode) { + gf_proc_dump_build_key(key, prefix, "inode"); + gf_proc_dump_write(key, "%ld", fd->inode->ino); + } } @@ -726,12 +726,20 @@ fdentry_dump (fdentry_t *fdentry, char *prefix) void fdtable_dump (fdtable_t *fdtable, char *prefix) { - char key[GF_DUMP_MAX_BUF_LEN]; - int i = 0; + char key[GF_DUMP_MAX_BUF_LEN]; + int i = 0; + int ret = -1; if (!fdtable) return; + ret = pthread_mutex_trylock (&fdtable->lock); + + if (ret) { + gf_log ("fd", GF_LOG_WARNING, "Unable to acquire lock"); + return; + } + memset(key, 0, sizeof(key)); gf_proc_dump_build_key(key, prefix, "refcount"); gf_proc_dump_write(key, "%d", fdtable->refcount); @@ -739,8 +747,6 @@ fdtable_dump (fdtable_t *fdtable, char *prefix) gf_proc_dump_write(key, "%d", fdtable->max_fds); gf_proc_dump_build_key(key, prefix, "first_free"); gf_proc_dump_write(key, "%d", fdtable->first_free); - gf_proc_dump_build_key(key, prefix, "lock"); - gf_proc_dump_write(key, "%d", fdtable->lock); for ( i = 0 ; i < fdtable->max_fds; i++) { if (GF_FDENTRY_ALLOCATED == @@ -750,5 +756,7 @@ fdtable_dump (fdtable_t *fdtable, char *prefix) fdentry_dump(&fdtable->fdentries[i], key); } } + + pthread_mutex_unlock(&fdtable->lock); } -- cgit