From: Wei Liu Subject: Re: [PATCH] Switch to poll() in cxenstored's IO loop Date: Tue, 22 Jan 2013 14:13:19 +0000 Message-ID: <1358863999.1836.23.camel@zion.uk.xensource.com> References: <1358796212-24178-1-git-send-email-wei.liu2@citrix.com> <1358848038.3279.296.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1358848038.3279.296.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: wei.liu2@citrix.com, "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On Tue, 2013-01-22 at 09:47 +0000, Ian Campbell wrote: > On Mon, 2013-01-21 at 19:23 +0000, Wei Liu wrote: > > > - if (reopen_log_pipe[0] != -1 && FD_ISSET(reopen_log_pipe[0], &inset)) { > > + if (reopen_log_pipe[0] != -1 && reopen_log_pipe0_pollfd && > > Is it the case that reopen_log_pip0_pollfd != NULL iff > reopen_log_pipe[0] != -1 ? Would simplify things a bit? > Not really. Pollfd is valid iff set_fd() returns a valid pointer. set_fd() invokes realloc() which can fail. > > + !(reopen_log_pipe0_pollfd->revents & ~(POLLIN|POLLOUT|POLLPRI)) && > > This represents an error case I think? Is there anything we can do about > it? If this sort of error occurs and we do nothing will we end up just > spinning because every subsequent poll will just return straight away? > > Yes, this represents an error. This indicates the pipe used to trigger reopen_log is broken. What's the motivation of reopening log file? I have no idea about the use case. But simply ignoring this error instead of crashing the process is better choice IMHO. The whole pollfd set is reinitialized for every loop. So it is also possible that for the next loop it will success even previous poll fails? > > + (reopen_log_pipe0_pollfd->revents & POLLIN)) { > > You only handle POLLIN, not POLLOUT or POLLPRI -- so should they not be > part of the error case above? I don't think you ask for them other than > on the conn->poll_fd? > > (those three comments apply to the other instances of this pattern too) > [...] > > @@ -1939,21 +1981,27 @@ int main(int argc, char *argv[]) > > if (talloc_free(conn) == 0) > > continue; > > } else { > > - if (FD_ISSET(conn->fd, &inset)) > > + if (conn->pollfd && > > + !(conn->pollfd->revents & ~(POLLIN|POLLOUT|POLLPRI)) && > > + (conn->pollfd->revents & POLLIN)) > > handle_input(conn); > > if (talloc_free(conn) == 0) > > continue; > > Do you know what this construct is all about? Some sort of reference > count on conn? Anyway, I wonder if this means you will frequently miss > setting pollfd = NULL below? > > talloc_free can apparently only return non-zero if a destructor fails, > which suggests that more often than not you will not make it as far as > checking POLLOUT. > > This is all pre-existing though, so maybe it just works and there is > some magic I don't understand ;-) > The document of talloc_free() says that if the pointer is freed 0 is returned otherwise -1 is returned. So if conn is successfully freed, than there is no need to reset pollfd in conn to NULL. Wei.