Whamcloud - gitweb
LU-16524 nodemap: add rbac property to nodemap
[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, 2017, 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 <lustre_disk.h>
35 #include <linux/rbtree.h>
36
37 #define DEFAULT_NODEMAP "default"
38
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
43
44 struct lprocfs_static_vars;
45
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;
50
51 extern struct mutex active_config_lock;
52 extern struct nodemap_config *active_config;
53
54 struct lu_nid_range {
55         /* unique id set by mgs */
56         unsigned int             rn_id;
57         /* lu_nodemap containing this range */
58         struct lu_nodemap       *rn_nodemap;
59         /* list for nodemap */
60         struct list_head         rn_list;
61         /* nid interval tree */
62         lnet_nid_t               rn_start,
63                                  rn_end,
64                                  rn_subtree_last;
65         struct rb_node           rn_rb;
66 };
67
68 struct lu_idmap {
69         /* uid/gid of client */
70         __u32           id_client;
71         /* uid/gid on filesystem */
72         __u32           id_fs;
73         /* tree mapping client ids to filesystem ids */
74         struct rb_node  id_client_to_fs;
75         /* tree mappung filesystem to client */
76         struct rb_node  id_fs_to_client;
77 };
78
79 static inline enum nodemap_idx_type nm_idx_get_type(unsigned int id)
80 {
81         return id >> NM_TYPE_SHIFT;
82 }
83
84 static inline __u32 nm_idx_set_type(unsigned int id, enum nodemap_idx_type t)
85 {
86         return (id & NM_TYPE_MASK) | (t << NM_TYPE_SHIFT);
87 }
88
89 void nodemap_config_set_active(struct nodemap_config *config);
90 struct lu_nodemap *nodemap_create(const char *name,
91                                   struct nodemap_config *config,
92                                   bool is_default);
93 void nodemap_putref(struct lu_nodemap *nodemap);
94 struct lu_nodemap *nodemap_lookup(const char *name);
95
96 int nodemap_procfs_init(void);
97 void nodemap_procfs_exit(void);
98 int lprocfs_nodemap_register(struct lu_nodemap *nodemap,
99                              bool is_default_nodemap);
100 void lprocfs_nodemap_remove(struct nodemap_pde *nodemap_pde);
101 struct lu_nid_range *nodemap_range_find(lnet_nid_t start_nid,
102                                         lnet_nid_t end_nid);
103 struct lu_nid_range *range_create(struct nodemap_range_tree *nm_range_tree,
104                                   lnet_nid_t start_nid, lnet_nid_t end_nid,
105                                   struct lu_nodemap *nodemap,
106                                   unsigned int range_id);
107 void range_destroy(struct lu_nid_range *range);
108 int range_insert(struct nodemap_range_tree *nm_range_tree,
109                  struct lu_nid_range *data);
110 void range_delete(struct nodemap_range_tree *nm_range_tree,
111                   struct lu_nid_range *data);
112 struct lu_nid_range *range_search(struct nodemap_range_tree *nm_range_tree,
113                                   lnet_nid_t nid);
114 struct lu_nid_range *range_find(struct nodemap_range_tree *nm_range_tree,
115                                 lnet_nid_t start_nid, lnet_nid_t end_nid);
116 int range_parse_nidstring(char *range_string, lnet_nid_t *start_nid,
117                           lnet_nid_t *end_nid);
118 void range_init_tree(void);
119 struct lu_idmap *idmap_create(__u32 client_id, __u32 fs_id);
120 struct lu_idmap *idmap_insert(enum nodemap_id_type id_type,
121                               struct lu_idmap *idmap,
122                               struct lu_nodemap *nodemap);
123 void idmap_delete(enum nodemap_id_type id_type,  struct lu_idmap *idmap,
124                   struct lu_nodemap *nodemap);
125 void idmap_delete_tree(struct lu_nodemap *nodemap);
126 struct lu_idmap *idmap_search(struct lu_nodemap *nodemap,
127                               enum nodemap_tree_type,
128                               enum nodemap_id_type id_type,
129                               __u32 id);
130 int nm_member_add(struct lu_nodemap *nodemap, struct obd_export *exp);
131 void nm_member_del(struct lu_nodemap *nodemap, struct obd_export *exp);
132 void nm_member_delete_list(struct lu_nodemap *nodemap);
133 struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid);
134 void nm_member_reclassify_nodemap(struct lu_nodemap *nodemap);
135 void nm_member_revoke_locks(struct lu_nodemap *nodemap);
136 void nm_member_revoke_locks_always(struct lu_nodemap *nodemap);
137 void nm_member_revoke_all(void);
138
139 int nodemap_add_idmap_helper(struct lu_nodemap *nodemap,
140                              enum nodemap_id_type id_type,
141                              const __u32 map[2]);
142 int nodemap_add_range_helper(struct nodemap_config *config,
143                              struct lu_nodemap *nodemap,
144                              const lnet_nid_t nid[2],
145                              unsigned int range_id);
146
147 struct rb_node *nm_rb_next_postorder(const struct rb_node *node);
148 struct rb_node *nm_rb_first_postorder(const struct rb_root *root);
149 void nodemap_getref(struct lu_nodemap *nodemap);
150 void nodemap_putref(struct lu_nodemap *nodemap);
151 int nm_hash_list_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
152                     struct hlist_node *hnode,
153                     void *nodemap_list_head);
154
155 #define nm_rbtree_postorder_for_each_entry_safe(pos, n,                 \
156                                                 root, field)            \
157         for (pos = nm_rb_first_postorder(root) ?                        \
158                 rb_entry(nm_rb_first_postorder(root), typeof(*pos),     \
159                 field) : NULL,                                          \
160                 n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
161                 rb_entry(nm_rb_next_postorder(&pos->field),             \
162                 typeof(*pos), field) : NULL;                            \
163                 pos != NULL;                                            \
164                 pos = n,                                                \
165                 n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
166                 rb_entry(nm_rb_next_postorder(&pos->field),             \
167                 typeof(*pos), field) : NULL)
168
169 int nodemap_idx_nodemap_add(const struct lu_nodemap *nodemap);
170 int nodemap_idx_nodemap_update(const struct lu_nodemap *nodemap);
171 int nodemap_idx_nodemap_del(const struct lu_nodemap *nodemap);
172 int nodemap_idx_cluster_roles_add(const struct lu_nodemap *nodemap);
173 int nodemap_idx_cluster_roles_update(const struct lu_nodemap *nodemap);
174 int nodemap_idx_cluster_roles_del(const struct lu_nodemap *nodemap);
175 int nodemap_idx_idmap_add(const struct lu_nodemap *nodemap,
176                           enum nodemap_id_type id_type,
177                           const __u32 map[2]);
178 int nodemap_idx_idmap_del(const struct lu_nodemap *nodemap,
179                           enum nodemap_id_type id_type,
180                           const __u32 map[2]);
181 int nodemap_idx_range_add(const struct lu_nid_range *range,
182                           const lnet_nid_t nid[2]);
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 */