Whamcloud - gitweb
LU-5435 lnet: lustre network latency simulation
[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  * Author: Joshua Walgenbach <jjw@iu.edu>
25  */
26
27 #ifndef _NODEMAP_INTERNAL_H
28 #define _NODEMAP_INTERNAL_H
29
30 #include <lustre_nodemap.h>
31 #include <interval_tree.h>
32
33 #define MODULE_STRING "nodemap"
34
35 /* Default nobody uid and gid values */
36
37 #define NODEMAP_NOBODY_UID 99
38 #define NODEMAP_NOBODY_GID 99
39
40 struct lprocfs_static_vars;
41
42 /* nodemap root proc directory under fs/lustre */
43 extern struct proc_dir_entry *proc_lustre_nodemap_root;
44 /* flag if nodemap is active */
45 extern bool nodemap_active;
46 /* lock for range interval tree, used in nodemap_lproc.c */
47 extern rwlock_t nm_range_tree_lock;
48
49 struct lu_nid_range {
50         /* unique id set my mgs */
51         unsigned int             rn_id;
52         /* lu_nodemap containing this range */
53         struct lu_nodemap       *rn_nodemap;
54         /* list for nodemap */
55         struct list_head         rn_list;
56         /* nid interval tree */
57         struct interval_node     rn_node;
58 };
59
60 struct lu_idmap {
61         /* uid/gid of client */
62         __u32           id_client;
63         /* uid/gid on filesystem */
64         __u32           id_fs;
65         /* tree mapping client ids to filesystem ids */
66         struct rb_node  id_client_to_fs;
67         /* tree mappung filesystem to client */
68         struct rb_node  id_fs_to_client;
69 };
70
71 int nodemap_procfs_init(void);
72 int lprocfs_nodemap_register(const char *name, bool is_default_nodemap,
73                              struct lu_nodemap *nodemap);
74 struct lu_nid_range *range_create(lnet_nid_t min, lnet_nid_t max,
75                                   struct lu_nodemap *nodemap);
76 void range_destroy(struct lu_nid_range *range);
77 int range_insert(struct lu_nid_range *data);
78 void range_delete(struct lu_nid_range *data);
79 struct lu_nid_range *range_search(lnet_nid_t nid);
80 struct lu_nid_range *range_find(lnet_nid_t start_nid, lnet_nid_t end_nid);
81 int range_parse_nidstring(char *range_string, lnet_nid_t *start_nid,
82                           lnet_nid_t *end_nid);
83 void range_init_tree(void);
84 struct lu_idmap *idmap_create(__u32 client_id, __u32 fs_id);
85 void idmap_insert(enum nodemap_id_type id_type, struct lu_idmap *idmap,
86                  struct lu_nodemap *nodemap);
87 void idmap_delete(enum nodemap_id_type id_type,  struct lu_idmap *idmap,
88                   struct lu_nodemap *nodemap);
89 void idmap_delete_tree(struct lu_nodemap *nodemap);
90 struct lu_idmap *idmap_search(struct lu_nodemap *nodemap,
91                               enum nodemap_tree_type,
92                               enum nodemap_id_type id_type,
93                               __u32 id);
94 int nodemap_cleanup_nodemaps(void);
95 int nm_member_init_hash(struct lu_nodemap *nodemap);
96 int nm_member_add(struct lu_nodemap *nodemap, struct obd_export *exp);
97 void nm_member_del(struct lu_nodemap *nodemap, struct obd_export *exp);
98 void nm_member_delete_hash(struct lu_nodemap *nodemap);
99 void nm_member_reclassify_nodemap(struct lu_nodemap *nodemap);
100 void nm_member_revoke_locks(struct lu_nodemap *nodemap);
101 void nm_member_revoke_all(void);
102
103 struct rb_node *nm_rb_next_postorder(const struct rb_node *node);
104 struct rb_node *nm_rb_first_postorder(const struct rb_root *root);
105
106 #define nm_rbtree_postorder_for_each_entry_safe(pos, n,                 \
107                                                 root, field)            \
108         for (pos = nm_rb_first_postorder(root) ?                        \
109                 rb_entry(nm_rb_first_postorder(root), typeof(*pos),     \
110                 field) : NULL,                                          \
111                 n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
112                 rb_entry(nm_rb_next_postorder(&pos->field),             \
113                 typeof(*pos), field) : NULL;                            \
114                 pos != NULL;                                            \
115                 pos = n,                                                \
116                 n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
117                 rb_entry(nm_rb_next_postorder(&pos->field),             \
118                 typeof(*pos), field) : NULL)
119 #endif  /* _NODEMAP_INTERNAL_H */