2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003 Sistina Software
|
2008-04-25 04:43:06 +08:00
|
|
|
* Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This file is released under the LGPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/vmalloc.h>
|
2008-04-25 05:02:01 +08:00
|
|
|
#include <linux/dm-io.h>
|
|
|
|
#include <linux/dm-dirty-log.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-10-22 00:44:59 +08:00
|
|
|
#include <linux/device-mapper.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-25 04:43:06 +08:00
|
|
|
#define DM_MSG_PREFIX "dirty region log"
|
2006-06-26 15:27:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static LIST_HEAD(_log_types);
|
|
|
|
static DEFINE_SPINLOCK(_lock);
|
|
|
|
|
2009-04-03 02:55:30 +08:00
|
|
|
static struct dm_dirty_log_type *__find_dirty_log_type(const char *name)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-04-03 02:55:30 +08:00
|
|
|
struct dm_dirty_log_type *log_type;
|
2008-04-25 04:43:41 +08:00
|
|
|
|
|
|
|
list_for_each_entry(log_type, &_log_types, list)
|
2009-04-03 02:55:30 +08:00
|
|
|
if (!strcmp(name, log_type->name))
|
2008-04-25 04:43:41 +08:00
|
|
|
return log_type;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-04-03 02:55:30 +08:00
|
|
|
static struct dm_dirty_log_type *_get_dirty_log_type(const char *name)
|
2008-04-25 04:43:41 +08:00
|
|
|
{
|
2009-04-03 02:55:30 +08:00
|
|
|
struct dm_dirty_log_type *log_type;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock(&_lock);
|
2008-04-25 04:43:41 +08:00
|
|
|
|
|
|
|
log_type = __find_dirty_log_type(name);
|
2009-04-03 02:55:30 +08:00
|
|
|
if (log_type && !try_module_get(log_type->module))
|
2009-04-03 02:55:29 +08:00
|
|
|
log_type = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_unlock(&_lock);
|
2008-04-25 04:43:41 +08:00
|
|
|
|
|
|
|
return log_type;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-02-08 10:11:19 +08:00
|
|
|
/*
|
|
|
|
* get_type
|
|
|
|
* @type_name
|
|
|
|
*
|
2008-04-25 04:43:41 +08:00
|
|
|
* Attempt to retrieve the dm_dirty_log_type by name. If not already
|
2008-02-08 10:11:19 +08:00
|
|
|
* 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
|
|
|
|
*/
|
2008-04-25 04:43:35 +08:00
|
|
|
static struct dm_dirty_log_type *get_type(const char *type_name)
|
2008-02-08 10:11:19 +08:00
|
|
|
{
|
|
|
|
char *p, *type_name_dup;
|
2009-04-03 02:55:30 +08:00
|
|
|
struct dm_dirty_log_type *log_type;
|
2008-02-08 10:11:19 +08:00
|
|
|
|
2008-04-25 04:43:41 +08:00
|
|
|
if (!type_name)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
log_type = _get_dirty_log_type(type_name);
|
|
|
|
if (log_type)
|
2009-04-03 02:55:30 +08:00
|
|
|
return log_type;
|
2008-02-08 10:11:19 +08:00
|
|
|
|
|
|
|
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) ||
|
2008-04-25 04:43:41 +08:00
|
|
|
!(log_type = _get_dirty_log_type(type_name))) {
|
2008-02-08 10:11:19 +08:00
|
|
|
p = strrchr(type_name_dup, '-');
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
p[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:41 +08:00
|
|
|
if (!log_type)
|
2008-02-08 10:11:19 +08:00
|
|
|
DMWARN("Module for logging type \"%s\" not found.", type_name);
|
|
|
|
|
|
|
|
kfree(type_name_dup);
|
|
|
|
|
2009-04-03 02:55:30 +08:00
|
|
|
return log_type;
|
2008-02-08 10:11:19 +08:00
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static void put_type(struct dm_dirty_log_type *type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-25 04:43:41 +08:00
|
|
|
if (!type)
|
|
|
|
return;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&_lock);
|
2009-04-03 02:55:30 +08:00
|
|
|
if (!__find_dirty_log_type(type->name))
|
2008-04-25 04:43:41 +08:00
|
|
|
goto out;
|
|
|
|
|
2009-04-03 02:55:29 +08:00
|
|
|
module_put(type->module);
|
2008-04-25 04:43:41 +08:00
|
|
|
|
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&_lock);
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:38 +08:00
|
|
|
int dm_dirty_log_type_register(struct dm_dirty_log_type *type)
|
|
|
|
{
|
2008-04-25 04:43:41 +08:00
|
|
|
int r = 0;
|
|
|
|
|
2008-04-25 04:43:38 +08:00
|
|
|
spin_lock(&_lock);
|
2008-04-25 04:43:41 +08:00
|
|
|
if (!__find_dirty_log_type(type->name))
|
2009-04-03 02:55:30 +08:00
|
|
|
list_add(&type->list, &_log_types);
|
|
|
|
else
|
2008-04-25 04:43:41 +08:00
|
|
|
r = -EEXIST;
|
2008-04-25 04:43:38 +08:00
|
|
|
spin_unlock(&_lock);
|
|
|
|
|
2008-04-25 04:43:41 +08:00
|
|
|
return r;
|
2008-04-25 04:43:38 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dm_dirty_log_type_register);
|
|
|
|
|
|
|
|
int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type)
|
|
|
|
{
|
|
|
|
spin_lock(&_lock);
|
|
|
|
|
2009-04-03 02:55:30 +08:00
|
|
|
if (!__find_dirty_log_type(type->name)) {
|
2008-04-25 04:43:41 +08:00
|
|
|
spin_unlock(&_lock);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-04-03 02:55:30 +08:00
|
|
|
list_del(&type->list);
|
2008-04-25 04:43:38 +08:00
|
|
|
|
|
|
|
spin_unlock(&_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dm_dirty_log_type_unregister);
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
|
2009-12-11 07:52:01 +08:00
|
|
|
struct dm_target *ti,
|
|
|
|
int (*flush_callback_fn)(struct dm_target *ti),
|
|
|
|
unsigned int argc, char **argv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-25 04:43:35 +08:00
|
|
|
struct dm_dirty_log_type *type;
|
|
|
|
struct dm_dirty_log *log;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
log = kmalloc(sizeof(*log), GFP_KERNEL);
|
|
|
|
if (!log)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
type = get_type(type_name);
|
|
|
|
if (!type) {
|
|
|
|
kfree(log);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-11 07:52:01 +08:00
|
|
|
log->flush_callback_fn = flush_callback_fn;
|
2005-04-17 06:20:36 +08:00
|
|
|
log->type = type;
|
|
|
|
if (type->ctr(log, ti, argc, argv)) {
|
|
|
|
kfree(log);
|
|
|
|
put_type(type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return log;
|
|
|
|
}
|
2008-04-25 04:43:35 +08:00
|
|
|
EXPORT_SYMBOL(dm_dirty_log_create);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
void dm_dirty_log_destroy(struct dm_dirty_log *log)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
log->type->dtr(log);
|
|
|
|
put_type(log->type);
|
|
|
|
kfree(log);
|
|
|
|
}
|
2008-04-25 04:43:35 +08:00
|
|
|
EXPORT_SYMBOL(dm_dirty_log_destroy);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*-----------------------------------------------------------------
|
|
|
|
* Persistent and core logs share a lot of their implementation.
|
|
|
|
* FIXME: need a reload method to be called from a resume
|
|
|
|
*---------------------------------------------------------------*/
|
|
|
|
/*
|
|
|
|
* Magic for persistent mirrors: "MiRr"
|
|
|
|
*/
|
|
|
|
#define MIRROR_MAGIC 0x4D695272
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The on-disk version of the metadata.
|
|
|
|
*/
|
2006-02-01 19:04:51 +08:00
|
|
|
#define MIRROR_DISK_VERSION 2
|
2005-04-17 06:20:36 +08:00
|
|
|
#define LOG_OFFSET 2
|
|
|
|
|
2011-08-02 19:32:01 +08:00
|
|
|
struct log_header_disk {
|
|
|
|
__le32 magic;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Simple, incrementing version. no backward
|
|
|
|
* compatibility.
|
|
|
|
*/
|
2011-08-02 19:32:01 +08:00
|
|
|
__le32 version;
|
|
|
|
__le64 nr_regions;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct log_header_core {
|
|
|
|
uint32_t magic;
|
2005-04-17 06:20:36 +08:00
|
|
|
uint32_t version;
|
2011-08-02 19:32:01 +08:00
|
|
|
uint64_t nr_regions;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct log_c {
|
|
|
|
struct dm_target *ti;
|
2009-12-11 07:51:59 +08:00
|
|
|
int touched_dirtied;
|
|
|
|
int touched_cleaned;
|
2009-12-11 07:52:00 +08:00
|
|
|
int flush_failed;
|
2005-04-17 06:20:36 +08:00
|
|
|
uint32_t region_size;
|
|
|
|
unsigned int region_count;
|
|
|
|
region_t sync_count;
|
|
|
|
|
|
|
|
unsigned bitset_uint32_count;
|
|
|
|
uint32_t *clean_bits;
|
|
|
|
uint32_t *sync_bits;
|
|
|
|
uint32_t *recovering_bits; /* FIXME: this seems excessive */
|
|
|
|
|
|
|
|
int sync_search;
|
|
|
|
|
|
|
|
/* Resync flag */
|
|
|
|
enum sync {
|
|
|
|
DEFAULTSYNC, /* Synchronize if necessary */
|
|
|
|
NOSYNC, /* Devices known to be already in sync */
|
|
|
|
FORCESYNC, /* Force a sync to happen */
|
|
|
|
} sync;
|
|
|
|
|
2007-05-09 17:33:03 +08:00
|
|
|
struct dm_io_request io_req;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Disk log fields
|
|
|
|
*/
|
2007-05-09 17:32:57 +08:00
|
|
|
int log_dev_failed;
|
2009-12-11 07:52:02 +08:00
|
|
|
int log_dev_flush_failed;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dm_dev *log_dev;
|
2011-08-02 19:32:01 +08:00
|
|
|
struct log_header_core header;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-25 04:43:17 +08:00
|
|
|
struct dm_io_region header_location;
|
2011-08-02 19:32:01 +08:00
|
|
|
struct log_header_disk *disk_header;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The touched member needs to be updated every time we access
|
|
|
|
* one of the bitsets.
|
|
|
|
*/
|
2008-04-25 04:43:35 +08:00
|
|
|
static inline int log_test_bit(uint32_t *bs, unsigned bit)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-08-02 19:32:01 +08:00
|
|
|
return test_bit_le(bit, bs) ? 1 : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void log_set_bit(struct log_c *l,
|
|
|
|
uint32_t *bs, unsigned bit)
|
|
|
|
{
|
2011-08-02 19:32:01 +08:00
|
|
|
__set_bit_le(bit, bs);
|
2009-12-11 07:51:59 +08:00
|
|
|
l->touched_cleaned = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void log_clear_bit(struct log_c *l,
|
|
|
|
uint32_t *bs, unsigned bit)
|
|
|
|
{
|
2011-08-02 19:32:01 +08:00
|
|
|
__clear_bit_le(bit, bs);
|
2009-12-11 07:51:59 +08:00
|
|
|
l->touched_dirtied = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------
|
|
|
|
* Header IO
|
|
|
|
*--------------------------------------------------------------*/
|
2011-08-02 19:32:01 +08:00
|
|
|
static void header_to_disk(struct log_header_core *core, struct log_header_disk *disk)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
disk->magic = cpu_to_le32(core->magic);
|
|
|
|
disk->version = cpu_to_le32(core->version);
|
|
|
|
disk->nr_regions = cpu_to_le64(core->nr_regions);
|
|
|
|
}
|
|
|
|
|
2011-08-02 19:32:01 +08:00
|
|
|
static void header_from_disk(struct log_header_core *core, struct log_header_disk *disk)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
core->magic = le32_to_cpu(disk->magic);
|
|
|
|
core->version = le32_to_cpu(disk->version);
|
|
|
|
core->nr_regions = le64_to_cpu(disk->nr_regions);
|
|
|
|
}
|
|
|
|
|
2007-05-09 17:33:03 +08:00
|
|
|
static int rw_header(struct log_c *lc, int rw)
|
|
|
|
{
|
2016-06-06 03:32:04 +08:00
|
|
|
lc->io_req.bi_op = rw;
|
2007-05-09 17:33:03 +08:00
|
|
|
|
|
|
|
return dm_io(&lc->io_req, 1, &lc->header_location, NULL);
|
|
|
|
}
|
|
|
|
|
2009-12-11 07:52:00 +08:00
|
|
|
static int flush_header(struct log_c *lc)
|
|
|
|
{
|
|
|
|
struct dm_io_region null_location = {
|
|
|
|
.bdev = lc->header_location.bdev,
|
|
|
|
.sector = 0,
|
|
|
|
.count = 0,
|
|
|
|
};
|
|
|
|
|
2016-06-06 03:32:04 +08:00
|
|
|
lc->io_req.bi_op = REQ_OP_WRITE;
|
|
|
|
lc->io_req.bi_op_flags = WRITE_FLUSH;
|
2009-12-11 07:52:00 +08:00
|
|
|
|
|
|
|
return dm_io(&lc->io_req, 1, &null_location, NULL);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int read_header(struct log_c *log)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2007-05-09 17:33:03 +08:00
|
|
|
r = rw_header(log, READ);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
header_from_disk(&log->header, log->disk_header);
|
|
|
|
|
|
|
|
/* New log required? */
|
|
|
|
if (log->sync != DEFAULTSYNC || log->header.magic != MIRROR_MAGIC) {
|
|
|
|
log->header.magic = MIRROR_MAGIC;
|
|
|
|
log->header.version = MIRROR_DISK_VERSION;
|
|
|
|
log->header.nr_regions = 0;
|
|
|
|
}
|
|
|
|
|
2006-02-01 19:04:51 +08:00
|
|
|
#ifdef __LITTLE_ENDIAN
|
|
|
|
if (log->header.version == 1)
|
|
|
|
log->header.version = 2;
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (log->header.version != MIRROR_DISK_VERSION) {
|
|
|
|
DMWARN("incompatible disk log version");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-06 11:05:01 +08:00
|
|
|
static int _check_region_size(struct dm_target *ti, uint32_t region_size)
|
|
|
|
{
|
|
|
|
if (region_size < 2 || region_size > ti->len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!is_power_of_2(region_size))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*----------------------------------------------------------------
|
|
|
|
* core log constructor/destructor
|
|
|
|
*
|
|
|
|
* argv contains region_size followed optionally by [no]sync
|
|
|
|
*--------------------------------------------------------------*/
|
|
|
|
#define BYTE_SHIFT 3
|
2008-04-25 04:43:35 +08:00
|
|
|
static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
|
2006-06-26 15:27:29 +08:00
|
|
|
unsigned int argc, char **argv,
|
|
|
|
struct dm_dev *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
enum sync sync = DEFAULTSYNC;
|
|
|
|
|
|
|
|
struct log_c *lc;
|
|
|
|
uint32_t region_size;
|
|
|
|
unsigned int region_count;
|
2006-06-26 15:27:29 +08:00
|
|
|
size_t bitset_size, buf_size;
|
2007-05-09 17:33:03 +08:00
|
|
|
int r;
|
dm: reject trailing characters in sccanf input
Device mapper uses sscanf to convert arguments to numbers. The problem is that
the way we use it ignores additional unmatched characters in the scanned string.
For example, this `if (sscanf(string, "%d", &number) == 1)' will match a number,
but also it will match number with some garbage appended, like "123abc".
As a result, device mapper accepts garbage after some numbers. For example
the command `dmsetup create vg1-new --table "0 16384 linear 254:1bla 34816bla"'
will pass without an error.
This patch fixes all sscanf uses in device mapper. It appends "%c" with
a pointer to a dummy character variable to every sscanf statement.
The construct `if (sscanf(string, "%d%c", &number, &dummy) == 1)' succeeds
only if string is a null-terminated number (optionally preceded by some
whitespace characters). If there is some character appended after the number,
sscanf matches "%c", writes the character to the dummy variable and returns 2.
We check the return value for 1 and consequently reject numbers with some
garbage appended.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2012-03-29 01:41:26 +08:00
|
|
|
char dummy;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (argc < 1 || argc > 2) {
|
2008-04-25 04:43:06 +08:00
|
|
|
DMWARN("wrong number of arguments to dirty region log");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
if (!strcmp(argv[1], "sync"))
|
|
|
|
sync = FORCESYNC;
|
|
|
|
else if (!strcmp(argv[1], "nosync"))
|
|
|
|
sync = NOSYNC;
|
|
|
|
else {
|
2008-04-25 04:43:06 +08:00
|
|
|
DMWARN("unrecognised sync argument to "
|
|
|
|
"dirty region log: %s", argv[1]);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
dm: reject trailing characters in sccanf input
Device mapper uses sscanf to convert arguments to numbers. The problem is that
the way we use it ignores additional unmatched characters in the scanned string.
For example, this `if (sscanf(string, "%d", &number) == 1)' will match a number,
but also it will match number with some garbage appended, like "123abc".
As a result, device mapper accepts garbage after some numbers. For example
the command `dmsetup create vg1-new --table "0 16384 linear 254:1bla 34816bla"'
will pass without an error.
This patch fixes all sscanf uses in device mapper. It appends "%c" with
a pointer to a dummy character variable to every sscanf statement.
The construct `if (sscanf(string, "%d%c", &number, &dummy) == 1)' succeeds
only if string is a null-terminated number (optionally preceded by some
whitespace characters). If there is some character appended after the number,
sscanf matches "%c", writes the character to the dummy variable and returns 2.
We check the return value for 1 and consequently reject numbers with some
garbage appended.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2012-03-29 01:41:26 +08:00
|
|
|
if (sscanf(argv[0], "%u%c", ®ion_size, &dummy) != 1 ||
|
2009-01-06 11:05:01 +08:00
|
|
|
!_check_region_size(ti, region_size)) {
|
|
|
|
DMWARN("invalid region size %s", argv[0]);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
region_count = dm_sector_div_up(ti->len, region_size);
|
|
|
|
|
|
|
|
lc = kmalloc(sizeof(*lc), GFP_KERNEL);
|
|
|
|
if (!lc) {
|
|
|
|
DMWARN("couldn't allocate core log");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
lc->ti = ti;
|
2009-12-11 07:51:59 +08:00
|
|
|
lc->touched_dirtied = 0;
|
|
|
|
lc->touched_cleaned = 0;
|
2009-12-11 07:52:00 +08:00
|
|
|
lc->flush_failed = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
lc->region_size = region_size;
|
|
|
|
lc->region_count = region_count;
|
|
|
|
lc->sync = sync;
|
|
|
|
|
|
|
|
/*
|
2005-11-22 13:32:34 +08:00
|
|
|
* Work out how many "unsigned long"s we need to hold the bitset.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
bitset_size = dm_round_up(region_count,
|
2006-06-26 15:27:29 +08:00
|
|
|
sizeof(*lc->clean_bits) << BYTE_SHIFT);
|
2005-04-17 06:20:36 +08:00
|
|
|
bitset_size >>= BYTE_SHIFT;
|
|
|
|
|
2006-06-26 15:27:29 +08:00
|
|
|
lc->bitset_uint32_count = bitset_size / sizeof(*lc->clean_bits);
|
2006-06-26 15:27:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disk log?
|
|
|
|
*/
|
|
|
|
if (!dev) {
|
|
|
|
lc->clean_bits = vmalloc(bitset_size);
|
|
|
|
if (!lc->clean_bits) {
|
|
|
|
DMWARN("couldn't allocate clean bitset");
|
|
|
|
kfree(lc);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
lc->disk_header = NULL;
|
|
|
|
} else {
|
|
|
|
lc->log_dev = dev;
|
2007-05-09 17:32:57 +08:00
|
|
|
lc->log_dev_failed = 0;
|
2009-12-11 07:52:02 +08:00
|
|
|
lc->log_dev_flush_failed = 0;
|
2006-06-26 15:27:29 +08:00
|
|
|
lc->header_location.bdev = lc->log_dev->bdev;
|
|
|
|
lc->header_location.sector = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Buffer holds both header and bitset.
|
|
|
|
*/
|
2009-06-22 17:12:33 +08:00
|
|
|
buf_size =
|
|
|
|
dm_round_up((LOG_OFFSET << SECTOR_SHIFT) + bitset_size,
|
|
|
|
bdev_logical_block_size(lc->header_location.
|
|
|
|
bdev));
|
2009-01-06 11:05:02 +08:00
|
|
|
|
2009-06-22 17:12:14 +08:00
|
|
|
if (buf_size > i_size_read(dev->bdev->bd_inode)) {
|
2009-01-06 11:05:02 +08:00
|
|
|
DMWARN("log device %s too small: need %llu bytes",
|
|
|
|
dev->name, (unsigned long long)buf_size);
|
|
|
|
kfree(lc);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2006-06-26 15:27:29 +08:00
|
|
|
lc->header_location.count = buf_size >> SECTOR_SHIFT;
|
2009-01-06 11:04:59 +08:00
|
|
|
|
2007-05-09 17:33:03 +08:00
|
|
|
lc->io_req.mem.type = DM_IO_VMA;
|
2009-01-06 11:04:59 +08:00
|
|
|
lc->io_req.notify.fn = NULL;
|
2011-05-29 20:03:09 +08:00
|
|
|
lc->io_req.client = dm_io_client_create();
|
2007-05-09 17:33:03 +08:00
|
|
|
if (IS_ERR(lc->io_req.client)) {
|
|
|
|
r = PTR_ERR(lc->io_req.client);
|
|
|
|
DMWARN("couldn't allocate disk io client");
|
|
|
|
kfree(lc);
|
2011-01-14 04:00:00 +08:00
|
|
|
return r;
|
2007-05-09 17:33:03 +08:00
|
|
|
}
|
2006-06-26 15:27:29 +08:00
|
|
|
|
|
|
|
lc->disk_header = vmalloc(buf_size);
|
|
|
|
if (!lc->disk_header) {
|
|
|
|
DMWARN("couldn't allocate disk log buffer");
|
2009-01-06 11:04:56 +08:00
|
|
|
dm_io_client_destroy(lc->io_req.client);
|
2006-06-26 15:27:29 +08:00
|
|
|
kfree(lc);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2009-01-06 11:04:59 +08:00
|
|
|
lc->io_req.mem.ptr.vma = lc->disk_header;
|
2006-06-26 15:27:29 +08:00
|
|
|
lc->clean_bits = (void *)lc->disk_header +
|
|
|
|
(LOG_OFFSET << SECTOR_SHIFT);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-06-26 15:27:29 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
memset(lc->clean_bits, -1, bitset_size);
|
|
|
|
|
|
|
|
lc->sync_bits = vmalloc(bitset_size);
|
|
|
|
if (!lc->sync_bits) {
|
|
|
|
DMWARN("couldn't allocate sync bitset");
|
2006-06-26 15:27:29 +08:00
|
|
|
if (!dev)
|
|
|
|
vfree(lc->clean_bits);
|
2009-01-06 11:04:56 +08:00
|
|
|
else
|
|
|
|
dm_io_client_destroy(lc->io_req.client);
|
2006-06-26 15:27:29 +08:00
|
|
|
vfree(lc->disk_header);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(lc);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
memset(lc->sync_bits, (sync == NOSYNC) ? -1 : 0, bitset_size);
|
|
|
|
lc->sync_count = (sync == NOSYNC) ? region_count : 0;
|
|
|
|
|
2011-08-02 19:32:02 +08:00
|
|
|
lc->recovering_bits = vzalloc(bitset_size);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!lc->recovering_bits) {
|
|
|
|
DMWARN("couldn't allocate sync bitset");
|
|
|
|
vfree(lc->sync_bits);
|
2006-06-26 15:27:29 +08:00
|
|
|
if (!dev)
|
|
|
|
vfree(lc->clean_bits);
|
2009-01-06 11:04:56 +08:00
|
|
|
else
|
|
|
|
dm_io_client_destroy(lc->io_req.client);
|
2006-06-26 15:27:29 +08:00
|
|
|
vfree(lc->disk_header);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(lc);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
lc->sync_search = 0;
|
|
|
|
log->context = lc;
|
2006-06-26 15:27:29 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static int core_ctr(struct dm_dirty_log *log, struct dm_target *ti,
|
2006-06-26 15:27:29 +08:00
|
|
|
unsigned int argc, char **argv)
|
|
|
|
{
|
|
|
|
return create_log_context(log, ti, argc, argv, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_log_context(struct log_c *lc)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
vfree(lc->sync_bits);
|
|
|
|
vfree(lc->recovering_bits);
|
|
|
|
kfree(lc);
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static void core_dtr(struct dm_dirty_log *log)
|
2006-06-26 15:27:29 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
|
|
|
|
|
|
|
vfree(lc->clean_bits);
|
|
|
|
destroy_log_context(lc);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*----------------------------------------------------------------
|
|
|
|
* disk log constructor/destructor
|
|
|
|
*
|
|
|
|
* argv contains log_device region_size followed optionally by [no]sync
|
|
|
|
*--------------------------------------------------------------*/
|
2008-04-25 04:43:35 +08:00
|
|
|
static int disk_ctr(struct dm_dirty_log *log, struct dm_target *ti,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int argc, char **argv)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct dm_dev *dev;
|
|
|
|
|
|
|
|
if (argc < 2 || argc > 3) {
|
2008-04-25 04:43:06 +08:00
|
|
|
DMWARN("wrong number of arguments to disk dirty region log");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-03-24 21:52:14 +08:00
|
|
|
r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
2006-06-26 15:27:29 +08:00
|
|
|
r = create_log_context(log, ti, argc - 1, argv + 1, dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (r) {
|
|
|
|
dm_put_device(ti, dev);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static void disk_dtr(struct dm_dirty_log *log)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
2006-06-26 15:27:29 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
dm_put_device(lc->ti, lc->log_dev);
|
|
|
|
vfree(lc->disk_header);
|
2007-05-09 17:33:03 +08:00
|
|
|
dm_io_client_destroy(lc->io_req.client);
|
2006-06-26 15:27:29 +08:00
|
|
|
destroy_log_context(lc);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-05-09 17:32:57 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static int disk_resume(struct dm_dirty_log *log)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
unsigned i;
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
|
|
|
size_t size = lc->bitset_uint32_count * sizeof(uint32_t);
|
|
|
|
|
|
|
|
/* read the disk header */
|
|
|
|
r = read_header(lc);
|
2007-05-09 17:32:57 +08:00
|
|
|
if (r) {
|
2008-04-25 04:43:06 +08:00
|
|
|
DMWARN("%s: Failed to read header on dirty region log device",
|
2007-05-09 17:32:57 +08:00
|
|
|
lc->log_dev->name);
|
|
|
|
fail_log_device(lc);
|
2007-05-09 17:33:08 +08:00
|
|
|
/*
|
|
|
|
* 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;
|
2007-05-09 17:32:57 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-26 15:27:30 +08:00
|
|
|
/* set or clear any new bits -- device has grown */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (lc->sync == NOSYNC)
|
|
|
|
for (i = lc->header.nr_regions; i < lc->region_count; i++)
|
|
|
|
/* FIXME: amazingly inefficient */
|
|
|
|
log_set_bit(lc, lc->clean_bits, i);
|
|
|
|
else
|
|
|
|
for (i = lc->header.nr_regions; i < lc->region_count; i++)
|
|
|
|
/* FIXME: amazingly inefficient */
|
|
|
|
log_clear_bit(lc, lc->clean_bits, i);
|
|
|
|
|
2006-06-26 15:27:30 +08:00
|
|
|
/* clear any old bits -- device has shrunk */
|
|
|
|
for (i = lc->region_count; i % (sizeof(*lc->clean_bits) << BYTE_SHIFT); i++)
|
|
|
|
log_clear_bit(lc, lc->clean_bits, i);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* copy clean across to sync */
|
|
|
|
memcpy(lc->sync_bits, lc->clean_bits, size);
|
2012-07-31 05:40:59 +08:00
|
|
|
lc->sync_count = memweight(lc->clean_bits,
|
|
|
|
lc->bitset_uint32_count * sizeof(uint32_t));
|
2006-12-08 18:41:12 +08:00
|
|
|
lc->sync_search = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* set the correct number of regions in the header */
|
|
|
|
lc->header.nr_regions = lc->region_count;
|
|
|
|
|
2009-01-06 11:04:59 +08:00
|
|
|
header_to_disk(&lc->header, lc->disk_header);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* write the new header */
|
2009-01-06 11:04:59 +08:00
|
|
|
r = rw_header(lc, WRITE);
|
2009-12-11 07:52:02 +08:00
|
|
|
if (!r) {
|
2009-12-11 07:52:00 +08:00
|
|
|
r = flush_header(lc);
|
2009-12-11 07:52:02 +08:00
|
|
|
if (r)
|
|
|
|
lc->log_dev_flush_failed = 1;
|
|
|
|
}
|
2007-05-09 17:32:57 +08:00
|
|
|
if (r) {
|
2008-04-25 04:43:06 +08:00
|
|
|
DMWARN("%s: Failed to write header on dirty region log device",
|
2007-05-09 17:32:57 +08:00
|
|
|
lc->log_dev->name);
|
|
|
|
fail_log_device(lc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static uint32_t core_get_region_size(struct dm_dirty_log *log)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
|
|
|
return lc->region_size;
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static int core_resume(struct dm_dirty_log *log)
|
2006-12-08 18:41:12 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
|
|
|
lc->sync_search = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static int core_is_clean(struct dm_dirty_log *log, region_t region)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
|
|
|
return log_test_bit(lc->clean_bits, region);
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static int core_in_sync(struct dm_dirty_log *log, region_t region, int block)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
|
|
|
return log_test_bit(lc->sync_bits, region);
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static int core_flush(struct dm_dirty_log *log)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* no op */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static int disk_flush(struct dm_dirty_log *log)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-12-11 07:52:01 +08:00
|
|
|
int r, i;
|
|
|
|
struct log_c *lc = log->context;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* only write if the log has changed */
|
2009-12-11 07:51:59 +08:00
|
|
|
if (!lc->touched_cleaned && !lc->touched_dirtied)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
2009-12-11 07:52:01 +08:00
|
|
|
if (lc->touched_cleaned && log->flush_callback_fn &&
|
|
|
|
log->flush_callback_fn(lc->ti)) {
|
|
|
|
/*
|
|
|
|
* At this point it is impossible to determine which
|
|
|
|
* regions are clean and which are dirty (without
|
|
|
|
* re-reading the log off disk). So mark all of them
|
|
|
|
* dirty.
|
|
|
|
*/
|
|
|
|
lc->flush_failed = 1;
|
|
|
|
for (i = 0; i < lc->region_count; i++)
|
|
|
|
log_clear_bit(lc, lc->clean_bits, i);
|
|
|
|
}
|
|
|
|
|
2009-01-06 11:04:59 +08:00
|
|
|
r = rw_header(lc, WRITE);
|
2007-05-09 17:32:57 +08:00
|
|
|
if (r)
|
|
|
|
fail_log_device(lc);
|
2009-12-11 07:51:59 +08:00
|
|
|
else {
|
2009-12-11 07:52:00 +08:00
|
|
|
if (lc->touched_dirtied) {
|
|
|
|
r = flush_header(lc);
|
2009-12-11 07:52:02 +08:00
|
|
|
if (r) {
|
|
|
|
lc->log_dev_flush_failed = 1;
|
2009-12-11 07:52:00 +08:00
|
|
|
fail_log_device(lc);
|
2009-12-11 07:52:02 +08:00
|
|
|
} else
|
2009-12-11 07:52:00 +08:00
|
|
|
lc->touched_dirtied = 0;
|
|
|
|
}
|
2009-12-11 07:51:59 +08:00
|
|
|
lc->touched_cleaned = 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static void core_mark_region(struct dm_dirty_log *log, region_t region)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
|
|
|
log_clear_bit(lc, lc->clean_bits, region);
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static void core_clear_region(struct dm_dirty_log *log, region_t region)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
2009-12-11 07:52:00 +08:00
|
|
|
if (likely(!lc->flush_failed))
|
|
|
|
log_set_bit(lc, lc->clean_bits, region);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static int core_get_resync_work(struct dm_dirty_log *log, region_t *region)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
|
|
|
|
|
|
|
if (lc->sync_search >= lc->region_count)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
do {
|
2011-08-02 19:32:01 +08:00
|
|
|
*region = find_next_zero_bit_le(lc->sync_bits,
|
2005-04-17 06:20:36 +08:00
|
|
|
lc->region_count,
|
|
|
|
lc->sync_search);
|
|
|
|
lc->sync_search = *region + 1;
|
|
|
|
|
[PATCH] make dm-mirror not issue invalid resync requests
I've been attempting to set up a (Host)RAID mirror with dm_mirror on
2.6.14.3, and I've been having a strange little problem. The configuration
in question is a set of 9GB SCSI disks that have 17942584 sectors. I set
up the dm_mirror table as such:
0 17942528 mirror core 2 2048 nosync 2 8:48 0 8:64 0
If I'm not mistaken, this sets up a 9GB RAID1 mriror with 1MB stripes
across both SCSI disks. The sector count of the dm device is less than the
size of the disks, so we shouldn't fall off the end. However, I always get
the messages like this in dmesg when I set up the dm table:
attempt to access beyond end of device
sdd: rw=0, want=17958656, limit=17942584
Clearly, something is trying to read sectors past the end of the drive. I
traced it down to the __rh_recovery_prepare function in dm-raid1.c, which
gets called when we're putting the mirror set together. This function
calls the dirty region log's get_resync_work function to see if there's any
resync that needs to be done, and queues up any areas that are out of sync.
The log's get_resync_work function is actually a pointer to the
core_get_resync_work function in dm-log.c.
The core_get_resync_work function queries a bitset lc->sync_bits to find
out if there are any regions that are out of date (i.e. the bit is 0),
which is where the problem occurs. If every bit in lc->sync_bits is 1
(which is the case when we've just configured a new RAID1 with the nosync
option), the find_next_zero_bit does NOT return the size parameter
(lc->region_count in this case), it returns the size parameter rounded up
to the nearest multiple of 32! I don't know if this is intentional, but
i386 and x86_64 both exhibit this behavior.
In any case, the statement "if (*region == lc->region_count)" looks like
it's supposed to catch the case where are no regions to resync and
return 0. Since find_next_zero_bit apparently has a habit of returning
a value that's larger than lc->region_count, the enclosed patch changes
the equality test to a greater-than test so that we don't try to resync
areas outside of the RAID1 region. Seeing as the HostRAID metadata
lives just past the end of the RAID1 data, mucking around in that area
is not a good idea.
I suppose another way to fix this would be to amend find_next_zero_bit so
that it doesn't return values larger than "size", but I don't know if
there's a reason for the current behavior.
Signed-Off-By: Darrick J. Wong <djwong@us.ibm.com>
Acked-by: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-06 16:20:11 +08:00
|
|
|
if (*region >= lc->region_count)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
} while (log_test_bit(lc->recovering_bits, *region));
|
|
|
|
|
|
|
|
log_set_bit(lc, lc->recovering_bits, *region);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static void core_set_region_sync(struct dm_dirty_log *log, region_t region,
|
2006-12-08 18:41:11 +08:00
|
|
|
int in_sync)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
|
|
|
|
|
|
|
log_clear_bit(lc, lc->recovering_bits, region);
|
2006-12-08 18:41:11 +08:00
|
|
|
if (in_sync) {
|
2005-04-17 06:20:36 +08:00
|
|
|
log_set_bit(lc, lc->sync_bits, region);
|
|
|
|
lc->sync_count++;
|
2006-12-08 18:41:11 +08:00
|
|
|
} else if (log_test_bit(lc->sync_bits, region)) {
|
|
|
|
lc->sync_count--;
|
|
|
|
log_clear_bit(lc, lc->sync_bits, region);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static region_t core_get_sync_count(struct dm_dirty_log *log)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct log_c *lc = (struct log_c *) log->context;
|
|
|
|
|
|
|
|
return lc->sync_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DMEMIT_SYNC \
|
|
|
|
if (lc->sync != DEFAULTSYNC) \
|
|
|
|
DMEMIT("%ssync ", lc->sync == NOSYNC ? "no" : "")
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static int core_status(struct dm_dirty_log *log, status_type_t status,
|
2005-04-17 06:20:36 +08:00
|
|
|
char *result, unsigned int maxlen)
|
|
|
|
{
|
|
|
|
int sz = 0;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
|
|
|
switch(status) {
|
|
|
|
case STATUSTYPE_INFO:
|
2007-05-09 17:32:58 +08:00
|
|
|
DMEMIT("1 %s", log->type->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUSTYPE_TABLE:
|
|
|
|
DMEMIT("%s %u %u ", log->type->name,
|
|
|
|
lc->sync == DEFAULTSYNC ? 1 : 2, lc->region_size);
|
|
|
|
DMEMIT_SYNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static int disk_status(struct dm_dirty_log *log, status_type_t status,
|
2005-04-17 06:20:36 +08:00
|
|
|
char *result, unsigned int maxlen)
|
|
|
|
{
|
|
|
|
int sz = 0;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
|
|
|
switch(status) {
|
|
|
|
case STATUSTYPE_INFO:
|
2007-05-09 17:32:58 +08:00
|
|
|
DMEMIT("3 %s %s %c", log->type->name, lc->log_dev->name,
|
2009-12-11 07:52:02 +08:00
|
|
|
lc->log_dev_flush_failed ? 'F' :
|
|
|
|
lc->log_dev_failed ? 'D' :
|
|
|
|
'A');
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUSTYPE_TABLE:
|
|
|
|
DMEMIT("%s %u %s %u ", log->type->name,
|
2007-05-09 17:32:58 +08:00
|
|
|
lc->sync == DEFAULTSYNC ? 2 : 3, lc->log_dev->name,
|
2005-04-17 06:20:36 +08:00
|
|
|
lc->region_size);
|
|
|
|
DMEMIT_SYNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static struct dm_dirty_log_type _core_type = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.name = "core",
|
|
|
|
.module = THIS_MODULE,
|
|
|
|
.ctr = core_ctr,
|
|
|
|
.dtr = core_dtr,
|
2006-12-08 18:41:12 +08:00
|
|
|
.resume = core_resume,
|
2005-04-17 06:20:36 +08:00
|
|
|
.get_region_size = core_get_region_size,
|
|
|
|
.is_clean = core_is_clean,
|
|
|
|
.in_sync = core_in_sync,
|
|
|
|
.flush = core_flush,
|
|
|
|
.mark_region = core_mark_region,
|
|
|
|
.clear_region = core_clear_region,
|
|
|
|
.get_resync_work = core_get_resync_work,
|
2006-12-08 18:41:11 +08:00
|
|
|
.set_region_sync = core_set_region_sync,
|
2005-04-17 06:20:36 +08:00
|
|
|
.get_sync_count = core_get_sync_count,
|
|
|
|
.status = core_status,
|
|
|
|
};
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
static struct dm_dirty_log_type _disk_type = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.name = "disk",
|
|
|
|
.module = THIS_MODULE,
|
|
|
|
.ctr = disk_ctr,
|
|
|
|
.dtr = disk_dtr,
|
2007-10-20 05:47:57 +08:00
|
|
|
.postsuspend = disk_flush,
|
2005-04-17 06:20:36 +08:00
|
|
|
.resume = disk_resume,
|
|
|
|
.get_region_size = core_get_region_size,
|
|
|
|
.is_clean = core_is_clean,
|
|
|
|
.in_sync = core_in_sync,
|
|
|
|
.flush = disk_flush,
|
|
|
|
.mark_region = core_mark_region,
|
|
|
|
.clear_region = core_clear_region,
|
|
|
|
.get_resync_work = core_get_resync_work,
|
2006-12-08 18:41:11 +08:00
|
|
|
.set_region_sync = core_set_region_sync,
|
2005-04-17 06:20:36 +08:00
|
|
|
.get_sync_count = core_get_sync_count,
|
|
|
|
.status = disk_status,
|
|
|
|
};
|
|
|
|
|
2008-07-21 19:00:27 +08:00
|
|
|
static int __init dm_dirty_log_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
r = dm_dirty_log_type_register(&_core_type);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (r)
|
|
|
|
DMWARN("couldn't register core log");
|
|
|
|
|
2008-04-25 04:43:35 +08:00
|
|
|
r = dm_dirty_log_type_register(&_disk_type);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (r) {
|
|
|
|
DMWARN("couldn't register disk type");
|
2008-04-25 04:43:35 +08:00
|
|
|
dm_dirty_log_type_unregister(&_core_type);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-07-21 19:00:27 +08:00
|
|
|
static void __exit dm_dirty_log_exit(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-25 04:43:35 +08:00
|
|
|
dm_dirty_log_type_unregister(&_disk_type);
|
|
|
|
dm_dirty_log_type_unregister(&_core_type);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-25 04:43:09 +08:00
|
|
|
module_init(dm_dirty_log_init);
|
|
|
|
module_exit(dm_dirty_log_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION(DM_NAME " dirty region log");
|
|
|
|
MODULE_AUTHOR("Joe Thornber, Heinz Mauelshagen <dm-devel@redhat.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|