[DRBD-cvs] r1693 - in trunk: . drbd user

svn at svn.drbd.org svn at svn.drbd.org
Tue Jan 4 15:25:50 CET 2005


Author: phil
Date: 2005-01-04 15:25:47 +0100 (Tue, 04 Jan 2005)
New Revision: 1693

Modified:
   trunk/ROADMAP
   trunk/drbd/drbd_int.h
   trunk/drbd/drbd_main.c
   trunk/drbd/drbd_receiver.c
   trunk/user/drbdmeta.c
Log:
Introduced UUIDs.


Modified: trunk/ROADMAP
===================================================================
--- trunk/ROADMAP	2005-01-03 13:13:09 UTC (rev 1692)
+++ trunk/ROADMAP	2005-01-04 14:25:47 UTC (rev 1693)
@@ -354,6 +354,11 @@
   are inherited from the common section, if they are not
   defined in a resource section.
 
+13 Introduce a UUID (universally unique identifier) in the
+  meta data. One purpose is to tag the bitmap with this UUID. 
+  If the peer's UUID is different to what we expect we know that 
+  we have to do a full sync....
+
 plus-banches:
 ----------------------
 

Modified: trunk/drbd/drbd_int.h
===================================================================
--- trunk/drbd/drbd_int.h	2005-01-03 13:13:09 UTC (rev 1692)
+++ trunk/drbd/drbd_int.h	2005-01-04 14:25:47 UTC (rev 1693)
@@ -472,6 +472,7 @@
 	Drbd_Header head;
 	u64         p_size;  // size of disk
 	u64         u_size;  // user requested size
+	u64         uuid;
 	u32         state;
 	u32         protocol;
 	u32         version;
@@ -687,6 +688,8 @@
 	/* volatile */ drbd_state_t state;
 	wait_queue_head_t cstate_wait; // TODO Rename into "misc_wait". 
 	sector_t la_size;     // last agreed disk size in sectors.
+	u64 uuid;
+	u64 peer_uuid;
 	unsigned int send_cnt;
 	unsigned int recv_cnt;
 	unsigned int read_cnt;

Modified: trunk/drbd/drbd_main.c
===================================================================
--- trunk/drbd/drbd_main.c	2005-01-03 13:13:09 UTC (rev 1692)
+++ trunk/drbd/drbd_main.c	2005-01-04 14:25:47 UTC (rev 1693)
@@ -844,6 +844,7 @@
 
 	p.u_size = cpu_to_be64(mdev->lo_usize);
 	p.p_size = cpu_to_be64(m_size);
+	p.uuid   = cpu_to_be64(mdev->uuid);
 
 	p.state    = cpu_to_be32(mdev->state.i);
 	p.protocol = cpu_to_be32(mdev->conf.wire_protocol);
