]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Update data offset format and warn about the previous one.
authorGabriel <g2p.code@gmail.com>
Sat, 9 Mar 2013 13:58:57 +0000 (14:58 +0100)
committerKent Overstreet <koverstreet@google.com>
Mon, 15 Apr 2013 19:48:39 +0000 (12:48 -0700)
Also update the macro to select a bdev.
Also reindent.

bcache-super-show.c
bcache.h
make-bcache.c

index 67f141ebea34e31a3c235914f52b41b13c960f33..04e27268ee1979249d379bd194a4a2be4b147370 100644 (file)
@@ -60,13 +60,13 @@ int main(int argc, char **argv)
                exit(2);
        }
 
-       if (pread(fd, &sb, sizeof(sb), 4096) != sizeof(sb)) {
+       if (pread(fd, &sb, sizeof(sb), SB_START) != sizeof(sb)) {
                fprintf(stderr, "Couldn't read\n");
                exit(2);
        }
 
        printf("sb.magic\t\t");
-       if (! memcmp(sb.magic, bcache_magic, 16)) {
+       if (!memcmp(sb.magic, bcache_magic, 16)) {
                printf("ok\n");
        } else {
                printf("bad magic\n");
@@ -89,7 +89,7 @@ int main(int argc, char **argv)
                printf(" [match]\n");
        } else {
                printf(" [expected %" PRIX64 "]\n", expected_csum);
-               if (! force_csum) {
+               if (!force_csum) {
                        fprintf(stderr, "Corrupt superblock (bad csum)\n");
                        exit(2);
                }
@@ -97,16 +97,22 @@ int main(int argc, char **argv)
 
        printf("sb.version\t\t%" PRIu64, sb.version);
        switch (sb.version) {
-               case 0:
+               case BCACHE_SB_VERSION_CDEV:
                        printf(" [cache device]\n");
                        break;
 
-               // SB_BDEV macro says bdev iff version is odd; only 0 and 1
-               // seem to be fully implemented however.
-               case CACHE_BACKING_DEV: // 1
+               case BCACHE_SB_VERSION_CDEV_WITH_UUID:
+                       printf(" [cache device (new UUID format)]\n");
+                       break;
+
+               case BCACHE_SB_VERSION_BDEV:
                        printf(" [backing device]\n");
                        break;
 
+               case BCACHE_SB_VERSION_BDEV_WITH_OFFSET:
+                       printf(" [backing device with data offset]\n");
+                       break;
+
                default:
                        printf(" [unknown]\n");
                        // exit code?
@@ -118,30 +124,36 @@ int main(int argc, char **argv)
        uuid_unparse(sb.uuid, uuid);
        printf("dev.uuid\t\t%s\n", uuid);
 
-       printf(
-                       "dev.sectors_per_block\t%u\n"
-                       "dev.sectors_per_bucket\t%u\n"
-                       "dev.bucket_count\t%ju\n"
-                       "dev.cache_count\t\t%u\n", // expect version == 0 ? 1 : 0
-                       sb.block_size,
-                       sb.bucket_size,
-                       sb.nbuckets,
-                       sb.nr_this_dev);
-
-       if (sb.version == 0) {
-               printf(
-                               "dev.cache.first_bucket\t%u\n"
-                               "dev.cache.first_sector\t%u\n"
-                               "dev.cache.discard\t%s\n",
-                               sb.first_bucket,
-                               sb.bucket_size * sb.first_bucket,
-                               CACHE_DISCARD(&sb) ? "yes" : "no");
-       } else if (sb.version == CACHE_BACKING_DEV) {
-               printf(
-                               "dev.data.first_sector\t%u\n"
-                               "dev.data.writeback\t%s\n",
-                               BDEV_DATA_START,
-                               BDEV_WRITEBACK(&sb) ? "yes" : "no");
+       printf("dev.sectors_per_block\t%u\n"
+              "dev.sectors_per_bucket\t%u\n"
+              "dev.bucket_count\t%ju\n"
+              "dev.cache_count\t\t%u\n", // expect SB_IS_BDEV(&sb) ? 0 : 1
+              sb.block_size,
+              sb.bucket_size,
+              sb.nbuckets,
+              sb.nr_this_dev);
+
+       if (!SB_IS_BDEV(&sb)) {
+               printf("dev.cache.first_bucket\t%u\n"
+                      "dev.cache.first_sector\t%u\n"
+                      "dev.cache.discard\t%s\n",
+                      sb.first_bucket,
+                      sb.bucket_size * sb.first_bucket,
+                      CACHE_DISCARD(&sb) ? "yes" : "no");
+       } else if (sb.version == BCACHE_SB_VERSION_BDEV) {
+               printf("dev.data.first_sector\t%u\n"
+                      "dev.data.writeback\t%s\n",
+                      BDEV_DATA_START_DEFAULT,
+                      BDEV_WRITEBACK(&sb) ? "yes" : "no");
+       } else if (sb.version == BCACHE_SB_VERSION_BDEV_WITH_OFFSET) {
+               if (sb.keys == 1 || sb.d[0]) {
+                       fprintf(stderr, "Possible experimental format detected, bailing\n");
+                       exit(3);
+               }
+               printf("dev.data.first_sector\t%lu\n"
+                      "dev.data.writeback\t%s\n",
+                      sb.data_offset,
+                      BDEV_WRITEBACK(&sb) ? "yes" : "no");
        }
        putchar('\n');
 
index 25e3047f4bf300c75a598365b35ce9495bdc4899..bd8712102ed2095015e5e0167e12ebd96da32dde 100644 (file)
--- a/bcache.h
+++ b/bcache.h
@@ -32,6 +32,7 @@ static const char bcache_magic[] = {
 #define SB_LABEL_SIZE          32
 #define SB_JOURNAL_BUCKETS     256U
 #define BDEV_DATA_START_DEFAULT        16      /* sectors */
+#define SB_START               (SB_SECTOR * 512)
 
 struct cache_sb {
        uint64_t                csum;
@@ -84,7 +85,11 @@ struct cache_sb {
        uint64_t                d[SB_JOURNAL_BUCKETS];  /* journal buckets */
 };
 
-BITMASK(SB_BDEV,       struct cache_sb, version, 0, 1);
+static inline bool SB_IS_BDEV(const struct cache_sb *sb)
+{
+       return sb->version == BCACHE_SB_VERSION_BDEV
+               || sb->version == BCACHE_SB_VERSION_BDEV_WITH_OFFSET;
+}
 
 BITMASK(BDEV_WRITEBACK,        struct cache_sb, flags, 0, 1);
 
index 1c5d3e6bed0bc7aa3746d0c09480e68d4cc242bc..fbf547f83af2f99f9cf7ab9c6b3398c3652d5ae9 100644 (file)
@@ -185,7 +185,7 @@ static void write_sb(char *dev, unsigned block_size, unsigned bucket_size,
        uuid_unparse(sb.uuid, uuid_str);
        uuid_unparse(sb.set_uuid, set_uuid_str);
 
-       if (SB_BDEV(&sb)) {
+       if (SB_IS_BDEV(&sb)) {
                SET_BDEV_WRITEBACK(&sb, writeback);
 
                if (data_offset != BDEV_DATA_START_DEFAULT) {