2006-10-31 21:31:00 +00:00
|
|
|
/*-
|
2017-11-27 15:17:37 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2006-10-31 21:31:00 +00:00
|
|
|
* Copyright (c) 2005-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
|
|
|
#include <ufs/ufs/extattr.h>
|
|
|
|
#include <ufs/ufs/quota.h>
|
|
|
|
#include <ufs/ufs/inode.h>
|
|
|
|
#include <ufs/ufs/ufs_extern.h>
|
|
|
|
#include <ufs/ufs/ufsmount.h>
|
|
|
|
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
#include <ufs/ffs/ffs_extern.h>
|
|
|
|
|
|
|
|
#include <geom/geom.h>
|
2019-08-07 19:28:35 +00:00
|
|
|
#include <geom/geom_dbg.h>
|
2006-10-31 21:31:00 +00:00
|
|
|
#include <geom/journal/g_journal.h>
|
|
|
|
|
|
|
|
static int
|
|
|
|
g_journal_ufs_clean(struct mount *mp)
|
|
|
|
{
|
|
|
|
struct ufsmount *ump;
|
|
|
|
struct fs *fs;
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
ump = VFSTOUFS(mp);
|
|
|
|
fs = ump->um_fs;
|
|
|
|
|
|
|
|
flags = fs->fs_flags;
|
|
|
|
fs->fs_flags &= ~(FS_UNCLEAN | FS_NEEDSFSCK);
|
|
|
|
ffs_sbupdate(ump, MNT_WAIT, 1);
|
|
|
|
fs->fs_flags = flags;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_journal_ufs_dirty(struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
struct fs *fs;
|
2018-01-26 00:58:32 +00:00
|
|
|
int error;
|
2006-10-31 21:31:00 +00:00
|
|
|
|
2018-02-16 15:41:03 +00:00
|
|
|
fs = NULL;
|
2018-01-26 00:58:32 +00:00
|
|
|
if (SBLOCKSIZE % cp->provider->sectorsize != 0 ||
|
Normally when an attempt is made to mount a UFS/FFS filesystem whose
superblock has a check-hash error, an error message noting the
superblock check-hash failure is printed and the mount fails. The
administrator then runs fsck to repair the filesystem and when
successful, the filesystem can once again be mounted.
This approach fails if the filesystem in question is a root filesystem
from which you are trying to boot. Here, the loader fails when trying
to access the filesystem to get the kernel to boot. So it is necessary
to allow the loader to ignore the superblock check-hash error and make
a best effort to read the kernel. The filesystem may be suffiently
corrupted that the read attempt fails, but there is no harm in trying
since the loader makes no attempt to write to the filesystem.
Once the kernel is loaded and starts to run, it attempts to mount its
root filesystem. Once again, failure means that it breaks to its prompt
to ask where to get its root filesystem. Unless you have an alternate
root filesystem, you are stuck.
Since the root filesystem is initially mounted read-only, it is
safe to make an attempt to mount the root filesystem with the failed
superblock check-hash. Thus, when asked to mount a root filesystem
with a failed superblock check-hash, the kernel prints a warning
message that the root filesystem superblock check-hash needs repair,
but notes that it is ignoring the error and proceeding. It does
mark the filesystem as needing an fsck which prevents it from being
enabled for writing until fsck has been run on it. The net effect
is that the reboot fails to single user, but at least at that point
the administrator has the tools at hand to fix the problem.
Reported by: Rick Macklem (rmacklem@)
Discussed with: Warner Losh (imp@)
Sponsored by: Netflix
2018-12-06 00:09:39 +00:00
|
|
|
ffs_sbget(cp, &fs, STDSB, M_GEOM, g_use_g_read_data) != 0) {
|
2018-01-26 00:58:32 +00:00
|
|
|
GJ_DEBUG(0, "Cannot find superblock to mark file system %s "
|
|
|
|
"as dirty.", cp->provider->name);
|
This change is some refactoring of Mark Johnston's changes in r329375
to fix the memory leak that I introduced in r328426. Instead of
trying to clear up the possible memory leak in all the clients, I
ensure that it gets cleaned up in the source (e.g., ffs_sbget ensures
that memory is always freed if it returns an error).
The original change in r328426 was a bit sparse in its description.
So I am expanding on its description here (thanks cem@ and rgrimes@
for your encouragement for my longer commit messages).
In preparation for adding check hashing to superblocks, r328426 is
a refactoring of the code to get the reading/writing of the superblock
into one place. Unlike the cylinder group reading/writing which
ends up in two places (ffs_getcg/ffs_geom_strategy in the kernel
and cgget/cgput in libufs), I have the core superblock functions
just in the kernel (ffs_sbfetch/ffs_sbput in ffs_subr.c which is
already imported into utilities like fsck_ffs as well as libufs to
implement sbget/sbput). The ffs_sbfetch and ffs_sbput functions
take a function pointer to do the actual I/O for which there are
four variants:
ffs_use_bread / ffs_use_bwrite for the in-kernel filesystem
g_use_g_read_data / g_use_g_write_data for kernel geom clients
ufs_use_sa_read for the standalone code (stand/libsa/ufs.c
but not stand/libsa/ufsread.c which is size constrained)
use_pread / use_pwrite for libufs
Uses of these interfaces are in the UFS filesystem, geoms journal &
label, libsa changes, and libufs. They also permeate out into the
filesystem utilities fsck_ffs, newfs, growfs, clri, dump, quotacheck,
fsirand, fstyp, and quot. Some of these utilities should probably be
converted to directly use libufs (like dumpfs was for example), but
there does not seem to be much win in doing so.
Tested by: Peter Holm (pho@)
2018-03-02 04:34:53 +00:00
|
|
|
KASSERT(fs == NULL,
|
|
|
|
("g_journal_ufs_dirty: non-NULL fs %p\n", fs));
|
2006-10-31 21:31:00 +00:00
|
|
|
return;
|
2018-01-26 00:58:32 +00:00
|
|
|
}
|
|
|
|
GJ_DEBUG(0, "clean=%d flags=0x%x", fs->fs_clean, fs->fs_flags);
|
|
|
|
fs->fs_clean = 0;
|
|
|
|
fs->fs_flags |= FS_NEEDSFSCK | FS_UNCLEAN;
|
|
|
|
error = ffs_sbput(cp, fs, fs->fs_sblockloc, g_use_g_write_data);
|
2018-03-24 15:36:25 +00:00
|
|
|
g_free(fs->fs_csp);
|
2018-01-26 00:58:32 +00:00
|
|
|
g_free(fs);
|
|
|
|
if (error != 0) {
|
|
|
|
GJ_DEBUG(0, "Cannot mark file system %s as dirty "
|
|
|
|
"(error=%d).", cp->provider->name, error);
|
|
|
|
} else {
|
|
|
|
GJ_DEBUG(0, "File system %s marked as dirty.",
|
|
|
|
cp->provider->name);
|
2006-10-31 21:31:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct g_journal_desc g_journal_ufs = {
|
|
|
|
.jd_fstype = "ufs",
|
|
|
|
.jd_clean = g_journal_ufs_clean,
|
|
|
|
.jd_dirty = g_journal_ufs_dirty
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEPEND(g_journal, ufs, 1, 1, 1);
|
2018-04-10 19:18:16 +00:00
|
|
|
MODULE_VERSION(geom_journal, 0);
|