a0668fa
commit e6499c6f4b5f56a16f8b8ef60529c1da28b13aea
a0668fa
Author: Bryan Schumaker <bjschuma@netapp.com>
a0668fa
Date:   Thu Jan 26 16:54:23 2012 -0500
a0668fa
a0668fa
    NFS: Fall back on old idmapper if request_key() fails
a0668fa
    
a0668fa
    This patch removes the CONFIG_NFS_USE_NEW_IDMAPPER compile option.
a0668fa
    First, the idmapper will attempt to map the id using /sbin/request-key
a0668fa
    and nfsidmap.  If this fails (if /etc/request-key.conf is not configured
a0668fa
    properly) then the idmapper will call the legacy code to perform the
a0668fa
    mapping.  I left a comment stating where the legacy code begins to make
a0668fa
    it easier for somebody to remove in the future.
a0668fa
    
a0668fa
    Signed-off-by: Bryan Schumaker <bjschuma@netapp.com>
a0668fa
    Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
a0668fa
a0668fa
diff -up linux-3.2.noarch/fs/nfs/idmap.c.orig linux-3.2.noarch/fs/nfs/idmap.c
a0668fa
--- linux-3.2.noarch/fs/nfs/idmap.c.orig	2012-01-27 10:07:07.209851446 -0500
a0668fa
+++ linux-3.2.noarch/fs/nfs/idmap.c	2012-01-27 10:15:42.914563082 -0500
a0668fa
@@ -142,8 +142,6 @@ static int nfs_map_numeric_to_string(__u
a0668fa
 	return snprintf(buf, buflen, "%u", id);
a0668fa
 }
a0668fa
 
a0668fa
-#ifdef CONFIG_NFS_USE_NEW_IDMAPPER
a0668fa
-
a0668fa
 #include <linux/cred.h>
a0668fa
 #include <linux/sunrpc/sched.h>
a0668fa
 #include <linux/nfs4.h>
a0668fa
@@ -328,43 +326,7 @@ static int nfs_idmap_lookup_id(const cha
a0668fa
 	return ret;
a0668fa
 }
a0668fa
 
a0668fa
-int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid)
a0668fa
-{
a0668fa
-	if (nfs_map_string_to_numeric(name, namelen, uid))
a0668fa
-		return 0;
a0668fa
-	return nfs_idmap_lookup_id(name, namelen, "uid", uid);
a0668fa
-}
a0668fa
-
a0668fa
-int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *gid)
a0668fa
-{
a0668fa
-	if (nfs_map_string_to_numeric(name, namelen, gid))
a0668fa
-		return 0;
a0668fa
-	return nfs_idmap_lookup_id(name, namelen, "gid", gid);
a0668fa
-}
a0668fa
-
a0668fa
-int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen)
a0668fa
-{
a0668fa
-	int ret = -EINVAL;
a0668fa
-
a0668fa
-	if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
a0668fa
-		ret = nfs_idmap_lookup_name(uid, "user", buf, buflen);
a0668fa
-	if (ret < 0)
a0668fa
-		ret = nfs_map_numeric_to_string(uid, buf, buflen);
a0668fa
-	return ret;
a0668fa
-}
a0668fa
-int nfs_map_gid_to_group(const struct nfs_server *server, __u32 gid, char *buf, size_t buflen)
a0668fa
-{
a0668fa
-	int ret = -EINVAL;
a0668fa
-
a0668fa
-	if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
a0668fa
-		ret = nfs_idmap_lookup_name(gid, "group", buf, buflen);
a0668fa
-	if (ret < 0)
a0668fa
-		ret = nfs_map_numeric_to_string(gid, buf, buflen);
a0668fa
-	return ret;
a0668fa
-}
a0668fa
-
a0668fa
-#else  /* CONFIG_NFS_USE_NEW_IDMAPPER not defined */
a0668fa
-
a0668fa
+/* idmap classic begins here */
a0668fa
 #include <linux/module.h>
a0668fa
 #include <linux/mutex.h>
a0668fa
 #include <linux/init.h>
