linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root
@ 2013-02-04 11:02 Stanislav Kinsbursky
  2013-02-04 11:02 ` [PATCH v2 1/6] NFS: use SUNRPC cache creation and destruction helper for DNS cache Stanislav Kinsbursky
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Stanislav Kinsbursky @ 2013-02-04 11:02 UTC (permalink / raw)
  To: bfields; +Cc: linux-nfs, Trond.Myklebust, linux-kernel, devel

swapping

The main idea of this patch set is to call cache request not on kthread
upcall, but on userspace daemon cache_read call. This fixes the problem with
gaining of wrong dentry path after calling d_path() in kthread root context
(svc_export_request() callback), which always work in init root context, but
containers can work in "root jail" - i.e. have it's own nested root.

v2:
1) NFS DNS cache update wasn't done in the firest version. So this patch set
does preparation cleanup of the NFS DNS cache routines.
2) Also, this patch set doesn't remove cache_upcall helper anymore, because
it's still required for NFS DNS cache.

The following series implements...

---

Stanislav Kinsbursky (6):
      NFS: use SUNRPC cache creation and destruction helper for DNS cache
      NFS; simlify and clean cache library
      SUNRPC: introduce cache_detail->cache_request callback
      SUNRPC: rework cache upcall logic
      SUNRPC: remove "cache_request" argument in sunrpc_cache_pipe_upcall() function
      SUNRPC: move cache_detail->cache_request callback call to cache_read()


 fs/nfs/cache_lib.c                |   12 ++-----
 fs/nfs/cache_lib.h                |    2 -
 fs/nfs/dns_resolve.c              |   65 +++++++++++++++----------------------
 fs/nfsd/export.c                  |   14 +-------
 fs/nfsd/nfs4idmap.c               |   16 +--------
 include/linux/sunrpc/cache.h      |   10 +++---
 net/sunrpc/auth_gss/svcauth_gss.c |    8 +----
 net/sunrpc/cache.c                |   49 ++++++++++++++++------------
 net/sunrpc/svcauth_unix.c         |   14 +-------
 9 files changed, 69 insertions(+), 121 deletions(-)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/6] NFS: use SUNRPC cache creation and destruction helper for DNS cache
  2013-02-04 11:02 [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root Stanislav Kinsbursky
@ 2013-02-04 11:02 ` Stanislav Kinsbursky
  2013-02-08 21:13   ` J. Bruce Fields
  2013-02-04 11:02 ` [PATCH v2 2/6] NFS; simlify and clean cache library Stanislav Kinsbursky
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Stanislav Kinsbursky @ 2013-02-04 11:02 UTC (permalink / raw)
  To: bfields; +Cc: linux-nfs, Trond.Myklebust, linux-kernel, devel

This cache was the first containerized and doesn't use net-aware cache
creation and destruction helpers.
This is a cleanup patch which just makes code looks clearer and reduce amount
of lines of code.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
---
 fs/nfs/dns_resolve.c |   60 +++++++++++++++++++++-----------------------------
 1 files changed, 25 insertions(+), 35 deletions(-)

diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c
index ca4b11e..5015447 100644
--- a/fs/nfs/dns_resolve.c
+++ b/fs/nfs/dns_resolve.c
@@ -351,48 +351,39 @@ ssize_t nfs_dns_resolve_name(struct net *net, char *name,
 }
 EXPORT_SYMBOL_GPL(nfs_dns_resolve_name);
 
+static struct cache_detail nfs_dns_resolve_template = {
+	.owner		= THIS_MODULE,
+	.hash_size	= NFS_DNS_HASHTBL_SIZE,
+	.name		= "dns_resolve",
+	.cache_put	= nfs_dns_ent_put,
+	.cache_upcall	= nfs_dns_upcall,
+	.cache_parse	= nfs_dns_parse,
+	.cache_show	= nfs_dns_show,
+	.match		= nfs_dns_match,
+	.init		= nfs_dns_ent_init,
+	.update		= nfs_dns_ent_update,
+	.alloc		= nfs_dns_ent_alloc,
+};
+
+
 int nfs_dns_resolver_cache_init(struct net *net)
 {
-	int err = -ENOMEM;
+	int err;
 	struct nfs_net *nn = net_generic(net, nfs_net_id);
-	struct cache_detail *cd;
-	struct cache_head **tbl;
 
-	cd = kzalloc(sizeof(struct cache_detail), GFP_KERNEL);
-	if (cd == NULL)
-		goto err_cd;
-
-	tbl = kzalloc(NFS_DNS_HASHTBL_SIZE * sizeof(struct cache_head *),
-			GFP_KERNEL);
-	if (tbl == NULL)
-		goto err_tbl;
-
-	cd->owner = THIS_MODULE,
-	cd->hash_size = NFS_DNS_HASHTBL_SIZE,
-	cd->hash_table = tbl,
-	cd->name = "dns_resolve",
-	cd->cache_put = nfs_dns_ent_put,
-	cd->cache_upcall = nfs_dns_upcall,
-	cd->cache_parse = nfs_dns_parse,
-	cd->cache_show = nfs_dns_show,
-	cd->match = nfs_dns_match,
-	cd->init = nfs_dns_ent_init,
-	cd->update = nfs_dns_ent_update,
-	cd->alloc = nfs_dns_ent_alloc,
-
-	nfs_cache_init(cd);
-	err = nfs_cache_register_net(net, cd);
+	nn->nfs_dns_resolve = cache_create_net(&nfs_dns_resolve_template, net);
+	if (IS_ERR(nn->nfs_dns_resolve))
+		return PTR_ERR(nn->nfs_dns_resolve);
+
+	nfs_cache_init(nn->nfs_dns_resolve);
+	err = nfs_cache_register_net(net, nn->nfs_dns_resolve);
 	if (err)
 		goto err_reg;
-	nn->nfs_dns_resolve = cd;
 	return 0;
 
 err_reg:
-	nfs_cache_destroy(cd);
-	kfree(cd->hash_table);
-err_tbl:
-	kfree(cd);
-err_cd:
+	nfs_cache_destroy(nn->nfs_dns_resolve);
+	cache_destroy_net(nn->nfs_dns_resolve, net);
 	return err;
 }
 
@@ -403,8 +394,7 @@ void nfs_dns_resolver_cache_destroy(struct net *net)
 
 	nfs_cache_unregister_net(net, cd);
 	nfs_cache_destroy(cd);
