genfio: Splitting gen_template in 2 parts
[fio.git] / diskutil.c
index d2c0b976f1c89208cf30cc99feed81e438a03b8c..e29d1c34af24d116f9a601437adb798a8ec194cf 100644 (file)
@@ -15,7 +15,6 @@ static int last_majdev, last_mindev;
 static struct disk_util *last_du;
 
 static struct fio_mutex *disk_util_mutex;
-static int disk_util_exit;
 
 FLIST_HEAD(disk_list);
 
@@ -277,13 +276,25 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev,
 {
        struct disk_util *du, *__du;
        struct flist_head *entry;
+       int l;
 
        dprint(FD_DISKUTIL, "add maj/min %d/%d: %s\n", majdev, mindev, path);
 
        du = smalloc(sizeof(*du));
+       if (!du) {
+               log_err("fio: smalloc() pool exhausted\n");
+               return NULL;
+       }
+
        memset(du, 0, sizeof(*du));
        INIT_FLIST_HEAD(&du->list);
-       sprintf(du->path, "%s/stat", path);
+       l = snprintf(du->path, sizeof(du->path), "%s/stat", path);
+       if (l < 0 || l >= sizeof(du->path)) {
+               log_err("constructed path \"%.100s[...]/stat\" larger than buffer (%zu bytes)\n",
+                       path, sizeof(du->path) - 1);
+               sfree(du);
+               return NULL;
+       }
        strncpy((char *) du->dus.name, basename(path), FIO_DU_NAME_SZ);
        du->sysfs_root = path;
        du->major = majdev;
@@ -539,16 +550,13 @@ static void aggregate_slaves_stats(struct disk_util *masterdu)
                agg->max_util.u.f = 100.0;
 }
 
-void free_disk_util(void)
+void disk_util_prune_entries(void)
 {
-       struct disk_util *du;
-
-       disk_util_exit = 1;
-       wait_for_disk_thread_exit();
-
        fio_mutex_down(disk_util_mutex);
 
        while (!flist_empty(&disk_list)) {
+               struct disk_util *du;
+
                du = flist_entry(disk_list.next, struct disk_util, list);
                flist_del(&du->list);
                disk_util_free(du);
@@ -662,7 +670,7 @@ void show_disk_util(int terse, struct json_object *parent)
        if (!terse)
                log_info("\nDisk stats (read/write):\n");
 
-       if (terse && terse_version == 4) {
+       if (output_format == FIO_OUTPUT_JSON) {
                array = json_create_array();
                json_object_add_value_array(parent, "disk_util", array);
        }
@@ -671,7 +679,7 @@ void show_disk_util(int terse, struct json_object *parent)
                du = flist_entry(entry, struct disk_util, list);
 
                aggregate_slaves_stats(du);
-               if (terse && terse_version == 4)
+               if (output_format == FIO_OUTPUT_JSON)
                        print_disk_util_json(du, array);
                else
                        print_disk_util(&du->dus, &du->agg, terse);