[Linux-cluster] [PATCH] Fix usage of sk_alloc in cman-kernel (2.6.12rc2)

Fabio Massimo Di Nitto fabbione at fabbione.net
Sat Apr 16 08:33:44 UTC 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi everybody,

the 26th of March 2005 Arnaldo Carvalho de Melo commited a quite big change to
sk_alloc:

ChangeSet 1.2181.42.2 2005/03/26 20:04:49 acme at toy.ghostprotocols.net
  [NET] make all protos partially use sk_prot
  
  sk_alloc_slab becomes proto_register, that receives a struct proto not necessarily
  completely filled, but at least with the proto name, owner and obj_size (aka proto
  specific sock size), with this we can remove the struct sock sk_owner and sk_slab,
  using sk->sk_prot->{owner,slab} instead.
  
  This patch also makes sk_set_owner not necessary anymore, as at sk_alloc time we
  have now access to the struct proto onwer and slab members, so we can bump the
  module refcount exactly at sock allocation time. 
  
  Another nice "side effect" is that this patch removes the generic sk_cachep slab
  cache, making the only last two protocols that used it use just kmalloc, informing
  a struct proto obj_size equal to sizeof(struct sock).
  
  Ah, almost forgot that with this patch it is very easy to use a slab cache, as it is
  now created at proto_register time, and all protocols need to use proto_register,
  so its just a matter of switching the second parameter of proto_register to '1', heck,
  this can be done even at module load time with some small additional patch. 
  
  Another optimization that will be possible in the future is to move the sk_protocol
  and sk_type struct sock members to struct proto, but this has to wait for all protocols
  to move completely to sk_prot.
  
  This changeset also introduces /proc/net/protocols, that lists the registered protocols
  details, some may seem excessive, but I'd like to keep them while working on further 
  struct sock hierarchy work and also to realize which protocols are old ones, i.e. that
  still use struct proto_ops, etc, yeah, this is a bit of an exaggeration, as all protos
  still use struct proto_ops, but in time the idea is to move all to use sk->sk_prot and
  make the proto_ops infrastructure be shared among all protos, reducing one level of
  indirection.
  
  Signed-off-by: Arnaldo Carvalho de Melo <acme at conectiva.com.br>
  Signed-off-by: David S. Miller <davem at davemloft.net>

The same change needs to be propagated to cman-kernel (probably more,
but i am working on one module at a time).
Here is a preliminary patch that works for me.

Please review before applying.

Signed-off-by: Fabio M. Di Nitto <fabbione at ubuntu.com>

Index: cnxman.c
===================================================================
RCS file: /cvs/cluster/cluster/cman-kernel/src/cnxman.c,v
retrieving revision 1.55
diff -u -r1.55 cnxman.c
- --- cnxman.c	5 Apr 2005 13:43:09 -0000	1.55
+++ cnxman.c	16 Apr 2005 08:20:42 -0000
@@ -66,8 +66,8 @@
 extern void cman_set_realtime(struct task_struct *tsk, int prio);
 
 static struct proto_ops cl_proto_ops;
+static struct proto cl_proto;
 static struct sock *master_sock;
- -static kmem_cache_t *cluster_sk_cachep;
 
 /* Pointer to the pseudo node that maintains quorum in a 2node system */
 struct cluster_node *quorum_device = NULL;
@@ -918,14 +918,14 @@
 	return;
 }
 
- -static struct sock *cl_alloc_sock(struct socket *sock, int gfp)
+static struct sock *cl_alloc_sock(struct socket *sock, int gfp, int protocol)
 {
 	struct sock *sk;
 	struct cluster_sock *c;
 
 	if ((sk =
- -	     sk_alloc(AF_CLUSTER, gfp, sizeof (struct cluster_sock),
- -		      cluster_sk_cachep)) == NULL)
+	     sk_alloc(AF_CLUSTER, gpf, &cl_proto,
+		      1)) == NULL)
 		goto no_sock;
 
 	if (sock) {
@@ -937,6 +937,7 @@
 	sk->sk_no_check = 1;
 	sk->sk_family = PF_CLUSTER;
 	sk->sk_allocation = gfp;
+	sk->sk_protocol = protocol;
 
 	c = cluster_sk(sk);
 	c->port = 0;
@@ -1031,7 +1032,7 @@
 	if (!atomic_read(&cnxman_running) && protocol != CLPROTO_MASTER)
 		return -ENETDOWN;
 
- -	if ((sk = cl_alloc_sock(sock, GFP_KERNEL)) == NULL)
+	if ((sk = cl_alloc_sock(sock, GFP_KERNEL, protocol)) == NULL)
 		return -ENOBUFS;
 
 	sk->sk_protocol = protocol;
@@ -4155,6 +4156,12 @@
 	.owner       = THIS_MODULE,
 };
 
