Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

NFSv4: Send unmapped uid/gids to the server if the idmapper fails

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

+26 -4
+26 -4
fs/nfs/idmap.c
··· 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> ··· 257 252 258 253 int nfs_map_uid_to_name(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen) 259 254 { 260 - return nfs_idmap_lookup_name(uid, "user", buf, buflen); 255 + int ret; 256 + ret = nfs_idmap_lookup_name(uid, "user", buf, buflen); 257 + if (ret < 0) 258 + ret = nfs_map_numeric_to_string(uid, buf, buflen); 259 + return ret; 261 260 } 262 261 int nfs_map_gid_to_group(struct nfs_client *clp, __u32 gid, char *buf, size_t buflen) 263 262 { 264 - return nfs_idmap_lookup_name(gid, "group", buf, buflen); 263 + int ret; 264 + 265 + ret = nfs_idmap_lookup_name(gid, "group", buf, buflen); 266 + if (ret < 0) 267 + ret = nfs_map_numeric_to_string(gid, buf, buflen); 268 + return ret; 265 269 } 266 270 267 271 #else /* CONFIG_NFS_USE_NEW_IDMAPPER not defined */ ··· 750 736 int nfs_map_uid_to_name(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen) 751 737 { 752 738 struct idmap *idmap = clp->cl_idmap; 739 + int ret; 753 740 754 - return nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf); 741 + ret = nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf); 742 + if (ret < 0) 743 + ret = nfs_map_numeric_to_string(uid, buf, buflen); 744 + return ret; 755 745 } 756 746 int nfs_map_gid_to_group(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen) 757 747 { 758 748 struct idmap *idmap = clp->cl_idmap; 749 + int ret; 759 750 760 - return nfs_idmap_name(idmap, &idmap->idmap_group_hash, uid, buf); 751 + ret = nfs_idmap_name(idmap, &idmap->idmap_group_hash, uid, buf); 752 + if (ret < 0) 753 + ret = nfs_map_numeric_to_string(uid, buf, buflen); 754 + return ret; 761 755 } 762 756 763 757 #endif /* CONFIG_NFS_USE_NEW_IDMAPPER */