It's passed as const but we modify it through 'dots'. This would break
parsing the string multiple times.
Signed-off-by: David Sterba <dsterba@suse.com>
This is needed by the patch which introduces new devid option for the
btrfs device delete.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Breaking from the while loop makes ret overwritten to zero, goto error
label directly and return -ENOMEM.
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
The same code is executed when the condition "ret" is true or false,
because the code in the if-then branch and after the if statement is
identical.
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
The variable "err" is assigned to "ret" then "ret" gets overwritten by
check_extent_refs() before "ret" can be used. Reported by Coverity.
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
deeper code, and return fuzzy error message.
Before patch:
./btrfs-fragments -o 123 /mnt/tmp1
ERROR: can't perform the search
After patch:
# ./btrfs-fragments -o 123 /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.
Before patch:
# ./btrfs replace cancel /mnt/tmp1
ERROR: ioctl(DEV_REPLACE_CANCEL) failed on "/mnt/tmp1": Inappropriate ioctl for device
# ./btrfs replace status /mnt/tmp1
ERROR: ioctl(DEV_REPLACE_STATUS) failed on "/mnt/tmp1": Inappropriate ioctl for device
After patch:
# ./btrfs replace cancel /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs replace status /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Use btrfs_open_dir() in open_path_or_dev_mnt() to make the function
return error when target is neither block device nor btrfs mount point.
Also add "verbose" argument to let function output common error
message instead of putting duplicated lines in caller.
Before patch:
# ./btrfs device stats /mnt/tmp1
ERROR: getting dev info for devstats failed: Inappropriate ioctl for device
# ./btrfs replace start /dev/vdd /dev/vde /mnt/tmp1
ERROR: ioctl(DEV_REPLACE_STATUS) failed on "/mnt/tmp1": Inappropriate ioctl for device
After patch:
# ./btrfs device stats /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs replace start /dev/vdd /dev/vde /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.
Before patch:
# ./btrfs quota enable /mnt/tmp1
ERROR: quota command failed: Inappropriate ioctl for device
# ./btrfs quota disable /mnt/tmp1
ERROR: quota command failed: Inappropriate ioctl for device
# ./btrfs quota rescan /mnt/tmp1
ERROR: quota rescan failed: Inappropriate ioctl for device
#
After patch:
# ./btrfs quota enable /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs quota disable /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs quota rescan /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
#
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.
Before patch:
# ./btrfs qgroup create 1/5 /mnt/tmp1
ERROR: unable to create quota group: Inappropriate ioctl for device
#
# ./btrfs qgroup assign 1/5 2/5 /mnt/tmp1
ERROR: unable to assign quota group: Inappropriate ioctl for device
#
# ./btrfs qgroup show /mnt/tmp1
ERROR: can't perform the search - Inappropriate ioctl for device
ERROR: can't list qgroups: Inappropriate ioctl for device
#
# ./btrfs qgroup limit 1G 1/5 /mnt/tmp1
ERROR: unable to limit requested quota group: Inappropriate ioctl for device
After patch:
# ./btrfs qgroup create 1/5 /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs qgroup assign 1/5 2/5 /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs qgroup show /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs qgroup limit 1G 1/5 /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.
Before patch:
# ./btrfs inspect-internal rootid /mnt/tmp1
ERROR: Failed to lookup root id - Inappropriate ioctl for device
btrfs inspect-internal rootid: rootid failed with ret=-1
# ./btrfs inspect-internal inode-resolve 256 /mnt/tmp1
ioctl ret=-1, error: Inappropriate ioctl for device
# ./btrfs inspect-internal min-dev-size /mnt/tmp1
Error invoking tree search ioctl: Inappropriate ioctl for device
After patch:
# ./btrfs inspect-internal rootid /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs inspect-internal inode-resolve 256 /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs inspect-internal min-dev-size /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
In case of open_file_or_dir() failed, ret is not set to right value,
and the function will return unwanted value(ret of sprintf).
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
No need to cleanup fd in open_fail case, because it is not opened.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.
Before patch:
# btrfs balance start /mnt/tmp
ERROR: error during balancing '/mnt/tmp' - Inappropriate ioctl for device
There may be more info in syslog - try dmesg | tail
#
After patch:
# btrfs balance start /mnt/tmp
ERROR: not btrfs filesystem: /mnt/tmp
#
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.
Before patch:
# (/mnt/tmp is not btrfs mountpoint)
#
# btrfs filesystem df /mnt/tmp
ERROR: couldn't get space info - Inappropriate ioctl for device
ERROR: get_df failed Inappropriate ioctl for device
#
After patch:
# ./btrfs filesystem df /mnt/tmp
ERROR: not btrfs filesystem: /mnt/tmp
#
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.
Before patch:
# (/mnt/tmp is not btrfs mountpoint)
#
# btrfs subvolume create /mnt/tmp/123
Create subvolume '/mnt/tmp/123'
ERROR: cannot create subvolume - Inappropriate ioctl for device
#
After patch:
# btrfs subvolume create /mnt/tmp/123
ERROR: not btrfs filesystem: /mnt/tmp
#
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Include last_snapshot value in print_root(). With btrfs-debug-tree, it
helps to identify whether its a snapshot-ed subvolume or not.
Signed-off-by: Lakshmipathi.G <Lakshmipathi.G@giis.co.in>
Signed-off-by: David Sterba <dsterba@suse.com>
Copied from linux kernel, 'make W=1' will build with various additional
warnings turned on. There are 3 levels, combinations are possible. The
build is quite noisy, not all warnings need to be fixed.
A specific warning can be turned on by 'make EXTRA_CFLAGS=-Wsomething'.
Signed-off-by: David Sterba <dsterba@suse.com>
Set the variable TEST_LOG=tty (in the enviroment or as parameter to
make) to print commands executed by 'run_check' helpers to terminal (ie.
/dev/tty). This might be useful to see the test progress beside watching
the results file.
Signed-off-by: David Sterba <dsterba@suse.com>
This patch is generated from a coccinelle semantic patch:
identifier t;
expression e;
statement s;
@@
-t = malloc(e);
+t = calloc(1, e);
(
if (!t) s
|
if (t == NULL) s
|
)
-memset(t, 0, e);
Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com>
[squashed patches into one]
Signed-off-by: David Sterba <dsterba@suse.com>
Use common warning/error functions in cmds-scrub.c, it can make
message format unified and make code simple.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[removed ending newlines from messages]
Signed-off-by: David Sterba <dsterba@suse.com>
Current code use fprintf(stderr, "...") to output warnning and
error information.
The error message have different style, as:
# grep fprintf *.c
fprintf(stderr, "Open ctree failed\n");
fprintf(stderr, "%s: open ctree failed\n", __func__);
fprintf(stderr, "ERROR: cannot open ctree\n");
...
And sometimes, we forgot add tailed '\n', or use printf instead,
as in current code:
printf("warning, device %llu is missing\n",
This patch introduce warning() and error() as common function,
to make:
1: Each warning and error information have same format
2: Easy to search/change all error message
3: Easy to modify function's internal for debug or other requirement,
for example:
print function/linenumber in error()
dumpstack in error()
add some trace for some style of message
add support for -v, -vv, ...
support for locales
custom output functions
support some special device/tty
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[print newline after the message]
Signed-off-by: David Sterba <dsterba@suse.com>
Now btrfs-progs will have much more strict superblock checks based on
kernel superblock checks.
This should prevent crashes or invalid memory access on crafted or
fuzzed images.
Based on kernel commit c926093ec516f5d316ecdf8c1be11f577ac71b85 .
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[added reference to kernel and comments]
Signed-off-by: David Sterba <dsterba@suse.com>
Before the patch, btrfs-progs will only read sizeof(struct
btrfs_super_block) and restore it into super_copy.
This makes checksum check for superblock impossible. Change it to read
the whole superblock.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Scrub output prints the following error message in my test:
ERROR: scrubbing /var/ltf/tester/scratch_mnt failed for device id 5 (Success)
It is caused by a broken kernel and fs, but the we need to avoid
printing both "error and success" on one line as above.
This patch modified above message to:
ERROR: scrubbing /var/ltf/tester/scratch_mnt failed for device id 5: ret=1, errno=0 (Success)
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[minor updates in formatting]
Signed-off-by: David Sterba <dsterba@suse.com>
002-bad-transid outout 'transid verify failed' message in screen
which is just a warning in btrfs-image in normal condition of this
test.
This patch move above warning into $RESULTS, to:
1: Avoid trouble screen output
2: Let user known detail if other error happened in btrfs-image
Before patch:
# ./fsck-tests.sh
[TEST] 001-bad-file-extent-bytenr
[TEST] 002-bad-transid
parent transid verify failed on 29360128 wanted 9 found 755944791
parent transid verify failed on 29360128 wanted 9 found 755944791
Ignoring transid failure
[TEST] 003-shift-offsets
[TEST] 004-no-dir-index
...
After patch:
# ./fsck-tests.sh
[TEST] 001-bad-file-extent-bytenr
[TEST] 002-bad-transid
[TEST] 003-shift-offsets
[TEST] 004-no-dir-index
...
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
There is a bug in btrfs-convert in 4.1.2, even we don't allow mixed
block group for converted image, btrfs-convert will still create image
with data and metadata inside one chunk.
And further more, the chunk type is still DATA or METADATA, not
DATA|METADATA (not mixed).
So add btrfsck check for it right now.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
To check is btrfs-convert create bad filesystem with
leaf across stripes.
It is happened in progs version <=v4.1.2, and fixed by patch titled:
btrfs: convert: Avoid allocating metadata extent crossing stripe boundary
which was merged in v4.2.
Notice thar this testcase can not report error in old version of
btrfs-progs, because "btrfs check" can't check this type of error
in those version, but we have another testcase in fsck-tests, to
check is "btrfs check" support this check.
So, the above 2 testcase together can check leaf-crossing-stripes
bug in all versions.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[renamed and other minor changes]
Signed-off-by: David Sterba <dsterba@suse.com>
To test if fsck can check detec "leaf crossing stripes".
This function was introduced from patch titled:
btrfs-progs: fsck: Check if a metadata tree block crossing stripe boundary
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[renamed and other minor changes]
Signed-off-by: David Sterba <dsterba@suse.com>
Move code for extract image file to a function from check_all_images()
for common use, so caller can use this function to extrace single
image file.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[minor reformatting and updates]
Signed-off-by: David Sterba <dsterba@suse.com>
Fix a check of len versus PATH_MAX in function copy_symlink(), to
account for the terminating null byte.
Resolves-Coverity-CID: 1296749
Signed-off-by: Vincent Stehlé <vincent.stehle@freescale.com>
Signed-off-by: David Sterba <dsterba@suse.com>
In my local change to 07cc891d1d9819d5cf0628af555e7727d289cf7b
("btrfs-progs: Simplify all-subvolumn-clean condition for
wait_for_subvolume_cleaning") that reversed the meaning of the variable
dirty -> clean, I made a mistake and broke 'subvol sync' that will not
wait as expected and ends prematurely. Zhao Lei's original patch worked.
CC: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
When testing under libguestfs, btrfs-convert will never succeed to fix
chunk map, and always fails.
But in that case, it's already a mountable btrfs.
So better to info user with different error message for that case.
The root cause of it is still under investigation.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fsid can be mounted multiple times, with different subvolid.
And we don't have to scan a mount point if we already have
that in the scanned list.
And thus nicely avoids the following warning with multiple
subvol mounts on older kernel like 2.6.32 where
BTRFS_IOC_GET_FSLABEL ioctl does not exist.
./btrfs fi show -m
Label: none uuid: 31845933-611e-422d-ae6f-386e57ad81aa
Total devices 2 FS bytes used 172.00KiB
devid 1 size 3.00GiB used 642.38MiB path /dev/sdd
devid 2 size 3.00GiB used 622.38MiB path /dev/sde
warning, device 2 is missing
warning devid 2 not found already
warning, device 2 is missing
warning devid 2 not found already
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
load_device_info queries the FS_INFO ioctl and this may fail with EPERM
on older kernels. The check did not verify the ioctl return value and
incorrectly returned EPERM if it was previously stored in errno.
This fixes 'btrfs fi usage' that will print the overall summary for all
users (provided that the FS_INFO ioctl is already unprivileged).
Signed-off-by: David Sterba <dsterba@suse.com>
If there are different devices mounted to the same directory we can run
into double free issue in the scanning code and this can lead to a
crash. The dev_info_arg buffer allocation get_fs_info might be skipped,
eg. if the FS_INFO ioctl fails due to EPERM in older kernels. Reset the
pointer before each loop starts.
Signed-off-by: David Sterba <dsterba@suse.com>