Skip to content

Commit

Permalink
stream: Eliminate pstream_set_dscp().
Browse files Browse the repository at this point in the history
This function is really of marginal utility.  This commit drops it and
makes the existing callers instead open a new pstream with the desired
dscp.

The ulterior motive here is that the set_dscp() function that actually sets
the DSCP on a socket really wants to know the address family (AF_INET vs.
AF_INET6).  We could plumb that down through the stream code, and that's
one reasonable option, but I thought that simply eliminating some calls
to set_dscp() where we don't already have the address family handy was
another reasonable way to go.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Alex Wang <[email protected]>
  • Loading branch information
blp committed Feb 20, 2015
1 parent ee5315b commit c2e3cba
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 85 deletions.
18 changes: 3 additions & 15 deletions lib/jsonrpc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1134,21 +1134,9 @@ jsonrpc_session_set_dscp(struct jsonrpc_session *s,
uint8_t dscp)
{
if (s->dscp != dscp) {
if (s->pstream) {
int error;
pstream_close(s->pstream);
s->pstream = NULL;

error = pstream_set_dscp(s->pstream, dscp);
if (error) {
VLOG_ERR("%s: failed set_dscp %s",
reconnect_get_name(s->reconnect),
ovs_strerror(error));
}
/*
* XXX race window between setting dscp to listening socket
* and accepting socket. accepted socket may have old dscp value.
* Ignore this race window for now.
*/
}
s->dscp = dscp;
jsonrpc_session_force_reconnect(s);
}
Expand Down
14 changes: 0 additions & 14 deletions lib/stream-fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ struct fd_pstream
int fd;
int (*accept_cb)(int fd, const struct sockaddr_storage *, size_t ss_len,
struct stream **);
int (*set_dscp_cb)(int fd, uint8_t dscp);
char *unlink_path;
};

Expand Down Expand Up @@ -212,14 +211,12 @@ int
new_fd_pstream(const char *name, int fd,
int (*accept_cb)(int fd, const struct sockaddr_storage *ss,
size_t ss_len, struct stream **streamp),
int (*set_dscp_cb)(int fd, uint8_t dscp),
char *unlink_path, struct pstream **pstreamp)
{
struct fd_pstream *ps = xmalloc(sizeof *ps);
pstream_init(&ps->pstream, &fd_pstream_class, name);
ps->fd = fd;
ps->accept_cb = accept_cb;
ps->set_dscp_cb = set_dscp_cb;
ps->unlink_path = unlink_path;
*pstreamp = &ps->pstream;
return 0;
Expand Down Expand Up @@ -273,24 +270,13 @@ pfd_wait(struct pstream *pstream)
poll_fd_wait(ps->fd, POLLIN);
}

static int
pfd_set_dscp(struct pstream *pstream, uint8_t dscp)
{
struct fd_pstream *ps = fd_pstream_cast(pstream);
if (ps->set_dscp_cb) {
return ps->set_dscp_cb(ps->fd, dscp);
}
return 0;
}

static const struct pstream_class fd_pstream_class = {
"pstream",
false,
NULL,
pfd_close,
pfd_accept,
pfd_wait,
pfd_set_dscp,
};

/* Helper functions. */
Expand Down
3 changes: 1 addition & 2 deletions lib/stream-fd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2012, 2014 Nicira, Inc.
* Copyright (c) 2008, 2009, 2012, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +33,6 @@ int new_fd_stream(const char *name, int fd, int connect_status,
int new_fd_pstream(const char *name, int fd,
int (*accept_cb)(int fd, const struct sockaddr_storage *ss,
size_t ss_len, struct stream **),
int (*set_dscp_cb)(int fd, uint8_t dscp),
char *unlink_path,
struct pstream **pstreamp);

Expand Down
5 changes: 1 addition & 4 deletions lib/stream-provider.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2010, 2012, 2013 Nicira, Inc.
* Copyright (c) 2009, 2010, 2012, 2013, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -183,9 +183,6 @@ struct pstream_class {
/* Arranges for the poll loop to wake up when a connection is ready to be
* accepted on 'pstream'. */
void (*wait)(struct pstream *pstream);

/* Set DSCP value of the listening socket. */
int (*set_dscp)(struct pstream *pstream, uint8_t dscp);
};

/* Active and passive stream classes. */
Expand Down
10 changes: 1 addition & 9 deletions lib/stream-ssl.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -871,21 +871,13 @@ pssl_wait(struct pstream *pstream)
poll_fd_wait(pssl->fd, POLLIN);
}

static int
pssl_set_dscp(struct pstream *pstream, uint8_t dscp)
{
struct pssl_pstream *pssl = pssl_pstream_cast(pstream);
return set_dscp(pssl->fd, dscp);
}

const struct pstream_class pssl_pstream_class = {
"pssl",
true,
pssl_open,
pssl_close,
pssl_accept,
pssl_wait,
pssl_set_dscp,
};