@@ -2026,6 +2027,8 @@
 
 struct meta_data_on_disk {
 	u64 la_size;           // last agreed size.
+	u64 uuid;              // universally unique identifier
+	u64 peer_uuid;         // universally unique identifier
 	u32 gc[GEN_CNT_SIZE];  // generation counter
 	u32 magic;
 	u32 md_size;
@@ -2063,6 +2066,9 @@
 	for (i = Flags; i < GEN_CNT_SIZE; i++)
 		buffer->gc[i]=cpu_to_be32(mdev->gen_cnt[i]);
 	buffer->la_size=cpu_to_be64(drbd_get_capacity(mdev->this_bdev));
+	buffer->uuid=cpu_to_be64(mdev->uuid);
+	buffer->peer_uuid=cpu_to_be64(mdev->peer_uuid);
+
 	buffer->magic=cpu_to_be32(DRBD_MD_MAGIC);
 
 	buffer->md_size = __constant_cpu_to_be32(MD_RESERVED_SIZE);
@@ -2134,6 +2140,8 @@
 	for(i=Flags;i<=ArbitraryCnt;i++)
 		mdev->gen_cnt[i]=be32_to_cpu(buffer->gc[i]);
 	mdev->la_size = be64_to_cpu(buffer->la_size);
+	mdev->uuid = be64_to_cpu(buffer->uuid);
+	mdev->peer_uuid = be64_to_cpu(buffer->peer_uuid);
 	mdev->sync_conf.al_extents = be32_to_cpu(buffer->al_nr_extents);
 	if (mdev->sync_conf.al_extents < 7)
 		mdev->sync_conf.al_extents = 127;

Modified: trunk/drbd/drbd_receiver.c
===================================================================
--- trunk/drbd/drbd_receiver.c	2005-01-03 13:13:09 UTC (rev 1692)
+++ trunk/drbd/drbd_receiver.c	2005-01-04 14:25:47 UTC (rev 1693)
@@ -1233,6 +1233,12 @@
 	}
 
 	if( sync ) {
+		if( mdev->peer_uuid != be64_to_cpu(p->uuid) ) {
+			WARN("Peer presented a new UUID -> full sync.\n");
+			mdev->peer_uuid = be64_to_cpu(p->uuid);
+			drbd_bm_set_all(mdev);
+		}
+
 		if(have_good == 1) {
 			D_ASSERT(drbd_md_test_flag(mdev,MDF_Consistent));
 			rv = WFBitMapS;

Modified: trunk/user/drbdmeta.c
===================================================================
--- trunk/user/drbdmeta.c	2005-01-03 13:13:09 UTC (rev 1692)
+++ trunk/user/drbdmeta.c	2005-01-04 14:25:47 UTC (rev 1693)
@@ -159,6 +159,8 @@
 	 * 0.7 stores la_size on disk as kb, 0.8 in units of sectors.
 	 * we use sectors in our general working structure here */
 	u64 la_sect;		/* last agreed size. */
+	u64 uuid;
+	u64 peer_uuid;
 	u32 md_size;
 	u32 al_offset;		/* offset to this block */
 	u32 al_nr_extents;	/* important for restoring the AL */
@@ -339,19 +341,23 @@
 
 struct __attribute__ ((packed)) md_on_disk_08 {
 	be_u64 la_sect;		/* last agreed size. */
+	be_u64 uuid;            /* universally unique identifier */
+	be_u64 peer_uuid;       /* universally unique identifier */
 	be_u32 gc[GEN_CNT_SIZE];	/* generation counter */
 	be_u32 magic;
 	be_u32 md_size;
 	be_u32 al_offset;	/* offset to this block */
 	be_u32 al_nr_extents;	/* important for restoring the AL */
 	be_u32 bm_offset;	/* offset to the bitmap, from here */
-	char reserved[8 * 512 - 48];
+	char reserved[8 * 512 - 56];
 };
 
 void md_disk_08_to_cpu(struct md_cpu *cpu, const struct md_on_disk_08 *disk)
 {
 	int i;
 	cpu->la_sect = be64_to_cpu(disk->la_sect.be);
+	cpu->uuid = be64_to_cpu(disk->uuid.be);
+	cpu->peer_uuid = be64_to_cpu(disk->peer_uuid.be);
 	for (i = 0; i < GEN_CNT_SIZE; i++)
 		cpu->gc[i] = be32_to_cpu(disk->gc[i].be);
 	cpu->magic = be32_to_cpu(disk->magic.be);
@@ -365,6 +371,8 @@
 {
 	int i;
 	disk->la_sect.be = cpu_to_be64(cpu->la_sect);
+	disk->uuid.be  = cpu_to_be64(cpu->uuid);
+	disk->peer_uuid.be  = cpu_to_be64(cpu->peer_uuid);
 	for (i = 0; i < GEN_CNT_SIZE; i++)
 		disk->gc[i].be = cpu_to_be32(cpu->gc[i]);
 	disk->magic.be = cpu_to_be32(cpu->magic);
@@ -1016,11 +1024,27 @@
 	return 0;
 }
 
+int get_real_random(void * p, int size)
+{
+	int fd,rv;
+
+	fd = open("/dev/random", O_RDONLY);
+	if(fd == -1) {
+		PERROR("open('/dev/random',O_RDONLY)");
+		exit(20);
+	}
+	rv = size == read(fd,p,size);
+	close(fd);
+	return rv;
+}
+
 int v08_md_initialize(struct format *cfg)
 {
 	u64 al_offset, bm_offset;
 
 	cfg->md.la_sect = 0;
+	get_real_random(&cfg->md.uuid,sizeof(u64));
+	cfg->md.peer_uuid = 0;
 	cfg->md.gc[Flags] = 0;
 	cfg->md.gc[HumanCnt] = 1;	/* THINK 0? 1? */
 	cfg->md.gc[TimeoutCnt] = 1;
@@ -1148,12 +1172,19 @@
 	}
 	printf(" }\n");
 
-	if (cfg->ops > f_ops + Drbd_06) {
+	if (cfg->ops >= f_ops + Drbd_07) {
 		printf("la-size-sect %llu;\n", cfg->md.la_sect);
-		printf("# bm-bytes %u;\n", cfg->bm_bytes);	/* informational only */
-		printf("# bits-set %u;\n", cfg->bits_set);	/* informational only */
-		printf
-		    ("# FIXME include offsets, once they are not fixed anymore\n");
+	}
+
+	if (cfg->ops >= f_ops + Drbd_08) {
+		printf("uuid %llX;\n", cfg->md.uuid);
+		printf("peer-uuid %llX;\n", cfg->md.peer_uuid);
+		printf("# FIXME include offsets, once they are not fixed anymore\n");
+	}
+
+	if (cfg->ops >= f_ops + Drbd_07) {
+		printf("# bm-bytes %u;\n", cfg->bm_bytes);
+		printf("# bits-set %u;\n", cfg->bits_set);
 		if (cfg->on_disk.bm)
 			printf_bm((le_u64 *) cfg->on_disk.bm,
 				  cfg->bm_bytes / sizeof(le_u64));
@@ -1175,6 +1206,8 @@
 	 * We only need to adjust the magic here. */
 	printf("Converting meta data...\n");
 	cfg->md.magic = DRBD_MD_MAGIC_08;
+	get_real_random(&cfg->md.uuid,sizeof(u64));
+	cfg->md.peer_uuid = 0;
 	if (cfg->ops->md_cpu_to_disk(cfg)
 	    || cfg->ops->close(cfg)) {
 		fprintf(stderr, "conversion failed\n");



More information about the drbd-cvs mailing list