Whamcloud - gitweb
LU-3527 nodemap: idmap management functions
[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 /** The nodemap id 0 will be the default nodemap. It will have a configuration
51  * set by the MGS, but no ranges will be allowed as all NIDs that do not map
52  * will be added to the default nodemap
53  */
54
55 struct lu_nodemap {
56         /* human readable ID */
57         char                    nm_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
58         /* flags to govern nodemap behavior */
59         bool                    nmf_trust_client_ids:1,
60                                 nmf_allow_root_access:1,
61                                 nmf_block_lookups:1,
62                                 nmf_hmac_required:1,
63                                 nmf_encryption_required:1;
64         /* unique ID set by MGS */
65         int                     nm_id;
66         /* nodemap ref counter */
67         atomic_t                nm_refcount;
68         /* UID to squash unmapped UIDs */
69         uid_t                   nm_squash_uid;
70         /* GID to squash unmapped GIDs */
71         gid_t                   nm_squash_gid;
72         /* NID range list */
73         struct list_head        nm_ranges;
74         /* UID map keyed by local UID */
75         struct rb_root          nm_fs_to_client_uidmap;
76         /* UID map keyed by remote UID */
77         struct rb_root          nm_client_to_fs_uidmap;
78         /* GID map keyed by local UID */
79         struct rb_root          nm_fs_to_client_gidmap;
80         /* GID map keyed by remote UID */
81         struct rb_root          nm_client_to_fs_gidmap;
82         /* proc directory entry */
83         struct proc_dir_entry   *nm_proc_entry;
84         /* attached client members of this nodemap */
85         struct list_head        nm_exports;
86         /* access by nodemap name */
87         cfs_hlist_node_t        nm_hash;
88 };
89
90 void nodemap_activate(const bool value);
91 int nodemap_add(const char *nodemap_name);
92 int nodemap_del(const char *nodemap_name);
93 struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid);
94 int nodemap_parse_range(const char *range_string, lnet_nid_t range[2]);
95 int nodemap_parse_idmap(const char *idmap_string, __u32 idmap[2]);
96 int nodemap_add_range(const char *name, const lnet_nid_t nid[2]);
97 int nodemap_del_range(const char *name, const lnet_nid_t nid[2]);
98 int nodemap_set_allow_root(const char *name, bool allow_root);
99 int nodemap_set_trust_client_ids(const char *name, bool trust_client_ids);
100 int nodemap_set_squash_uid(const char *name, uid_t uid);
101 int nodemap_set_squash_gid(const char *name, gid_t gid);
102 int nodemap_add_idmap(const char *name, enum nodemap_id_type id_type,
103                       const __u32 map[2]);
104 int nodemap_del_idmap(const char *name, enum nodemap_id_type id_type,
105                       const __u32 map[2]);
106 __u32 nodemap_map_id(struct lu_nodemap *nodemap,
107                      enum nodemap_id_type id_type,
108                      enum nodemap_tree_type tree_type, __u32 id);
109 #endif  /* _LUSTRE_NODEMAP_H */