Fix disconnection detection
parent
49f8011917
commit
f2e9749c93
6
Makefile
6
Makefile
|
@ -1,5 +1,5 @@
|
||||||
BLOCKSTORE_OBJS := allocator.o blockstore.o blockstore_init.o blockstore_open.o blockstore_journal.o blockstore_read.o \
|
BLOCKSTORE_OBJS := allocator.o blockstore.o blockstore_init.o blockstore_open.o blockstore_journal.o blockstore_read.o \
|
||||||
blockstore_write.o blockstore_sync.o blockstore_stable.o blockstore_flush.o crc32c.o ringloop.o timerfd_interval.o osd.o
|
blockstore_write.o blockstore_sync.o blockstore_stable.o blockstore_flush.o crc32c.o ringloop.o timerfd_interval.o
|
||||||
CXXFLAGS := -g -O3 -Wall -Wno-sign-compare -Wno-comment -Wno-parentheses -Wno-pointer-arith -fPIC -fdiagnostics-color=always
|
CXXFLAGS := -g -O3 -Wall -Wno-sign-compare -Wno-comment -Wno-parentheses -Wno-pointer-arith -fPIC -fdiagnostics-color=always
|
||||||
all: $(BLOCKSTORE_OBJS) test test_blockstore libfio_blockstore.so osd
|
all: $(BLOCKSTORE_OBJS) test test_blockstore libfio_blockstore.so osd
|
||||||
clean:
|
clean:
|
||||||
|
@ -8,8 +8,8 @@ crc32c.o: crc32c.c
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
%.o: %.cpp allocator.h blockstore_flush.h blockstore.h blockstore_init.h blockstore_journal.h crc32c.h ringloop.h xor.h timerfd_interval.h
|
%.o: %.cpp allocator.h blockstore_flush.h blockstore.h blockstore_init.h blockstore_journal.h crc32c.h ringloop.h xor.h timerfd_interval.h
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
osd: $(BLOCKSTORE_OBJS) osd_main.cpp osd.h osd_ops.h
|
osd: $(BLOCKSTORE_OBJS) osd_main.cpp osd.h osd_ops.h osd.o
|
||||||
g++ $(CXXFLAGS) -ltcmalloc_minimal -luring -o osd osd_main.cpp $(BLOCKSTORE_OBJS)
|
g++ $(CXXFLAGS) -ltcmalloc_minimal -luring -o osd osd_main.cpp osd.o $(BLOCKSTORE_OBJS)
|
||||||
test: test.cpp
|
test: test.cpp
|
||||||
g++ $(CXXFLAGS) -o test -luring test.cpp
|
g++ $(CXXFLAGS) -o test -luring test.cpp
|
||||||
test_blockstore: $(BLOCKSTORE_OBJS) test_blockstore.cpp
|
test_blockstore: $(BLOCKSTORE_OBJS) test_blockstore.cpp
|
||||||
|
|
12
osd.cpp
12
osd.cpp
|
@ -83,6 +83,11 @@ osd_t::~osd_t()
|
||||||
close(listen_fd);
|
close(listen_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool osd_t::shutdown()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
void osd_t::loop()
|
void osd_t::loop()
|
||||||
{
|
{
|
||||||
if (wait_state == 0)
|
if (wait_state == 0)
|
||||||
|
@ -132,6 +137,8 @@ int osd_t::handle_epoll_events()
|
||||||
int peer_fd;
|
int peer_fd;
|
||||||
while ((peer_fd = accept(listen_fd, (sockaddr*)&addr, &peer_addr_size)) >= 0)
|
while ((peer_fd = accept(listen_fd, (sockaddr*)&addr, &peer_addr_size)) >= 0)
|
||||||
{
|
{
|
||||||
|
char peer_str[256];
|
||||||
|
printf("osd: new client %d: connection from %s port %d\n", peer_fd, inet_ntop(AF_INET, &addr.sin_addr, peer_str, 256), ntohs(addr.sin_port));
|
||||||
fcntl(peer_fd, F_SETFL, fcntl(listen_fd, F_GETFL, 0) | O_NONBLOCK);
|
fcntl(peer_fd, F_SETFL, fcntl(listen_fd, F_GETFL, 0) | O_NONBLOCK);
|
||||||
clients[peer_fd] = {
|
clients[peer_fd] = {
|
||||||
.peer_addr = addr,
|
.peer_addr = addr,
|
||||||
|
@ -141,7 +148,7 @@ int osd_t::handle_epoll_events()
|
||||||
// Add FD to epoll
|
// Add FD to epoll
|
||||||
epoll_event ev;
|
epoll_event ev;
|
||||||
ev.data.fd = peer_fd;
|
ev.data.fd = peer_fd;
|
||||||
ev.events = EPOLLIN | EPOLLHUP;
|
ev.events = EPOLLIN | EPOLLRDHUP;
|
||||||
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peer_fd, &ev) < 0)
|
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peer_fd, &ev) < 0)
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string("epoll_ctl: ") + strerror(errno));
|
throw std::runtime_error(std::string("epoll_ctl: ") + strerror(errno));
|
||||||
|
@ -157,9 +164,10 @@ int osd_t::handle_epoll_events()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto & cl = clients[events[i].data.fd];
|
auto & cl = clients[events[i].data.fd];
|
||||||
if (events[i].events & EPOLLHUP)
|
if (events[i].events & EPOLLRDHUP)
|
||||||
{
|
{
|
||||||
// Stop client
|
// Stop client
|
||||||
|
printf("osd: client %d disconnected\n", cl.peer_fd);
|
||||||
stop_client(cl.peer_fd);
|
stop_client(cl.peer_fd);
|
||||||
}
|
}
|
||||||
else if (!cl.read_ready)
|
else if (!cl.read_ready)
|
||||||
|
|
6
osd.h
6
osd.h
|
@ -63,6 +63,8 @@ class osd_t
|
||||||
{
|
{
|
||||||
// config
|
// config
|
||||||
|
|
||||||
|
std::string bind_address;
|
||||||
|
int bind_port, listen_backlog;
|
||||||
int client_queue_depth = 128;
|
int client_queue_depth = 128;
|
||||||
|
|
||||||
// fields
|
// fields
|
||||||
|
@ -75,9 +77,6 @@ class osd_t
|
||||||
int listen_fd = 0;
|
int listen_fd = 0;
|
||||||
ring_consumer_t consumer;
|
ring_consumer_t consumer;
|
||||||
|
|
||||||
std::string bind_address;
|
|
||||||
int bind_port, listen_backlog;
|
|
||||||
|
|
||||||
std::unordered_map<int,osd_client_t> clients;
|
std::unordered_map<int,osd_client_t> clients;
|
||||||
std::vector<int> read_ready_clients;
|
std::vector<int> read_ready_clients;
|
||||||
std::vector<int> write_ready_clients;
|
std::vector<int> write_ready_clients;
|
||||||
|
@ -94,4 +93,5 @@ class osd_t
|
||||||
public:
|
public:
|
||||||
osd_t(blockstore_config_t & config, blockstore *bs, ring_loop_t *ringloop);
|
osd_t(blockstore_config_t & config, blockstore *bs, ring_loop_t *ringloop);
|
||||||
~osd_t();
|
~osd_t();
|
||||||
|
bool shutdown();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue