Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Nov 2017 03:06:22 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Konstantin Belousov <kib@freebsd.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r324853 - in head/sys: kern sys
Message-ID:  <20171105014453.L1354@besplex.bde.org>
In-Reply-To: <201710220811.v9M8Bjw5033551@repo.freebsd.org>
References:  <201710220811.v9M8Bjw5033551@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 22 Oct 2017, Konstantin Belousov wrote:

> Author: kib
> Date: Sun Oct 22 08:11:45 2017
> New Revision: 324853
> URL: https://svnweb.freebsd.org/changeset/base/324853
>
> Log:
>  Remove the support for mknod(S_IFMT), which created dummy vnodes with
>  VBAD type.
>
>  FFS ffs_write() VOP catches such vnodes and panics, other VOPs do not
>  check for the type and their behaviour is really undefined.  The
>  comment claims that this support was done for 'badsect' to flag bad
>  sectors, we do not have such facility in kernel anyway.

badsect(8) is a utility and this commit breaks it by removing its kernel
support.

The panic for ffs is a user error (not running fsck after badsect, or not
following the directions for using badsect, or using the privileged
mknod(S_IFMT) operation in an unsafe way).  The bugs for other file systems
are not having a badsect utility and not even disallowing creation of the
vnodes to support badsect.

64-bit dev_t made badsect work better than ever.  It worked as well as
possible (not very well) with at least old badsect and old fsck.  Its
man page has much more bitrot than its code, mostly due to removal of
other utilities:

X BADSECT(8)              FreeBSD System Manager's Manual             BADSECT(8)
X 
X NAME
X      badsect - create files to contain bad sectors
X 
X SYNOPSIS
X      badsect bbdir sector ...
X 
X DESCRIPTION
X      The badsect utility makes a file to contain a bad sector.  Normally, bad

Thus has bad grammar and some technical bugs.  "makes a file to contain a bad
sector" should be something like "makes file[s] containing the specified
bad sector[s].  "containing" needs further descripton.  The containers are
fragments which usually consist of multiple sectors.

X      sectors are made inaccessible by the standard formatter, which provides a
X      forwarding table for bad sectors to the driver.  If a driver supports the

Actually, bad sectors are normally made inaccessible by replacing the drive.
The "standard" formatter was removed.

X      bad blocking standard it is much preferable to use that method to isolate
X      bad blocks, since the bad block forwarding makes the pack appear perfect,
X      and such packs can then be copied with dd(1).  The technique used by this

The bad blocking standard was bad144.  It was removed, so using it is
impossible.

X      program is also less general than bad block forwarding, as badsect cannot
X      make amends for bad blocks in the i-list of file systems or in swap
X      areas.

badsect is much more primitive than bad144, but was usable for disks with
just a few bad sectors.

X 
X      On some disks, adding a sector which is suddenly bad to the bad sector
X      table currently requires the running of the standard DEC formatter.  Thus

The standard DEC formatter never existed in FreeBSD.

X      to deal with a newly bad block or on disks where the drivers do not
X      support the bad-blocking standard badsect may be used to good effect.
X 
X      The badsect utility is used on a quiet file system in the following way:

The file system must be quiet else you will get panics before fsck can be
run to fix the file system.

X      First mount the file system, and change to its root directory.  Make a
X      directory BAD there.  Run badsect giving as argument the BAD directory
X      followed by all the bad sectors you wish to add.  (The sector numbers
X      must be relative to the beginning of the file system, but this is not
X      hard as the system reports relative sector numbers in its console error
X      messages.)  Then change back to the root directory, unmount the file

This is now hard.  Non-broken drivers in old versions of FreeBSD used
diskerr(9) to report errors in a uniform way.  This was dumbed down and
renamed disk_err() which is only called by aac, xen/blkfront, virtio/block
and mfi.  This only prints absolute block numbers in unclear units.  GEOM
would have to be involved to print relative sector numbers and partition
names, but I don't know of any GEOM function for this.  I think CAM prints
absolute block numbers (after an error) in a verbose format that is less
useful execpt for SCSI debugging.

I used lm's filelocks or mckusick's prtblknos utility to find block numbers.
Since I don't have any disks with bad sectors handy, I used good sectors.
These utilities print the (relative) ffs fragment number.  This must be
multiplied by fs_frag (default 8) to get the sector number for badsect.

X      system and run fsck(8) on the file system.  The bad sectors should show
X      up in two files or in the bad sector files and the free list.  Have
X      fsck(8) remove files containing the offending bad sectors, but do not
X      have it remove the BAD/nnnnn files.  This will leave the bad sectors in
X      only the BAD files.

fsck must be run twice, at least now.

X 
X      The badsect utility works by giving the specified sector numbers in a
X      mknod(2) system call, creating an illegal file whose first block address
X      is the block containing bad sector and whose name is the bad sector
X      number.  When it is discovered by fsck(8) it will ask "HOLD BAD BLOCK ?".
X      A positive response will cause fsck(8) to convert the inode to a regular
X      file containing the bad block.
X 
X DIAGNOSTICS
X      The badsect utility refuses to attach a block that resides in a critical
X      area or is out of range of the file system.  A warning is issued if the
X      block is already in use.
X 
X SEE ALSO
X      fsck(8)
X 
X HISTORY
X      The badsect utility appeared in 4.1BSD.
X 
X BUGS
X      If more than one sector which comprise a file system fragment are bad,
X      you should specify only one of them to badsect, as the blocks in the bad
X      sector files actually cover all the sectors in a file system fragment.

This is a fairly confusing way of saying that you must match up sectors
with fragments.  E.g., with 8 sectors per frag, round down the sector number
to a multiple of 8 and tell badsect that.  This gives a fragment of 8 sectors.
Even good sectors in this fragment are marked as bad.  Don't tell badsect
about any other sectors in the fragment.

Further BUGS: this man page hasn't been updated much since it first appeared.

X 
X FreeBSD 12.0-CURRENT             June 5, 1993             FreeBSD 12.0-CURRENT

Better support for bad sectors would do things like automatically marking the
bad sector files as nodump, nounlink and unreadable even by root.  I think
some suj sysctls can handle raw ffs blocks less hackishly, but there is no
utility like badsect to use them for marking some blocks as bad.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20171105014453.L1354>