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