Whamcloud - gitweb
b=15625
[fs/lustre-release.git] / lustre / include / lustre_idmap.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *   This file is part of Lustre, http://www.lustre.org
5  *
6  * MDS data structures.
7  * See also lustre_idl.h for wire formats of requests.
8  */
9
10 #ifndef _LUSTRE_IDMAP_H
11 #define _LUSTRE_IDMAP_H
12
13 #include <md_object.h>
14
15 #define CFS_NGROUPS_PER_BLOCK   ((int)(CFS_PAGE_SIZE / sizeof(gid_t)))
16
17 #define CFS_GROUP_AT(gi, i) \
18         ((gi)->blocks[(i) / CFS_NGROUPS_PER_BLOCK][(i) % CFS_NGROUPS_PER_BLOCK])
19
20 enum {
21         CFS_IC_NOTHING     = 0,    /* convert nothing */
22         CFS_IC_ALL         = 1,    /* convert all items */
23         CFS_IC_MAPPED      = 2,    /* convert mapped uid/gid */
24         CFS_IC_UNMAPPED    = 3     /* convert unmapped uid/gid */
25 };
26
27 #define  CFS_IDMAP_NOTFOUND     (-1)
28
29 #define CFS_IDMAP_HASHSIZE      32
30
31 enum lustre_idmap_idx {
32         RMT_UIDMAP_IDX,
33         LCL_UIDMAP_IDX,
34         RMT_GIDMAP_IDX,
35         LCL_GIDMAP_IDX,
36         CFS_IDMAP_N_HASHES
37 };
38
39 struct lustre_idmap_table {
40         spinlock_t       lit_lock;
41         struct list_head lit_idmaps[CFS_IDMAP_N_HASHES][CFS_IDMAP_HASHSIZE];
42 };
43
44 extern void lustre_groups_from_list(struct group_info *ginfo, gid_t *glist);
45 extern void lustre_groups_sort(struct group_info *group_info);
46 extern int lustre_in_group_p(struct md_ucred *mu, gid_t grp);
47
48 extern int lustre_idmap_add(struct lustre_idmap_table *t,
49                             uid_t ruid, uid_t luid,
50                             gid_t rgid, gid_t lgid);
51 extern int lustre_idmap_del(struct lustre_idmap_table *t,
52                             uid_t ruid, uid_t luid,
53                             gid_t rgid, gid_t lgid);
54 extern int lustre_idmap_lookup_uid(struct md_ucred *mu,
55                                    struct lustre_idmap_table *t,
56                                    int reverse, uid_t uid);
57 extern int lustre_idmap_lookup_gid(struct md_ucred *mu,
58                                    struct lustre_idmap_table *t,
59                                    int reverse, gid_t gid);
60 extern struct lustre_idmap_table *lustre_idmap_init(void);
61 extern void lustre_idmap_fini(struct lustre_idmap_table *t);
62
63 #endif