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