hammer expand: Refactor a bit
authorMichael Neumann <mneumann@ntecs.de>
Tue, 24 Nov 2009 21:08:24 +0000 (22:08 +0100)
committerMichael Neumann <mneumann@ntecs.de>
Tue, 24 Nov 2009 21:08:24 +0000 (22:08 +0100)
sys/vfs/hammer/hammer_expand.c

index fc93392..ae496bf 100644 (file)
@@ -50,11 +50,10 @@ hammer_format_volume_header(struct hammer_mount *hmp, struct vnode *devvp,
        const char *vol_name, int vol_no, int vol_count,
        int64_t vol_size, int64_t boot_area_size, int64_t mem_area_size);
 
-static int
+static uint64_t
 hammer_format_freemap(struct hammer_mount *hmp,
        hammer_transaction_t trans,
-       hammer_volume_t volume,
-       hammer_volume_t root_volume);
+       hammer_volume_t volume);
 
 static uint64_t
 hammer_format_layer2_chunk(struct hammer_mount *hmp,
@@ -157,11 +156,30 @@ hammer_ioc_expand(hammer_transaction_t trans, hammer_inode_t ip,
 
        volume = hammer_get_volume(hmp, free_vol_no, &error);
        KKASSERT(volume != NULL && error == 0);
-
        root_volume = hammer_get_root_volume(hmp, &error);
        KKASSERT(root_volume != NULL && error == 0);
 
-       error = hammer_format_freemap(hmp, trans, volume, root_volume);
+       uint64_t total_free_bigblocks =
+               hammer_format_freemap(hmp, trans, volume);
+
+       /*
+        * Increase the total number of bigblocks
+        */
+       hammer_modify_volume_field(trans, root_volume,
+               vol0_stat_bigblocks);
+       root_volume->ondisk->vol0_stat_bigblocks += total_free_bigblocks;
+       hammer_modify_volume_done(root_volume);
+
+       /*
+        * Increase the number of free bigblocks
+        * (including the copy in hmp)
+        */
+       hammer_modify_volume_field(trans, root_volume,
+               vol0_stat_freebigblocks);
+       root_volume->ondisk->vol0_stat_freebigblocks += total_free_bigblocks;
+       hmp->copy_stat_freebigblocks =
+               root_volume->ondisk->vol0_stat_freebigblocks;
+       hammer_modify_volume_done(root_volume);
 
        hammer_rel_volume(root_volume, 0);
        hammer_rel_volume(volume, 0);
@@ -175,11 +193,10 @@ end:
        return (error);
 }
 
-static int
+static uint64_t
 hammer_format_freemap(struct hammer_mount *hmp,
        hammer_transaction_t trans,
-       hammer_volume_t volume,
-       hammer_volume_t root_volume)
+       hammer_volume_t volume)
 {
        hammer_off_t phys_offset;
        hammer_buffer_t buffer = NULL;
@@ -224,31 +241,12 @@ hammer_format_freemap(struct hammer_mount *hmp,
                total_free_bigblocks += free_bigblocks;
        }
 
-       /*
-        * Increase the total number of bigblocks
-        */
-       hammer_modify_volume_field(trans, root_volume,
-               vol0_stat_bigblocks);
-       root_volume->ondisk->vol0_stat_bigblocks += total_free_bigblocks;
-       hammer_modify_volume_done(root_volume);
-
-       /*
-        * Increase the number of free bigblocks
-        * (including the copy in hmp)
-        */
-       hammer_modify_volume_field(trans, root_volume,
-               vol0_stat_freebigblocks);
-       root_volume->ondisk->vol0_stat_freebigblocks += total_free_bigblocks;
-       hmp->copy_stat_freebigblocks =
-               root_volume->ondisk->vol0_stat_freebigblocks;
-       hammer_modify_volume_done(root_volume);
-
        if (buffer) {
                hammer_rel_buffer(buffer, 0);
                buffer = NULL;
        }
 
-       return (error);
+       return total_free_bigblocks;
 }
 
 /*