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 65534
41 #define NODEMAP_NOBODY_GID 65534
42 #define NODEMAP_NOBODY_PROJID 65534
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 void nodemap_getref(struct lu_nodemap *nodemap);
149 void nodemap_putref(struct lu_nodemap *nodemap);
150 int nm_hash_list_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
151 struct hlist_node *hnode,
152 void *nodemap_list_head);
154 int nodemap_idx_nodemap_add(const struct lu_nodemap *nodemap);
155 int nodemap_idx_nodemap_update(const struct lu_nodemap *nodemap);
156 int nodemap_idx_nodemap_del(const struct lu_nodemap *nodemap);
157 int nodemap_idx_cluster_roles_add(const struct lu_nodemap *nodemap);
158 int nodemap_idx_cluster_roles_update(const struct lu_nodemap *nodemap);
159 int nodemap_idx_cluster_roles_del(const struct lu_nodemap *nodemap);
160 int nodemap_idx_idmap_add(const struct lu_nodemap *nodemap,
161 enum nodemap_id_type id_type,
163 int nodemap_idx_idmap_del(const struct lu_nodemap *nodemap,
164 enum nodemap_id_type id_type,
166 int nodemap_idx_range_add(const struct lu_nid_range *range);
167 int nodemap_idx_range_del(const struct lu_nid_range *range);
168 int nodemap_idx_nodemap_activate(bool value);
169 int nodemap_index_read(struct lu_env *env, struct nm_config_file *ncf,
170 struct idx_info *ii, const struct lu_rdpg *rdpg);
172 #endif /* _NODEMAP_INTERNAL_H */