-int lustre_in_group_p(struct md_ucred *mu, gid_t grp)
-{
- int rc = 1;
-
- if (grp != mu->mu_fsgid) {
- cfs_group_info_t *group_info = NULL;
-
- if (mu->mu_ginfo || !mu->mu_identity ||
- mu->mu_valid == UCRED_OLD)
- if (grp == mu->mu_suppgids[0] ||
- grp == mu->mu_suppgids[1])
- return 1;
-
- if (mu->mu_ginfo)
- group_info = mu->mu_ginfo;
- else if (mu->mu_identity)
- group_info = mu->mu_identity->mi_ginfo;
-
- if (!group_info)
- return 0;
-
- lustre_get_group_info(group_info);
- rc = lustre_groups_search(group_info, grp);
- lustre_put_group_info(group_info);
- }
- return rc;
-}
-EXPORT_SYMBOL(lustre_in_group_p);
-
-struct lustre_idmap_entry {
- cfs_list_t lie_rmt_uid_hash; /* hashed as lie_rmt_uid; */
- cfs_list_t lie_lcl_uid_hash; /* hashed as lie_lcl_uid; */
- cfs_list_t lie_rmt_gid_hash; /* hashed as lie_rmt_gid; */
- cfs_list_t lie_lcl_gid_hash; /* hashed as lie_lcl_gid; */
- uid_t lie_rmt_uid; /* remote uid */
- uid_t lie_lcl_uid; /* local uid */
- gid_t lie_rmt_gid; /* remote gid */
- gid_t lie_lcl_gid; /* local gid */
-};
-
-static inline __u32 lustre_idmap_hashfunc(__u32 id)
-{
- return id & (CFS_IDMAP_HASHSIZE - 1);
-}
-
-static
-struct lustre_idmap_entry *idmap_entry_alloc(uid_t rmt_uid, uid_t lcl_uid,
- gid_t rmt_gid, gid_t lcl_gid)
-{
- struct lustre_idmap_entry *e;
-
- OBD_ALLOC_PTR(e);
- if (e == NULL)
- return NULL;
-
- CFS_INIT_LIST_HEAD(&e->lie_rmt_uid_hash);
- CFS_INIT_LIST_HEAD(&e->lie_lcl_uid_hash);
- CFS_INIT_LIST_HEAD(&e->lie_rmt_gid_hash);
- CFS_INIT_LIST_HEAD(&e->lie_lcl_gid_hash);
- e->lie_rmt_uid = rmt_uid;
- e->lie_lcl_uid = lcl_uid;
- e->lie_rmt_gid = rmt_gid;
- e->lie_lcl_gid = lcl_gid;
-
- return e;
-}
-
-static void idmap_entry_free(struct lustre_idmap_entry *e)
-{
- if (!cfs_list_empty(&e->lie_rmt_uid_hash))
- cfs_list_del(&e->lie_rmt_uid_hash);
- if (!cfs_list_empty(&e->lie_lcl_uid_hash))
- cfs_list_del(&e->lie_lcl_uid_hash);
- if (!cfs_list_empty(&e->lie_rmt_gid_hash))
- cfs_list_del(&e->lie_rmt_gid_hash);
- if (!cfs_list_empty(&e->lie_lcl_gid_hash))
- cfs_list_del(&e->lie_lcl_gid_hash);
- OBD_FREE_PTR(e);
-}
-
-/*
- * return value
- * NULL: not found entry
- * ERR_PTR(-EACCES): found 1(remote):N(local) mapped entry
- * others: found normal entry
- */
-static
-struct lustre_idmap_entry *idmap_search_entry(struct lustre_idmap_table *t,
- uid_t rmt_uid, uid_t lcl_uid,
- gid_t rmt_gid, gid_t lcl_gid)
-{
- cfs_list_t *head;
- struct lustre_idmap_entry *e;
-
- head = &t->lit_idmaps[RMT_UIDMAP_IDX][lustre_idmap_hashfunc(rmt_uid)];
- cfs_list_for_each_entry(e, head, lie_rmt_uid_hash)
- if (e->lie_rmt_uid == rmt_uid) {
- if (e->lie_lcl_uid == lcl_uid) {
- if (e->lie_rmt_gid == rmt_gid &&
- e->lie_lcl_gid == lcl_gid)
- /* must be quaternion match */
- return e;
- } else {
- /* 1:N uid mapping */
- CERROR("rmt uid %u already be mapped to %u"
- " (new %u)\n", e->lie_rmt_uid,
- e->lie_lcl_uid, lcl_uid);
- return ERR_PTR(-EACCES);
- }
- }
-
- head = &t->lit_idmaps[RMT_GIDMAP_IDX][lustre_idmap_hashfunc(rmt_gid)];
- cfs_list_for_each_entry(e, head, lie_rmt_gid_hash)
- if (e->lie_rmt_gid == rmt_gid) {
- if (e->lie_lcl_gid == lcl_gid) {
- if (unlikely(e->lie_rmt_uid == rmt_uid &&
- e->lie_lcl_uid == lcl_uid))
- /* after uid mapping search above,
- * we should never come here */
- LBUG();
- } else {
- /* 1:N gid mapping */
- CERROR("rmt gid %u already be mapped to %u"
- " (new %u)\n", e->lie_rmt_gid,
- e->lie_lcl_gid, lcl_gid);
- return ERR_PTR(-EACCES);
- }
- }
-
- return NULL;
-}
-
-static __u32 idmap_lookup_uid(cfs_list_t *hash, int reverse,
- __u32 uid)
-{
- cfs_list_t *head = &hash[lustre_idmap_hashfunc(uid)];
- struct lustre_idmap_entry *e;
-
- if (!reverse) {
- cfs_list_for_each_entry(e, head, lie_rmt_uid_hash)
- if (e->lie_rmt_uid == uid)
- return e->lie_lcl_uid;
- } else {
- cfs_list_for_each_entry(e, head, lie_lcl_uid_hash)
- if (e->lie_lcl_uid == uid)
- return e->lie_rmt_uid;
- }
-
- return CFS_IDMAP_NOTFOUND;
-}
-
-static __u32 idmap_lookup_gid(cfs_list_t *hash, int reverse, __u32 gid)