2 * Copyright (C) 2003 Sistina Software.
3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
5 * Module Author: Heinz Mauelshagen
7 * This file is released under the GPL.
9 * Path selector registration.
12 #include <linux/device-mapper.h>
14 #include "dm-path-selector.h"
16 #include <linux/slab.h>
19 struct path_selector_type pst;
20 struct list_head list;
23 #define pst_to_psi(__pst) container_of((__pst), struct ps_internal, pst)
25 static LIST_HEAD(_path_selectors);
26 static DECLARE_RWSEM(_ps_lock);
28 static struct ps_internal *__find_path_selector_type(const char *name)
30 struct ps_internal *psi;
32 list_for_each_entry(psi, &_path_selectors, list) {
33 if (!strcmp(name, psi->pst.name))
40 static struct ps_internal *get_path_selector(const char *name)
42 struct ps_internal *psi;
45 psi = __find_path_selector_type(name);
46 if (psi && !try_module_get(psi->pst.module))
53 struct path_selector_type *dm_get_path_selector(const char *name)
55 struct ps_internal *psi;
60 psi = get_path_selector(name);
62 request_module("dm-%s", name);
63 psi = get_path_selector(name);
66 return psi ? &psi->pst : NULL;
69 void dm_put_path_selector(struct path_selector_type *pst)
71 struct ps_internal *psi;
77 psi = __find_path_selector_type(pst->name);
81 module_put(psi->pst.module);
86 static struct ps_internal *_alloc_path_selector(struct path_selector_type *pst)
88 struct ps_internal *psi = kzalloc(sizeof(*psi), GFP_KERNEL);
96 int dm_register_path_selector(struct path_selector_type *pst)
99 struct ps_internal *psi = _alloc_path_selector(pst);
104 down_write(&_ps_lock);
106 if (__find_path_selector_type(pst->name)) {
110 list_add(&psi->list, &_path_selectors);
117 int dm_unregister_path_selector(struct path_selector_type *pst)
119 struct ps_internal *psi;
121 down_write(&_ps_lock);
123 psi = __find_path_selector_type(pst->name);
129 list_del(&psi->list);
138 EXPORT_SYMBOL_GPL(dm_register_path_selector);
139 EXPORT_SYMBOL_GPL(dm_unregister_path_selector);