-enum {
- MDT_IDMAP_NOTFOUND = -1,
-};
-
-struct mdt_idmap_entry {
- struct list_head mie_rmt_hash; /* hashed as mie_rmt_id; */
- struct list_head mie_lcl_hash; /* hashed as mie_lcl_id; */
- int mie_refcount;
- uid_t mie_rmt_id; /* remote uid/gid */
- uid_t mie_lcl_id; /* local uid/gid */
-};
-
-/* uid/gid mapping */
-static struct mdt_idmap_table *mdt_idmap_alloc(void)
-{
- struct mdt_idmap_table *tbl;
- int i, j;
-
- OBD_ALLOC_PTR(tbl);
- if (!tbl)
- return NULL;
-
- spin_lock_init(&tbl->mit_lock);
- for (i = 0; i < ARRAY_SIZE(tbl->mit_idmaps); i++)
- for (j = 0; j < ARRAY_SIZE(tbl->mit_idmaps[i]); j++)
- INIT_LIST_HEAD(&tbl->mit_idmaps[i][j]);
-
- return tbl;
-}
-
-static struct mdt_idmap_entry *idmap_entry_alloc(__u32 mie_rmt_id,
- __u32 mie_lcl_id)
-{
- struct mdt_idmap_entry *e;
-
- OBD_ALLOC_PTR(e);
- if (!e)
- return NULL;
-
- INIT_LIST_HEAD(&e->mie_rmt_hash);
- INIT_LIST_HEAD(&e->mie_lcl_hash);
- e->mie_refcount = 1;
- e->mie_rmt_id = mie_rmt_id;
- e->mie_lcl_id = mie_lcl_id;
-
- return e;
-}
-
-static void idmap_entry_free(struct mdt_idmap_entry *e)
-{
- if (!list_empty(&e->mie_rmt_hash))
- list_del(&e->mie_rmt_hash);
- if (!list_empty(&e->mie_lcl_hash))
- list_del(&e->mie_lcl_hash);
- OBD_FREE_PTR(e);
-}
-
-int mdt_init_idmap(struct mdt_thread_info *info)
-{
- struct ptlrpc_request *req = mdt_info_req(info);
- char *client = libcfs_nid2str(req->rq_peer.nid);
- struct mdt_export_data *med = mdt_req2med(req);
- struct obd_device *obd = req->rq_export->exp_obd;
- struct obd_connect_data *data, *reply;
- int rc = 0, remote;
- ENTRY;
-
- data = req_capsule_client_get(&info->mti_pill, &RMF_CONNECT_DATA);
- reply = req_capsule_server_get(&info->mti_pill, &RMF_CONNECT_DATA);
- if (data == NULL || reply == NULL)
- RETURN(-EFAULT);
-
- if (!req->rq_auth_gss || req->rq_auth_usr_mdt) {
- med->med_rmtclient = 0;
- reply->ocd_connect_flags &= ~OBD_CONNECT_RMT_CLIENT;
- //reply->ocd_connect_flags |= OBD_CONNECT_LCL_CLIENT;
- RETURN(0);
- }
-
- remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT;
-
- if (remote) {
- med->med_rmtclient = 1;
- if (!req->rq_auth_remote)
- CWARN("client (local realm) %s -> target %s asked "
- "to be remote!\n", client, obd->obd_name);
- } else if (req->rq_auth_remote) {
- med->med_rmtclient = 1;
- CWARN("client (remote realm) %s -> target %s forced "
- "to be remote!\n", client, obd->obd_name);
- }
-
- if (med->med_rmtclient) {
- med->med_nllu = data->ocd_nllu;
- med->med_nllg = data->ocd_nllg;
- if (!med->med_idmap)
- med->med_idmap = mdt_idmap_alloc();
- if (!med->med_idmap) {
- CERROR("client %s -> target %s failed to alloc idmap!\n"
- , client, obd->obd_name);
- RETURN(-ENOMEM);
- }
-
- reply->ocd_connect_flags &= ~OBD_CONNECT_LCL_CLIENT;
- //reply->ocd_connect_flags |= OBD_CONNECT_RMT_CLIENT;
- CDEBUG(D_SEC, "client %s -> target %s is remote.\n",
- client, obd->obd_name);
-
- /* NB, MDT_CONNECT establish root idmap too! */
- rc = mdt_handle_idmap(info);
- } else {
- if (req->rq_auth_uid == INVALID_UID) {
- CERROR("client %s -> target %s: user is not "
- "authenticated!\n", client, obd->obd_name);
- RETURN(-EACCES);
- }
- reply->ocd_connect_flags &= ~OBD_CONNECT_RMT_CLIENT;
- //reply->ocd_connect_flags |= OBD_CONNECT_LCL_CLIENT;
- }
-
- RETURN(rc);
-}
-
-static void idmap_clear_mie_rmt_hash(struct list_head *list)