/*
Expand Down
6 changes: 2 additions & 4 deletions lib/stream-tcp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2012, 2013, 2014 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2012, 2013, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -161,8 +161,7 @@ new_pstream(char *suffix, const char *name, struct pstream **pstreamp,
conn_name = bound_name;
}

error = new_fd_pstream(conn_name, fd, ptcp_accept, set_dscp, unlink_path,
pstreamp);
error = new_fd_pstream(conn_name, fd, ptcp_accept, unlink_path, pstreamp);
if (!error) {
pstream_set_bound_port(*pstreamp, htons(port));
}
Expand Down Expand Up @@ -196,7 +195,6 @@ const struct pstream_class ptcp_pstream_class = {
NULL,
NULL,
NULL,
NULL,
};

#ifdef _WIN32
Expand Down
5 changes: 2 additions & 3 deletions lib/stream-unix.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -102,7 +102,7 @@ punix_open(const char *name OVS_UNUSED, char *suffix,
return error;
}

return new_fd_pstream(name, fd, punix_accept, NULL, bind_path, pstreamp);
return new_fd_pstream(name, fd, punix_accept, bind_path, pstreamp);
}

static int
Expand All @@ -128,6 +128,5 @@ const struct pstream_class punix_pstream_class = {
NULL,
NULL,
NULL,
NULL,
};

11 changes: 1 addition & 10 deletions lib/stream.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -592,15 +592,6 @@ pstream_wait(struct pstream *pstream)
(pstream->class->wait)(pstream);
}

int
pstream_set_dscp(struct pstream *pstream, uint8_t dscp)
{
if (pstream->class->set_dscp) {
return pstream->class->set_dscp(pstream, dscp);
}
return 0;
}

/* Returns the transport port on which 'pstream' is listening, or 0 if the
* concept doesn't apply. */
ovs_be16
Expand Down
3 changes: 1 addition & 2 deletions lib/stream.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2010, 2011, 2013 Nicira, Inc.
* Copyright (c) 2009, 2010, 2011, 2013, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,7 +66,6 @@ void pstream_close(struct pstream *);
int pstream_accept(struct pstream *, struct stream **);
int pstream_accept_block(struct pstream *, struct stream **);
void pstream_wait(struct pstream *);
int pstream_set_dscp(struct pstream *, uint8_t dscp);

ovs_be16 pstream_get_bound_port(const struct pstream *);

Expand Down
35 changes: 13 additions & 22 deletions ovsdb/jsonrpc-server.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
/* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -198,10 +198,16 @@ ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *svr,
struct shash_node *node, *next;

SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) {
if (!shash_find(new_remotes, node->name)) {
struct ovsdb_jsonrpc_remote *remote = node->data;
struct ovsdb_jsonrpc_options *options
= shash_find_data(new_remotes, node->name);

if (!options) {
VLOG_INFO("%s: remote deconfigured", node->name);
ovsdb_jsonrpc_server_del_remote(node);
}
} else if (options->dscp != remote->dscp) {
ovsdb_jsonrpc_server_del_remote(node);
}
}
SHASH_FOR_EACH (node, new_remotes) {
const struct ovsdb_jsonrpc_options *options = node->data;
Expand Down Expand Up @@ -384,8 +390,6 @@ static int ovsdb_jsonrpc_session_run(struct ovsdb_jsonrpc_session *);
static void ovsdb_jsonrpc_session_wait(struct ovsdb_jsonrpc_session *);
static void ovsdb_jsonrpc_session_get_memory_usage(
const struct ovsdb_jsonrpc_session *, struct simap *usage);
static void ovsdb_jsonrpc_session_set_options(
struct ovsdb_jsonrpc_session *, const struct ovsdb_jsonrpc_options *);
static void ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *,
struct jsonrpc_msg *);
static void ovsdb_jsonrpc_session_got_notify(struct ovsdb_jsonrpc_session *,
Expand Down Expand Up @@ -556,30 +560,17 @@ ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *remote)
}

/* Sets the options for all of the JSON-RPC sessions managed by 'remote' to
* 'options'. */
* 'options'.
*
* (The dscp value can't be changed directly; the caller must instead close and
* re-open the session.) */
static void
ovsdb_jsonrpc_session_set_all_options(
struct ovsdb_jsonrpc_remote *remote,
const struct ovsdb_jsonrpc_options *options)
{
struct ovsdb_jsonrpc_session *s;

if (remote->listener) {
int error;

error = pstream_set_dscp(remote->listener, options->dscp);
if (error) {
VLOG_ERR("%s: set_dscp failed %s",
pstream_get_name(remote->listener), ovs_strerror(error));
} else {
remote->dscp = options->dscp;
}
/*
* XXX race window between setting dscp to listening socket
* and accepting socket. Accepted socket may have old dscp value.
* Ignore this race window for now.
*/
}
LIST_FOR_EACH (s, node, &remote->sessions) {
ovsdb_jsonrpc_session_set_options(s, options);
}
Expand Down

0 comments on commit c2e3cba

Please sign in to comment.