Commit Graph

71 Commits

Author SHA1 Message Date
Ed Maste
0dcde5cc12 growfs: allow operation on RW-mounted filesystems
growfs supports growing mounted filesystems (writes are temporarily
suspended while the grow happens).  Drop the check for fs_clean == 0
to restore this case.  Leave fs_flags check for FS_UNCLEAN or
FS_NEEDSFSCK which represent the state of the filesystem when it was
mounted, and fsck should be run first if they are set.

PR:		253754
Reviewed by:	mckusick
MFC after:	3 days
Fixes:		6eb925f845 ("Filesystem utilities that modify the...")
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D29021
2021-03-03 18:35:21 -05:00
Kirk McKusick
6eb925f845 Filesystem utilities that modify the filesystem (growfs(8), tunefs(8),
and fsirand(8)) should check the filesystem status and require that
fsck(8) be run if it is unclean. This requirement is not imposed on
fsdb(8) or clri(8) since they may be used to clean up a filesystem.

MFC after:    2 weeks
Sponsored by: Netflix
2020-10-25 01:36:33 +00:00
Kirk McKusick
54fab0fbc4 Add missing cylinder group check-hash updates when doing large expansions
of filesystems.

Reported by:  Colin Percival (cperciva@)
Tested by:    Colin Percival (cperciva@)
MFC after:    3 days
Sponsored by: Netflix
2020-09-22 03:57:48 +00:00
Kirk McKusick
fb14e73cb4 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
Kirk McKusick
9fc5d538fc In preparation for adding inode check-hashes, clean up and
document the libufs interface for fetching and storing inodes.
The undocumented getino / putino interface has been replaced
with a new getinode / putinode interface.

Convert the utilities that had been using the undocumented
interface to use the new documented interface.

No functional change (as for now the libufs library does not
do inode check-hashes).

Reviewed by:  kib
Tested by:    Peter Holm
Sponsored by: Netflix
2018-11-13 21:40:56 +00:00
Kirk McKusick
dffce2150e Refactoring of reading and writing of the UFS/FFS superblock.
Specifically reading is done if ffs_sbget() and writing is done
in ffs_sbput(). These functions are exported to libufs via the
sbget() and sbput() functions which then used in the various
filesystem utilities. This work is in preparation for adding
subperblock check hashes.

No functional change intended.

Reviewed by: kib
2018-01-26 00:58:32 +00:00
Pedro F. Giffuni
df57947f08 spdx: initial adoption of licensing ID tags.
The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.

Initially, only tag files that use BSD 4-Clause "Original" license.

RelNotes:	yes
Differential Revision:	https://reviews.freebsd.org/D13133
2017-11-18 14:26:50 +00:00
Ed Maste
4887fa3635 growfs: ANSIfy cgckhash()
The build was broken on GCC-using architectures with:

growfs.c: In function 'cgckhash':
growfs.c:1753: warning: old-style function definition

Sponsored by:	The FreeBSD Foundation
2017-10-10 21:16:07 +00:00
Kirk McKusick
3abf5d76f2 Growfs got missed in r323923 that added a check hash to cylinder groups.
This makes the needed changes to add/update cylinder group check hashes
when a filesystem is expanded.

Reported by: kib and Warner Losh (imp)
Reviewed by: kib
Tested by: Peter Holm (pho)
2017-10-10 16:17:03 +00:00
Ed Maste
1dc349ab95 prefix UFS symbols with UFS_ to reduce namespace pollution
Specifically:
  ROOTINO -> UFS_ROOTINO
  WINO -> UFS_WINO
  NXADDR -> UFS_NXADDR
  NDADDR -> UFS_NDADDR
  NIADDR -> UFS_NIADDR
  MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Also prefix ext2's and nandfs's NDADDR and NIADDR with EXT2_ and NANDFS_

