Whamcloud - gitweb
86c55b0346aaf9ba784fc9434ce6cc923c727b6e
[fs/lustre-release.git] / lustre / ptlrpc / nodemap_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (C) 2013, Trustees of Indiana University
24  *
25  * Copyright (c) 2013, 2014, Intel Corporation.
26  *
27  * Author: Joshua Walgenbach <jjw@iu.edu>
28  */
29
30 #ifndef _NODEMAP_INTERNAL_H
31 #define _NODEMAP_INTERNAL_H
32
33 #include <lustre_nodemap.h>
34 #include <interval_tree.h>
35
36 #define MODULE_STRING "nodemap"
37
38 /* Default nobody uid and gid values */
39
40 #define NODEMAP_NOBODY_UID 99
41 #define NODEMAP_NOBODY_GID 99
42
43 struct lprocfs_static_vars;
44
45 /* nodemap root proc directory under fs/lustre */
46 extern struct proc_dir_entry *proc_lustre_nodemap_root;
47 /* flag if nodemap is active */
48 extern bool nodemap_active;
49
50 extern struct mutex active_config_lock;
51 extern struct nodemap_config *active_config;
52
53 struct lu_nid_range {
54         /* unique id set by mgs */
55         unsigned int             rn_id;
56         /* lu_nodemap containing this range */
57         struct lu_nodemap       *rn_nodemap;
58         /* list for nodemap */
59         struct list_head         rn_list;
60         /* nid interval tree */
61         struct interval_node     rn_node;
62 };
63
64 struct lu_idmap {
65         /* uid/gid of client */
66         __u32           id_client;
67         /* uid/gid on filesystem */
68         __u32           id_fs;
69         /* tree mapping client ids to filesystem ids */
70         struct rb_node  id_client_to_fs;
71         /* tree mappung filesystem to client */
72         struct rb_node  id_fs_to_client;
73 };
74
75 struct nodemap_range_tree {
76         struct interval_node *nmrt_range_interval_root;
77         unsigned int nmrt_range_highest_id;
78 };
79
80 struct nodemap_config {
81         /* Highest numerical lu_nodemap.nm_id defined */
82         unsigned int nmc_nodemap_highest_id;
83
84         /* Simple flag to determine if nodemaps are active */
85         bool nmc_nodemap_is_active;
86
87         /* Pointer to default nodemap as it is needed more often */
88         struct lu_nodemap *nmc_default_nodemap;
89
90         /**
91          * Lock required to access the range tree.
92          */
93         struct rw_semaphore nmc_range_tree_lock;
94         struct nodemap_range_tree nmc_range_tree;
95
96         /**
97          * Hash keyed on nodemap name containing all
98          * nodemaps
99          */
100         struct cfs_hash *nmc_nodemap_hash;
101 };
102
103 struct nodemap_config *nodemap_config_alloc(void);
104 void nodemap_config_dealloc(struct nodemap_config *config);
105 void nodemap_config_set_active(struct nodemap_config *config);
106 struct lu_nodemap *nodemap_create(const char *name,
107                                   struct nodemap_config *config,
108                                   bool is_default);
109 void nodemap_putref(struct lu_nodemap *nodemap);
110 struct lu_nodemap *nodemap_lookup(const char *name);
111
112 int nodemap_procfs_init(void);
113 void nodemap_procfs_exit(void);
114 int lprocfs_nodemap_register(struct lu_nodemap *nodemap,
115                              bool is_default_nodemap);
116 void lprocfs_nodemap_remove(struct nodemap_pde *nodemap_pde);
117 struct lu_nid_range *nodemap_range_find(lnet_nid_t start_nid,
118                                         lnet_nid_t end_nid);
119 struct lu_nid_range *range_create(struct nodemap_range_tree *nm_range_tree,
120                                   lnet_nid_t start_nid, lnet_nid_t end_nid,
121                                   struct lu_nodemap *nodemap);
122 void range_destroy(struct lu_nid_range *range);
123 int range_insert(struct nodemap_range_tree *nm_range_tree,
124                  struct lu_nid_range *data);
125 void range_delete(struct nodemap_range_tree *nm_range_tree,
126                   struct lu_nid_range *data);
127 struct lu_nid_range *range_search(struct nodemap_range_tree *nm_range_tree,
128                                   lnet_nid_t nid);
129 struct lu_nid_range *range_find(struct nodemap_range_tree *nm_range_tree,
130                                 lnet_nid_t start_nid, lnet_nid_t end_nid);
131 int range_parse_nidstring(char *range_string, lnet_nid_t *start_nid,
132                           lnet_nid_t *end_nid);
133 void range_init_tree(void);
134 struct lu_idmap *idmap_create(__u32 client_id, __u32 fs_id);
135 void idmap_insert(enum nodemap_id_type id_type, struct lu_idmap *idmap,
136                  struct lu_nodemap *nodemap);
137 void idmap_delete(enum nodemap_id_type id_type,  struct lu_idmap *idmap,
138                   struct lu_nodemap *nodemap);
139 void idmap_delete_tree(struct lu_nodemap *nodemap);
140 struct lu_idmap *idmap_search(struct lu_nodemap *nodemap,
141                               enum nodemap_tree_type,
142                               enum nodemap_id_type id_type,
143                               __u32 id);
144 int nm_member_add(struct lu_nodemap *nodemap, struct obd_export *exp);
145 void nm_member_del(struct lu_nodemap *nodemap, struct obd_export *exp);
146 void nm_member_delete_list(struct lu_nodemap *nodemap);
147 struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid);
148 void nm_member_reclassify_nodemap(struct lu_nodemap *nodemap);
149 void nm_member_revoke_locks(struct lu_nodemap *nodemap);
150 void nm_member_revoke_all(void);
151
152 struct rb_node *nm_rb_next_postorder(const struct rb_node *node);
153 struct rb_node *nm_rb_first_postorder(const struct rb_root *root);
154 void nodemap_putref(struct lu_nodemap *nodemap);
155
156 #define nm_rbtree_postorder_for_each_entry_safe(pos, n,                 \
157                                                 root, field)            \
158         for (pos = nm_rb_first_postorder(root) ?                        \
159                 rb_entry(nm_rb_first_postorder(root), typeof(*pos),     \
160                 field) : NULL,                                          \
161                 n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
162                 rb_entry(nm_rb_next_postorder(&pos->field),             \
163                 typeof(*pos), field) : NULL;                            \
164                 pos != NULL;                                            \
165                 pos = n,                                                \
166                 n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
167                 rb_entry(nm_rb_next_postorder(&pos->field),             \
168                 typeof(*pos), field) : NULL)
169 #endif  /* _NODEMAP_INTERNAL_H */