This macro is deprecated in autoconf 2.72.
Remove it and fix the following warning:
configure.ac:167: warning: The macro 'AC_PROG_GCC_TRADITIONAL' is obsolete.
configure.ac:167: You should run autoupdate.
./lib/autoconf/c.m4:1676: AC_PROG_GCC_TRADITIONAL is expanded from...
configure.ac:167: the top level
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
nilfs_find_fs(), called from nilfs_open(), parses "/proc/mounts" using its
own routines, but these parsing routines have a problem in that they
cannot handle escaped path strings. For example, if the mount point path
name contains spaces, the search will fail.
This is causing errors when running lscp, lssu, and other nilfs tools.
Fix this issue by avoiding custom parsing and using standard mount table
access routines such as setmntent(), getmntent_r(), endmntent(), and
hasmntopt().
Closes: https://github.com/nilfs-dev/nilfs-utils/issues/22
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Although nilfs_cleaner_find_fs() uses endmntent() to close the file
descriptor for "/proc/mounts", its uses fopen() directly to open it
instead of setmntent(). This asymmetry is undesirable because it can
cause unintended problems such as lock inconsistencies. Therefore,
properly use setmntent().
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The block address is now represented by uint64_t, but only mkfs.nilfs2
uses its own type "blocknr_t".
Eliminate the own type so that the bit width of variables that handle
it can be made stricter (such as when displaying).
Additionally, to avoid obscuring the meaning of "start" in identifiers
intended to be block addresses, rename them to "start_blocknr".
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The commands under "bin/" output the error messages by themselves by
setting opterr to 0, and are compatible with getopt_long, but if
an invalid long option is specified, the option that causes the error
will not be displayed as shown below:
lscp: invalid option --
Also lscp and lssu do not properly display error messages for options
that require an additional argument and it is not provided.
Fix these issues by not setting opterr to 0 and leaving error output
for argument options to getopt() or getopt_long()'s built-in features.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
These commands overlap the error messages output by getopt() or
getopt_long() and the error messages output by themselves when invalid
command line options are specified.
Fix this issue by removing the own error message and printing the
usage instructions instead.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
nilfs_resize_count_inuse_segments() is used to count the segments to
be moved in order to evaluate the progress of the progress bar.
However, the current implementation counts segments whose flags are in
the reclaimable state (dirty, not active, not error), and does not
count active segments, resulting in a discrepancy.
To represent the progress bar more acculately, change the count to
literally "in-use" (dirty) segments instead of reclaimable segments.
Also, there is some confusion regarding the term "in-use" in the
description of the nilfs_resize_reclaim() function, so correct that
as well.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
nilfs_resize_inuse_segments() checks the sufile's segusage flags and
collects and returns the numbers of segments that are reclaimable
(dirty, not active, not error). However, this function name is a bit
confusing, since active segments are also "in-use".
Change the function name to the more direct
nilfs_resize_reclaimable_segments() in order to treat "inuse" as meaning
that it is literally in use, including active segments.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
If nilfs_acc_blocks_segment() fails, nilfs_acc_blocks() returns an
error without releasing the segment allocated by nilfs_get_segment()
with nilfs_put_segment().
Fix this potential leak issue by calling nilfs_put_segment() regardless
of whether the call to nilfs_acc_blocks_segment() is successful or not.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
In order to shrink the file system even when there are only active
segments in the area to be truncated, force arcive segments to be
evicted by creating a file (called a balloon file) with the required
size on the root directory of the file system and then deleting it.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Allow nilfs_resize_find_active_segments() to return the total number
of used blocks in the active segments it finds through an optional
argument.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Define and apply the msg() wrapper macro err(), which adds and outputs
the error cause string, and errx(), which outputs the error message
without adding the error cause.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Add and apply the verbose_msg() macro that prints the argument's
message when global variable "verbose" is true.
Also, shorten the name of the message output function "myprintf" for
coexistence with a progress bar to "msg".
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Add export functions to get the absolute path name or file descriptor
of the mount point directory (file system root directory).
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
In the current libnilfs implementation, nilfs_open() returns the first
matching mount when searching the mount table. Therefore, when the
same mount points are stacked, the inaccessible mount point will be
unexpectedly selected.
Fix this issue by choosing the last match instead of the first one
when searching the mount table.
The changes required here also fixes potential memory leaks related to
device pathname and mount point pathname strings when nilfs_find_fs()
is called multiple times.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
When nilfs_open() opens a mount point to obtain an ioctl FD, it may be
overlaid by another mount and may be a directory of a file system
mounted with a different device.
Most nilfs utilities cannot operate in situations where the mount
point is hidden, but with the current implementation, an ioctl FD is
opened for the overlying file system, and ioctl commands are issued
wrongly for it.
Fix this issue by detecting such condition and returning a ENOENT error
in that case.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
mkfs.nilfs2, nilfs-resize, and nilfs-tune commands do not display the
error cause when they fail to open a nilfs2 device, so add a string
that represents the error.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
In the current implementation, if nilfs_open() fails to retrieve an
existing nilfs mount from the mount table, it returns an error with
errno = ENOENT, resulting in inappropriate error messages, such as the
following:
$ lscp /dev/sdb1
lscp: cannot open NILFS on /dev/sdb1: No such file or directory
Fix this issue by changing the error code set in errno to ENXIO.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
libmount based umount.nilfs2 does not display the node (target)
correctly in its message on error as below:
umount.nilfs2: (null): device is busy
Fix this issue.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The ability to maintain per-checkpoint block count statistics was enabled
in kernel 2.6.39, and at the same time a dedicated compat flag
(NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT) was introduced to prevent this
block count from being corrupted by read/write mounts in earlier versions.
More than 12 years have passed since this flag was introduced, and there
are almost no opportunities to mount nilfs2 partitions with older kernels
of this generation (it is not recommended in the first place), so turn on
this flag for new file systems created by mkfs.nilfs2.
Note that we can use nilfs-tune command to clear or reset this flag.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Change nilfs_resize_check_free_space() to output the required device
size instead of the total byte size of the required segments when free
space is insufficient.
This gives a guideline for the device size to be specified when
respecifying the device size and retrying shrinking.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
When we specify a fractional device size for nilfs-resize command, the
device size will be abnormally truncated due to an error in size
correction calculation (missing type cast).
For example, if we specify 8,796,093,023,200 bytes (= 8TiB - 32 bytes)
as the device size for an 8TiB partition, the size will be adjusted to
512 bytes as shown below, resulting in an insufficient size error:
$ sudo nilfs-resize /dev/loop0 8796093023200
size 8796093023200 is not aligned to sector size. truncated to 512.
Partition size = 8796093023232 bytes.
Shrink the filesystem size from 8796093023232 bytes to 512 bytes.
Error: the filesystem does not have enough free space.
At least 10 more segments (83886080 bytes) are required.
Aborted.
Fix this issue by inserting the missing typecast in the alignment
correction calculation. After applying this modification, the device
size will be rounded down appropriately to the sector size as shown
below:
$ sudo nilfs-resize /dev/loop0 8796093023200
size 8796093023200 is not aligned to sector size. truncated to 8796093022720.
Partition size = 8796093023232 bytes.
Shrink the filesystem size from 8796093023232 bytes to 8796093022720 bytes.
No segments will be truncated.
Do you wish to proceed (y/N)? y
Done.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
If we specify a device size less than 4096 bytes, an insufficient size
error will occur, but due to an underflow in calculating the number of
segments, the output of the required number of segments and required
size will become abnormal:
$ sudo nilfs-resize /dev/loop0 1024
Partition size = 8796093023232 bytes.
Shrink the filesystem size from 8796093022720 bytes to 1024 bytes.
Error: the filesystem does not have enough free space.
At least 18446741984637458845 more segments (922337203713998848
bytes) are required.
Aborted.
Fix this issue by preventing underflow when calculating the number of
segments.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
When outputting the number segments in messages, switch between
singular and plural forms of string "segment" depending on the count.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The nilfs-tune command's show_nilfs_sb() function, incorrectly uses
the 32-bit width conversion macro le32_to_cpu() for two 16-bit width
fields, so fix them.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Like other commands, add the "-V" option to display version information
and suppress output during normal execution.
Also update the manpage and help messages.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The current mkfs.nilfs2 device mount status check does not support
files mounted via loop devices.
Use libmountchk (check_mount) for stricter checking.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The check_mount() function used to check the mount of a block device
does not support determining the mount status when the source is an
image file mounted via a loop device.
As a result, nilfs-tune can rewrite the loop device mount source file
without the force option "-f".
Fix this issue by making check_mount() detect if a loop device is
attached and a file system is mounted on it.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
This moves the definition of PATH_MAX, including completions where
PATH_MAX is undefined, to "compat.h" so that it does not have to be
defined in multiple places.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
In preparation for adding a routine that searches for a backing file
from a loop device, make the major() and minor() macros available.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Since the exit code when the mount is detected is the success value,
it is not possible to determine whether the program was successfully
executed or not just from the exit code.
Fix this issue by returning an error exit code when a mount is
detected on the device during the mount check performed without
the "-f" option.
Also use errx() to output the error message and adjust the message
format.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The "-f" option is missing from the help message, so add it. Also,
organize the help message by execution examples.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Unlike mkfs.nilfs2, nilfs-tune and dumpseg commands will cause errors
if used directly on a disk image files. This is because
__nilfs_sb_read(), which reads superblocks, uses the BLKGETSIZE64 ioctl
command to get the device size, which fails for disk image files.
Fix this issue by using the size information obtained from the fstat
system call for regular files.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The bundled kernel's uapi header files ("nilfs2_ondisk.h" and
"nilfs2_api.h") are included in kernel-related development packages
in modern Linux distributions, resulting in duplicate installations.
In order to eliminate this duplication, make the installation of these
files optional and not install them by default.
The utilities will continue to refer to the included uapi header files,
and will only allow installation on the system, which can be specified
using the "--enable-uapi-header-install" option in configure file
arguments.
This is a workaround for older environments and should normally be
disabled.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Change the location of the uapi header files "nilfs2_ondisk.h" and
"nilfs2_api.h" to the "linux" subdirectory, as they are located in Linux
kernel-related development packages.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
For nilfs2 mounts that are read-only mounted and then remounted in
read/write mode, nilfs_cleanerd will no longer be shut down by umount or
remount, and the file system will not be able to be unmounted unless the
user manually kills it.
This is because the mount root key "ROOT", which libmount needs to
identify the mount entry on utab that stores file system-specific mount
attributes, is not set by remount or fake mount. This prevents
libmount-based mount and umount programs from correctly inheriting
cleanerd's PID, making it impossible to control cleanerd when remounting
or unmounting.
Fix this issue by searching the mount table and completing the missing
mount root with the mount entry information obtained when performing
remount or fake mount.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Add a general-purpose mount entry search function nilfs_find_mount(),
which makes nilfs_find_rw_mount() more general and allows the caller to
specify matching conditions for the mount point and mount options.
This is a preparation to resolve issues with cleanerd state management
in {mount,umount}_libmount.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Although the return value of nilfs_resize_count_inuse_segments() is type
ssize_t, nilfs_shrink_online(), which calls it, receives the return value
as a local variable of type uint64_t.
This causes the following abnormality:
1. If nilfs_resize_count_inuse_segments() returns an error, it is not
treated as an error, and the message output assuming its success it not
skipped.
2. An abnormal progress message like "Moving xx in-use segment(null)." is
output during file system shrink in a 32-bit environment due to type
mismatch.
Fix these issues by changing the type of the local variable in question to
ssize_t.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Add configuration method to install libraries into a subdirectory such as
/usr/lib64/nilfs instead of /usr/lib64.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
An issue exists where scrapped segments generated during recovery of
dsync blocks are incorrectly determined to be protected due to
comparisons using invalid segment summary sequence numbers on disk.
Segments that are incorrectly determined to be protected will not be
reclaimed for a long period of time, occupying disk space unnecessarily.
In addition, it may prevent nilfs-resize from shrinking the file system.
Fix these issues by using segment usage information to determine whether
a segment has been scrapped, in which case it is considered unprotected
without comparing sequence numbers.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Insert kernel-doc comments before each major function to help understand
internal behavior and ease maintenance.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Fix error in checkpatch.pl errors due to use of deprecated unescaped
left braces in perl regular expressions.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
GCC 8 emits -Wstringop-truncation warnings at user_string() and
group_string().
This suppresses these warnings by explicitly writing a null character
to the last character in buffers, even if it is not computationally
necessary.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
For the volume name buffer in super blocks, we store a volume name
without a terminating null character if it is truncated to the buffer
size.
This suppresses false positive -Wstringop-truncation warnings of GCC 8
related to the volume name buffers and adds comments so as to clarify
the treatment of truncation on them.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The current note about dependency on the selinux library is obscure.
Clarify that libselinux-devel (or libselinux1-dev) package is not
required unless we explicitly remove the use of libmount.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The nilfs-utils master branch is newer than v2.2.y branch, but it
looks older from the version number of utilities since it still
remains as 2.2.5.
To avoid the confusion, adjust the version number with '-dev'
pre-release suffix.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The AC_TYPE_SIGNAL macro is diagnosed as obsolete in Autoconf 2.70 and
later:
configure.ac:164: warning: The macro `AC_TYPE_SIGNAL' is obsolete.
configure.ac:164: You should run autoupdate.
./lib/autoconf/types.m4:776: AC_TYPE_SIGNAL is expanded from...
configure.ac:164: the top level
AC_TYPE_SIGNAL defines the value of RETSIGTYPE macro, which will be
set to 'void' or 'int' depending on platforms. But, in the first
place, signal handlers returning 'int' became obsolete long ago and no
modern C platforms use the legacy return type.
So, this replaces RETSIGTYPE with 'void' in codebase of nilfs-utils in
addition to removing the AC_TYPE_SIGNAL macro.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The AC_HEADER_TIME macro is diagnosed as obsolete in Autoconf 2.70 and
later:
configure.ac:150: warning: The macro `AC_HEADER_TIME' is obsolete.
configure.ac:150: You should run autoupdate.
./lib/autoconf/headers.m4:743: AC_HEADER_TIME is expanded from...
configure.ac:150: the top level
We don't use the result (TIME_WITH_SYS_TIME) of AC_HEADER_TIME, so
just remove the macro to fix the warning.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>