Reviewed by:	kib, mckusick
Obtained from:	NetBSD
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D9536
2017-02-15 19:50:26 +00:00
Edward Tomasz Napierala
b8a1930fcf Cosmetic fixes for growfs(8) - remove unneeded capitalization and a spurious
newline, clarify a message.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-11 09:26:23 +00:00
Marcelo Araujo
e921a133f1 Use MIN() macro from sys/param.h.
Reviewed by:	trasz
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D6119
2016-05-02 00:44:19 +00:00
Marcelo Araujo
edf6b683e8 Use NULL instead of 0 for pointers.
strchr(3) will return NULL if the character does not appear in the
string.

MFC after:	2 weeks.
2016-04-18 14:08:35 +00:00
Edward Tomasz Napierala
a44ba043c9 Fix growfs(8) build with debug enabled (make -DGFSDBG).
PR:		199641
Submitted by:	Willem Jan Withagen <wjw at digiware dot nl>
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2015-04-24 12:48:48 +00:00
Christian Brueffer
295a5bd78c Refer newfs and growfs users to fsck_ffs instead of
fsck, the latter does not accept the referred to "-b" flag.

This change was accidently committed directly to 9-STABLE in
r237505.

PR:		82720
Submitted by:	David D.W. Downey
MFC after:	1 week
2014-02-09 14:28:47 +00:00
Eitan Adler
63efd0a107 Allow the use of lowercase 'yes'
PR:		bin/178422
Submitted by:	Garrett Cooper <yaneurabeya@gmail.com>
2013-05-08 18:55:38 +00:00
Xin LI
44246b4c36 Use arc4random() instead of random().
MFC after:	2 weeks
2013-04-15 05:39:21 +00:00
Edward Tomasz Napierala
be1bfa99a4 When growing a filesystem, don't leave unused space at the end
if there is not enough room for a full cylinder group.

Reviewed by:	mckusick@
2012-12-16 14:37:25 +00:00
Edward Tomasz Napierala
cd379aaff1 Fix extending filesystems of weird size by making sure the actual size
is always multiple of fragment size.
2012-12-15 08:53:58 +00:00
Edward Tomasz Napierala
2ec1a00656 Make it possible to resize filesystems mounted read-write, using newly
introduced UFS write suspension mechanism.

Reviewed by:	kib, mckusick
Sponsored by:	FreeBSD Foundation
2012-11-18 19:01:00 +00:00
Edward Tomasz Napierala
549f62fa42 Fix problem with geom_label(4) not recognizing UFS labels on filesystems
extended using growfs(8).  The problem here is that geom_label checks if
the filesystem size recorded in UFS superblock is equal to the provider
(i.e. device) size.  This check cannot be removed due to backward
compatibility.  On the other hand, in most cases growfs(8) cannot set
fs_size in the superblock to match the provider size, because, differently
from newfs(8), it cannot recompute cylinder group sizes.

To fix this problem, add another superblock field, fs_providersize, used
only for this purpose.  The geom_label(4) will attach if either fs_size
(filesystem created with newfs(8)) or fs_providersize (filesystem expanded
using growfs(8)) matches the device size.

PR:		kern/165962
Reviewed by:	mckusick
Sponsored by:	FreeBSD Foundation
2012-10-30 21:32:10 +00:00
Matthew D Fleming
e25a029eb2 Fix sbin/ build with a 64-bit ino_t.
Original code by:	Gleb Kurtsou
2012-09-27 23:31:06 +00:00
Eitan Adler
089d61ec12 Remove unneeded variable reported by gcc46 which stopped being used in
r234178.

Approved by:	cperciva
MFC after:	3 days
2012-07-07 17:25:36 +00:00
Edward Tomasz Napierala
deb35287b3 Fix offset calculation to actually rewrite the _last_ block. 2012-05-06 11:48:37 +00:00
Edward Tomasz Napierala
e35497f13b Improve growfs(8) in a few ways; unfortunately, it's somewhat hard to untangle
them and commit separately.

1. Rewrite the way growfs(8) finds the device and mount point.  This makes
   it possible to use e.g. "growfs /mnt"; it's also used to display more
   helpful messages.

2. Be more user-friendly, using descriptive messages, like this:

   OK to grow filesystem on /dev/md0, mounted on /mnt, from 9.8GB to 20GB? [Yes/No]"

3. Allow to specify the size (-s option) just like with mdconfig(8), i.e. with
   postfixes ("mdconfig -s 10g").

