]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
file_writer: Make file_write_open() a no-op.
authorAndre Noll <maan@systemlinux.org>
Fri, 5 Nov 2010 18:28:24 +0000 (19:28 +0100)
committerAndre Noll <maan@systemlinux.org>
Tue, 23 Nov 2010 16:43:08 +0000 (17:43 +0100)
Move the allocation of the private_file_write_data struct to ->post_select()
and adjust the the check whether the output file has already been opened
accordingly.

If the output file has just been opened, pfwd->fd will never be set in
the write fd set of the scheduler, so we can skip this test.

file_write.c

index e6a3229e7303c459e4fa05807c17dd1aa405087e..149b48efcc38afe4b3f72aca2eecc6b5364001cc 100644 (file)
@@ -50,20 +50,16 @@ __must_check __malloc static char *random_filename(void)
        return result;
 }
 
-static void file_write_open(struct writer_node *wn)
+static void file_write_open(__a_unused struct writer_node *wn)
 {
-       struct private_file_write_data *pfwd = para_calloc(sizeof(*pfwd));
-
-       wn->private_data = pfwd;
-       pfwd->fd = -1;
 }
 
 static int prepare_output_file(struct writer_node *wn)
 {
        struct file_write_args_info *conf = wn->conf;
-       struct private_file_write_data *pfwd = wn->private_data;
        char *filename;
        int ret;
+       struct private_file_write_data *pfwd = para_calloc(sizeof(*pfwd));
 
        if (conf->filename_given)
                filename = conf->filename_arg;
@@ -76,8 +72,11 @@ static int prepare_output_file(struct writer_node *wn)
                goto out;
        pfwd->fd = ret;
        ret = mark_fd_blocking(pfwd->fd);
-       if (ret >= 0)
-               return 1;
+       if (ret < 0)
+               goto out_close;
+       wn->private_data = pfwd;
+       return 1;
+out_close:
        close(pfwd->fd);
 out:
        free(pfwd);
@@ -92,7 +91,7 @@ static void file_write_pre_select(struct sched *s, struct task *t)
 
        if (ret == 0)
                return;
-       if (ret < 0 || pfwd->fd < 0)
+       if (ret < 0 || !pfwd)
                return sched_min_delay(s);
        para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
 }
@@ -101,8 +100,9 @@ static void file_write_close(struct writer_node *wn)
 {
        struct private_file_write_data *pfwd = wn->private_data;
 
-       if (pfwd->fd >= 0)
-               close(pfwd->fd);
+       if (!pfwd)
+               return;
+       close(pfwd->fd);
        free(pfwd);
 }
 
@@ -120,10 +120,9 @@ static void file_write_post_select(__a_unused struct sched *s,
        ret = btr_node_status(btrn, wn->min_iqs, BTR_NT_LEAF);
        if (ret <= 0)
                goto out;
-       if (pfwd->fd < 0) {
+       if (!pfwd) {
                ret = prepare_output_file(wn);
-               if (ret < 0)
-                       goto out;
+               goto out;
        }
        if (!FD_ISSET(pfwd->fd, &s->wfds))
                return;