Commit f0b851689a5da2354f19bcbbac30cd2cab45c4a1
1 parent
5cf36cfdc8
Exists in
master
and in
20 other branches
NFSv4: Send unmapped uid/gids to the server if the idmapper fails
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Showing 1 changed file with 26 additions and 4 deletions Side-by-side Diff
fs/nfs/idmap.c
... | ... | @@ -52,6 +52,11 @@ |
52 | 52 | return 1; |
53 | 53 | } |
54 | 54 | |
55 | +static int nfs_map_numeric_to_string(__u32 id, char *buf, size_t buflen) | |
56 | +{ | |
57 | + return snprintf(buf, buflen, "%u", id); | |
58 | +} | |
59 | + | |
55 | 60 | #ifdef CONFIG_NFS_USE_NEW_IDMAPPER |
56 | 61 | |
57 | 62 | #include <linux/slab.h> |
58 | 63 | |
... | ... | @@ -252,11 +257,20 @@ |
252 | 257 | |
253 | 258 | int nfs_map_uid_to_name(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen) |
254 | 259 | { |
255 | - return nfs_idmap_lookup_name(uid, "user", buf, buflen); | |
260 | + int ret; | |
261 | + ret = nfs_idmap_lookup_name(uid, "user", buf, buflen); | |
262 | + if (ret < 0) | |
263 | + ret = nfs_map_numeric_to_string(uid, buf, buflen); | |
264 | + return ret; | |
256 | 265 | } |
257 | 266 | int nfs_map_gid_to_group(struct nfs_client *clp, __u32 gid, char *buf, size_t buflen) |
258 | 267 | { |
259 | - return nfs_idmap_lookup_name(gid, "group", buf, buflen); | |
268 | + int ret; | |
269 | + | |
270 | + ret = nfs_idmap_lookup_name(gid, "group", buf, buflen); | |
271 | + if (ret < 0) | |
272 | + ret = nfs_map_numeric_to_string(gid, buf, buflen); | |
273 | + return ret; | |
260 | 274 | } |
261 | 275 | |
262 | 276 | #else /* CONFIG_NFS_USE_NEW_IDMAPPER not defined */ |
263 | 277 | |
264 | 278 | |
265 | 279 | |
... | ... | @@ -736,14 +750,22 @@ |
736 | 750 | int nfs_map_uid_to_name(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen) |
737 | 751 | { |
738 | 752 | struct idmap *idmap = clp->cl_idmap; |
753 | + int ret; | |
739 | 754 | |
740 | - return nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf); | |
755 | + ret = nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf); | |
756 | + if (ret < 0) | |
757 | + ret = nfs_map_numeric_to_string(uid, buf, buflen); | |
758 | + return ret; | |
741 | 759 | } |
742 | 760 | int nfs_map_gid_to_group(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen) |
743 | 761 | { |
744 | 762 | struct idmap *idmap = clp->cl_idmap; |
763 | + int ret; | |
745 | 764 | |
746 | - return nfs_idmap_name(idmap, &idmap->idmap_group_hash, uid, buf); | |
765 | + ret = nfs_idmap_name(idmap, &idmap->idmap_group_hash, uid, buf); | |
766 | + if (ret < 0) | |
767 | + ret = nfs_map_numeric_to_string(uid, buf, buflen); | |
768 | + return ret; | |
747 | 769 | } |
748 | 770 | |
749 | 771 | #endif /* CONFIG_NFS_USE_NEW_IDMAPPER */ |