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