4 * UID and GID to name mapping for clients.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Marius Aamodt Eriksen <marius@umich.edu>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <linux/types.h>
37 #include <linux/string.h>
38 #include <linux/kernel.h>
39 #include <linux/slab.h>
40 #include <linux/nfs_idmap.h>
41 #include <linux/nfs_fs.h>
44 * nfs_fattr_init_names - initialise the nfs_fattr owner_name/group_name fields
45 * @fattr: fully initialised struct nfs_fattr
46 * @owner_name: owner name string cache
47 * @group_name: group name string cache
49 void nfs_fattr_init_names(struct nfs_fattr
*fattr
,
50 struct nfs4_string
*owner_name
,
51 struct nfs4_string
*group_name
)
53 fattr
->owner_name
= owner_name
;
54 fattr
->group_name
= group_name
;
57 static void nfs_fattr_free_owner_name(struct nfs_fattr
*fattr
)
59 fattr
->valid
&= ~NFS_ATTR_FATTR_OWNER_NAME
;
60 kfree(fattr
->owner_name
->data
);
63 static void nfs_fattr_free_group_name(struct nfs_fattr
*fattr
)
65 fattr
->valid
&= ~NFS_ATTR_FATTR_GROUP_NAME
;
66 kfree(fattr
->group_name
->data
);
69 static bool nfs_fattr_map_owner_name(struct nfs_server
*server
, struct nfs_fattr
*fattr
)
71 struct nfs4_string
*owner
= fattr
->owner_name
;
74 if (!(fattr
->valid
& NFS_ATTR_FATTR_OWNER_NAME
))
76 if (nfs_map_name_to_uid(server
, owner
->data
, owner
->len
, &uid
) == 0) {
78 fattr
->valid
|= NFS_ATTR_FATTR_OWNER
;
83 static bool nfs_fattr_map_group_name(struct nfs_server
*server
, struct nfs_fattr
*fattr
)
85 struct nfs4_string
*group
= fattr
->group_name
;
88 if (!(fattr
->valid
& NFS_ATTR_FATTR_GROUP_NAME
))
90 if (nfs_map_group_to_gid(server
, group
->data
, group
->len
, &gid
) == 0) {
92 fattr
->valid
|= NFS_ATTR_FATTR_GROUP
;
98 * nfs_fattr_free_names - free up the NFSv4 owner and group strings
99 * @fattr: a fully initialised nfs_fattr structure
101 void nfs_fattr_free_names(struct nfs_fattr
*fattr
)
103 if (fattr
->valid
& NFS_ATTR_FATTR_OWNER_NAME
)
104 nfs_fattr_free_owner_name(fattr
);
105 if (fattr
->valid
& NFS_ATTR_FATTR_GROUP_NAME
)
106 nfs_fattr_free_group_name(fattr
);
110 * nfs_fattr_map_and_free_names - map owner/group strings into uid/gid and free
111 * @server: pointer to the filesystem nfs_server structure
112 * @fattr: a fully initialised nfs_fattr structure
114 * This helper maps the cached NFSv4 owner/group strings in fattr into
115 * their numeric uid/gid equivalents, and then frees the cached strings.
117 void nfs_fattr_map_and_free_names(struct nfs_server
*server
, struct nfs_fattr
*fattr
)
119 if (nfs_fattr_map_owner_name(server
, fattr
))
120 nfs_fattr_free_owner_name(fattr
);
121 if (nfs_fattr_map_group_name(server
, fattr
))
122 nfs_fattr_free_group_name(fattr
);
125 static int nfs_map_string_to_numeric(const char *name
, size_t namelen
, __u32
*res
)
130 if (memchr(name
, '@', namelen
) != NULL
|| namelen
>= sizeof(buf
))
132 memcpy(buf
, name
, namelen
);
134 if (strict_strtoul(buf
, 0, &val
) != 0)
140 static int nfs_map_numeric_to_string(__u32 id
, char *buf
, size_t buflen
)
142 return snprintf(buf
, buflen
, "%u", id
);
145 #ifdef CONFIG_NFS_USE_NEW_IDMAPPER
147 #include <linux/cred.h>
148 #include <linux/sunrpc/sched.h>
149 #include <linux/nfs4.h>
150 #include <linux/nfs_fs_sb.h>
151 #include <linux/keyctl.h>
152 #include <linux/key-type.h>
153 #include <linux/rcupdate.h>
154 #include <linux/err.h>
156 #include <keys/user-type.h>
158 #define NFS_UINT_MAXLEN 11
160 const struct cred
*id_resolver_cache
;
162 struct key_type key_type_id_resolver
= {
163 .name
= "id_resolver",
164 .instantiate
= user_instantiate
,
166 .revoke
= user_revoke
,
167 .destroy
= user_destroy
,
168 .describe
= user_describe
,
172 int nfs_idmap_init(void)
178 printk(KERN_NOTICE
"Registering the %s key type\n", key_type_id_resolver
.name
);
180 cred
= prepare_kernel_cred(NULL
);
184 keyring
= key_alloc(&key_type_keyring
, ".id_resolver", 0, 0, cred
,
185 (KEY_POS_ALL
& ~KEY_POS_SETATTR
) |
186 KEY_USR_VIEW
| KEY_USR_READ
,
187 KEY_ALLOC_NOT_IN_QUOTA
);
188 if (IS_ERR(keyring
)) {
189 ret
= PTR_ERR(keyring
);
190 goto failed_put_cred
;
193 ret
= key_instantiate_and_link(keyring
, NULL
, 0, NULL
, NULL
);
197 ret
= register_key_type(&key_type_id_resolver
);
201 cred
->thread_keyring
= keyring
;
202 cred
->jit_keyring
= KEY_REQKEY_DEFL_THREAD_KEYRING
;
203 id_resolver_cache
= cred
;
213 void nfs_idmap_quit(void)
215 key_revoke(id_resolver_cache
->thread_keyring
);
216 unregister_key_type(&key_type_id_resolver
);
217 put_cred(id_resolver_cache
);
221 * Assemble the description to pass to request_key()
222 * This function will allocate a new string and update dest to point
223 * at it. The caller is responsible for freeing dest.
225 * On error 0 is returned. Otherwise, the length of dest is returned.
227 static ssize_t
nfs_idmap_get_desc(const char *name
, size_t namelen
,
228 const char *type
, size_t typelen
, char **desc
)
231 size_t desclen
= typelen
+ namelen
+ 2;
233 *desc
= kmalloc(desclen
, GFP_KERNEL
);
238 memcpy(cp
, type
, typelen
);
242 memcpy(cp
, name
, namelen
);
248 static ssize_t
nfs_idmap_request_key(const char *name
, size_t namelen
,
249 const char *type
, void *data
, size_t data_size
)
251 const struct cred
*saved_cred
;
254 struct user_key_payload
*payload
;
257 ret
= nfs_idmap_get_desc(name
, namelen
, type
, strlen(type
), &desc
);
261 saved_cred
= override_creds(id_resolver_cache
);
262 rkey
= request_key(&key_type_id_resolver
, desc
, "");
263 revert_creds(saved_cred
);
271 rkey
->perm
|= KEY_USR_VIEW
;
273 ret
= key_validate(rkey
);
277 payload
= rcu_dereference(rkey
->payload
.data
);
278 if (IS_ERR_OR_NULL(payload
)) {
279 ret
= PTR_ERR(payload
);
283 ret
= payload
->datalen
;
284 if (ret
> 0 && ret
<= data_size
)
285 memcpy(data
, payload
->data
, ret
);
298 static ssize_t
nfs_idmap_lookup_name(__u32 id
, const char *type
, char *buf
, size_t buflen
)
300 char id_str
[NFS_UINT_MAXLEN
];
304 id_len
= snprintf(id_str
, sizeof(id_str
), "%u", id
);
305 ret
= nfs_idmap_request_key(id_str
, id_len
, type
, buf
, buflen
);
312 static int nfs_idmap_lookup_id(const char *name
, size_t namelen
,
313 const char *type
, __u32
*id
)
315 char id_str
[NFS_UINT_MAXLEN
];
320 data_size
= nfs_idmap_request_key(name
, namelen
, type
, id_str
, NFS_UINT_MAXLEN
);
321 if (data_size
<= 0) {
324 ret
= strict_strtol(id_str
, 10, &id_long
);
325 *id
= (__u32
)id_long
;
330 int nfs_map_name_to_uid(const struct nfs_server
*server
, const char *name
, size_t namelen
, __u32
*uid
)
332 if (nfs_map_string_to_numeric(name
, namelen
, uid
))
334 return nfs_idmap_lookup_id(name
, namelen
, "uid", uid
);
337 int nfs_map_group_to_gid(const struct nfs_server
*server
, const char *name
, size_t namelen
, __u32
*gid
)
339 if (nfs_map_string_to_numeric(name
, namelen
, gid
))
341 return nfs_idmap_lookup_id(name
, namelen
, "gid", gid
);
344 int nfs_map_uid_to_name(const struct nfs_server
*server
, __u32 uid
, char *buf
, size_t buflen
)
348 if (!(server
->caps
& NFS_CAP_UIDGID_NOMAP
))
349 ret
= nfs_idmap_lookup_name(uid
, "user", buf
, buflen
);
351 ret
= nfs_map_numeric_to_string(uid
, buf
, buflen
);
354 int nfs_map_gid_to_group(const struct nfs_server
*server
, __u32 gid
, char *buf
, size_t buflen
)
358 if (!(server
->caps
& NFS_CAP_UIDGID_NOMAP
))
359 ret
= nfs_idmap_lookup_name(gid
, "group", buf
, buflen
);
361 ret
= nfs_map_numeric_to_string(gid
, buf
, buflen
);
365 #else /* CONFIG_NFS_USE_NEW_IDMAPPER not defined */
367 #include <linux/module.h>
368 #include <linux/mutex.h>
369 #include <linux/init.h>
370 #include <linux/socket.h>
371 #include <linux/in.h>
372 #include <linux/sched.h>
373 #include <linux/sunrpc/clnt.h>
374 #include <linux/workqueue.h>
375 #include <linux/sunrpc/rpc_pipe_fs.h>
377 #include <linux/nfs_fs.h>
381 #define IDMAP_HASH_SZ 128
383 /* Default cache timeout is 10 minutes */
384 unsigned int nfs_idmap_cache_timeout
= 600 * HZ
;
386 static int param_set_idmap_timeout(const char *val
, struct kernel_param
*kp
)
389 int num
= simple_strtol(val
, &endp
, 0);
391 if (endp
== val
|| *endp
|| num
< 0 || jif
< num
)
393 *((int *)kp
->arg
) = jif
;
397 module_param_call(idmap_cache_timeout
, param_set_idmap_timeout
, param_get_int
,
398 &nfs_idmap_cache_timeout
, 0644);
400 struct idmap_hashent
{
401 unsigned long ih_expires
;
404 char ih_name
[IDMAP_NAMESZ
];
407 struct idmap_hashtable
{
409 struct idmap_hashent h_entries
[IDMAP_HASH_SZ
];
413 struct rpc_pipe
*idmap_pipe
;
414 wait_queue_head_t idmap_wq
;
415 struct idmap_msg idmap_im
;
416 struct mutex idmap_lock
; /* Serializes upcalls */
417 struct mutex idmap_im_lock
; /* Protects the hashtable */
418 struct idmap_hashtable idmap_user_hash
;
419 struct idmap_hashtable idmap_group_hash
;
422 static ssize_t
idmap_pipe_downcall(struct file
*, const char __user
*,
424 static void idmap_pipe_destroy_msg(struct rpc_pipe_msg
*);
426 static unsigned int fnvhash32(const void *, size_t);
428 static const struct rpc_pipe_ops idmap_upcall_ops
= {
429 .upcall
= rpc_pipe_generic_upcall
,
430 .downcall
= idmap_pipe_downcall
,
431 .destroy_msg
= idmap_pipe_destroy_msg
,
434 static void __nfs_idmap_unregister(struct rpc_pipe
*pipe
)
437 rpc_unlink(pipe
->dentry
);
440 static int __nfs_idmap_register(struct dentry
*dir
,
442 struct rpc_pipe
*pipe
)
444 struct dentry
*dentry
;
446 dentry
= rpc_mkpipe_dentry(dir
, "idmap", idmap
, pipe
);
448 return PTR_ERR(dentry
);
449 pipe
->dentry
= dentry
;
453 static void nfs_idmap_unregister(struct nfs_client
*clp
,
454 struct rpc_pipe
*pipe
)
456 struct net
*net
= clp
->net
;
457 struct super_block
*pipefs_sb
;
459 pipefs_sb
= rpc_get_sb_net(net
);
461 __nfs_idmap_unregister(pipe
);
466 static int nfs_idmap_register(struct nfs_client
*clp
,
468 struct rpc_pipe
*pipe
)
470 struct net
*net
= clp
->net
;
471 struct super_block
*pipefs_sb
;
474 pipefs_sb
= rpc_get_sb_net(net
);
476 if (clp
->cl_rpcclient
->cl_dentry
)
477 err
= __nfs_idmap_register(clp
->cl_rpcclient
->cl_dentry
,
485 nfs_idmap_new(struct nfs_client
*clp
)
488 struct rpc_pipe
*pipe
;
491 BUG_ON(clp
->cl_idmap
!= NULL
);
493 idmap
= kzalloc(sizeof(*idmap
), GFP_KERNEL
);
497 pipe
= rpc_mkpipe_data(&idmap_upcall_ops
, 0);
499 error
= PTR_ERR(pipe
);
503 error
= nfs_idmap_register(clp
, idmap
, pipe
);
505 rpc_destroy_pipe_data(pipe
);
509 idmap
->idmap_pipe
= pipe
;
510 mutex_init(&idmap
->idmap_lock
);
511 mutex_init(&idmap
->idmap_im_lock
);
512 init_waitqueue_head(&idmap
->idmap_wq
);
513 idmap
->idmap_user_hash
.h_type
= IDMAP_TYPE_USER
;
514 idmap
->idmap_group_hash
.h_type
= IDMAP_TYPE_GROUP
;
516 clp
->cl_idmap
= idmap
;
521 nfs_idmap_delete(struct nfs_client
*clp
)
523 struct idmap
*idmap
= clp
->cl_idmap
;
527 nfs_idmap_unregister(clp
, idmap
->idmap_pipe
);
528 rpc_destroy_pipe_data(idmap
->idmap_pipe
);
529 clp
->cl_idmap
= NULL
;
534 * Helper routines for manipulating the hashtable
536 static inline struct idmap_hashent
*
537 idmap_name_hash(struct idmap_hashtable
* h
, const char *name
, size_t len
)
539 return &h
->h_entries
[fnvhash32(name
, len
) % IDMAP_HASH_SZ
];
542 static struct idmap_hashent
*
543 idmap_lookup_name(struct idmap_hashtable
*h
, const char *name
, size_t len
)
545 struct idmap_hashent
*he
= idmap_name_hash(h
, name
, len
);
547 if (he
->ih_namelen
!= len
|| memcmp(he
->ih_name
, name
, len
) != 0)
549 if (time_after(jiffies
, he
->ih_expires
))
554 static inline struct idmap_hashent
*
555 idmap_id_hash(struct idmap_hashtable
* h
, __u32 id
)
557 return &h
->h_entries
[fnvhash32(&id
, sizeof(id
)) % IDMAP_HASH_SZ
];
560 static struct idmap_hashent
*
561 idmap_lookup_id(struct idmap_hashtable
*h
, __u32 id
)
563 struct idmap_hashent
*he
= idmap_id_hash(h
, id
);
564 if (he
->ih_id
!= id
|| he
->ih_namelen
== 0)
566 if (time_after(jiffies
, he
->ih_expires
))
572 * Routines for allocating new entries in the hashtable.
573 * For now, we just have 1 entry per bucket, so it's all
576 static inline struct idmap_hashent
*
577 idmap_alloc_name(struct idmap_hashtable
*h
, char *name
, size_t len
)
579 return idmap_name_hash(h
, name
, len
);
582 static inline struct idmap_hashent
*
583 idmap_alloc_id(struct idmap_hashtable
*h
, __u32 id
)
585 return idmap_id_hash(h
, id
);
589 idmap_update_entry(struct idmap_hashent
*he
, const char *name
,
590 size_t namelen
, __u32 id
)
593 memcpy(he
->ih_name
, name
, namelen
);
594 he
->ih_name
[namelen
] = '\0';
595 he
->ih_namelen
= namelen
;
596 he
->ih_expires
= jiffies
+ nfs_idmap_cache_timeout
;
603 nfs_idmap_id(struct idmap
*idmap
, struct idmap_hashtable
*h
,
604 const char *name
, size_t namelen
, __u32
*id
)
606 struct rpc_pipe_msg msg
;
607 struct idmap_msg
*im
;
608 struct idmap_hashent
*he
;
609 DECLARE_WAITQUEUE(wq
, current
);
612 im
= &idmap
->idmap_im
;
615 * String sanity checks
616 * Note that the userland daemon expects NUL terminated strings
621 if (name
[namelen
-1] != '\0')
625 if (namelen
>= IDMAP_NAMESZ
)
628 mutex_lock(&idmap
->idmap_lock
);
629 mutex_lock(&idmap
->idmap_im_lock
);
631 he
= idmap_lookup_name(h
, name
, namelen
);
638 memset(im
, 0, sizeof(*im
));
639 memcpy(im
->im_name
, name
, namelen
);
641 im
->im_type
= h
->h_type
;
642 im
->im_conv
= IDMAP_CONV_NAMETOID
;
644 memset(&msg
, 0, sizeof(msg
));
646 msg
.len
= sizeof(*im
);
648 add_wait_queue(&idmap
->idmap_wq
, &wq
);
649 if (rpc_queue_upcall(idmap
->idmap_pipe
, &msg
) < 0) {
650 remove_wait_queue(&idmap
->idmap_wq
, &wq
);
654 set_current_state(TASK_UNINTERRUPTIBLE
);
655 mutex_unlock(&idmap
->idmap_im_lock
);
657 __set_current_state(TASK_RUNNING
);
658 remove_wait_queue(&idmap
->idmap_wq
, &wq
);
659 mutex_lock(&idmap
->idmap_im_lock
);
661 if (im
->im_status
& IDMAP_STATUS_SUCCESS
) {
667 memset(im
, 0, sizeof(*im
));
668 mutex_unlock(&idmap
->idmap_im_lock
);
669 mutex_unlock(&idmap
->idmap_lock
);
677 nfs_idmap_name(struct idmap
*idmap
, struct idmap_hashtable
*h
,
678 __u32 id
, char *name
)
680 struct rpc_pipe_msg msg
;
681 struct idmap_msg
*im
;
682 struct idmap_hashent
*he
;
683 DECLARE_WAITQUEUE(wq
, current
);
687 im
= &idmap
->idmap_im
;
689 mutex_lock(&idmap
->idmap_lock
);
690 mutex_lock(&idmap
->idmap_im_lock
);
692 he
= idmap_lookup_id(h
, id
);
694 memcpy(name
, he
->ih_name
, he
->ih_namelen
);
695 ret
= he
->ih_namelen
;
699 memset(im
, 0, sizeof(*im
));
700 im
->im_type
= h
->h_type
;
701 im
->im_conv
= IDMAP_CONV_IDTONAME
;
704 memset(&msg
, 0, sizeof(msg
));
706 msg
.len
= sizeof(*im
);
708 add_wait_queue(&idmap
->idmap_wq
, &wq
);
710 if (rpc_queue_upcall(idmap
->idmap_pipe
, &msg
) < 0) {
711 remove_wait_queue(&idmap
->idmap_wq
, &wq
);
715 set_current_state(TASK_UNINTERRUPTIBLE
);
716 mutex_unlock(&idmap
->idmap_im_lock
);
718 __set_current_state(TASK_RUNNING
);
719 remove_wait_queue(&idmap
->idmap_wq
, &wq
);
720 mutex_lock(&idmap
->idmap_im_lock
);
722 if (im
->im_status
& IDMAP_STATUS_SUCCESS
) {
723 if ((len
= strnlen(im
->im_name
, IDMAP_NAMESZ
)) == 0)
725 memcpy(name
, im
->im_name
, len
);
730 memset(im
, 0, sizeof(*im
));
731 mutex_unlock(&idmap
->idmap_im_lock
);
732 mutex_unlock(&idmap
->idmap_lock
);
737 idmap_pipe_downcall(struct file
*filp
, const char __user
*src
, size_t mlen
)
739 struct rpc_inode
*rpci
= RPC_I(filp
->f_path
.dentry
->d_inode
);
740 struct idmap
*idmap
= (struct idmap
*)rpci
->private;
741 struct idmap_msg im_in
, *im
= &idmap
->idmap_im
;
742 struct idmap_hashtable
*h
;
743 struct idmap_hashent
*he
= NULL
;
747 if (mlen
!= sizeof(im_in
))
750 if (copy_from_user(&im_in
, src
, mlen
) != 0)
753 mutex_lock(&idmap
->idmap_im_lock
);
756 im
->im_status
= im_in
.im_status
;
757 /* If we got an error, terminate now, and wake up pending upcalls */
758 if (!(im_in
.im_status
& IDMAP_STATUS_SUCCESS
)) {
759 wake_up(&idmap
->idmap_wq
);
763 /* Sanity checking of strings */
765 namelen_in
= strnlen(im_in
.im_name
, IDMAP_NAMESZ
);
766 if (namelen_in
== 0 || namelen_in
== IDMAP_NAMESZ
)
769 switch (im_in
.im_type
) {
770 case IDMAP_TYPE_USER
:
771 h
= &idmap
->idmap_user_hash
;
773 case IDMAP_TYPE_GROUP
:
774 h
= &idmap
->idmap_group_hash
;
780 switch (im_in
.im_conv
) {
781 case IDMAP_CONV_IDTONAME
:
782 /* Did we match the current upcall? */
783 if (im
->im_conv
== IDMAP_CONV_IDTONAME
784 && im
->im_type
== im_in
.im_type
785 && im
->im_id
== im_in
.im_id
) {
786 /* Yes: copy string, including the terminating '\0' */
787 memcpy(im
->im_name
, im_in
.im_name
, namelen_in
);
788 im
->im_name
[namelen_in
] = '\0';
789 wake_up(&idmap
->idmap_wq
);
791 he
= idmap_alloc_id(h
, im_in
.im_id
);
793 case IDMAP_CONV_NAMETOID
:
794 /* Did we match the current upcall? */
795 if (im
->im_conv
== IDMAP_CONV_NAMETOID
796 && im
->im_type
== im_in
.im_type
797 && strnlen(im
->im_name
, IDMAP_NAMESZ
) == namelen_in
798 && memcmp(im
->im_name
, im_in
.im_name
, namelen_in
) == 0) {
799 im
->im_id
= im_in
.im_id
;
800 wake_up(&idmap
->idmap_wq
);
802 he
= idmap_alloc_name(h
, im_in
.im_name
, namelen_in
);
808 /* If the entry is valid, also copy it to the cache */
810 idmap_update_entry(he
, im_in
.im_name
, namelen_in
, im_in
.im_id
);
813 mutex_unlock(&idmap
->idmap_im_lock
);
818 idmap_pipe_destroy_msg(struct rpc_pipe_msg
*msg
)
820 struct idmap_msg
*im
= msg
->data
;
821 struct idmap
*idmap
= container_of(im
, struct idmap
, idmap_im
);
825 mutex_lock(&idmap
->idmap_im_lock
);
826 im
->im_status
= IDMAP_STATUS_LOOKUPFAIL
;
827 wake_up(&idmap
->idmap_wq
);
828 mutex_unlock(&idmap
->idmap_im_lock
);
832 * Fowler/Noll/Vo hash
833 * http://www.isthe.com/chongo/tech/comp/fnv/
836 #define FNV_P_32 ((unsigned int)0x01000193) /* 16777619 */
837 #define FNV_1_32 ((unsigned int)0x811c9dc5) /* 2166136261 */
839 static unsigned int fnvhash32(const void *buf
, size_t buflen
)
841 const unsigned char *p
, *end
= (const unsigned char *)buf
+ buflen
;
842 unsigned int hash
= FNV_1_32
;
844 for (p
= buf
; p
< end
; p
++) {
846 hash
^= (unsigned int)*p
;
852 int nfs_map_name_to_uid(const struct nfs_server
*server
, const char *name
, size_t namelen
, __u32
*uid
)
854 struct idmap
*idmap
= server
->nfs_client
->cl_idmap
;
856 if (nfs_map_string_to_numeric(name
, namelen
, uid
))
858 return nfs_idmap_id(idmap
, &idmap
->idmap_user_hash
, name
, namelen
, uid
);
861 int nfs_map_group_to_gid(const struct nfs_server
*server
, const char *name
, size_t namelen
, __u32
*uid
)
863 struct idmap
*idmap
= server
->nfs_client
->cl_idmap
;
865 if (nfs_map_string_to_numeric(name
, namelen
, uid
))
867 return nfs_idmap_id(idmap
, &idmap
->idmap_group_hash
, name
, namelen
, uid
);
870 int nfs_map_uid_to_name(const struct nfs_server
*server
, __u32 uid
, char *buf
, size_t buflen
)
872 struct idmap
*idmap
= server
->nfs_client
->cl_idmap
;
875 if (!(server
->caps
& NFS_CAP_UIDGID_NOMAP
))
876 ret
= nfs_idmap_name(idmap
, &idmap
->idmap_user_hash
, uid
, buf
);
878 ret
= nfs_map_numeric_to_string(uid
, buf
, buflen
);
881 int nfs_map_gid_to_group(const struct nfs_server
*server
, __u32 uid
, char *buf
, size_t buflen
)
883 struct idmap
*idmap
= server
->nfs_client
->cl_idmap
;
886 if (!(server
->caps
& NFS_CAP_UIDGID_NOMAP
))
887 ret
= nfs_idmap_name(idmap
, &idmap
->idmap_group_hash
, uid
, buf
);
889 ret
= nfs_map_numeric_to_string(uid
, buf
, buflen
);
893 #endif /* CONFIG_NFS_USE_NEW_IDMAPPER */