summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan D. Brunelle <alan.brunelle@hp.com>2009-01-23 09:48:21 -0500
committerAlan D. Brunelle <alan.brunelle@hp.com>2009-01-23 09:48:21 -0500
commit99bb5ebc255618e4af913d2e5f1bf268af552bdf (patch)
tree583ae4e2f228cdad0098560c21baf592d25dc259
parent69dd57c2986bb025d7de12ab6eb52d5cd130d453 (diff)
downloadblktrace-99bb5ebc255618e4af913d2e5f1bf268af552bdf.tar.gz
blktrace-99bb5ebc255618e4af913d2e5f1bf268af552bdf.tar.bz2
Fix btt to handle large numbers of output files
Simply bump resource limits if file opens fail, and retry. Signed-off-by: Alan D. Brunelle <alan.brunelle@hp.com>
-rw-r--r--btt/aqd.c2
-rw-r--r--btt/args.c10
-rw-r--r--btt/bno_dump.c2
-rw-r--r--btt/devmap.c2
-rw-r--r--btt/devs.c2
-rw-r--r--btt/globals.h1
-rw-r--r--btt/latency.c2
-rw-r--r--btt/misc.c46
-rw-r--r--btt/output.c4
-rw-r--r--btt/plat.c2
-rw-r--r--btt/seek.c4
11 files changed, 61 insertions, 16 deletions
diff --git a/btt/aqd.c b/btt/aqd.c
index 6dc3a7a..f619975 100644
--- a/btt/aqd.c
+++ b/btt/aqd.c
@@ -43,7 +43,7 @@ void *aqd_init(char *str)
oname = malloc(strlen(aqd_name) + strlen(str) + 32);
sprintf(oname, "%s_%s.dat", aqd_name, str);
- if ((ap->fp = fopen(oname, "w")) == NULL) {
+ if ((ap->fp = my_fopen(oname, "w")) == NULL) {
perror(oname);
return NULL;
}
diff --git a/btt/args.c b/btt/args.c
index c648b93..0ddd47c 100644
--- a/btt/args.c
+++ b/btt/args.c
@@ -240,7 +240,7 @@ static FILE *setup_ofile(char *fname)
{
if (fname) {
char *buf;
- FILE *ofp = fopen(fname, "w");
+ FILE *ofp = my_fopen(fname, "w");
if (!ofp) {
perror(fname);
@@ -382,7 +382,7 @@ void handle_args(int argc, char *argv[])
char *fname = malloc(strlen(output_name) + 32);
sprintf(fname, "%s.dat", output_name);
- ranges_ofp = fopen(fname, "w");
+ ranges_ofp = my_fopen(fname, "w");
if (ranges_ofp == NULL) {
perror(fname);
exit(1);
@@ -391,7 +391,7 @@ void handle_args(int argc, char *argv[])
printf("Sending range data to %s\n", fname);
sprintf(fname, "%s.avg", output_name);
- avgs_ofp = fopen(fname, "w");
+ avgs_ofp = my_fopen(fname, "w");
if (avgs_ofp == NULL) {
perror(fname);
exit(1);
@@ -400,7 +400,7 @@ void handle_args(int argc, char *argv[])
printf("Sending stats data to %s\n", fname);
sprintf(fname, "%s.msg", output_name);
- msgs_ofp = fopen(fname, "w");
+ msgs_ofp = my_fopen(fname, "w");
if (msgs_ofp == NULL) {
perror(fname);
exit(1);
@@ -410,7 +410,7 @@ void handle_args(int argc, char *argv[])
if (easy_parse_avgs) {
sprintf(fname, "%s.xvg", output_name);
- xavgs_ofp = fopen(fname, "w");
+ xavgs_ofp = my_fopen(fname, "w");
if (avgs_ofp == NULL) {
perror(fname);
exit(1);
diff --git a/btt/bno_dump.c b/btt/bno_dump.c
index 1f5433b..7f7680e 100644
--- a/btt/bno_dump.c
+++ b/btt/bno_dump.c
@@ -37,7 +37,7 @@ static FILE *bno_dump_open(__u32 device, char rwc)
oname = malloc(strlen(bno_dump_name) + 32);
sprintf(oname, "%s_%03d,%03d_%c.dat", bno_dump_name, mjr, mnr, rwc);
- if ((fp = fopen(oname, "w")) == NULL)
+ if ((fp = my_fopen(oname, "w")) == NULL)
perror(oname);
else
add_file(&bno_dump_files, fp, oname);
diff --git a/btt/devmap.c b/btt/devmap.c
index a74f224..5841446 100644
--- a/btt/devmap.c
+++ b/btt/devmap.c
@@ -59,7 +59,7 @@ int dev_map_read(char *fname)
{
char line[256];
struct devmap dm;
- FILE *fp = fopen(fname, "r");
+ FILE *fp = my_fopen(fname, "r");
if (!fp) {
perror(fname);
diff --git a/btt/devs.c b/btt/devs.c
index e530477..ea560a2 100644
--- a/btt/devs.c
+++ b/btt/devs.c
@@ -110,7 +110,7 @@ static inline char *mkhandle(char *str, __u32 device, char *post)
static inline FILE *open_pit(char *str)
{
- FILE *fp = fopen(str, "w");
+ FILE *fp = my_fopen(str, "w");
if (fp == NULL)
perror(str);
diff --git a/btt/globals.h b/btt/globals.h
index 0ee06ed..cc83095 100644
--- a/btt/globals.h
+++ b/btt/globals.h
@@ -262,6 +262,7 @@ void clean_files(struct file_info **fipp);
void add_buf(void *buf);
void clean_bufs(void);
char *make_dev_hdr(char *pad, size_t len, struct d_info *dip, int add_parens);
+FILE *my_fopen(const char *path, const char *mode);
void dbg_ping(void);
/* mmap.c */
diff --git a/btt/latency.c b/btt/latency.c
index 0c6e55d..d12f60c 100644
--- a/btt/latency.c
+++ b/btt/latency.c
@@ -41,7 +41,7 @@ FILE *latency_open(__u32 device, char *name, char *post)
oname = malloc(strlen(name)+32);
sprintf(oname, "%s_%03d,%03d_%s.dat", name, mjr, mnr, post);
- if ((fp = fopen(oname, "w")) == NULL)
+ if ((fp = my_fopen(oname, "w")) == NULL)
perror(oname);
else
add_file(&all_files, fp, oname);
diff --git a/btt/misc.c b/btt/misc.c
index 0ddd260..c79da2c 100644
--- a/btt/misc.c
+++ b/btt/misc.c
@@ -18,11 +18,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
+#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <unistd.h>
+#include <sys/time.h>
+#include <sys/resource.h>
#define INLINE_DECLARE
#include "globals.h"
@@ -116,4 +119,45 @@ char *make_dev_hdr(char *pad, size_t len, struct d_info *dip, int add_parens)
return pad;
}
+/*
+ * Due to the N(devs) parts of a lot of the output features provided
+ * by btt, it will fail opens on large(ish) systems. Here we try to
+ * keep bumping our open file limits, and if those fail, we return NULL.
+ *
+ * Root users will probably be OK with this, others...
+ */
+FILE *my_fopen(const char *path, const char *mode)
+{
+ FILE *fp;
+
+ fp = fopen(path, mode);
+ while (fp == NULL) {
+ if (errno == ENFILE || errno == EMFILE) {
+ struct rlimit rlim;
+
+ if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
+ perror("get: RLIMIT_NOFILE");
+ return NULL;
+ }
+
+ rlim.rlim_cur++;
+ if (rlim.rlim_cur >= rlim.rlim_max)
+ rlim.rlim_max++;
+
+ if (setrlimit(RLIMIT_NOFILE, &rlim) < 0) {
+ perror("set: RLIMIT_NOFILE");
+ return NULL;
+ }
+ }
+ else {
+ perror(path);
+ return NULL;
+ }
+
+ fp = fopen(path, mode);
+ }
+
+ return fp;
+}
+
void dbg_ping(void) {}
diff --git a/btt/output.c b/btt/output.c
index c08e7da..ace1bcd 100644
--- a/btt/output.c
+++ b/btt/output.c
@@ -678,7 +678,7 @@ void output_histos(void)
if (output_name == NULL) return;
sprintf(fname, "%s_qhist.dat", output_name);
- ofp = fopen(fname, "w");
+ ofp = my_fopen(fname, "w");
if (!ofp) {
perror(fname);
return;
@@ -693,7 +693,7 @@ void output_histos(void)
fclose(ofp);
sprintf(fname, "%s_dhist.dat", output_name);
- ofp = fopen(fname, "w");
+ ofp = my_fopen(fname, "w");
if (!ofp) {
perror(fname);
return;
diff --git a/btt/plat.c b/btt/plat.c
index 9b7a2a1..80716b9 100644
--- a/btt/plat.c
+++ b/btt/plat.c
@@ -42,7 +42,7 @@ void *plat_init(char *str)
oname = malloc(strlen(str) + 32);
sprintf(oname, "%s.dat", str);
- if ((pp->fp = fopen(oname, "w")) == NULL) {
+ if ((pp->fp = my_fopen(oname, "w")) == NULL) {
perror(oname);
return NULL;
}
diff --git a/btt/seek.c b/btt/seek.c
index 69400c8..444013c 100644
--- a/btt/seek.c
+++ b/btt/seek.c
@@ -53,7 +53,7 @@ static FILE *seek_open(char *str, char rw)
oname = malloc(strlen(seek_name) + strlen(str) + 32);
sprintf(oname, "%s_%s_%c.dat", seek_name, str, rw);
- if ((fp = fopen(oname, "w")) == NULL)
+ if ((fp = my_fopen(oname, "w")) == NULL)
perror(oname);
else
add_file(&seek_files, fp, oname);
@@ -187,7 +187,7 @@ void *seeki_init(char *str)
oname = malloc(strlen(sps_name) + strlen(str) + 32);
sprintf(oname, "%s_%s.dat", sps_name, str);
- if ((sip->sps_fp = fopen(oname, "w")) == NULL)
+ if ((sip->sps_fp = my_fopen(oname, "w")) == NULL)
perror(oname);
else
add_file(&seek_files, sip->sps_fp, oname);