]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - drivers/md/dm-log.c
dm log: add flush callback fn
[mirror_ubuntu-zesty-kernel.git] / drivers / md / dm-log.c
index 9443896ede070152020046d15979bb9f1dc55b29..666a80e3602e07dcb8c312fd4d2081b707de11f1 100644 (file)
@@ -145,8 +145,9 @@ int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type)
 EXPORT_SYMBOL(dm_dirty_log_type_unregister);
 
 struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
-                                        struct dm_target *ti,
-                                        unsigned int argc, char **argv)
+                       struct dm_target *ti,
+                       int (*flush_callback_fn)(struct dm_target *ti),
+                       unsigned int argc, char **argv)
 {
        struct dm_dirty_log_type *type;
        struct dm_dirty_log *log;
@@ -161,6 +162,7 @@ struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
                return NULL;
        }
 
+       log->flush_callback_fn = flush_callback_fn;
        log->type = type;
        if (type->ctr(log, ti, argc, argv)) {
                kfree(log);
@@ -208,7 +210,9 @@ struct log_header {
 
 struct log_c {
        struct dm_target *ti;
-       int touched;
+       int touched_dirtied;
+       int touched_cleaned;
+       int flush_failed;
        uint32_t region_size;
        unsigned int region_count;
        region_t sync_count;
@@ -253,14 +257,14 @@ static inline void log_set_bit(struct log_c *l,
                               uint32_t *bs, unsigned bit)
 {
        ext2_set_bit(bit, (unsigned long *) bs);
-       l->touched = 1;
+       l->touched_cleaned = 1;
 }
 
 static inline void log_clear_bit(struct log_c *l,
                                 uint32_t *bs, unsigned bit)
 {
        ext2_clear_bit(bit, (unsigned long *) bs);
-       l->touched = 1;
+       l->touched_dirtied = 1;
 }
 
 /*----------------------------------------------------------------
@@ -287,6 +291,19 @@ static int rw_header(struct log_c *lc, int rw)
        return dm_io(&lc->io_req, 1, &lc->header_location, NULL);
 }
 
+static int flush_header(struct log_c *lc)
+{
+       struct dm_io_region null_location = {
+               .bdev = lc->header_location.bdev,
+               .sector = 0,
+               .count = 0,
+       };
+
+       lc->io_req.bi_rw = WRITE_BARRIER;
+
+       return dm_io(&lc->io_req, 1, &null_location, NULL);
+}
+
 static int read_header(struct log_c *log)
 {
        int r;
@@ -378,7 +395,9 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
        }
 
        lc->ti = ti;
-       lc->touched = 0;
+       lc->touched_dirtied = 0;
+       lc->touched_cleaned = 0;
+       lc->flush_failed = 0;
        lc->region_size = region_size;
        lc->region_count = region_count;
        lc->sync = sync;
@@ -614,6 +633,8 @@ static int disk_resume(struct dm_dirty_log *log)
 
        /* write the new header */
        r = rw_header(lc, WRITE);
+       if (!r)
+               r = flush_header(lc);
        if (r) {
                DMWARN("%s: Failed to write header on dirty region log device",
                       lc->log_dev->name);
@@ -660,14 +681,22 @@ static int disk_flush(struct dm_dirty_log *log)
        struct log_c *lc = (struct log_c *) log->context;
 
        /* only write if the log has changed */
-       if (!lc->touched)
+       if (!lc->touched_cleaned && !lc->touched_dirtied)
                return 0;
 
        r = rw_header(lc, WRITE);
        if (r)
                fail_log_device(lc);
-       else
-               lc->touched = 0;
+       else {
+               if (lc->touched_dirtied) {
+                       r = flush_header(lc);
+                       if (r)
+                               fail_log_device(lc);
+                       else
+                               lc->touched_dirtied = 0;
+               }
+               lc->touched_cleaned = 0;
+       }
 
        return r;
 }
@@ -681,7 +710,8 @@ static void core_mark_region(struct dm_dirty_log *log, region_t region)
 static void core_clear_region(struct dm_dirty_log *log, region_t region)
 {
        struct log_c *lc = (struct log_c *) log->context;
-       log_set_bit(lc, lc->clean_bits, region);
+       if (likely(!lc->flush_failed))
+               log_set_bit(lc, lc->clean_bits, region);
 }
 
 static int core_get_resync_work(struct dm_dirty_log *log, region_t *region)