HAMMER 42E/Many: Cleanup.
authorMatthew Dillon <dillon@dragonflybsd.org>
Mon, 12 May 2008 05:13:11 +0000 (05:13 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Mon, 12 May 2008 05:13:11 +0000 (05:13 +0000)
* Finish cleaning up the pruning and reblocking code.  The reblocking
  code still does not handle internal B-Tree nodes, though.

* Add options to allow the B-Tree, records, and data to be reblocked
  independantly of each other.

sys/vfs/hammer/hammer_btree.c
sys/vfs/hammer/hammer_ioctl.c
sys/vfs/hammer/hammer_ioctl.h
sys/vfs/hammer/hammer_reblock.c

index 61603f1..93f3176 100644 (file)
@@ -31,7 +31,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sys/vfs/hammer/hammer_btree.c,v 1.44 2008/05/06 00:21:07 dillon Exp $
+ * $DragonFly: src/sys/vfs/hammer/hammer_btree.c,v 1.45 2008/05/12 05:13:11 dillon Exp $
  */
 
 /*
@@ -548,6 +548,9 @@ hammer_btree_first(hammer_cursor_t cursor)
 
 /*
  * Similarly but for an iteration in the reverse direction.
+ *
+ * Set ATEDISK when iterating backwards to skip the current entry,
+ * which after an ENOENT lookup will be pointing beyond our end point.
  */
 int
 hammer_btree_last(hammer_cursor_t cursor)
@@ -561,7 +564,7 @@ hammer_btree_last(hammer_cursor_t cursor)
        cursor->key_beg = save;
        if (error == ENOENT ||
            (cursor->flags & HAMMER_CURSOR_END_INCLUSIVE) == 0) {
-               cursor->flags &= ~HAMMER_CURSOR_ATEDISK;
+               cursor->flags |= HAMMER_CURSOR_ATEDISK;
                error = hammer_btree_iterate_reverse(cursor);
        }
        cursor->flags |= HAMMER_CURSOR_ATEDISK;
index d55d626..0eb7c87 100644 (file)
@@ -31,7 +31,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sys/vfs/hammer/hammer_ioctl.c,v 1.15 2008/05/11 21:45:44 dillon Exp $
+ * $DragonFly: src/sys/vfs/hammer/hammer_ioctl.c,v 1.16 2008/05/12 05:13:11 dillon Exp $
  */
 
 #include "hammer.h"
@@ -106,6 +106,9 @@ hammer_ioc_prune(hammer_transaction_t trans, hammer_inode_t ip,
        if ((prune->head.flags & HAMMER_IOC_PRUNE_ALL) && prune->nelms)
                return(EINVAL);
 
+       prune->cur_obj_id = cursor.key_end.obj_id;
+       prune->cur_key = HAMMER_MAX_KEY;
+
 retry:
        error = hammer_init_cursor(trans, &cursor, NULL, NULL);
        if (error) {
@@ -119,8 +122,8 @@ retry:
        cursor.key_beg.rec_type = HAMMER_MIN_RECTYPE;
        cursor.key_beg.obj_type = 0;
 
-       cursor.key_end.obj_id = prune->end_obj_id;
-       cursor.key_end.key = HAMMER_MAX_KEY;
+       cursor.key_end.obj_id = prune->cur_obj_id;
+       cursor.key_end.key = prune->cur_key;
        cursor.key_end.create_tid = HAMMER_MAX_TID - 1;
        cursor.key_end.delete_tid = 0;
        cursor.key_end.rec_type = HAMMER_MAX_RECTYPE;
@@ -129,9 +132,6 @@ retry:
        cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE;
        cursor.flags |= HAMMER_CURSOR_BACKEND;
 
-       prune->cur_obj_id = cursor.key_end.obj_id;
-       prune->cur_key = cursor.key_end.key;
-
        error = hammer_btree_last(&cursor);
        while (error == 0) {
                elm = &cursor.node->ondisk->elms[cursor.index];
index 2254cc9..1ee5b9c 100644 (file)
@@ -31,7 +31,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sys/vfs/hammer/hammer_ioctl.h,v 1.6 2008/05/05 20:34:47 dillon Exp $
+ * $DragonFly: src/sys/vfs/hammer/hammer_ioctl.h,v 1.7 2008/05/12 05:13:11 dillon Exp $
  */
 /*
  * HAMMER ioctl's.  This file can be #included from userland
@@ -56,6 +56,12 @@ struct hammer_ioc_head {
 };
 
 #define HAMMER_IOC_HEAD_INTR   0x00010000
+#define HAMMER_IOC_DO_BTREE    0x00020000      /* reblocker */
+#define HAMMER_IOC_DO_RECS     0x00040000      /* reblocker */
+#define HAMMER_IOC_DO_DATA     0x00080000      /* reblocker */
+
+#define HAMMER_IOC_DO_FLAGS    (HAMMER_IOC_DO_BTREE | HAMMER_IOC_DO_RECS | \
+                                HAMMER_IOC_DO_DATA)
 
 /*
  * HAMMERIOC_PRUNE
index e844f22..8fa5f76 100644 (file)
@@ -31,7 +31,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sys/vfs/hammer/hammer_reblock.c,v 1.12 2008/05/10 19:52:38 dillon Exp $
+ * $DragonFly: src/sys/vfs/hammer/hammer_reblock.c,v 1.13 2008/05/12 05:13:11 dillon Exp $
  */
 /*
  * HAMMER reblocker - This code frees up fragmented physical space
@@ -68,6 +68,8 @@ hammer_ioc_reblock(hammer_transaction_t trans, hammer_inode_t ip,
        if (reblock->free_level < 0)
                return(EINVAL);
 
+       reblock->cur_obj_id = reblock->beg_obj_id;
+
 retry:
        error = hammer_init_cursor(trans, &cursor, NULL, NULL);
        if (error) {
@@ -159,12 +161,13 @@ hammer_reblock_helper(struct hammer_ioc_reblock *reblock,
        tmp_offset = elm->leaf.data_offset;
        zone = HAMMER_ZONE_DECODE(tmp_offset);          /* can be 0 */
        if ((zone == HAMMER_ZONE_SMALL_DATA_INDEX ||
-            zone == HAMMER_ZONE_LARGE_DATA_INDEX) && error == 0) {
+            zone == HAMMER_ZONE_LARGE_DATA_INDEX) &&
+           error == 0 && (reblock->head.flags & HAMMER_IOC_DO_DATA)) {
                ++reblock->data_count;
                reblock->data_byte_count += elm->leaf.data_len;
                bytes = hammer_blockmap_getfree(cursor->trans->hmp, tmp_offset,
                                                &cur, &error);
-               if (error == 0 && cur == 0 && bytes > reblock->free_level) {
+               if (error == 0 && cur == 0 && bytes >= reblock->free_level) {
                        if (hammer_debug_general & 0x4000)
                                kprintf("%6d ", bytes);
                        error = hammer_cursor_upgrade(cursor);
@@ -184,11 +187,12 @@ hammer_reblock_helper(struct hammer_ioc_reblock *reblock,
         */
        tmp_offset = elm->leaf.rec_offset;
        zone = HAMMER_ZONE_DECODE(tmp_offset);
-       if (zone == HAMMER_ZONE_RECORD_INDEX && error == 0) {
+       if (zone == HAMMER_ZONE_RECORD_INDEX &&
+           error == 0 && (reblock->head.flags & HAMMER_IOC_DO_RECS)) {
                ++reblock->record_count;
                bytes = hammer_blockmap_getfree(cursor->trans->hmp, tmp_offset,
                                                &cur, &error);
-               if (error == 0 && cur == 0 && bytes > reblock->free_level) {
+               if (error == 0 && cur == 0 && bytes >= reblock->free_level) {
                        if (hammer_debug_general & 0x4000)
                                kprintf("%6d ", bytes);
                        error = hammer_cursor_upgrade(cursor);
@@ -208,12 +212,12 @@ hammer_reblock_helper(struct hammer_ioc_reblock *reblock,
         */
        tmp_offset = cursor->node->node_offset;
        zone = HAMMER_ZONE_DECODE(tmp_offset);
-       if (zone == HAMMER_ZONE_BTREE_INDEX && error == 0 &&
-           cursor->index == 0) {
+       if (zone == HAMMER_ZONE_BTREE_INDEX && cursor->index == 0 &&
+           error == 0 && (reblock->head.flags & HAMMER_IOC_DO_BTREE)) {
                ++reblock->btree_count;
                bytes = hammer_blockmap_getfree(cursor->trans->hmp, tmp_offset,
                                                &cur, &error);
-               if (error == 0 && cur == 0 && bytes > reblock->free_level) {
+               if (error == 0 && cur == 0 && bytes >= reblock->free_level) {
                        if (hammer_debug_general & 0x4000)
                                kprintf("%6d ", bytes);
                        error = hammer_cursor_upgrade(cursor);