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