4. Reload read-only filesystem after growing.

Reviewed by:	kib, mckusick (earlier version)
Sponsored by:	The FreeBSD Foundation
2012-04-30 16:08:02 +00:00
Edward Tomasz Napierala
91ac147931 Style. 2012-04-18 13:50:17 +00:00
Edward Tomasz Napierala
f979d8ac99 Style. 2012-04-15 15:15:16 +00:00
Edward Tomasz Napierala
b408e19c58 Remove FSIRAND and FSMAXSWAP ifdefs, removing code unconditionally.
Reviewed by:	kib, mckusick
Sponsored by:	The FreeBSD Foundation
2012-04-15 15:13:29 +00:00
Edward Tomasz Napierala
6ad07d53c2 Style. 2012-04-12 16:55:48 +00:00
Edward Tomasz Napierala
9f2d8a3834 Remove block reallocation used to make room for the cylinder group
summary structure.  From now on, when there is no room for it,
we simply allocate new one in a newly added cylinder group.

This patch removes a conditional in updcsloc(), reindents some code
there, and removes unused routines.  I decided to do it this way instead
of disabling reallocation when the filesystem is live and leaving it
as it is otherwise, because this allows for removal of lots of complicated
and hard to test code.  Also, conditionally disabling it would result
in a different layout in filesystems resized online and offline, which
would look somewhat weird.

Reviewed by:		mckusick
No objections from:	kib
Sponsored by:		The FreeBSD Foundation
2012-04-12 13:43:43 +00:00
Edward Tomasz Napierala
50c603c4ec Remove disklabel handling code from growfs. This should be done
via geom_part(4), and it doesn't belong in growfs anyway.

Reviewed by:	kib, mckusick
Sponsored by:	The FreeBSD Foundation
2012-03-29 11:20:19 +00:00
Dimitry Andric
8f061f61db After r232548, clang complains about the apparent '=-' operator (a
left-over from ancient C times, and a frequent typo) in growfs.c:

sbin/growfs/growfs.c:1550:8: error: use of unary operator that may be intended as compound assignment (-=) [-Werror]
        blkno =- 1;
              ^~

Use 'blkno = -1' instead, to silence the error.
2012-03-12 11:15:44 +00:00
Edward Tomasz Napierala
a1da07403e Make growfs(8) mostly style compliant. No functional changes,
verified with MD5.
2012-03-05 16:37:51 +00:00
Ed Schouten
11dc480601 Allow growfs to be built with GCC 4.7 and -Werror.
The dp1 variable is only used when FSIRAND is defined. Just place the
variable behind #ifdefs entirely.
2012-01-17 22:19:35 +00:00
Ed Schouten
1efe3c6b58 Add missing static keywords for global variables to tools in sbin/.
These tools declare global variables without using the static keyword,
even though their use is limited to a single C-file, or without placing
an extern declaration of them in the proper header file.
2011-11-04 13:36:02 +00:00
Edward Tomasz Napierala
8857bdbc59 Revert the mechanical change from 'file system' to 'filesystem', committed
in r223429.  As bde@ pointed out, it was mostly backwards.
2011-06-28 19:59:46 +00:00
Edward Tomasz Napierala
b2168df843 Cosmetic fixes; mostly s/file system/filesystem/g and removing weird indent
from messages.
2011-06-22 17:59:53 +00:00
Rebecca Cran
974206cf70 Fix typos - remove duplicate "is".
PR:		docs/154934
Submitted by:	Eitan Adler <lists at eitanadler.com>
MFC after:	3 days
2011-02-23 09:22:33 +00:00
Marcel Moolenaar
ea6de5ee49 s/utime/modtime/g -- utime shadows utime(3).
Submitted by:	Garrett Cooper
2011-01-22 21:27:17 +00:00
Marcel Moolenaar
e29560acd7 Unbreak the build on strong-aligned architectures (arm, ia64).
Casting from (char *) to (struct ufs1_dinode *) changes the
alignment requirement of the pointer and GCC does not know that
the pointer is adequately aligned (due to malloc(3)), and warns
about it. Cast to (void *) first to by-pass the check.
2010-09-20 04:20:55 +00:00
Brian Somers
1ad5f80fac Revise r197763 which fixes filesystem corruption when extending
into un-zeroed storage.

