summaryrefslogtreecommitdiff
path: root/utilities/ovs-dpctl.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-01-10 13:12:12 -0800
committerBen Pfaff <blp@nicira.com>2011-01-27 21:08:36 -0800
commitb0ec0f279ea4537cb421eba807254aba8f1971f2 (patch)
treea75fc9103d901333f548d8838854d19db86a9eeb /utilities/ovs-dpctl.c
parent856081f683d3e7d5b5fa07af4233d285eb205c47 (diff)
downloadopenvswitch-b0ec0f279ea4537cb421eba807254aba8f1971f2.tar.gz
datapath: Change listing ports to use an iterator concept.
One of the goals for Open vSwitch is to decouple kernel and userspace software, so that either one can be upgraded or rolled back independent of the other. To do this in full generality, it must be possible to add new features to the kernel vport layer without changing userspace software. In turn, that means that the odp_port structure must become variable-length. This does not, however, fit in well with the ODP_PORT_LIST ioctl in its current form, because that would require userspace to know how much space to allocate for each port in advance, or to allocate as much space as could possibly be needed. Neither choice is very attractive. This commit prepares for a different solution, by replacing ODP_PORT_LIST by a new ioctl ODP_VPORT_DUMP that retrieves information about a single vport from the datapath on each call. It is much cleaner to allocate the maximum amount of space for a single vport than to do so for possibly a large number of vports. It would be faster to retrieve a number of vports in batch instead of just one at a time, but that will naturally happen later when the kernel datapath interface is changed to use Netlink, so this patch does not bother with it. The Netlink version won't need to take the starting port number from userspace, since Netlink sockets can keep track of that state as part of their "dump" feature. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Jesse Gross <jesse@nicira.com>
Diffstat (limited to 'utilities/ovs-dpctl.c')
-rw-r--r--utilities/ovs-dpctl.c29
1 files changed, 5 insertions, 24 deletions
diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
index f7409fb18..23733fde0 100644
--- a/utilities/ovs-dpctl.c
+++ b/utilities/ovs-dpctl.c
@@ -214,21 +214,6 @@ do_del_dp(int argc OVS_UNUSED, char *argv[])
dpif_close(dpif);
}
-static int
-compare_ports(const void *a_, const void *b_)
-{
- const struct odp_port *a = a_;
- const struct odp_port *b = b_;
- return a->port < b->port ? -1 : a->port > b->port;
-}
-
-static void
-query_ports(struct dpif *dpif, struct odp_port **ports, size_t *n_ports)
-{
- run(dpif_port_list(dpif, ports, n_ports), "listing ports");
- qsort(*ports, *n_ports, sizeof **ports, compare_ports);
-}
-
static void
do_add_if(int argc OVS_UNUSED, char *argv[])
{
@@ -346,10 +331,9 @@ do_del_if(int argc OVS_UNUSED, char *argv[])
static void
show_dpif(struct dpif *dpif)
{
- struct odp_port *ports;
+ struct dpif_port_dump dump;
+ struct odp_port odp_port;
struct odp_stats stats;
- size_t n_ports;
- size_t i;
printf("%s:\n", dpif_name(dpif));
if (!dpif_get_dp_stats(dpif, &stats)) {
@@ -366,19 +350,16 @@ show_dpif(struct dpif *dpif)
printf("\tqueues: max-miss:%"PRIu16", max-action:%"PRIu16"\n",
stats.max_miss_queue, stats.max_action_queue);
}
- query_ports(dpif, &ports, &n_ports);
- for (i = 0; i < n_ports; i++) {
- const struct odp_port *p = &ports[i];
+ DPIF_PORT_FOR_EACH (&odp_port, &dump, dpif) {
struct ds ds;
- printf("\tport %u: %s", p->port, p->devname);
+ printf("\tport %u: %s", odp_port.port, odp_port.devname);
ds_init(&ds);
- format_odp_port_type(&ds, p);
+ format_odp_port_type(&ds, &odp_port);
printf("%s\n", ds_cstr(&ds));
ds_destroy(&ds);
}
- free(ports);
dpif_close(dpif);
}