From 08249e9e6eea8e11cb2df2c69ccb808c63964932 Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Sat, 28 Aug 2004 02:34:10 +0000 Subject: [PATCH] Warn the user if we are not going to use whole provider space. Requested by: Michael Handler --- sbin/geom/class/raid3/geom_raid3.c | 14 +++++++++----- sys/geom/raid3/g_raid3_ctl.c | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/sbin/geom/class/raid3/geom_raid3.c b/sbin/geom/class/raid3/geom_raid3.c index 8e507ec037f2..1d948b4bb4b8 100644 --- a/sbin/geom/class/raid3/geom_raid3.c +++ b/sbin/geom/class/raid3/geom_raid3.c @@ -149,8 +149,8 @@ raid3_label(struct gctl_req *req) char param[16]; int *hardcode, *nargs, *noautosync, *round_robin, *verify; int error, i; - unsigned sectorsize; - off_t mediasize; + unsigned sectorsize, ssize; + off_t mediasize, msize; nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); if (nargs == NULL) { @@ -222,9 +222,6 @@ raid3_label(struct gctl_req *req) mediasize = 0; sectorsize = 0; for (i = 1; i < *nargs; i++) { - unsigned ssize; - off_t msize; - snprintf(param, sizeof(param), "arg%u", i); str = gctl_get_asciiparam(req, param); @@ -268,6 +265,13 @@ raid3_label(struct gctl_req *req) snprintf(param, sizeof(param), "arg%u", i); str = gctl_get_asciiparam(req, param); + msize = g_get_mediasize(str) - g_get_sectorsize(str); + if (mediasize < msize) { + fprintf(stderr, + "warning: %s: only %jd bytes from %jd bytes used.\n", + str, (intmax_t)mediasize, (intmax_t)msize); + } + md.md_no = i - 1; if (!*hardcode) bzero(md.md_provider, sizeof(md.md_provider)); diff --git a/sys/geom/raid3/g_raid3_ctl.c b/sys/geom/raid3/g_raid3_ctl.c index 8fa67261e3c8..94ec67ec4ee8 100644 --- a/sys/geom/raid3/g_raid3_ctl.c +++ b/sys/geom/raid3/g_raid3_ctl.c @@ -338,6 +338,7 @@ g_raid3_ctl_insert(struct gctl_req *req, struct g_class *mp) struct g_consumer *cp; const char *name; u_char *sector; + off_t compsize; intmax_t *no; int *hardcode, *nargs, error; @@ -390,16 +391,23 @@ g_raid3_ctl_insert(struct gctl_req *req, struct g_class *mp) gctl_error(req, "Invalid provider."); return; } - if ((sc->sc_mediasize / (sc->sc_ndisks - 1)) > pp->mediasize) { - gctl_error(req, "Provider %s too small.", pp->name); - return; - } if (((sc->sc_sectorsize / (sc->sc_ndisks - 1)) % pp->sectorsize) != 0) { gctl_error(req, "Cannot insert provider %s, because of its sector size.", pp->name); return; } + compsize = sc->sc_mediasize / (sc->sc_ndisks - 1); + if (compsize > pp->mediasize - pp->sectorsize) { + gctl_error(req, "Provider %s too small.", pp->name); + return; + } + if (compsize < pp->mediasize - pp->sectorsize) { + gctl_error(req, + "warning: %s: only %jd bytes from %jd bytes used.", + pp->name, (intmax_t)compsize, + (intmax_t)(pp->mediasize - pp->sectorsize)); + } gp = g_new_geomf(mp, "raid3:insert"); gp->orphan = g_raid3_ctl_insert_orphan; cp = g_new_consumer(gp);