public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org, torvalds@osdl.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	akpm@osdl.org, alan@lxorguk.ukuu.org.uk, agk@redhat.com,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [patch 08/37] dm snapshot: unify chunk_size
Date: Wed, 6 Sep 2006 15:55:30 -0700	[thread overview]
Message-ID: <20060906225530.GI15922@kroah.com> (raw)
In-Reply-To: <20060906225444.GA15922@kroah.com>

[-- Attachment #1: dm-snapshot-unify-chunk_size.patch --]
[-- Type: text/plain, Size: 6456 bytes --]

-stable review patch.  If anyone has any objections, please let us know.

------------------

From: Alasdair G Kergon <agk@redhat.com>

Persistent snapshots currently store a private copy of the chunk size. 
Userspace also supplies the chunk size when loading a snapshot.  Ensure
consistency by only storing the chunk_size in one place instead of two.


Currently the two sizes will differ if the chunk size supplied by userspace
does not match the chunk size an existing snapshot actually uses.  Amongst
other problems, this causes an incorrect 'percentage full' to be reported.

The patch ensures consistency by only storing the chunk_size in one place,
removing it from struct pstore.  Some initialisation is delayed until the
correct chunk_size is known.  If read_header() discovers that the wrong chunk
size was supplied, the 'area' buffer (which the header already got read into)
is reinitialised to the correct size.

[akpm: too late for 2.6.17 - suitable for 2.6.17.x after it has settled]

Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---

 drivers/md/dm-exception-store.c |   65 +++++++++++++++++++++++++---------------
 drivers/md/dm-snap.c            |    6 +--
 2 files changed, 45 insertions(+), 26 deletions(-)

--- linux-2.6.17.11.orig/drivers/md/dm-exception-store.c
+++ linux-2.6.17.11/drivers/md/dm-exception-store.c
@@ -91,7 +91,6 @@ struct pstore {
 	struct dm_snapshot *snap;	/* up pointer to my snapshot */
 	int version;
 	int valid;
-	uint32_t chunk_size;
 	uint32_t exceptions_per_area;
 
 	/*
@@ -133,7 +132,7 @@ static int alloc_area(struct pstore *ps)
 	int r = -ENOMEM;
 	size_t len;
 
-	len = ps->chunk_size << SECTOR_SHIFT;
+	len = ps->snap->chunk_size << SECTOR_SHIFT;
 
 	/*
 	 * Allocate the chunk_size block of memory that will hold
@@ -160,8 +159,8 @@ static int chunk_io(struct pstore *ps, u
 	unsigned long bits;
 
 	where.bdev = ps->snap->cow->bdev;
-	where.sector = ps->chunk_size * chunk;
-	where.count = ps->chunk_size;
+	where.sector = ps->snap->chunk_size * chunk;
+	where.count = ps->snap->chunk_size;
 
 	return dm_io_sync_vm(1, &where, rw, ps->area, &bits);
 }
@@ -188,7 +187,7 @@ static int area_io(struct pstore *ps, ui
 
 static int zero_area(struct pstore *ps, uint32_t area)
 {
-	memset(ps->area, 0, ps->chunk_size << SECTOR_SHIFT);
+	memset(ps->area, 0, ps->snap->chunk_size << SECTOR_SHIFT);
 	return area_io(ps, area, WRITE);
 }
 
@@ -196,6 +195,7 @@ static int read_header(struct pstore *ps
 {
 	int r;
 	struct disk_header *dh;
+	chunk_t chunk_size;
 
 	r = chunk_io(ps, 0, READ);
 	if (r)
@@ -210,8 +210,29 @@ static int read_header(struct pstore *ps
 		*new_snapshot = 0;
 		ps->valid = le32_to_cpu(dh->valid);
 		ps->version = le32_to_cpu(dh->version);
-		ps->chunk_size = le32_to_cpu(dh->chunk_size);
-
+		chunk_size = le32_to_cpu(dh->chunk_size);
+		if (ps->snap->chunk_size != chunk_size) {
+			DMWARN("chunk size %llu in device metadata overrides "
+			       "table chunk size of %llu.",
+			       (unsigned long long)chunk_size,
+			       (unsigned long long)ps->snap->chunk_size);
+
+			/* We had a bogus chunk_size. Fix stuff up. */
+			dm_io_put(sectors_to_pages(ps->snap->chunk_size));
+			free_area(ps);
+
+			ps->snap->chunk_size = chunk_size;
+			ps->snap->chunk_mask = chunk_size - 1;
+			ps->snap->chunk_shift = ffs(chunk_size) - 1;
+
+			r = alloc_area(ps);
+			if (r)
+				return r;
+
+			r = dm_io_get(sectors_to_pages(chunk_size));
+			if (r)
+				return r;
+		}
 	} else {
 		DMWARN("Invalid/corrupt snapshot");
 		r = -ENXIO;
@@ -224,13 +245,13 @@ static int write_header(struct pstore *p
 {
 	struct disk_header *dh;
 
-	memset(ps->area, 0, ps->chunk_size << SECTOR_SHIFT);
+	memset(ps->area, 0, ps->snap->chunk_size << SECTOR_SHIFT);
 
 	dh = (struct disk_header *) ps->area;
 	dh->magic = cpu_to_le32(SNAP_MAGIC);
 	dh->valid = cpu_to_le32(ps->valid);
 	dh->version = cpu_to_le32(ps->version);
-	dh->chunk_size = cpu_to_le32(ps->chunk_size);
+	dh->chunk_size = cpu_to_le32(ps->snap->chunk_size);
 
 	return chunk_io(ps, 0, WRITE);
 }
@@ -365,7 +386,7 @@ static void persistent_destroy(struct ex
 {
 	struct pstore *ps = get_info(store);
 
-	dm_io_put(sectors_to_pages(ps->chunk_size));
+	dm_io_put(sectors_to_pages(ps->snap->chunk_size));
 	vfree(ps->callbacks);
 	free_area(ps);
 	kfree(ps);
@@ -384,6 +405,16 @@ static int persistent_read_metadata(stru
 		return r;
 
 	/*
+	 * Now we know correct chunk_size, complete the initialisation.
+	 */
+	ps->exceptions_per_area = (ps->snap->chunk_size << SECTOR_SHIFT) /
+				  sizeof(struct disk_exception);
+	ps->callbacks = dm_vcalloc(ps->exceptions_per_area,
+			sizeof(*ps->callbacks));
+	if (!ps->callbacks)
+		return -ENOMEM;
+
+	/*
 	 * Do we need to setup a new snapshot ?
 	 */
 	if (new_snapshot) {
@@ -533,9 +564,6 @@ int dm_create_persistent(struct exceptio
 	ps->snap = store->snap;
 	ps->valid = 1;
 	ps->version = SNAPSHOT_DISK_VERSION;
-	ps->chunk_size = chunk_size;
-	ps->exceptions_per_area = (chunk_size << SECTOR_SHIFT) /
-	    sizeof(struct disk_exception);
 	ps->next_free = 2;	/* skipping the header and first area */
 	ps->current_committed = 0;
 
@@ -543,18 +571,9 @@ int dm_create_persistent(struct exceptio
 	if (r)
 		goto bad;
 
-	/*
-	 * Allocate space for all the callbacks.
-	 */
 	ps->callback_count = 0;
 	atomic_set(&ps->pending_count, 0);
-	ps->callbacks = dm_vcalloc(ps->exceptions_per_area,
-				   sizeof(*ps->callbacks));
-
-	if (!ps->callbacks) {
-		r = -ENOMEM;
-		goto bad;
-	}
+	ps->callbacks = NULL;
 
 	store->destroy = persistent_destroy;
 	store->read_metadata = persistent_read_metadata;
--- linux-2.6.17.11.orig/drivers/md/dm-snap.c
+++ linux-2.6.17.11/drivers/md/dm-snap.c
@@ -530,7 +530,7 @@ static int snapshot_ctr(struct dm_target
 	}
 
 	ti->private = s;
-	ti->split_io = chunk_size;
+	ti->split_io = s->chunk_size;
 
 	return 0;
 
@@ -1204,7 +1204,7 @@ static int origin_status(struct dm_targe
 
 static struct target_type origin_target = {
 	.name    = "snapshot-origin",
-	.version = {1, 1, 0},
+	.version = {1, 4, 0},
 	.module  = THIS_MODULE,
 	.ctr     = origin_ctr,
 	.dtr     = origin_dtr,
@@ -1215,7 +1215,7 @@ static struct target_type origin_target 
 
 static struct target_type snapshot_target = {
 	.name    = "snapshot",
-	.version = {1, 1, 0},
+	.version = {1, 4, 0},
 	.module  = THIS_MODULE,
 	.ctr     = snapshot_ctr,
 	.dtr     = snapshot_dtr,

--

  parent reply	other threads:[~2006-09-06 23:01 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20060906224631.999046890@quad.kroah.org>
2006-09-06 22:54 ` [patch 00/37] -stable review Greg KH
2006-09-06 22:54   ` [patch 01/37] TEXTSEARCH: Fix Boyer Moore initialization bug Greg KH
2006-09-06 22:55   ` [patch 02/37] spectrum_cs: Fix firmware uploading errors Greg KH
2006-09-06 22:55   ` [patch 03/37] Fix output framentation of paged-skbs Greg KH
2006-09-06 22:55   ` [patch 04/37] fix compilation error on IA64 Greg KH
2006-09-07  8:45     ` Kirill Korotaev
2006-09-06 22:55   ` [patch 05/37] bridge-netfilter: dont overwrite memory outside of skb Greg KH
2006-09-06 22:55   ` [patch 06/37] Allow per-route window scale limiting Greg KH
2006-09-06 22:55   ` [patch 07/37] Have ext2 reject file handles with bad inode numbers early Greg KH
2006-09-06 22:55   ` Greg KH [this message]
2006-09-06 22:55   ` [patch 09/37] dm: fix idr minor allocation Greg KH
2006-09-06 22:55   ` [patch 10/37] dm: move idr_pre_get Greg KH
2006-09-06 22:55   ` [patch 11/37] dm: change minor_lock to spinlock Greg KH
2006-09-06 22:55   ` [patch 12/37] dm: add DMF_FREEING Greg KH
2006-09-06 22:56   ` [patch 13/37] dm: fix mapped device ref counting Greg KH
2006-09-06 22:56   ` [patch 14/37] dm: add module " Greg KH
2006-09-06 22:56   ` [patch 15/37] dm: fix block device initialisation Greg KH
2006-09-06 22:56   ` [patch 16/37] dm: mirror sector offset fix Greg KH
2006-09-06 22:56   ` [patch 17/37] TG3: Disable TSO by default Greg KH
2006-09-06 22:56   ` [patch 18/37] SPARC64: Fix X server crashes on sparc64 Greg KH
2006-09-06 22:56   ` [patch 19/37] SCTP: Fix sctp_primitive_ABORT() call in sctp_close() Greg KH
2006-09-06 22:56   ` [patch 20/37] IPV6 OOPSer triggerable by any user Greg KH
2006-09-06 22:56   ` [patch 21/37] fcntl(F_SETSIG) fix Greg KH
2006-09-06 22:57   ` [patch 22/37] bug in futex unqueue_me Greg KH
2006-09-06 22:57   ` [patch 23/37] binfmt_elf: fix checks for bad address Greg KH
2006-09-06 22:57   ` [patch 24/37] uhci-hcd: fix list access bug Greg KH
2006-09-06 22:57   ` [patch 25/37] Silent data corruption caused by XPC Greg KH
2006-09-06 22:57   ` [patch 26/37] PKTGEN: Make sure skb->{nh,h} are initialized in fill_packet_ipv6() too Greg KH
2006-09-06 22:57   ` [patch 27/37] PKTGEN: Fix oops when used with balance-tlb bonding Greg KH
2006-09-06 22:57   ` [patch 28/37] Missing PCI id update for VIA IDE Greg KH
2006-09-06 23:33     ` [-stable patch] pci_ids.h: add some VIA IDE identifiers Adrian Bunk
2006-09-06 22:57   ` [patch 29/37] dvb-core: Proper handling ULE SNDU length of 0 Greg KH
2006-09-07 12:57     ` Marcel Holtmann
2006-09-07 15:39       ` [stable] " Greg KH
2006-09-08 11:31         ` Marcel Holtmann
2006-09-08 12:58     ` Michael Krufky
2006-09-08 13:11       ` Ang Way Chuang
2006-09-08 17:29       ` Greg KH
2006-09-15 16:11         ` Michael Krufky
2006-09-15 16:15           ` Marcel Siegert
2006-09-15 16:36           ` Marcel Holtmann
2006-09-15 18:07             ` Michael Krufky
2006-09-15 18:18               ` Marcel Holtmann
2006-09-20  9:38                 ` Ang Way Chuang
2006-09-06 22:57   ` [patch 30/37] Remove redundant up() in stop_machine() Greg KH
2006-09-06 22:57   ` [patch 31/37] dm: Fix deadlock under high i/o load in raid1 setup Greg KH
2006-09-06 22:57   ` [patch 32/37] sky2: accept flow control Greg KH
2006-09-06 22:57   ` [patch 33/37] sky2: clear status IRQ after empty Greg KH
2006-09-06 22:57   ` [patch 34/37] sky2: use dev_alloc_skb for receive buffers Greg KH
2006-09-06 22:58   ` [patch 35/37] sky2: MSI test timing Greg KH
2006-09-06 22:58   ` [patch 36/37] sky2: fix fiber support Greg KH
2006-09-06 22:58   ` [patch 37/37] sky2: version 1.6.1 Greg KH
2006-09-07 19:25     ` Pavel Machek
2006-09-07 20:34       ` Greg KH
2006-09-07 21:03         ` Pavel Machek
2006-09-07 21:50           ` Stephen Hemminger
2006-09-06 23:33   ` [patch 00/37] -stable review Adrian Bunk
2006-09-07  2:08     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060906225530.GI15922@kroah.com \
    --to=gregkh@suse.de \
    --cc=agk@redhat.com \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=jmforbes@linuxtx.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=stable@kernel.org \
    --cc=torvalds@osdl.org \
    --cc=tytso@mit.edu \
    --cc=zwane@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox