Whamcloud - gitweb
LU-5092 nodemap: add structure to hold nodemap config
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
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 #define LUSTRE_NODEMAP_NAME "nodemap"
31 #define LUSTRE_NODEMAP_NAME_LENGTH 16
32
33 #define LUSTRE_NODEMAP_DEFAULT_ID 0
34
35 /** enums containing the types of ids contained in a nodemap
36  * kept so other modules (mgs, mdt, etc) can define the type
37  * of search easily
38  */
39
40 enum nodemap_id_type {
41         NODEMAP_UID,
42         NODEMAP_GID,
43 };
44
45 enum nodemap_tree_type {
46         NODEMAP_FS_TO_CLIENT,
47         NODEMAP_CLIENT_TO_FS,
48 };
49
50 struct nodemap_pde {
51         char                     npe_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
52         struct proc_dir_entry   *npe_proc_entry;
53         struct list_head         npe_list_member;
54 };
55
56 /** The nodemap id 0 will be the default nodemap. It will have a configuration
57  * set by the MGS, but no ranges will be allowed as all NIDs that do not map
58  * will be added to the default nodemap
59  */
60
61 struct lu_nodemap {
62         /* human readable ID */
63         char                     nm_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
64         /* flags to govern nodemap behavior */
65         bool                     nmf_trust_client_ids:1,
66                                  nmf_allow_root_access:1,
67                                  nmf_block_lookups:1,
68                                  nmf_hmac_required:1,
69                                  nmf_encryption_required:1;
70         /* unique ID set by MGS */
71         unsigned int             nm_id;
72         /* nodemap ref counter */
73         atomic_t                 nm_refcount;
74         /* UID to squash unmapped UIDs */
75         uid_t                    nm_squash_uid;
76         /* GID to squash unmapped GIDs */
77         gid_t                    nm_squash_gid;
78         /* NID range list */
79         struct list_head         nm_ranges;
80         /* lock for idmap red/black trees */
81         rwlock_t                 nm_idmap_lock;
82         /* UID map keyed by local UID */
83         struct rb_root           nm_fs_to_client_uidmap;
84         /* UID map keyed by remote UID */
85         struct rb_root           nm_client_to_fs_uidmap;
86         /* GID map keyed by local UID */
87         struct rb_root           nm_fs_to_client_gidmap;
88         /* GID map keyed by remote UID */
89         struct rb_root           nm_client_to_fs_gidmap;
90         /* attached client members of this nodemap */
91         struct mutex             nm_member_list_lock;
92         struct list_head         nm_member_list;
93         /* access by nodemap name */
94         struct hlist_node        nm_hash;
95         struct nodemap_pde      *nm_pde_data;
96
97         /* used when unloading nodemaps */
98         struct list_head         nm_list;
99 };
100
101 void nodemap_activate(const bool value);
102 int nodemap_add(const char *nodemap_name);
103 int nodemap_del(const char *nodemap_name);
104 int nodemap_add_member(lnet_nid_t nid, struct obd_export *exp);
105 void nodemap_del_member(struct obd_export *exp);
106 int nodemap_parse_range(const char *range_string, lnet_nid_t range[2]);
107 int nodemap_parse_idmap(char *idmap_string, __u32 idmap[2]);
108 int nodemap_add_range(const char *name, const lnet_nid_t nid[2]);
109 int nodemap_del_range(const char *name, const lnet_nid_t nid[2]);
110 int nodemap_set_allow_root(const char *name, bool allow_root);
111 int nodemap_set_trust_client_ids(const char *name, bool trust_client_ids);
112 int nodemap_set_squash_uid(const char *name, uid_t uid);
113 int nodemap_set_squash_gid(const char *name, gid_t gid);
114 bool nodemap_can_setquota(const struct lu_nodemap *nodemap);
115 int nodemap_add_idmap(const char *name, enum nodemap_id_type id_type,
116                       const __u32 map[2]);
117 int nodemap_del_idmap(const char *name, enum nodemap_id_type id_type,
118                       const __u32 map[2]);
119 __u32 nodemap_map_id(struct lu_nodemap *nodemap,
120                      enum nodemap_id_type id_type,
121                      enum nodemap_tree_type tree_type, __u32 id);
122 ssize_t nodemap_map_acl(struct lu_nodemap *nodemap, void *buf, size_t size,
123                         enum nodemap_tree_type tree_type);
124 void nodemap_test_nid(lnet_nid_t nid, char *name_buf, size_t name_len);
125 __u32 nodemap_test_id(lnet_nid_t nid, enum nodemap_id_type idtype,
126                       __u32 client_id);
127 #endif  /* _LUSTRE_NODEMAP_H */