Whamcloud - gitweb
libext2fs: fix parents when modifying extents
authorDarrick J. Wong <darrick.wong@oracle.com>
Sat, 15 Mar 2014 15:36:34 +0000 (11:36 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 15 Mar 2014 15:36:36 +0000 (11:36 -0400)
commitacbca26e254f0c39ea07024f49ba40855ba31070
tree2b5cc8ff7bae5ac5c054fd946203bc51b617a9d6
parenta14f0a647b206622aff71432ba995dcfd8305a95
libext2fs: fix parents when modifying extents

In ext2fs_extent_set_bmap() and ext2fs_punch_extent(), fix the parents
when altering either end of an extent so that the parent nodes reflect
the added mapping.

There's a slight complication to using fix_parents: if there are two
mappings to an lblk in the tree, the value of handle->path->curr can
point to either extent afterwards), which is documented in a comment.

Some additional color commentary from Darrick:

  In the _set_bmap() case, I noticed that the "remapping last block in
  extent" case would produce symptoms if we are trying to remap a
  block from "extent" to "next_extent", and the two extents are
  pointed to by different index nodes.  _extent_replace(...,
  next_extent) updates e_lblk in the leaf extent, but because there's
  no _extent_fix_parents() call, the index nodes never get updated.

  In the _punch_extent() case, we conclude that we need to split an
  extent into two pieces since we're punching out the middle.  If the
  extent is the last extent in the block, the second extent will be
  inserted into a new leaf node block.  Without _fix_parents(), the
  index node doesn't seem to get updated.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/extent.c
lib/ext2fs/punch.c