X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdclass%2Fidmap.c;h=6313ec80f970fcb134aa75dbe32b0ebfbcc80ae8;hb=57649535fee8e92412db6806a30d2fa0752f762f;hp=1cda8501b1e1b21d7ff267406b5b8c8fb0bb9ad4;hpb=0f8dca08a4f68cba82c2c822998ecc309d3b7aaf;p=fs%2Flustre-release.git diff --git a/lustre/obdclass/idmap.c b/lustre/obdclass/idmap.c index 1cda850..6313ec8 100644 --- a/lustre/obdclass/idmap.c +++ b/lustre/obdclass/idmap.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -28,6 +26,8 @@ /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2012, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -40,72 +40,69 @@ * Author: Fan Yong */ -#ifndef EXPORT_SYMTAB -# define EXPORT_SYMTAB -#endif - #define DEBUG_SUBSYSTEM S_SEC #include +#include #include #define lustre_get_group_info(group_info) do { \ - cfs_atomic_inc(&(group_info)->usage); \ + atomic_inc(&(group_info)->usage); \ } while (0) #define lustre_put_group_info(group_info) do { \ - if (cfs_atomic_dec_and_test(&(group_info)->usage)) \ - cfs_groups_free(group_info); \ + if (atomic_dec_and_test(&(group_info)->usage)) \ + groups_free(group_info); \ } while (0) /* * groups_search() is copied from linux kernel! * A simple bsearch. */ -static int lustre_groups_search(cfs_group_info_t *group_info, - gid_t grp) +static int lustre_groups_search(struct group_info *group_info, + gid_t grp) { - int left, right; - - if (!group_info) - return 0; - - left = 0; - right = group_info->ngroups; - while (left < right) { - int mid = (left + right) / 2; - int cmp = grp - CFS_GROUP_AT(group_info, mid); - - if (cmp > 0) - left = mid + 1; - else if (cmp < 0) - right = mid; - else - return 1; - } - return 0; + int left, right; + + if (!group_info) + return 0; + + left = 0; + right = group_info->ngroups; + while (left < right) { + int mid = (left + right) / 2; + int cmp = grp - CFS_GROUP_AT(group_info, mid); + + if (cmp > 0) + left = mid + 1; + else if (cmp < 0) + right = mid; + else + return 1; + } + return 0; } -void lustre_groups_from_list(cfs_group_info_t *ginfo, gid_t *glist) +void lustre_groups_from_list(struct group_info *ginfo, gid_t *glist) { - int i; - int count = ginfo->ngroups; - - /* fill group_info from gid array */ - for (i = 0; i < ginfo->nblocks && count > 0; i++) { - int cp_count = min(CFS_NGROUPS_PER_BLOCK, count); - int off = i * CFS_NGROUPS_PER_BLOCK; - int len = cp_count * sizeof(*glist); - - memcpy(ginfo->blocks[i], glist + off, len); - count -= cp_count; - } + int i; + int count = ginfo->ngroups; + + /* fill group_info from gid array */ + for (i = 0; i < ginfo->nblocks && count > 0; i++) { + int cp_count = min(CFS_NGROUPS_PER_BLOCK, count); + int off = i * CFS_NGROUPS_PER_BLOCK; + int len = cp_count * sizeof(*glist); + + memcpy(ginfo->blocks[i], glist + off, len); + count -= cp_count; + } } EXPORT_SYMBOL(lustre_groups_from_list); /* groups_sort() is copied from linux kernel! */ /* a simple shell-metzner sort */ -void lustre_groups_sort(cfs_group_info_t *group_info) +void lustre_groups_sort(struct group_info *group_info) { int base, max, stride; int gidsetsize = group_info->ngroups; @@ -135,32 +132,32 @@ void lustre_groups_sort(cfs_group_info_t *group_info) } EXPORT_SYMBOL(lustre_groups_sort); -int lustre_in_group_p(struct md_ucred *mu, gid_t grp) +int lustre_in_group_p(struct lu_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; + int rc = 1; + + if (grp != mu->uc_fsgid) { + struct group_info *group_info = NULL; + + if (mu->uc_ginfo || !mu->uc_identity || + mu->uc_valid == UCRED_OLD) + if (grp == mu->uc_suppgids[0] || + grp == mu->uc_suppgids[1]) + return 1; + + if (mu->uc_ginfo) + group_info = mu->uc_ginfo; + else if (mu->uc_identity) + group_info = mu->uc_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); @@ -305,22 +302,22 @@ static __u32 idmap_lookup_gid(cfs_list_t *hash, int reverse, __u32 gid) } int lustre_idmap_add(struct lustre_idmap_table *t, - uid_t ruid, uid_t luid, - gid_t rgid, gid_t lgid) + uid_t ruid, uid_t luid, + gid_t rgid, gid_t lgid) { - struct lustre_idmap_entry *e0, *e1; + struct lustre_idmap_entry *e0, *e1; - LASSERT(t); + LASSERT(t); - cfs_spin_lock(&t->lit_lock); - e0 = idmap_search_entry(t, ruid, luid, rgid, lgid); - cfs_spin_unlock(&t->lit_lock); - if (!e0) { - e0 = idmap_entry_alloc(ruid, luid, rgid, lgid); - if (!e0) - return -ENOMEM; + spin_lock(&t->lit_lock); + e0 = idmap_search_entry(t, ruid, luid, rgid, lgid); + spin_unlock(&t->lit_lock); + if (!e0) { + e0 = idmap_entry_alloc(ruid, luid, rgid, lgid); + if (!e0) + return -ENOMEM; - cfs_spin_lock(&t->lit_lock); + spin_lock(&t->lit_lock); e1 = idmap_search_entry(t, ruid, luid, rgid, lgid); if (e1 == NULL) { cfs_list_add_tail(&e0->lie_rmt_uid_hash, @@ -336,7 +333,7 @@ int lustre_idmap_add(struct lustre_idmap_table *t, &t->lit_idmaps[LCL_GIDMAP_IDX] [lustre_idmap_hashfunc(lgid)]); } - cfs_spin_unlock(&t->lit_lock); + spin_unlock(&t->lit_lock); if (e1 != NULL) { idmap_entry_free(e0); if (IS_ERR(e1)) @@ -354,85 +351,85 @@ int lustre_idmap_del(struct lustre_idmap_table *t, uid_t ruid, uid_t luid, gid_t rgid, gid_t lgid) { - struct lustre_idmap_entry *e; - int rc = 0; + struct lustre_idmap_entry *e; + int rc = 0; - LASSERT(t); + LASSERT(t); - cfs_spin_lock(&t->lit_lock); - e = idmap_search_entry(t, ruid, luid, rgid, lgid); - if (IS_ERR(e)) - rc = PTR_ERR(e); - else if (e) - idmap_entry_free(e); - cfs_spin_unlock(&t->lit_lock); + spin_lock(&t->lit_lock); + e = idmap_search_entry(t, ruid, luid, rgid, lgid); + if (IS_ERR(e)) + rc = PTR_ERR(e); + else if (e) + idmap_entry_free(e); + spin_unlock(&t->lit_lock); - return rc; + return rc; } EXPORT_SYMBOL(lustre_idmap_del); -int lustre_idmap_lookup_uid(struct md_ucred *mu, - struct lustre_idmap_table *t, - int reverse, uid_t uid) +int lustre_idmap_lookup_uid(struct lu_ucred *mu, + struct lustre_idmap_table *t, + int reverse, uid_t uid) { - cfs_list_t *hash; - - if (mu && (mu->mu_valid == UCRED_OLD || mu->mu_valid == UCRED_NEW)) { - if (!reverse) { - if (uid == mu->mu_o_uid) - return mu->mu_uid; - else if (uid == mu->mu_o_fsuid) - return mu->mu_fsuid; - } else { - if (uid == mu->mu_uid) - return mu->mu_o_uid; - else if (uid == mu->mu_fsuid) - return mu->mu_o_fsuid; - } - } + cfs_list_t *hash; + + if (mu && (mu->uc_valid == UCRED_OLD || mu->uc_valid == UCRED_NEW)) { + if (!reverse) { + if (uid == mu->uc_o_uid) + return mu->uc_uid; + else if (uid == mu->uc_o_fsuid) + return mu->uc_fsuid; + } else { + if (uid == mu->uc_uid) + return mu->uc_o_uid; + else if (uid == mu->uc_fsuid) + return mu->uc_o_fsuid; + } + } if (t == NULL) return CFS_IDMAP_NOTFOUND; hash = t->lit_idmaps[reverse ? LCL_UIDMAP_IDX : RMT_UIDMAP_IDX]; - cfs_spin_lock(&t->lit_lock); - uid = idmap_lookup_uid(hash, reverse, uid); - cfs_spin_unlock(&t->lit_lock); + spin_lock(&t->lit_lock); + uid = idmap_lookup_uid(hash, reverse, uid); + spin_unlock(&t->lit_lock); - return uid; + return uid; } EXPORT_SYMBOL(lustre_idmap_lookup_uid); -int lustre_idmap_lookup_gid(struct md_ucred *mu, struct lustre_idmap_table *t, - int reverse, gid_t gid) +int lustre_idmap_lookup_gid(struct lu_ucred *mu, struct lustre_idmap_table *t, + int reverse, gid_t gid) { - cfs_list_t *hash; - - if (mu && (mu->mu_valid == UCRED_OLD || mu->mu_valid == UCRED_NEW)) { - if (!reverse) { - if (gid == mu->mu_o_gid) - return mu->mu_gid; - else if (gid == mu->mu_o_fsgid) - return mu->mu_fsgid; - } else { - if (gid == mu->mu_gid) - return mu->mu_o_gid; - else if (gid == mu->mu_fsgid) - return mu->mu_o_fsgid; - } - } + cfs_list_t *hash; + + if (mu && (mu->uc_valid == UCRED_OLD || mu->uc_valid == UCRED_NEW)) { + if (!reverse) { + if (gid == mu->uc_o_gid) + return mu->uc_gid; + else if (gid == mu->uc_o_fsgid) + return mu->uc_fsgid; + } else { + if (gid == mu->uc_gid) + return mu->uc_o_gid; + else if (gid == mu->uc_fsgid) + return mu->uc_o_fsgid; + } + } if (t == NULL) return CFS_IDMAP_NOTFOUND; hash = t->lit_idmaps[reverse ? LCL_GIDMAP_IDX : RMT_GIDMAP_IDX]; - cfs_spin_lock(&t->lit_lock); - gid = idmap_lookup_gid(hash, reverse, gid); - cfs_spin_unlock(&t->lit_lock); + spin_lock(&t->lit_lock); + gid = idmap_lookup_gid(hash, reverse, gid); + spin_unlock(&t->lit_lock); - return gid; + return gid; } EXPORT_SYMBOL(lustre_idmap_lookup_gid); @@ -445,12 +442,12 @@ struct lustre_idmap_table *lustre_idmap_init(void) if(unlikely(t == NULL)) return (ERR_PTR(-ENOMEM)); - cfs_spin_lock_init(&t->lit_lock); - for (i = 0; i < ARRAY_SIZE(t->lit_idmaps); i++) - for (j = 0; j < ARRAY_SIZE(t->lit_idmaps[i]); j++) - CFS_INIT_LIST_HEAD(&t->lit_idmaps[i][j]); + spin_lock_init(&t->lit_lock); + for (i = 0; i < ARRAY_SIZE(t->lit_idmaps); i++) + for (j = 0; j < ARRAY_SIZE(t->lit_idmaps[i]); j++) + CFS_INIT_LIST_HEAD(&t->lit_idmaps[i][j]); - return t; + return t; } EXPORT_SYMBOL(lustre_idmap_init); @@ -462,16 +459,16 @@ void lustre_idmap_fini(struct lustre_idmap_table *t) LASSERT(t); list = t->lit_idmaps[RMT_UIDMAP_IDX]; - cfs_spin_lock(&t->lit_lock); - for (i = 0; i < CFS_IDMAP_HASHSIZE; i++) - while (!cfs_list_empty(&list[i])) { - e = cfs_list_entry(list[i].next, - struct lustre_idmap_entry, - lie_rmt_uid_hash); - idmap_entry_free(e); - } - cfs_spin_unlock(&t->lit_lock); - - OBD_FREE_PTR(t); + spin_lock(&t->lit_lock); + for (i = 0; i < CFS_IDMAP_HASHSIZE; i++) + while (!cfs_list_empty(&list[i])) { + e = cfs_list_entry(list[i].next, + struct lustre_idmap_entry, + lie_rmt_uid_hash); + idmap_entry_free(e); + } + spin_unlock(&t->lit_lock); + + OBD_FREE_PTR(t); } EXPORT_SYMBOL(lustre_idmap_fini);