X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fworker.c;h=b6d268deb62e71a5316d53318869d03c3b678fae;hb=85b20fd6ee585f462e012fbcc7f966a81edab2ed;hp=f2b896e881f64b7ea8962b134a9ea62317dd874a;hpb=7a97619ae4484604c15b846ce7268094e048729a;p=sliver-openvswitch.git diff --git a/lib/worker.c b/lib/worker.c index f2b896e88..b6d268deb 100644 --- a/lib/worker.c +++ b/lib/worker.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2012 Nicira, Inc. +/* Copyright (c) 2012, 2013 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -198,6 +198,7 @@ worker_send_iovec(const struct iovec iovs[], size_t n_iovs, size_t sent = 0; for (;;) { + struct pollfd pfd; int error; /* Try to send the rest of the request. */ @@ -210,8 +211,21 @@ worker_send_iovec(const struct iovec iovs[], size_t n_iovs, /* Process replies to avoid deadlock. */ worker_run(); - poll_fd_wait(client_sock, POLLIN | POLLOUT); - poll_block(); + /* Wait for 'client_sock' to become ready before trying again. We + * can't use poll_block() because it sometimes calls into vlog, which + * calls indirectly into worker_send_iovec(). To be usable here, + * poll_block() would therefore need to be reentrant, but it isn't + * (calling it recursively causes memory corruption and an eventual + * crash). */ + pfd.fd = client_sock; + pfd.events = POLLIN | POLLOUT; + do { + error = poll(&pfd, 1, -1) < 0 ? errno : 0; + } while (error == EINTR); + if (error) { + worker_broke(); + VLOG_ABORT("poll failed (%s)", strerror(error)); + } } } @@ -223,11 +237,14 @@ worker_request_iovec(const struct iovec iovs[], size_t n_iovs, worker_request_func *request_cb, worker_reply_func *reply_cb, void *aux) { + static bool recursing = false; struct worker_request rq; struct iovec *all_iovs; int error; assert(worker_is_running()); + assert(!recursing); + recursing = true; rq.request_len = iovec_len(iovs, n_iovs); rq.request_cb = request_cb; @@ -241,6 +258,8 @@ worker_request_iovec(const struct iovec iovs[], size_t n_iovs, VLOG_ABORT("send failed (%s)", strerror(error)); } free(all_iovs); + + recursing = false; } /* Closes the client socket, if any, so that worker_is_running() will return @@ -428,8 +447,6 @@ rxbuf_run(struct rxbuf *rx, int sock, size_t header_len) } } } - - return EAGAIN; } static struct iovec *