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,
67 nmf_allow_root_access:1;
68 /* unique ID set by MGS */
70 /* nodemap ref counter */
72 /* UID to squash unmapped UIDs */
74 /* GID to squash unmapped GIDs */
77 struct list_head nm_ranges;
78 /* lock for idmap red/black trees */
79 rwlock_t nm_idmap_lock;
80 /* UID map keyed by local UID */
81 struct rb_root nm_fs_to_client_uidmap;
82 /* UID map keyed by remote UID */
83 struct rb_root nm_client_to_fs_uidmap;
84 /* GID map keyed by local UID */
85 struct rb_root nm_fs_to_client_gidmap;
86 /* GID map keyed by remote UID */
87 struct rb_root nm_client_to_fs_gidmap;
88 /* attached client members of this nodemap */
89 struct mutex nm_member_list_lock;
90 struct list_head nm_member_list;
91 /* access by nodemap name */
92 struct hlist_node nm_hash;
93 struct nodemap_pde *nm_pde_data;
94 /* fileset the nodes of this nodemap are restricted to */
95 char nm_fileset[PATH_MAX+1];
97 /* used when loading/unloading nodemaps */
98 struct list_head nm_list;
101 /* Store handles to local MGC storage to save config locally. In future
102 * versions of nodemap, mgc will receive the config directly and so this might
105 struct nm_config_file {
106 struct local_oid_storage *ncf_los;
107 struct dt_object *ncf_obj;
108 struct list_head ncf_list;
111 void nodemap_activate(const bool value);
112 int nodemap_add(const char *nodemap_name);
113 int nodemap_del(const char *nodemap_name);
114 int nodemap_add_member(lnet_nid_t nid, struct obd_export *exp);
115 void nodemap_del_member(struct obd_export *exp);
116 int nodemap_parse_range(const char *range_string, lnet_nid_t range[2]);
117 int nodemap_parse_idmap(char *idmap_string, __u32 idmap[2]);
118 int nodemap_add_range(const char *name, const lnet_nid_t nid[2]);
119 int nodemap_del_range(const char *name, const lnet_nid_t nid[2]);
120 int nodemap_set_allow_root(const char *name, bool allow_root);
121 int nodemap_set_trust_client_ids(const char *name, bool trust_client_ids);
122 int nodemap_set_squash_uid(const char *name, uid_t uid);
123 int nodemap_set_squash_gid(const char *name, gid_t gid);
124 bool nodemap_can_setquota(const struct lu_nodemap *nodemap);
125 int nodemap_add_idmap(const char *name, enum nodemap_id_type id_type,
127 int nodemap_del_idmap(const char *name, enum nodemap_id_type id_type,
129 int nodemap_set_fileset(const char *name, const char *fileset);
130 char *nodemap_get_fileset(const struct lu_nodemap *nodemap);
131 __u32 nodemap_map_id(struct lu_nodemap *nodemap,
132 enum nodemap_id_type id_type,
133 enum nodemap_tree_type tree_type, __u32 id);
134 ssize_t nodemap_map_acl(struct lu_nodemap *nodemap, void *buf, size_t size,
135 enum nodemap_tree_type tree_type);
136 #ifdef HAVE_SERVER_SUPPORT
137 void nodemap_test_nid(lnet_nid_t nid, char *name_buf, size_t name_len);
139 #define nodemap_test_nid(nid, name_buf, name_len) do {} while(0)
141 __u32 nodemap_test_id(lnet_nid_t nid, enum nodemap_id_type idtype,
144 enum nm_config_file_type {
148 struct nm_config_file *nm_config_file_register(const struct lu_env *env,
149 struct dt_object *obj,
150 struct local_oid_storage *los,
151 enum nm_config_file_type ncf_type);
152 void nm_config_file_deregister(const struct lu_env *env,
153 struct nm_config_file *ncf,
154 enum nm_config_file_type ncf_type);
155 struct lu_nodemap *nodemap_get_from_exp(struct obd_export *exp);
156 void nodemap_putref(struct lu_nodemap *nodemap);
158 #ifdef HAVE_SERVER_SUPPORT
159 struct nodemap_range_tree {
160 struct interval_node *nmrt_range_interval_root;
161 unsigned int nmrt_range_highest_id;
164 struct nodemap_config {
165 /* Highest numerical lu_nodemap.nm_id defined */
166 unsigned int nmc_nodemap_highest_id;
168 /* Simple flag to determine if nodemaps are active */
169 bool nmc_nodemap_is_active;
171 /* Pointer to default nodemap as it is needed more often */
172 struct lu_nodemap *nmc_default_nodemap;
175 * Lock required to access the range tree.
177 struct rw_semaphore nmc_range_tree_lock;
178 struct nodemap_range_tree nmc_range_tree;
181 * Hash keyed on nodemap name containing all
184 struct cfs_hash *nmc_nodemap_hash;
187 struct nodemap_config *nodemap_config_alloc(void);
188 void nodemap_config_dealloc(struct nodemap_config *config);
189 void nodemap_config_set_active_mgc(struct nodemap_config *config);
191 int nodemap_process_idx_pages(struct nodemap_config *config, union lu_page *lip,
192 struct lu_nodemap **recent_nodemap);
193 #else /* disable nodemap processing in MGC of non-servers */
194 static inline int nodemap_process_idx_pages(void *config,
196 struct lu_nodemap **recent_nodemap)
198 #endif /* HAVE_SERVER_SUPPORT */
200 int nodemap_get_config_req(struct obd_device *mgs_obd,
201 struct ptlrpc_request *req);
202 #endif /* _LUSTRE_NODEMAP_H */