Whamcloud - gitweb
LU-13783 procfs: fix improper prop_ops fields
[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 <linux/rbtree.h>
35
36 #define DEFAULT_NODEMAP "default"
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         lnet_nid_t               rn_start,
62                                  rn_end,
63                                  rn_subtree_last;
64         struct rb_node           rn_rb;
65 };
66
67 struct lu_idmap {
68         /* uid/gid of client */
69         __u32           id_client;
70         /* uid/gid on filesystem */
71         __u32           id_fs;
72         /* tree mapping client ids to filesystem ids */
73         struct rb_node  id_client_to_fs;
74         /* tree mappung filesystem to client */
75         struct rb_node  id_fs_to_client;
76 };
77
78 /* first 4 bits of the nodemap_id is the index type */
79 struct nodemap_key {
80         __u32 nk_nodemap_id;
81         union {
82                 __u32 nk_range_id;
83                 __u32 nk_id_client;
84                 __u32 nk_unused;
85         };
86 };
87
88 enum nodemap_idx_type {
89         NODEMAP_EMPTY_IDX = 0,          /* index created with blank record */
90         NODEMAP_CLUSTER_IDX = 1,        /* a nodemap cluster of nodes */
91         NODEMAP_RANGE_IDX = 2,          /* nid range assigned to a nm cluster */
92         NODEMAP_UIDMAP_IDX = 3,         /* uid map assigned to a nm cluster */
93         NODEMAP_GIDMAP_IDX = 4,         /* gid map assigned to a nm cluster */
94         NODEMAP_GLOBAL_IDX = 15,        /* stores nodemap activation status */
95 };
96
97 #define NM_TYPE_MASK 0x0FFFFFFF
98 #define NM_TYPE_SHIFT 28
99
100 static inline enum nodemap_idx_type nm_idx_get_type(unsigned int id)
101 {
102         return id >> NM_TYPE_SHIFT;
103 }
104
105 static inline __u32 nm_idx_set_type(unsigned int id, enum nodemap_idx_type t)
106 {
107         return (id & NM_TYPE_MASK) | (t << NM_TYPE_SHIFT);
108 }
109
110 void nodemap_config_set_active(struct nodemap_config *config);
111 struct lu_nodemap *nodemap_create(const char *name,
112                                   struct nodemap_config *config,
113                                   bool is_default);
114 void nodemap_putref(struct lu_nodemap *nodemap);
115 struct lu_nodemap *nodemap_lookup(const char *name);
116
117 int nodemap_procfs_init(void);
118 void nodemap_procfs_exit(void);
119 int lprocfs_nodemap_register(struct lu_nodemap *nodemap,
120                              bool is_default_nodemap);
121 void lprocfs_nodemap_remove(struct nodemap_pde *nodemap_pde);
122 struct lu_nid_range *nodemap_range_find(lnet_nid_t start_nid,
123                                         lnet_nid_t end_nid);
124 struct lu_nid_range *range_create(struct nodemap_range_tree *nm_range_tree,
125                                   lnet_nid_t start_nid, lnet_nid_t end_nid,
126                                   struct lu_nodemap *nodemap,
127                                   unsigned int range_id);
128 void range_destroy(struct lu_nid_range *range);
129 int range_insert(struct nodemap_range_tree *nm_range_tree,
130                  struct lu_nid_range *data);
131 void range_delete(struct nodemap_range_tree *nm_range_tree,
132                   struct lu_nid_range *data);
133 struct lu_nid_range *range_search(struct nodemap_range_tree *nm_range_tree,
134                                   lnet_nid_t nid);
135 struct lu_nid_range *range_find(struct nodemap_range_tree *nm_range_tree,
136                                 lnet_nid_t start_nid, lnet_nid_t end_nid);
137 int range_parse_nidstring(char *range_string, lnet_nid_t *start_nid,
138                           lnet_nid_t *end_nid);
139 void range_init_tree(void);
140 struct lu_idmap *idmap_create(__u32 client_id, __u32 fs_id);
141 struct lu_idmap *idmap_insert(enum nodemap_id_type id_type,
142                               struct lu_idmap *idmap,
143                               struct lu_nodemap *nodemap);
144 void idmap_delete(enum nodemap_id_type id_type,  struct lu_idmap *idmap,
145                   struct lu_nodemap *nodemap);
146 void idmap_delete_tree(struct lu_nodemap *nodemap);
147 struct lu_idmap *idmap_search(struct lu_nodemap *nodemap,
148                               enum nodemap_tree_type,
149                               enum nodemap_id_type id_type,
150                               __u32 id);
151 int nm_member_add(struct lu_nodemap *nodemap, struct obd_export *exp);
152 void nm_member_del(struct lu_nodemap *nodemap, struct obd_export *exp);
153 void nm_member_delete_list(struct lu_nodemap *nodemap);
154 struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid);
155 void nm_member_reclassify_nodemap(struct lu_nodemap *nodemap);
156 void nm_member_revoke_locks(struct lu_nodemap *nodemap);
157 void nm_member_revoke_locks_always(struct lu_nodemap *nodemap);
158 void nm_member_revoke_all(void);
159
160 int nodemap_add_idmap_helper(struct lu_nodemap *nodemap,
161                              enum nodemap_id_type id_type,
162                              const __u32 map[2]);
163 int nodemap_add_range_helper(struct nodemap_config *config,
164                              struct lu_nodemap *nodemap,
165                              const lnet_nid_t nid[2],
166                              unsigned int range_id);
167
168 struct rb_node *nm_rb_next_postorder(const struct rb_node *node);
169 struct rb_node *nm_rb_first_postorder(const struct rb_root *root);
170 void nodemap_getref(struct lu_nodemap *nodemap);
171 void nodemap_putref(struct lu_nodemap *nodemap);
172 int nm_hash_list_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
173                     struct hlist_node *hnode,
174                     void *nodemap_list_head);
175
176 #define nm_rbtree_postorder_for_each_entry_safe(pos, n,                 \
177                                                 root, field)            \
178         for (pos = nm_rb_first_postorder(root) ?                        \
179                 rb_entry(nm_rb_first_postorder(root), typeof(*pos),     \
180                 field) : NULL,                                          \
181                 n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
182                 rb_entry(nm_rb_next_postorder(&pos->field),             \
183                 typeof(*pos), field) : NULL;                            \
184                 pos != NULL;                                            \
185                 pos = n,                                                \
186                 n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
187                 rb_entry(nm_rb_next_postorder(&pos->field),             \
188                 typeof(*pos), field) : NULL)
189
190 int nodemap_idx_nodemap_add(const struct lu_nodemap *nodemap);
191 int nodemap_idx_nodemap_update(const struct lu_nodemap *nodemap);
192 int nodemap_idx_nodemap_del(const struct lu_nodemap *nodemap);
193 int nodemap_idx_idmap_add(const struct lu_nodemap *nodemap,
194                           enum nodemap_id_type id_type,
195                           const __u32 map[2]);
196 int nodemap_idx_idmap_del(const struct lu_nodemap *nodemap,
197                           enum nodemap_id_type id_type,
198                           const __u32 map[2]);
199 int nodemap_idx_range_add(const struct lu_nid_range *range,
200                           const lnet_nid_t nid[2]);
201 int nodemap_idx_range_del(const struct lu_nid_range *range);
202 int nodemap_idx_nodemap_activate(bool value);
203 #endif  /* _NODEMAP_INTERNAL_H */