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