HAMMER Utilities: Feature add
authorMatthew Dillon <dillon@dragonflybsd.org>
Mon, 5 May 2008 20:34:52 +0000 (20:34 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Mon, 5 May 2008 20:34:52 +0000 (20:34 +0000)
* Check record crc and signature in extra-verbose mode

* Adjustments for structural changes

* Generate proper CRCs for structures laid down by newfs_hammer

sbin/hammer/cmd_history.c
sbin/hammer/cmd_prune.c
sbin/hammer/cmd_reblock.c
sbin/hammer/cmd_show.c
sbin/hammer/ondisk.c

index 264e560..e9b55ba 100644 (file)
@@ -31,7 +31,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sbin/hammer/cmd_history.c,v 1.1 2008/02/04 08:34:22 dillon Exp $
+ * $DragonFly: src/sbin/hammer/cmd_history.c,v 1.2 2008/05/05 20:34:52 dillon Exp $
  */
 
 #include "hammer.h"
@@ -82,7 +82,7 @@ hammer_do_history(const char *path, off_t off, int len)
        hist.end_tid = HAMMER_MAX_TID;
 
        if (off >= 0) {
-               hist.flags |= HAMMER_IOC_HISTORY_ATKEY;
+               hist.head.flags |= HAMMER_IOC_HISTORY_ATKEY;
                hist.key = off;
                hist.nxt_key = off + 1;
        }
@@ -93,7 +93,7 @@ hammer_do_history(const char *path, off_t off, int len)
                close(fd);
                return;
        }
