linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libext2fs: reset handle after inserting new extent
@ 2009-07-06 22:15 Eric Sandeen
  2009-07-07 13:35 ` Theodore Tso
  2009-07-07 19:30 ` [PATCH V2] " Eric Sandeen
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Sandeen @ 2009-07-06 22:15 UTC (permalink / raw)
  To: ext4 development

Commit 53422e8a5644e22ea3f6e0efba82a765b72e4308 moved
the new extent insertion in ext2fs_extent_set_bmap prior
to the modification of the original extent, but the
insert function left the handle pointing a the new
extent; this left us modifying the -new- extent not
the original one, and winding up with a corrupt extent
tree something like:

BLOCKS:
(0-1):588791-588792, (0):588791

We need to move back to the previous extent prior
to modification, if we inserted a new one.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

(aside: should there be functions to simply move
the handle around, w/o necessarily populating an
extent structure?)

(aside2: maybe ext2fs_extent_insert should take a flag
saying whether the handle should be moved after the
insertion; moving it around to back where we want to be
seems a bit tedious)

diff --git a/lib/ext2fs/extent.c b/lib/ext2fs/extent.c
index 35b080e..9ea5c30 100644
--- a/lib/ext2fs/extent.c
+++ b/lib/ext2fs/extent.c
@@ -1257,6 +1257,11 @@ again:
 					EXT2_EXTENT_INSERT_AFTER, &newextent);
 			if (retval)
 				goto done;
+			/* Now pointing at new extent; move back to prev */
+			retval = ext2fs_extent_get(handle, EXT2_EXTENT_PREV,
+						   &extent);
+			if (retval)
+				goto done;
 		}
 		extent.e_len--;
 		retval = ext2fs_extent_replace(handle, 0, &extent);


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] libext2fs: reset handle after inserting new extent
  2009-07-06 22:15 [PATCH] libext2fs: reset handle after inserting new extent Eric Sandeen
@ 2009-07-07 13:35 ` Theodore Tso
  2009-07-07 14:22   ` Eric Sandeen
  2009-07-07 19:30 ` [PATCH V2] " Eric Sandeen
  1 sibling, 1 reply; 4+ messages in thread
From: Theodore Tso @ 2009-07-07 13:35 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development

On Mon, Jul 06, 2009 at 05:15:07PM -0500, Eric Sandeen wrote:
> Commit 53422e8a5644e22ea3f6e0efba82a765b72e4308 moved
> the new extent insertion in ext2fs_extent_set_bmap prior
> to the modification of the original extent, but the
> insert function left the handle pointing a the new
> extent; this left us modifying the -new- extent not
> the original one, and winding up with a corrupt extent
> tree something like:
> 
> BLOCKS:
> (0-1):588791-588792, (0):588791
> 
> We need to move back to the previous extent prior
> to modification, if we inserted a new one.

Hmm, I just thought of something awful; what if the insert resulted in
a node split?  Instead of using ext2fs_extent_get(EXT2_EXTENT_PREV),
we may need to use ext2fs_extent_goto() to seek to the correct logical
block instead.

						- Ted

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libext2fs: reset handle after inserting new extent
  2009-07-07 13:35 ` Theodore Tso
@ 2009-07-07 14:22   ` Eric Sandeen
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Sandeen @ 2009-07-07 14:22 UTC (permalink / raw)
  To: Theodore Tso; +Cc: ext4 development

Theodore Tso wrote:
> On Mon, Jul 06, 2009 at 05:15:07PM -0500, Eric Sandeen wrote:
>> Commit 53422e8a5644e22ea3f6e0efba82a765b72e4308 moved
>> the new extent insertion in ext2fs_extent_set_bmap prior
>> to the modification of the original extent, but the
>> insert function left the handle pointing a the new
>> extent; this left us modifying the -new- extent not
>> the original one, and winding up with a corrupt extent
>> tree something like:
>>
>> BLOCKS:
>> (0-1):588791-588792, (0):588791
>>
>> We need to move back to the previous extent prior
>> to modification, if we inserted a new one.
> 
> Hmm, I just thought of something awful; what if the insert resulted in
> a node split?  Instead of using ext2fs_extent_get(EXT2_EXTENT_PREV),
> we may need to use ext2fs_extent_goto() to seek to the correct logical
> block instead.
> 
> 						- Ted

Hm....

so PREV doesn't go to the node for the previous logical block, but to
what, the node to the left at this level?  Guess I need to read more
carefully...

-Eric

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH V2] libext2fs: reset handle after inserting new extent
  2009-07-06 22:15 [PATCH] libext2fs: reset handle after inserting new extent Eric Sandeen
  2009-07-07 13:35 ` Theodore Tso
@ 2009-07-07 19:30 ` Eric Sandeen
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Sandeen @ 2009-07-07 19:30 UTC (permalink / raw)
  To: ext4 development

Commit 53422e8a5644e22ea3f6e0efba82a765b72e4308 moved
the new extent insertion in ext2fs_extent_set_bmap prior
to the modification of the original extent, but the
insert function left the handle pointing a the new
extent; this left us modifying the -new- extent not
the original one, and winding up with a corrupt extent
tree something like:

BLOCKS:
(0-1):588791-588792, (0):588791

We need to move back to the previous extent prior
to modification, if we inserted a new one.

V2: Use extent_goto vs. extent_get.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/lib/ext2fs/extent.c b/lib/ext2fs/extent.c
index 35b080e..4a4fd2c 100644
--- a/lib/ext2fs/extent.c
+++ b/lib/ext2fs/extent.c
@@ -1257,6 +1257,10 @@ again:
 					EXT2_EXTENT_INSERT_AFTER, &newextent);
 			if (retval)
 				goto done;
+			/* Now pointing at inserted extent; move back to prev */
+			retval = ext2fs_extent_goto(handle, logical - 1);
+			if (retval)
+				goto done;
 		}
 		extent.e_len--;
 		retval = ext2fs_extent_replace(handle, 0, &extent);


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-07-07 19:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-06 22:15 [PATCH] libext2fs: reset handle after inserting new extent Eric Sandeen
2009-07-07 13:35 ` Theodore Tso
2009-07-07 14:22   ` Eric Sandeen
2009-07-07 19:30 ` [PATCH V2] " Eric Sandeen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).