a0668fa
@@ -796,19 +758,27 @@ static unsigned int fnvhash32(const void
a0668fa
 int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid)
a0668fa
 {
a0668fa
 	struct idmap *idmap = server->nfs_client->cl_idmap;
a0668fa
+	int ret = -EINVAL;
a0668fa
 
a0668fa
 	if (nfs_map_string_to_numeric(name, namelen, uid))
a0668fa
 		return 0;
a0668fa
-	return nfs_idmap_id(idmap, &idmap->idmap_user_hash, name, namelen, uid);
a0668fa
+	ret = nfs_idmap_lookup_id(name, namelen, "uid", uid);
a0668fa
+	if (ret < 0)
a0668fa
+		ret = nfs_idmap_id(idmap, &idmap->idmap_user_hash, name, namelen, uid);
a0668fa
+	return ret;
a0668fa
 }
a0668fa
 
a0668fa
-int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid)
a0668fa
+int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *gid)
a0668fa
 {
a0668fa
 	struct idmap *idmap = server->nfs_client->cl_idmap;
a0668fa
+	int ret = -EINVAL;
a0668fa
 
a0668fa
-	if (nfs_map_string_to_numeric(name, namelen, uid))
a0668fa
+	if (nfs_map_string_to_numeric(name, namelen, gid))
a0668fa
 		return 0;
a0668fa
-	return nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, uid);
a0668fa
+	ret = nfs_idmap_lookup_id(name, namelen, "gid", gid);
a0668fa
+	if (ret < 0)
a0668fa
+		ret = nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, gid);
a0668fa
+	return ret;
a0668fa
 }
a0668fa
 
a0668fa
 int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen)
a0668fa
@@ -816,22 +786,26 @@ int nfs_map_uid_to_name(const struct nfs
a0668fa
 	struct idmap *idmap = server->nfs_client->cl_idmap;
a0668fa
 	int ret = -EINVAL;
a0668fa
 
a0668fa
-	if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
a0668fa
-		ret = nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf);
a0668fa
+	if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) {
a0668fa
+		ret = nfs_idmap_lookup_name(uid, "user", buf, buflen);
a0668fa
+		if (ret < 0)
a0668fa
+			ret = nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf);
a0668fa
+	}
a0668fa
 	if (ret < 0)
a0668fa
 		ret = nfs_map_numeric_to_string(uid, buf, buflen);
a0668fa
 	return ret;
a0668fa
 }
a0668fa
-int nfs_map_gid_to_group(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen)
a0668fa
+int nfs_map_gid_to_group(const struct nfs_server *server, __u32 gid, char *buf, size_t buflen)
a0668fa
 {
a0668fa
 	struct idmap *idmap = server->nfs_client->cl_idmap;
a0668fa
 	int ret = -EINVAL;
a0668fa
 
a0668fa
-	if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
a0668fa
-		ret = nfs_idmap_name(idmap, &idmap->idmap_group_hash, uid, buf);
a0668fa
+	if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) {
a0668fa
+		ret = nfs_idmap_lookup_name(gid, "group", buf, buflen);
a0668fa
+		if (ret < 0)
a0668fa
+			ret = nfs_idmap_name(idmap, &idmap->idmap_group_hash, gid, buf);
a0668fa
+	}
a0668fa
 	if (ret < 0)
a0668fa
-		ret = nfs_map_numeric_to_string(uid, buf, buflen);
a0668fa
+		ret = nfs_map_numeric_to_string(gid, buf, buflen);
a0668fa
 	return ret;
a0668fa
 }
a0668fa
-
a0668fa
-#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
a0668fa
diff -up linux-3.2.noarch/fs/nfs/Kconfig.orig linux-3.2.noarch/fs/nfs/Kconfig
a0668fa
--- linux-3.2.noarch/fs/nfs/Kconfig.orig	2012-01-04 18:55:44.000000000 -0500
a0668fa
+++ linux-3.2.noarch/fs/nfs/Kconfig	2012-01-27 10:15:42.913562572 -0500
a0668fa
@@ -132,14 +132,3 @@ config NFS_USE_KERNEL_DNS
a0668fa
 	select DNS_RESOLVER
