summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/dev/softraid.c44
-rw-r--r--sys/dev/softraid_raid5.c18
-rw-r--r--sys/dev/softraidvar.h3
3 files changed, 25 insertions, 40 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c
index 15ace3bd556..d66adb6d658 100644
--- a/sys/dev/softraid.c
+++ b/sys/dev/softraid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid.c,v 1.375 2016/04/29 14:01:37 krw Exp $ */
+/* $OpenBSD: softraid.c,v 1.376 2016/05/31 15:19:12 jsing Exp $ */
/*
* Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org>
@@ -2600,7 +2600,6 @@ sr_ioctl_vol(struct sr_softc *sc, struct bioc_vol *bv)
int vol = -1, rv = EINVAL;
struct sr_discipline *sd;
struct sr_chunk *hotspare;
- int64_t rb, sz;
TAILQ_FOREACH(sd, &sc->sc_dis_list, sd_link) {
vol++;
@@ -2617,16 +2616,8 @@ sr_ioctl_vol(struct sr_softc *sc, struct bioc_vol *bv)
sd->mds.mdd_crypto.key_disk != NULL)
bv->bv_nodisk++;
#endif
+ bv->bv_percent = sr_rebuild_percent(sd);
- if (bv->bv_status == BIOC_SVREBUILD) {
- sz = sd->sd_meta->ssdi.ssd_size;
- rb = sd->sd_meta->ssd_rebuild;
- if (rb > 0)
- bv->bv_percent = 100 -
- ((sz * 100 - rb * 100) / sz) - 1;
- else
- bv->bv_percent = 0;
- }
strlcpy(bv->bv_dev, sd->sd_meta->ssd_devname,
sizeof(bv->bv_dev));
strlcpy(bv->bv_vendor, sd->sd_meta->ssdi.ssd_vendor,
@@ -3269,6 +3260,20 @@ done:
return (rv);
}
+int
+sr_rebuild_percent(struct sr_discipline *sd)
+{
+ daddr_t rb, sz;
+
+ sz = sd->sd_meta->ssdi.ssd_size;
+ rb = sd->sd_meta->ssd_rebuild;
+
+ if (rb > 0)
+ return (100 - ((sz * 100 - rb * 100) / sz) - 1);
+
+ return (0);
+}
+
void
sr_roam_chunks(struct sr_discipline *sd)
{
@@ -4637,9 +4642,8 @@ void
sr_rebuild(struct sr_discipline *sd)
{
struct sr_softc *sc = sd->sd_sc;
- u_int64_t sz, psz, whole_blk, partial_blk, blk, restart;
+ u_int64_t sz, whole_blk, partial_blk, blk, restart;
daddr_t lba;
- int64_t rb;
struct sr_workunit *wu_r, *wu_w;
struct scsi_xfer xs_r, xs_w;
struct scsi_rw_16 *cr, *cw;
@@ -4665,12 +4669,7 @@ sr_rebuild(struct sr_discipline *sd)
* replaced). We need to check the uuid of the chunk that is
* being rebuilt to assert this.
*/
- psz = sd->sd_meta->ssdi.ssd_size;
- rb = sd->sd_meta->ssd_rebuild;
- if (rb > 0)
- percent = 100 - ((psz * 100 - rb * 100) / psz) - 1;
- else
- percent = 0;
+ percent = sr_rebuild_percent(sd);
printf("%s: resuming rebuild on %s at %d%%\n",
DEVNAME(sc), sd->sd_meta->ssd_devname, percent);
}
@@ -4768,12 +4767,7 @@ sr_rebuild(struct sr_discipline *sd)
/* XXX - this should be based on size, not percentage. */
/* save metadata every percent */
- psz = sd->sd_meta->ssdi.ssd_size;
- rb = sd->sd_meta->ssd_rebuild;
- if (rb > 0)
- percent = 100 - ((psz * 100 - rb * 100) / psz) - 1;
- else
- percent = 0;
+ percent = sr_rebuild_percent(sd);
if (percent != old_percent && blk != whole_blk) {
if (sr_meta_save(sd, SR_META_DIRTY))
printf("%s: could not save metadata to %s\n",
diff --git a/sys/dev/softraid_raid5.c b/sys/dev/softraid_raid5.c
index 934be2677cf..192ceae057d 100644
--- a/sys/dev/softraid_raid5.c
+++ b/sys/dev/softraid_raid5.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid_raid5.c,v 1.25 2016/04/12 16:26:54 krw Exp $ */
+/* $OpenBSD: softraid_raid5.c,v 1.26 2016/05/31 15:19:12 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
* Copyright (c) 2009 Marco Peereboom <marco@peereboom.us>
@@ -765,7 +765,7 @@ sr_raid5_xor(void *a, void *b, int len)
void
sr_raid5_rebuild(struct sr_discipline *sd)
{
- int64_t strip_no, strip_size, strip_bits, i, psz, rb, restart;
+ int64_t strip_no, strip_size, strip_bits, i, restart;
int64_t chunk_count, chunk_strips, chunk_lba, chunk_size, row_size;
struct sr_workunit *wu_r, *wu_w;
int s, slept, percent = 0, old_percent = -1;
@@ -802,12 +802,7 @@ sr_raid5_rebuild(struct sr_discipline *sd)
restart = 0;
}
if (restart != 0) {
- psz = sd->sd_meta->ssdi.ssd_size;
- rb = sd->sd_meta->ssd_rebuild;
- if (rb > 0)
- percent = 100 - ((psz * 100 - rb * 100) / psz) - 1;
- else
- percent = 0;
+ percent = sr_rebuild_percent(sd);
printf("%s: resuming rebuild on %s at %d%%\n",
DEVNAME(sd->sd_sc), sd->sd_meta->ssd_devname, percent);
}
@@ -867,12 +862,7 @@ sr_raid5_rebuild(struct sr_discipline *sd)
sd->sd_meta->ssd_rebuild = chunk_lba * chunk_count;
- psz = sd->sd_meta->ssdi.ssd_size;
- rb = sd->sd_meta->ssd_rebuild;
- if (rb > 0)
- percent = 100 - ((psz * 100 - rb * 100) / psz) - 1;
- else
- percent = 0;
+ percent = sr_rebuild_percent(sd);
if (percent != old_percent && strip_no != chunk_strips - 1) {
if (sr_meta_save(sd, SR_META_DIRTY))
printf("%s: could not save metadata to %s\n",
diff --git a/sys/dev/softraidvar.h b/sys/dev/softraidvar.h
index 00e7ba4c61b..d71fc35cdf2 100644
--- a/sys/dev/softraidvar.h
+++ b/sys/dev/softraidvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraidvar.h,v 1.162 2016/04/04 18:48:39 krw Exp $ */
+/* $OpenBSD: softraidvar.h,v 1.163 2016/05/31 15:19:12 jsing Exp $ */
/*
* Copyright (c) 2006 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org>
@@ -687,6 +687,7 @@ struct sr_workunit *sr_scsi_wu_get(struct sr_discipline *, int);
void sr_scsi_wu_put(struct sr_discipline *,
struct sr_workunit *);
int sr_chunk_in_use(struct sr_softc *, dev_t);
+int sr_rebuild_percent(struct sr_discipline *);
/* discipline functions */
int sr_raid_inquiry(struct sr_workunit *);