Pre-2.0 release: Sync with HAMMER 64 - simplify PFS operations.
authorMatthew Dillon <dillon@dragonflybsd.org>
Sat, 19 Jul 2008 18:49:09 +0000 (19 18:49 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Sat, 19 Jul 2008 18:49:09 +0000 (19 18:49 +0000)
sbin/hammer/cmd_blockmap.c
sbin/hammer/cmd_mirror.c
sbin/hammer/cmd_pseudofs.c
sbin/hammer/hammer.8
sbin/mount_hammer/mount_hammer.8
sbin/mount_hammer/mount_hammer.c

index 24174ac..d3a1f8c 100644 (file)
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sbin/hammer/cmd_blockmap.c,v 1.3 2008/06/17 04:03:38 dillon Exp $
+ * $DragonFly: src/sbin/hammer/cmd_blockmap.c,v 1.3.2.1 2008/07/19 18:49:08 dillon Exp $
  */
 
 #include "hammer.h"
 
-#if 0
 static void dump_blockmap(const char *label, int zone);
-#endif
 
 void
 hammer_cmd_blockmap(void)
 {
+       dump_blockmap("btree", HAMMER_ZONE_FREEMAP_INDEX);
 #if 0
        dump_blockmap("btree", HAMMER_ZONE_BTREE_INDEX);
        dump_blockmap("meta", HAMMER_ZONE_META_INDEX);
@@ -51,7 +50,7 @@ hammer_cmd_blockmap(void)
 #endif
 }
 
-#if 0
+#if 1
 
 static
 void
@@ -68,7 +67,6 @@ dump_blockmap(const char *label, int zone)
        hammer_off_t scan1;
        hammer_off_t scan2;
 
-       assert(zone >= HAMMER_ZONE_BTREE_INDEX && zone < HAMMER_MAX_ZONES);
        assert(RootVolNo >= 0);
        root_volume = get_volume(RootVolNo);
        rootmap = &root_volume->ondisk->vol0_blockmap[zone];
@@ -78,21 +76,22 @@ dump_blockmap(const char *label, int zone)
                label, rootmap->next_offset, rootmap->alloc_offset);
 
        for (scan1 = HAMMER_ZONE_ENCODE(zone, 0);
-            scan1 < rootmap->alloc_offset;
-            scan1 += HAMMER_BLOCKMAP_LAYER1) {
+            scan1 < HAMMER_ZONE_ENCODE(zone, HAMMER_OFF_LONG_MASK);
+            scan1 += HAMMER_BLOCKMAP_LAYER2) {
                /*
                 * Dive layer 1.
                 */
                layer1_offset = rootmap->phys_offset +
                                HAMMER_BLOCKMAP_LAYER1_OFFSET(scan1);
                layer1 = get_buffer_data(layer1_offset, &buffer1, 0);
+               if (layer1->phys_offset == HAMMER_BLOCKMAP_UNAVAIL)
+                       continue;
                printf(" layer1 %016llx @%016llx blocks-free %lld\n",
                        scan1, layer1->phys_offset, layer1->blocks_free);
                if (layer1->phys_offset == HAMMER_BLOCKMAP_FREE)
                        continue;
                for (scan2 = scan1; 
-                    scan2 < scan1 + HAMMER_BLOCKMAP_LAYER1 &&
-                    scan2 < rootmap->alloc_offset;
+                    scan2 < scan1 + HAMMER_BLOCKMAP_LAYER2;
                     scan2 += HAMMER_LARGEBLOCK_SIZE
                ) {
                        /*
@@ -101,20 +100,11 @@ dump_blockmap(const char *label, int zone)
                        layer2_offset = layer1->phys_offset +
                                        HAMMER_BLOCKMAP_LAYER2_OFFSET(scan2);
                        layer2 = get_buffer_data(layer2_offset, &buffer2, 0);
-                       switch(layer2->u.phys_offset) {
-                       case HAMMER_BLOCKMAP_FREE:
-                               break;
-                       case HAMMER_BLOCKMAP_UNAVAIL:
-                               break;
-                       default:
-                               printf("        %016llx @%016llx "
-                                      "free %3d%% (%u)\n",
-                                      scan2, layer2->u.phys_offset,
-                                      layer2->bytes_free * 100 /
-                                       HAMMER_LARGEBLOCK_SIZE,
-                                      layer2->bytes_free);
-                               break;
-                       }
+                       printf("        %016llx zone=%d app=%-7d free=%-7d\n",
+                               scan2,
+                               layer2->zone,
+                               layer2->append_off,
+                               layer2->bytes_free);
                }
        }
        if (buffer1)
index 77dce88..cd74b87 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_mirror.c,v 1.9.2.1 2008/07/18 23:25:05 swildner Exp $
+ * $DragonFly: src/sbin/hammer/cmd_mirror.c,v 1.9.2.2 2008/07/19 18:49:08 dillon Exp $
  */
 
 #include "hammer.h"
@@ -341,6 +341,7 @@ hammer_cmd_mirror_write(char **av, int ac)
                fprintf(stderr, "Mirror-write %s: Did not get termination "
                                "sync record, or rec_size is wrong rt=%d\n",
                                filesystem, mrec->head.type);
+               exit(1);
        }
        free(mrec);
        mrec = NULL;
index 79d2be2..0990020 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_pseudofs.c,v 1.6 2008/07/12 02:48:46 dillon Exp $
+ * $DragonFly: src/sbin/hammer/cmd_pseudofs.c,v 1.6.2.1 2008/07/19 18:49:08 dillon Exp $
  */
 
 #include "hammer.h"
@@ -301,7 +301,7 @@ hammer_cmd_pseudofs_destroy(char **av, int ac)
         * RMR the PFS is basically destroyed even if someone ^C's it.
         */
        pfs.ondisk->mirror_flags |= HAMMER_PFSD_SLAVE;
-       pfs.ondisk->master_id = -1;
+       pfs.ondisk->reserved01 = -1;
        pfs.ondisk->sync_beg_tid = 1;
        pfs.ondisk->sync_end_tid = 1;
 
@@ -346,13 +346,6 @@ hammer_cmd_pseudofs_upgrade(char **av, int ac)
                                " (It should already be a master)\n");
                exit(1);
        }
