Whamcloud - gitweb
Teach ext2fs_extent_insert() to split the current node if necessary
authorEric Sandeen <sandeen@redhat.com>
Tue, 20 May 2008 15:15:27 +0000 (10:15 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 2 Jun 2008 14:14:08 +0000 (10:14 -0400)
If ext2fs_extent_insert finds that the requested node
for insertion is full, it will currently fail.

With this patch it will split as necessary to make room, unless an
EXT2_EXTENT_INSERT_NOSPLIT flag is passed to it.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ext2fs.h
lib/ext2fs/extent.c

index 7a1d966..30ca906 100644 (file)
@@ -332,8 +332,8 @@ typedef struct ext2_extent_path *ext2_extent_path_t;
 /*
  * Flags used by ext2fs_extent_insert()
  */
-
-#define EXT2_EXTENT_INSERT_AFTER  0x0001
+#define EXT2_EXTENT_INSERT_AFTER       0x0001 /* insert after handle loc'n */
+#define EXT2_EXTENT_INSERT_NOSPLIT     0x0002 /* insert may not cause split */
 
 /*
  * Data structure returned by ext2fs_extent_get_info()
index 4fa8ba0..b3129e7 100644 (file)
@@ -942,8 +942,17 @@ errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags,
 
        path = handle->path + handle->level;
 
-       if (path->entries >= path->max_entries)
-               return EXT2_ET_CANT_INSERT_EXTENT;
+       if (path->entries >= path->max_entries) {
+               if (flags & EXT2_EXTENT_INSERT_NOSPLIT) {
+                       return EXT2_ET_CANT_INSERT_EXTENT;
+               } else {
+                       dbg_printf("node full - splitting\n");
+                       retval = extent_node_split(handle, 0);
+                       if (retval)
+                               goto errout;
+                       path = handle->path + handle->level;
+               }
+       }
 
        eh = (struct ext3_extent_header *) path->buf;
        if (path->curr) {
@@ -1313,7 +1322,7 @@ void do_insert_node(int argc, char *argv[])
        }
 
        if (argc != 4) {
-               fprintf(stderr, "usage: %s <lblk> <len> <pblk>\n", cmd);
+               fprintf(stderr, "usage: %s [--after] <lblk> <len> <pblk>\n", cmd);
                return;
        }