diff options
author | Stefan Behrens <sbehrens@giantdisaster.de> | 2012-05-25 10:06:09 -0400 |
---|---|---|
committer | Josef Bacik <josef@redhat.com> | 2012-05-30 10:23:40 -0400 |
commit | c11d2c236cc260b36ef644700fbe99bcc7e7da33 (patch) | |
tree | e240721e0b6e5784177ac39bc299db4063b93c72 /fs/btrfs/volumes.c | |
parent | 442a4f6308e694e0fa6025708bd5e4e424bbf51c (diff) |
Btrfs: add ioctl to get and reset the device stats
An ioctl interface is added to get the device statistic counters.
A second ioctl is added to atomically get and reset these counters.
Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r-- | fs/btrfs/volumes.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 2915521f44ee..a112b758822e 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -4673,3 +4673,37 @@ void btrfs_dev_stat_print_on_error(struct btrfs_device *dev) | |||
4673 | btrfs_dev_stat_read(dev, | 4673 | btrfs_dev_stat_read(dev, |
4674 | BTRFS_DEV_STAT_GENERATION_ERRS)); | 4674 | BTRFS_DEV_STAT_GENERATION_ERRS)); |
4675 | } | 4675 | } |
4676 | |||
4677 | int btrfs_get_dev_stats(struct btrfs_root *root, | ||
4678 | struct btrfs_ioctl_get_dev_stats *stats, | ||
4679 | int reset_after_read) | ||
4680 | { | ||
4681 | struct btrfs_device *dev; | ||
4682 | struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; | ||
4683 | int i; | ||
4684 | |||
4685 | mutex_lock(&fs_devices->device_list_mutex); | ||
4686 | dev = btrfs_find_device(root, stats->devid, NULL, NULL); | ||
4687 | mutex_unlock(&fs_devices->device_list_mutex); | ||
4688 | |||
4689 | if (!dev) { | ||
4690 | printk(KERN_WARNING | ||
4691 | "btrfs: get dev_stats failed, device not found\n"); | ||
4692 | return -ENODEV; | ||
4693 | } else if (reset_after_read) { | ||
4694 | for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++) { | ||
4695 | if (stats->nr_items > i) | ||
4696 | stats->values[i] = | ||
4697 | btrfs_dev_stat_read_and_reset(dev, i); | ||
4698 | else | ||
4699 | btrfs_dev_stat_reset(dev, i); | ||
4700 | } | ||
4701 | } else { | ||
4702 | for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++) | ||
4703 | if (stats->nr_items > i) | ||
4704 | stats->values[i] = btrfs_dev_stat_read(dev, i); | ||
4705 | } | ||
4706 | if (stats->nr_items > BTRFS_DEV_STAT_VALUES_MAX) | ||
4707 | stats->nr_items = BTRFS_DEV_STAT_VALUES_MAX; | ||
4708 | return 0; | ||
4709 | } | ||