-       status = ((hist.flags & HAMMER_IOC_HISTORY_UNSYNCED) ?
+       status = ((hist.head.flags & HAMMER_IOC_HISTORY_UNSYNCED) ?
                 "dirty" : "clean");
        printf("%016llx %s {\n", hist.obj_id, status);
        for (;;) {
@@ -136,11 +136,11 @@ hammer_do_history(const char *path, off_t off, int len)
                        printf("\n");
                        free(hist_path);
                }
-               if (hist.flags & HAMMER_IOC_HISTORY_EOF)
+               if (hist.head.flags & HAMMER_IOC_HISTORY_EOF)
                        break;
-               if (hist.flags & HAMMER_IOC_HISTORY_NEXT_KEY)
+               if (hist.head.flags & HAMMER_IOC_HISTORY_NEXT_KEY)
                        break;
-               if ((hist.flags & HAMMER_IOC_HISTORY_NEXT_TID) == 0)
+               if ((hist.head.flags & HAMMER_IOC_HISTORY_NEXT_TID) == 0)
                        break;
                hist.beg_tid = hist.nxt_tid;
                if (ioctl(fd, HAMMERIOC_GETHISTORY, &hist) < 0) {
index ac4199b..6cfb220 100644 (file)
@@ -31,7 +31,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sbin/hammer/Attic/cmd_prune.c,v 1.5 2008/05/04 19:18:17 dillon Exp $
+ * $DragonFly: src/sbin/hammer/Attic/cmd_prune.c,v 1.6 2008/05/05 20:34:52 dillon Exp $
  */
 
 #include "hammer.h"
@@ -66,8 +66,8 @@ hammer_cmd_prune(char **av, int ac)
        prune.nelms = 0;
        prune.beg_obj_id = HAMMER_MIN_OBJID;
        prune.end_obj_id = HAMMER_MAX_OBJID;
-       prune.cur_obj_id = prune.end_obj_id;    /* reverse scan */
-       prune.cur_key = HAMMER_MAX_KEY;
+       prune.cur_obj_id = prune.end_obj_id;    /* remove me */
+       prune.cur_key = HAMMER_MAX_KEY;         /* remove me */
        prune.stat_oldest_tid = HAMMER_MAX_TID;
 
        if (ac == 0)
@@ -81,7 +81,7 @@ hammer_cmd_prune(char **av, int ac)
                        prune_usage(1);
                hammer_prune_load_file(now_tid, &prune, filesystem, av[2]);
        } else if (strcmp(av[1], "everything") == 0) {
-               prune.flags |= HAMMER_IOC_PRUNE_ALL;
+               prune.head.flags |= HAMMER_IOC_PRUNE_ALL;
                if (ac > 2)
                        prune_usage(1);
        } else {
@@ -94,12 +94,11 @@ hammer_cmd_prune(char **av, int ac)
        if (fd < 0)
                err(1, "Unable to open %s", filesystem);
        if (ioctl(fd, HAMMERIOC_PRUNE, &prune) < 0) {
-               if (errno == EINTR) {
-                       printf("Prune %s interrupted by timer\n", filesystem);
-               } else {
-                       printf("Prune %s failed: %s\n",
-                              filesystem, strerror(errno));
-               }
+               printf("Prune %s failed: %s\n",
+                      filesystem, strerror(errno));
+       } else if (prune.head.flags & HAMMER_IOC_HEAD_INTR) {
+               printf("Prune %s interrupted by timer at %016llx\n",
+                      filesystem, prune.cur_obj_id);
        } else {
                printf("Prune %s succeeded\n", filesystem);
        }
@@ -381,6 +380,7 @@ prune_usage(int code)
 {
        fprintf(stderr, "Bad prune directive, specify one of:\n"
                        "prune filesystem [using filename]\n"
-                       "prune filesystem from <modulo_time> to <modulo_time> every <modulo_time>\n");
+                       "prune filesystem from <modulo_time> to <modulo_time> every <modulo_time>\n"
+                       "prune filesystem everything\n");
        exit(code);
 }
index c396c0a..42eb2de 100644 (file)
@@ -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.2 2008/05/04 19:18:17 dillon Exp $
+ * $DragonFly: src/sbin/hammer/cmd_reblock.c,v 1.3 2008/05/05 20:34:52 dillon Exp $
  */
 
 #include "hammer.h"
@@ -52,7 +52,6 @@ hammer_cmd_reblock(char **av, int ac)
        bzero(&reblock, sizeof(reblock));
        reblock.beg_obj_id = HAMMER_MIN_OBJID;
        reblock.end_obj_id = HAMMER_MAX_OBJID;
-       reblock.cur_obj_id = reblock.beg_obj_id;
 
        if (ac == 0)
                reblock_usage(1);
@@ -75,7 +74,8 @@ hammer_cmd_reblock(char **av, int ac)
                err(1, "Unable to open %s", filesystem);
        if (ioctl(fd, HAMMERIOC_REBLOCK, &reblock) < 0) {
                if (errno == EINTR) {
-                       printf("Reblock %s interrupted by timer\n", filesystem);
+                       printf("Reblock %s interrupted by timer at %016llx\n",
+                               filesystem, reblock.cur_obj_id);
                } else {
                        printf("Reblock %s failed: %s\n",
                               filesystem, strerror(errno));
index 9528e7d..4363667 100644 (file)
@@ -31,7 +31,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sbin/hammer/cmd_show.c,v 1.7 2008/05/04 19:18:17 dillon Exp $
+ * $DragonFly: src/sbin/hammer/cmd_show.c,v 1.8 2008/05/05 20:34:52 dillon Exp $
  */
 
 #include "hammer.h"
@@ -280,6 +280,7 @@ print_record(hammer_btree_elm_t elm)
        hammer_record_ondisk_t rec;
        hammer_off_t rec_offset;
        hammer_off_t data_offset;
+       hammer_crc_t crc;
        int32_t data_len;
        char *data;
 
@@ -295,17 +296,18 @@ print_record(hammer_btree_elm_t elm)
        else
                data = NULL;
 
-       printf("\n%17s", "");
        if (rec == NULL) {
                printf("record FAILED\n");
                return;
        }
        switch(rec->base.base.rec_type) {
        case HAMMER_RECTYPE_INODE:
+               printf("\n%17s", "");
                printf("size=%lld nlinks=%lld",
                       rec->inode.ino_size, rec->inode.ino_nlinks);
                break;
        case HAMMER_RECTYPE_DIRENTRY:
+               printf("\n%17s", "");
                printf("dir-entry ino=%016llx name=\"%*.*s\"",
                       rec->entry.obj_id,
                       data_len, data_len, data);
@@ -313,6 +315,7 @@ print_record(hammer_btree_elm_t elm)
        case HAMMER_RECTYPE_FIX:
                switch(rec->base.base.key) {
                case HAMMER_FIXKEY_SYMLINK:
+                       printf("\n%17s", "");
                        printf("symlink=\"%*.*s\"", data_len, data_len, data);
                        break;
                default:
@@ -322,6 +325,16 @@ print_record(hammer_btree_elm_t elm)
        default:
                break;
        }
+       if (rec->base.signature != HAMMER_RECORD_SIGNATURE_GOOD) {
+               printf("\n%17s", "");
+               printf("BAD SIGNATURE: %08x\n", rec->base.signature);
+       }
+       crc = crc32(&rec->base.rec_crc + 1, HAMMER_RECORD_CRCSIZE);
+       if (crc != rec->base.rec_crc) {
+               printf("\n%17s", "");
+               printf("BAD CRC: %08x v %08x\n", rec->base.rec_crc, crc);
+       }
+
        if (rec_buffer)
                rel_buffer(rec_buffer);
        if (data_buffer)
index 54fba33..0f0d12e 100644 (file)
@@ -31,7 +31,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sbin/hammer/ondisk.c,v 1.15 2008/04/27 00:43:55 dillon Exp $
+ * $DragonFly: src/sbin/hammer/ondisk.c,v 1.16 2008/05/05 20:34:52 dillon Exp $
  */
 
 #include <sys/types.h>
@@ -41,6 +41,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <unistd.h>
+#include <stddef.h>
 #include <err.h>
 #include <fcntl.h>
 #include "hammer_util.h"
@@ -352,7 +353,7 @@ format_freemap(struct volume_info *root_vol, hammer_blockmap_t blockmap)
                                         &buffer, isnew);
                bzero(layer1, sizeof(*layer1));
                layer1->phys_offset = HAMMER_BLOCKMAP_UNAVAIL;
-               layer1->layer1_crc = crc32(layer1, sizeof(*layer1));
+               layer1->layer1_crc = crc32(layer1, HAMMER_LAYER1_CRCSIZE);
        }
        rel_buffer(buffer);
 
@@ -361,7 +362,7 @@ format_freemap(struct volume_info *root_vol, hammer_blockmap_t blockmap)
        blockmap->alloc_offset = HAMMER_ENCODE_RAW_BUFFER(255, -1);
        blockmap->next_offset = HAMMER_ENCODE_RAW_BUFFER(0, 0);
        blockmap->reserved01 = 0;
-       blockmap->entry_crc = crc32(blockmap, sizeof(*blockmap));
+       blockmap->entry_crc = crc32(blockmap, HAMMER_BLOCKMAP_CRCSIZE);
        root_vol->cache.modified = 1;
 }
 
@@ -385,6 +386,7 @@ initialize_freemap(struct volume_info *vol)
        hammer_off_t phys_offset;
        hammer_off_t aligned_vol_free_end;
        int64_t count = 0;
+       int modified1 = 0;
 
        root_vol = get_volume(RootVolNo);
        aligned_vol_free_end = (vol->vol_free_end + HAMMER_BLOCKMAP_LAYER2_MASK)
@@ -409,6 +411,8 @@ initialize_freemap(struct volume_info *vol)
                        layer1->phys_offset = alloc_bigblock(vol, 0);
                        layer1->blocks_free = 0;
                        buffer1->cache.modified = 1;
+                       layer1->layer1_crc = crc32(layer1,
+                                                  HAMMER_LAYER1_CRCSIZE);
                }
        }
 
