Create: support --readonly flag.
authorNeilBrown <neilb@suse.de>
Mon, 9 Jul 2012 07:14:17 +0000 (17:14 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 9 Jul 2012 07:14:17 +0000 (17:14 +1000)
Allow array to be created read-only

Signed-off-by: NeilBrown <neilb@suse.de>
Create.c
mdadm.c
mdadm.h

index af09495..ed6d2ae 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -67,7 +67,8 @@ int Create(struct supertype *st, char *mddev,
           int raiddisks, int sparedisks,
           char *name, char *homehost, int *uuid,
           int subdevs, struct mddev_dev *devlist,
-          int runstop, int verbose, int force, int assume_clean,
+          int runstop, int readonly, int verbose,
+          int force, int assume_clean,
           char *bitmap_file, int bitmap_chunk, int write_behind,
           int delay, int autof)
 {
@@ -958,7 +959,9 @@ int Create(struct supertype *st, char *mddev,
                        case LEVEL_MULTIPATH:
                        case 0:
                                err = sysfs_set_str(&info, NULL, "array_state",
-                                                   "active");
+                                                   readonly
+                                                   ? "readonly"
+                                                   : "active");
                                need_mdmon = 0;
                                break;
                        default:
@@ -973,12 +976,22 @@ int Create(struct supertype *st, char *mddev,
                                ioctl(mdfd, STOP_ARRAY, NULL);
                                goto abort;
                        }
+               } else if (readonly &&
+                          sysfs_attribute_available(
+                                  &info, NULL, "array_state")) {
+                       if (sysfs_set_str(&info, NULL,
+                                         "array_state", "readonly") < 0) {
+                               pr_err("Failed to start array: %s\n",
+                                      strerror(errno));
+                               ioctl(mdfd, STOP_ARRAY, NULL);
+                               goto abort;
+                       }
                } else {
                        /* param is not actually used */
                        mdu_param_t param;
                        if (ioctl(mdfd, RUN_ARRAY, &param)) {
                                pr_err("RUN_ARRAY failed: %s\n",
-                                       strerror(errno));
+                                      strerror(errno));
                                if (info.array.chunk_size & (info.array.chunk_size-1)) {
                                        cont_err("Problem may be that "
                                                 "chunk size is not a power of 2\n");
diff --git a/mdadm.c b/mdadm.c
index e10fc38..5aa0823 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1373,7 +1373,8 @@ int main(int argc, char *argv[])
                rv = Create(ss, devlist->devname, chunk, level, layout, size<0 ? 0 : size,
                            raiddisks, sparedisks, ident.name, homehost,
                            ident.uuid_set ? ident.uuid : NULL,
-                           devs_found-1, devlist->next, runstop, verbose-quiet, force, assume_clean,
+                           devs_found-1, devlist->next, runstop,
+                           readonly, verbose-quiet, force, assume_clean,
                            bitmap_file, bitmap_chunk, write_behind, delay, autof);
                break;
        case MISC:
diff --git a/mdadm.h b/mdadm.h
index f96ac7b..564b510 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1085,10 +1085,12 @@ extern int Build(char *mddev, int chunk, int level, int layout,
 
 
 extern int Create(struct supertype *st, char *mddev,
-                 int chunk, int level, int layout, unsigned long long size, int raiddisks, int sparedisks,
+                 int chunk, int level, int layout, unsigned long long size,
+                 int raiddisks, int sparedisks,
                  char *name, char *homehost, int *uuid,
                  int subdevs, struct mddev_dev *devlist,
-                 int runstop, int verbose, int force, int assume_clean,
+                 int runstop, int readonly, int verbose,
+                 int force, int assume_clean,
                  char *bitmap_file, int bitmap_chunk, int write_behind, int delay, int autof);
 
 extern int Detail(char *dev, int brief, int export, int test, char *homehost, char *prefer);