> On 17 Sep 2026, at 02:29, Kenneth Westerback <[email protected]> wrote:
>
> Pushing Claudio's suggestion into potentially reductio ad absurdum
> territory, does this version work?
>
> It seems to read better to me if it does work.
>
> I leave off the separate issue of freeing the work units. I definitely
> lack the knowledge to know how good an idea that is.
>
> I have 4K disks but no softraid, I only get dragged into softraid when
> it's original sin of mixing bytes, DEV_BSIZE and disk sector values into
> various fields blows something up. :-)
> --
> .... Ken
Hi, I had a second take at your diff, sadly I think I found some issues… :)
>
> diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c
> index 60c5eb0bc02..b4b042c7f89 100644
> --- a/sys/dev/softraid.c
> +++ b/sys/dev/softraid.c
> @@ -4677,24 +4677,25 @@ void
> sr_rebuild(struct sr_discipline *sd)
> {
> struct sr_softc *sc = sd->sd_sc;
> - u_int64_t sz, whole_blk, partial_blk, blk, restart;
> - daddr_t lba;
> + u_int64_t io_bytes, partial_io;
> + u_int64_t restart_lba, lba, final_lba;
> + u_int32_t sec_size;
> struct sr_workunit *wu_r, *wu_w;
> struct scsi_xfer xs_r, xs_w;
> struct scsi_rw_16 *cr, *cw;
> int c, s, slept, percent = 0, old_percent = -1;
> u_int8_t *buf;
>
> - whole_blk = sd->sd_meta->ssdi.ssd_size / SR_REBUILD_IO_SIZE;
> - partial_blk = sd->sd_meta->ssdi.ssd_size % SR_REBUILD_IO_SIZE;
> + sec_size = sd->sd_meta->ssdi.ssd_secsize;
> + restart_lba = sd->sd_meta->ssd_rebuild / (sec_size / DEV_BSIZE);
> + final_lba = ((sd->sd_meta->ssdi.ssd_size / SR_REBUILD_IO_SIZE) *
> SR_REBUILD_IO_SIZE) / sec_size;
This does not seem right, ssd_size is measured in DEV_BSIZE blocks, while
sec_size is bytes.
This seems to make the final_lba off by a factor of 1/512 :)
Adding an explicit blokes per sector variable might make this cleaner:
blks_per_sec = secsize / DEV_BSIZE;
secs_per_io = SR_REBUILD_IO_SIZE / blks_per_sec;
restart_lba = sd->sd_meta->ssd_rebuild / blks_per_sec;
final_lba = sd->sd_meta->ssdi.ssd_size / blks_per_sec;
>
> - restart = sd->sd_meta->ssd_rebuild / SR_REBUILD_IO_SIZE;
> - if (restart > whole_blk) {
> + if (restart_lba > final_lba) {
> printf("%s: bogus rebuild restart offset, starting from 0\n",
> DEVNAME(sc));
> - restart = 0;
> + restart_lba = 0;
> }
> - if (restart) {
> + if (restart_lba) {
> /*
> * XXX there is a hole here; there is a possibility that we
> * had a restart however the chunk that was supposed to
> @@ -4710,14 +4711,16 @@ sr_rebuild(struct sr_discipline *sd)
> }
>
> /* currently this is 64k therefore we can use dma_alloc */
> - buf = dma_alloc(SR_REBUILD_IO_SIZE << DEV_BSHIFT, PR_WAITOK);
> - for (blk = restart; blk <= whole_blk; blk++) {
> - lba = blk * SR_REBUILD_IO_SIZE;
> - sz = SR_REBUILD_IO_SIZE;
> - if (blk == whole_blk) {
> - if (partial_blk == 0)
> + io_bytes = SR_REBUILD_IO_SIZE << DEV_BSHIFT;
> + buf = dma_alloc(io_bytes, PR_WAITOK);
> +
> + partial_io = (sd->sd_meta->ssdi.ssd_size % SR_REBUILD_IO_SIZE) <<
> DEV_BSHIFT;
I believe this should be routed to sec_size
> +
> + for (lba = restart_lba; lba <= final_lba; lba += io_bytes / sec_size ) {
> + if (lba == final_lba) {
> + if (partial_io == 0)
> break;
> - sz = partial_blk;
> + io_bytes = partial_io;
> }
>
> /* get some wu */
> @@ -4731,12 +4734,12 @@ sr_rebuild(struct sr_discipline *sd)
> bzero(&xs_r, sizeof xs_r);
> xs_r.error = XS_NOERROR;
> xs_r.flags = SCSI_DATA_IN;
> - xs_r.datalen = sz << DEV_BSHIFT;
> + xs_r.datalen = io_bytes;
> xs_r.data = buf;
> xs_r.cmdlen = sizeof(*cr);
> cr = (struct scsi_rw_16 *)&xs_r.cmd;
> cr->opcode = READ_16;
> - _lto4b(sz, cr->length);
> + _lto4b(io_bytes / sec_size, cr->length);
> _lto8b(lba, cr->addr);
> wu_r->swu_state = SR_WU_CONSTRUCT;
> wu_r->swu_flags |= SR_WUF_REBUILD;
> @@ -4751,12 +4754,12 @@ sr_rebuild(struct sr_discipline *sd)
> bzero(&xs_w, sizeof xs_w);
> xs_w.error = XS_NOERROR;
> xs_w.flags = SCSI_DATA_OUT;
> - xs_w.datalen = sz << DEV_BSHIFT;
> + xs_w.datalen = io_bytes;
> xs_w.data = buf;
> xs_w.cmdlen = sizeof(*cw);
> cw = (struct scsi_rw_16 *)&xs_w.cmd;
> cw->opcode = WRITE_16;
> - _lto4b(sz, cw->length);
> + _lto4b(io_bytes / sec_size , cr->length);
The above should use cw not cr
> _lto8b(lba, cw->addr);
> wu_w->swu_state = SR_WU_CONSTRUCT;
> wu_w->swu_flags |= SR_WUF_REBUILD | SR_WUF_WAKEUP;
> @@ -4796,12 +4799,12 @@ sr_rebuild(struct sr_discipline *sd)
> sr_scsi_wu_put(sd, wu_r);
> sr_scsi_wu_put(sd, wu_w);
>
> - sd->sd_meta->ssd_rebuild = lba;
> + sd->sd_meta->ssd_rebuild = lba * (sec_size / DEV_BSIZE);
>
> /* XXX - this should be based on size, not percentage. */
> /* save metadata every percent */
> percent = sr_rebuild_percent(sd);
> - if (percent != old_percent && blk != whole_blk) {
> + if (percent != old_percent && lba != final_lba) {
> if (sr_meta_save(sd, SR_META_DIRTY))
> printf("%s: could not save metadata to %s\n",
> DEVNAME(sc), sd->sd_meta->ssd_devname);
I think the attached diff fixes those issue, I’ve tested it,
seems to be working, a sync of a larger partition is still
ongoing but has already passed all the critical points. Will
Report back when it passes 100% and throwing away the healthy
Chunk results in clean fsck.
greets
Dariusz Swiderski
--
A mouse is a device used to point at the xterm you want to type in.
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c
index 60c5eb0bc02..ae433420ea5 100644
--- a/sys/dev/softraid.ceta->ssd_rebuild = lba;
+++ b/sys/dev/softraid.ceta->ssd_rebuild = lba * blks_per_sec;
@@ -4677,24 +4677,26 @@ void
sr_rebuild(struct sr_discipline *sd)be based on size, not percentage. */
{ /* save metadata every percent */
struct sr_softc *sc = sd->sd_sc;;
- u_int64_t sz, whole_blk, partial_blk, blk, restart;
- daddr_t lba;ercent && lba + nsecs < final_lba) {
+ u_int64_t restart_lba, lba, final_lba;
+ u_int32_t io_bytes, secsize, blks_per_sec;ata to %s\n",
+ u_int32_t secs_per_io, nsecs;->sd_meta->ssd_devname);
struct sr_workunit *wu_r, *wu_w;
struct scsi_xfer xs_r, xs_w;
struct scsi_rw_16 *cr, *cw;
int c, s, slept, percent = 0, old_percent = -1;
u_int8_t *buf;
- whole_blk = sd->sd_meta->ssdi.ssd_size / SR_REBUILD_IO_SIZE;
- partial_blk = sd->sd_meta->ssdi.ssd_size % SR_REBUILD_IO_SIZE;
-
- restart = sd->sd_meta->ssd_rebuild / SR_REBUILD_IO_SIZE;
- if (restart > whole_blk) {
+ secsize = sd->sd_meta->ssdi.ssd_secsize;
+ blks_per_sec = secsize / DEV_BSIZE;
+ secs_per_io = SR_REBUILD_IO_SIZE / blks_per_sec;
+ restart_lba = sd->sd_meta->ssd_rebuild / blks_per_sec;
+ final_lba = sd->sd_meta->ssdi.ssd_size / blks_per_sec;
+ if (restart_lba > final_lba) {
printf("%s: bogus rebuild restart offset, starting from 0\n",
DEVNAME(sc));
- restart = 0;
+ restart_lba = 0;
}
- if (restart) {
+ if (restart_lba) {
/*
* XXX there is a hole here; there is a possibility that we
* had a restart however the chunk that was supposed to
@@ -4711,14 +4713,9 @@ sr_rebuild(struct sr_discipline *sd)
/* currently this is 64k therefore we can use dma_alloc */
buf = dma_alloc(SR_REBUILD_IO_SIZE << DEV_BSHIFT, PR_WAITOK);
- for (blk = restart; blk <= whole_blk; blk++) {
- lba = blk * SR_REBUILD_IO_SIZE;
- sz = SR_REBUILD_IO_SIZE;
- if (blk == whole_blk) {
- if (partial_blk == 0)
- break;
- sz = partial_blk;
- }
+ for (lba = restart_lba; lba < final_lba; lba += secs_per_io) {
+ nsecs = MIN(secs_per_io, final_lba - lba);
+ io_bytes = nsecs * secsize;
/* get some wu */
wu_r = sr_scsi_wu_get(sd, 0);
@@ -4731,12 +4728,12 @@ sr_rebuild(struct sr_discipline *sd)
bzero(&xs_r, sizeof xs_r);
xs_r.error = XS_NOERROR;
xs_r.flags = SCSI_DATA_IN;
- xs_r.datalen = sz << DEV_BSHIFT;
+ xs_r.datalen = io_bytes;
xs_r.data = buf;
xs_r.cmdlen = sizeof(*cr);
cr = (struct scsi_rw_16 *)&xs_r.cmd;
cr->opcode = READ_16;
- _lto4b(sz, cr->length);
+ _lto4b(nsecs, cr->length);
_lto8b(lba, cr->addr);
wu_r->swu_state = SR_WU_CONSTRUCT;
wu_r->swu_flags |= SR_WUF_REBUILD;
@@ -4751,12 +4748,12 @@ sr_rebuild(struct sr_discipline *sd)
bzero(&xs_w, sizeof xs_w);
xs_w.error = XS_NOERROR;
xs_w.flags = SCSI_DATA_OUT;
- xs_w.datalen = sz << DEV_BSHIFT;
+ xs_w.datalen = io_bytes;
xs_w.data = buf;
xs_w.cmdlen = sizeof(*cw);
cw = (struct scsi_rw_16 *)&xs_w.cmd;
cw->opcode = WRITE_16;
- _lto4b(sz, cw->length);
+ _lto4b(nsecs, cw->length);
_lto8b(lba, cw->addr);
wu_w->swu_state = SR_WU_CONSTRUCT;
wu_w->swu_flags |= SR_WUF_REBUILD | SR_WUF_WAKEUP;
@@ -4796,12 +4793,12 @@ sr_rebuild(struct sr_discipline *sd)
sr_scsi_wu_put(sd, wu_r);
sr_scsi_wu_put(sd, wu_w);
- sd->sd_meta->ssd_rebuild = lba;
+ sd->sd_meta->ssd_rebuild = lba * blks_per_sec;
/* XXX - this should be based on size, not percentage. */
/* save metadata every percent */
percent = sr_rebuild_percent(sd);
- if (percent != old_percent && blk != whole_blk) {
+ if (percent != old_percent && lba + nsecs < final_lba) {
if (sr_meta_save(sd, SR_META_DIRTY))
printf("%s: could not save metadata to %s\n",
DEVNAME(sc), sd->sd_meta->ssd_devname);