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>
31 #include <lustre/lustre_user.h>
33 #define LUSTRE_NODEMAP_NAME "nodemap"
35 #define LUSTRE_NODEMAP_DEFAULT_ID 0
37 /** enums containing the types of ids contained in a nodemap
38 * kept so other modules (mgs, mdt, etc) can define the type
42 enum nodemap_id_type {
47 enum nodemap_tree_type {
53 char npe_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
54 struct proc_dir_entry *npe_proc_entry;
55 struct list_head npe_list_member;
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
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_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 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,
143 struct nm_config_file *nm_config_file_register(const struct lu_env *env,
144 struct dt_object *obj);
145 void nm_config_file_deregister(const struct lu_env *env,
146 struct nm_config_file *ncf);
147 struct lu_nodemap *nodemap_get_from_exp(struct obd_export *exp);
148 void nodemap_putref(struct lu_nodemap *nodemap);
150 #ifdef HAVE_SERVER_SUPPORT
151 struct nodemap_range_tree {
152 struct interval_node *nmrt_range_interval_root;
153 unsigned int nmrt_range_highest_id;
156 struct nodemap_config {
157 /* Highest numerical lu_nodemap.nm_id defined */
158 unsigned int nmc_nodemap_highest_id;
160 /* Simple flag to determine if nodemaps are active */
161 bool nmc_nodemap_is_active;
163 /* Pointer to default nodemap as it is needed more often */
164 struct lu_nodemap *nmc_default_nodemap;
167 * Lock required to access the range tree.
169 struct rw_semaphore nmc_range_tree_lock;
170 struct nodemap_range_tree nmc_range_tree;
173 * Hash keyed on nodemap name containing all
176 struct cfs_hash *nmc_nodemap_hash;
179 struct nodemap_config *nodemap_config_alloc(void);
180 void nodemap_config_dealloc(struct nodemap_config *config);
181 void nodemap_config_set_active(struct nodemap_config *config);
183 int nodemap_process_idx_pages(struct nodemap_config *config, union lu_page *lip,
184 struct lu_nodemap **recent_nodemap);
185 #else /* disable nodemap processing in MGC of non-servers */
186 static inline int nodemap_process_idx_pages(void *config,
188 struct lu_nodemap **recent_nodemap)
190 #endif /* HAVE_SERVER_SUPPORT */
192 int nodemap_get_config_req(struct obd_device *mgs_obd,
193 struct ptlrpc_request *req);
194 #endif /* _LUSTRE_NODEMAP_H */