diff options
author | phk <phk@FreeBSD.org> | 2002-10-20 20:28:24 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2002-10-20 20:28:24 +0000 |
commit | af63f9546ade194575238522dacd38cebe3b63f6 (patch) | |
tree | 4be4d44cd73707526477ac8dedf166de6841e46d /sys | |
parent | f0693daa1f5896bbd37f2ad85ba732389ac99646 (diff) | |
download | FreeBSD-src-af63f9546ade194575238522dacd38cebe3b63f6.zip FreeBSD-src-af63f9546ade194575238522dacd38cebe3b63f6.tar.gz |
Now that the sectorsize and mediasize are properties of the provider,
don't take the detour over the I/O path to discover them using getattr(),
we can just pick them out directly.
Do note though, that for now they are only valid after the first open
of the underlying disk device due compatibility with the old disk_create()
API. This will change in the future so they will always be valid.
Sponsored by: DARPA & NAI Labs.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/geom/bde/g_bde.c | 12 | ||||
-rw-r--r-- | sys/geom/geom_aes.c | 13 | ||||
-rw-r--r-- | sys/geom/geom_bsd.c | 18 | ||||
-rw-r--r-- | sys/geom/geom_ctl.c | 1 | ||||
-rw-r--r-- | sys/geom/geom_dev.c | 14 | ||||
-rw-r--r-- | sys/geom/geom_disk.c | 12 | ||||
-rw-r--r-- | sys/geom/geom_gpt.c | 4 | ||||
-rw-r--r-- | sys/geom/geom_mbr.c | 8 | ||||
-rw-r--r-- | sys/geom/geom_pc98.c | 16 | ||||
-rw-r--r-- | sys/geom/geom_slice.c | 11 | ||||
-rw-r--r-- | sys/geom/geom_sunlabel.c | 16 |
11 files changed, 38 insertions, 87 deletions
diff --git a/sys/geom/bde/g_bde.c b/sys/geom/bde/g_bde.c index 614139c..aaf6323 100644 --- a/sys/geom/bde/g_bde.c +++ b/sys/geom/bde/g_bde.c @@ -68,10 +68,6 @@ g_bde_start(struct bio *bp) break; case BIO_GETATTR: case BIO_SETATTR: - if (g_handleattr_off_t(bp, "GEOM::mediasize", sc->mediasize)) - return; - if (g_handleattr_int(bp, "GEOM::sectorsize", sc->sectorsize)) - return; g_io_deliver(bp, EOPNOTSUPP); break; default: @@ -213,12 +209,8 @@ g_bde_create(struct g_createargs *ga) } g_topology_unlock(); while (1) { - error = g_getattr("GEOM::sectorsize", cp, §orsize); - if (error) - break; - error = g_getattr("GEOM::mediasize", cp, &mediasize); - if (error) - break; + sectorsize = cp->provider->sectorsize; + mediasize = cp->provider->mediasize; sc = g_malloc(sizeof(struct g_bde_softc), M_WAITOK | M_ZERO); gp->softc = sc; sc->geom = gp; diff --git a/sys/geom/geom_aes.c b/sys/geom/geom_aes.c index 6aae347..fae7f34 100644 --- a/sys/geom/geom_aes.c +++ b/sys/geom/geom_aes.c @@ -229,10 +229,6 @@ g_aes_start(struct bio *bp) break; case BIO_GETATTR: case BIO_SETATTR: - if (g_handleattr_off_t(bp, "GEOM::mediasize", sc->mediasize)) - return; - if (g_handleattr_int(bp, "GEOM::sectorsize", sc->sectorsize)) - return; bp2 = g_clone_bio(bp); if (bp2 == NULL) { g_io_deliver(bp, ENOMEM); @@ -320,12 +316,8 @@ g_aes_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) while (1) { if (gp->rank != 2) break; - error = g_getattr("GEOM::sectorsize", cp, §orsize); - if (error) - break; - error = g_getattr("GEOM::mediasize", cp, &mediasize); - if (error) - break; + sectorsize = cp->provider->sectorsize; + mediasize = cp->provider->mediasize; buf = g_read_data(cp, 0, sectorsize, &error); if (buf == NULL || error != 0) { break; @@ -373,6 +365,7 @@ g_aes_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) g_topology_lock(); pp = g_new_providerf(gp, gp->name); pp->mediasize = mediasize - sectorsize; + pp->sectorsize = sectorsize; g_error_provider(pp, 0); g_topology_unlock(); break; diff --git a/sys/geom/geom_bsd.c b/sys/geom/geom_bsd.c index f8688e1..9446186 100644 --- a/sys/geom/geom_bsd.c +++ b/sys/geom/geom_bsd.c @@ -319,12 +319,8 @@ g_bsd_modify(struct g_geom *gp, struct disklabel *dl) /* Get dimensions of our device. */ cp = LIST_FIRST(&gp->consumer); - error = g_getattr("GEOM::sectorsize", cp, &secsize); - if (error) - return (error); - error = g_getattr("GEOM::mediasize", cp, &mediasize); - if (error) - return (error); + secsize = cp->provider->sectorsize; + mediasize = cp->provider->mediasize; #ifdef nolonger /* @@ -513,11 +509,7 @@ g_bsd_ioctl(void *arg) KASSERT(gio->cmd == DIOCWDINFO, ("Unknown ioctl in g_bsd_ioctl")); cp = LIST_FIRST(&gp->consumer); /* Get sector size, we need it to read data. */ - error = g_getattr("GEOM::sectorsize", cp, &secsize); - if (error || secsize < 512) { - g_io_deliver(bp, error); - return; - } + secsize = cp->provider->sectorsize; secoff = ms->labeloffset % secsize; buf = g_read_data(cp, ms->labeloffset - secoff, secsize, &error); if (buf == NULL || error != 0) { @@ -703,8 +695,8 @@ g_bsd_taste(struct g_class *mp, struct g_provider *pp, int flags) break; /* Get sector size, we need it to read data. */ - error = g_getattr("GEOM::sectorsize", cp, &secsize); - if (error || secsize < 512) + secsize = cp->provider->sectorsize; + if (secsize < 512) break; /* First look for a label at the start of the second sector. */ diff --git a/sys/geom/geom_ctl.c b/sys/geom/geom_ctl.c index 3d24296..1ae88fb 100644 --- a/sys/geom/geom_ctl.c +++ b/sys/geom/geom_ctl.c @@ -85,6 +85,7 @@ g_ctl_init2(void *p __unused) gp->start = g_ctl_start; gp->access = g_ctl_access; pp = g_new_providerf(gp, "%s", gp->name); + pp->sectorsize = 512; g_error_provider(pp, 0); } diff --git a/sys/geom/geom_dev.c b/sys/geom/geom_dev.c index b044111..bdd6670 100644 --- a/sys/geom/geom_dev.c +++ b/sys/geom/geom_dev.c @@ -245,13 +245,13 @@ g_dev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) i = IOCPARM_LEN(cmd); switch (cmd) { case DIOCGSECTORSIZE: - error = g_io_getattr("GEOM::sectorsize", cp, &i, data); - if (error == 0 && *(u_int *)data == 0) + *(u_int *)data = cp->provider->sectorsize; + if (*(u_int *)data == 0) error = ENOENT; break; case DIOCGMEDIASIZE: - error = g_io_getattr("GEOM::mediasize", cp, &i, data); - if (error == 0 && *(off_t *)data == 0) + *(off_t *)data = cp->provider->mediasize; + if (*(off_t *)data == 0) error = ENOENT; break; case DIOCGFWSECTORS: @@ -329,15 +329,11 @@ static int g_dev_psize(dev_t dev) { struct g_consumer *cp; - int i, error; off_t mediasize; cp = dev->si_drv2; - i = sizeof mediasize; - error = g_io_getattr("GEOM::mediasize", cp, &i, &mediasize); - if (error) - return (-1); + mediasize = cp->provider->mediasize; return (mediasize >> DEV_BSHIFT); } diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c index 5e2f939..bd3bf2e 100644 --- a/sys/geom/geom_disk.c +++ b/sys/geom/geom_disk.c @@ -89,6 +89,8 @@ g_disk_access(struct g_provider *pp, int r, int w, int e) if (error != 0) printf("Opened disk %s -> %d\n", pp->name, error); mtx_unlock(&Giant); + pp->mediasize = dp->d_mediasize; + pp->sectorsize = dp->d_sectorsize; } else if ((pp->acr + pp->acw + pp->ace) > 0 && (r + w + e) == 0) { mtx_lock(&Giant); error = devsw(dev)->d_close(dev, 3, 0, NULL); @@ -98,8 +100,6 @@ g_disk_access(struct g_provider *pp, int r, int w, int e) } else { error = 0; } - pp->mediasize = dp->d_mediasize; - pp->sectorsize = dp->d_sectorsize; return (error); } @@ -166,14 +166,10 @@ g_disk_start(struct bio *bp) mtx_unlock(&Giant); break; case BIO_GETATTR: - if (g_handleattr_int(bp, "GEOM::sectorsize", dp->d_sectorsize)) - break; - else if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors)) + if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors)) break; else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads)) break; - else if (g_handleattr_off_t(bp, "GEOM::mediasize", dp->d_mediasize)) - break; else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0)) break; else if (!strcmp(bp->bio_attribute, "GEOM::kerneldump")) @@ -236,6 +232,8 @@ g_disk_create(void *arg) gp->dumpconf = g_disk_dumpconf; dev->si_disk->d_softc = gp; pp = g_new_providerf(gp, "%s", gp->name); + pp->mediasize = dev->si_disk->d_mediasize; + pp->sectorsize = dev->si_disk->d_sectorsize; g_error_provider(pp, 0); } diff --git a/sys/geom/geom_gpt.c b/sys/geom/geom_gpt.c index ef23af0..6f90507 100644 --- a/sys/geom/geom_gpt.c +++ b/sys/geom/geom_gpt.c @@ -168,8 +168,8 @@ g_gpt_taste(struct g_class *mp, struct g_provider *pp, int insist) if (gp->rank != 2 && insist == 0) break; - error = g_getattr("GEOM::sectorsize", cp, &secsz); - if (error) + secsz = cp->provider->sectorsize; + if (secsz < 512) break; /* XXX: we need to get the media size as well. */ diff --git a/sys/geom/geom_mbr.c b/sys/geom/geom_mbr.c index 418fa4d..108a013 100644 --- a/sys/geom/geom_mbr.c +++ b/sys/geom/geom_mbr.c @@ -192,9 +192,7 @@ g_mbr_taste(struct g_class *mp, struct g_provider *pp, int insist) error = g_getattr("GEOM::fwsectors", cp, &fwsectors); if (error) fwsectors = 17; - error = g_getattr("GEOM::sectorsize", cp, §orsize); - if (error) - break; + sectorsize = cp->provider->sectorsize; if (sectorsize != 512) break; gsp->frontstuff = sectorsize * fwsectors; @@ -355,9 +353,7 @@ g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) error = g_getattr("GEOM::fwsectors", cp, &fwsectors); if (error) fwsectors = 17; - error = g_getattr("GEOM::sectorsize", cp, §orsize); - if (error) - break; + sectorsize = cp->provider->sectorsize; if (sectorsize != 512) break; gsp->frontstuff = sectorsize * fwsectors; diff --git a/sys/geom/geom_pc98.c b/sys/geom/geom_pc98.c index a47724f..6aa466b 100644 --- a/sys/geom/geom_pc98.c +++ b/sys/geom/geom_pc98.c @@ -113,18 +113,10 @@ g_pc98_taste(struct g_class *mp, struct g_provider *pp, int flags) while (1) { /* a trick to allow us to use break */ if (gp->rank != 2 && flags == G_TF_NORMAL) break; - error = g_getattr("GEOM::sectorsize", cp, §orsize); - if (error) { - sectorsize = 512; - printf("g_pc98_taste: error %d Sectors are %d bytes\n", - error, sectorsize); - } - error = g_getattr("GEOM::mediasize", cp, &mediasize); - if (error) { - mediasize = 0; - printf("g_error %d Mediasize is %jd bytes\n", - error, (intmax_t)mediasize); - } + sectorsize = cp->provider->sectorsize; + if (sectorsize < 512) + break; + mediasize = cp->provider->mediasize; error = g_getattr("GEOM::fwsectors", cp, &fwsect); if (error || fwsect == 0) { fwsect = 17; diff --git a/sys/geom/geom_slice.c b/sys/geom/geom_slice.c index 64745bf..35e7896 100644 --- a/sys/geom/geom_slice.c +++ b/sys/geom/geom_slice.c @@ -163,9 +163,6 @@ g_slice_start(struct bio *bp) /* Give the real method a chance to override */ if (gsp->start(bp)) return; - if (g_handleattr_off_t(bp, "GEOM::mediasize", - gsp->slices[index].length)) - return; if (!strcmp("GEOM::frontstuff", bp->bio_attribute)) { t = gsp->cfrontstuff; if (gsp->frontstuff > t) @@ -335,10 +332,12 @@ g_slice_new(struct g_class *mp, int slices, struct g_provider *pp, struct g_cons gp->spoiled = g_std_spoiled; gp->dumpconf = g_slice_dumpconf; cp = g_new_consumer(gp); - g_attach(cp, pp); - error = g_access_rel(cp, 1, 0, 0); + error = g_attach(cp, pp); + if (error == 0) + error = g_access_rel(cp, 1, 0, 0); if (error) { - g_detach(cp); + if (cp->provider != NULL) + g_detach(cp); g_destroy_consumer(cp); g_free(gsp->slices); g_free(gp->softc); diff --git a/sys/geom/geom_sunlabel.c b/sys/geom/geom_sunlabel.c index 78d496a..5c9d6ad 100644 --- a/sys/geom/geom_sunlabel.c +++ b/sys/geom/geom_sunlabel.c @@ -110,19 +110,11 @@ g_sunlabel_taste(struct g_class *mp, struct g_provider *pp, int flags) while (1) { /* a trick to allow us to use break */ if (gp->rank != 2 && flags == G_TF_NORMAL) break; - error = g_getattr("GEOM::sectorsize", cp, §orsize); - if (error) { - sectorsize = 512; - printf("g_sunlabel_taste: error %d Sectors are %d bytes\n", - error, sectorsize); - } + sectorsize = cp->provider->sectorsize; + if (sectorsize < 512) + break; gsp->frontstuff = 16 * sectorsize; - error = g_getattr("GEOM::mediasize", cp, &mediasize); - if (error) { - mediasize = 0; - printf("g_error %d Mediasize is %lld bytes\n", - error, (long long)mediasize); - } + mediasize = cp->provider->mediasize; buf = g_read_data(cp, 0, sectorsize, &error); if (buf == NULL || error != 0) break; |