Whamcloud - gitweb
d8553e912004e9ac8c37bff094cd5abd7f15b75f
[fs/lustre-release.git] / lustre / include / lustre_nodemap.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 _LUSTRE_NODEMAP_H
28 #define _LUSTRE_NODEMAP_H
29
30 #include <lustre/lustre_idl.h>
31
32 #define LUSTRE_NODEMAP_NAME "nodemap"
33
34 #define LUSTRE_NODEMAP_DEFAULT_ID 0
35
36 /** enums containing the types of ids contained in a nodemap
37  * kept so other modules (mgs, mdt, etc) can define the type
38  * of search easily
39  */
40
41 enum nodemap_id_type {
42         NODEMAP_UID,
43         NODEMAP_GID,
44 };
45
46 enum nodemap_tree_type {
47         NODEMAP_FS_TO_CLIENT,
48         NODEMAP_CLIENT_TO_FS,
49 };
50
51 enum nodemap_mapping_modes {
52         NODEMAP_MAP_BOTH,
53         NODEMAP_MAP_UID_ONLY,
54         NODEMAP_MAP_GID_ONLY,
55 };
56
57 struct nodemap_pde {
58         char                     npe_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
59         struct proc_dir_entry   *npe_proc_entry;
60         struct list_head         npe_list_member;
61 };
62
63 /** The nodemap id 0 will be the default nodemap. It will have a configuration
64  * set by the MGS, but no ranges will be allowed as all NIDs that do not map
65  * will be added to the default nodemap
66  */
67
68 struct lu_nodemap {
69         /* human readable ID */
70         char                     nm_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
71         /* flags to govern nodemap behavior */
72         bool                     nmf_trust_client_ids:1,
73                                  nmf_deny_unknown:1,
74                                  nmf_allow_root_access:1,
75                                  nmf_map_uid_only:1,
76                                  nmf_map_gid_only:1;
77         /* unique ID set by MGS */
78         unsigned int             nm_id;
79         /* nodemap ref counter */
80         atomic_t                 nm_refcount;
81         /* UID to squash unmapped UIDs */
82         uid_t                    nm_squash_uid;
83         /* GID to squash unmapped GIDs */
84         gid_t                    nm_squash_gid;
85         /* NID range list */
86         struct list_head         nm_ranges;
87         /* lock for idmap red/black trees */
88         rwlock_t                 nm_idmap_lock;
89         /* UID map keyed by local UID */
90         struct rb_root           nm_fs_to_client_uidmap;
91         /* UID map keyed by remote UID */
92         struct rb_root           nm_client_to_fs_uidmap;
93         /* GID map keyed by local UID */
94         struct rb_root           nm_fs_to_client_gidmap;
95         /* GID map keyed by remote UID */
96         struct rb_root           nm_client_to_fs_gidmap;
97         /* attached client members of this nodemap */
98         struct mutex             nm_member_list_lock;
99         struct list_head         nm_member_list;
100         /* access by nodemap name */
101         struct hlist_node        nm_hash;
102         struct nodemap_pde      *nm_pde_data;
103         /* fileset the nodes of this nodemap are restricted to */
104         char                     nm_fileset[PATH_MAX+1];
105
106         /* used when loading/unloading nodemaps */
107         struct list_head         nm_list;
108 };
109
110 /* Store handles to local MGC storage to save config locally. In future
111  * versions of nodemap, mgc will receive the config directly and so this might
112  * not be needed.
113  */
114 struct nm_config_file {
115         struct local_oid_storage        *ncf_los;
116         struct dt_object                *ncf_obj;
117         struct list_head                 ncf_list;
118 };
119
120 void nodemap_activate(const bool value);
121 int nodemap_add(const char *nodemap_name);
122 int nodemap_del(const char *nodemap_name);
123 int nodemap_add_member(lnet_nid_t nid, struct obd_export *exp);
124 void nodemap_del_member(struct obd_export *exp);
125 int nodemap_parse_range(const char *range_string, lnet_nid_t range[2]);
126 int nodemap_parse_idmap(char *idmap_string, __u32 idmap[2]);
127 int nodemap_add_range(const char *name, const lnet_nid_t nid[2]);
128 int nodemap_del_range(const char *name, const lnet_nid_t nid[2]);
129 int nodemap_set_allow_root(const char *name, bool allow_root);
130 int nodemap_set_trust_client_ids(const char *name, bool trust_client_ids);
131 int nodemap_set_deny_unknown(const char *name, bool deny_unknown);
132 int nodemap_set_mapping_mode(const char *name, enum nodemap_mapping_modes mode);
133 int nodemap_set_squash_uid(const char *name, uid_t uid);
134 int nodemap_set_squash_gid(const char *name, gid_t gid);
135 bool nodemap_can_setquota(const struct lu_nodemap *nodemap);
136 int nodemap_add_idmap(const char *name, enum nodemap_id_type id_type,
137                       const __u32 map[2]);
138 int nodemap_del_idmap(const char *name, enum nodemap_id_type id_type,
139                       const __u32 map[2]);
140 int nodemap_set_fileset(const char *name, const char *fileset);
141 char *nodemap_get_fileset(const struct lu_nodemap *nodemap);
142 __u32 nodemap_map_id(struct lu_nodemap *nodemap,
143                      enum nodemap_id_type id_type,
144                      enum nodemap_tree_type tree_type, __u32 id);
145 ssize_t nodemap_map_acl(struct lu_nodemap *nodemap, void *buf, size_t size,
146                         enum nodemap_tree_type tree_type);
147 #ifdef HAVE_SERVER_SUPPORT
148 void nodemap_test_nid(lnet_nid_t nid, char *name_buf, size_t name_len);
149 #else
150 #define nodemap_test_nid(nid, name_buf, name_len) do {} while(0)
151 #endif
152 int nodemap_test_id(lnet_nid_t nid, enum nodemap_id_type idtype,
153                     __u32 client_id, __u32 *fs_id);
154
155 struct nm_config_file *nm_config_file_register_mgs(const struct lu_env *env,
156                                                    struct dt_object *obj,
157                                                    struct local_oid_storage *los);
158 struct dt_device;
159 struct nm_config_file *nm_config_file_register_tgt(const struct lu_env *env,
160                                                    struct dt_device *dev,
161                                                    struct local_oid_storage *los);
162 void nm_config_file_deregister_mgs(const struct lu_env *env,
163                                    struct nm_config_file *ncf);
164 void nm_config_file_deregister_tgt(const struct lu_env *env,
165                                    struct nm_config_file *ncf);
166 struct lu_nodemap *nodemap_get_from_exp(struct obd_export *exp);
167 void nodemap_putref(struct lu_nodemap *nodemap);
168
169 #ifdef HAVE_SERVER_SUPPORT
170 struct nodemap_range_tree {
171         struct interval_node *nmrt_range_interval_root;
172         unsigned int nmrt_range_highest_id;
173 };
174
175 struct nodemap_config {
176         /* Highest numerical lu_nodemap.nm_id defined */
177         unsigned int nmc_nodemap_highest_id;
178
179         /* Simple flag to determine if nodemaps are active */
180         bool nmc_nodemap_is_active;
181
182         /* Pointer to default nodemap as it is needed more often */
183         struct lu_nodemap *nmc_default_nodemap;
184
185         /**
186          * Lock required to access the range tree.
187          */
188         struct rw_semaphore nmc_range_tree_lock;
189         struct nodemap_range_tree nmc_range_tree;
190
191         /**
192          * Hash keyed on nodemap name containing all
193          * nodemaps
194          */
195         struct cfs_hash *nmc_nodemap_hash;
196 };
197
198 struct nodemap_config *nodemap_config_alloc(void);
199 void nodemap_config_dealloc(struct nodemap_config *config);
200 void nodemap_config_set_active_mgc(struct nodemap_config *config);
201
202 int nodemap_process_idx_pages(struct nodemap_config *config, union lu_page *lip,
203                               struct lu_nodemap **recent_nodemap);
204
205 #else /* disable nodemap processing in MGC of non-servers */
206 static inline int nodemap_process_idx_pages(void *config,
207                                             union lu_page *lip,
208                                             struct lu_nodemap **recent_nodemap)
209 { return 0; }
210 #endif /* HAVE_SERVER_SUPPORT */
211
212 int nodemap_get_config_req(struct obd_device *mgs_obd,
213                            struct ptlrpc_request *req);
214 #endif  /* _LUSTRE_NODEMAP_H */