Release 4.7 drivers/md/dm-round-robin.c
/*
* Copyright (C) 2003 Sistina Software.
* Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
*
* Module Author: Heinz Mauelshagen
*
* This file is released under the GPL.
*
* Round-robin path selector.
*/
#include <linux/device-mapper.h>
#include "dm-path-selector.h"
#include <linux/slab.h>
#include <linux/module.h>
#define DM_MSG_PREFIX "multipath round-robin"
#define RR_MIN_IO 1000
#define RR_VERSION "1.1.0"
/*-----------------------------------------------------------------
* Path-handling code, paths are held in lists
*---------------------------------------------------------------*/
struct path_info {
struct list_head list;
struct dm_path *path;
unsigned repeat_count;
};
static void free_paths(struct list_head *paths)
{
struct path_info *pi, *next;
list_for_each_entry_safe(pi, next, paths, list) {
list_del(&pi->list);
kfree(pi);
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alasdair kergon | alasdair kergon | 44 | 100.00% | 1 | 100.00% |
| Total | 44 | 100.00% | 1 | 100.00% |
/*-----------------------------------------------------------------
* Round-robin selector
*---------------------------------------------------------------*/
struct selector {
struct list_head valid_paths;
struct list_head invalid_paths;
spinlock_t lock;
struct dm_path * __percpu *current_path;
struct percpu_counter repeat_count;
};
static void set_percpu_current_path(struct selector *s, struct dm_path *path)
{
int cpu;
for_each_possible_cpu(cpu)
*per_cpu_ptr(s->current_path, cpu) = path;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
mike snitzer | mike snitzer | 35 | 100.00% | 1 | 100.00% |
| Total | 35 | 100.00% | 1 | 100.00% |
static struct selector *alloc_selector(void)
{
struct selector *s = kmalloc(sizeof(*s), GFP_KERNEL);
if (!s)
return NULL;
INIT_LIST_HEAD(&s->valid_paths);
INIT_LIST_HEAD(&s->invalid_paths);
spin_lock_init(&s->lock);
s->current_path = alloc_percpu(struct dm_path *);
if (!s->current_path)
goto out_current_path;
set_percpu_current_path(s, NULL);
if (percpu_counter_init(&s->repeat_count, 0, GFP_KERNEL))
goto out_repeat_count;
return s;
out_repeat_count:
free_percpu(s->current_path);
out_current_path:
kfree(s);
return NULL;;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
mike snitzer | mike snitzer | 77 | 61.11% | 2 | 66.67% |
alasdair kergon | alasdair kergon | 49 | 38.89% | 1 | 33.33% |
| Total | 126 | 100.00% | 3 | 100.00% |
static int rr_create(struct path_selector *ps, unsigned argc, char **argv)
{
struct selector *s;
s = alloc_selector();
if (!s)
return -ENOMEM;
ps->context = s;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alasdair kergon | alasdair kergon | 47 | 100.00% | 2 | 100.00% |
| Total | 47 | 100.00% | 2 | 100.00% |
static void rr_destroy(struct path_selector *ps)
{
struct selector *s = ps->context;
free_paths(&s->valid_paths);
free_paths(&s->invalid_paths);
free_percpu(s->current_path);
percpu_counter_destroy(&s->repeat_count);
kfree(s);
ps->context = NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alasdair kergon | alasdair kergon | 47 | 75.81% | 2 | 66.67% |
mike snitzer | mike snitzer | 15 | 24.19% | 1 | 33.33% |
| Total | 62 | 100.00% | 3 | 100.00% |
static int rr_status(struct path_selector *ps, struct dm_path *path,
status_type_t type, char *result, unsigned int maxlen)
{
struct path_info *pi;
int sz = 0;
if (!path)
DMEMIT("0 ");
else {
switch(type) {
case STATUSTYPE_INFO:
break;
case STATUSTYPE_TABLE:
pi = path->pscontext;
DMEMIT("%u ", pi->repeat_count);
break;
}
}
return sz;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alasdair kergon | alasdair kergon | 81 | 98.78% | 1 | 50.00% |
josef 'jeff' sipek | josef 'jeff' sipek | 1 | 1.22% | 1 | 50.00% |
| Total | 82 | 100.00% | 2 | 100.00% |
/*
* Called during initialisation to register each path with an
* optional repeat_count.
*/
static int rr_add_path(struct path_selector *ps, struct dm_path *path,
int argc, char **argv, char **error)
{
struct selector *s = ps->context;
struct path_info *pi;
unsigned repeat_count = RR_MIN_IO;
char dummy;
unsigned long flags;
if (argc > 1) {
*error = "round-robin ps: incorrect number of arguments";
return -EINVAL;
}
/* First path argument is number of I/Os before switching path */
if ((argc == 1) && (sscanf(argv[0], "%u%c", &repeat_count, &dummy) != 1)) {
*error = "round-robin ps: invalid repeat count";
return -EINVAL;
}
/* allocate the path */
pi = kmalloc(sizeof(*pi), GFP_KERNEL);
if (!pi) {
*error = "round-robin ps: Error allocating path context";
return -ENOMEM;
}
pi->path = path;
pi->repeat_count = repeat_count;
path->pscontext = pi;
spin_lock_irqsave(&s->lock, flags);
list_add_tail(&pi->list, &s->valid_paths);
spin_unlock_irqrestore(&s->lock, flags);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alasdair kergon | alasdair kergon | 163 | 83.16% | 1 | 20.00% |
mike snitzer | mike snitzer | 24 | 12.24% | 1 | 20.00% |
mikulas patocka | mikulas patocka | 7 | 3.57% | 1 | 20.00% |
jonathan brassow | jonathan brassow | 1 | 0.51% | 1 | 20.00% |
josef 'jeff' sipek | josef 'jeff' sipek | 1 | 0.51% | 1 | 20.00% |
| Total | 196 | 100.00% | 5 | 100.00% |
static void rr_fail_path(struct path_selector *ps, struct dm_path *p)
{
unsigned long flags;
struct selector *s = ps->context;
struct path_info *pi = p->pscontext;
spin_lock_irqsave(&s->lock, flags);
if (p == *this_cpu_ptr(s->current_path))
set_percpu_current_path(s, NULL);
list_move(&pi->list, &s->invalid_paths);
spin_unlock_irqrestore(&s->lock, flags);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alasdair kergon | alasdair kergon | 46 | 51.11% | 1 | 25.00% |
mike snitzer | mike snitzer | 43 | 47.78% | 2 | 50.00% |
josef 'jeff' sipek | josef 'jeff' sipek | 1 | 1.11% | 1 | 25.00% |
| Total | 90 | 100.00% | 4 | 100.00% |
static int rr_reinstate_path(struct path_selector *ps, struct dm_path *p)
{
unsigned long flags;
struct selector *s = ps->context;
struct path_info *pi = p->pscontext;
spin_lock_irqsave(&s->lock, flags);
list_move(&pi->list, &s->valid_paths);
spin_unlock_irqrestore(&s->lock, flags);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alasdair kergon | alasdair kergon | 49 | 66.22% | 1 | 33.33% |
mike snitzer | mike snitzer | 24 | 32.43% | 1 | 33.33% |
josef 'jeff' sipek | josef 'jeff' sipek | 1 | 1.35% | 1 | 33.33% |
| Total | 74 | 100.00% | 3 | 100.00% |
static struct dm_path *rr_select_path(struct path_selector *ps, size_t nr_bytes)
{
unsigned long flags;
struct selector *s = ps->context;
struct path_info *pi = NULL;
struct dm_path *current_path = NULL;
current_path = *this_cpu_ptr(s->current_path);
if (current_path) {
percpu_counter_dec(&s->repeat_count);
if (percpu_counter_read_positive(&s->repeat_count) > 0)
return current_path;
}
spin_lock_irqsave(&s->lock, flags);
if (!list_empty(&s->valid_paths)) {
pi = list_entry(s->valid_paths.next, struct path_info, list);
list_move_tail(&pi->list, &s->valid_paths);
percpu_counter_set(&s->repeat_count, pi->repeat_count);
set_percpu_current_path(s, pi->path);
current_path = pi->path;
}
spin_unlock_irqrestore(&s->lock, flags);
return current_path;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
mike snitzer | mike snitzer | 98 | 56.32% | 2 | 40.00% |
alasdair kergon | alasdair kergon | 73 | 41.95% | 1 | 20.00% |
kiyoshi ueda | kiyoshi ueda | 2 | 1.15% | 1 | 20.00% |
josef 'jeff' sipek | josef 'jeff' sipek | 1 | 0.57% | 1 | 20.00% |
| Total | 174 | 100.00% | 5 | 100.00% |
static struct path_selector_type rr_ps = {
.name = "round-robin",
.module = THIS_MODULE,
.table_args = 1,
.info_args = 0,
.create = rr_create,
.destroy = rr_destroy,
.status = rr_status,
.add_path = rr_add_path,
.fail_path = rr_fail_path,
.reinstate_path = rr_reinstate_path,
.select_path = rr_select_path,
};
static int __init dm_rr_init(void)
{
int r = dm_register_path_selector(&rr_ps);
if (r < 0)
DMERR("register failed %d", r);
DMINFO("version " RR_VERSION " loaded");
return r;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alasdair kergon | alasdair kergon | 38 | 92.68% | 2 | 66.67% |
mike snitzer | mike snitzer | 3 | 7.32% | 1 | 33.33% |
| Total | 41 | 100.00% | 3 | 100.00% |
static void __exit dm_rr_exit(void)
{
int r = dm_unregister_path_selector(&rr_ps);
if (r < 0)
DMERR("unregister failed %d", r);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alasdair kergon | alasdair kergon | 31 | 100.00% | 2 | 100.00% |
| Total | 31 | 100.00% | 2 | 100.00% |
module_init(dm_rr_init);
module_exit(dm_rr_exit);
MODULE_DESCRIPTION(DM_NAME " round-robin multipath path selector");
MODULE_AUTHOR("Sistina Software <dm-devel@redhat.com>");
MODULE_LICENSE("GPL");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alasdair kergon | alasdair kergon | 801 | 68.93% | 4 | 30.77% |
mike snitzer | mike snitzer | 341 | 29.35% | 3 | 23.08% |
mikulas patocka | mikulas patocka | 8 | 0.69% | 2 | 15.38% |
josef 'jeff' sipek | josef 'jeff' sipek | 6 | 0.52% | 1 | 7.69% |
paul gortmaker | paul gortmaker | 3 | 0.26% | 1 | 7.69% |
kiyoshi ueda | kiyoshi ueda | 2 | 0.17% | 1 | 7.69% |
jonathan brassow | jonathan brassow | 1 | 0.09% | 1 | 7.69% |
| Total | 1162 | 100.00% | 13 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.