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;
21 struct list_head list;
25 #define pst_to_psi(__pst) container_of((__pst), struct ps_internal, pst)
27 static LIST_HEAD(_path_selectors);
28 static DECLARE_RWSEM(_ps_lock);
30 static struct ps_internal *__find_path_selector_type(const char *name)
32 struct ps_internal *psi;
34 list_for_each_entry(psi, &_path_selectors, list) {
35 if (!strcmp(name, psi->pst.name))
42 static struct ps_internal *get_path_selector(const char *name)
44 struct ps_internal *psi;
47 psi = __find_path_selector_type(name);
49 if ((psi->use == 0) && !try_module_get(psi->pst.module))
59 struct path_selector_type *dm_get_path_selector(const char *name)
61 struct ps_internal *psi;
66 psi = get_path_selector(name);
68 request_module("dm-%s", name);
69 psi = get_path_selector(name);
72 return psi ? &psi->pst : NULL;
75 void dm_put_path_selector(struct path_selector_type *pst)
77 struct ps_internal *psi;
83 psi = __find_path_selector_type(pst->name);
88 module_put(psi->pst.module);
96 static struct ps_internal *_alloc_path_selector(struct path_selector_type *pst)
98 struct ps_internal *psi = kzalloc(sizeof(*psi), GFP_KERNEL);
106 int dm_register_path_selector(struct path_selector_type *pst)
109 struct ps_internal *psi = _alloc_path_selector(pst);
114 down_write(&_ps_lock);
116 if (__find_path_selector_type(pst->name)) {
120 list_add(&psi->list, &_path_selectors);
127 int dm_unregister_path_selector(struct path_selector_type *pst)
129 struct ps_internal *psi;
131 down_write(&_ps_lock);
133 psi = __find_path_selector_type(pst->name);
144 list_del(&psi->list);
153 EXPORT_SYMBOL_GPL(dm_register_path_selector);
154 EXPORT_SYMBOL_GPL(dm_unregister_path_selector);