4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (C) 2013, Trustees of Indiana University
25 * Copyright (c) 2013, 2014, Intel Corporation.
27 * Author: Joshua Walgenbach <jjw@iu.edu>
30 #ifndef _NODEMAP_INTERNAL_H
31 #define _NODEMAP_INTERNAL_H
33 #include <lustre_nodemap.h>
34 #include <interval_tree.h>
36 #define DEFAULT_NODEMAP "default"
38 /* Turn on proc debug interface to allow OSS and
39 * MDS nodes to configure nodemap independently of
40 * MGS (since the nodemap distribution is not written
42 #define NODEMAP_PROC_DEBUG 1
44 /* Default nobody uid and gid values */
46 #define NODEMAP_NOBODY_UID 99
47 #define NODEMAP_NOBODY_GID 99
49 struct lprocfs_static_vars;
51 /* nodemap root proc directory under fs/lustre */
52 extern struct proc_dir_entry *proc_lustre_nodemap_root;
53 /* flag if nodemap is active */
54 extern bool nodemap_active;
56 extern struct mutex active_config_lock;
57 extern struct nodemap_config *active_config;
60 /* unique id set by mgs */
62 /* lu_nodemap containing this range */
63 struct lu_nodemap *rn_nodemap;
64 /* list for nodemap */
65 struct list_head rn_list;
66 /* nid interval tree */
67 struct interval_node rn_node;
71 /* uid/gid of client */
73 /* uid/gid on filesystem */
75 /* tree mapping client ids to filesystem ids */
76 struct rb_node id_client_to_fs;
77 /* tree mappung filesystem to client */
78 struct rb_node id_fs_to_client;
81 /* first 4 bits of the nodemap_id is the index type */
91 enum nodemap_idx_type {
92 NODEMAP_EMPTY_IDX = 0, /* index created with blank record */
93 NODEMAP_CLUSTER_IDX = 1, /* a nodemap cluster of nodes */
94 NODEMAP_RANGE_IDX = 2, /* nid range assigned to a nm cluster */
95 NODEMAP_UIDMAP_IDX = 3, /* uid map assigned to a nm cluster */
96 NODEMAP_GIDMAP_IDX = 4, /* gid map assigned to a nm cluster */
97 NODEMAP_GLOBAL_IDX = 15, /* stores nodemap activation status */
100 #define NM_TYPE_MASK 0x0FFFFFFF
101 #define NM_TYPE_SHIFT 28
103 static inline enum nodemap_idx_type nm_idx_get_type(unsigned int id)
105 return id >> NM_TYPE_SHIFT;
108 static inline __u32 nm_idx_set_type(unsigned int id, enum nodemap_idx_type t)
110 return (id & NM_TYPE_MASK) | (t << NM_TYPE_SHIFT);
113 void nodemap_config_set_active(struct nodemap_config *config);
114 struct lu_nodemap *nodemap_create(const char *name,
115 struct nodemap_config *config,
117 void nodemap_putref(struct lu_nodemap *nodemap);
118 struct lu_nodemap *nodemap_lookup(const char *name);
120 int nodemap_procfs_init(void);
121 void nodemap_procfs_exit(void);
122 int lprocfs_nodemap_register(struct lu_nodemap *nodemap,
123 bool is_default_nodemap);
124 void lprocfs_nodemap_remove(struct nodemap_pde *nodemap_pde);
125 struct lu_nid_range *nodemap_range_find(lnet_nid_t start_nid,
127 struct lu_nid_range *range_create(struct nodemap_range_tree *nm_range_tree,
128 lnet_nid_t start_nid, lnet_nid_t end_nid,
129 struct lu_nodemap *nodemap,
130 unsigned int range_id);
131 void range_destroy(struct lu_nid_range *range);
132 int range_insert(struct nodemap_range_tree *nm_range_tree,
133 struct lu_nid_range *data);
134 void range_delete(struct nodemap_range_tree *nm_range_tree,
135 struct lu_nid_range *data);
136 struct lu_nid_range *range_search(struct nodemap_range_tree *nm_range_tree,
138 struct lu_nid_range *range_find(struct nodemap_range_tree *nm_range_tree,
139 lnet_nid_t start_nid, lnet_nid_t end_nid);
140 int range_parse_nidstring(char *range_string, lnet_nid_t *start_nid,
141 lnet_nid_t *end_nid);
142 void range_init_tree(void);
143 struct lu_idmap *idmap_create(__u32 client_id, __u32 fs_id);
144 void idmap_insert(enum nodemap_id_type id_type, struct lu_idmap *idmap,
145 struct lu_nodemap *nodemap);
146 void idmap_delete(enum nodemap_id_type id_type, struct lu_idmap *idmap,
147 struct lu_nodemap *nodemap);
148 void idmap_delete_tree(struct lu_nodemap *nodemap);
149 struct lu_idmap *idmap_search(struct lu_nodemap *nodemap,
150 enum nodemap_tree_type,
151 enum nodemap_id_type id_type,
153 int nm_member_add(struct lu_nodemap *nodemap, struct obd_export *exp);
154 void nm_member_del(struct lu_nodemap *nodemap, struct obd_export *exp);
155 void nm_member_delete_list(struct lu_nodemap *nodemap);
156 struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid);
157 void nm_member_reclassify_nodemap(struct lu_nodemap *nodemap);
158 void nm_member_revoke_locks(struct lu_nodemap *nodemap);
159 void nm_member_revoke_locks_always(struct lu_nodemap *nodemap);
160 void nm_member_revoke_all(void);
162 int nodemap_add_idmap_helper(struct lu_nodemap *nodemap,
163 enum nodemap_id_type id_type,
165 int nodemap_add_range_helper(struct nodemap_config *config,
166 struct lu_nodemap *nodemap,
167 const lnet_nid_t nid[2],
168 unsigned int range_id);
170 struct rb_node *nm_rb_next_postorder(const struct rb_node *node);
171 struct rb_node *nm_rb_first_postorder(const struct rb_root *root);
172 void nodemap_getref(struct lu_nodemap *nodemap);
173 void nodemap_putref(struct lu_nodemap *nodemap);
174 int nm_hash_list_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
175 struct hlist_node *hnode,
176 void *nodemap_list_head);
178 #define nm_rbtree_postorder_for_each_entry_safe(pos, n, \
180 for (pos = nm_rb_first_postorder(root) ? \
181 rb_entry(nm_rb_first_postorder(root), typeof(*pos), \
183 n = (pos && nm_rb_next_postorder(&pos->field)) ? \
184 rb_entry(nm_rb_next_postorder(&pos->field), \
185 typeof(*pos), field) : NULL; \
188 n = (pos && nm_rb_next_postorder(&pos->field)) ? \
189 rb_entry(nm_rb_next_postorder(&pos->field), \
190 typeof(*pos), field) : NULL)
192 int nodemap_idx_nodemap_add(const struct lu_nodemap *nodemap);
193 int nodemap_idx_nodemap_update(const struct lu_nodemap *nodemap);
194 int nodemap_idx_nodemap_del(const struct lu_nodemap *nodemap);
195 int nodemap_idx_idmap_add(const struct lu_nodemap *nodemap,
196 enum nodemap_id_type id_type,
198 int nodemap_idx_idmap_del(const struct lu_nodemap *nodemap,
199 enum nodemap_id_type id_type,
201 int nodemap_idx_range_add(const struct lu_nid_range *range,
202 const lnet_nid_t nid[2]);
203 int nodemap_idx_range_del(const struct lu_nid_range *range);
204 int nodemap_idx_nodemap_activate(bool value);
205 #endif /* _NODEMAP_INTERNAL_H */