1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2003 Sistina Software.
4 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
6 * Module Author: Heinz Mauelshagen
8 * This file is released under the GPL.
10 * Path selector registration.
13 #include <linux/device-mapper.h>
14 #include <linux/module.h>
16 #include "dm-path-selector.h"
18 #include <linux/slab.h>
21 struct path_selector_type pst;
22 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);
48 if (psi && !try_module_get(psi->pst.module))
55 struct path_selector_type *dm_get_path_selector(const char *name)
57 struct ps_internal *psi;
62 psi = get_path_selector(name);
64 request_module("dm-%s", name);
65 psi = get_path_selector(name);
68 return psi ? &psi->pst : NULL;
71 void dm_put_path_selector(struct path_selector_type *pst)
73 struct ps_internal *psi;
79 psi = __find_path_selector_type(pst->name);
83 module_put(psi->pst.module);
88 static struct ps_internal *_alloc_path_selector(struct path_selector_type *pst)
90 struct ps_internal *psi = kzalloc(sizeof(*psi), GFP_KERNEL);
98 int dm_register_path_selector(struct path_selector_type *pst)
101 struct ps_internal *psi = _alloc_path_selector(pst);
106 down_write(&_ps_lock);
108 if (__find_path_selector_type(pst->name)) {
112 list_add(&psi->list, &_path_selectors);
118 EXPORT_SYMBOL_GPL(dm_register_path_selector);
120 int dm_unregister_path_selector(struct path_selector_type *pst)
122 struct ps_internal *psi;
124 down_write(&_ps_lock);
126 psi = __find_path_selector_type(pst->name);
132 list_del(&psi->list);
140 EXPORT_SYMBOL_GPL(dm_unregister_path_selector);