From d85bfa1067be4f063cbfaa5207eee2492b2f0f0c Mon Sep 17 00:00:00 2001 From: Greg Lehey Date: Fri, 9 Apr 1999 01:20:22 +0000 Subject: update_plex_config: Eliminate a potential divide-by-zero. Tripped-over-by: Karl Pielorz --- sys/dev/vinum/vinumconfig.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/vinum/vinumconfig.c b/sys/dev/vinum/vinumconfig.c index 7fc6520bd860..67cd1c64b5ec 100644 --- a/sys/dev/vinum/vinumconfig.c +++ b/sys/dev/vinum/vinumconfig.c @@ -1826,19 +1826,21 @@ update_plex_config(int plexno, int diskconfig) * the stripe size. If not, trim off the end * of each subdisk and return it to the drive. */ - remainder = (int) (plex->length % ((u_int64_t) plex->stripesize * data_sds)); /* are we exact? */ - if (remainder) { /* no */ - log(LOG_INFO, "vinum: removing %d blocks of partial stripe at the end of %s\n", - remainder, - plex->name); - plex->length -= remainder; /* shorten the plex */ - remainder /= data_sds; /* spread the remainder amongst the sds */ - for (sdno = 0; sdno < plex->subdisks; sdno++) { - sd = &SD[plex->sdnos[sdno]]; /* point to the subdisk */ - return_drive_space(sd->driveno, /* return the space */ - sd->driveoffset + sd->sectors - remainder, - remainder); - sd->sectors -= remainder; /* and shorten it */ + if (plex->length > 0) { + remainder = (int) (plex->length % ((u_int64_t) plex->stripesize * data_sds)); /* are we exact? */ + if (remainder) { /* no */ + log(LOG_INFO, "vinum: removing %d blocks of partial stripe at the end of %s\n", + remainder, + plex->name); + plex->length -= remainder; /* shorten the plex */ + remainder /= data_sds; /* spread the remainder amongst the sds */ + for (sdno = 0; sdno < plex->subdisks; sdno++) { + sd = &SD[plex->sdnos[sdno]]; /* point to the subdisk */ + return_drive_space(sd->driveno, /* return the space */ + sd->driveoffset + sd->sectors - remainder, + remainder); + sd->sectors -= remainder; /* and shorten it */ + } } } } -- cgit v1.3