-	kfree(cd->hash_table);
-	kfree(cd);
+	cache_destroy_net(nn->nfs_dns_resolve, net);
 }
 
 static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/6] NFS; simlify and clean cache library
  2013-02-04 11:02 [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root Stanislav Kinsbursky
  2013-02-04 11:02 ` [PATCH v2 1/6] NFS: use SUNRPC cache creation and destruction helper for DNS cache Stanislav Kinsbursky
@ 2013-02-04 11:02 ` Stanislav Kinsbursky
  2013-02-08 21:14   ` J. Bruce Fields
  2013-02-04 11:02 ` [PATCH v2 3/6] SUNRPC: introduce cache_detail->cache_request callback Stanislav Kinsbursky
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Stanislav Kinsbursky @ 2013-02-04 11:02 UTC (permalink / raw)
  To: bfields; +Cc: linux-nfs, Trond.Myklebust, linux-kernel, devel

This is a cleanup patch.
Such helpers like nfs_cache_init() and nfs_cache_destroy() are redundant,
because they are just a wrappers around sunrpc_init_cache_detail() and
sunrpc_destroy_cache_detail() respectively.
So let's remove them completely and move corresponding logic to
nfs_cache_register_net() and nfs_cache_unregister_net() respectively (since
they are called together anyway).

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
---
 fs/nfs/cache_lib.c   |   12 +++---------
 fs/nfs/cache_lib.h   |    2 --
 fs/nfs/dns_resolve.c |    6 +-----
 3 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/fs/nfs/cache_lib.c b/fs/nfs/cache_lib.c
index 862a2f1..5f7b053 100644
--- a/fs/nfs/cache_lib.c
+++ b/fs/nfs/cache_lib.c
@@ -128,10 +128,13 @@ int nfs_cache_register_net(struct net *net, struct cache_detail *cd)
 	struct super_block *pipefs_sb;
 	int ret = 0;
 
+	sunrpc_init_cache_detail(cd);
 	pipefs_sb = rpc_get_sb_net(net);
 	if (pipefs_sb) {
 		ret = nfs_cache_register_sb(pipefs_sb, cd);
 		rpc_put_sb_net(net);
+		if (ret)
+			sunrpc_destroy_cache_detail(cd);
 	}
 	return ret;
 }
@@ -151,14 +154,5 @@ void nfs_cache_unregister_net(struct net *net, struct cache_detail *cd)
 		nfs_cache_unregister_sb(pipefs_sb, cd);
 		rpc_put_sb_net(net);
 	}
-}
-
-void nfs_cache_init(struct cache_detail *cd)
-{
-	sunrpc_init_cache_detail(cd);
-}
-
-void nfs_cache_destroy(struct cache_detail *cd)
-{
 	sunrpc_destroy_cache_detail(cd);
 }
diff --git a/fs/nfs/cache_lib.h b/fs/nfs/cache_lib.h
index 317db95..4116d2c 100644
--- a/fs/nfs/cache_lib.h
+++ b/fs/nfs/cache_lib.h
@@ -23,8 +23,6 @@ extern struct nfs_cache_defer_req *nfs_cache_defer_req_alloc(void);
 extern void nfs_cache_defer_req_put(struct nfs_cache_defer_req *dreq);
 extern int nfs_cache_wait_for_upcall(struct nfs_cache_defer_req *dreq);
 
-extern void nfs_cache_init(struct cache_detail *cd);
-extern void nfs_cache_destroy(struct cache_detail *cd);
 extern int nfs_cache_register_net(struct net *net, struct cache_detail *cd);
 extern void nfs_cache_unregister_net(struct net *net, struct cache_detail *cd);
 extern int nfs_cache_register_sb(struct super_block *sb,
diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c
index 5015447..499834b 100644
--- a/fs/nfs/dns_resolve.c
+++ b/fs/nfs/dns_resolve.c
@@ -375,14 +375,12 @@ int nfs_dns_resolver_cache_init(struct net *net)
 	if (IS_ERR(nn->nfs_dns_resolve))
 		return PTR_ERR(nn->nfs_dns_resolve);
 
-	nfs_cache_init(nn->nfs_dns_resolve);
 	err = nfs_cache_register_net(net, nn->nfs_dns_resolve);
 	if (err)
 		goto err_reg;
 	return 0;
 
 err_reg:
-	nfs_cache_destroy(nn->nfs_dns_resolve);
 	cache_destroy_net(nn->nfs_dns_resolve, net);
 	return err;
 }
