x86: clean up cpu capabilities accesses, cyrix.c
[sfrench/cifs-2.6.git] / drivers / md / dm-log.c
index 6a9261351848ba7e3272de48a51d100345a45a7f..2a74b2142f502a6e2ea944e39b598d90cbb96cac 100644 (file)
@@ -41,7 +41,7 @@ int dm_unregister_dirty_log_type(struct dirty_log_type *type)
        return 0;
 }
 
-static struct dirty_log_type *get_type(const char *type_name)
+static struct dirty_log_type *_get_type(const char *type_name)
 {
        struct dirty_log_type *type;
 
@@ -61,6 +61,55 @@ static struct dirty_log_type *get_type(const char *type_name)
        return NULL;
 }
 
+/*
+ * get_type
+ * @type_name
+ *
+ * Attempt to retrieve the dirty_log_type by name.  If not already
+ * available, attempt to load the appropriate module.
+ *
+ * Log modules are named "dm-log-" followed by the 'type_name'.
+ * Modules may contain multiple types.
+ * This function will first try the module "dm-log-<type_name>",
+ * then truncate 'type_name' on the last '-' and try again.
+ *
+ * For example, if type_name was "clustered-disk", it would search
+ * 'dm-log-clustered-disk' then 'dm-log-clustered'.
+ *
+ * Returns: dirty_log_type* on success, NULL on failure
+ */
+static struct dirty_log_type *get_type(const char *type_name)
+{
+       char *p, *type_name_dup;
+       struct dirty_log_type *type;
+
+       type = _get_type(type_name);
+       if (type)
+               return type;
+
+       type_name_dup = kstrdup(type_name, GFP_KERNEL);
+       if (!type_name_dup) {
+               DMWARN("No memory left to attempt log module load for \"%s\"",
+                      type_name);
+               return NULL;
+       }
+
+       while (request_module("dm-log-%s", type_name_dup) ||
+              !(type = _get_type(type_name))) {
+               p = strrchr(type_name_dup, '-');
+               if (!p)
+                       break;
+               p[0] = '\0';
+       }
+
+       if (!type)
+               DMWARN("Module for logging type \"%s\" not found.", type_name);
+
+       kfree(type_name_dup);
+
+       return type;
+}
+
 static void put_type(struct dirty_log_type *type)
 {
        spin_lock(&_lock);
@@ -149,9 +198,12 @@ struct log_c {
                FORCESYNC,      /* Force a sync to happen */
        } sync;
 
+       struct dm_io_request io_req;
+
        /*
         * Disk log fields
         */
+       int log_dev_failed;
        struct dm_dev *log_dev;
        struct log_header header;
 
@@ -199,13 +251,20 @@ static void header_from_disk(struct log_header *core, struct log_header *disk)
        core->nr_regions = le64_to_cpu(disk->nr_regions);
 }
 
