]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super-intel.c
imsm: Do not require MDADM_EXPERIMENTAL flag anymore
[thirdparty/mdadm.git] / super-intel.c
index c55c85f1b0f9d316c8d0cf966d1bda7ae4a16869..a01be132e3a3ac1286193ca2087043fb7d595014 100644 (file)
@@ -1928,7 +1928,6 @@ static void examine_super_imsm(struct supertype *st, char *homehost)
        strncpy(str, (char *)mpb->sig, MPB_SIG_LEN);
        str[MPB_SIG_LEN-1] = '\0';
        printf("          Magic : %s\n", str);
-       snprintf(str, strlen(MPB_VERSION_RAID0), "%s", get_imsm_version(mpb));
        printf("        Version : %s\n", get_imsm_version(mpb));
        printf("    Orig Family : %08x\n", __le32_to_cpu(mpb->orig_family_num));
        printf("         Family : %08x\n", __le32_to_cpu(mpb->family_num));
@@ -3228,27 +3227,27 @@ int imsm_reshape_blocks_arrays_changes(struct intel_super *super)
        }
        return rv;
 }
-static unsigned long long imsm_component_size_aligment_check(int level,
+static unsigned long long imsm_component_size_alignment_check(int level,
                                              int chunk_size,
                                              unsigned int sector_size,
                                              unsigned long long component_size)
 {
-       unsigned int component_size_alligment;
+       unsigned int component_size_alignment;
 
-       /* check component size aligment
+       /* check component size alignment
        */
-       component_size_alligment = component_size % (chunk_size/sector_size);
+       component_size_alignment = component_size % (chunk_size/sector_size);
 
-       dprintf("(Level: %i, chunk_size = %i, component_size = %llu), component_size_alligment = %u\n",
+       dprintf("(Level: %i, chunk_size = %i, component_size = %llu), component_size_alignment = %u\n",
                level, chunk_size, component_size,
-               component_size_alligment);
+               component_size_alignment);
 
-       if (component_size_alligment && (level != 1) && (level != UnSet)) {
-               dprintf("imsm: reported component size alligned from %llu ",
+       if (component_size_alignment && (level != 1) && (level != UnSet)) {
+               dprintf("imsm: reported component size aligned from %llu ",
                        component_size);
-               component_size -= component_size_alligment;
+               component_size -= component_size_alignment;
                dprintf_cont("to %llu (%i).\n",
-                       component_size, component_size_alligment);
+                       component_size, component_size_alignment);
        }
 
        return component_size;
@@ -3351,7 +3350,7 @@ static void getinfo_super_imsm_volume(struct supertype *st, struct mdinfo *info,
 
        info->data_offset         = pba_of_lba0(map_to_analyse);
        info->component_size = calc_component_size(map, dev);
-       info->component_size = imsm_component_size_aligment_check(
+       info->component_size = imsm_component_size_alignment_check(
                                                        info->array.level,
                                                        info->array.chunk_size,
                                                        super->sector_size,
@@ -5323,6 +5322,7 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
        struct imsm_map *map;
        int idx = mpb->num_raid_devs;
        int i;
+       int namelen;
        unsigned long long array_blocks;
        size_t size_old, size_new;
        unsigned long long num_data_stripes;
@@ -5402,7 +5402,12 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
                return 0;
        dv = xmalloc(sizeof(*dv));
        dev = xcalloc(1, sizeof(*dev) + sizeof(__u32) * (info->raid_disks - 1));
-       strncpy((char *) dev->volume, name, MAX_RAID_SERIAL_LEN);
+       /*
+        * Explicitly allow truncating to not confuse gcc's
+        * -Werror=stringop-truncation
+        */
+       namelen = min((int) strlen(name), MAX_RAID_SERIAL_LEN);
+       memcpy(dev->volume, name, namelen);
        array_blocks = calc_array_size(info->level, info->raid_disks,
                                               info->layout, info->chunk_size,
                                               s->size * BLOCKS_PER_KB);
@@ -5611,6 +5616,11 @@ static int add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
                return 1;
        }
 
+       if (mpb->num_disks == 0)
+               if (!get_dev_sector_size(dl->fd, dl->devname,
+                                        &super->sector_size))
+                       return 1;
+
        if (!drive_validate_sector_size(super, dl)) {
                pr_err("Combining drives of different sector size in one volume is not allowed\n");
                return 1;
@@ -7089,7 +7099,7 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level,
        mpb = super->anchor;
 
        if (!validate_geometry_imsm_orom(super, level, layout, raiddisks, chunk, size, verbose)) {
-               pr_err("RAID gemetry validation failed. Cannot proceed with the action(s).\n");
+               pr_err("RAID geometry validation failed. Cannot proceed with the action(s).\n");
                return 0;
        }
        if (!dev) {
@@ -7358,6 +7368,16 @@ static int validate_geometry_imsm(struct supertype *st, int level, int layout,
                                                        verbose);
        }
 
+       if (size && ((size < 1024) || (*chunk != UnSet &&
+           size < (unsigned long long) *chunk))) {
+               pr_err("Given size must be greater than 1M and chunk size.\n");
+               /* Depends on algorithm in Create.c :
+                * if container was given (dev == NULL) return -1,
+                * if block device was given ( dev != NULL) return 0.
+                */
+               return dev ? -1 : 0;
+       }
+
        if (!dev) {
                if (st->sb) {
                        struct intel_super *super = st->sb;
@@ -7572,11 +7592,12 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,
                        append_metadata_update(st, u, sizeof(*u));
                } else {
                        struct imsm_dev *dev;
-                       int i;
+                       int i, namelen;
 
                        dev = get_imsm_dev(super, vol);
-                       strncpy((char *) dev->volume, name, MAX_RAID_SERIAL_LEN);
-                       dev->volume[MAX_RAID_SERIAL_LEN-1] = '\0';
+                       memset(dev->volume, '\0', MAX_RAID_SERIAL_LEN);
+                       namelen = min((int)strlen(name), MAX_RAID_SERIAL_LEN);
+                       memcpy(dev->volume, name, namelen);
                        for (i = 0; i < mpb->num_raid_devs; i++) {
                                dev = get_imsm_dev(super, i);
                                handle_missing(super, dev);
@@ -8082,7 +8103,7 @@ static int mark_failure(struct intel_super *super,
        strcat(buf, ":0");
        if ((len = strlen(buf)) >= MAX_RAID_SERIAL_LEN)
                shift = len - MAX_RAID_SERIAL_LEN + 1;
-       strncpy((char *)disk->serial, &buf[shift], MAX_RAID_SERIAL_LEN);
+       memcpy(disk->serial, &buf[shift], len + 1 - shift);
 
        disk->status |= FAILED_DISK;
        set_imsm_ord_tbl_ent(map, slot, idx | IMSM_ORD_REBUILD);
@@ -9866,6 +9887,7 @@ static void imsm_process_update(struct supertype *st,
                /* sanity check that we are not affecting the uuid of
                 * an active array
                 */
+               memset(name, 0, sizeof(name));
                snprintf(name, MAX_RAID_SERIAL_LEN, "%s", (char *) u->name);
                name[MAX_RAID_SERIAL_LEN] = '\0';
                for (a = st->arrays; a; a = a->next)
@@ -9877,7 +9899,7 @@ static void imsm_process_update(struct supertype *st,
                        break;
                }
 
-               snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, "%s", name);
+               memcpy(dev->volume, name, MAX_RAID_SERIAL_LEN);
                super->updates_pending++;
                break;
        }
@@ -11424,7 +11446,7 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st,
        if (geo->size > 0 && geo->size != MAX_SIZE) {
                /* align component size
                 */
-               geo->size = imsm_component_size_aligment_check(
+               geo->size = imsm_component_size_alignment_check(
                                    get_imsm_raid_level(dev->vol.map),
                                    chunk * 1024, super->sector_size,
                                    geo->size * 2);
@@ -11458,7 +11480,7 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st,
                        max_size = free_size + current_size;
                        /* align component size
                         */
-                       max_size = imsm_component_size_aligment_check(
+                       max_size = imsm_component_size_alignment_check(
                                        get_imsm_raid_level(dev->vol.map),
                                        chunk * 1024, super->sector_size,
                                        max_size);
@@ -11585,9 +11607,6 @@ static int imsm_reshape_super(struct supertype *st, unsigned long long size,
        dprintf("for level      : %i\n", geo.level);
        dprintf("for raid_disks : %i\n", geo.raid_disks);
 
-       if (experimental() == 0)
-               return ret_val;
-
        if (strcmp(st->container_devnm, st->devnm) == 0) {
                /* On container level we can only increase number of devices. */
                dprintf("imsm: info: Container operation\n");
@@ -11960,7 +11979,7 @@ static int imsm_manage_reshape(
        buf_size = __le32_to_cpu(migr_rec->blocks_per_unit) * 512;
        /* extend  buffer size for parity disk */
        buf_size += __le32_to_cpu(migr_rec->dest_depth_per_unit) * 512;
-       /* add space for stripe aligment */
+       /* add space for stripe alignment */
        buf_size += old_data_stripe_length;
        if (posix_memalign((void **)&buf, MAX_SECTOR_SIZE, buf_size)) {
                dprintf("imsm: Cannot allocate checkpoint buffer\n");