@@ -390,10 +388,8 @@ err_reg:
 void nfs_dns_resolver_cache_destroy(struct net *net)
 {
 	struct nfs_net *nn = net_generic(net, nfs_net_id);
-	struct cache_detail *cd = nn->nfs_dns_resolve;
 
-	nfs_cache_unregister_net(net, cd);
-	nfs_cache_destroy(cd);
+	nfs_cache_unregister_net(net, nn->nfs_dns_resolve);
 	cache_destroy_net(nn->nfs_dns_resolve, net);
 }
 


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/6] SUNRPC: introduce cache_detail->cache_request callback
  2013-02-04 11:02 [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root Stanislav Kinsbursky
  2013-02-04 11:02 ` [PATCH v2 1/6] NFS: use SUNRPC cache creation and destruction helper for DNS cache Stanislav Kinsbursky
  2013-02-04 11:02 ` [PATCH v2 2/6] NFS; simlify and clean cache library Stanislav Kinsbursky
@ 2013-02-04 11:02 ` Stanislav Kinsbursky
  2013-02-04 11:02 ` [PATCH v2 4/6] SUNRPC: rework cache upcall logic Stanislav Kinsbursky
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Stanislav Kinsbursky @ 2013-02-04 11:02 UTC (permalink / raw)
  To: bfields; +Cc: linux-nfs, Trond.Myklebust, linux-kernel, devel

This callback will allow to simplify upcalls in further patches in this
series.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
---
 fs/nfs/dns_resolve.c              |    3 ++-
 fs/nfsd/export.c                  |    6 ++++--
 fs/nfsd/nfs4idmap.c               |    6 ++++--
 include/linux/sunrpc/cache.h      |    4 ++++
 net/sunrpc/auth_gss/svcauth_gss.c |    3 ++-
 net/sunrpc/svcauth_unix.c         |    6 ++++--
 6 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c
index 499834b..53109f0 100644
--- a/fs/nfs/dns_resolve.c
+++ b/fs/nfs/dns_resolve.c
@@ -142,7 +142,7 @@ static int nfs_dns_upcall(struct cache_detail *cd,
 
 	ret = nfs_cache_upcall(cd, key->hostname);
 	if (ret)
-		ret = sunrpc_cache_pipe_upcall(cd, ch, nfs_dns_request);
+		ret = sunrpc_cache_pipe_upcall(cd, ch, cd->cache_request);
 	return ret;
 }
 
@@ -357,6 +357,7 @@ static struct cache_detail nfs_dns_resolve_template = {
 	.name		= "dns_resolve",
 	.cache_put	= nfs_dns_ent_put,
 	.cache_upcall	= nfs_dns_upcall,
+	.cache_request	= nfs_dns_request,
 	.cache_parse	= nfs_dns_parse,
 	.cache_show	= nfs_dns_show,
 	.match		= nfs_dns_match,
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 45159ee..22f4d4e 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -69,7 +69,7 @@ static void expkey_request(struct cache_detail *cd,
 
 static int expkey_upcall(struct cache_detail *cd, struct cache_head *h)
 {
-	return sunrpc_cache_pipe_upcall(cd, h, expkey_request);
+	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
 }
 
 static struct svc_expkey *svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new,
@@ -246,6 +246,7 @@ static struct cache_detail svc_expkey_cache_template = {
 	.name		= "nfsd.fh",
 	.cache_put	= expkey_put,
 	.cache_upcall	= expkey_upcall,
+	.cache_request	= expkey_request,
 	.cache_parse	= expkey_parse,
 	.cache_show	= expkey_show,
 	.match		= expkey_match,
@@ -340,7 +341,7 @@ static void svc_export_request(struct cache_detail *cd,
 
 static int svc_export_upcall(struct cache_detail *cd, struct cache_head *h)
 {
-	return sunrpc_cache_pipe_upcall(cd, h, svc_export_request);
+	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
 }
 
 static struct svc_export *svc_export_update(struct svc_export *new,
@@ -713,6 +714,7 @@ static struct cache_detail svc_export_cache_template = {
 	.name		= "nfsd.export",
 	.cache_put	= svc_export_put,
 	.cache_upcall	= svc_export_upcall,
+	.cache_request	= svc_export_request,
 	.cache_parse	= svc_export_parse,
 	.cache_show	= svc_export_show,
 	.match		= svc_export_match,
diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c
index a1f10c0..9033dfd 100644
--- a/fs/nfsd/nfs4idmap.c
+++ b/fs/nfsd/nfs4idmap.c
@@ -142,7 +142,7 @@ idtoname_request(struct cache_detail *cd, struct cache_head *ch, char **bpp,
 static int
 idtoname_upcall(struct cache_detail *cd, struct cache_head *ch)
 {
-	return sunrpc_cache_pipe_upcall(cd, ch, idtoname_request);
+	return sunrpc_cache_pipe_upcall(cd, ch, cd->cache_request);
 }
 
 static int
@@ -193,6 +193,7 @@ static struct cache_detail idtoname_cache_template = {
 	.name		= "nfs4.idtoname",
 	.cache_put	= ent_put,
 	.cache_upcall	= idtoname_upcall,
+	.cache_request	= idtoname_request,
 	.cache_parse	= idtoname_parse,
 	.cache_show	= idtoname_show,
 	.warn_no_listener = warn_no_idmapd,
@@ -323,7 +324,7 @@ nametoid_request(struct cache_detail *cd, struct cache_head *ch, char **bpp,
 static int
 nametoid_upcall(struct cache_detail *cd, struct cache_head *ch)
 {
-	return sunrpc_cache_pipe_upcall(cd, ch, nametoid_request);
+	return sunrpc_cache_pipe_upcall(cd, ch, cd->cache_request);
 }
 
 static int
@@ -366,6 +367,7 @@ static struct cache_detail nametoid_cache_template = {
 	.name		= "nfs4.nametoid",
 	.cache_put	= ent_put,
 	.cache_upcall	= nametoid_upcall,
+	.cache_request	= nametoid_request,
 	.cache_parse	= nametoid_parse,
 	.cache_show	= nametoid_show,
 	.warn_no_listener = warn_no_idmapd,
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 5dc9ee4..4f1c858 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -83,6 +83,10 @@ struct cache_detail {
 	int			(*cache_upcall)(struct cache_detail *,
 						struct cache_head *);
 
+	void			(*cache_request)(struct cache_detail *cd,
+						 struct cache_head *ch,
+						 char **bpp, int *blen);
+
 	int			(*cache_parse)(struct cache_detail *,
 					       char *buf, int len);
 
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index 73e9573..82437f9 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -184,7 +184,7 @@ static void rsi_request(struct cache_detail *cd,
 
 static int rsi_upcall(struct cache_detail *cd, struct cache_head *h)
 {
-	return sunrpc_cache_pipe_upcall(cd, h, rsi_request);
+	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
 }
 
 
@@ -276,6 +276,7 @@ static struct cache_detail rsi_cache_template = {
 	.name           = "auth.rpcsec.init",
 	.cache_put      = rsi_put,
 	.cache_upcall   = rsi_upcall,
+	.cache_request  = rsi_request,
 	.cache_parse    = rsi_parse,
 	.match		= rsi_match,
 	.init		= rsi_init,
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 4d01292..6b03cc1 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -159,7 +159,7 @@ static void ip_map_request(struct cache_detail *cd,
 
 static int ip_map_upcall(struct cache_detail *cd, struct cache_head *h)
 {
-	return sunrpc_cache_pipe_upcall(cd, h, ip_map_request);
+	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
 }
 
 static struct ip_map *__ip_map_lookup(struct cache_detail *cd, char *class, struct in6_addr *addr);
@@ -472,7 +472,7 @@ static void unix_gid_request(struct cache_detail *cd,
 
 static int unix_gid_upcall(struct cache_detail *cd, struct cache_head *h)
 {
-	return sunrpc_cache_pipe_upcall(cd, h, unix_gid_request);
+	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
 }
 
 static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, uid_t uid);
@@ -578,6 +578,7 @@ static struct cache_detail unix_gid_cache_template = {
 	.name		= "auth.unix.gid",
 	.cache_put	= unix_gid_put,
 	.cache_upcall	= unix_gid_upcall,
+	.cache_request	= unix_gid_request,
 	.cache_parse	= unix_gid_parse,
 	.cache_show	= unix_gid_show,
 	.match		= unix_gid_match,
@@ -875,6 +876,7 @@ static struct cache_detail ip_map_cache_template = {
 	.name		= "auth.unix.ip",
 	.cache_put	= ip_map_put,
 	.cache_upcall	= ip_map_upcall,
+	.cache_request	= ip_map_request,
 	.cache_parse	= ip_map_parse,
 	.cache_show	= ip_map_show,
 	.match		= ip_map_match,


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 4/6] SUNRPC: rework cache upcall logic
  2013-02-04 11:02 [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root Stanislav Kinsbursky
                   ` (2 preceding siblings ...)
  2013-02-04 11:02 ` [PATCH v2 3/6] SUNRPC: introduce cache_detail->cache_request callback Stanislav Kinsbursky
@ 2013-02-04 11:02 ` Stanislav Kinsbursky
  2013-02-04 11:02 ` [PATCH v2 5/6] SUNRPC: remove "cache_request" argument in sunrpc_cache_pipe_upcall() function Stanislav Kinsbursky
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Stanislav Kinsbursky @ 2013-02-04 11:02 UTC (permalink / raw)
  To: bfields; +Cc: linux-nfs, Trond.Myklebust, linux-kernel, devel

For most of SUNRPC caches (except NFS DNS cache) cache_detail->cache_upcall is
redundant since all that it's implementations are doing is calling
sunrpc_cache_pipe_upcall() with proper function address argument.
Cache request function address is now stored on cache_detail structure and
thus all the code can be simplified.
Now, for those cache details, which doesn't have cache_upcall callback (the
only one, which still has is nfs_dns_resolve_template)
sunrpc_cache_pipe_upcall will be called instead.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
---
 fs/nfsd/export.c                  |   12 ------------
 fs/nfsd/nfs4idmap.c               |   14 --------------
 net/sunrpc/auth_gss/svcauth_gss.c |    7 -------
 net/sunrpc/cache.c                |   11 +++++++----
 net/sunrpc/svcauth_unix.c         |   12 ------------
 5 files changed, 7 insertions(+), 49 deletions(-)

diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 22f4d4e..30a572d 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -67,11 +67,6 @@ static void expkey_request(struct cache_detail *cd,
 	(*bpp)[-1] = '\n';
 }
 
-static int expkey_upcall(struct cache_detail *cd, struct cache_head *h)
-{
-	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
-}
-
 static struct svc_expkey *svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new,
 					    struct svc_expkey *old);
 static struct svc_expkey *svc_expkey_lookup(struct cache_detail *cd, struct svc_expkey *);
@@ -245,7 +240,6 @@ static struct cache_detail svc_expkey_cache_template = {
 	.hash_size	= EXPKEY_HASHMAX,
 	.name		= "nfsd.fh",
 	.cache_put	= expkey_put,
-	.cache_upcall	= expkey_upcall,
 	.cache_request	= expkey_request,
 	.cache_parse	= expkey_parse,
 	.cache_show	= expkey_show,
@@ -339,11 +333,6 @@ static void svc_export_request(struct cache_detail *cd,
 	(*bpp)[-1] = '\n';
 }
 
-static int svc_export_upcall(struct cache_detail *cd, struct cache_head *h)
-{
-	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
-}
-
 static struct svc_export *svc_export_update(struct svc_export *new,
 					    struct svc_export *old);
 static struct svc_export *svc_export_lookup(struct svc_export *);
@@ -713,7 +702,6 @@ static struct cache_detail svc_export_cache_template = {
 	.hash_size	= EXPORT_HASHMAX,
 	.name		= "nfsd.export",
 	.cache_put	= svc_export_put,
-	.cache_upcall	= svc_export_upcall,
 	.cache_request	= svc_export_request,
 	.cache_parse	= svc_export_parse,
 	.cache_show	= svc_export_show,
diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c
index 9033dfd..d9402ea 100644
--- a/fs/nfsd/nfs4idmap.c
+++ b/fs/nfsd/nfs4idmap.c
@@ -140,12 +140,6 @@ idtoname_request(struct cache_detail *cd, struct cache_head *ch, char **bpp,
 }
 
 static int
-idtoname_upcall(struct cache_detail *cd, struct cache_head *ch)
-{
-	return sunrpc_cache_pipe_upcall(cd, ch, cd->cache_request);
-}
-
-static int
 idtoname_match(struct cache_head *ca, struct cache_head *cb)
 {
 	struct ent *a = container_of(ca, struct ent, h);
@@ -192,7 +186,6 @@ static struct cache_detail idtoname_cache_template = {
 	.hash_size	= ENT_HASHMAX,
 	.name		= "nfs4.idtoname",
 	.cache_put	= ent_put,
-	.cache_upcall	= idtoname_upcall,
 	.cache_request	= idtoname_request,
 	.cache_parse	= idtoname_parse,
 	.cache_show	= idtoname_show,
@@ -322,12 +315,6 @@ nametoid_request(struct cache_detail *cd, struct cache_head *ch, char **bpp,
 }
 
 static int
-nametoid_upcall(struct cache_detail *cd, struct cache_head *ch)
-{
-	return sunrpc_cache_pipe_upcall(cd, ch, cd->cache_request);
-}
-
-static int
 nametoid_match(struct cache_head *ca, struct cache_head *cb)
 {
 	struct ent *a = container_of(ca, struct ent, h);
@@ -366,7 +353,6 @@ static struct cache_detail nametoid_cache_template = {
 	.hash_size	= ENT_HASHMAX,
 	.name		= "nfs4.nametoid",
 	.cache_put	= ent_put,
-	.cache_upcall	= nametoid_upcall,
 	.cache_request	= nametoid_request,
 	.cache_parse	= nametoid_parse,
 	.cache_show	= nametoid_show,
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index 82437f9..1bd18af 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -182,12 +182,6 @@ static void rsi_request(struct cache_detail *cd,
 	(*bpp)[-1] = '\n';
 }
 
-static int rsi_upcall(struct cache_detail *cd, struct cache_head *h)
-{
-	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
-}
-
-
 static int rsi_parse(struct cache_detail *cd,
 		    char *mesg, int mlen)
 {
@@ -275,7 +269,6 @@ static struct cache_detail rsi_cache_template = {
 	.hash_size	= RSI_HASHMAX,
 	.name           = "auth.rpcsec.init",
 	.cache_put      = rsi_put,
-	.cache_upcall   = rsi_upcall,
 	.cache_request  = rsi_request,
 	.cache_parse    = rsi_parse,
 	.match		= rsi_match,
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 9f84703..51853d8 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -196,9 +196,9 @@ EXPORT_SYMBOL_GPL(sunrpc_cache_update);
 
 static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
 {
-	if (!cd->cache_upcall)
-		return -EINVAL;
-	return cd->cache_upcall(cd, h);
+	if (cd->cache_upcall)
+		return cd->cache_upcall(cd, h);
+	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
 }
 
 static inline int cache_is_valid(struct cache_detail *detail, struct cache_head *h)
@@ -1152,6 +1152,9 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h,
 	char *bp;
 	int len;
 
+	if (!detail->cache_request)
+		return -EINVAL;
+
 	if (!cache_listeners_exist(detail)) {
 		warn_no_listener(detail);
 		return -EINVAL;
@@ -1605,7 +1608,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
 	if (p == NULL)
 		goto out_nomem;
 
-	if (cd->cache_upcall || cd->cache_parse) {
+	if (cd->cache_request || cd->cache_parse) {
 		p = proc_create_data("channel", S_IFREG|S_IRUSR|S_IWUSR,
 				     cd->u.procfs.proc_ent,
 				     &cache_file_operations_procfs, cd);
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 6b03cc1..002ddd9 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -157,11 +157,6 @@ static void ip_map_request(struct cache_detail *cd,
 	(*bpp)[-1] = '\n';
 }
 
-static int ip_map_upcall(struct cache_detail *cd, struct cache_head *h)
-{
-	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
-}
-
 static struct ip_map *__ip_map_lookup(struct cache_detail *cd, char *class, struct in6_addr *addr);
 static int __ip_map_update(struct cache_detail *cd, struct ip_map *ipm, struct unix_domain *udom, time_t expiry);
 
@@ -470,11 +465,6 @@ static void unix_gid_request(struct cache_detail *cd,
 	(*bpp)[-1] = '\n';
 }
 
-static int unix_gid_upcall(struct cache_detail *cd, struct cache_head *h)
-{
-	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
-}
-
 static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, uid_t uid);
 
 static int unix_gid_parse(struct cache_detail *cd,
@@ -577,7 +567,6 @@ static struct cache_detail unix_gid_cache_template = {
 	.hash_size	= GID_HASHMAX,
 	.name		= "auth.unix.gid",
 	.cache_put	= unix_gid_put,
-	.cache_upcall	= unix_gid_upcall,
 	.cache_request	= unix_gid_request,
 	.cache_parse	= unix_gid_parse,
 	.cache_show	= unix_gid_show,
@@ -875,7 +864,6 @@ static struct cache_detail ip_map_cache_template = {
 	.hash_size	= IP_HASHMAX,
 	.name		= "auth.unix.ip",
 	.cache_put	= ip_map_put,
-	.cache_upcall	= ip_map_upcall,
 	.cache_request	= ip_map_request,
 	.cache_parse	= ip_map_parse,
 	.cache_show	= ip_map_show,


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 5/6] SUNRPC: remove "cache_request" argument in sunrpc_cache_pipe_upcall() function
  2013-02-04 11:02 [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root Stanislav Kinsbursky
                   ` (3 preceding siblings ...)
  2013-02-04 11:02 ` [PATCH v2 4/6] SUNRPC: rework cache upcall logic Stanislav Kinsbursky
@ 2013-02-04 11:02 ` Stanislav Kinsbursky
  2013-02-04 11:03 ` [PATCH v2 6/6] SUNRPC: move cache_detail->cache_request callback call to cache_read() Stanislav Kinsbursky
  2013-02-04 14:17 ` [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root J. Bruce Fields
  6 siblings, 0 replies; 11+ messages in thread
From: Stanislav Kinsbursky @ 2013-02-04 11:02 UTC (permalink / raw)
  To: bfields; +Cc: linux-nfs, Trond.Myklebust, linux-kernel, devel

Passing this pointer is redundant since it's stored on cache_detail structure,
which is also passed to sunrpc_cache_pipe_upcall () function.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
---
 fs/nfs/dns_resolve.c         |    2 +-
 include/linux/sunrpc/cache.h |    6 +-----
 net/sunrpc/cache.c           |   10 +++-------
 3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c
index 53109f0..88b46c7 100644
--- a/fs/nfs/dns_resolve.c
+++ b/fs/nfs/dns_resolve.c
@@ -142,7 +142,7 @@ static int nfs_dns_upcall(struct cache_detail *cd,
 
 	ret = nfs_cache_upcall(cd, key->hostname);
 	if (ret)
-		ret = sunrpc_cache_pipe_upcall(cd, ch, cd->cache_request);
+		ret = sunrpc_cache_pipe_upcall(cd, ch);
 	return ret;
 }
 
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 4f1c858..303399b 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -161,11 +161,7 @@ sunrpc_cache_update(struct cache_detail *detail,
 		    struct cache_head *new, struct cache_head *old, int hash);
 
 extern int
-sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h,
-		void (*cache_request)(struct cache_detail *,
-				      struct cache_head *,
-				      char **,
-				      int *));
+sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h);
 
 
 extern void cache_clean_deferred(void *owner);
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 51853d8..8ffec5a 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -198,7 +198,7 @@ static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
 {
 	if (cd->cache_upcall)
 		return cd->cache_upcall(cd, h);
-	return sunrpc_cache_pipe_upcall(cd, h, cd->cache_request);
+	return sunrpc_cache_pipe_upcall(cd, h);
 }
 
 static inline int cache_is_valid(struct cache_detail *detail, struct cache_head *h)
@@ -1140,11 +1140,7 @@ static bool cache_listeners_exist(struct cache_detail *detail)
  *
  * Each request is at most one page long.
  */
-int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h,
-		void (*cache_request)(struct cache_detail *,
-				      struct cache_head *,
-				      char **,
-				      int *))
+int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
 {
 
 	char *buf;
@@ -1172,7 +1168,7 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h,
 
 	bp = buf; len = PAGE_SIZE;
 
-	cache_request(detail, h, &bp, &len);
+	detail->cache_request(detail, h, &bp, &len);
 
 	if (len < 0) {
 		kfree(buf);


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 6/6] SUNRPC: move cache_detail->cache_request callback call to cache_read()
  2013-02-04 11:02 [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root Stanislav Kinsbursky
                   ` (4 preceding siblings ...)
  2013-02-04 11:02 ` [PATCH v2 5/6] SUNRPC: remove "cache_request" argument in sunrpc_cache_pipe_upcall() function Stanislav Kinsbursky
@ 2013-02-04 11:03 ` Stanislav Kinsbursky
  2013-02-04 14:17 ` [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root J. Bruce Fields
  6 siblings, 0 replies; 11+ messages in thread
From: Stanislav Kinsbursky @ 2013-02-04 11:03 UTC (permalink / raw)
  To: bfields; +Cc: linux-nfs, Trond.Myklebust, linux-kernel, devel

The reason to move cache_request() callback call from
sunrpc_cache_pipe_upcall() to cache_read() is that this garantees, that cache
access will be done userspace process context (only userspace process have
proper root context).
This is required for NFSd support in container: svc_export_request() (which is
cache_request callback) calls d_path(), which, in turn, traverse dentry up to
current->fs->root. Kernel threads always have global root, while container
have be in "root jail" - i.e. have it's own nested root.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
---
 net/sunrpc/cache.c |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 8ffec5a..5502471 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -750,6 +750,18 @@ struct cache_reader {
 	int			offset;	/* if non-0, we have a refcnt on next request */
 };
 
+static int cache_request(struct cache_detail *detail,
+			       struct cache_request *crq)
+{
+	char *bp = crq->buf;
+	int len = PAGE_SIZE;
+
+	detail->cache_request(detail, crq->item, &bp, &len);
+	if (len < 0)
+		return -EAGAIN;
+	return PAGE_SIZE - len;
+}
+
 static ssize_t cache_read(struct file *filp, char __user *buf, size_t count,
 			  loff_t *ppos, struct cache_detail *cd)
 {
@@ -784,6 +796,13 @@ static ssize_t cache_read(struct file *filp, char __user *buf, size_t count,
 		rq->readers++;
 	spin_unlock(&queue_lock);
 
+	if (rq->len == 0) {
+		err = cache_request(cd, rq);
+		if (err < 0)
+			goto out;
+		rq->len = err;
+	}
+
 	if (rp->offset == 0 && !test_bit(CACHE_PENDING, &rq->item->flags)) {
 		err = -EAGAIN;
 		spin_lock(&queue_lock);
@@ -1145,8 +1164,6 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
 
 	char *buf;
 	struct cache_request *crq;
-	char *bp;
-	int len;
 
 	if (!detail->cache_request)
 		return -EINVAL;
@@ -1166,19 +1183,10 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
 		return -EAGAIN;
 	}
 
-	bp = buf; len = PAGE_SIZE;
-
-	detail->cache_request(detail, h, &bp, &len);
-
-	if (len < 0) {
-		kfree(buf);
-		kfree(crq);
-		return -EAGAIN;
-	}
 	crq->q.reader = 0;
 	crq->item = cache_get(h);
 	crq->buf = buf;
-	crq->len = PAGE_SIZE - len;
+	crq->len = 0;
 	crq->readers = 0;
 	spin_lock(&queue_lock);
 	list_add_tail(&crq->q.list, &detail->queue);


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root
  2013-02-04 11:02 [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root Stanislav Kinsbursky
                   ` (5 preceding siblings ...)
  2013-02-04 11:03 ` [PATCH v2 6/6] SUNRPC: move cache_detail->cache_request callback call to cache_read() Stanislav Kinsbursky
@ 2013-02-04 14:17 ` J. Bruce Fields
  2013-02-05  5:36   ` Stanislav Kinsbursky
  6 siblings, 1 reply; 11+ messages in thread
From: J. Bruce Fields @ 2013-02-04 14:17 UTC (permalink / raw)
  To: Stanislav Kinsbursky; +Cc: linux-nfs, Trond.Myklebust, linux-kernel, devel

On Mon, Feb 04, 2013 at 02:02:29PM +0300, Stanislav Kinsbursky wrote:
> swapping
> 
> The main idea of this patch set is to call cache request not on kthread
> upcall, but on userspace daemon cache_read call. This fixes the problem with
> gaining of wrong dentry path after calling d_path() in kthread root context
> (svc_export_request() callback), which always work in init root context, but
> containers can work in "root jail" - i.e. have it's own nested root.
> 
> v2:
> 1) NFS DNS cache update wasn't done in the firest version. So this patch set
> does preparation cleanup of the NFS DNS cache routines.
> 2) Also, this patch set doesn't remove cache_upcall helper anymore, because
> it's still required for NFS DNS cache.

Argh--I really prefer incremental patches once I've already committed
something, but OK.

Backing out the old patches, I'll take a look at these.  The first two
should probably get an ACK from Trond.

--b.

> 
> The following series implements...
> 
> ---
> 
> Stanislav Kinsbursky (6):
>       NFS: use SUNRPC cache creation and destruction helper for DNS cache
>       NFS; simlify and clean cache library
>       SUNRPC: introduce cache_detail->cache_request callback
>       SUNRPC: rework cache upcall logic
>       SUNRPC: remove "cache_request" argument in sunrpc_cache_pipe_upcall() function
>       SUNRPC: move cache_detail->cache_request callback call to cache_read()
> 
> 
>  fs/nfs/cache_lib.c                |   12 ++-----
>  fs/nfs/cache_lib.h                |    2 -
>  fs/nfs/dns_resolve.c              |   65 +++++++++++++++----------------------
>  fs/nfsd/export.c                  |   14 +-------
>  fs/nfsd/nfs4idmap.c               |   16 +--------
>  include/linux/sunrpc/cache.h      |   10 +++---
>  net/sunrpc/auth_gss/svcauth_gss.c |    8 +----
>  net/sunrpc/cache.c                |   49 ++++++++++++++++------------
>  net/sunrpc/svcauth_unix.c         |   14 +-------
>  9 files changed, 69 insertions(+), 121 deletions(-)
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root
  2013-02-04 14:17 ` [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root J. Bruce Fields
@ 2013-02-05  5:36   ` Stanislav Kinsbursky
  0 siblings, 0 replies; 11+ messages in thread
From: Stanislav Kinsbursky @ 2013-02-05  5:36 UTC (permalink / raw)
  To: J. Bruce Fields, linux-nfs; +Cc: Trond.Myklebust, linux-kernel, devel

04.02.2013 18:17, J. Bruce Fields пишет:
> On Mon, Feb 04, 2013 at 02:02:29PM +0300, Stanislav Kinsbursky wrote:
>> swapping
>>
>> The main idea of this patch set is to call cache request not on kthread
>> upcall, but on userspace daemon cache_read call. This fixes the problem with
>> gaining of wrong dentry path after calling d_path() in kthread root context
>> (svc_export_request() callback), which always work in init root context, but
>> containers can work in "root jail" - i.e. have it's own nested root.
>>
>> v2:
>> 1) NFS DNS cache update wasn't done in the firest version. So this patch set
>> does preparation cleanup of the NFS DNS cache routines.
>> 2) Also, this patch set doesn't remove cache_upcall helper anymore, because
>> it's still required for NFS DNS cache.
>
> Argh--I really prefer incremental patches once I've already committed
> something, but OK.
>

Sorry. I was thinking about incremental patches. Next time I'll do so.

> Backing out the old patches, I'll take a look at these.  The first two
> should probably get an ACK from Trond.
>

Trond, could you review first two patches, please?
They are just clean-ups, actually. Nothing special. Required to unify the interfaces for latter patches in the series.

-- 
Best regards,
Stanislav Kinsbursky

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/6] NFS: use SUNRPC cache creation and destruction helper for DNS cache
  2013-02-04 11:02 ` [PATCH v2 1/6] NFS: use SUNRPC cache creation and destruction helper for DNS cache Stanislav Kinsbursky
@ 2013-02-08 21:13   ` J. Bruce Fields
  0 siblings, 0 replies; 11+ messages in thread
From: J. Bruce Fields @ 2013-02-08 21:13 UTC (permalink / raw)
  To: Stanislav Kinsbursky; +Cc: linux-nfs, Trond.Myklebust, linux-kernel, devel

On Mon, Feb 04, 2013 at 02:02:35PM +0300, Stanislav Kinsbursky wrote:
> This cache was the first containerized and doesn't use net-aware cache
> creation and destruction helpers.
> This is a cleanup patch which just makes code looks clearer and reduce amount
> of lines of code.

This looks like uncontroversial cleanup, and should probably go in
with the rest through my tree, so I'm inclined to just merge it.

But an "ACK" from Trond would be reassuring.--b.

> 
> Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
> ---
>  fs/nfs/dns_resolve.c |   60 +++++++++++++++++++++-----------------------------
>  1 files changed, 25 insertions(+), 35 deletions(-)
> 
> diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c
> index ca4b11e..5015447 100644
> --- a/fs/nfs/dns_resolve.c
> +++ b/fs/nfs/dns_resolve.c
> @@ -351,48 +351,39 @@ ssize_t nfs_dns_resolve_name(struct net *net, char *name,
>  }
>  EXPORT_SYMBOL_GPL(nfs_dns_resolve_name);
>  
> +static struct cache_detail nfs_dns_resolve_template = {
> +	.owner		= THIS_MODULE,
> +	.hash_size	= NFS_DNS_HASHTBL_SIZE,
> +	.name		= "dns_resolve",
> +	.cache_put	= nfs_dns_ent_put,
> +	.cache_upcall	= nfs_dns_upcall,
> +	.cache_parse	= nfs_dns_parse,
> +	.cache_show	= nfs_dns_show,
> +	.match		= nfs_dns_match,
> +	.init		= nfs_dns_ent_init,
> +	.update		= nfs_dns_ent_update,
> +	.alloc		= nfs_dns_ent_alloc,
> +};
> +
> +
>  int nfs_dns_resolver_cache_init(struct net *net)
>  {
> -	int err = -ENOMEM;
> +	int err;
>  	struct nfs_net *nn = net_generic(net, nfs_net_id);
> -	struct cache_detail *cd;
> -	struct cache_head **tbl;
>  
> -	cd = kzalloc(sizeof(struct cache_detail), GFP_KERNEL);
> -	if (cd == NULL)
> -		goto err_cd;
> -
> -	tbl = kzalloc(NFS_DNS_HASHTBL_SIZE * sizeof(struct cache_head *),
> -			GFP_KERNEL);
> -	if (tbl == NULL)
> -		goto err_tbl;
> -
> -	cd->owner = THIS_MODULE,
> -	cd->hash_size = NFS_DNS_HASHTBL_SIZE,
> -	cd->hash_table = tbl,
> -	cd->name = "dns_resolve",
> -	cd->cache_put = nfs_dns_ent_put,
> -	cd->cache_upcall = nfs_dns_upcall,
> -	cd->cache_parse = nfs_dns_parse,
> -	cd->cache_show = nfs_dns_show,
> -	cd->match = nfs_dns_match,
> -	cd->init = nfs_dns_ent_init,
> -	cd->update = nfs_dns_ent_update,
> -	cd->alloc = nfs_dns_ent_alloc,
> -
> -	nfs_cache_init(cd);
> -	err = nfs_cache_register_net(net, cd);
> +	nn->nfs_dns_resolve = cache_create_net(&nfs_dns_resolve_template, net);
> +	if (IS_ERR(nn->nfs_dns_resolve))
> +		return PTR_ERR(nn->nfs_dns_resolve);
> +
> +	nfs_cache_init(nn->nfs_dns_resolve);
> +	err = nfs_cache_register_net(net, nn->nfs_dns_resolve);
>  	if (err)
>  		goto err_reg;
> -	nn->nfs_dns_resolve = cd;
>  	return 0;
>  
>  err_reg:
> -	nfs_cache_destroy(cd);
> -	kfree(cd->hash_table);
> -err_tbl:
> -	kfree(cd);
> -err_cd:
> +	nfs_cache_destroy(nn->nfs_dns_resolve);
> +	cache_destroy_net(nn->nfs_dns_resolve, net);
>  	return err;
>  }
>  
> @@ -403,8 +394,7 @@ void nfs_dns_resolver_cache_destroy(struct net *net)
>  
>  	nfs_cache_unregister_net(net, cd);
>  	nfs_cache_destroy(cd);
> -	kfree(cd->hash_table);
> -	kfree(cd);
> +	cache_destroy_net(nn->nfs_dns_resolve, net);
>  }
>  
>  static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/6] NFS; simlify and clean cache library
  2013-02-04 11:02 ` [PATCH v2 2/6] NFS; simlify and clean cache library Stanislav Kinsbursky
@ 2013-02-08 21:14   ` J. Bruce Fields
  0 siblings, 0 replies; 11+ messages in thread
From: J. Bruce Fields @ 2013-02-08 21:14 UTC (permalink / raw)
  To: Stanislav Kinsbursky; +Cc: linux-nfs, Trond.Myklebust, linux-kernel, devel

On Mon, Feb 04, 2013 at 02:02:40PM +0300, Stanislav Kinsbursky wrote:
> This is a cleanup patch.
> Such helpers like nfs_cache_init() and nfs_cache_destroy() are redundant,
> because they are just a wrappers around sunrpc_init_cache_detail() and
> sunrpc_destroy_cache_detail() respectively.
> So let's remove them completely and move corresponding logic to
> nfs_cache_register_net() and nfs_cache_unregister_net() respectively (since
> they are called together anyway).

Ditto for this one--Trond, any objection?

--b.

> 
> Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
> ---
>  fs/nfs/cache_lib.c   |   12 +++---------
>  fs/nfs/cache_lib.h   |    2 --
>  fs/nfs/dns_resolve.c |    6 +-----
>  3 files changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/fs/nfs/cache_lib.c b/fs/nfs/cache_lib.c
> index 862a2f1..5f7b053 100644
> --- a/fs/nfs/cache_lib.c
> +++ b/fs/nfs/cache_lib.c
> @@ -128,10 +128,13 @@ int nfs_cache_register_net(struct net *net, struct cache_detail *cd)
>  	struct super_block *pipefs_sb;
>  	int ret = 0;
>  
> +	sunrpc_init_cache_detail(cd);
>  	pipefs_sb = rpc_get_sb_net(net);
>  	if (pipefs_sb) {
>  		ret = nfs_cache_register_sb(pipefs_sb, cd);
>  		rpc_put_sb_net(net);
> +		if (ret)
> +			sunrpc_destroy_cache_detail(cd);
>  	}
>  	return ret;
>  }
> @@ -151,14 +154,5 @@ void nfs_cache_unregister_net(struct net *net, struct cache_detail *cd)
>  		nfs_cache_unregister_sb(pipefs_sb, cd);
>  		rpc_put_sb_net(net);
>  	}
> -}
> -
> -void nfs_cache_init(struct cache_detail *cd)
> -{
> -	sunrpc_init_cache_detail(cd);
> -}
> -
> -void nfs_cache_destroy(struct cache_detail *cd)
> -{
>  	sunrpc_destroy_cache_detail(cd);
>  }
> diff --git a/fs/nfs/cache_lib.h b/fs/nfs/cache_lib.h
> index 317db95..4116d2c 100644
> --- a/fs/nfs/cache_lib.h
> +++ b/fs/nfs/cache_lib.h
> @@ -23,8 +23,6 @@ extern struct nfs_cache_defer_req *nfs_cache_defer_req_alloc(void);
>  extern void nfs_cache_defer_req_put(struct nfs_cache_defer_req *dreq);
>  extern int nfs_cache_wait_for_upcall(struct nfs_cache_defer_req *dreq);
>  
> -extern void nfs_cache_init(struct cache_detail *cd);
> -extern void nfs_cache_destroy(struct cache_detail *cd);
>  extern int nfs_cache_register_net(struct net *net, struct cache_detail *cd);
>  extern void nfs_cache_unregister_net(struct net *net, struct cache_detail *cd);
>  extern int nfs_cache_register_sb(struct super_block *sb,
> diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c
> index 5015447..499834b 100644
> --- a/fs/nfs/dns_resolve.c
> +++ b/fs/nfs/dns_resolve.c
> @@ -375,14 +375,12 @@ int nfs_dns_resolver_cache_init(struct net *net)
>  	if (IS_ERR(nn->nfs_dns_resolve))
>  		return PTR_ERR(nn->nfs_dns_resolve);
>  
> -	nfs_cache_init(nn->nfs_dns_resolve);
>  	err = nfs_cache_register_net(net, nn->nfs_dns_resolve);
>  	if (err)
>  		goto err_reg;
>  	return 0;
>  
>  err_reg:
> -	nfs_cache_destroy(nn->nfs_dns_resolve);
>  	cache_destroy_net(nn->nfs_dns_resolve, net);
>  	return err;
>  }
> @@ -390,10 +388,8 @@ err_reg:
>  void nfs_dns_resolver_cache_destroy(struct net *net)
>  {
>  	struct nfs_net *nn = net_generic(net, nfs_net_id);
> -	struct cache_detail *cd = nn->nfs_dns_resolve;
>  
> -	nfs_cache_unregister_net(net, cd);
> -	nfs_cache_destroy(cd);
> +	nfs_cache_unregister_net(net, nn->nfs_dns_resolve);
>  	cache_destroy_net(nn->nfs_dns_resolve, net);
>  }
>  
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-02-08 21:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-04 11:02 [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root Stanislav Kinsbursky
2013-02-04 11:02 ` [PATCH v2 1/6] NFS: use SUNRPC cache creation and destruction helper for DNS cache Stanislav Kinsbursky
2013-02-08 21:13   ` J. Bruce Fields
2013-02-04 11:02 ` [PATCH v2 2/6] NFS; simlify and clean cache library Stanislav Kinsbursky
2013-02-08 21:14   ` J. Bruce Fields
2013-02-04 11:02 ` [PATCH v2 3/6] SUNRPC: introduce cache_detail->cache_request callback Stanislav Kinsbursky
2013-02-04 11:02 ` [PATCH v2 4/6] SUNRPC: rework cache upcall logic Stanislav Kinsbursky
2013-02-04 11:02 ` [PATCH v2 5/6] SUNRPC: remove "cache_request" argument in sunrpc_cache_pipe_upcall() function Stanislav Kinsbursky
2013-02-04 11:03 ` [PATCH v2 6/6] SUNRPC: move cache_detail->cache_request callback call to cache_read() Stanislav Kinsbursky
2013-02-04 14:17 ` [PATCH v2 0/6] SUNRPC: rework cache upcall to avoid NFSd root J. Bruce Fields
2013-02-05  5:36   ` Stanislav Kinsbursky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).