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, 2017, 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 <lustre_disk.h>
35 #include <linux/rbtree.h>
37 #define DEFAULT_NODEMAP "default"
39 /* Default nobody uid, gid and projid values */
40 #define NODEMAP_NOBODY_UID 99
41 #define NODEMAP_NOBODY_GID 99
42 #define NODEMAP_NOBODY_PROJID 99
44 struct lprocfs_static_vars;
46 /* nodemap root proc directory under fs/lustre */
47 extern struct proc_dir_entry *proc_lustre_nodemap_root;
48 /* flag if nodemap is active */
49 extern bool nodemap_active;
51 extern struct mutex active_config_lock;
52 extern struct nodemap_config *active_config;
55 /* unique id set by mgs */
57 /* lu_nodemap containing this range */
58 struct lu_nodemap *rn_nodemap;
59 /* list for nodemap */
60 struct list_head rn_list;
61 /* list for nodemap config */
62 struct list_head rn_collect;
63 /* nid interval tree */
64 struct lnet_nid rn_start,
66 lnet_nid_t rn_subtree_last;
67 /* Large NID netmask */
73 /* uid/gid of client */
75 /* uid/gid on filesystem */
77 /* tree mapping client ids to filesystem ids */
78 struct rb_node id_client_to_fs;
79 /* tree mappung filesystem to client */
80 struct rb_node id_fs_to_client;
83 static inline enum nodemap_idx_type nm_idx_get_type(unsigned int id)
85 return id >> NM_TYPE_SHIFT;
88 static inline __u32 nm_idx_set_type(unsigned int id, enum nodemap_idx_type t)
90 return (id & NM_TYPE_MASK) | (t << NM_TYPE_SHIFT);
93 void nodemap_config_set_active(struct nodemap_config *config);
94 struct lu_nodemap *nodemap_create(const char *name,
95 struct nodemap_config *config,
97 void nodemap_putref(struct lu_nodemap *nodemap);
98 struct lu_nodemap *nodemap_lookup(const char *name);
100 int nodemap_procfs_init(void);
101 void nodemap_procfs_exit(void);
102 int lprocfs_nodemap_register(struct lu_nodemap *nodemap,
103 bool is_default_nodemap);
104 void lprocfs_nodemap_remove(struct nodemap_pde *nodemap_pde);
105 struct lu_nid_range *range_create(struct nodemap_config *config,
106 const struct lnet_nid *start_nid,
107 const struct lnet_nid *end_nid,
108 u8 netmask, struct lu_nodemap *nodemap,
109 unsigned int range_id);
110 void range_destroy(struct lu_nid_range *range);
111 int range_insert(struct nodemap_config *config, struct lu_nid_range *data);
112 void range_delete(struct nodemap_config *config, struct lu_nid_range *data);
113 struct lu_nid_range *range_search(struct nodemap_config *config,
114 struct lnet_nid *nid);
115 struct lu_nid_range *range_find(struct nodemap_config *config,
116 const struct lnet_nid *start_nid,
117 const struct lnet_nid *end_nid,
119 void range_init_tree(void);
120 struct lu_idmap *idmap_create(__u32 client_id, __u32 fs_id);
121 struct lu_idmap *idmap_insert(enum nodemap_id_type id_type,
122 struct lu_idmap *idmap,
123 struct lu_nodemap *nodemap);
124 void idmap_delete(enum nodemap_id_type id_type, struct lu_idmap *idmap,
125 struct lu_nodemap *nodemap);
126 void idmap_delete_tree(struct lu_nodemap *nodemap);
127 struct lu_idmap *idmap_search(struct lu_nodemap *nodemap,
128 enum nodemap_tree_type,
129 enum nodemap_id_type id_type,
131 int nm_member_add(struct lu_nodemap *nodemap, struct obd_export *exp);
132 void nm_member_del(struct lu_nodemap *nodemap, struct obd_export *exp);
133 void nm_member_delete_list(struct lu_nodemap *nodemap);
134 struct lu_nodemap *nodemap_classify_nid(struct lnet_nid *nid);
135 void nm_member_reclassify_nodemap(struct lu_nodemap *nodemap);
136 void nm_member_revoke_locks(struct lu_nodemap *nodemap);
137 void nm_member_revoke_locks_always(struct lu_nodemap *nodemap);
138 void nm_member_revoke_all(void);
140 int nodemap_add_idmap_helper(struct lu_nodemap *nodemap,
141 enum nodemap_id_type id_type,
143 int nodemap_add_range_helper(struct nodemap_config *config,
144 struct lu_nodemap *nodemap,
145 const struct lnet_nid nid[2],
146 u8 netmask, unsigned int range_id);
148 struct rb_node *nm_rb_next_postorder(const struct rb_node *node);
149 struct rb_node *nm_rb_first_postorder(const struct rb_root *root);
150 void nodemap_getref(struct lu_nodemap *nodemap);
151 void nodemap_putref(struct lu_nodemap *nodemap);
152 int nm_hash_list_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
153 struct hlist_node *hnode,
154 void *nodemap_list_head);
156 #define nm_rbtree_postorder_for_each_entry_safe(pos, n, \
158 for (pos = nm_rb_first_postorder(root) ? \
159 rb_entry(nm_rb_first_postorder(root), typeof(*pos), \
161 n = (pos && nm_rb_next_postorder(&pos->field)) ? \
162 rb_entry(nm_rb_next_postorder(&pos->field), \
163 typeof(*pos), field) : NULL; \
166 n = (pos && nm_rb_next_postorder(&pos->field)) ? \
167 rb_entry(nm_rb_next_postorder(&pos->field), \
168 typeof(*pos), field) : NULL)
170 int nodemap_idx_nodemap_add(const struct lu_nodemap *nodemap);
171 int nodemap_idx_nodemap_update(const struct lu_nodemap *nodemap);
172 int nodemap_idx_nodemap_del(const struct lu_nodemap *nodemap);
173 int nodemap_idx_cluster_roles_add(const struct lu_nodemap *nodemap);
174 int nodemap_idx_cluster_roles_update(const struct lu_nodemap *nodemap);
175 int nodemap_idx_cluster_roles_del(const struct lu_nodemap *nodemap);
176 int nodemap_idx_idmap_add(const struct lu_nodemap *nodemap,
177 enum nodemap_id_type id_type,
179 int nodemap_idx_idmap_del(const struct lu_nodemap *nodemap,
180 enum nodemap_id_type id_type,
182 int nodemap_idx_range_add(const struct lu_nid_range *range);
183 int nodemap_idx_range_del(const struct lu_nid_range *range);
184 int nodemap_idx_nodemap_activate(bool value);
185 #endif /* _NODEMAP_INTERNAL_H */