+static struct proto cl_proto = {
+	.name	     = "CMAN",
+	.owner	     = THIS_MODULE,
+	.obj_size    = sizeof(struct cluster_sock)
+};
+
 #ifdef MODULE
 MODULE_DESCRIPTION("Cluster Connection and Service Manager");
 MODULE_AUTHOR("Red Hat, Inc");
@@ -4166,19 +4173,14 @@
 	printk("CMAN %s (built %s %s) installed\n",
 	       CMAN_RELEASE_NAME, __DATE__, __TIME__);
 
- -	if (sock_register(&cl_family_ops)) {
- -		printk(KERN_INFO "Unable to register cluster socket type\n");
+	if (proto_register(&cl_proto,0) < 0) {
+		printk(KERN_INFO "Unable to register cluster protocol type\n");
 		return -1;
 	}
 
- -	/* allocate our sock slab cache */
- -	cluster_sk_cachep = kmem_cache_create("cluster_sock",
- -					      sizeof (struct cluster_sock), 0,
- -					      SLAB_HWCACHE_ALIGN, 0, 0);
- -	if (!cluster_sk_cachep) {
- -		printk(KERN_CRIT
- -		       "cluster_init: Cannot create cluster_sock SLAB cache\n");
- -		sock_unregister(AF_CLUSTER);
+	if (sock_register(&cl_family_ops)) {
+		proto_unregister(&cl_proto);
+		printk(KERN_INFO "Unable to register cluster socket type\n");
 		return -1;
 	}
 
@@ -4234,7 +4236,7 @@
 	cnxman_ioctl32_exit();
 #endif
 	sock_unregister(AF_CLUSTER);
- -	kmem_cache_destroy(cluster_sk_cachep);
+	proto_unregister(&cl_proto);
 }
 
 module_init(cluster_init);
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iQIVAwUBQmDNYFA6oBJjVJ+OAQJzyQ/+PjjPRmdqGKzpsms+96wTSzw5iaEsZHx4
9tZF6nbVBaCoygB9B0xkR0ra37DwZg+vWHOlzcS6HoHkiz0LveeXWb6Xu9bsTu2a
/9pIFSXFAaiwJTCE7FEHamHgm7yf2SyVyL2BS+05UzvYsfoG9JTIX2b8gsBtfb5J
qF5sZIqYrcrGn3wNLqxID+qgb1pKcgQfUGOWAVrdVy0xP2xClJQKSyFCsRcwCUmW
2qzIPW3DtBe996rlwVZAkupvHfueqGTkXNjhockah37+jO0KivcUA6ej2m+ZO1mk
Rc2Q5mEvjsq5UHHFXO27BomLXNYXdge9HZ9cAvip4tGvlby2PA90R0txTECKUbFK
jJCcfg9l0rS+OKGlCSEnyC52UIlU67lrvXiPvUFhyd0VMfVpaSFHe4NYJZbx0iQx
AFRcxaCkSLpZU78b4NpSig+qLz4ynLYcyPRXxL+WZpqRrbjaGnPdjkkwaX9hPqzs
cGLHMhgS8ImMZK6s67hutTIBXfgYZA7cdu9VzR+zITcssfuxowfCEMZOR/ixaD7+
jYSzS89NTHKhv0cAppu0JWNwC5vIKYu4WBxkRzTjjU8OqsozaSnvoDlQlyfn7Ffb
kqbXeJopnMHY1NW8DyazNRtrdArlP/Jw+7gi00S7LVDRlOpboxG9g5NDXhzTzmdP
goIHcBuTlWk=
=Dfi6
-----END PGP SIGNATURE-----




More information about the Linux-cluster mailing list