Skip to content

Commit f0b8516

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFSv4: Send unmapped uid/gids to the server if the idmapper fails
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 5cf36cf commit f0b8516

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

fs/nfs/idmap.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ static int nfs_map_string_to_numeric(const char *name, size_t namelen, __u32 *re
5252
return 1;
5353
}
5454

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+
5560
#ifdef CONFIG_NFS_USE_NEW_IDMAPPER
5661

5762
#include <linux/slab.h>
@@ -252,11 +257,20 @@ int nfs_map_group_to_gid(struct nfs_client *clp, const char *name, size_t namele
252257

253258
int nfs_map_uid_to_name(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen)
254259
{
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;
256265
}
257266
int nfs_map_gid_to_group(struct nfs_client *clp, __u32 gid, char *buf, size_t buflen)
258267
{
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;
260274
}
261275

262276
#else /* CONFIG_NFS_USE_NEW_IDMAPPER not defined */
@@ -736,14 +750,22 @@ int nfs_map_group_to_gid(struct nfs_client *clp, const char *name, size_t namele
736750
int nfs_map_uid_to_name(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen)
737751
{
738752
struct idmap *idmap = clp->cl_idmap;
753+
int ret;
739754

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;
741759
}
742760
int nfs_map_gid_to_group(struct nfs_client *clp, __u32 uid, char *buf, size_t buflen)
743761
{
744762
struct idmap *idmap = clp->cl_idmap;
763+
int ret;
745764

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;
747769
}
748770

749771
#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */

0 commit comments

Comments
 (0)