@@ -418,6 +422,7 @@ initialize_freemap(struct volume_info *vol)
        for (phys_offset = HAMMER_ENCODE_RAW_BUFFER(vol->vol_no, 0);
             phys_offset < aligned_vol_free_end;
             phys_offset += HAMMER_LARGEBLOCK_SIZE) {
+               modified1 = 0;
                layer1_offset = layer1_base +
                                HAMMER_BLOCKMAP_LAYER1_OFFSET(phys_offset);
                layer1 = get_buffer_data(layer1_offset, &buffer1, 0);
@@ -438,17 +443,19 @@ initialize_freemap(struct volume_info *vol)
                        buffer1->cache.modified = 1;
                        layer2->u.owner = HAMMER_BLOCKMAP_FREE;
                        ++count;
+                       modified1 = 1;
                } else {
                        layer2->u.owner = HAMMER_BLOCKMAP_UNAVAIL;
                }
-               layer2->entry_crc = crc32(layer2, sizeof(*layer2));
+               layer2->entry_crc = crc32(layer2, HAMMER_LAYER2_CRCSIZE);
                buffer2->cache.modified = 1;
 
                /*
                 * Finish-up layer 1
                 */
-               if (((phys_offset + HAMMER_LARGEBLOCK_SIZE) & HAMMER_BLOCKMAP_LAYER2_MASK) == 0) {
-                       layer1->layer1_crc = crc32(layer1, sizeof(*layer1));
+               if (modified1) {
+                       layer1->layer1_crc = crc32(layer1,
+                                                  HAMMER_LAYER1_CRCSIZE);
                        buffer1->cache.modified = 1;
                }
        }
