Fix bad sscan() -> scanf() conversion
authorJens Axboe <jens.axboe@oracle.com>
Fri, 7 Mar 2008 12:19:35 +0000 (13:19 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 7 Mar 2008 12:19:35 +0000 (13:19 +0100)
Caused fio to stall waiting for disk updates.

Also add --debug=diskutil debug option, to trace what diskutil is doing.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
README
blktrace.c
debug.h
diskutil.c
init.c

diff --git a/README b/README
index ef614a28f250bc424c0b3c36f1e4ba95a003568c..7d6262ec8eb777260c708b1bed343ff3a0b1c2ed 100644 (file)
--- a/README
+++ b/README
@@ -101,6 +101,7 @@ options in fio. Currently the options are:
        all             Enable all debug options
        random          Dump info related to random offset generation
        parse           Dump info related to option matching and parsing
+       diskutil        Dump info related to disk utilization updates
        ? or help       Show available debug options.
 
 You can specify as many as you want, eg --debug=file,mem will enable
index b7071808ccec0b9aec5a49fa85460ad823a963be..111619c6c47301bbf1208895c6315ed3497c22f8 100644 (file)
@@ -204,22 +204,16 @@ static void store_ipo(struct thread_data *td, unsigned long long offset,
        list_add_tail(&ipo->list, &td->io_log_list);
 }
 
-/*
- * We only care for queue traces, most of the others are side effects
- * due to internal workings of the block layer.
- */
-static void handle_trace(struct thread_data *td, struct blk_io_trace *t,
-                        unsigned long long ttime, unsigned long *ios,
-                        unsigned int *bs)
+static void handle_trace_notify(struct thread_data *td, struct blk_io_trace *t)
 {
-       int rw;
+       printf("got notify: %x, %d\n", t->action, t->pid);
+}
 
-       if ((t->action & 0xffff) != __BLK_TA_QUEUE)
-               return;
-       if (t->action & BLK_TC_ACT(BLK_TC_PC))
-               return;
-       if (t->action & BLK_TC_ACT(BLK_TC_NOTIFY))
-               return;
+static void handle_trace_fs(struct thread_data *td, struct blk_io_trace *t,
+                           unsigned long long ttime, unsigned long *ios,
+                           unsigned int *bs)
+{
+       int rw;
 
        trace_add_file(td, t->device);
 
@@ -233,6 +227,25 @@ static void handle_trace(struct thread_data *td, struct blk_io_trace *t,
        store_ipo(td, t->sector, t->bytes, rw, ttime);
 }
 
+/*
+ * We only care for queue traces, most of the others are side effects
+ * due to internal workings of the block layer.
+ */
+static void handle_trace(struct thread_data *td, struct blk_io_trace *t,
+                        unsigned long long ttime, unsigned long *ios,
+                        unsigned int *bs)
+{
+       if ((t->action & 0xffff) != __BLK_TA_QUEUE)
+               return;
+       if (t->action & BLK_TC_ACT(BLK_TC_PC))
+               return;
+
+       if (t->action & BLK_TC_ACT(BLK_TC_NOTIFY))
+               handle_trace_notify(td, t);
+       else
+               handle_trace_fs(td, t, ttime, ios, bs);
+}
+
 /*
  * Load a blktrace file by reading all the blk_io_trace entries, and storing
  * them as io_pieces like the fio text version would do.
diff --git a/debug.h b/debug.h
index b11a9012eeb2b169f6d1c328603581e53aa5e227..22577a8a8afccee744c55c8ec8c4879659208093 100644 (file)
--- a/debug.h
+++ b/debug.h
@@ -13,6 +13,7 @@ enum {
        FD_VERIFY,
        FD_RANDOM,
        FD_PARSE,
+       FD_DISKUTIL,
        FD_DEBUG_MAX,
 };
 
index b5ba709e1638846994db9a990671a8296de25240..b3bb605aa6592c0f23fcfdcbf4c4744e7cb38961 100644 (file)
@@ -22,6 +22,8 @@ static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus)
        char *p;
        int ret;
 
+       dprint(FD_DISKUTIL, "open stat file: %s\n", du->path);
+
        f = fopen(du->path, "r");
        if (!f)
                return 1;
@@ -32,19 +34,17 @@ static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus)
                return 1;
        }
 
-       ret = scanf(p, "%u %u %llu %u %u %u %llu %u %u %u %u\n", &dus->ios[0],
+       dprint(FD_DISKUTIL, "%s: %s", du->path, p);
+
+       ret = sscanf(p, "%u %u %llu %u %u %u %llu %u %u %u %u\n", &dus->ios[0],
                                        &dus->merges[0], &dus->sectors[0],
                                        &dus->ticks[0], &dus->ios[1],
                                        &dus->merges[1], &dus->sectors[1],
                                        &dus->ticks[1], &in_flight,
                                        &dus->io_ticks, &dus->time_in_queue);
-       if (ret != 11) {
-               fclose(f);
-               return 1;
-       }
-
        fclose(f);
-       return 0;
+       dprint(FD_DISKUTIL, "%s: stat read ok? %d\n", du->path, ret == 1);
+       return ret != 11;
 }
 
 static void update_io_tick_disk(struct disk_util *du)
@@ -80,6 +80,8 @@ void update_io_ticks(void)
        struct list_head *entry;
        struct disk_util *du;
 
+       dprint(FD_DISKUTIL, "update io ticks\n");
+
        list_for_each(entry, &disk_list) {
                du = list_entry(entry, struct disk_util, list);
                update_io_tick_disk(du);
@@ -106,6 +108,8 @@ static void disk_util_add(int majdev, int mindev, char *path)
        struct disk_util *du, *__du;
        struct list_head *entry;
 
+       dprint(FD_DISKUTIL, "add maj/min %d/%d: %s\n", majdev, mindev, path);
+
        du = malloc(sizeof(*du));
        memset(du, 0, sizeof(*du));
        INIT_LIST_HEAD(&du->list);
@@ -118,6 +122,8 @@ static void disk_util_add(int majdev, int mindev, char *path)
        list_for_each(entry, &disk_list) {
                __du = list_entry(entry, struct disk_util, list);
 
+               dprint(FD_DISKUTIL, "found %s in list\n", __du->name);
+
                if (!strcmp(du->name, __du->name)) {
                        free(du->name);
                        free(du);
@@ -125,6 +131,8 @@ static void disk_util_add(int majdev, int mindev, char *path)
                }
        }
 
+       dprint(FD_DISKUTIL, "add %s to list\n", du->name);
+
        fio_gettime(&du->time, NULL);
        get_io_ticks(du, &du->last_dus);
 
@@ -246,6 +254,9 @@ static void __init_disk_util(struct thread_data *td, struct fio_file *f)
                mindev = minor(st.st_dev);
        }
 
+       dprint(FD_DISKUTIL, "%s belongs to maj/min %d/%d\n", f->file_name,
+                                                       majdev, mindev);
+
        du = disk_util_exists(majdev, mindev);
        if (du) {
                if (td->o.ioscheduler && !td->sysfs_root)
diff --git a/init.c b/init.c
index 7711189ccd4d2f86a2ddd49db271cfef200b97c9..8683ba63a67b16fef47401541c6792b8f55c7504 100644 (file)
--- a/init.c
+++ b/init.c
@@ -838,6 +838,7 @@ struct debug_level debug_levels[] = {
        { .name = "verify",     .shift = FD_VERIFY },
        { .name = "random",     .shift = FD_RANDOM },
        { .name = "parse",      .shift = FD_PARSE },
+       { .name = "diskutil",   .shift = FD_DISKUTIL },
        { },
 };