The original patch was questioned by Kirk as it forces the filesystem
to do excessive work initialising inodes on first use, and was never
MFC'd.  This change mimics the newfs(8) approach of zeroing two
blocks of inodes for each new cylinder group.

Reviewed by:	mckusick
MFC after:	3 weeks
2010-09-19 08:18:56 +00:00
Gavin Atkinson
08f353ebe3 When growing a UFS1 filesystem, we need to initialise all inodes in any new
cylinder groups that are created.  When the filesystem is first created,
newfs always initialises the first two blocks of inodes, and then in the
UFS1 case will also initialise the remaining inode blocks.  The changes in
growfs.c 1.23 broke the initialisation of all inodes, seemingly based on
this implementation detail in newfs(8).  The result was that instead of
initialising all inodes, we would actually end up initialising all but the
first two blocks of inodes.  If the filesystem was grown into empty
(all-zeros) space then the resulting filesystem was fine, however when
grown onto non-zeroed space the filesystem produced would appear to have
massive corruption on the first fsck after growing.
A test case for this problem can be found in the PR audit trail.

Fix this by once again initialising all inodes in the UFS1 case.

PR:		bin/115174
Submitted by:	Nate Eldredgei  nge cs.hmc.edu
Reviewed by:	mjacob
MFC after:	1 month
2010-02-13 16:22:08 +00:00
Kirk McKusick
14a176a0e2 Quiet spurious warnings. 2010-02-11 06:42:08 +00:00
Gavin Atkinson
eb747250e6 Remove dead code. This section of code is only run in the
(sblock.fs_magic == FS_UFS1_MAGIC) case, so the check within the
loop is redundant.

Submitted by:	Nate Eldredge  nge cs.hmc.edu
Reviewed by:	mjacob
Approved by:	ed (mentor)
MFC after:	1 month
2010-01-02 20:18:10 +00:00
Matt Jacob
4bdcc9c7d7 The cylinder group tag cg_initediblk needs to match the number of inodes
actually initialized. In the growfs case for UFS2, no inodes were actually
being initialized and the number of inodes noted as initialized was the
number of inodes per group. This created a filesystem that was deemed
corrupted because the inodes thus added were full of garbage.

MFC after:	1 month
2009-10-05 01:31:16 +00:00
David Schultz
baa15be0ea Fix an int overflow on very large file systems.
PR:		bin/113399
Submitted by:	Staffan Ulfberg <staffan@ulfberg.se>
2007-12-17 08:03:18 +00:00
Stefan Farfeleder
42e355872b Remove duplicated assignment. 2006-07-17 20:48:36 +00:00
Philippe Charnier
e3ec673e97 Remove \n at the end of err(3) strings 2005-01-16 14:37:30 +00:00
Scott Long
e7c4605481 3 important fixes for growfs:
1) ginode() is passed a cylinder group number and inode number.  The inode
number is relative to the cg.  Use this relative number rather than the
absolute inode number when searching the cg inode bitmap to see if the inode
is allocated.  Using the absolute number quickly runs the check off the end
of the array and causes invalid inodes to be referenced.

2) ginode() checks the absolute indoe number to make sure that it is greater
than ROOTINO.  However, the caller loops through all of the possible inode
numbers and directly passes in values that are < ROOTINO.  Instead of halting
the program with an error, just return NULL.

3) When allocating new cylinder groups, growfs was initializing all of the
inodes in the group regardless of this only being required for UFS1.  Not
doing this for UFS2 provides a significant performance increase.

These fixes allow growing a filesystem beyond a trivial amount and have
been tested to grow an 8GB filesystem to 1.9TB.  Much more testing would
be appreciated.

Obtained from: Sandvine, Inc.
2004-10-09 02:53:47 +00:00
Lukas Ertl
691ae40438 Catch up with recent gcc changes and introduce a DIP_SET macro
to use when setting values that depend on the UFS version.
Raise WARNS again.
2004-07-29 11:28:24 +00:00