-       if (pfs.ondisk->master_id == -1) {
-               fprintf(stderr, "You must configure a master id before "
-                               "upgrading a slave to a master.\n"
-                               "Use pfs-update ... master=<id> first.\n");
-               exit(1);
-       }
-
        if (ioctl(fd, HAMMERIOC_UPG_PSEUDOFS, &pfs) == 0) {
                printf("pfs-upgrade of PFS#%d (%s) succeeded\n",
                        pfs.pfs_id, pfs.ondisk->label);
@@ -436,12 +429,8 @@ init_pfsd(hammer_pseudofs_data_t pfsd, int is_slave)
        pfsd->sync_end_ts = 0;
        uuid_create(&pfsd->shared_uuid, &status);
        uuid_create(&pfsd->unique_uuid, &status);
-       if (is_slave) {
-               pfsd->master_id = -1;
+       if (is_slave)
                pfsd->mirror_flags |= HAMMER_PFSD_SLAVE;
-       } else {
-               pfsd->master_id = 0;
-       }
 }
 
 static
@@ -460,21 +449,11 @@ dump_pfsd(hammer_pseudofs_data_t pfsd)
        if (pfsd->mirror_flags & HAMMER_PFSD_SLAVE) {
                printf("    slave\n");
        }
-       if (pfsd->master_id < 0) {
-               if (pfsd->mirror_flags & HAMMER_PFSD_SLAVE) {
-                       printf("    master=-1 "
-                              "(no upgrade id assigned for slave)\n");
-               } else {
-                       printf("    no-mirror "
-                              "(mirror TID propagation disabled)\n");
-               }
-       } else {
-               printf("    master=%d", pfsd->master_id);
-               if (pfsd->mirror_flags & HAMMER_PFSD_SLAVE)
-                       printf(" (only if upgraded, currently a slave)");
-               printf("\n");
-       }
        printf("    label=\"%s\"\n", pfsd->label);
+       if (pfsd->mirror_flags & HAMMER_PFSD_SLAVE)
+               printf("    operating as a SLAVE\n");
+       else
+               printf("    operating as a MASTER\n");
 }
 
 static void
@@ -493,22 +472,11 @@ parse_pfsd_options(char **av, int ac, hammer_pseudofs_data_t pfsd)
                /*
                 * Basic assignment value test
                 */
