HAMMER VFS - Add workaround to HAMMERIOC_GET_SNAPSHOT for bad conversions
authorMatthew Dillon <dillon@apollo.backplane.com>
Mon, 11 Jan 2010 00:02:58 +0000 (16:02 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Mon, 11 Jan 2010 00:15:21 +0000 (16:15 -0800)
* When hammer cleanup converts to a hammer v3 snapshot a bad record
  can sometimes be created.  This record is not harmful in anyway.

* However when listing available snapshots correct the tid field in the
  bad record so it can be deleted.

sys/vfs/hammer/hammer_ioctl.c

index 2e039f0..7d68e13 100644 (file)
@@ -822,9 +822,32 @@ hammer_ioc_get_snapshot(hammer_transaction_t trans, hammer_inode_t ip,
                if (error)
                        break;
                if (cursor.leaf->base.rec_type == HAMMER_RECTYPE_SNAPSHOT) {
-                       error = hammer_btree_extract(&cursor, HAMMER_CURSOR_GET_LEAF |
-                                                             HAMMER_CURSOR_GET_DATA);
+                       error = hammer_btree_extract(
+                                            &cursor, HAMMER_CURSOR_GET_LEAF |
+                                                     HAMMER_CURSOR_GET_DATA);
                        snap->snaps[snap->count] = cursor.data->snap;
+
+                       /*
+                        * The snap data tid should match the key but might
+                        * not due to a bug in the HAMMER v3 conversion code.
+                        *
+                        * This error will work itself out over time but we
+                        * have to force a match or the snapshot will not
+                        * be deletable.
+                        */
+                       if (cursor.data->snap.tid !=
+                           (hammer_tid_t)cursor.leaf->base.key) {
+                               kprintf("HAMMER: lo=%08x snapshot key "
+                                       "0x%016jx data mismatch 0x%016jx\n",
+                                       cursor.key_beg.localization,
+                                       (uintmax_t)cursor.data->snap.tid,
+                                       cursor.leaf->base.key);
+                               kprintf("HAMMER: Probably left over from the "
+                                       "original v3 conversion, hammer "
+                                       "cleanup should get it eventually\n");
+                               snap->snaps[snap->count].tid =
+                                       cursor.leaf->base.key;
+                       }
                        ++snap->count;
                }
                error = hammer_btree_iterate(&cursor);