Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 294480
b: refs/heads/master
c: 685f50f
h: refs/heads/master
v: v3
  • Loading branch information
Trond Myklebust authored and Trond Myklebust committed Feb 15, 2012
1 parent e706c09 commit ecaed7b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e3da87066f950076fe274b58f0d0adc7d9f9d412
refs/heads/master: 685f50f9188ac1e8244d0340a9d6ea36b6136cec
42 changes: 36 additions & 6 deletions trunk/fs/nfs/idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ struct idmap_hashent {

struct idmap_hashtable {
__u8 h_type;
struct idmap_hashent h_entries[IDMAP_HASH_SZ];
struct idmap_hashent *h_entries;
};

struct idmap {
Expand Down Expand Up @@ -478,21 +478,40 @@ nfs_idmap_new(struct nfs_client *clp)
return 0;
}

static void
idmap_alloc_hashtable(struct idmap_hashtable *h)
{
if (h->h_entries != NULL)
return;
h->h_entries = kcalloc(IDMAP_HASH_SZ,
sizeof(*h->h_entries),
GFP_KERNEL);
}

static void
idmap_free_hashtable(struct idmap_hashtable *h)
{
int i;

if (h->h_entries == NULL)
return;
for (i = 0; i < IDMAP_HASH_SZ; i++)
kfree(h->h_entries[i].ih_name);
kfree(h->h_entries);
}

void
nfs_idmap_delete(struct nfs_client *clp)
{
struct idmap *idmap = clp->cl_idmap;
int i;

if (!idmap)
return;
nfs_idmap_unregister(clp, idmap->idmap_pipe);
rpc_destroy_pipe_data(idmap->idmap_pipe);
clp->cl_idmap = NULL;
for (i = 0; i < ARRAY_SIZE(idmap->idmap_user_hash.h_entries); i++)
kfree(idmap->idmap_user_hash.h_entries[i].ih_name);
for (i = 0; i < ARRAY_SIZE(idmap->idmap_group_hash.h_entries); i++)
kfree(idmap->idmap_group_hash.h_entries[i].ih_name);
idmap_free_hashtable(&idmap->idmap_user_hash);
idmap_free_hashtable(&idmap->idmap_group_hash);
kfree(idmap);
}

Expand Down Expand Up @@ -586,6 +605,8 @@ void nfs_idmap_quit(void)
static inline struct idmap_hashent *
idmap_name_hash(struct idmap_hashtable* h, const char *name, size_t len)
{
if (h->h_entries == NULL)
return NULL;
return &h->h_entries[fnvhash32(name, len) % IDMAP_HASH_SZ];
}

Expand All @@ -594,6 +615,8 @@ idmap_lookup_name(struct idmap_hashtable *h, const char *name, size_t len)
{
struct idmap_hashent *he = idmap_name_hash(h, name, len);

if (he == NULL)
return NULL;
if (he->ih_namelen != len || memcmp(he->ih_name, name, len) != 0)
return NULL;
if (time_after(jiffies, he->ih_expires))
Expand All @@ -604,13 +627,18 @@ idmap_lookup_name(struct idmap_hashtable *h, const char *name, size_t len)
static inline struct idmap_hashent *
idmap_id_hash(struct idmap_hashtable* h, __u32 id)
{
if (h->h_entries == NULL)
return NULL;
return &h->h_entries[fnvhash32(&id, sizeof(id)) % IDMAP_HASH_SZ];
}

static struct idmap_hashent *
idmap_lookup_id(struct idmap_hashtable *h, __u32 id)
{
struct idmap_hashent *he = idmap_id_hash(h, id);

if (he == NULL)
return NULL;
if (he->ih_id != id || he->ih_namelen == 0)
return NULL;
if (time_after(jiffies, he->ih_expires))
Expand All @@ -626,12 +654,14 @@ idmap_lookup_id(struct idmap_hashtable *h, __u32 id)
static inline struct idmap_hashent *
idmap_alloc_name(struct idmap_hashtable *h, char *name, size_t len)
{
idmap_alloc_hashtable(h);
return idmap_name_hash(h, name, len);
}

static inline struct idmap_hashent *
idmap_alloc_id(struct idmap_hashtable *h, __u32 id)
{
idmap_alloc_hashtable(h);
return idmap_id_hash(h, id);
}

Expand Down

0 comments on commit ecaed7b

Please sign in to comment.