-               if (strcmp(cmd, "no-mirror") == 0 ||
-                   strcmp(cmd, "slave") == 0) {
-                       if (ptr) {
-                               fprintf(stderr,
-                                       "option %s should not have "
-                                       "an assignment\n",
-                                       cmd);
-                               exit(1);
-                       }
-               } else {
-                       if (ptr == NULL) {
-                               fprintf(stderr,
-                                       "option %s requires an assignment\n",
-                                       cmd);
-                               exit(1);
-                       }
+               if (ptr == NULL) {
+                       fprintf(stderr,
+                               "option %s requires an assignment\n",
+                               cmd);
+                       exit(1);
                }
 
                status = uuid_s_ok;
@@ -520,31 +488,6 @@ parse_pfsd_options(char **av, int ac, hammer_pseudofs_data_t pfsd)
                        uuid_from_string(ptr, &pfsd->shared_uuid, &status);
                } else if (strcmp(cmd, "unique-uuid") == 0) {
                        uuid_from_string(ptr, &pfsd->unique_uuid, &status);
-               } else if (strcmp(cmd, "master") == 0) {
-                       if (pfsd->mirror_flags & HAMMER_PFSD_SLAVE) {
-                               printf("NOTE: This PFS is a slave, the master "
-                                      "id you are setting only applies\n"
-                                      "when you pfs-upgrade the PFS to "
-                                      "a master!\n");
-                       }
-                       pfsd->master_id = strtol(ptr, NULL, 0);
-               } else if (strcmp(cmd, "slave") == 0) {
-                       if ((pfsd->mirror_flags & HAMMER_PFSD_SLAVE) == 0) {
-                               fprintf(stderr,
-                                       "slave mode cannot be set on a master "
-                                       "PFS, use pfs-upgrade instead!\n");
-                               exit(1);
-                       }
-                       pfsd->mirror_flags |= HAMMER_PFSD_SLAVE;
-               } else if (strcmp(cmd, "no-mirror") == 0) {
-                       if (pfsd->mirror_flags & HAMMER_PFSD_SLAVE) {
-                               fprintf(stderr,
-                                       "no-mirror mode cannot be set on a "
-                                       "slave PFS\n");
-                               exit(1);
-                       }
-                       pfsd->master_id = -1;
-                       pfsd->mirror_flags &= ~HAMMER_PFSD_SLAVE;
                } else if (strcmp(cmd, "label") == 0) {
                        len = strlen(ptr);
                        if (ptr[0] == '"' && ptr[len-1] == '"') {
@@ -589,9 +532,6 @@ pseudofs_usage(int code)
                "    sync-end-tid=0x16llx\n"
                "    shared-uuid=0x16llx\n"
                "    unique-uuid=0x16llx\n"
-               "    master=0-15\n"
-               "    slave\n"
-               "    no-mirror\n"
                "    label=\"string\"\n"
        );
        exit(code);
index 1228ade..7f7cc3d 100644 (file)
@@ -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.38.2.1 2008/07/17 23:58:08 thomas Exp $
+.\" $DragonFly: src/sbin/hammer/hammer.8,v 1.38.2.2 2008/07/19 18:49:08 dillon Exp $
 .Dd July 16, 2008
 .Dt HAMMER 8
 .Os
@@ -313,8 +313,9 @@ A PFS can only be truly destroyed with the
 directive.
 Removing the softlink will not destroy the underlying PFS.
 .It Ar pfs-upgrade Ar dirpath
-Upgrade a PFS from slave to master operation.  The PFS becomes writable.
-A master id must already be assigned to the PFS.
+Upgrade a PFS from slave to master operation.  The PFS will be rolled back
+to the current end synchronization tid (removing any partial synchronizations),
+and will then becomes writable.
 .Pp
 WARNING!  HAMMER currently supports only single masters and using
 this command can easily result in filesystem corruption if you don't
@@ -370,29 +371,6 @@ to corruption of the mirroring target.
 .It unique-uuid=<uuid>
 Set the unique UUID for this filesystem.  This UUID should not be used
 anywhere else, even on exact copies of the filesystem.
-.It master=<num>
-Set the master id for multi-master mirroring.  Only values between 0 and 15
-inclusive may be specified.  All masters sharing the same
-.Ar shared-uuid
-must have different ids.
-Up to 16 masters will eventually be supported.
-.Pp
-Multi-master mirroring is not supported yet and the master id should be
-set to 0 on the single master when mirroring to one or more slaves.
-.Pp
-The master id may only be changed if the PFS is in master mode.  A PFS
-slave cannot be upgraded to a master at this time.
-.It no-mirror
-This disables the ability to use this filesystem as a mirroring source
-or target.  You can still do full scans with mirror-read but incremental
-scans will not work.  This option may only be set on masters.
-.It slave
-Sets slave mode, allowing the mirror to be used as a slave.  Except for
-the mirror-write directive all accesses to the mirror will be made read-only
-and will be as-of the
-.Ar sync-beg-tid .
-This option is currently not supported, slave mode must be specified
-when creating the PFS and cannot be changed on the fly.
 .It label=<string>
 Set a descriptive label for this filesystem.
 .El
index fc7667b..7ab263b 100644 (file)
@@ -30,7 +30,7 @@
 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\" 
-.\" $DragonFly: src/sbin/mount_hammer/mount_hammer.8,v 1.9.2.1 2008/07/17 23:54:06 thomas Exp $
+.\" $DragonFly: src/sbin/mount_hammer/mount_hammer.8,v 1.9.2.2 2008/07/19 18:49:09 dillon Exp $
 .Dd June 24, 2008
 .Dt MOUNT_HAMMER 8
 .Os
@@ -71,6 +71,19 @@ Put the entire filesystem in no-history mode.  Change history is not
 retained.
 Use of this option may increase the overhead of doing mirroring.
 This option is generally only used in an emergency.
+.It Ar master=<id>
+Assign a master id for the entire mount which applies to all PFSs under
+the mount.  This is intended to help support multi-master and fail-over
+operation.  Multi-master operation is not yet supported.  If you intend
+to upgrade slaves to masters and downgrade masters to slaves as part of
+a fail-over setup, it's a good idea to assign a different master id
+to the HAMMER mounts making up the fail-over group.
+.It Ar nomirror
+By default a HAMMER mount assigns a master id of 0.  You can force
+no-mirror operation by specifying this option.  This option disables
+mirror transaction id propagation in the B-Tree and will improve write
+performance somewhat but also prevents incremental mirroring from working
+at all, and is not recommended.
 .El
 .It Fl T Ar transaction-id
 Mount the filesystem as-of a particular
index f9119b7..1715faa 100644 (file)
@@ -31,7 +31,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sbin/mount_hammer/mount_hammer.c,v 1.7.2.1 2008/07/17 23:54:06 thomas Exp $
+ * $DragonFly: src/sbin/mount_hammer/mount_hammer.c,v 1.7.2.2 2008/07/19 18:49:09 dillon Exp $
  */
 
 #include <sys/types.h>
@@ -63,7 +63,9 @@ static void extract_volumes(ary_ptr_t *aryp, int *countp, char **av, int ac);
 #define MOPT_UPDATE         { "update",     0, MNT_UPDATE, 0 }
 
 #define MOPT_HAMMEROPTS                \
-       { "history", 1, HMNT_NOHISTORY, 1 }     \
+       { "history", 1, HMNT_NOHISTORY, 1 },    \
+       { "master=", 0, HMNT_MASTERID, 1 },     \
+       { "nomirror", 0, HMNT_MASTERID, 1 }
 
 static struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_HAMMEROPTS,
                                 MOPT_UPDATE, MOPT_NULL };
@@ -80,6 +82,7 @@ main(int ac, char **av)
        int ch;
        int init_flags = 0;
        char *mountpt;
+       char *ptr;
 
        bzero(&info, sizeof(info));
        info.asof = 0;
@@ -93,6 +96,25 @@ main(int ac, char **av)
                        break;
                case 'o':
                        getmntopts(optarg, mopts, &mount_flags, &info.hflags);
+
+
+                       /*
+                        * Handle extended flags with parameters.
+                        */
+                       if (info.hflags & HMNT_MASTERID) {
+                               ptr = strstr(optarg, "master=");
+                               if (ptr) {
+                                       info.master_id = strtol(ptr + 7, NULL, 0);
+                                       if (info.master_id == 0) {
+                                               fprintf(stderr,
+       "hammer_mount: Warning: a master id of 0 is the default, explicit\n"
+       "settings should probably use 1-15\n");
+                                       }
+                               }
+                               ptr = strstr(optarg, "nomirror");
+                               if (ptr)
+                                       info.master_id = -1;
+                       }
                        break;
                case 'u':
                        init_flags |= MNT_UPDATE;