From 07c9a96627932ad3fc8c99193f8cfdae522ca9c1 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Fri, 11 May 2012 18:11:31 +0530 Subject: libglusterfs/fd: while dumping the fd_ctx use fd->xl_count While dumping the fd_ctx when statedump is issued fd->xl_count should be used to determine the number of xlators instead of using latest graph's count, since while creating the fd only those many slots would have been allocated as the number of xlators in the graph at that instant. Then the graph would have changed, thus the xl count. All the above things should happen before any operation is done on fd, otherwise fd_ctx_set will allocate the extra slots for the new xlators present in the graph. Also added the program which can be used to reproduce the bug. Change-Id: I11fe75d71ef5d37e29e2958d53752aa31098c313 BUG: 820887 Signed-off-by: Raghavendra Bhat Reviewed-on: http://review.gluster.com/3335 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- extras/test/open-fd-tests.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 extras/test/open-fd-tests.c (limited to 'extras') diff --git a/extras/test/open-fd-tests.c b/extras/test/open-fd-tests.c new file mode 100644 index 000000000..4184079d0 --- /dev/null +++ b/extras/test/open-fd-tests.c @@ -0,0 +1,64 @@ + +#include +#include +#include +#include +#include +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + int ret = -1; + int fd = 0; + char *filename = NULL; + int loop = 0; + struct stat stbuf = {0,}; + char string[1024] = {0,}; + + if (argc > 1) + filename = argv[1]; + + if (!filename) + filename = "temp-fd-test-file"; + + fd = open (filename, O_RDWR|O_CREAT|O_TRUNC); + if (fd < 0) { + fd = 0; + fprintf (stderr, "open failed : %s\n", strerror (errno)); + goto out; + } + + while (loop < 1000) { + /* Use it as a mechanism to test time delays */ + memset (string, 0, 1024); + scanf ("%s", string); + + ret = write (fd, string, strlen (string)); + if (ret != strlen (string)) { + fprintf (stderr, "write failed : %s (%s %d)\n", + strerror (errno), string, loop); + goto out; + } + + ret = write (fd, "\n", 1); + if (ret != 1) { + fprintf (stderr, "write failed : %s (%d)\n", + strerror (errno), loop); + goto out; + } + + loop++; + } + + fprintf (stdout, "finishing the test after %d loops\n", loop); + + ret = 0; +out: + if (fd) + close (fd); + + return ret; +} -- cgit