Optimize the code that copies strings
[fio.git] / init.c
diff --git a/init.c b/init.c
index 1eddc6f20721a77db3e3ac0656455637f548cf48..63f2168eabcbbebb8cf6c2ae96967b46f2114713 100644 (file)
--- a/init.c
+++ b/init.c
@@ -744,19 +744,12 @@ static int fixup_options(struct thread_data *td)
        /*
         * There's no need to check for in-flight overlapping IOs if the job
         * isn't changing data or the maximum iodepth is guaranteed to be 1
+        * when we are not in offload mode
         */
        if (o->serialize_overlap && !(td->flags & TD_F_READ_IOLOG) &&
-           (!(td_write(td) || td_trim(td)) || o->iodepth == 1))
+           (!(td_write(td) || td_trim(td)) || o->iodepth == 1) &&
+           o->io_submit_mode != IO_MODE_OFFLOAD)
                o->serialize_overlap = 0;
-       /*
-        * Currently can't check for overlaps in offload mode
-        */
-       if (o->serialize_overlap && o->io_submit_mode == IO_MODE_OFFLOAD) {
-               log_err("fio: checking for in-flight overlaps when the "
-                       "io_submit_mode is offload is not supported\n");
-               o->serialize_overlap = 0;
-               ret |= warnings_fatal;
-       }
 
        if (o->nr_files > td->files_index)
                o->nr_files = td->files_index;
@@ -1224,7 +1217,7 @@ static void init_flags(struct thread_data *td)
 
 static int setup_random_seeds(struct thread_data *td)
 {
-       unsigned long seed;
+       uint64_t seed;
        unsigned int i;
 
        if (!td->o.rand_repeatable && !fio_option_is_set(&td->o, rand_seed)) {
@@ -1280,8 +1273,7 @@ static char *make_filename(char *buf, size_t buf_size,struct thread_options *o,
        for (f = &fpre_keywords[0]; f->keyword; f++)
                f->strlen = strlen(f->keyword);
 
-       buf[buf_size - 1] = '\0';
-       strncpy(buf, o->filename_format, buf_size - 1);
+       snprintf(buf, buf_size, "%s", o->filename_format);
 
        memset(copy, 0, sizeof(copy));
        for (f = &fpre_keywords[0]; f->keyword; f++) {
@@ -1360,7 +1352,7 @@ static char *make_filename(char *buf, size_t buf_size,struct thread_options *o,
                        if (post_start)
                                strncpy(dst, buf + post_start, dst_left);
 
-                       strncpy(buf, copy, buf_size - 1);
+                       snprintf(buf, buf_size, "%s", copy);
                } while (1);
        }
 
@@ -1445,7 +1437,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
                   int recursed, int client_type)
 {
        unsigned int i;
-       char fname[PATH_MAX];
+       char fname[PATH_MAX + 1];
        int numjobs, file_alloced;
        struct thread_options *o = &td->o;
        char logname[PATH_MAX + 32];
@@ -1894,7 +1886,7 @@ static int __parse_jobs_ini(struct thread_data *td,
                }
        }
 
-       string = malloc(4096);
+       string = malloc(OPT_LEN_MAX);
 
        /*
         * it's really 256 + small bit, 280 should suffice
@@ -1927,7 +1919,7 @@ static int __parse_jobs_ini(struct thread_data *td,
                        if (is_buf)
                                p = strsep(&file, "\n");
                        else
-                               p = fgets(string, 4096, f);
+                               p = fgets(string, OPT_LEN_MAX, f);
                        if (!p)
                                break;
                }
@@ -1996,7 +1988,7 @@ static int __parse_jobs_ini(struct thread_data *td,
                                if (is_buf)
                                        p = strsep(&file, "\n");
                                else
-                                       p = fgets(string, 4096, f);
+                                       p = fgets(string, OPT_LEN_MAX, f);
                                if (!p)
                                        break;
                                dprint(FD_PARSE, "%s", p);
@@ -2036,19 +2028,12 @@ static int __parse_jobs_ini(struct thread_data *td,
                                 */
                                if (access(filename, F_OK) &&
                                    (ts = strrchr(file, '/'))) {
-                                       int len = ts - file +
-                                               strlen(filename) + 2;
-
-                                       if (!(full_fn = calloc(1, len))) {
+                                       if (asprintf(&full_fn, "%.*s%s",
+                                                (int)(ts - file + 1), file,
+                                                filename) < 0) {
                                                ret = ENOMEM;
                                                break;
                                        }
-
-                                       strncpy(full_fn,
-                                               file, (ts - file) + 1);
-                                       strncpy(full_fn + (ts - file) + 1,
-                                               filename, strlen(filename));
-                                       full_fn[len - 1] = 0;
                                        filename = full_fn;
                                }
 
@@ -2914,6 +2899,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        log_err("%s: unrecognized option '%s'\n", argv[0],
                                                        argv[optind - 1]);
                        show_closest_option(argv[optind - 1]);
+                       /* fall through */
                default:
                        do_exit++;
                        exit_val = 1;