]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
imsm: write anchor last
authorDan Williams <dan.j.williams@intel.com>
Mon, 16 Jun 2008 22:36:41 +0000 (15:36 -0700)
committerDan Williams <dan.j.williams@intel.com>
Mon, 16 Jun 2008 22:36:41 +0000 (15:36 -0700)
Ensure that newly written anchors reflect a consistent metadata block.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
super-intel.c

index c8419f001d34041167fbd504f312e4506c90542e..3a85e2c3037b392e3ae83a62076b7f96645854b4 100644 (file)
@@ -1795,24 +1795,23 @@ static int store_imsm_mpb(int fd, struct intel_super *super)
 
        get_dev_size(fd, NULL, &dsize);
 
-       /* first block is stored on second to last sector of the disk */
-       if (lseek64(fd, dsize - (512 * 2), SEEK_SET) < 0)
-               return 1;
+       if (mpb_size > 512) {
+               /* -1 to account for anchor */
+               sectors = mpb_sectors(mpb) - 1;
 
-       if (write(fd, super->buf, 512) != 512)
-               return 1;
-
-       if (mpb_size <= 512)
-               return 0;
+               /* write the extended mpb to the sectors preceeding the anchor */
+               if (lseek64(fd, dsize - (512 * (2 + sectors)), SEEK_SET) < 0)
+                       return 1;
 
-       /* -1 because we already wrote a sector */
-       sectors = mpb_sectors(mpb) - 1;
+               if (write(fd, super->buf + 512, mpb_size - 512) != mpb_size - 512)
+                       return 1;
+       }
 
-       /* write the extended mpb to the sectors preceeding the anchor */
-       if (lseek64(fd, dsize - (512 * (2 + sectors)), SEEK_SET) < 0)
+       /* first block is stored on second to last sector of the disk */
+       if (lseek64(fd, dsize - (512 * 2), SEEK_SET) < 0)
                return 1;
 
-       if (write(fd, super->buf + 512, mpb_size - 512) != mpb_size - 512)
+       if (write(fd, super->buf, 512) != 512)
                return 1;
 
        fsync(fd);