include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / fs / nilfs2 / segbuf.c
index 636590c..17851f7 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/writeback.h>
 #include <linux/crc32.h>
 #include <linux/backing-dev.h>
+#include <linux/slab.h>
 #include "page.h"
 #include "segbuf.h"
 
@@ -32,7 +33,7 @@
 struct nilfs_write_info {
        struct the_nilfs       *nilfs;
        struct bio             *bio;
-       int                     start, end; /* The region to be submitted */
+       int                     start, end; /* The region to be submitted */
        int                     rest_blocks;
        int                     max_pages;
        int                     nr_vecs;
@@ -40,6 +41,11 @@ struct nilfs_write_info {
 };
 
 
+static int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
+                             struct the_nilfs *nilfs);
+static int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf);
+
+
 static struct kmem_cache *nilfs_segbuf_cachep;
 
 static void nilfs_segbuf_init_once(void *obj)
@@ -100,6 +106,22 @@ void nilfs_segbuf_map(struct nilfs_segment_buffer *segbuf, __u64 segnum,
                segbuf->sb_fseg_end - segbuf->sb_pseg_start + 1;
 }
 
+/**
+ * nilfs_segbuf_map_cont - map a new log behind a given log
+ * @segbuf: new segment buffer
+ * @prev: segment buffer containing a log to be continued
+ */
+void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf,
+                          struct nilfs_segment_buffer *prev)
+{
+       segbuf->sb_segnum = prev->sb_segnum;
+       segbuf->sb_fseg_start = prev->sb_fseg_start;
+       segbuf->sb_fseg_end = prev->sb_fseg_end;
+       segbuf->sb_pseg_start = prev->sb_pseg_start + prev->sb_sum.nblocks;
+       segbuf->sb_rest_blocks =
+               segbuf->sb_fseg_end - segbuf->sb_pseg_start + 1;
+}
+
 void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *segbuf,
                                  __u64 nextnum, struct the_nilfs *nilfs)
 {
@@ -153,7 +175,7 @@ int nilfs_segbuf_reset(struct nilfs_segment_buffer *segbuf, unsigned flags,
 }
 
 /*
- * Setup segument summary
+ * Setup segment summary
  */
 void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *segbuf)
 {
@@ -234,7 +256,7 @@ void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *segbuf,
        raw_sum->ss_datasum = cpu_to_le32(crc);
 }
 
-void nilfs_release_buffers(struct list_head *list)
+static void nilfs_release_buffers(struct list_head *list)
 {
        struct buffer_head *bh, *n;
 
@@ -256,6 +278,62 @@ void nilfs_release_buffers(struct list_head *list)
        }
 }
 
+static void nilfs_segbuf_clear(struct nilfs_segment_buffer *segbuf)
+{
+       nilfs_release_buffers(&segbuf->sb_segsum_buffers);
+       nilfs_release_buffers(&segbuf->sb_payload_buffers);
+}
+
+/*
+ * Iterators for segment buffers
+ */
+void nilfs_clear_logs(struct list_head *logs)
+{
+       struct nilfs_segment_buffer *segbuf;
+
+       list_for_each_entry(segbuf, logs, sb_list)
+               nilfs_segbuf_clear(segbuf);
+}
+
+void nilfs_truncate_logs(struct list_head *logs,
+                        struct nilfs_segment_buffer *last)
+{
+       struct nilfs_segment_buffer *n, *segbuf;
+
+       segbuf = list_prepare_entry(last, logs, sb_list);
+       list_for_each_entry_safe_continue(segbuf, n, logs, sb_list) {
+               list_del_init(&segbuf->sb_list);
+               nilfs_segbuf_clear(segbuf);
+               nilfs_segbuf_free(segbuf);
+       }
+}
+
+int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs)
+{
+       struct nilfs_segment_buffer *segbuf;
+       int ret = 0;
+
+       list_for_each_entry(segbuf, logs, sb_list) {
+               ret = nilfs_segbuf_write(segbuf, nilfs);
+               if (ret)
+                       break;
+       }
+       return ret;
+}
+
+int nilfs_wait_on_logs(struct list_head *logs)
+{
+       struct nilfs_segment_buffer *segbuf;
+       int err, ret = 0;
+
+       list_for_each_entry(segbuf, logs, sb_list) {
+               err = nilfs_segbuf_wait(segbuf);
+               if (err && !ret)
+                       ret = err;
+       }
+       return ret;
+}
+
 /*
  * BIO operations
  */
@@ -393,8 +471,8 @@ static int nilfs_segbuf_submit_bh(struct nilfs_segment_buffer *segbuf,
  *
  * %-ENOMEM - Insufficient memory available.
  */
-int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
-                      struct the_nilfs *nilfs)
+static int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
+                             struct the_nilfs *nilfs)
 {
        struct nilfs_write_info wi;
        struct buffer_head *bh;
@@ -437,7 +515,7 @@ int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
  *
  * %-EIO - I/O error
  */
-int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf)
+static int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf)
 {
        int err = 0;