]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Grow.c
remove ANNOUNCE-2.0-devel-?
[thirdparty/mdadm.git] / Grow.c
diff --git a/Grow.c b/Grow.c
index 817a17a8e5b667cae63e4b7e0156572be58dff4f..623daf3fe910ec08c3fb16e1f203eaca9f6a6b68 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -123,7 +123,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
        info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
        st->ss->update_super(&info, super, "grow", newdev, 0);
 
-       if (st->ss->store_super(nfd, super)) {
+       if (st->ss->store_super(st, nfd, super)) {
                fprintf(stderr, Name ": Cannot store new superblock on %s\n", newdev);
                close(nfd);
                return 1;
@@ -181,7 +181,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
                st->ss->update_super(&info, super, "grow", dv, 0);
                
-               if (st->ss->store_super(fd2, super)) {
+               if (st->ss->store_super(st, fd2, super)) {
                        fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv);
                        close(fd2);
                        return 1;
@@ -192,7 +192,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
        return 0;
 }
 
-int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay)
+int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int write_behind)
 {
        /*
         * First check that array doesn't have a bitmap
@@ -215,6 +215,14 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay)
                return 1;
        }
        if (bmf.pathname[0]) {
+               if (strcmp(file,"none")==0) {
+                       if (ioctl(fd, SET_BITMAP_FILE, -1)!= 0) {
+                               fprintf(stderr, Name ": failed to remove bitmap %s\n",
+                                       bmf.pathname);
+                               return 1;
+                       }
+                       return 0;
+               }
                fprintf(stderr, Name ": %s already has a bitmap (%s)\n",
                        devname, bmf.pathname);
                return 1;
@@ -224,6 +232,14 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay)
                return 1;
        }
        if (array.state & (1<<MD_SB_BITMAP_PRESENT)) {
+               if (strcmp(file, "none")==0) {
+                       array.state &= ~(1<<MD_SB_BITMAP_PRESENT);
+                       if (ioctl(fd, SET_ARRAY_INFO, &array)!= 0) {
+                               fprintf(stderr, Name ": failed to remove internal bitmap.\n");
+                               return 1;
+                       }
+                       return 0;
+               }
                fprintf(stderr, Name ": Internal bitmap already present on %s\n",
                        devname);
                return 1;
@@ -234,9 +250,12 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay)
                        array.major_version, array.minor_version);
                return 1;
        }
-       if (strcmp(file, "internal") == 0) {
+       if (strcmp(file, "none") == 0) {
+               fprintf(stderr, Name ": no bitmap found on %s\n", devname);
+               return 1;
+       } else if (strcmp(file, "internal") == 0) {
                int d;
-               for (d=0; d< MD_SB_DISKS; d++) {
+               for (d=0; d< st->max_devs; d++) {
                        mdu_disk_info_t disk;
                        char *dv;
                        disk.number = d;
@@ -254,8 +273,8 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay)
                                if (fd2 < 0)
                                        continue;
                                if (st->ss->load_super(st, fd2, &super, NULL)==0) {
-                                       st->ss->add_internal_bitmap(super, 
-                                                                   chunk, delay,
+                                       st->ss->add_internal_bitmap(st, super,
+                                                                   chunk, delay, write_behind,
                                                                    array.size);
                                        st->ss->write_bitmap(st, fd2, super);
                                }
@@ -267,8 +286,57 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay)
                        fprintf(stderr, Name ": failed to set internal bitmap.\n");
                        return 1;
                }
-       } else
-               abort(); /* FIXME */
+       } else {
+               int uuid[4];
+               int bitmap_fd;
+               int d;
+               int max_devs = st->max_devs;
+               void *super = NULL;
+               if (chunk == UnSet)
+                       chunk = DEFAULT_BITMAP_CHUNK;
+
+               /* try to load a superblock */
+               for (d=0; d<max_devs; d++) {
+                       mdu_disk_info_t disk;
+                       char *dv;
+                       int fd2;
+                       disk.number = d;
+                       if (ioctl(fd, GET_DISK_INFO, &disk) < 0)
+                               continue;
+                       if ((disk.major==0 && disk.minor==0) ||
+                           (disk.state & (1<<MD_DISK_REMOVED)))
+                               continue;
+                       dv = map_dev(disk.major, disk.minor);
+                       if (!dv) continue;
+                       fd2 = open(dv, O_RDONLY);
+                       if (fd2 >= 0 &&
+                           st->ss->load_super(st, fd2, &super, NULL) == 0) {
+                               close(fd2);
+                               st->ss->uuid_from_super(uuid, super);
+                               break;
+                       }
+                       close(fd2);
+               }
+               if (d == max_devs) {
+                       fprintf(stderr, Name ": cannot find UUID for array!\n");
+                       return 1;
+               }
+               if (CreateBitmap(file, 0, (char*)uuid, chunk,
+                                delay, write_behind, array.size*2ULL)) {
+                       return 1;
+               }
+               bitmap_fd = open(file, O_RDWR);
+               if (bitmap_fd < 0) {
+                       fprintf(stderr, Name ": weird: %s cannot be openned\n",
+                               file);
+                       return 1;
+               }
+               if (ioctl(fd, SET_BITMAP_FILE, bitmap_fd) < 0) {
+                       fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n",
+                               devname, strerror(errno));
+                       return 1;
+               }
+       }
 
        return 0;
 }