Make FreeBSD "struct disklabel" agnostic, step 311 of 723:

Rename diskerr() to disk_err() for naming consistency.

Drop the by now entirely useless struct disklabel argument.

Add a flag argument for new-line termination.

Fix a couple of printf-format-casts to %j instead of %l.

Correctly print the name of all bio commands.

Move the function from subr_disklabel.c to subr_disk.c,
and from <sys/disklabel.h> to <sys/disk.h>.

Use the new disk_err() throughout, #include <sys/disk.h> as needed.

Bump __FreeBSD_version for the sake of the aac disk drivers #ifdefs.

Remove unused disklabel members of softc for aac, amr and mlx, which seem
to originally have been intended for diskerr() use, but which only rotted
and got Copy&Pasted at least two times to many.

Sponsored by:   DARPA & NAI Labs.
This commit is contained in:
Poul-Henning Kamp 2002-09-20 12:52:03 +00:00
parent 47fae43eab
commit f90c382c0c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=103675
19 changed files with 72 additions and 97 deletions

View File

@ -305,7 +305,6 @@ void
aac_biodone(struct bio *bp)
{
struct aac_disk *sc;
int blkno;
debug_called(4);
@ -313,10 +312,15 @@ aac_biodone(struct bio *bp)
devstat_end_transaction_bio(&sc->ad_stats, bp);
if (bp->bio_flags & BIO_ERROR) {
#if __FreeBSD_version > 500039
disk_err(bp, "hard error", -1, 1);
#elif __FreeBSD_version > 500005
int blkno;
blkno = (sc->ad_label.d_nsectors) ? 0 : -1;
#if __FreeBSD_version > 500005
diskerr(bp, (char *)bp->bio_driver1, blkno, &sc->ad_label);
#else
int blkno;
blkno = (sc->ad_label.d_nsectors) ? 0 : -1;
diskerr(bp, (char *)bp->bio_driver1, 0, blkno, &sc->ad_label);
#endif
}

View File

@ -120,7 +120,6 @@ struct aac_disk
struct aac_container *ad_container;
struct disk ad_disk;
struct devstat ad_stats;
struct disklabel ad_label;
int ad_flags;
#define AAC_DISK_OPEN (1<<0)
int ad_cylinders;

View File

@ -223,7 +223,6 @@ struct amrd_softc
struct amr_logdrive *amrd_drive;
struct disk amrd_disk;
struct devstat amrd_stats;
struct disklabel amrd_label;
int amrd_unit;
int amrd_flags;
#define AMRD_OPEN (1<<0) /* drive is open (can't detach) */

View File

@ -563,19 +563,17 @@ ad_interrupt(struct ad_request *request)
/* do we have a corrected soft error ? */
if (adp->device->channel->status & ATA_S_CORR)
diskerr(request->bp, "soft error (ECC corrected)",
request->blockaddr + (request->donecount / DEV_BSIZE),
&adp->disk.d_label);
disk_err(request->bp, "soft error (ECC corrected)",
request->blockaddr + (request->donecount / DEV_BSIZE), 1);
/* did any real errors happen ? */
if ((adp->device->channel->status & ATA_S_ERROR) ||
(request->flags & ADR_F_DMA_USED && dma_stat & ATA_BMSTAT_ERROR)) {
adp->device->channel->error =
ATA_INB(adp->device->channel->r_io, ATA_ERROR);
diskerr(request->bp, (adp->device->channel->error & ATA_E_ICRC) ?
disk_err(request->bp, (adp->device->channel->error & ATA_E_ICRC) ?
"UDMA ICRC error" : "hard error",
request->blockaddr + (request->donecount / DEV_BSIZE),
&adp->disk.d_label);
request->blockaddr + (request->donecount / DEV_BSIZE), 1);
/* if this is a UDMA CRC error, reinject request */
if (request->flags & ADR_F_DMA_USED &&

View File

@ -62,6 +62,7 @@
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/devicestat.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/fcntl.h>
#include <sys/fdcio.h>
@ -2512,8 +2513,8 @@ retrier(struct fdc_data *fdc)
default:
fail:
if ((fd->options & FDOPT_NOERRLOG) == 0) {
diskerr(bp, "hard error", fdc->fd->skip / DEV_BSIZE,
(struct disklabel *)NULL);
disk_err(bp, "hard error",
fdc->fd->skip / DEV_BSIZE, 0);
if (fdc->flags & FDC_STAT_VALID) {
printf(
" (ST0 %b ST1 %b ST2 %b cyl %u hd %u sec %u)\n",

View File

@ -230,7 +230,6 @@ struct mlxd_softc
struct mlx_sysdrive *mlxd_drive;
struct disk mlxd_disk;
struct devstat mlxd_stats;
struct disklabel mlxd_label;
int mlxd_unit;
int mlxd_flags;
#define MLXD_OPEN (1<<0) /* drive is open (can't shut down) */

View File

@ -62,6 +62,7 @@
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/devicestat.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/fcntl.h>
#include <sys/fdcio.h>
@ -2512,8 +2513,8 @@ retrier(struct fdc_data *fdc)
default:
fail:
if ((fd->options & FDOPT_NOERRLOG) == 0) {
diskerr(bp, "hard error", fdc->fd->skip / DEV_BSIZE,
(struct disklabel *)NULL);
disk_err(bp, "hard error",
fdc->fd->skip / DEV_BSIZE, 0);
if (fdc->flags & FDC_STAT_VALID) {
printf(
" (ST0 %b ST1 %b ST2 %b cyl %u hd %u sec %u)\n",

View File

@ -11,15 +11,16 @@
*/
#include "opt_geom.h"
#ifndef GEOM
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/stdint.h>
#include <sys/bio.h>
#include <sys/conf.h>
#include <sys/disk.h>
#ifndef GEOM
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/sysctl.h>
#include <machine/md_var.h>
@ -432,3 +433,39 @@ SYSCTL_INT(_debug_sizeof, OID_AUTO, disk, CTLFLAG_RD,
0, sizeof(struct disk), "sizeof(struct disk)");
#endif
/*-
* Disk error is the preface to plaintive error messages
* about failing disk transfers. It prints messages of the form
* "hp0g: BLABLABLA cmd=read fsbn 12345 of 12344-12347"
* blkdone should be -1 if the position of the error is unknown.
* The message is printed with printf.
*/
void
disk_err(struct bio *bp, const char *what, int blkdone, int nl)
{
daddr_t sn;
printf("%s: %s", devtoname(bp->bio_dev), what);
switch(bp->bio_cmd) {
case BIO_READ: printf("cmd=read"); break;
case BIO_WRITE: printf("cmd=write"); break;
case BIO_DELETE: printf("cmd=delete"); break;
case BIO_GETATTR: printf("cmd=getattr"); break;
case BIO_SETATTR: printf("cmd=setattr"); break;
default: printf("cmd=%x", bp->bio_cmd); break;
}
sn = bp->bio_blkno;
if (bp->bio_bcount <= DEV_BSIZE) {
printf("fsbn %jd%s", (intmax_t)sn, nl ? "\n" : "");
return;
}
if (blkdone >= 0) {
sn += blkdone;
printf("fsbn %jd of ", (intmax_t)sn);
}
printf("%jd-%jd", (intmax_t)bp->bio_blkno,
(intmax_t)(bp->bio_blkno + (bp->bio_bcount - 1) / DEV_BSIZE));
if (nl)
printf("\n");
}

View File

@ -367,60 +367,3 @@ writedisklabel(dev, lp)
brelse(bp);
return (error);
}
/*
* Disk error is the preface to plaintive error messages
* about failing disk transfers. It prints messages of the form
hp0g: hard error reading fsbn 12345 of 12344-12347 (hp0 bn %d cn %d tn %d sn %d)
* if the offset of the error in the transfer and a disk label
* are both available. blkdone should be -1 if the position of the error
* is unknown; the disklabel pointer may be null from drivers that have not
* been converted to use them. The message is printed with printf.
* The message should be completed with at least a newline. There is no
* trailing space.
*/
void
diskerr(bp, what, blkdone, lp)
struct bio *bp;
char *what;
int blkdone;
register struct disklabel *lp;
{
int part = dkpart(bp->bio_dev);
char partname[2];
char *sname;
daddr_t sn;
*partname = '\0';
sname = bp->bio_dev->si_name;
printf("%s%s: %s %sing fsbn ", sname, partname, what,
bp->bio_cmd == BIO_READ ? "read" : "writ");
sn = bp->bio_blkno;
if (bp->bio_bcount <= DEV_BSIZE)
printf("%jd", (intmax_t)sn);
else {
if (blkdone >= 0) {
sn += blkdone;
printf("%jd of ", (intmax_t)sn);
}
printf("%ld-%ld", (long)bp->bio_blkno,
(long)(bp->bio_blkno + (bp->bio_bcount - 1) / DEV_BSIZE));
}
if (lp && (blkdone >= 0 || bp->bio_bcount <= lp->d_secsize)) {
sn += lp->d_partitions[part].p_offset;
/*
* XXX should add slice offset and not print the slice,
* but we don't know the slice pointer.
* XXX should print bp->b_pblkno so that this will work
* independent of slices, labels and bad sector remapping,
* but some drivers don't set bp->b_pblkno.
*/
printf(" (%s bn %jd; cn %jd", sname, (intmax_t)sn,
(intmax_t)(sn / lp->d_secpercyl));
sn %= lp->d_secpercyl;
printf(" tn %ld sn %ld)", (long)(sn / lp->d_nsectors),
(long)(sn % lp->d_nsectors));
}
}

View File

@ -47,6 +47,7 @@
#define PC98_ATCOMPAT
#define dsinit atcompat_dsinit
#endif
#include <sys/disk.h>
#include <sys/disklabel.h>
#define DOSPTYP_EXTENDED 5
#define DOSPTYP_EXTENDEDX 15
@ -214,9 +215,8 @@ dsinit(dev, lp, sspp)
bp->b_iocmd = BIO_READ;
DEV_STRATEGY(bp, 1);
if (bufwait(bp) != 0) {
diskerr(&bp->b_io, "reading primary partition table: error",
0, (struct disklabel *)NULL);
printf("\n");
disk_err(&bp->b_io, "reading primary partition table: error",
0, 1);
error = EIO;
goto done;
}
@ -417,9 +417,8 @@ mbr_extended(dev, lp, ssp, ext_offset, ext_size, base_ext_offset, nsectors,
bp->b_iocmd = BIO_READ;
DEV_STRATEGY(bp, 1);
if (bufwait(bp) != 0) {
diskerr(&bp->b_io, "reading extended partition table: error",
0, (struct disklabel *)NULL);
printf("\n");
disk_err(&bp->b_io, "reading extended partition table: error",
0, 1);
goto done;
}

View File

@ -3054,8 +3054,8 @@ retrier(struct fdc_data *fdc)
default:
fail:
if ((fd->options & FDOPT_NOERRLOG) == 0) {
diskerr(bp, "hard error", fdc->fd->skip / DEV_BSIZE,
(struct disklabel *)NULL);
disk_err(bp, "hard error",
fdc->fd->skip / DEV_BSIZE, 0);
if (fdc->flags & FDC_STAT_VALID) {
printf(
" (ST0 %b ST1 %b ST2 %b cyl %u hd %u sec %u)\n",

View File

@ -250,9 +250,8 @@ dsinit(dev, lp, sspp)
#endif
DEV_STRATEGY(bp, 1);
if (bufwait(bp) != 0) {
diskerr(&bp->b_io, "reading primary partition table: error",
0, (struct disklabel *)NULL);
printf("\n");
disk_err(&bp->b_io, "reading primary partition table: error",
0, 1);
error = EIO;
goto done;
}
@ -533,9 +532,8 @@ mbr_extended(dev, lp, ssp, ext_offset, ext_size, base_ext_offset, nsectors,
bp->b_iocmd = BIO_READ;
DEV_STRATEGY(bp, 1);
if (bufwait(bp) != 0) {
diskerr(&bp->b_io, "reading extended partition table: error",
0, (struct disklabel *)NULL);
printf("\n");
disk_err(&bp->b_io, "reading extended partition table: error",
0, 1);
goto done;
}

View File

@ -3054,8 +3054,8 @@ retrier(struct fdc_data *fdc)
default:
fail:
if ((fd->options & FDOPT_NOERRLOG) == 0) {
diskerr(bp, "hard error", fdc->fd->skip / DEV_BSIZE,
(struct disklabel *)NULL);
disk_err(bp, "hard error",
fdc->fd->skip / DEV_BSIZE, 0);
if (fdc->flags & FDC_STAT_VALID) {
printf(
" (ST0 %b ST1 %b ST2 %b cyl %u hd %u sec %u)\n",

View File

@ -1874,8 +1874,7 @@ wderror(struct bio *bp, struct softc *du, char *mesg)
if (bp == NULL)
printf("wd%d: %s", du->dk_lunit, mesg);
else
diskerr(bp, mesg, du->dk_skip,
dsgetlabel(bp->bio_dev, du->dk_slices));
disk_err(bp, mesg, du->dk_skip, 0);
printf(" (status %b error %b)\n",
du->dk_status, WDCS_BITS, du->dk_error, WDERR_BITS);
}

View File

@ -43,6 +43,7 @@ struct disk {
dev_t disk_create(int unit, struct disk *disk, int flags, struct cdevsw *cdevsw, struct cdevsw *diskdevsw);
void disk_destroy(dev_t dev);
struct disk *disk_enumerate(struct disk *disk);
void disk_err(struct bio *bp, const char *what, int blkdone, int nl);
void disk_invalidate(struct disk *disk);
#endif

View File

@ -395,7 +395,6 @@ struct bio_queue_head;
int bounds_check_with_label(struct bio *bp, struct disklabel *lp,
int wlabel);
void diskerr(struct bio *bp, char *what, int blkdone, struct disklabel *lp);
dev_t dkmodpart(dev_t dev, int part);
dev_t dkmodslice(dev_t dev, int slice);
u_int dkunit(dev_t dev);

View File

@ -395,7 +395,6 @@ struct bio_queue_head;
int bounds_check_with_label(struct bio *bp, struct disklabel *lp,
int wlabel);
void diskerr(struct bio *bp, char *what, int blkdone, struct disklabel *lp);
dev_t dkmodpart(dev_t dev, int part);
dev_t dkmodslice(dev_t dev, int slice);
u_int dkunit(dev_t dev);

View File

@ -395,7 +395,6 @@ struct bio_queue_head;
int bounds_check_with_label(struct bio *bp, struct disklabel *lp,
int wlabel);
void diskerr(struct bio *bp, char *what, int blkdone, struct disklabel *lp);
dev_t dkmodpart(dev_t dev, int part);
dev_t dkmodslice(dev_t dev, int slice);
u_int dkunit(dev_t dev);

View File

@ -55,7 +55,7 @@
* doc/en_US.ISO8859-1/books/porters-handbook/book.sgml
*/
#undef __FreeBSD_version
#define __FreeBSD_version 500039 /* Master, propagated to newvers */
#define __FreeBSD_version 500040 /* Master, propagated to newvers */
#ifndef NULL
#define NULL 0