+static int rw_header(struct log_c *lc, int rw)
+{
+       lc->io_req.bi_rw = rw;
+       lc->io_req.mem.ptr.vma = lc->disk_header;
+       lc->io_req.notify.fn = NULL;
+
+       return dm_io(&lc->io_req, 1, &lc->header_location, NULL);
+}
+
 static int read_header(struct log_c *log)
 {
        int r;
-       unsigned long ebits;
 
-       r = dm_io_sync_vm(1, &log->header_location, READ,
-                         log->disk_header, &ebits);
+       r = rw_header(log, READ);
        if (r)
                return r;
 
@@ -233,11 +292,8 @@ static int read_header(struct log_c *log)
 
 static inline int write_header(struct log_c *log)
 {
-       unsigned long ebits;
-
        header_to_disk(&log->header, log->disk_header);
-       return dm_io_sync_vm(1, &log->header_location, WRITE,
-                            log->disk_header, &ebits);
+       return rw_header(log, WRITE);
 }
 
 /*----------------------------------------------------------------
@@ -256,6 +312,7 @@ static int create_log_context(struct dirty_log *log, struct dm_target *ti,
        uint32_t region_size;
        unsigned int region_count;
        size_t bitset_size, buf_size;
+       int r;
 
        if (argc < 1 || argc > 2) {
                DMWARN("wrong number of arguments to mirror log");
@@ -315,6 +372,7 @@ static int create_log_context(struct dirty_log *log, struct dm_target *ti,
                lc->disk_header = NULL;
        } else {
                lc->log_dev = dev;
+               lc->log_dev_failed = 0;
                lc->header_location.bdev = lc->log_dev->bdev;
                lc->header_location.sector = 0;
 
@@ -324,6 +382,15 @@ static int create_log_context(struct dirty_log *log, struct dm_target *ti,
                buf_size = dm_round_up((LOG_OFFSET << SECTOR_SHIFT) +
                                       bitset_size, ti->limits.hardsect_size);
                lc->header_location.count = buf_size >> SECTOR_SHIFT;
+               lc->io_req.mem.type = DM_IO_VMA;
+               lc->io_req.client = dm_io_client_create(dm_div_up(buf_size,
+                                                                  PAGE_SIZE));
+               if (IS_ERR(lc->io_req.client)) {
+                       r = PTR_ERR(lc->io_req.client);
+                       DMWARN("couldn't allocate disk io client");
+                       kfree(lc);
+                       return -ENOMEM;
+               }
 
                lc->disk_header = vmalloc(buf_size);
                if (!lc->disk_header) {
@@ -424,6 +491,7 @@ static void disk_dtr(struct dirty_log *log)
 
        dm_put_device(lc->ti, lc->log_dev);
        vfree(lc->disk_header);
+       dm_io_client_destroy(lc->io_req.client);
        destroy_log_context(lc);
 }
 
@@ -437,6 +505,15 @@ static int count_bits32(uint32_t *addr, unsigned size)
        return count;
 }
 
+static void fail_log_device(struct log_c *lc)
+{
+       if (lc->log_dev_failed)
+               return;
+
+       lc->log_dev_failed = 1;
+       dm_table_event(lc->ti->table);
+}
+
 static int disk_resume(struct dirty_log *log)
 {
        int r;
@@ -446,8 +523,19 @@ static int disk_resume(struct dirty_log *log)
 
        /* read the disk header */
        r = read_header(lc);
-       if (r)
-               return r;
+       if (r) {
+               DMWARN("%s: Failed to read header on mirror log device",
+                      lc->log_dev->name);
+               fail_log_device(lc);
+               /*
+                * If the log device cannot be read, we must assume
+                * all regions are out-of-sync.  If we simply return
+                * here, the state will be uninitialized and could
+                * lead us to return 'in-sync' status for regions
+                * that are actually 'out-of-sync'.
+                */
+               lc->header.nr_regions = 0;
+       }
 
        /* set or clear any new bits -- device has grown */
        if (lc->sync == NOSYNC)
@@ -472,7 +560,14 @@ static int disk_resume(struct dirty_log *log)
        lc->header.nr_regions = lc->region_count;
 
        /* write the new header */
-       return write_header(lc);
+       r = write_header(lc);
+       if (r) {
+               DMWARN("%s: Failed to write header on mirror log device",
+                      lc->log_dev->name);
+               fail_log_device(lc);
+       }
+
+       return r;
 }
 
 static uint32_t core_get_region_size(struct dirty_log *log)
@@ -516,7 +611,9 @@ static int disk_flush(struct dirty_log *log)
                return 0;
 
        r = write_header(lc);
-       if (!r)
+       if (r)
+               fail_log_device(lc);
+       else
                lc->touched = 0;
 
        return r;
@@ -591,6 +688,7 @@ static int core_status(struct dirty_log *log, status_type_t status,
 
        switch(status) {
        case STATUSTYPE_INFO:
+               DMEMIT("1 %s", log->type->name);
                break;
 
        case STATUSTYPE_TABLE:
@@ -606,17 +704,17 @@ static int disk_status(struct dirty_log *log, status_type_t status,
                       char *result, unsigned int maxlen)
 {
        int sz = 0;
-       char buffer[16];
        struct log_c *lc = log->context;
 
        switch(status) {
        case STATUSTYPE_INFO:
+               DMEMIT("3 %s %s %c", log->type->name, lc->log_dev->name,
+                      lc->log_dev_failed ? 'D' : 'A');
                break;
 
        case STATUSTYPE_TABLE:
-               format_dev_t(buffer, lc->log_dev->bdev->bd_dev);
                DMEMIT("%s %u %s %u ", log->type->name,
-                      lc->sync == DEFAULTSYNC ? 2 : 3, buffer,
+                      lc->sync == DEFAULTSYNC ? 2 : 3, lc->log_dev->name,
                       lc->region_size);
                DMEMIT_SYNC;
        }
@@ -647,7 +745,7 @@ static struct dirty_log_type _disk_type = {
        .module = THIS_MODULE,
        .ctr = disk_ctr,
        .dtr = disk_dtr,
-       .suspend = disk_flush,
+       .postsuspend = disk_flush,
        .resume = disk_resume,
        .get_region_size = core_get_region_size,
        .is_clean = core_is_clean,