Move snapshot metadata loading to happen when the table is created instead of
when the device is resumed. Writes to the origin device don't trigger
exceptions until each snapshot table becomes active when resume() is called on
each snapshot.
If you're using lvm2, for this patch to work properly you should update to
lvm2 version 2.02.01 or later and device-mapper version 1.02.02 or later.
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
static void read_snapshot_metadata(struct dm_snapshot *s)
{
static void read_snapshot_metadata(struct dm_snapshot *s)
{
- if (s->have_metadata)
- return;
-
if (s->store.read_metadata(&s->store)) {
down_write(&s->lock);
s->valid = 0;
up_write(&s->lock);
}
if (s->store.read_metadata(&s->store)) {
down_write(&s->lock);
s->valid = 0;
up_write(&s->lock);
}
-
- s->have_metadata = 1;
s->chunk_shift = ffs(chunk_size) - 1;
s->valid = 1;
s->chunk_shift = ffs(chunk_size) - 1;
s->valid = 1;
s->last_percent = 0;
init_rwsem(&s->lock);
s->table = ti->table;
s->last_percent = 0;
init_rwsem(&s->lock);
s->table = ti->table;
+ /* Metadata must only be loaded into one table at once */
+ read_snapshot_metadata(s);
+
/* Add snapshot to the list of snapshots for this origin */
/* Add snapshot to the list of snapshots for this origin */
+ /* Exceptions aren't triggered till snapshot_resume() is called */
if (register_snapshot(s)) {
r = -EINVAL;
ti->error = "Cannot register snapshot origin";
if (register_snapshot(s)) {
r = -EINVAL;
ti->error = "Cannot register snapshot origin";
{
struct dm_snapshot *s = (struct dm_snapshot *) ti->private;
{
struct dm_snapshot *s = (struct dm_snapshot *) ti->private;
- read_snapshot_metadata(s);
+ down_write(&s->lock);
+ s->active = 1;
+ up_write(&s->lock);
}
static int snapshot_status(struct dm_target *ti, status_type_t type,
}
static int snapshot_status(struct dm_target *ti, status_type_t type,
/* Do all the snapshots on this origin */
list_for_each_entry (snap, snapshots, list) {
/* Do all the snapshots on this origin */
list_for_each_entry (snap, snapshots, list) {
- /* Only deal with valid snapshots */
- if (!snap->valid)
+ /* Only deal with valid and active snapshots */
+ if (!snap->valid || !snap->active)
continue;
/* Nothing to do if writing beyond end of snapshot */
continue;
/* Nothing to do if writing beyond end of snapshot */
static struct target_type origin_target = {
.name = "snapshot-origin",
static struct target_type origin_target = {
.name = "snapshot-origin",
.module = THIS_MODULE,
.ctr = origin_ctr,
.dtr = origin_dtr,
.module = THIS_MODULE,
.ctr = origin_ctr,
.dtr = origin_dtr,
static struct target_type snapshot_target = {
.name = "snapshot",
static struct target_type snapshot_target = {
.name = "snapshot",
.module = THIS_MODULE,
.ctr = snapshot_ctr,
.dtr = snapshot_dtr,
.module = THIS_MODULE,
.ctr = snapshot_ctr,
.dtr = snapshot_dtr,
/* You can't use a snapshot if this is 0 (e.g. if full) */
int valid;
/* You can't use a snapshot if this is 0 (e.g. if full) */
int valid;
+
+ /* Origin writes don't trigger exceptions until this is set */
+ int active;
/* Used for display of table */
char type;
/* Used for display of table */
char type;