summaryrefslogtreecommitdiffstats
path: root/sys/geom/mirror
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2005-02-27 23:07:47 +0000
committerpjd <pjd@FreeBSD.org>2005-02-27 23:07:47 +0000
commit668a0286708d7bde5d5f9e9076fa8ffe8ec62f34 (patch)
treef9b8b8d23d31087c21fbc78a229ae7d39ac1bfb1 /sys/geom/mirror
parenta8b71d95fab6042a43dfe6aa45b43537a7eb00ba (diff)
downloadFreeBSD-src-668a0286708d7bde5d5f9e9076fa8ffe8ec62f34.zip
FreeBSD-src-668a0286708d7bde5d5f9e9076fa8ffe8ec62f34.tar.gz
- Add md_provsize field to metadata, which will help with
shared-last-sector problem. After this change, even if there is more than one provider with the same last sector, the proper one will be chosen based on its size. It still doesn't fix the 'c' partition problem (when da0s1 can be confused with da0s1c) and situation when 'a' partition starts at offset 0 (then da0s1a can be confused with da0s1 and da0s1c). One can use '-h' option there, when creating device or avoid sharing last sector. Actually, when providers share the same last sector and their size is equal, they provide exactly the same data, so the name (da0s1, da0s1a, da0s1c) isn't important at all. - Provide backward compatibility. - Update copyright's year. MFC after: 1 week
Diffstat (limited to 'sys/geom/mirror')
-rw-r--r--sys/geom/mirror/g_mirror.c4
-rw-r--r--sys/geom/mirror/g_mirror.h47
2 files changed, 48 insertions, 3 deletions
diff --git a/sys/geom/mirror/g_mirror.c b/sys/geom/mirror/g_mirror.c
index 45b480a..71456b4 100644
--- a/sys/geom/mirror/g_mirror.c
+++ b/sys/geom/mirror/g_mirror.c
@@ -669,6 +669,7 @@ g_mirror_fill_metadata(struct g_mirror_softc *sc, struct g_mirror_disk *disk,
md->md_syncid = 0;
md->md_dflags = 0;
md->md_sync_offset = 0;
+ md->md_provsize = 0;
} else {
md->md_did = disk->d_id;
md->md_priority = disk->d_priority;
@@ -683,6 +684,7 @@ g_mirror_fill_metadata(struct g_mirror_softc *sc, struct g_mirror_disk *disk,
disk->d_consumer->provider->name,
sizeof(md->md_provider));
}
+ md->md_provsize = disk->d_consumer->provider->mediasize;
}
}
@@ -2646,6 +2648,8 @@ g_mirror_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
if (md.md_provider[0] != '\0' && strcmp(md.md_provider, pp->name) != 0)
return (NULL);
+ if (md.md_provsize != 0 && md.md_provsize != pp->mediasize)
+ return (NULL);
if ((md.md_dflags & G_MIRROR_DISK_FLAG_INACTIVE) != 0) {
G_MIRROR_DEBUG(0,
"Device %s: provider %s marked as inactive, skipping.",
diff --git a/sys/geom/mirror/g_mirror.h b/sys/geom/mirror/g_mirror.h
index 64a8f98..03827ea 100644
--- a/sys/geom/mirror/g_mirror.h
+++ b/sys/geom/mirror/g_mirror.h
@@ -40,8 +40,9 @@
* 0 - Initial version number.
* 1 - Added 'prefer' balance algorithm.
* 2 - Added md_genid field to metadata.
+ * 3 - Added md_provsize field to metadata.
*/
-#define G_MIRROR_VERSION 2
+#define G_MIRROR_VERSION 3
#define G_MIRROR_BALANCE_NONE 0
#define G_MIRROR_BALANCE_ROUND_ROBIN 1
@@ -226,6 +227,7 @@ struct g_mirror_metadata {
uint64_t md_mflags; /* Additional mirror flags. */
uint64_t md_dflags; /* Additional disk flags. */
char md_provider[16]; /* Hardcoded provider. */
+ uint64_t md_provsize; /* Provider's size. */
u_char md_hash[16]; /* MD5 hash. */
};
static __inline void
@@ -250,10 +252,11 @@ mirror_metadata_encode(struct g_mirror_metadata *md, u_char *data)
le64enc(data + 79, md->md_mflags);
le64enc(data + 87, md->md_dflags);
bcopy(md->md_provider, data + 95, 16);
+ le64enc(data + 111, md->md_provsize);
MD5Init(&ctx);
- MD5Update(&ctx, data, 111);
+ MD5Update(&ctx, data, 119);
MD5Final(md->md_hash, &ctx);
- bcopy(md->md_hash, data + 111, 16);
+ bcopy(md->md_hash, data + 119, 16);
}
static __inline int
mirror_metadata_decode_v0v1(const u_char *data, struct g_mirror_metadata *md)
@@ -283,6 +286,7 @@ mirror_metadata_decode_v0v1(const u_char *data, struct g_mirror_metadata *md)
/* New fields. */
md->md_genid = 0;
+ md->md_provsize = 0;
return (0);
}
@@ -312,6 +316,39 @@ mirror_metadata_decode_v2(const u_char *data, struct g_mirror_metadata *md)
MD5Final(md->md_hash, &ctx);
if (bcmp(md->md_hash, data + 111, 16) != 0)
return (EINVAL);
+
+ /* New fields. */
+ md->md_provsize = 0;
+
+ return (0);
+}
+static __inline int
+mirror_metadata_decode_v3(const u_char *data, struct g_mirror_metadata *md)
+{
+ MD5_CTX ctx;
+
+ bcopy(data + 20, md->md_name, 16);
+ md->md_mid = le32dec(data + 36);
+ md->md_did = le32dec(data + 40);
+ md->md_all = *(data + 44);
+ md->md_genid = le32dec(data + 45);
+ md->md_syncid = le32dec(data + 49);
+ md->md_priority = *(data + 53);
+ md->md_slice = le32dec(data + 54);
+ md->md_balance = *(data + 58);
+ md->md_mediasize = le64dec(data + 59);
+ md->md_sectorsize = le32dec(data + 67);
+ md->md_sync_offset = le64dec(data + 71);
+ md->md_mflags = le64dec(data + 79);
+ md->md_dflags = le64dec(data + 87);
+ bcopy(data + 95, md->md_provider, 16);
+ md->md_provsize = le64dec(data + 111);
+ bcopy(data + 119, md->md_hash, 16);
+ MD5Init(&ctx);
+ MD5Update(&ctx, data, 119);
+ MD5Final(md->md_hash, &ctx);
+ if (bcmp(md->md_hash, data + 119, 16) != 0)
+ return (EINVAL);
return (0);
}
static __inline int
@@ -329,6 +366,9 @@ mirror_metadata_decode(const u_char *data, struct g_mirror_metadata *md)
case 2:
error = mirror_metadata_decode_v2(data, md);
break;
+ case 3:
+ error = mirror_metadata_decode_v3(data, md);
+ break;
default:
error = EINVAL;
break;
@@ -417,6 +457,7 @@ mirror_metadata_dump(const struct g_mirror_metadata *md)
}
printf("\n");
printf("hcprovider: %s\n", md->md_provider);
+ printf(" provsize: %ju\n", (uintmax_t)md->md_provsize);
bzero(hash, sizeof(hash));
for (i = 0; i < 16; i++) {
hash[i * 2] = hex[md->md_hash[i] >> 4];
OpenPOWER on IntegriCloud