4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.sun.com/software/products/lustre/docs/GPLv2.pdf
23 * Copyright (C) 2013, Trustees of Indiana University
24 * Author: Joshua Walgenbach <jjw@iu.edu>
27 #ifndef _LUSTRE_NODEMAP_H
28 #define _LUSTRE_NODEMAP_H
30 #include <lustre/lustre_idl.h>
32 #define LUSTRE_NODEMAP_NAME "nodemap"
34 #define LUSTRE_NODEMAP_DEFAULT_ID 0
36 /** enums containing the types of ids contained in a nodemap
37 * kept so other modules (mgs, mdt, etc) can define the type
41 enum nodemap_id_type {
46 enum nodemap_tree_type {
52 char npe_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
53 struct proc_dir_entry *npe_proc_entry;
54 struct list_head npe_list_member;
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
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,
68 nmf_allow_root_access:1;
69 /* unique ID set by MGS */
71 /* nodemap ref counter */
73 /* UID to squash unmapped UIDs */
75 /* GID to squash unmapped GIDs */
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];
98 /* used when loading/unloading nodemaps */
99 struct list_head nm_list;
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
106 struct nm_config_file {
107 struct local_oid_storage *ncf_los;
108 struct dt_object *ncf_obj;
109 struct list_head ncf_list;
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,
129 int nodemap_del_idmap(const char *name, enum nodemap_id_type id_type,
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);
141 #define nodemap_test_nid(nid, name_buf, name_len) do {} while(0)
143 int nodemap_test_id(lnet_nid_t nid, enum nodemap_id_type idtype,
144 __u32 client_id, __u32 *fs_id);
146 enum nm_config_file_type {
150 struct nm_config_file *nm_config_file_register(const struct lu_env *env,
151 struct dt_object *obj,
152 struct local_oid_storage *los,
153 enum nm_config_file_type ncf_type);
154 void nm_config_file_deregister(const struct lu_env *env,
155 struct nm_config_file *ncf,
156 enum nm_config_file_type ncf_type);
157 struct lu_nodemap *nodemap_get_from_exp(struct obd_export *exp);
158 void nodemap_putref(struct lu_nodemap *nodemap);
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;
166 struct nodemap_config {
167 /* Highest numerical lu_nodemap.nm_id defined */
168 unsigned int nmc_nodemap_highest_id;
170 /* Simple flag to determine if nodemaps are active */
171 bool nmc_nodemap_is_active;
173 /* Pointer to default nodemap as it is needed more often */
174 struct lu_nodemap *nmc_default_nodemap;
177 * Lock required to access the range tree.
179 struct rw_semaphore nmc_range_tree_lock;
180 struct nodemap_range_tree nmc_range_tree;
183 * Hash keyed on nodemap name containing all
186 struct cfs_hash *nmc_nodemap_hash;
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);
193 int nodemap_process_idx_pages(struct nodemap_config *config, union lu_page *lip,
194 struct lu_nodemap **recent_nodemap);
195 #else /* disable nodemap processing in MGC of non-servers */
196 static inline int nodemap_process_idx_pages(void *config,
198 struct lu_nodemap **recent_nodemap)
200 #endif /* HAVE_SERVER_SUPPORT */
202 int nodemap_get_config_req(struct obd_device *mgs_obd,
203 struct ptlrpc_request *req);
204 #endif /* _LUSTRE_NODEMAP_H */