@@ -495,14 +502,14 @@ alloc_bigblock(struct volume_info *volume, hammer_off_t owner)
                layer1 = get_buffer_data(layer_offset, &buffer, 0);
                assert(layer1->phys_offset != HAMMER_BLOCKMAP_UNAVAIL);
                --layer1->blocks_free;
-               layer1->layer1_crc = crc32(layer1, sizeof(*layer1));
+               layer1->layer1_crc = crc32(layer1, HAMMER_LAYER1_CRCSIZE);
                buffer->cache.modified = 1;
                layer_offset = layer1->phys_offset +
                               HAMMER_BLOCKMAP_LAYER2_OFFSET(result_offset);
                layer2 = get_buffer_data(layer_offset, &buffer, 0);
                assert(layer2->u.owner == HAMMER_BLOCKMAP_FREE);
                layer2->u.owner = owner;
-               layer2->entry_crc = crc32(layer2, sizeof(*layer2));
+               layer2->entry_crc = crc32(layer2, HAMMER_LAYER2_CRCSIZE);
                buffer->cache.modified = 1;
 
                rel_buffer(buffer);
@@ -550,8 +557,7 @@ format_undomap(hammer_volume_ondisk_t ondisk)
        blockmap->first_offset = HAMMER_ZONE_ENCODE(undo_zone, 0);
        blockmap->next_offset = blockmap->first_offset;
        blockmap->alloc_offset = HAMMER_ZONE_ENCODE(undo_zone, undo_limit);
-       
-       blockmap->entry_crc = crc32(blockmap, sizeof(*blockmap));
+       blockmap->entry_crc = crc32(blockmap, HAMMER_BLOCKMAP_CRCSIZE);
 
        layer2 = &ondisk->vol0_undo_array[0];
        n = 0;
@@ -563,7 +569,7 @@ format_undomap(hammer_volume_ondisk_t ondisk)
        for (n = 0; n < limit_index; ++n) {
                layer2->u.phys_offset = alloc_bigblock(NULL, scan);
                layer2->bytes_free = -1;        /* not used */
-               layer2->entry_crc = crc32(layer2, sizeof(*layer2));
+               layer2->entry_crc = crc32(layer2, HAMMER_LAYER2_CRCSIZE);
 
                scan += HAMMER_LARGEBLOCK_SIZE;
                ++layer2;
@@ -571,7 +577,7 @@ format_undomap(hammer_volume_ondisk_t ondisk)
        while (n < HAMMER_UNDO_LAYER2) {
                layer2->u.phys_offset = HAMMER_BLOCKMAP_UNAVAIL;
                layer2->bytes_free = -1;
-               layer2->entry_crc = crc32(layer2, sizeof(*layer2));
+               layer2->entry_crc = crc32(layer2, HAMMER_LAYER2_CRCSIZE);
                ++layer2;
                ++n;
        }
@@ -589,7 +595,7 @@ format_blockmap(hammer_blockmap_t blockmap, hammer_off_t zone_off)
        blockmap->alloc_offset = zone_off;
        blockmap->first_offset = zone_off;
        blockmap->next_offset = zone_off;
-       blockmap->entry_crc = crc32(blockmap, sizeof(*blockmap));
+       blockmap->entry_crc = crc32(blockmap, HAMMER_BLOCKMAP_CRCSIZE);
 }
 
 static
@@ -665,6 +671,10 @@ alloc_blockmap(int zone, int bytes, hammer_off_t *result_offp,
 
        bigblock_offset = layer2->u.phys_offset + 
                          (*result_offp & HAMMER_LARGEBLOCK_MASK);
+
+       layer1->layer1_crc = crc32(layer1, HAMMER_LAYER1_CRCSIZE);
+       layer2->entry_crc = crc32(layer2, HAMMER_LAYER2_CRCSIZE);
+
        ptr = get_buffer_data(bigblock_offset, bufferp, 0);
        (*bufferp)->cache.modified = 1;