2009-06-22 17:12:35 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006-2009 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This file is released under the LGPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/bio.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-06-22 17:12:35 +08:00
|
|
|
#include <linux/dm-dirty-log.h>
|
|
|
|
#include <linux/device-mapper.h>
|
|
|
|
#include <linux/dm-log-userspace.h>
|
2011-07-04 01:58:33 +08:00
|
|
|
#include <linux/module.h>
|
2009-06-22 17:12:35 +08:00
|
|
|
|
|
|
|
#include "dm-log-userspace-transfer.h"
|
|
|
|
|
2011-01-14 03:59:52 +08:00
|
|
|
#define DM_LOG_USERSPACE_VSN "1.1.0"
|
|
|
|
|
2009-06-22 17:12:35 +08:00
|
|
|
struct flush_entry {
|
|
|
|
int type;
|
|
|
|
region_t region;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2011-01-14 03:59:51 +08:00
|
|
|
/*
|
|
|
|
* This limit on the number of mark and clear request is, to a degree,
|
|
|
|
* arbitrary. However, there is some basis for the choice in the limits
|
|
|
|
* imposed on the size of data payload by dm-log-userspace-transfer.c:
|
|
|
|
* dm_consult_userspace().
|
|
|
|
*/
|
|
|
|
#define MAX_FLUSH_GROUP_COUNT 32
|
|
|
|
|
2009-06-22 17:12:35 +08:00
|
|
|
struct log_c {
|
|
|
|
struct dm_target *ti;
|
2011-11-01 04:21:24 +08:00
|
|
|
struct dm_dev *log_dev;
|
2009-06-22 17:12:35 +08:00
|
|
|
uint32_t region_size;
|
|
|
|
region_t region_count;
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
uint64_t luid;
|
2009-06-22 17:12:35 +08:00
|
|
|
char uuid[DM_UUID_LEN];
|
|
|
|
|
|
|
|
char *usr_argv_str;
|
|
|
|
uint32_t usr_argc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* in_sync_hint gets set when doing is_remote_recovering. It
|
|
|
|
* represents the first region that needs recovery. IOW, the
|
|
|
|
* first zero bit of sync_bits. This can be useful for to limit
|
|
|
|
* traffic for calls like is_remote_recovering and get_resync_work,
|
|
|
|
* but be take care in its use for anything else.
|
|
|
|
*/
|
|
|
|
uint64_t in_sync_hint;
|
|
|
|
|
2011-01-14 03:59:50 +08:00
|
|
|
/*
|
|
|
|
* Mark and clear requests are held until a flush is issued
|
|
|
|
* so that we can group, and thereby limit, the amount of
|
|
|
|
* network traffic between kernel and userspace. The 'flush_lock'
|
|
|
|
* is used to protect these lists.
|
|
|
|
*/
|
2009-06-22 17:12:35 +08:00
|
|
|
spinlock_t flush_lock;
|
2011-01-14 03:59:50 +08:00
|
|
|
struct list_head mark_list;
|
|
|
|
struct list_head clear_list;
|
2009-06-22 17:12:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static mempool_t *flush_entry_pool;
|
|
|
|
|
|
|
|
static void *flush_entry_alloc(gfp_t gfp_mask, void *pool_data)
|
|
|
|
{
|
|
|
|
return kmalloc(sizeof(struct flush_entry), gfp_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flush_entry_free(void *element, void *pool_data)
|
|
|
|
{
|
|
|
|
kfree(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int userspace_do_request(struct log_c *lc, const char *uuid,
|
|
|
|
int request_type, char *data, size_t data_size,
|
|
|
|
char *rdata, size_t *rdata_size)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the server isn't there, -ESRCH is returned,
|
|
|
|
* and we must keep trying until the server is
|
|
|
|
* restored.
|
|
|
|
*/
|
|
|
|
retry:
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
r = dm_consult_userspace(uuid, lc->luid, request_type, data,
|
2009-06-22 17:12:35 +08:00
|
|
|
data_size, rdata, rdata_size);
|
|
|
|
|
|
|
|
if (r != -ESRCH)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
DMERR(" Userspace log server not found.");
|
|
|
|
while (1) {
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
schedule_timeout(2*HZ);
|
|
|
|
DMWARN("Attempting to contact userspace log server...");
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
r = dm_consult_userspace(uuid, lc->luid, DM_ULOG_CTR,
|
|
|
|
lc->usr_argv_str,
|
2009-06-22 17:12:35 +08:00
|
|
|
strlen(lc->usr_argv_str) + 1,
|
|
|
|
NULL, NULL);
|
|
|
|
if (!r)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DMINFO("Reconnected to userspace log server... DM_ULOG_CTR complete");
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
r = dm_consult_userspace(uuid, lc->luid, DM_ULOG_RESUME, NULL,
|
2009-06-22 17:12:35 +08:00
|
|
|
0, NULL, NULL);
|
|
|
|
if (!r)
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
DMERR("Error trying to resume userspace log: %d", r);
|
|
|
|
|
|
|
|
return -ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int build_constructor_string(struct dm_target *ti,
|
|
|
|
unsigned argc, char **argv,
|
|
|
|
char **ctr_str)
|
|
|
|
{
|
|
|
|
int i, str_size;
|
|
|
|
char *str = NULL;
|
|
|
|
|
|
|
|
*ctr_str = NULL;
|
|
|
|
|
|
|
|
for (i = 0, str_size = 0; i < argc; i++)
|
|
|
|
str_size += strlen(argv[i]) + 1; /* +1 for space between args */
|
|
|
|
|
|
|
|
str_size += 20; /* Max number of chars in a printed u64 number */
|
|
|
|
|
|
|
|
str = kzalloc(str_size, GFP_KERNEL);
|
|
|
|
if (!str) {
|
|
|
|
DMWARN("Unable to allocate memory for constructor string");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2009-09-05 03:40:30 +08:00
|
|
|
str_size = sprintf(str, "%llu", (unsigned long long)ti->len);
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
str_size += sprintf(str + str_size, " %s", argv[i]);
|
2009-06-22 17:12:35 +08:00
|
|
|
|
|
|
|
*ctr_str = str;
|
|
|
|
return str_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* userspace_ctr
|
|
|
|
*
|
|
|
|
* argv contains:
|
|
|
|
* <UUID> <other args>
|
|
|
|
* Where 'other args' is the userspace implementation specific log
|
|
|
|
* arguments. An example might be:
|
2011-11-01 04:21:22 +08:00
|
|
|
* <UUID> clustered-disk <arg count> <log dev> <region_size> [[no]sync]
|
2009-06-22 17:12:35 +08:00
|
|
|
*
|
|
|
|
* So, this module will strip off the <UUID> for identification purposes
|
|
|
|
* when communicating with userspace about a log; but will pass on everything
|
|
|
|
* else.
|
|
|
|
*/
|
|
|
|
static int userspace_ctr(struct dm_dirty_log *log, struct dm_target *ti,
|
|
|
|
unsigned argc, char **argv)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
int str_size;
|
|
|
|
char *ctr_str = NULL;
|
|
|
|
struct log_c *lc = NULL;
|
|
|
|
uint64_t rdata;
|
|
|
|
size_t rdata_size = sizeof(rdata);
|
2011-11-01 04:21:24 +08:00
|
|
|
char *devices_rdata = NULL;
|
|
|
|
size_t devices_rdata_size = DM_NAME_LEN;
|
2009-06-22 17:12:35 +08:00
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
DMWARN("Too few arguments to userspace dirty log");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-11-01 04:21:24 +08:00
|
|
|
lc = kzalloc(sizeof(*lc), GFP_KERNEL);
|
2009-06-22 17:12:35 +08:00
|
|
|
if (!lc) {
|
|
|
|
DMWARN("Unable to allocate userspace log context.");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
/* The ptr value is sufficient for local unique id */
|
2009-10-17 06:18:15 +08:00
|
|
|
lc->luid = (unsigned long)lc;
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
|
2009-06-22 17:12:35 +08:00
|
|
|
lc->ti = ti;
|
|
|
|
|
|
|
|
if (strlen(argv[0]) > (DM_UUID_LEN - 1)) {
|
|
|
|
DMWARN("UUID argument too long.");
|
|
|
|
kfree(lc);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(lc->uuid, argv[0], DM_UUID_LEN);
|
|
|
|
spin_lock_init(&lc->flush_lock);
|
2011-01-14 03:59:50 +08:00
|
|
|
INIT_LIST_HEAD(&lc->mark_list);
|
|
|
|
INIT_LIST_HEAD(&lc->clear_list);
|
2009-06-22 17:12:35 +08:00
|
|
|
|
|
|
|
str_size = build_constructor_string(ti, argc - 1, argv + 1, &ctr_str);
|
|
|
|
if (str_size < 0) {
|
|
|
|
kfree(lc);
|
|
|
|
return str_size;
|
|
|
|
}
|
|
|
|
|
2011-11-01 04:21:24 +08:00
|
|
|
devices_rdata = kzalloc(devices_rdata_size, GFP_KERNEL);
|
|
|
|
if (!devices_rdata) {
|
|
|
|
DMERR("Failed to allocate memory for device information");
|
|
|
|
r = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send table string and get back any opened device.
|
|
|
|
*/
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_CTR,
|
2011-11-01 04:21:24 +08:00
|
|
|
ctr_str, str_size,
|
|
|
|
devices_rdata, &devices_rdata_size);
|
2009-06-22 17:12:35 +08:00
|
|
|
|
2011-01-14 03:59:49 +08:00
|
|
|
if (r < 0) {
|
|
|
|
if (r == -ESRCH)
|
|
|
|
DMERR("Userspace log server not found");
|
|
|
|
else
|
|
|
|
DMERR("Userspace log server failed to create log");
|
2009-06-22 17:12:35 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Since the region size does not change, get it now */
|
|
|
|
rdata_size = sizeof(rdata);
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_GET_REGION_SIZE,
|
2009-06-22 17:12:35 +08:00
|
|
|
NULL, 0, (char *)&rdata, &rdata_size);
|
|
|
|
|
|
|
|
if (r) {
|
|
|
|
DMERR("Failed to get region size of dirty log");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
lc->region_size = (uint32_t)rdata;
|
|
|
|
lc->region_count = dm_sector_div_up(ti->len, lc->region_size);
|
|
|
|
|
2011-11-01 04:21:24 +08:00
|
|
|
if (devices_rdata_size) {
|
|
|
|
if (devices_rdata[devices_rdata_size - 1] != '\0') {
|
|
|
|
DMERR("DM_ULOG_CTR device return string not properly terminated");
|
|
|
|
r = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
r = dm_get_device(ti, devices_rdata,
|
|
|
|
dm_table_get_mode(ti->table), &lc->log_dev);
|
|
|
|
if (r)
|
|
|
|
DMERR("Failed to register %s with device-mapper",
|
|
|
|
devices_rdata);
|
|
|
|
}
|
2009-06-22 17:12:35 +08:00
|
|
|
out:
|
2011-11-01 04:21:24 +08:00
|
|
|
kfree(devices_rdata);
|
2009-06-22 17:12:35 +08:00
|
|
|
if (r) {
|
|
|
|
kfree(lc);
|
|
|
|
kfree(ctr_str);
|
|
|
|
} else {
|
|
|
|
lc->usr_argv_str = ctr_str;
|
|
|
|
lc->usr_argc = argc;
|
|
|
|
log->context = lc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void userspace_dtr(struct dm_dirty_log *log)
|
|
|
|
{
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
2011-01-14 03:59:49 +08:00
|
|
|
(void) dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_DTR,
|
2009-06-22 17:12:35 +08:00
|
|
|
NULL, 0,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2011-11-01 04:21:24 +08:00
|
|
|
if (lc->log_dev)
|
|
|
|
dm_put_device(lc->ti, lc->log_dev);
|
|
|
|
|
2009-06-22 17:12:35 +08:00
|
|
|
kfree(lc->usr_argv_str);
|
|
|
|
kfree(lc);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int userspace_presuspend(struct dm_dirty_log *log)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_PRESUSPEND,
|
2009-06-22 17:12:35 +08:00
|
|
|
NULL, 0,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int userspace_postsuspend(struct dm_dirty_log *log)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_POSTSUSPEND,
|
2009-06-22 17:12:35 +08:00
|
|
|
NULL, 0,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int userspace_resume(struct dm_dirty_log *log)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
|
|
|
lc->in_sync_hint = 0;
|
dm log: userspace add luid to distinguish between concurrent log instances
Device-mapper userspace logs (like the clustered log) are
identified by a universally unique identifier (UUID). This
identifier is used to associate requests from the kernel to
a specific log in userspace. The UUID must be unique everywhere,
since multiple machines may use this identifier when communicating
about a particular log, as is the case for cluster logs.
Sometimes, device-mapper/LVM may re-use a UUID. This is the
case during pvmoves, when moving from one segment of an LV
to another, or when resizing a mirror, etc. In these cases,
a new log is created with the same UUID and loaded in the
"inactive" slot. When a device-mapper "resume" is issued,
the "live" table is deactivated and the new "inactive" table
becomes "live". (The "inactive" table can also be removed
via a device-mapper 'clear' command.)
The above two issues were colliding. More than one log was being
created with the same UUID, and there was no way to distinguish
between them. So, sometimes the wrong log would be swapped
out during the exchange.
The solution is to create a locally unique identifier,
'luid', to go along with the UUID. This new identifier is used
to determine exactly which log is being referenced by the kernel
when the log exchange is made. The identifier is not
universally safe, but it does not need to be, since
create/destroy/suspend/resume operations are bound to a specific
machine; and these are the operations that make up the exchange.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2009-09-05 03:40:34 +08:00
|
|
|
r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_RESUME,
|
2009-06-22 17:12:35 +08:00
|
|
|
NULL, 0,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t userspace_get_region_size(struct dm_dirty_log *log)
|
|
|
|
{
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
|
|
|
return lc->region_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* userspace_is_clean
|
|
|
|
*
|
|
|
|
* Check whether a region is clean. If there is any sort of
|
|
|
|
* failure when consulting the server, we return not clean.
|
|
|
|
*
|
|
|
|
* Returns: 1 if clean, 0 otherwise
|
|
|
|
*/
|
|
|
|
static int userspace_is_clean(struct dm_dirty_log *log, region_t region)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
uint64_t region64 = (uint64_t)region;
|
|
|
|
int64_t is_clean;
|
|
|
|
size_t rdata_size;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
|
|
|
rdata_size = sizeof(is_clean);
|
|
|
|
r = userspace_do_request(lc, lc->uuid, DM_ULOG_IS_CLEAN,
|
|
|
|
(char *)®ion64, sizeof(region64),
|
|
|
|
(char *)&is_clean, &rdata_size);
|
|
|
|
|
|
|
|
return (r) ? 0 : (int)is_clean;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* userspace_in_sync
|
|
|
|
*
|
|
|
|
* Check if the region is in-sync. If there is any sort
|
|
|
|
* of failure when consulting the server, we assume that
|
|
|
|
* the region is not in sync.
|
|
|
|
*
|
|
|
|
* If 'can_block' is set, return immediately
|
|
|
|
*
|
|
|
|
* Returns: 1 if in-sync, 0 if not-in-sync, -EWOULDBLOCK
|
|
|
|
*/
|
|
|
|
static int userspace_in_sync(struct dm_dirty_log *log, region_t region,
|
|
|
|
int can_block)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
uint64_t region64 = region;
|
|
|
|
int64_t in_sync;
|
|
|
|
size_t rdata_size;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can never respond directly - even if in_sync_hint is
|
|
|
|
* set. This is because another machine could see a device
|
|
|
|
* failure and mark the region out-of-sync. If we don't go
|
|
|
|
* to userspace to ask, we might think the region is in-sync
|
|
|
|
* and allow a read to pick up data that is stale. (This is
|
|
|
|
* very unlikely if a device actually fails; but it is very
|
|
|
|
* likely if a connection to one device from one machine fails.)
|
|
|
|
*
|
|
|
|
* There still might be a problem if the mirror caches the region
|
|
|
|
* state as in-sync... but then this call would not be made. So,
|
|
|
|
* that is a mirror problem.
|
|
|
|
*/
|
|
|
|
if (!can_block)
|
|
|
|
return -EWOULDBLOCK;
|
|
|
|
|
|
|
|
rdata_size = sizeof(in_sync);
|
|
|
|
r = userspace_do_request(lc, lc->uuid, DM_ULOG_IN_SYNC,
|
|
|
|
(char *)®ion64, sizeof(region64),
|
|
|
|
(char *)&in_sync, &rdata_size);
|
|
|
|
return (r) ? 0 : (int)in_sync;
|
|
|
|
}
|
|
|
|
|
2011-01-14 03:59:51 +08:00
|
|
|
static int flush_one_by_one(struct log_c *lc, struct list_head *flush_list)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
struct flush_entry *fe;
|
|
|
|
|
|
|
|
list_for_each_entry(fe, flush_list, list) {
|
|
|
|
r = userspace_do_request(lc, lc->uuid, fe->type,
|
|
|
|
(char *)&fe->region,
|
|
|
|
sizeof(fe->region),
|
|
|
|
NULL, NULL);
|
|
|
|
if (r)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int flush_by_group(struct log_c *lc, struct list_head *flush_list)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
int count;
|
|
|
|
uint32_t type = 0;
|
|
|
|
struct flush_entry *fe, *tmp_fe;
|
|
|
|
LIST_HEAD(tmp_list);
|
|
|
|
uint64_t group[MAX_FLUSH_GROUP_COUNT];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Group process the requests
|
|
|
|
*/
|
|
|
|
while (!list_empty(flush_list)) {
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(fe, tmp_fe, flush_list, list) {
|
|
|
|
group[count] = fe->region;
|
|
|
|
count++;
|
|
|
|
|
2011-08-02 19:32:02 +08:00
|
|
|
list_move(&fe->list, &tmp_list);
|
2011-01-14 03:59:51 +08:00
|
|
|
|
|
|
|
type = fe->type;
|
|
|
|
if (count >= MAX_FLUSH_GROUP_COUNT)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = userspace_do_request(lc, lc->uuid, type,
|
|
|
|
(char *)(group),
|
|
|
|
count * sizeof(uint64_t),
|
|
|
|
NULL, NULL);
|
|
|
|
if (r) {
|
|
|
|
/* Group send failed. Attempt one-by-one. */
|
|
|
|
list_splice_init(&tmp_list, flush_list);
|
|
|
|
r = flush_one_by_one(lc, flush_list);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must collect flush_entrys that were successfully processed
|
|
|
|
* as a group so that they will be free'd by the caller.
|
|
|
|
*/
|
|
|
|
list_splice_init(&tmp_list, flush_list);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-06-22 17:12:35 +08:00
|
|
|
/*
|
|
|
|
* userspace_flush
|
|
|
|
*
|
|
|
|
* This function is ok to block.
|
|
|
|
* The flush happens in two stages. First, it sends all
|
|
|
|
* clear/mark requests that are on the list. Then it
|
|
|
|
* tells the server to commit them. This gives the
|
|
|
|
* server a chance to optimise the commit, instead of
|
|
|
|
* doing it for every request.
|
|
|
|
*
|
|
|
|
* Additionally, we could implement another thread that
|
|
|
|
* sends the requests up to the server - reducing the
|
|
|
|
* load on flush. Then the flush would have less in
|
|
|
|
* the list and be responsible for the finishing commit.
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, < 0 on failure
|
|
|
|
*/
|
|
|
|
static int userspace_flush(struct dm_dirty_log *log)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
struct log_c *lc = log->context;
|
2011-01-14 03:59:50 +08:00
|
|
|
LIST_HEAD(mark_list);
|
|
|
|
LIST_HEAD(clear_list);
|
2009-06-22 17:12:35 +08:00
|
|
|
struct flush_entry *fe, *tmp_fe;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&lc->flush_lock, flags);
|
2011-01-14 03:59:50 +08:00
|
|
|
list_splice_init(&lc->mark_list, &mark_list);
|
|
|
|
list_splice_init(&lc->clear_list, &clear_list);
|
2009-06-22 17:12:35 +08:00
|
|
|
spin_unlock_irqrestore(&lc->flush_lock, flags);
|
|
|
|
|
2011-01-14 03:59:50 +08:00
|
|
|
if (list_empty(&mark_list) && list_empty(&clear_list))
|
2009-06-22 17:12:35 +08:00
|
|
|
return 0;
|
|
|
|
|
2011-01-14 03:59:51 +08:00
|
|
|
r = flush_by_group(lc, &mark_list);
|
|
|
|
if (r)
|
|
|
|
goto fail;
|
2011-01-14 03:59:50 +08:00
|
|
|
|
2011-01-14 03:59:51 +08:00
|
|
|
r = flush_by_group(lc, &clear_list);
|
|
|
|
if (r)
|
|
|
|
goto fail;
|
2009-06-22 17:12:35 +08:00
|
|
|
|
|
|
|
r = userspace_do_request(lc, lc->uuid, DM_ULOG_FLUSH,
|
|
|
|
NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
/*
|
|
|
|
* We can safely remove these entries, even if failure.
|
|
|
|
* Calling code will receive an error and will know that
|
|
|
|
* the log facility has failed.
|
|
|
|
*/
|
2011-01-14 03:59:50 +08:00
|
|
|
list_for_each_entry_safe(fe, tmp_fe, &mark_list, list) {
|
|
|
|
list_del(&fe->list);
|
|
|
|
mempool_free(fe, flush_entry_pool);
|
|
|
|
}
|
|
|
|
list_for_each_entry_safe(fe, tmp_fe, &clear_list, list) {
|
2009-06-22 17:12:35 +08:00
|
|
|
list_del(&fe->list);
|
|
|
|
mempool_free(fe, flush_entry_pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
dm_table_event(lc->ti->table);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* userspace_mark_region
|
|
|
|
*
|
|
|
|
* This function should avoid blocking unless absolutely required.
|
|
|
|
* (Memory allocation is valid for blocking.)
|
|
|
|
*/
|
|
|
|
static void userspace_mark_region(struct dm_dirty_log *log, region_t region)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
struct flush_entry *fe;
|
|
|
|
|
|
|
|
/* Wait for an allocation, but _never_ fail */
|
|
|
|
fe = mempool_alloc(flush_entry_pool, GFP_NOIO);
|
|
|
|
BUG_ON(!fe);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&lc->flush_lock, flags);
|
|
|
|
fe->type = DM_ULOG_MARK_REGION;
|
|
|
|
fe->region = region;
|
2011-01-14 03:59:50 +08:00
|
|
|
list_add(&fe->list, &lc->mark_list);
|
2009-06-22 17:12:35 +08:00
|
|
|
spin_unlock_irqrestore(&lc->flush_lock, flags);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* userspace_clear_region
|
|
|
|
*
|
|
|
|
* This function must not block.
|
|
|
|
* So, the alloc can't block. In the worst case, it is ok to
|
|
|
|
* fail. It would simply mean we can't clear the region.
|
|
|
|
* Does nothing to current sync context, but does mean
|
|
|
|
* the region will be re-sync'ed on a reload of the mirror
|
|
|
|
* even though it is in-sync.
|
|
|
|
*/
|
|
|
|
static void userspace_clear_region(struct dm_dirty_log *log, region_t region)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
struct flush_entry *fe;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we fail to allocate, we skip the clearing of
|
|
|
|
* the region. This doesn't hurt us in any way, except
|
|
|
|
* to cause the region to be resync'ed when the
|
|
|
|
* device is activated next time.
|
|
|
|
*/
|
|
|
|
fe = mempool_alloc(flush_entry_pool, GFP_ATOMIC);
|
|
|
|
if (!fe) {
|
|
|
|
DMERR("Failed to allocate memory to clear region.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&lc->flush_lock, flags);
|
|
|
|
fe->type = DM_ULOG_CLEAR_REGION;
|
|
|
|
fe->region = region;
|
2011-01-14 03:59:50 +08:00
|
|
|
list_add(&fe->list, &lc->clear_list);
|
2009-06-22 17:12:35 +08:00
|
|
|
spin_unlock_irqrestore(&lc->flush_lock, flags);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* userspace_get_resync_work
|
|
|
|
*
|
|
|
|
* Get a region that needs recovery. It is valid to return
|
|
|
|
* an error for this function.
|
|
|
|
*
|
|
|
|
* Returns: 1 if region filled, 0 if no work, <0 on error
|
|
|
|
*/
|
|
|
|
static int userspace_get_resync_work(struct dm_dirty_log *log, region_t *region)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
size_t rdata_size;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
struct {
|
|
|
|
int64_t i; /* 64-bit for mix arch compatibility */
|
|
|
|
region_t r;
|
|
|
|
} pkg;
|
|
|
|
|
|
|
|
if (lc->in_sync_hint >= lc->region_count)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rdata_size = sizeof(pkg);
|
|
|
|
r = userspace_do_request(lc, lc->uuid, DM_ULOG_GET_RESYNC_WORK,
|
|
|
|
NULL, 0,
|
|
|
|
(char *)&pkg, &rdata_size);
|
|
|
|
|
|
|
|
*region = pkg.r;
|
|
|
|
return (r) ? r : (int)pkg.i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* userspace_set_region_sync
|
|
|
|
*
|
|
|
|
* Set the sync status of a given region. This function
|
|
|
|
* must not fail.
|
|
|
|
*/
|
|
|
|
static void userspace_set_region_sync(struct dm_dirty_log *log,
|
|
|
|
region_t region, int in_sync)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
struct {
|
|
|
|
region_t r;
|
|
|
|
int64_t i;
|
|
|
|
} pkg;
|
|
|
|
|
|
|
|
pkg.r = region;
|
|
|
|
pkg.i = (int64_t)in_sync;
|
|
|
|
|
|
|
|
r = userspace_do_request(lc, lc->uuid, DM_ULOG_SET_REGION_SYNC,
|
|
|
|
(char *)&pkg, sizeof(pkg),
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It would be nice to be able to report failures.
|
|
|
|
* However, it is easy emough to detect and resolve.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* userspace_get_sync_count
|
|
|
|
*
|
|
|
|
* If there is any sort of failure when consulting the server,
|
|
|
|
* we assume that the sync count is zero.
|
|
|
|
*
|
|
|
|
* Returns: sync count on success, 0 on failure
|
|
|
|
*/
|
|
|
|
static region_t userspace_get_sync_count(struct dm_dirty_log *log)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
size_t rdata_size;
|
|
|
|
uint64_t sync_count;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
|
|
|
rdata_size = sizeof(sync_count);
|
|
|
|
r = userspace_do_request(lc, lc->uuid, DM_ULOG_GET_SYNC_COUNT,
|
|
|
|
NULL, 0,
|
|
|
|
(char *)&sync_count, &rdata_size);
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (sync_count >= lc->region_count)
|
|
|
|
lc->in_sync_hint = lc->region_count;
|
|
|
|
|
|
|
|
return (region_t)sync_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* userspace_status
|
|
|
|
*
|
|
|
|
* Returns: amount of space consumed
|
|
|
|
*/
|
|
|
|
static int userspace_status(struct dm_dirty_log *log, status_type_t status_type,
|
|
|
|
char *result, unsigned maxlen)
|
|
|
|
{
|
|
|
|
int r = 0;
|
2009-09-05 03:40:30 +08:00
|
|
|
char *table_args;
|
2009-06-22 17:12:35 +08:00
|
|
|
size_t sz = (size_t)maxlen;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
|
|
|
|
switch (status_type) {
|
|
|
|
case STATUSTYPE_INFO:
|
|
|
|
r = userspace_do_request(lc, lc->uuid, DM_ULOG_STATUS_INFO,
|
|
|
|
NULL, 0,
|
|
|
|
result, &sz);
|
|
|
|
|
|
|
|
if (r) {
|
|
|
|
sz = 0;
|
|
|
|
DMEMIT("%s 1 COM_FAILURE", log->type->name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATUSTYPE_TABLE:
|
|
|
|
sz = 0;
|
2009-09-11 05:13:28 +08:00
|
|
|
table_args = strchr(lc->usr_argv_str, ' ');
|
2009-09-05 03:40:30 +08:00
|
|
|
BUG_ON(!table_args); /* There will always be a ' ' */
|
|
|
|
table_args++;
|
|
|
|
|
|
|
|
DMEMIT("%s %u %s %s ", log->type->name, lc->usr_argc,
|
|
|
|
lc->uuid, table_args);
|
2009-06-22 17:12:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (r) ? 0 : (int)sz;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* userspace_is_remote_recovering
|
|
|
|
*
|
|
|
|
* Returns: 1 if region recovering, 0 otherwise
|
|
|
|
*/
|
|
|
|
static int userspace_is_remote_recovering(struct dm_dirty_log *log,
|
|
|
|
region_t region)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
uint64_t region64 = region;
|
|
|
|
struct log_c *lc = log->context;
|
|
|
|
static unsigned long long limit;
|
|
|
|
struct {
|
|
|
|
int64_t is_recovering;
|
|
|
|
uint64_t in_sync_hint;
|
|
|
|
} pkg;
|
|
|
|
size_t rdata_size = sizeof(pkg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Once the mirror has been reported to be in-sync,
|
|
|
|
* it will never again ask for recovery work. So,
|
|
|
|
* we can safely say there is not a remote machine
|
|
|
|
* recovering if the device is in-sync. (in_sync_hint
|
|
|
|
* must be reset at resume time.)
|
|
|
|
*/
|
|
|
|
if (region < lc->in_sync_hint)
|
|
|
|
return 0;
|
|
|
|
else if (jiffies < limit)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
limit = jiffies + (HZ / 4);
|
|
|
|
r = userspace_do_request(lc, lc->uuid, DM_ULOG_IS_REMOTE_RECOVERING,
|
|
|
|
(char *)®ion64, sizeof(region64),
|
|
|
|
(char *)&pkg, &rdata_size);
|
|
|
|
if (r)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
lc->in_sync_hint = pkg.in_sync_hint;
|
|
|
|
|
|
|
|
return (int)pkg.is_recovering;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dm_dirty_log_type _userspace_type = {
|
|
|
|
.name = "userspace",
|
|
|
|
.module = THIS_MODULE,
|
|
|
|
.ctr = userspace_ctr,
|
|
|
|
.dtr = userspace_dtr,
|
|
|
|
.presuspend = userspace_presuspend,
|
|
|
|
.postsuspend = userspace_postsuspend,
|
|
|
|
.resume = userspace_resume,
|
|
|
|
.get_region_size = userspace_get_region_size,
|
|
|
|
.is_clean = userspace_is_clean,
|
|
|
|
.in_sync = userspace_in_sync,
|
|
|
|
.flush = userspace_flush,
|
|
|
|
.mark_region = userspace_mark_region,
|
|
|
|
.clear_region = userspace_clear_region,
|
|
|
|
.get_resync_work = userspace_get_resync_work,
|
|
|
|
.set_region_sync = userspace_set_region_sync,
|
|
|
|
.get_sync_count = userspace_get_sync_count,
|
|
|
|
.status = userspace_status,
|
|
|
|
.is_remote_recovering = userspace_is_remote_recovering,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init userspace_dirty_log_init(void)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
flush_entry_pool = mempool_create(100, flush_entry_alloc,
|
|
|
|
flush_entry_free, NULL);
|
|
|
|
|
|
|
|
if (!flush_entry_pool) {
|
|
|
|
DMWARN("Unable to create flush_entry_pool: No memory.");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = dm_ulog_tfr_init();
|
|
|
|
if (r) {
|
|
|
|
DMWARN("Unable to initialize userspace log communications");
|
|
|
|
mempool_destroy(flush_entry_pool);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = dm_dirty_log_type_register(&_userspace_type);
|
|
|
|
if (r) {
|
|
|
|
DMWARN("Couldn't register userspace dirty log type");
|
|
|
|
dm_ulog_tfr_exit();
|
|
|
|
mempool_destroy(flush_entry_pool);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-01-14 03:59:52 +08:00
|
|
|
DMINFO("version " DM_LOG_USERSPACE_VSN " loaded");
|
2009-06-22 17:12:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit userspace_dirty_log_exit(void)
|
|
|
|
{
|
|
|
|
dm_dirty_log_type_unregister(&_userspace_type);
|
|
|
|
dm_ulog_tfr_exit();
|
|
|
|
mempool_destroy(flush_entry_pool);
|
|
|
|
|
2011-01-14 03:59:52 +08:00
|
|
|
DMINFO("version " DM_LOG_USERSPACE_VSN " unloaded");
|
2009-06-22 17:12:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(userspace_dirty_log_init);
|
|
|
|
module_exit(userspace_dirty_log_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION(DM_NAME " userspace dirty log link");
|
|
|
|
MODULE_AUTHOR("Jonathan Brassow <dm-devel@redhat.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|