summaryrefslogtreecommitdiff
path: root/pfinet
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2015-09-27 18:50:11 +0200
committerJustus Winter <4winter@informatik.uni-hamburg.de>2015-09-27 22:09:58 +0200
commitf42c29d2172e953887542bf7fb31d2b739563887 (patch)
tree13122a5c38bb10838b52d5850d48580e6fd27707 /pfinet
parenta5d384c333dbbe863c1515d6167d956b0c5b4852 (diff)
pfinet: convert to trivfs dynamic classes and buckets
libtrivfs contains two ways of managing more than one port class and bucket. There is the old way of using a statically allocated array with explicit length, and the new way with dynamically allocated vectors. Converting all users to the new way of handling multiple classes and/or buckets, we can simplify the code in libtrivfs. In many cases, the code will be simpler and more expressive for the user. This also fixes a mild bug. The classes and buckets given to `trivfs_startup' end up in the dynamic vectors too, making the object lookup code use the more complicated code path. * pfinet/main.c: Convert to dynamic classes and buckets. * pfinet/options.c: Likewise. * pfinet/pfinet.h: Likewise. * pfinet/socket-ops.c: Likewise.
Diffstat (limited to 'pfinet')
-rw-r--r--pfinet/main.c61
-rw-r--r--pfinet/options.c8
-rw-r--r--pfinet/pfinet.h7
-rw-r--r--pfinet/socket-ops.c2
4 files changed, 41 insertions, 37 deletions
diff --git a/pfinet/main.c b/pfinet/main.c
index 8716fdbb..46457a90 100644
--- a/pfinet/main.c
+++ b/pfinet/main.c
@@ -56,11 +56,9 @@ int trivfs_support_write = 1;
int trivfs_support_exec = 0;
int trivfs_allow_open = O_READ | O_WRITE;
-struct port_class *trivfs_protid_portclasses[2];
-int trivfs_protid_nportclasses = 2;
-
-struct port_class *trivfs_cntl_portclasses[2];
-int trivfs_cntl_nportclasses = 2;
+/* We have a class each per portclass. */
+struct port_class *pfinet_protid_portclasses[2];
+struct port_class *pfinet_cntl_portclasses[2];
/* Which portclass to install on the bootstrap port, default to IPv4. */
int pfinet_bootstrap_portclass = PORTCLASS_INET;
@@ -334,7 +332,7 @@ main (int argc,
if (bootstrap != MACH_PORT_NULL) {
/* Create portclass to install on the bootstrap port. */
- if(trivfs_protid_portclasses[pfinet_bootstrap_portclass]
+ if(pfinet_protid_portclasses[pfinet_bootstrap_portclass]
!= MACH_PORT_NULL)
error(1, 0, "No portclass left to assign to bootstrap port");
@@ -342,17 +340,23 @@ main (int argc,
if (pfinet_bootstrap_portclass == PORTCLASS_INET6)
pfinet_activate_ipv6 ();
#endif
-
- trivfs_protid_portclasses[pfinet_bootstrap_portclass] =
- ports_create_class (trivfs_clean_protid, 0);
- trivfs_cntl_portclasses[pfinet_bootstrap_portclass] =
- ports_create_class (trivfs_clean_cntl, 0);
+
+ err = trivfs_add_protid_port_class (
+ &pfinet_protid_portclasses[pfinet_bootstrap_portclass]);
+ if (err)
+ error (1, 0, "error creating control port class");
+
+ err = trivfs_add_control_port_class (
+ &pfinet_cntl_portclasses[pfinet_bootstrap_portclass]);
+ if (err)
+ error (1, 0, "error creating control port class");
/* Talk to parent and link us in. */
err = trivfs_startup (bootstrap, 0,
- trivfs_cntl_portclasses[pfinet_bootstrap_portclass],
- pfinet_bucket, trivfs_protid_portclasses
- [pfinet_bootstrap_portclass], pfinet_bucket,
+ pfinet_cntl_portclasses[pfinet_bootstrap_portclass],
+ pfinet_bucket,
+ pfinet_protid_portclasses[pfinet_bootstrap_portclass],
+ pfinet_bucket,
&pfinetctl);
if (err)
@@ -371,7 +375,7 @@ main (int argc,
/* Check that at least one portclass has been bound,
error out otherwise. */
for (i = 0; i < trivfs_protid_nportclasses; i ++)
- if (trivfs_protid_portclasses[i] != MACH_PORT_NULL)
+ if (pfinet_protid_portclasses[i] != MACH_PORT_NULL)
break;
if (i == trivfs_protid_nportclasses)
@@ -424,22 +428,25 @@ pfinet_bind (int portclass, const char *name)
err = errno;
if (! err) {
- if (trivfs_protid_portclasses[portclass] != MACH_PORT_NULL)
+ if (pfinet_protid_portclasses[portclass] != MACH_PORT_NULL)
error (1, 0, "Cannot bind one protocol to multiple nodes.\n");
#ifdef CONFIG_IPV6
if (portclass == PORTCLASS_INET6)
pfinet_activate_ipv6 ();
#endif
+ //mark
+ err = trivfs_add_protid_port_class (&pfinet_protid_portclasses[portclass]);
+ if (err)
+ error (1, 0, "error creating control port class");
- trivfs_protid_portclasses[portclass] =
- ports_create_class (trivfs_clean_protid, 0);
- trivfs_cntl_portclasses[portclass] =
- ports_create_class (trivfs_clean_cntl, 0);
+ err = trivfs_add_control_port_class (&pfinet_cntl_portclasses[portclass]);
+ if (err)
+ error (1, 0, "error creating control port class");
- err = trivfs_create_control (file, trivfs_cntl_portclasses[portclass],
- pfinet_bucket,
- trivfs_protid_portclasses[portclass],
+ err = trivfs_create_control (file, pfinet_cntl_portclasses[portclass],
+ pfinet_bucket,
+ pfinet_protid_portclasses[portclass],
pfinet_bucket, &cntl);
}
@@ -473,16 +480,16 @@ trivfs_goaway (struct trivfs_control *cntl, int flags)
else
{
/* Stop new requests. */
- ports_inhibit_class_rpcs (trivfs_cntl_portclasses[0]);
- ports_inhibit_class_rpcs (trivfs_protid_portclasses[0]);
+ ports_inhibit_class_rpcs (pfinet_cntl_portclasses[0]);
+ ports_inhibit_class_rpcs (pfinet_protid_portclasses[0]);
ports_inhibit_class_rpcs (socketport_class);
if (ports_count_class (socketport_class) != 0)
{
/* We won't go away, so start things going again... */
ports_enable_class (socketport_class);
- ports_resume_class_rpcs (trivfs_cntl_portclasses[0]);
- ports_resume_class_rpcs (trivfs_protid_portclasses[0]);
+ ports_resume_class_rpcs (pfinet_cntl_portclasses[0]);
+ ports_resume_class_rpcs (pfinet_protid_portclasses[0]);
return EBUSY;
}
diff --git a/pfinet/options.c b/pfinet/options.c
index daffcd59..ae44759d 100644
--- a/pfinet/options.c
+++ b/pfinet/options.c
@@ -133,7 +133,7 @@ parse_interface_copy_device(struct device *src,
&& FIB_RES_GW(res) != INADDR_ANY)
dst->gateway = FIB_RES_GW (res);
#ifdef CONFIG_IPV6
- if (trivfs_protid_portclasses[PORTCLASS_INET6] != MACH_PORT_NULL)
+ if (pfinet_protid_portclasses[PORTCLASS_INET6] != MACH_PORT_NULL)
idev = ipv6_find_idev(src);
if (idev)
@@ -452,7 +452,7 @@ parse_opt (int opt, char *arg, struct argp_state *state)
{
#ifdef CONFIG_IPV6
struct inet6_dev *idev = NULL;
- if (trivfs_protid_portclasses[PORTCLASS_INET6] != MACH_PORT_NULL
+ if (pfinet_protid_portclasses[PORTCLASS_INET6] != MACH_PORT_NULL
&& in->device)
idev = ipv6_find_idev(in->device);
#endif
@@ -570,7 +570,7 @@ parse_opt (int opt, char *arg, struct argp_state *state)
/* Set IPv6 default router. */
#ifdef CONFIG_IPV6
- if (trivfs_protid_portclasses[PORTCLASS_INET6] != MACH_PORT_NULL)
+ if (pfinet_protid_portclasses[PORTCLASS_INET6] != MACH_PORT_NULL)
{
struct rt6_info *rt6i = ipv6_get_dflt_router ();
@@ -710,7 +710,7 @@ trivfs_append_args (struct trivfs_control *fsys, char **argz, size_t *argz_len)
#ifdef CONFIG_IPV6
struct inet6_dev *idev = NULL;
- if (trivfs_protid_portclasses[PORTCLASS_INET6] != MACH_PORT_NULL)
+ if (pfinet_protid_portclasses[PORTCLASS_INET6] != MACH_PORT_NULL)
idev = ipv6_find_idev(dev);
if (idev)
diff --git a/pfinet/pfinet.h b/pfinet/pfinet.h
index 46aa97bb..6e592259 100644
--- a/pfinet/pfinet.h
+++ b/pfinet/pfinet.h
@@ -92,11 +92,8 @@ enum {
PORTCLASS_INET6,
};
-extern struct port_class *trivfs_protid_portclasses[];
-extern int trivfs_protid_nportclasses;
-
-extern struct port_class *trivfs_cntl_portclasses[2];
-extern int trivfs_cntl_nportclasses;
+extern struct port_class *pfinet_protid_portclasses[2];
+extern struct port_class *pfinet_cntl_portclasses[2];
/* Which portclass to install on the bootstrap port. */
extern int pfinet_bootstrap_portclass;
diff --git a/pfinet/socket-ops.c b/pfinet/socket-ops.c
index 3f8b7fbc..14b3120c 100644
--- a/pfinet/socket-ops.c
+++ b/pfinet/socket-ops.c
@@ -82,7 +82,7 @@ S_socket_create (struct trivfs_protid *master,
isroot = 1;
}
- if (master->pi.class == trivfs_protid_portclasses[PORTCLASS_INET])
+ if (master->pi.class == pfinet_protid_portclasses[PORTCLASS_INET])
err = - (*net_families[PF_INET]->create) (sock, protocol);
else
err = - (*net_families[PF_INET6]->create) (sock, protocol);