From: Rafael Lopez Date: Thu, 4 Aug 2022 07:14:44 +0000 (+0000) Subject: msg: tidied up formatting for new poll driver X-Git-Tag: v18.1.0~874^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=3b212c066b66166da85a63fc56a2ed50f6f59417;p=ceph-ci.git msg: tidied up formatting for new poll driver Signed-off-by: Rafael Lopez --- diff --git a/src/msg/async/EventPoll.cc b/src/msg/async/EventPoll.cc index d3b3c22482c..dac5e18d403 100644 --- a/src/msg/async/EventPoll.cc +++ b/src/msg/async/EventPoll.cc @@ -1,5 +1,5 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab +// vim: ts=8 sw=2 smarttab ft=cpp /* * Ceph - scalable distributed file system * @@ -9,7 +9,7 @@ * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. + * Foundation. See file COPYING. * */ @@ -32,8 +32,7 @@ #endif #endif -int PollDriver::init(EventCenter *c, int nevent) -{ +int PollDriver::init(EventCenter *c, int nevent) { // pfds array will auto scale up to hard_max_pfds, which should be // greater than total daemons/op_threads (todo: cfg option?) hard_max_pfds = 8192; @@ -58,34 +57,33 @@ int PollDriver::init(EventCenter *c, int nevent) // Helper func to register/unregister interest in a FD's events by // manipulating it's entry in pfds array -int PollDriver::poll_ctl(int fd, int op, int events) -{ +int PollDriver::poll_ctl(int fd, int op, int events) { int pos = 0; if (op == POLL_ADD) { // Find an empty pollfd slot for(pos = 0; pos < max_pfds ; pos++){ if(pfds[pos].fd == -1){ - pfds[pos].fd = fd; - pfds[pos].events = events; - pfds[pos].revents = 0; - return 0; + pfds[pos].fd = fd; + pfds[pos].events = events; + pfds[pos].revents = 0; + return 0; } } // We ran out of slots, try to increase if (max_pfds < hard_max_pfds) { - ldout(cct, 10) << __func__ << " exhausted pollfd structure slots" - << ", doubling to " << max_pfds*2 << dendl; + ldout(cct, 10) << __func__ << " exhausted pollfd slots" + << ", doubling to " << max_pfds*2 << dendl; pfds = (POLLFD*)realloc(pfds, max_pfds*2*sizeof(POLLFD)); if (!pfds) { - lderr(cct) << __func__ << " unable to realloc for more pollfd structures" - << dendl; - return -ENOMEM; + lderr(cct) << __func__ << " unable to realloc for more pollfd slots" + << dendl; + return -ENOMEM; } // Initialise new slots for (int i = max_pfds ; i < max_pfds*2 ; i++){ - pfds[i].fd = -1; - pfds[i].events = 0; - pfds[i].revents = 0; + pfds[i].fd = -1; + pfds[i].events = 0; + pfds[i].revents = 0; } max_pfds = max_pfds*2; pfds[pos].fd = fd; @@ -95,57 +93,59 @@ int PollDriver::poll_ctl(int fd, int op, int events) } else { // Hit hard limit lderr(cct) << __func__ << " hard limit for file descriptors per op" - << " thread reached (" << hard_max_pfds << ")" << dendl; + << " thread reached (" << hard_max_pfds << ")" << dendl; return -EMFILE; } } else if (op == POLL_MOD) { for (pos = 0; pos < max_pfds; pos++ ){ if (pfds[pos].fd == fd) { - pfds[pos].events = events; - return 0; + pfds[pos].events = events; + return 0; } } } else if (op == POLL_DEL) { for (pos = 0; pos < max_pfds; pos++ ){ if (pfds[pos].fd == fd) { - pfds[pos].fd = -1; - pfds[pos].events = 0; - return 0; + pfds[pos].fd = -1; + pfds[pos].events = 0; + return 0; } } } return 0; } -int PollDriver::add_event(int fd, int cur_mask, int add_mask) -{ - ldout(cct, 10) << __func__ << " add event to fd=" << fd << " mask=" << add_mask - << dendl; +int PollDriver::add_event(int fd, int cur_mask, int add_mask) { + ldout(cct, 10) << __func__ << " add event to fd=" << fd << " mask=" + << add_mask << dendl; int op, events = 0; op = cur_mask == EVENT_NONE ? POLL_ADD: POLL_MOD; add_mask |= cur_mask; /* Merge old events */ - if (add_mask & EVENT_READABLE) + if (add_mask & EVENT_READABLE) { events |= POLLIN; - if (add_mask & EVENT_WRITABLE) + } + if (add_mask & EVENT_WRITABLE) { events |= POLLOUT; + } int ret = poll_ctl(fd, op, events); return ret; } -int PollDriver::del_event(int fd, int cur_mask, int delmask) -{ - ldout(cct, 10) << __func__ << " del event fd=" << fd << " cur mask=" << cur_mask - << dendl; +int PollDriver::del_event(int fd, int cur_mask, int delmask) { + ldout(cct, 10) << __func__ << " del event fd=" << fd << " cur mask=" + << cur_mask << dendl; int op, events = 0; int mask = cur_mask & (~delmask); if (mask != EVENT_NONE) { op = POLL_MOD; - if (mask & EVENT_READABLE) + if (mask & EVENT_READABLE) { events |= POLLIN; - if (mask & EVENT_WRITABLE) + } + if (mask & EVENT_WRITABLE) { events |= POLLOUT; + } } else { op = POLL_DEL; } @@ -153,36 +153,37 @@ int PollDriver::del_event(int fd, int cur_mask, int delmask) return 0; } -int PollDriver::resize_events(int newsize) -{ +int PollDriver::resize_events(int newsize) { return 0; } -int PollDriver::event_wait(std::vector &fired_events, struct timeval *tvp) -{ +int PollDriver::event_wait(std::vector &fired_events, + struct timeval *tvp) { int retval, numevents = 0; #ifdef _WIN32 retval = WSAPoll(pfds, max_pfds, - tvp ? (tvp->tv_sec*1000 + tvp->tv_usec/1000) : -1); + tvp ? (tvp->tv_sec*1000 + tvp->tv_usec/1000) : -1); #else retval = poll(pfds, max_pfds, - tvp ? (tvp->tv_sec*1000 + tvp->tv_usec/1000) : -1); + tvp ? (tvp->tv_sec*1000 + tvp->tv_usec/1000) : -1); #endif if (retval > 0) { for (int j = 0; j < max_pfds; j++) { if (pfds[j].fd != -1) { - int mask = 0; - struct FiredFileEvent fe; - if (pfds[j].revents & POLLIN) - mask |= EVENT_READABLE; - if (pfds[j].revents & POLLOUT) - mask |= EVENT_WRITABLE; - if (mask) { - fe.fd = pfds[j].fd; - fe.mask = mask; - fired_events.push_back(fe); - numevents++; - } + int mask = 0; + struct FiredFileEvent fe; + if (pfds[j].revents & POLLIN) { + mask |= EVENT_READABLE; + } + if (pfds[j].revents & POLLOUT) { + mask |= EVENT_WRITABLE; + } + if (mask) { + fe.fd = pfds[j].fd; + fe.mask = mask; + fired_events.push_back(fe); + numevents++; + } } } } diff --git a/src/msg/async/EventPoll.h b/src/msg/async/EventPoll.h index 866990c8517..772d46a3e79 100644 --- a/src/msg/async/EventPoll.h +++ b/src/msg/async/EventPoll.h @@ -16,13 +16,14 @@ #ifndef CEPH_MSG_EVENTPOLL_H #define CEPH_MSG_EVENTPOLL_H -#include "Event.h" #ifdef _WIN32 #include #else #include #endif +#include "Event.h" + typedef struct pollfd POLLFD; class PollDriver : public EventDriver {