From 9e29c876fdbd9f805deb6dec9ba305f1c8387bc6 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 14 Jun 2008 01:44:13 +0000 Subject: [PATCH] HAMMER Utilities: Sync with commit 55 - MEDIA STRUCTURES CHANGED! * newfs_hammer now creates a new blockmap zone for meta-data * The hammer utility has been enhanced and brought up-to-date. One can now reblock directories separately from other data. * The hammer show command now properly understands the B-Tree element localization field (fixed improper reporting of 'B'ad B-Tree elements). --- sbin/hammer/cmd_blockmap.c | 4 ++-- sbin/hammer/cmd_reblock.c | 8 +++++--- sbin/hammer/hammer.8 | 40 +++++++++++++++++++++++----------------- sbin/hammer/hammer.c | 4 +++- sbin/hammer/misc.c | 7 ++++++- sbin/newfs_hammer/newfs_hammer.c | 11 ++++++----- 6 files changed, 45 insertions(+), 29 deletions(-) diff --git a/sbin/hammer/cmd_blockmap.c b/sbin/hammer/cmd_blockmap.c index b0b70fd8e1..9fd075e336 100644 --- a/sbin/hammer/cmd_blockmap.c +++ b/sbin/hammer/cmd_blockmap.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/cmd_blockmap.c,v 1.1 2008/02/23 20:55:21 dillon Exp $ + * $DragonFly: src/sbin/hammer/cmd_blockmap.c,v 1.2 2008/06/14 01:44:11 dillon Exp $ */ #include "hammer.h" @@ -42,7 +42,7 @@ void hammer_cmd_blockmap(void) { dump_blockmap("btree", HAMMER_ZONE_BTREE_INDEX); - dump_blockmap("record", HAMMER_ZONE_RECORD_INDEX); + dump_blockmap("meta", HAMMER_ZONE_META_INDEX); dump_blockmap("large-data", HAMMER_ZONE_LARGE_DATA_INDEX); dump_blockmap("small-data", HAMMER_ZONE_SMALL_DATA_INDEX); } diff --git a/sbin/hammer/cmd_reblock.c b/sbin/hammer/cmd_reblock.c index 2af86e8651..566b72478e 100644 --- a/sbin/hammer/cmd_reblock.c +++ b/sbin/hammer/cmd_reblock.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/cmd_reblock.c,v 1.6 2008/05/18 01:49:41 dillon Exp $ + * $DragonFly: src/sbin/hammer/cmd_reblock.c,v 1.7 2008/06/14 01:44:11 dillon Exp $ */ #include "hammer.h" @@ -64,11 +64,12 @@ hammer_cmd_reblock(char **av, int ac, int flags) * Restrict the localization domain if asked to do inodes or data, * but not both. */ - switch(flags & (HAMMER_IOC_DO_INODES|HAMMER_IOC_DO_DATA)) { + switch(flags & (HAMMER_IOC_DO_INODES|HAMMER_IOC_DO_DATA|HAMMER_IOC_DO_DIRS)) { case HAMMER_IOC_DO_INODES: reblock.beg_localization = HAMMER_LOCALIZE_INODE; reblock.end_localization = HAMMER_LOCALIZE_INODE; break; + case HAMMER_IOC_DO_DIRS: case HAMMER_IOC_DO_DATA: reblock.beg_localization = HAMMER_LOCALIZE_MISC; reblock.end_localization = HAMMER_LOCALIZE_MISC; @@ -79,7 +80,7 @@ hammer_cmd_reblock(char **av, int ac, int flags) reblock_usage(1); filesystem = av[0]; if (ac == 1) { - perc = 90; + perc = 100; } else { perc = strtol(av[1], NULL, 0); if (perc < 0 || perc > 100) @@ -128,6 +129,7 @@ reblock_usage(int exit_code) fprintf(stderr, "hammer reblock [percentage]\n"); fprintf(stderr, "hammer reblock-btree [percentage]\n"); fprintf(stderr, "hammer reblock-inodes [percentage]\n"); + fprintf(stderr, "hammer reblock-dirs [percentage]\n"); fprintf(stderr, "hammer reblock-data [percentage]\n"); fprintf(stderr, "By default 90%% is used. Use 100%% to defragment\n"); exit(exit_code); diff --git a/sbin/hammer/hammer.8 b/sbin/hammer/hammer.8 index 1458c1ea13..21bcec3848 100644 --- a/sbin/hammer/hammer.8 +++ b/sbin/hammer/hammer.8 @@ -30,7 +30,7 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $DragonFly: src/sbin/hammer/hammer.8,v 1.19 2008/06/08 20:40:38 swildner Exp $ +.\" $DragonFly: src/sbin/hammer/hammer.8,v 1.20 2008/06/14 01:44:11 dillon Exp $ .Dd December 31, 2007 .Dt HAMMER 8 .Os @@ -229,25 +229,31 @@ available space. .It Ar reblock Ar filesystem Op Ar fill_percentage .It Ar reblock-btree Ar filesystem Op Ar fill_percentage .It Ar reblock-inodes Ar filesystem Op Ar fill_percentage +.It Ar reblock-dirs Ar filesystem Op Ar fill_percentage .It Ar reblock-data Ar filesystem Op Ar fill_percentage -Attempt to free space for reuse by reblocking a live HAMMER filesystem. -Big blocks cannot be reused until they are completely free. Scan the -filesystem and move B-Tree elements, inodes, and data from not-quite-full -big blocks to new big blocks in an attempt to free up the not-quite-full -big blocks. +Attempt to defragment and free space for reuse by reblocking a live +HAMMER filesystem. +Big blocks cannot be reused by HAMMER until they are completely free. +This command also has the effect of reordering all elements, effectively +defragmenting the filesystem. .Pp -If unspecified a fill percentage of 90% is used. B-Tree elements and data, -or B-Tree elements and inodes can be reblocked together or by separate -invocations. -Generally speaking it is better to reblock them with separate invocations. -In HAMMER, inodes and data are in separate localization domains and will -be independently reblocked. +The default fill percentage is 100% and will cause the filesystem to be +completely defragmented. All specified element types will be reallocated +and rewritten. If you wish to quickly free up space instead try specifying +a smaller fill percentage, such as 90% or 80% (the '%' suffix is not needed). .Pp -A HAMMER filesystem can be defragmented by specifying a fill percentage -of 100%. Since this can potentially rewrite the entire contents of the -disk it is best to do it incrementally from a cron job with a timeout -option set. The filesystem would thus be defragmented over long period -of time. +Since this command may rewrite the entire contents of the disk it is +best to do it incrementally from a cron job along with the +.Fl c Ar cyclefile +and +.Fl t Ar timeout +options to limit the run time. +The filesystem would thus be defragmented over long period of time. +.Pp +It is recommended that separate invocations be used for each data type. +Btree nodes, inodes, and directories are typically the most important +elements needing defragmentation. Data can be defragmented over a longer +period of time. .El .Sh EXAMPLES .Sh DIAGNOSTICS diff --git a/sbin/hammer/hammer.c b/sbin/hammer/hammer.c index 9ef610d9ec..f56e4180ed 100644 --- a/sbin/hammer/hammer.c +++ b/sbin/hammer/hammer.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/hammer.c,v 1.20 2008/05/31 18:45:04 dillon Exp $ + * $DragonFly: src/sbin/hammer/hammer.c,v 1.21 2008/06/14 01:44:11 dillon Exp $ */ #include "hammer.h" @@ -186,6 +186,8 @@ main(int ac, char **av) hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_BTREE); else if (strcmp(av[0], "reblock-inodes") == 0) hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_INODES); + else if (strcmp(av[0], "reblock-dirs") == 0) + hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_DIRS); else if (strcmp(av[0], "reblock-data") == 0) hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_DATA); else diff --git a/sbin/hammer/misc.c b/sbin/hammer/misc.c index 6871d18006..5e1ab690fc 100644 --- a/sbin/hammer/misc.c +++ b/sbin/hammer/misc.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/misc.c,v 1.3 2008/02/05 07:58:40 dillon Exp $ + * $DragonFly: src/sbin/hammer/misc.c,v 1.4 2008/06/14 01:44:11 dillon Exp $ */ #include "hammer.h" @@ -50,6 +50,11 @@ int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2) { + if (key1->localization < key2->localization) + return(-5); + if (key1->localization > key2->localization) + return(5); + if (key1->obj_id < key2->obj_id) return(-4); if (key1->obj_id > key2->obj_id) diff --git a/sbin/newfs_hammer/newfs_hammer.c b/sbin/newfs_hammer/newfs_hammer.c index 1a3c2d7541..d109b4e298 100644 --- a/sbin/newfs_hammer/newfs_hammer.c +++ b/sbin/newfs_hammer/newfs_hammer.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/newfs_hammer/newfs_hammer.c,v 1.29 2008/06/08 17:19:09 dillon Exp $ + * $DragonFly: src/sbin/newfs_hammer/newfs_hammer.c,v 1.30 2008/06/14 01:44:13 dillon Exp $ */ #include "newfs_hammer.h" @@ -172,6 +172,9 @@ main(int ac, char **av) printf("Initializing B-Tree blockmap\n"); presize_blockmap(&vol->ondisk->vol0_blockmap[HAMMER_ZONE_BTREE_INDEX], HAMMER_ZONE_BTREE, vol0_zone_limit); + printf("Initializing Meta-data blockmap\n"); + presize_blockmap(&vol->ondisk->vol0_blockmap[HAMMER_ZONE_META_INDEX], + HAMMER_ZONE_META, vol0_zone_limit); printf("Initializing Large-Data blockmap\n"); presize_blockmap(&vol->ondisk->vol0_blockmap[HAMMER_ZONE_LARGE_DATA_INDEX], HAMMER_ZONE_LARGE_DATA, vol0_zone_limit); @@ -452,11 +455,9 @@ format_volume(struct volume_info *vol, int nvols, const char *label, format_blockmap( &ondisk->vol0_blockmap[HAMMER_ZONE_BTREE_INDEX], HAMMER_ZONE_BTREE); -#if 0 format_blockmap( - &ondisk->vol0_blockmap[HAMMER_ZONE_RECORD_INDEX], - HAMMER_ZONE_RECORD); -#endif + &ondisk->vol0_blockmap[HAMMER_ZONE_META_INDEX], + HAMMER_ZONE_META); format_blockmap( &ondisk->vol0_blockmap[HAMMER_ZONE_LARGE_DATA_INDEX], HAMMER_ZONE_LARGE_DATA); -- 2.11.4.GIT