linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: init device stats for new devices
@ 2013-10-11 13:20 Stefan Behrens
  2013-10-11 13:43 ` Josef Bacik
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Stefan Behrens @ 2013-10-11 13:20 UTC (permalink / raw)
  To: linux-btrfs; +Cc: zab

Device stats are only initialized (read from tree items) on mount.
Trying to read device stats after adding or replacing new devices will
return errors.

btrfs_init_new_device() and btrfs_init_dev_replace_tgtdev() are the two
functions that allocate and initialize new btrfs_device structures after
a filesystem is mounted. They set the device stats to zero by using
kzalloc() which is correct for new devices. The only missing thing was
to declare these stats as being valid (device->dev_stats_valid = 1) and
this patch adds this missing code.

This is the reproducer:

TEST_DEV1=/dev/sdzzzzz1
TEST_DEV2=/dev/sdzzzzz2
TEST_DEV3=/dev/sdzzzzz3
TEST_MNT=/mnt
mkfs.btrfs $TEST_DEV1
mount $TEST_DEV1 $TEST_MNT
btrfs device add $TEST_DEV2 $TEST_MNT
btrfs device stat $TEST_MNT
btrfs replace start -B $TEST_DEV2 $TEST_DEV3 $TEST_MNT
btrfs device stat $TEST_MNT
umount $TEST_MNT

Reported-by: Ondrej Kunc <kunc88@gmail.com>
Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
---
The idea to fix this issue, the subject line of the patch and parts
of the commit log are reused from a patch that Zach Brown has sent.

 fs/btrfs/volumes.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 646d10d..9837439 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2041,6 +2041,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 	device->in_fs_metadata = 1;
 	device->is_tgtdev_for_dev_replace = 0;
 	device->mode = FMODE_EXCL;
+	device->dev_stats_valid = 1;
 	set_blocksize(device->bdev, 4096);
 
 	if (seeding_dev) {
@@ -2208,6 +2209,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path,
 	device->in_fs_metadata = 1;
 	device->is_tgtdev_for_dev_replace = 1;
 	device->mode = FMODE_EXCL;
+	device->dev_stats_valid = 1;
 	set_blocksize(device->bdev, 4096);
 	device->fs_devices = fs_info->fs_devices;
 	list_add(&device->dev_list, &fs_info->fs_devices->devices);
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* Not possible to read device stats for devices added after mount
@ 2013-09-28 19:49 Ondřej Kunc
  2013-09-30 21:58 ` [PATCH] btrfs: init device stats for new devices Zach Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Ondřej Kunc @ 2013-09-28 19:49 UTC (permalink / raw)
  To: linux-btrfs

Hi,

I discovered one minor bug in BTRFS filesystem. I made nagios check
for btrfs which reads device statistics for all devices in mounted
btrfs filesystem, calling btrfs dev stats /btrfs.

But there is one problem ... it's output looks like this:

[/dev/sda].corruption_errs 0
..
...
[/dev/sdt].generation_errs 0
ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on /dev/sdb2 failed: No such device
ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on /dev/sdh failed: No such device
ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on /dev/sdj failed: No such device
ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on /dev/sdk failed: No such device
ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on /dev/sdl failed: No such device
ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on /dev/sdp failed: No such device
ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on /dev/sdq failed: No such device
ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on /dev/sds failed: No such device
ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on /dev/sde failed: No such device

But this is not true ... all specified devices exist and are members
of btrfs filesystem. In dmesg I see this:
...
[973077.098957] btrfs: get dev_stats failed, not yet valid
[973077.098984] btrfs: get dev_stats failed, not yet valid
[973077.099011] btrfs: get dev_stats failed, not yet valid
[973077.099038] btrfs: get dev_stats failed, not yet valid
[973077.099065] btrfs: get dev_stats failed, not yet valid
[973077.099092] btrfs: get dev_stats failed, not yet valid
[973077.099118] btrfs: get dev_stats failed, not yet valid
....

What makes device statistics valid ? I tried doing full filesystem
scrub ... but it did not fix that issue.

Thank you for any hints

Using this kernel (if it matters):
3.10-2-amd64 #1 SMP Debian 3.10.7-1 (2013-08-17) x86_64 GNU/Linux

Ondřej Kunc

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-10-11 17:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-11 13:20 [PATCH] Btrfs: init device stats for new devices Stefan Behrens
2013-10-11 13:43 ` Josef Bacik
2013-10-11 17:32 ` Zach Brown
2013-10-11 17:36 ` Zach Brown
  -- strict thread matches above, loose matches on Subject: below --
2013-09-28 19:49 Not possible to read device stats for devices added after mount Ondřej Kunc
2013-09-30 21:58 ` [PATCH] btrfs: init device stats for new devices Zach Brown
2013-09-30 22:03   ` Ondřej Kunc
2013-09-30 22:54     ` Zach Brown
2013-10-07 15:25   ` Stefan Behrens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).