Re: [PATCH] Add support for `-' file to read from stdin

From: Jens Axboe <jens.axboe_at_oracle.com>
Date: Thu, 27 Sep 2007 10:40:18 +0200

On Thu, Sep 27 2007, Jens Axboe wrote:
> On Thu, Sep 27 2007, Aaron Carroll wrote:
> > I've just noticed this won't work for something like:
> > cat 'something.fio' | fio -
> > since FIO tries to seek in the file. Looking at it now.
>
> Ah good point. A quick test worked for me, but fio will use fsetpos()
> and fgetpos() on it on some occasions.

We can just get rid of the fgetpos/fsetpos. The were used to re-read the
same line again, if we encounted and end-of-section inside a job
section. This should work, on top of the previous.

diff --git a/init.c b/init.c
index 45bd92f..dc5fed9 100644
--- a/init.c
+++ b/init.c
@@ -565,11 +565,11 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
         unsigned int global;
         struct thread_data *td;
         char *string, *name;
- fpos_t off;
         FILE *f;
         char *p;
         int ret = 0, stonewall;
         int first_sect = 1;
+ int skip_fgets = 0;
 
         if (!strcmp(file, "-"))
                 f = stdin;
@@ -591,10 +591,17 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
 
         stonewall = stonewall_flag;
         do {
- p = fgets(string, 4095, f);
- if (!p)
- break;
+ /*
+ * if skip_fgets is set, we already have loaded a line we
+ * haven't handled.
+ */
+ if (!skip_fgets) {
+ p = fgets(string, 4095, f);
+ if (!p)
+ break;
+ }
 
+ skip_fgets = 0;
                 strip_blank_front(&p);
                 strip_blank_end(p);
 
@@ -631,20 +638,23 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
                         stonewall = 0;
                 }
 
- fgetpos(f, &off);
                 while ((p = fgets(string, 4096, f)) != NULL) {
                         if (is_empty_or_comment(p))
                                 continue;
 
                         strip_blank_front(&p);
 
- if (p[0] == '[')
+ /*
+ * new section, break out and make sure we don't
+ * fgets() a new line at the top.
+ */
+ if (p[0] == '[') {
+ skip_fgets = 1;
                                 break;
+ }
 
                         strip_blank_end(p);
 
- fgetpos(f, &off);
-
                         /*
                          * Don't break here, continue parsing options so we
                          * dump all the bad ones. Makes trial/error fixups
@@ -655,10 +665,9 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
                                 log_info("--%s ", p);
                 }
 
- if (!ret) {
- fsetpos(f, &off);
+ if (!ret)
                         ret = add_job(td, name, 0);
- } else {
+ else {
                         log_err("fio: job %s dropped\n", name);
                         put_job(td);
                 }

-- 
Jens Axboe
Received on Thu Sep 27 2007 - 10:40:18 CEST

This archive was generated by hypermail 2.2.0 : Thu Sep 27 2007 - 11:00:01 CEST