diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2016-04-04 18:48:40 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2016-04-04 18:48:40 +0000 |
commit | 920ebf8ac71d43445517fcb87fcc1a149478402e (patch) | |
tree | 29012a19ddc2698e55b6f8be4d873ddbc97f4c15 | |
parent | 9550b5c20eb6521c6be55ff7a01473d287609743 (diff) |
Enable creation of softraid volumes using disks with non-512 byte
sectors. Volumes created will present a sector size equal to the
largest sector size of the constituent disks.
Softraid Metadata version cranks to 6 due to new field.
ok jsing@ with tweaks that will follow soon.
-rw-r--r-- | sys/dev/softraid.c | 60 | ||||
-rw-r--r-- | sys/dev/softraid_concat.c | 10 | ||||
-rw-r--r-- | sys/dev/softraid_crypto.c | 13 | ||||
-rw-r--r-- | sys/dev/softraid_raid0.c | 12 | ||||
-rw-r--r-- | sys/dev/softraid_raid1.c | 11 | ||||
-rw-r--r-- | sys/dev/softraid_raid5.c | 12 | ||||
-rw-r--r-- | sys/dev/softraid_raid6.c | 12 | ||||
-rw-r--r-- | sys/dev/softraidvar.h | 7 |
8 files changed, 84 insertions, 53 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index 6d3adf25cfc..1fc82705fbb 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.366 2016/02/14 12:47:27 krw Exp $ */ +/* $OpenBSD: softraid.c,v 1.367 2016/04/04 18:48:39 krw Exp $ */ /* * Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> @@ -942,6 +942,7 @@ sr_meta_validate(struct sr_discipline *sd, dev_t dev, struct sr_metadata *sm, */ if (sm->ssd_data_blkno == 0) sm->ssd_data_blkno = SR_META_V3_DATA_OFFSET; + sm->ssdi.ssd_secsize = DEV_BSIZE; } else if (sm->ssdi.ssd_version == 4) { @@ -951,14 +952,22 @@ sr_meta_validate(struct sr_discipline *sd, dev_t dev, struct sr_metadata *sm, */ if (sm->ssd_data_blkno == 0) sm->ssd_data_blkno = SR_DATA_OFFSET; + sm->ssdi.ssd_secsize = DEV_BSIZE; - } else if (sm->ssdi.ssd_version == SR_META_VERSION) { + } else if (sm->ssdi.ssd_version == 5) { /* * Version 5 - variable length optional metadata. Migration * from earlier fixed length optional metadata is handled * in sr_meta_read(). */ + sm->ssdi.ssd_secsize = DEV_BSIZE; + + } else if (sm->ssdi.ssd_version == SR_META_VERSION) { + + /* + * Version 6 - store & report a sector size. + */ } else { @@ -1050,13 +1059,6 @@ sr_meta_native_bootprobe(struct sr_softc *sc, dev_t devno, } vput(vn); - /* Make sure this is a DEV_BSIZE byte/sector device. */ - if (label.d_secsize != DEV_BSIZE) { - DNPRINTF(SR_D_META, "%s: %s has unsupported sector size (%d)", - DEVNAME(sc), devname, label.d_secsize); - goto done; - } - md = malloc(SR_META_SIZE * DEV_BSIZE, M_DEVBUF, M_ZERO | M_NOWAIT); if (md == NULL) { sr_error(sc, "not enough memory for metadata buffer"); @@ -1563,13 +1565,6 @@ sr_meta_native_probe(struct sr_softc *sc, struct sr_chunk *ch_entry) } memcpy(ch_entry->src_duid, label.d_uid, sizeof(ch_entry->src_duid)); - /* Make sure this is a DEV_BSIZE byte/sector device. */ - if (label.d_secsize != DEV_BSIZE) { - sr_error(sc, "%s has unsupported sector size (%u)", - devname, label.d_secsize); - goto unwind; - } - /* make sure the partition is of the right type */ if (label.d_partitions[part].p_fstype != FS_RAID) { DNPRINTF(SR_D_META, @@ -1592,6 +1587,7 @@ sr_meta_native_probe(struct sr_softc *sc, struct sr_chunk *ch_entry) goto unwind; } ch_entry->src_size = size; + ch_entry->src_secsize = label.d_secsize; DNPRINTF(SR_D_META, "%s: probe found %s size %lld\n", DEVNAME(sc), devname, (long long)size); @@ -2871,11 +2867,6 @@ sr_hotspare(struct sr_softc *sc, dev_t dev) vput(vn); goto fail; } - if (label.d_secsize != DEV_BSIZE) { - sr_error(sc, "%s has unsupported sector size (%u)", - devname, label.d_secsize); - goto fail; - } if (label.d_partitions[part].p_fstype != FS_RAID) { sr_error(sc, "%s partition not of type RAID (%d)", devname, label.d_partitions[part].p_fstype); @@ -2935,6 +2926,7 @@ sr_hotspare(struct sr_softc *sc, dev_t dev) sm->ssdi.ssd_volid = SR_HOTSPARE_VOLID; sm->ssdi.ssd_level = SR_HOTSPARE_LEVEL; sm->ssdi.ssd_size = size; + sm->ssdi.ssd_secsize = label.d_secsize; strlcpy(sm->ssdi.ssd_vendor, "OPENBSD", sizeof(sm->ssdi.ssd_vendor)); snprintf(sm->ssdi.ssd_product, sizeof(sm->ssdi.ssd_product), "SR %s", "HOTSPARE"); @@ -3187,11 +3179,6 @@ sr_rebuild_init(struct sr_discipline *sd, dev_t dev, int hotspare) DEVNAME(sc)); goto done; } - if (label.d_secsize != DEV_BSIZE) { - sr_error(sc, "%s has unsupported sector size (%u)", - devname, label.d_secsize); - goto done; - } if (label.d_partitions[part].p_fstype != FS_RAID) { sr_error(sc, "%s partition not of type RAID (%d)", devname, label.d_partitions[part].p_fstype); @@ -3666,7 +3653,7 @@ sr_ioctl_installboot(struct sr_softc *sc, struct sr_discipline *sd, struct sr_meta_opt_item *omi; struct sr_meta_boot *sbm; struct disk *dk; - u_int32_t bbs, bls; + u_int32_t bbs, bls, secsize; u_char duid[8]; int rv = EINVAL; int i; @@ -3710,14 +3697,16 @@ sr_ioctl_installboot(struct sr_softc *sc, struct sr_discipline *sd, if (bb->bb_bootldr_size > SR_BOOT_LOADER_SIZE * DEV_BSIZE) goto done; + secsize = sd->sd_meta->ssdi.ssd_secsize; + /* Copy in boot block. */ - bbs = howmany(bb->bb_bootblk_size, DEV_BSIZE) * DEV_BSIZE; + bbs = howmany(bb->bb_bootblk_size, secsize) * secsize; bootblk = malloc(bbs, M_DEVBUF, M_WAITOK | M_ZERO); if (copyin(bb->bb_bootblk, bootblk, bb->bb_bootblk_size) != 0) goto done; /* Copy in boot loader. */ - bls = howmany(bb->bb_bootldr_size, DEV_BSIZE) * DEV_BSIZE; + bls = howmany(bb->bb_bootldr_size, secsize) * secsize; bootldr = malloc(bls, M_DEVBUF, M_WAITOK | M_ZERO); if (copyin(bb->bb_bootldr, bootldr, bb->bb_bootldr_size) != 0) goto done; @@ -4033,25 +4022,28 @@ sr_raid_read_cap(struct sr_workunit *wu) struct scsi_xfer *xs = wu->swu_xs; struct scsi_read_cap_data rcd; struct scsi_read_cap_data_16 rcd16; - int64_t addr; + u_int64_t addr; int rv = 1; + u_int32_t secsize; DNPRINTF(SR_D_DIS, "%s: sr_raid_read_cap\n", DEVNAME(sd->sd_sc)); - addr = sd->sd_meta->ssdi.ssd_size - 1; + secsize = sd->sd_meta->ssdi.ssd_secsize; + + addr = ((sd->sd_meta->ssdi.ssd_size * DEV_BSIZE) / secsize) - 1; if (xs->cmd->opcode == READ_CAPACITY) { bzero(&rcd, sizeof(rcd)); if (addr > 0xffffffffllu) _lto4b(0xffffffff, rcd.addr); else _lto4b(addr, rcd.addr); - _lto4b(DEV_BSIZE, rcd.length); + _lto4b(secsize, rcd.length); sr_copy_internal_data(xs, &rcd, sizeof(rcd)); rv = 0; } else if (xs->cmd->opcode == READ_CAPACITY_16) { bzero(&rcd16, sizeof(rcd16)); _lto8b(addr, rcd16.addr); - _lto4b(DEV_BSIZE, rcd16.length); + _lto4b(secsize, rcd16.length); sr_copy_internal_data(xs, &rcd16, sizeof(rcd16)); rv = 0; } @@ -4578,6 +4570,8 @@ sr_validate_io(struct sr_workunit *wu, daddr_t *blkno, char *func) goto bad; } + *blkno *= (sd->sd_meta->ssdi.ssd_secsize / DEV_BSIZE); + wu->swu_blk_start = *blkno; wu->swu_blk_end = *blkno + (xs->datalen >> DEV_BSHIFT) - 1; diff --git a/sys/dev/softraid_concat.c b/sys/dev/softraid_concat.c index b6ac55eb281..be770d4a23d 100644 --- a/sys/dev/softraid_concat.c +++ b/sys/dev/softraid_concat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_concat.c,v 1.23 2015/07/21 03:30:51 krw Exp $ */ +/* $OpenBSD: softraid_concat.c,v 1.24 2016/04/04 18:48:39 krw Exp $ */ /* * Copyright (c) 2008 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2011 Joel Sing <jsing@openbsd.org> @@ -61,6 +61,7 @@ sr_concat_create(struct sr_discipline *sd, struct bioc_createraid *bc, int no_chunk, int64_t coerced_size) { int i; + u_int32_t secsize; if (no_chunk < 2) { sr_error(sd->sd_sc, "%s requires two or more chunks", @@ -69,9 +70,14 @@ sr_concat_create(struct sr_discipline *sd, struct bioc_createraid *bc, } sd->sd_meta->ssdi.ssd_size = 0; - for (i = 0; i < no_chunk; i++) + secsize = 0; + for (i = 0; i < no_chunk; i++) { + if (sd->sd_vol.sv_chunks[i]->src_secsize > secsize) + secsize = sd->sd_vol.sv_chunks[i]->src_secsize; sd->sd_meta->ssdi.ssd_size += sd->sd_vol.sv_chunks[i]->src_size; + } + sd->sd_meta->ssdi.ssd_secsize = secsize; return sr_concat_init(sd); } diff --git a/sys/dev/softraid_crypto.c b/sys/dev/softraid_crypto.c index 499125e3d44..0fdc858c065 100644 --- a/sys/dev/softraid_crypto.c +++ b/sys/dev/softraid_crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_crypto.c,v 1.124 2015/12/29 04:46:28 mmcc Exp $ */ +/* $OpenBSD: softraid_crypto.c,v 1.125 2016/04/04 18:48:39 krw Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Hans-Joerg Hoexer <hshoexer@openbsd.org> @@ -179,6 +179,7 @@ sr_crypto_create(struct sr_discipline *sd, struct bioc_createraid *bc, goto done; sd->sd_meta->ssdi.ssd_size = coerced_size; + sd->sd_meta->ssdi.ssd_secsize = sd->sd_vol.sv_chunks[0]->src_secsize; sr_crypto_create_keys(sd); @@ -650,11 +651,6 @@ sr_crypto_create_key_disk(struct sr_discipline *sd, dev_t dev) vput(vn); goto fail; } - if (label.d_secsize != DEV_BSIZE) { - sr_error(sc, "%s has unsupported sector size (%d)", - devname, label.d_secsize); - goto fail; - } if (label.d_partitions[part].p_fstype != FS_RAID) { sr_error(sc, "%s partition not of type RAID (%d)", devname, label.d_partitions[part].p_fstype); @@ -820,11 +816,6 @@ sr_crypto_read_key_disk(struct sr_discipline *sd, dev_t dev) vput(vn); goto done; } - if (label.d_secsize != DEV_BSIZE) { - sr_error(sc, "%s has unsupported sector size (%d)", - devname, label.d_secsize); - goto done; - } if (label.d_partitions[part].p_fstype != FS_RAID) { sr_error(sc, "%s partition not of type RAID (%d)", devname, label.d_partitions[part].p_fstype); diff --git a/sys/dev/softraid_raid0.c b/sys/dev/softraid_raid0.c index fa0c6f076b1..f5d0af286f3 100644 --- a/sys/dev/softraid_raid0.c +++ b/sys/dev/softraid_raid0.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid0.c,v 1.50 2015/07/21 03:30:51 krw Exp $ */ +/* $OpenBSD: softraid_raid0.c,v 1.51 2016/04/04 18:48:39 krw Exp $ */ /* * Copyright (c) 2008 Marco Peereboom <marco@peereboom.us> * @@ -69,12 +69,22 @@ int sr_raid0_create(struct sr_discipline *sd, struct bioc_createraid *bc, int no_chunk, int64_t coerced_size) { + int i; + u_int32_t secsize; + if (no_chunk < 2) { sr_error(sd->sd_sc, "%s requires two or more chunks", sd->sd_name); return EINVAL; } + secsize = 0; + for (i = 0; i < no_chunk; i++) { + if (sd->sd_vol.sv_chunks[i]->src_secsize > secsize) + secsize = sd->sd_vol.sv_chunks[i]->src_secsize; + } + sd->sd_meta->ssdi.ssd_secsize = secsize; + /* * XXX add variable strip size later even though MAXPHYS is really * the clever value, users like to tinker with that type of stuff. diff --git a/sys/dev/softraid_raid1.c b/sys/dev/softraid_raid1.c index 4bb766bf550..5a6e2b21254 100644 --- a/sys/dev/softraid_raid1.c +++ b/sys/dev/softraid_raid1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid1.c,v 1.63 2015/07/21 03:30:51 krw Exp $ */ +/* $OpenBSD: softraid_raid1.c,v 1.64 2016/04/04 18:48:39 krw Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * @@ -76,12 +76,21 @@ int sr_raid1_create(struct sr_discipline *sd, struct bioc_createraid *bc, int no_chunk, int64_t coerced_size) { + int i; + u_int32_t secsize; + if (no_chunk < 2) { sr_error(sd->sd_sc, "%s requires two or more chunks", sd->sd_name); return EINVAL; } + secsize = 0; + for (i = 0; i < no_chunk; i++) { + if (sd->sd_vol.sv_chunks[i]->src_secsize > secsize) + secsize = sd->sd_vol.sv_chunks[i]->src_secsize; + } + sd->sd_meta->ssdi.ssd_secsize = secsize; sd->sd_meta->ssdi.ssd_size = coerced_size; return sr_raid1_init(sd); diff --git a/sys/dev/softraid_raid5.c b/sys/dev/softraid_raid5.c index ee0c7fddc1b..bf886bba3a5 100644 --- a/sys/dev/softraid_raid5.c +++ b/sys/dev/softraid_raid5.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid5.c,v 1.23 2015/07/21 03:30:51 krw Exp $ */ +/* $OpenBSD: softraid_raid5.c,v 1.24 2016/04/04 18:48:39 krw Exp $ */ /* * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> * Copyright (c) 2009 Marco Peereboom <marco@peereboom.us> @@ -96,12 +96,22 @@ int sr_raid5_create(struct sr_discipline *sd, struct bioc_createraid *bc, int no_chunk, int64_t coerced_size) { + int i; + u_int32_t secsize; + if (no_chunk < 3) { sr_error(sd->sd_sc, "%s requires three or more chunks", sd->sd_name); return EINVAL; } + secsize = sd->sd_vol.sv_chunks[0]->src_secsize; + for (i = 0; i < no_chunk; i++) { + if (sd->sd_vol.sv_chunks[i]->src_secsize > secsize) + secsize = sd->sd_vol.sv_chunks[i]->src_secsize; + } + sd->sd_meta->ssdi.ssd_secsize = secsize; + /* * XXX add variable strip size later even though MAXPHYS is really * the clever value, users like to tinker with that type of stuff. diff --git a/sys/dev/softraid_raid6.c b/sys/dev/softraid_raid6.c index 8afa6f5662e..62f124f80c9 100644 --- a/sys/dev/softraid_raid6.c +++ b/sys/dev/softraid_raid6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid6.c,v 1.69 2015/07/21 03:30:51 krw Exp $ */ +/* $OpenBSD: softraid_raid6.c,v 1.70 2016/04/04 18:48:39 krw Exp $ */ /* * Copyright (c) 2009 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2009 Jordan Hargrave <jordan@openbsd.org> @@ -112,12 +112,22 @@ int sr_raid6_create(struct sr_discipline *sd, struct bioc_createraid *bc, int no_chunk, int64_t coerced_size) { + int i; + u_int32_t secsize; + if (no_chunk < 4) { sr_error(sd->sd_sc, "%s requires four or more chunks", sd->sd_name); return EINVAL; } + secsize = 0; + for (i = 0; i < no_chunk; i++) { + if (sd->sd_vol.sv_chunks[i]->src_secsize > secsize) + secsize = sd->sd_vol.sv_chunks[i]->src_secsize; + } + sd->sd_meta->ssdi.ssd_secsize = secsize; + /* * XXX add variable strip size later even though MAXPHYS is really * the clever value, users like * to tinker with that type of stuff. diff --git a/sys/dev/softraidvar.h b/sys/dev/softraidvar.h index 86f757c344b..00e7ba4c61b 100644 --- a/sys/dev/softraidvar.h +++ b/sys/dev/softraidvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: softraidvar.h,v 1.161 2015/07/21 03:30:51 krw Exp $ */ +/* $OpenBSD: softraidvar.h,v 1.162 2016/04/04 18:48:39 krw Exp $ */ /* * Copyright (c) 2006 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> @@ -19,7 +19,7 @@ #ifndef SOFTRAIDVAR_H #define SOFTRAIDVAR_H -#define SR_META_VERSION 5 /* bump when sr_metadata changes */ +#define SR_META_VERSION 6 /* bump when sr_metadata changes */ #define SR_META_SIZE 64 /* save space at chunk beginning */ #define SR_META_OFFSET 16 /* skip 8192 bytes at chunk beginning */ @@ -135,7 +135,7 @@ struct sr_metadata { /* optional */ u_int32_t ssd_opt_no; /* nr of optional md elements */ - u_int32_t ssd_pad; + u_int32_t ssd_secsize; /* volume metadata */ u_int32_t ssd_volid; /* volume id */ @@ -473,6 +473,7 @@ struct sr_chunk { char src_devname[32]; u_char src_duid[8]; /* Chunk disklabel UID. */ int64_t src_size; /* in blocks */ + u_int32_t src_secsize; SLIST_ENTRY(sr_chunk) src_link; }; |