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.
13 #include "dm-path-selector.h"
15 #include <linux/slab.h>
18 struct path_selector_type pst;
20 struct list_head list;
24 #define pst_to_psi(__pst) container_of((__pst), struct ps_internal, pst)
26 static LIST_HEAD(_path_selectors);
27 static DECLARE_RWSEM(_ps_lock);
29 static struct ps_internal *__find_path_selector_type(const char *name)
31 struct ps_internal *psi;
33 list_for_each_entry(psi, &_path_selectors, list) {
34 if (!strcmp(name, psi->pst.name))
41 static struct ps_internal *get_path_selector(const char *name)
43 struct ps_internal *psi;
46 psi = __find_path_selector_type(name);
48 if ((psi->use == 0) && !try_module_get(psi->pst.module))
58 struct path_selector_type *dm_get_path_selector(const char *name)
60 struct ps_internal *psi;
65 psi = get_path_selector(name);
67 request_module("dm-%s", name);
68 psi = get_path_selector(name);
71 return psi ? &psi->pst : NULL;
74 void dm_put_path_selector(struct path_selector_type *pst)
76 struct ps_internal *psi;
82 psi = __find_path_selector_type(pst->name);
87 module_put(psi->pst.module);
95 static struct ps_internal *_alloc_path_selector(struct path_selector_type *pst)
97 struct ps_internal *psi = kmalloc(sizeof(*psi), GFP_KERNEL);
100 memset(psi, 0, sizeof(*psi));
107 int dm_register_path_selector(struct path_selector_type *pst)
110 struct ps_internal *psi = _alloc_path_selector(pst);
115 down_write(&_ps_lock);
117 if (__find_path_selector_type(pst->name)) {
121 list_add(&psi->list, &_path_selectors);
128 int dm_unregister_path_selector(struct path_selector_type *pst)
130 struct ps_internal *psi;
132 down_write(&_ps_lock);
134 psi = __find_path_selector_type(pst->name);
145 list_del(&psi->list);
154 EXPORT_SYMBOL_GPL(dm_register_path_selector);
155 EXPORT_SYMBOL_GPL(dm_unregister_path_selector);