From 5f1bcf28e725f8638cfbd1f84d321730b1e3ac9d Mon Sep 17 00:00:00 2001 From: Mike Snitzer Date: Mon, 5 Aug 2013 16:27:04 -0400 Subject: [PATCH 6/9] dm stats: cleaned up docs a bit and other whitespace tweaks --- Documentation/device-mapper/dm-statistics.txt | 13 ++++++------- drivers/md/dm-stats.c | 23 ++++++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Documentation/device-mapper/dm-statistics.txt b/Documentation/device-mapper/dm-statistics.txt index 7049caa..6578741 100644 --- a/Documentation/device-mapper/dm-statistics.txt +++ b/Documentation/device-mapper/dm-statistics.txt @@ -24,7 +24,7 @@ Messages "" - the number of sectors in each area "/" - the range is subdivided into the specified number - of areas + of areas An optional parameter. The string that identifies a program that created this range. The kernel returns this string back in the @@ -72,7 +72,7 @@ that were returned are cleared. @stats_delete region id returned from @stats_create -Deletes the range with the specified id. +Deletes the region with the specified id. @stats_list [] Lists all regions registered with @stats_create. @@ -87,13 +87,12 @@ Output format: Example ======= -Subdivide the logical volume vg1/lv into 100 pieces and start collecting +Subdivide the DM device 'vol' into 100 pieces and start collecting statistics on them: -dmsetup message vg1-lv 0 @stats_create - /100 +dmsetup message vol 0 @stats_create - /100 Print the statistics: -dmsetup message vg1-lv 0 @stats_print 0 +dmsetup message vol 0 @stats_print 0 Delete the statistics: -dmsetup message vg1-lv 0 @stats_delete 0 - +dmsetup message vol 0 @stats_delete 0 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c index d27bb0e..fa6dbed 100644 --- a/drivers/md/dm-stats.c +++ b/drivers/md/dm-stats.c @@ -69,6 +69,7 @@ static size_t shared_memory_amount = 0; static bool _check_shared_memory(size_t alloc_size) { size_t a; + a = shared_memory_amount + alloc_size; if (a < shared_memory_amount) return false; @@ -158,8 +159,9 @@ static void kvfree(void *ptr, size_t alloc_size) static void dm_stat_free(struct rcu_head *head) { - struct dm_stat *m = container_of(head, struct dm_stat, rcu_head); int cpu; + struct dm_stat *m = container_of(head, struct dm_stat, rcu_head); + kfree(m->program); kfree(m->aux); for_each_possible_cpu(cpu) @@ -175,6 +177,7 @@ static int dm_stat_in_flight(struct dm_stat_shared *s) void dm_stats_init_device(struct dm_stats *st) { int cpu; + mutex_init(&st->mutex); INIT_LIST_HEAD(&st->list); st->last = alloc_percpu(struct dm_stats_last_position); @@ -189,6 +192,7 @@ void dm_stats_init_device(struct dm_stats *st) void dm_stats_exit_device(struct dm_stats *st) { size_t ni; + while (!list_empty(&st->list)) { struct dm_stat *m = container_of(st->list.next, struct dm_stat, list_entry); list_del(&m->list_entry); @@ -373,6 +377,7 @@ static int dm_stats_list(struct dm_stats *st, const char *program, { struct dm_stat *m; unsigned sz = 0; + mutex_lock(&st->mutex); list_for_each_entry(m, &st->list, list_entry) { if (!program || !strcmp(program, m->program)) @@ -384,6 +389,7 @@ static int dm_stats_list(struct dm_stats *st, const char *program, m->aux); } mutex_unlock(&st->mutex); + return 1; } @@ -396,6 +402,7 @@ static void dm_stat_round(struct dm_stat_shared *s, struct dm_stat_percpu *p) unsigned in_flight_read; unsigned in_flight_write; unsigned long difference = now - s->stamp; + if (!difference) return; in_flight_read = atomic_read(&s->in_flight[0]); @@ -519,16 +526,16 @@ static unsigned long long jtom(unsigned long long j) { unsigned long long result = 0; unsigned mult; - if (j) { + + if (j) result = jiffies_to_msecs(j & 0x3fffff); - } if (j >= 1 << 22) { mult = jiffies_to_msecs(1 << 22); result += (unsigned long long)mult * (unsigned long long)jiffies_to_msecs((j >> 22) & 0x3fffff); } - if (j >= 1ULL << 44) { + if (j >= 1ULL << 44) result += (unsigned long long)mult * (unsigned long long)mult * (unsigned long long)jiffies_to_msecs(j >> 44); - } + return result; } @@ -706,8 +713,7 @@ static int message_stats_create(struct mapped_device *md, * If a buffer overflow happens after we created the region, * it's too late (the userspace would retry with a larger * buffer, but the region id that caused the overflow is already - * leaked). - * So we must detect buffer overflow in advance. + * leaked). So we must detect buffer overflow in advance. */ snprintf(result, maxlen, "%d", INT_MAX); if (dm_message_test_buffer_overflow(result, maxlen)) @@ -715,7 +721,6 @@ static int message_stats_create(struct mapped_device *md, id = dm_stats_create(dm_get_stats(md), start, end, step, program, aux, dm_internal_suspend, dm_internal_resume, md); - if (id < 0) return id; @@ -743,8 +748,8 @@ static int message_stats_list(struct mapped_device *md, unsigned argc, char **argv, char *result, unsigned maxlen) { - const char *program = NULL; int r; + const char *program = NULL; if (argc < 1 || argc > 2) return -EINVAL; -- 1.7.1