a0668fa
 	select KEYS
a0668fa
 	default y
a0668fa
-
a0668fa
-config NFS_USE_NEW_IDMAPPER
a0668fa
-	bool "Use the new idmapper upcall routine"
a0668fa
-	depends on NFS_V4 && KEYS
a0668fa
-	help
a0668fa
-	  Say Y here if you want NFS to use the new idmapper upcall functions.
a0668fa
-	  You will need /sbin/request-key (usually provided by the keyutils
a0668fa
-	  package).  For details, read
a0668fa
-	  <file:Documentation/filesystems/nfs/idmapper.txt>.
a0668fa
-
a0668fa
-	  If you are unsure, say N.
a0668fa
diff -up linux-3.2.noarch/fs/nfs/sysctl.c.orig linux-3.2.noarch/fs/nfs/sysctl.c
a0668fa
--- linux-3.2.noarch/fs/nfs/sysctl.c.orig	2012-01-04 18:55:44.000000000 -0500
a0668fa
+++ linux-3.2.noarch/fs/nfs/sysctl.c	2012-01-27 10:15:42.914563082 -0500
a0668fa
@@ -32,7 +32,6 @@ static ctl_table nfs_cb_sysctls[] = {
a0668fa
 		.extra1 = (int *)&nfs_set_port_min,
a0668fa
 		.extra2 = (int *)&nfs_set_port_max,
a0668fa
 	},
a0668fa
-#ifndef CONFIG_NFS_USE_NEW_IDMAPPER
a0668fa
 	{
a0668fa
 		.procname = "idmap_cache_timeout",
a0668fa
 		.data = &nfs_idmap_cache_timeout,
a0668fa
@@ -40,7 +39,6 @@ static ctl_table nfs_cb_sysctls[] = {
a0668fa
 		.mode = 0644,
a0668fa
 		.proc_handler = proc_dointvec_jiffies,
a0668fa
 	},
a0668fa
-#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
a0668fa
 #endif
a0668fa
 	{
a0668fa
 		.procname	= "nfs_mountpoint_timeout",
a0668fa
diff -up linux-3.2.noarch/include/linux/nfs_idmap.h.orig linux-3.2.noarch/include/linux/nfs_idmap.h
a0668fa
--- linux-3.2.noarch/include/linux/nfs_idmap.h.orig	2012-01-27 10:06:46.783643915 -0500
a0668fa
+++ linux-3.2.noarch/include/linux/nfs_idmap.h	2012-01-27 10:15:42.915563594 -0500
a0668fa
@@ -69,36 +69,11 @@ struct nfs_server;
a0668fa
 struct nfs_fattr;
a0668fa
 struct nfs4_string;
a0668fa
 
a0668fa
-#ifdef CONFIG_NFS_USE_NEW_IDMAPPER
a0668fa
-
a0668fa
 int nfs_idmap_init(void);
a0668fa
 void nfs_idmap_quit(void);
a0668fa
-
a0668fa
-static inline int nfs_idmap_new(struct nfs_client *clp)
a0668fa
-{
a0668fa
-	return 0;
a0668fa
-}
a0668fa
-
a0668fa
-static inline void nfs_idmap_delete(struct nfs_client *clp)
a0668fa
-{
a0668fa
-}
a0668fa
-
a0668fa
-#else /* CONFIG_NFS_USE_NEW_IDMAPPER not set */
a0668fa
-
a0668fa
-static inline int nfs_idmap_init(void)
a0668fa
-{
a0668fa
-	return 0;
a0668fa
-}
a0668fa
-
a0668fa
-static inline void nfs_idmap_quit(void)
a0668fa
-{
a0668fa
-}
a0668fa
-
a0668fa
 int nfs_idmap_new(struct nfs_client *);
a0668fa
 void nfs_idmap_delete(struct nfs_client *);
a0668fa
 
a0668fa
-#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
a0668fa
-
a0668fa
 void nfs_fattr_init_names(struct nfs_fattr *fattr,
a0668fa
 		struct nfs4_string *owner_name,
a0668fa
 		struct nfs4_string *group_name);