Skip to content

Commit

Permalink
libknet: remove that horrid dst_cache update and mask it around link_…
Browse files Browse the repository at this point in the history
…enabled

makes the API a bit more readable.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Oct 14, 2012
1 parent 0ce277e commit 4adc09f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
7 changes: 3 additions & 4 deletions kronosnetd/vty_cli_cmds.c
Expand Up @@ -717,8 +717,7 @@ static int knet_cmd_no_link(struct knet_vty *vty)
return -1;
}

host->link[j].configured = 0;
if (knet_host_dst_cache_update(knet_iface->cfg_ring.knet_h, host->node_id))
if (knet_link_enable(knet_iface->cfg_ring.knet_h, host->node_id, &host->link[j], 0))
knet_vty_write(vty, "Error: unable to update switching cache%s", telnet_newline);

return 0;
Expand Down Expand Up @@ -769,7 +768,7 @@ static int knet_cmd_link(struct knet_vty *vty)

knet_link_timeout(klink, 1000, 5000, 2048);

klink->configured = 1;
knet_link_enable(knet_iface->cfg_ring.knet_h, host->node_id, klink, 1);
}

vty->link = (void *)klink;
Expand Down Expand Up @@ -1273,7 +1272,7 @@ static int knet_cmd_no_interface(struct knet_vty *vty)
}

for (i = 0; i < KNET_MAX_LINK; i++)
host->link[i].configured = 0;
knet_link_enable(knet_iface->cfg_ring.knet_h, host->node_id, &host->link[i], 0);

knet_listener_remove(knet_iface->cfg_ring.knet_h, host->listener);

Expand Down
24 changes: 24 additions & 0 deletions libknet/handle.c
Expand Up @@ -230,6 +230,30 @@ int knet_handle_crypto(knet_handle_t knet_h, struct knet_handle_crypto_cfg *knet
return crypto_init(knet_h, knet_handle_crypto_cfg);
}

int knet_link_enable(knet_handle_t knet_h, uint16_t node_id, struct knet_link *lnk, int configured)
{
int write_retry = 0;

if (lnk->configured == configured)
return 0;

lnk->configured = configured;

if (configured)
return 0;

try_again:
if (write(knet_h->pipefd[1], &node_id, sizeof(node_id)) != sizeof(node_id)) {
if ((write_retry < 10) && ((errno = EAGAIN) || (errno = EWOULDBLOCK))) {
write_retry++;
goto try_again;
} else {
return -1;
}
}
return 0;
}

void knet_link_timeout(struct knet_link *lnk,
time_t interval, time_t timeout, int precision)
{
Expand Down
16 changes: 0 additions & 16 deletions libknet/host.c
Expand Up @@ -153,22 +153,6 @@ int knet_host_remove(knet_handle_t knet_h, uint16_t node_id)
return ret;
}

int knet_host_dst_cache_update(knet_handle_t knet_h, uint16_t node_id)
{
int write_retry = 0;

try_again:
if (write(knet_h->pipefd[1], &node_id, sizeof(node_id)) != sizeof(node_id)) {
if ((write_retry < 10) && ((errno = EAGAIN) || (errno = EWOULDBLOCK))) {
write_retry++;
goto try_again;
} else {
return -1;
}
}
return 0;
}

/* bcast = 0 -> unicast packet | 1 -> broadcast|mcast */

/* make this bcast/ucast aware */
Expand Down
2 changes: 1 addition & 1 deletion libknet/libknet.h
Expand Up @@ -152,8 +152,8 @@ int knet_host_acquire(knet_handle_t knet_h, struct knet_host **host);
int knet_host_get(knet_handle_t knet_h, uint16_t node_id, struct knet_host **host);
int knet_host_release(knet_handle_t knet_h, struct knet_host **host);
int knet_host_remove(knet_handle_t knet_h, uint16_t node_id);
int knet_host_dst_cache_update(knet_handle_t knet_h, uint16_t node_id);

int knet_link_enable(knet_handle_t knet_h, uint16_t node_id, struct knet_link *lnk, int configured);
void knet_link_timeout(struct knet_link *lnk, time_t interval, time_t timeout, int precision);

#define KNET_HOST_FOREACH_NEXT 0 /* next host */
Expand Down
2 changes: 1 addition & 1 deletion tests/listener_test.c
Expand Up @@ -50,7 +50,7 @@ static void test_add_host(void)
knet_host_get(knet_h, 1, &host);

host->link[0].sock = listener->sock;
host->link[0].configured = 1;
knet_link_enable(knet_h, host->node_id, &host->link[0], 1);

knet_host_release(knet_h, &host);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ping_test.c
Expand Up @@ -129,7 +129,7 @@ static void argv_to_hosts(int argc, char *argv[])

knet_link_timeout(&host->link[0], 1000, 5000, 2048);

host->link[0].configured = 1;
knet_link_enable(knet_h, host->node_id, &host->link[0], 1);

err = tok_inaddrport(argv[i],
(struct sockaddr_in *) &host->link[0].address);
Expand Down

0 comments on commit 4adc09f

Please sign in to comment.