You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-12-17 01:02:23 +03:00
add SMLogging.
This commit is contained in:
3
CMakeLists.txt
Normal file → Executable file
3
CMakeLists.txt
Normal file → Executable file
@@ -25,9 +25,10 @@ set(storagemanager_SRCS
|
|||||||
src/S3Storage.cpp
|
src/S3Storage.cpp
|
||||||
src/LocalStorage.cpp
|
src/LocalStorage.cpp
|
||||||
src/Cache.cpp
|
src/Cache.cpp
|
||||||
|
src/SMLogging.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
option(TRACE "Enable some tracing output" OFF)
|
option(TRACE "Enable some tracing output" ON)
|
||||||
if (TRACE)
|
if (TRACE)
|
||||||
add_definitions(-DSM_TRACE)
|
add_definitions(-DSM_TRACE)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include "AppendTask.h"
|
#include "AppendTask.h"
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -27,6 +28,7 @@ AppendTask::~AppendTask()
|
|||||||
|
|
||||||
bool AppendTask::run()
|
bool AppendTask::run()
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
bool success;
|
bool success;
|
||||||
uint8_t cmdbuf[1024] = {0};
|
uint8_t cmdbuf[1024] = {0};
|
||||||
int err;
|
int err;
|
||||||
@@ -44,7 +46,7 @@ bool AppendTask::run()
|
|||||||
check_error("AppendTask read", false);
|
check_error("AppendTask read", false);
|
||||||
|
|
||||||
#ifdef SM_TRACE
|
#ifdef SM_TRACE
|
||||||
syslog(LOG_DEBUG, "append %d bytes to %s.",cmd->count,cmd->filename);
|
logger->log(LOG_DEBUG,"append %d bytes to %s.",cmd->count,cmd->filename);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t readCount = 0, writeCount = 0;
|
size_t readCount = 0, writeCount = 0;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "S3Storage.h"
|
#include "S3Storage.h"
|
||||||
#include "LocalStorage.h"
|
#include "LocalStorage.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
#include <boost/thread/mutex.hpp>
|
#include <boost/thread/mutex.hpp>
|
||||||
#include <syslog.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ namespace storagemanager
|
|||||||
{
|
{
|
||||||
CloudStorage * CloudStorage::get()
|
CloudStorage * CloudStorage::get()
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
if (inst)
|
if (inst)
|
||||||
return inst;
|
return inst;
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ CloudStorage * CloudStorage::get()
|
|||||||
else if (type == "local")
|
else if (type == "local")
|
||||||
inst = new LocalStorage();
|
inst = new LocalStorage();
|
||||||
else {
|
else {
|
||||||
syslog(LOG_CRIT, "CloudStorage: got unknown service provider: %s", type.c_str());
|
logger->log(LOG_CRIT,"CloudStorage: got unknown service provider: %s", type.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
#include "CopyTask.h"
|
#include "CopyTask.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "syslog.h"
|
#include "SMLogging.h"
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -27,6 +27,8 @@ CopyTask::~CopyTask()
|
|||||||
bool CopyTask::run()
|
bool CopyTask::run()
|
||||||
{
|
{
|
||||||
bool success;
|
bool success;
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
|
|
||||||
uint8_t buf[2048] = {0};
|
uint8_t buf[2048] = {0};
|
||||||
|
|
||||||
if (getLength() > 2047)
|
if (getLength() > 2047)
|
||||||
@@ -42,7 +44,7 @@ bool CopyTask::run()
|
|||||||
f_name *filename2 = (f_name *) &buf[sizeof(copy_cmd) + cmd->file1.flen];
|
f_name *filename2 = (f_name *) &buf[sizeof(copy_cmd) + cmd->file1.flen];
|
||||||
|
|
||||||
#ifdef SM_TRACE
|
#ifdef SM_TRACE
|
||||||
syslog(LOG_DEBUG, "copy %s to %s.",filename1,filename2);
|
logger->log(LOG_DEBUG,"copy %s to %s.",filename1.c_str(),filename2->filename);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int err = ioc->copyFile(filename1.c_str(), filename2->filename);
|
int err = ioc->copyFile(filename1.c_str(), filename2->filename);
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
#include "IOCoordinator.h"
|
#include "IOCoordinator.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <syslog.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -191,6 +190,7 @@ int IOCoordinator::unlink(const char *path)
|
|||||||
|
|
||||||
int IOCoordinator::copyFile(const char *filename1, const char *filename2)
|
int IOCoordinator::copyFile(const char *filename1, const char *filename2)
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
int err = 0, l_errno;
|
int err = 0, l_errno;
|
||||||
try {
|
try {
|
||||||
boost::filesystem::copy_file(filename1, filename2);
|
boost::filesystem::copy_file(filename1, filename2);
|
||||||
@@ -200,7 +200,7 @@ int IOCoordinator::copyFile(const char *filename1, const char *filename2)
|
|||||||
l_errno = e.code().value(); // why not.
|
l_errno = e.code().value(); // why not.
|
||||||
// eh, not going to translate all of boost's errors into our errors for this.
|
// eh, not going to translate all of boost's errors into our errors for this.
|
||||||
// log the error
|
// log the error
|
||||||
syslog(LOG_ERR, "IOCoordinator::copy(): got %s",e.what());
|
logger->log(LOG_ERR,"IOCoordinator::copy(): got %s",e.what());
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
err = -1;
|
err = -1;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#include "ListDirectoryTask.h"
|
#include "ListDirectoryTask.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -57,6 +58,7 @@ bool ListDirectoryTask::writeString(uint8_t *buf, int *offset, int size, const s
|
|||||||
|
|
||||||
bool ListDirectoryTask::run()
|
bool ListDirectoryTask::run()
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
bool success;
|
bool success;
|
||||||
uint8_t buf[1024] = {0};
|
uint8_t buf[1024] = {0};
|
||||||
int err;
|
int err;
|
||||||
@@ -71,7 +73,7 @@ bool ListDirectoryTask::run()
|
|||||||
listdir_cmd *cmd = (listdir_cmd *) buf;
|
listdir_cmd *cmd = (listdir_cmd *) buf;
|
||||||
|
|
||||||
#ifdef SM_TRACE
|
#ifdef SM_TRACE
|
||||||
syslog(LOG_DEBUG, "list_directory %s.",cmd->path);
|
logger->log(LOG_DEBUG,"list_directory %s.",cmd->path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vector<string> listing;
|
vector<string> listing;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "OpenTask.h"
|
#include "OpenTask.h"
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -26,6 +27,7 @@ bool OpenTask::run()
|
|||||||
call IOManager to do the work
|
call IOManager to do the work
|
||||||
return the result
|
return the result
|
||||||
*/
|
*/
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
bool success;
|
bool success;
|
||||||
uint8_t buf[1024] = {0};
|
uint8_t buf[1024] = {0};
|
||||||
|
|
||||||
@@ -45,7 +47,7 @@ bool OpenTask::run()
|
|||||||
open_cmd *cmd = (open_cmd *) buf;
|
open_cmd *cmd = (open_cmd *) buf;
|
||||||
|
|
||||||
#ifdef SM_TRACE
|
#ifdef SM_TRACE
|
||||||
syslog(LOG_DEBUG, "open filename %s mode %o.",cmd->filename,cmd->openmode);
|
logger->log(LOG_DEBUG,"open filename %s mode %o.",cmd->filename,cmd->openmode);
|
||||||
#endif
|
#endif
|
||||||
sm_response *resp = (sm_response *) buf;
|
sm_response *resp = (sm_response *) buf;
|
||||||
int err = ioc->open(cmd->filename, cmd->openmode, (struct stat *) &resp->payload);
|
int err = ioc->open(cmd->filename, cmd->openmode, (struct stat *) &resp->payload);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
#include "PosixTask.h"
|
#include "PosixTask.h"
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <syslog.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define min(x, y) (x < y ? x : y)
|
#define min(x, y) (x < y ? x : y)
|
||||||
@@ -34,6 +34,7 @@ PosixTask::~PosixTask()
|
|||||||
|
|
||||||
void PosixTask::handleError(const char *name, int errCode)
|
void PosixTask::handleError(const char *name, int errCode)
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
char buf[sizeof(sm_response) + 4];
|
char buf[sizeof(sm_response) + 4];
|
||||||
|
|
||||||
// send an error response if possible
|
// send an error response if possible
|
||||||
@@ -43,7 +44,7 @@ void PosixTask::handleError(const char *name, int errCode)
|
|||||||
write(*resp, 4);
|
write(*resp, 4);
|
||||||
|
|
||||||
// TODO: construct and log a message
|
// TODO: construct and log a message
|
||||||
syslog(LOG_ERR, "%s caught an error: %s.",name,strerror_r(errCode, buf, 80));
|
logger->log(LOG_ERR,"%s caught an error: %s.",name,strerror_r(errCode, buf, 80));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint PosixTask::getRemainingLength()
|
uint PosixTask::getRemainingLength()
|
||||||
@@ -178,6 +179,8 @@ bool PosixTask::write(const vector<uint8_t> &buf)
|
|||||||
|
|
||||||
void PosixTask::consumeMsg()
|
void PosixTask::consumeMsg()
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
|
|
||||||
uint8_t buf[1024];
|
uint8_t buf[1024];
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@@ -187,7 +190,7 @@ void PosixTask::consumeMsg()
|
|||||||
|
|
||||||
while (remainingLengthInStream > 0)
|
while (remainingLengthInStream > 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "ERROR: eating data.");
|
logger->log(LOG_ERR,"ERROR: eating data.");
|
||||||
err = ::recv(sock, buf, min(remainingLengthInStream, 1024), 0);
|
err = ::recv(sock, buf, min(remainingLengthInStream, 1024), 0);
|
||||||
if (err <= 0) {
|
if (err <= 0) {
|
||||||
remainingLengthInStream = 0;
|
remainingLengthInStream = 0;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <syslog.h>
|
|
||||||
#include <boost/scoped_ptr.hpp>
|
#include <boost/scoped_ptr.hpp>
|
||||||
|
|
||||||
#include "AppendTask.h"
|
#include "AppendTask.h"
|
||||||
@@ -18,6 +17,7 @@
|
|||||||
#include "UnlinkTask.h"
|
#include "UnlinkTask.h"
|
||||||
#include "WriteTask.h"
|
#include "WriteTask.h"
|
||||||
#include "SessionManager.h"
|
#include "SessionManager.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -37,10 +37,11 @@ ProcessTask::~ProcessTask()
|
|||||||
|
|
||||||
void ProcessTask::handleError(int saved_errno)
|
void ProcessTask::handleError(int saved_errno)
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
SessionManager::get()->socketError(sock);
|
SessionManager::get()->socketError(sock);
|
||||||
returnedSock = true;
|
returnedSock = true;
|
||||||
char buf[80];
|
char buf[80];
|
||||||
syslog(LOG_ERR, "ProcessTask: got an error during a socket read: %s.",strerror_r(saved_errno, buf, 80));
|
logger->log(LOG_ERR,"ProcessTask: got an error during a socket read: %s.",strerror_r(saved_errno, buf, 80));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessTask::operator()()
|
void ProcessTask::operator()()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include "ReadTask.h"
|
#include "ReadTask.h"
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -27,6 +28,7 @@ ReadTask::~ReadTask()
|
|||||||
|
|
||||||
bool ReadTask::run()
|
bool ReadTask::run()
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
uint8_t buf[1024] = {0};
|
uint8_t buf[1024] = {0};
|
||||||
|
|
||||||
// get the parameters
|
// get the parameters
|
||||||
@@ -41,7 +43,7 @@ bool ReadTask::run()
|
|||||||
read_cmd *cmd = (read_cmd *) buf;
|
read_cmd *cmd = (read_cmd *) buf;
|
||||||
|
|
||||||
#ifdef SM_TRACE
|
#ifdef SM_TRACE
|
||||||
syslog(LOG_DEBUG, "read %s count %i offset %i.",cmd->filename,cmd->count,cmd->offset);
|
logger->log(LOG_DEBUG,"read %s count %i offset %i.",cmd->filename,cmd->count,cmd->offset);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// read from IOC, write to the socket
|
// read from IOC, write to the socket
|
||||||
|
|||||||
51
src/SMLogging.cpp
Normal file
51
src/SMLogging.cpp
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "SMLogging.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
storagemanager::SMLogging *smLog = NULL;
|
||||||
|
boost::mutex m;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace storagemanager
|
||||||
|
{
|
||||||
|
|
||||||
|
SMLogging::SMLogging()
|
||||||
|
{
|
||||||
|
//TODO: make this configurable
|
||||||
|
setlogmask (LOG_UPTO (LOG_DEBUG));
|
||||||
|
openlog ("StorageManager", LOG_PID | LOG_NDELAY, LOG_LOCAL2);
|
||||||
|
}
|
||||||
|
|
||||||
|
SMLogging::~SMLogging()
|
||||||
|
{
|
||||||
|
syslog(LOG_INFO, "CloseLog");
|
||||||
|
closelog();
|
||||||
|
}
|
||||||
|
|
||||||
|
SMLogging * SMLogging::get()
|
||||||
|
{
|
||||||
|
if (smLog)
|
||||||
|
return smLog;
|
||||||
|
boost::mutex::scoped_lock s(m);
|
||||||
|
if (smLog)
|
||||||
|
return smLog;
|
||||||
|
smLog = new SMLogging();
|
||||||
|
return smLog;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SMLogging::log(int priority,const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
|
||||||
|
vsyslog(priority, format, args);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
29
src/SMLogging.h
Normal file
29
src/SMLogging.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
#ifndef SM_LOGGING_H_
|
||||||
|
#define SM_LOGGING_H_
|
||||||
|
|
||||||
|
#include <syslog.h>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
|
namespace storagemanager
|
||||||
|
{
|
||||||
|
|
||||||
|
class SMLogging
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
static SMLogging *get();
|
||||||
|
~SMLogging();
|
||||||
|
|
||||||
|
void log(int priority, const char *format, ...);
|
||||||
|
|
||||||
|
private:
|
||||||
|
SMLogging();
|
||||||
|
//SMConfig& config;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <syslog.h>
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
@@ -20,6 +19,7 @@ using namespace std;
|
|||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
#include "SessionManager.h"
|
#include "SessionManager.h"
|
||||||
#include "ClientRequestProcessor.h"
|
#include "ClientRequestProcessor.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -53,6 +53,7 @@ SessionManager * SessionManager::get()
|
|||||||
|
|
||||||
int SessionManager::start()
|
int SessionManager::start()
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
int rc,listenSockfd,incomingSockfd,on = 1;
|
int rc,listenSockfd,incomingSockfd,on = 1;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
int nfds;
|
int nfds;
|
||||||
@@ -61,25 +62,25 @@ int SessionManager::start()
|
|||||||
int current_size = 0;
|
int current_size = 0;
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
|
||||||
syslog(LOG_INFO, "SessionManager starting...");
|
logger->log(LOG_INFO,"SessionManager starting...");
|
||||||
|
|
||||||
if (pipe(socketCtrl)==-1)
|
if (pipe(socketCtrl)==-1)
|
||||||
{
|
{
|
||||||
syslog(LOG_CRIT, "Pipe Failed: %s", strerror(errno));
|
logger->log(LOG_CRIT,"Pipe Failed: %s", strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
listenSockfd = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
listenSockfd = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (listenSockfd < 0)
|
if (listenSockfd < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_CRIT, "socket() failed: %s", strerror(errno));
|
logger->log(LOG_CRIT,"socket() failed: %s", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = ::setsockopt(listenSockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on));
|
rc = ::setsockopt(listenSockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on));
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_CRIT, "setsockopt() failed: %s", strerror(errno));
|
logger->log(LOG_CRIT,"setsockopt() failed: %s", strerror(errno));
|
||||||
close(listenSockfd);
|
close(listenSockfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -87,7 +88,7 @@ int SessionManager::start()
|
|||||||
rc = ::ioctl(listenSockfd, FIONBIO, (char *)&on);
|
rc = ::ioctl(listenSockfd, FIONBIO, (char *)&on);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_CRIT, "ioctl() failed: %s", strerror(errno));
|
logger->log(LOG_CRIT,"ioctl() failed: %s", strerror(errno));
|
||||||
close(listenSockfd);
|
close(listenSockfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -98,7 +99,7 @@ int SessionManager::start()
|
|||||||
rc = ::bind(listenSockfd,(struct sockaddr *)&addr, sizeof(addr));
|
rc = ::bind(listenSockfd,(struct sockaddr *)&addr, sizeof(addr));
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_CRIT, "bind() failed: %s", strerror(errno));
|
logger->log(LOG_CRIT,"bind() failed: %s", strerror(errno));
|
||||||
close(listenSockfd);
|
close(listenSockfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -106,7 +107,7 @@ int SessionManager::start()
|
|||||||
rc = ::listen(listenSockfd, 32);
|
rc = ::listen(listenSockfd, 32);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_CRIT, "listen() failed: %s", strerror(errno));
|
logger->log(LOG_CRIT,"listen() failed: %s", strerror(errno));
|
||||||
close(listenSockfd);
|
close(listenSockfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -118,18 +119,18 @@ int SessionManager::start()
|
|||||||
fds[1].events = POLLIN;
|
fds[1].events = POLLIN;
|
||||||
nfds = 2;
|
nfds = 2;
|
||||||
|
|
||||||
syslog(LOG_INFO, "SessionManager waiting for sockets.");
|
logger->log(LOG_INFO,"SessionManager waiting for sockets.");
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//if (current_size != nfds)
|
//if (current_size != nfds)
|
||||||
//syslog(LOG_DEBUG, "polling %i fds %i", nfds,fds);
|
//logger->log(LOG_DEBUG,"polling %i fds %i", nfds,fds);
|
||||||
//cout << "polling " << nfds << " fds" << endl;
|
//cout << "polling " << nfds << " fds" << endl;
|
||||||
rc = ::poll(fds, nfds, pollTimeout);
|
rc = ::poll(fds, nfds, pollTimeout);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_CRIT, "poll() failed: %s", strerror(errno));
|
logger->log(LOG_CRIT,"poll() failed: %s", strerror(errno));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current_size = nfds;
|
current_size = nfds;
|
||||||
@@ -139,16 +140,16 @@ int SessionManager::start()
|
|||||||
if(fds[socketIncr].revents == 0)
|
if(fds[socketIncr].revents == 0)
|
||||||
continue;
|
continue;
|
||||||
//if (socketIncr >= 2)
|
//if (socketIncr >= 2)
|
||||||
//syslog(LOG_DEBUG, "got event on fd %i index is %i", fds[socketIncr].fd,socketIncr);
|
//logger->log(LOG_DEBUG,"got event on fd %i index is %i", fds[socketIncr].fd,socketIncr);
|
||||||
if(fds[socketIncr].revents != POLLIN)
|
if(fds[socketIncr].revents != POLLIN)
|
||||||
{
|
{
|
||||||
//syslog(LOG_DEBUG, "Error! revents = %d", fds[socketIncr].revents,);
|
//logger->log(LOG_DEBUG,"Error! revents = %d", fds[socketIncr].revents,);
|
||||||
close(fds[socketIncr].fd);
|
close(fds[socketIncr].fd);
|
||||||
fds[socketIncr].fd = -1;
|
fds[socketIncr].fd = -1;
|
||||||
}
|
}
|
||||||
if (fds[socketIncr].fd == listenSockfd)
|
if (fds[socketIncr].fd == listenSockfd)
|
||||||
{
|
{
|
||||||
//syslog(LOG_DEBUG, "Listening socket is readable");
|
//logger->log(LOG_DEBUG,"Listening socket is readable");
|
||||||
incomingSockfd = 0;
|
incomingSockfd = 0;
|
||||||
while (incomingSockfd != -1)
|
while (incomingSockfd != -1)
|
||||||
{
|
{
|
||||||
@@ -160,12 +161,12 @@ int SessionManager::start()
|
|||||||
{
|
{
|
||||||
if (errno != EWOULDBLOCK)
|
if (errno != EWOULDBLOCK)
|
||||||
{
|
{
|
||||||
syslog(LOG_CRIT, "accept() failed: %s", strerror(errno));
|
logger->log(LOG_CRIT,"accept() failed: %s", strerror(errno));
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//syslog(LOG_DEBUG, "New incoming connection - %d",incomingSockfd);
|
//logger->log(LOG_DEBUG,"New incoming connection - %d",incomingSockfd);
|
||||||
fds[nfds].fd = incomingSockfd;
|
fds[nfds].fd = incomingSockfd;
|
||||||
fds[nfds].events = POLLIN;
|
fds[nfds].events = POLLIN;
|
||||||
nfds++;
|
nfds++;
|
||||||
@@ -173,7 +174,7 @@ int SessionManager::start()
|
|||||||
}
|
}
|
||||||
else if (fds[socketIncr].fd == socketCtrl[0])
|
else if (fds[socketIncr].fd == socketCtrl[0])
|
||||||
{
|
{
|
||||||
//syslog(LOG_DEBUG, "SocketControl is readable");
|
//logger->log(LOG_DEBUG,"SocketControl is readable");
|
||||||
uint8_t ctrlCode;
|
uint8_t ctrlCode;
|
||||||
int len,socket;
|
int len,socket;
|
||||||
|
|
||||||
@@ -194,7 +195,7 @@ int SessionManager::start()
|
|||||||
{
|
{
|
||||||
if(fds[i].fd == socket)
|
if(fds[i].fd == socket)
|
||||||
{
|
{
|
||||||
//syslog(LOG_DEBUG, "returned socket %i at index %i", fds[i].fd,i);
|
//logger->log(LOG_DEBUG,"returned socket %i at index %i", fds[i].fd,i);
|
||||||
fds[i].events = POLLIN;
|
fds[i].events = POLLIN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -222,7 +223,7 @@ int SessionManager::start()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//syslog(LOG_DEBUG, "socketIncr %d -- Descriptor %d is readable",socketIncr,fds[socketIncr].fd);
|
//logger->log(LOG_DEBUG,"socketIncr %d -- Descriptor %d is readable",socketIncr,fds[socketIncr].fd);
|
||||||
bool closeConn = false;
|
bool closeConn = false;
|
||||||
char recv_buffer[8192];
|
char recv_buffer[8192];
|
||||||
uint recvMsgLength = 0;
|
uint recvMsgLength = 0;
|
||||||
@@ -233,7 +234,7 @@ int SessionManager::start()
|
|||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
ts.tv_sec = 0;
|
ts.tv_sec = 0;
|
||||||
ts.tv_nsec = 100000000; // .1 sec
|
ts.tv_nsec = 100000000; // .1 sec
|
||||||
//syslog(LOG_DEBUG, "reading from fd %i index is %i", fds[socketIncr].fd,socketIncr);
|
//logger->log(LOG_DEBUG,"reading from fd %i index is %i", fds[socketIncr].fd,socketIncr);
|
||||||
if (sockState.find(fds[socketIncr].fd) != sockState.end())
|
if (sockState.find(fds[socketIncr].fd) != sockState.end())
|
||||||
{
|
{
|
||||||
SockState &state = sockState[fds[socketIncr].fd];
|
SockState &state = sockState[fds[socketIncr].fd];
|
||||||
@@ -260,7 +261,7 @@ int SessionManager::start()
|
|||||||
sockState[fds[socketIncr].fd] = state;
|
sockState[fds[socketIncr].fd] = state;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//syslog(LOG_DEBUG, "recv got %i bytes", peakLength);
|
//logger->log(LOG_DEBUG,"recv got %i bytes", peakLength);
|
||||||
endOfData = remainingBytes + peakLength;
|
endOfData = remainingBytes + peakLength;
|
||||||
if (endOfData < SM_HEADER_LEN)
|
if (endOfData < SM_HEADER_LEN)
|
||||||
{
|
{
|
||||||
@@ -276,12 +277,12 @@ int SessionManager::start()
|
|||||||
{
|
{
|
||||||
if (*((uint *) &recv_buffer[i]) == SM_MSG_START)
|
if (*((uint *) &recv_buffer[i]) == SM_MSG_START)
|
||||||
{
|
{
|
||||||
//syslog(LOG_DEBUG, "Received SM_MSG_START");
|
//logger->log(LOG_DEBUG,"Received SM_MSG_START");
|
||||||
//found it set msgLength and recvMsgStart offset of SM_MSG_START
|
//found it set msgLength and recvMsgStart offset of SM_MSG_START
|
||||||
recvMsgLength = *((uint *) &recv_buffer[i+4]);
|
recvMsgLength = *((uint *) &recv_buffer[i+4]);
|
||||||
//syslog(LOG_DEBUG, "got length = %i", recvMsgLength);
|
//logger->log(LOG_DEBUG,"got length = %i", recvMsgLength);
|
||||||
recvMsgStart = i + SM_HEADER_LEN;
|
recvMsgStart = i + SM_HEADER_LEN;
|
||||||
//syslog(LOG_DEBUG, "recvMsgLength %d recvMsgStart %d endofData %d", recvMsgLength,recvMsgStart,endOfData);
|
//logger->log(LOG_DEBUG,"recvMsgLength %d recvMsgStart %d endofData %d", recvMsgLength,recvMsgStart,endOfData);
|
||||||
// if >= endOfData then the start of the message data is the beginning of next message
|
// if >= endOfData then the start of the message data is the beginning of next message
|
||||||
if (recvMsgStart >= endOfData)
|
if (recvMsgStart >= endOfData)
|
||||||
recvMsgStart = 0;
|
recvMsgStart = 0;
|
||||||
@@ -292,7 +293,7 @@ int SessionManager::start()
|
|||||||
// didn't find SM_MSG_START in this message consume the data and loop back through on next message
|
// didn't find SM_MSG_START in this message consume the data and loop back through on next message
|
||||||
if (recvMsgLength == 0)
|
if (recvMsgLength == 0)
|
||||||
{
|
{
|
||||||
//syslog(LOG_DEBUG, "No SM_MSG_START");
|
//logger->log(LOG_DEBUG,"No SM_MSG_START");
|
||||||
len = ::read(fds[socketIncr].fd, &recv_buffer[remainingBytes], peakLength);
|
len = ::read(fds[socketIncr].fd, &recv_buffer[remainingBytes], peakLength);
|
||||||
assert(len == peakLength);
|
assert(len == peakLength);
|
||||||
// we know the msg header isn't in position [0, endOfData - i), so throw that out
|
// we know the msg header isn't in position [0, endOfData - i), so throw that out
|
||||||
@@ -307,7 +308,7 @@ int SessionManager::start()
|
|||||||
//remove the junk in front of the message
|
//remove the junk in front of the message
|
||||||
if (recvMsgStart > 0)
|
if (recvMsgStart > 0)
|
||||||
{
|
{
|
||||||
//syslog(LOG_DEBUG, "SM_MSG_START data is here");
|
//logger->log(LOG_DEBUG,"SM_MSG_START data is here");
|
||||||
// how many to consume here...
|
// how many to consume here...
|
||||||
// recvMsgStart is the position in the buffer
|
// recvMsgStart is the position in the buffer
|
||||||
// peakLength is the amount peeked this time
|
// peakLength is the amount peeked this time
|
||||||
@@ -316,7 +317,7 @@ int SessionManager::start()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//syslog(LOG_DEBUG, "SM_MSG_START data is next message");
|
//logger->log(LOG_DEBUG,"SM_MSG_START data is next message");
|
||||||
len = ::read(fds[socketIncr].fd, &recv_buffer[remainingBytes], peakLength);
|
len = ::read(fds[socketIncr].fd, &recv_buffer[remainingBytes], peakLength);
|
||||||
}
|
}
|
||||||
//Disable polling on this socket
|
//Disable polling on this socket
|
||||||
@@ -327,7 +328,7 @@ int SessionManager::start()
|
|||||||
/*
|
/*
|
||||||
//Doing this to work with cloudio_component_test
|
//Doing this to work with cloudio_component_test
|
||||||
len = ::read(fds[socketIncr].fd, out, recvMsgLength);
|
len = ::read(fds[socketIncr].fd, out, recvMsgLength);
|
||||||
syslog(LOG_DEBUG, "Read %d bytes.",len);
|
logger->log(LOG_DEBUG,"Read %d bytes.",len);
|
||||||
//Debug test lets send a reponse back
|
//Debug test lets send a reponse back
|
||||||
uint32_t response[4] = { storagemanager::SM_MSG_START, 8, (uint32_t ) -1, EINVAL };
|
uint32_t response[4] = { storagemanager::SM_MSG_START, 8, (uint32_t ) -1, EINVAL };
|
||||||
len = ::send(fds[socketIncr].fd, response, 16, 0);
|
len = ::send(fds[socketIncr].fd, response, 16, 0);
|
||||||
@@ -387,7 +388,8 @@ void SessionManager::returnSocket(int socket)
|
|||||||
void SessionManager::socketError(int socket)
|
void SessionManager::socketError(int socket)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock s(ctrlMutex);
|
boost::mutex::scoped_lock s(ctrlMutex);
|
||||||
syslog(LOG_CRIT, " ****** socket error!");
|
SMLogging* logger = SMLogging::get();
|
||||||
|
logger->log(LOG_CRIT," ****** socket error!");
|
||||||
int err;
|
int err;
|
||||||
uint8_t ctrlCode = REMOVEFD;
|
uint8_t ctrlCode = REMOVEFD;
|
||||||
err = ::write(socketCtrl[1], &ctrlCode, 1);
|
err = ::write(socketCtrl[1], &ctrlCode, 1);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include "StatTask.h"
|
#include "StatTask.h"
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -29,6 +30,7 @@ StatTask::~StatTask()
|
|||||||
|
|
||||||
bool StatTask::run()
|
bool StatTask::run()
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
bool success;
|
bool success;
|
||||||
uint8_t buf[1024] = {0};
|
uint8_t buf[1024] = {0};
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ bool StatTask::run()
|
|||||||
sm_response *resp = (sm_response *) buf;
|
sm_response *resp = (sm_response *) buf;
|
||||||
|
|
||||||
#ifdef SM_TRACE
|
#ifdef SM_TRACE
|
||||||
syslog(LOG_DEBUG, "stat %s.",cmd->filename);
|
logger->log(LOG_DEBUG,"stat %s.",cmd->filename);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int err = ioc->stat(cmd->filename, (struct stat *) resp->payload);
|
int err = ioc->stat(cmd->filename, (struct stat *) resp->payload);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "TruncateTask.h"
|
#include "TruncateTask.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ TruncateTask::~TruncateTask()
|
|||||||
|
|
||||||
bool TruncateTask::run()
|
bool TruncateTask::run()
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
bool success;
|
bool success;
|
||||||
uint8_t buf[1024] = {0};
|
uint8_t buf[1024] = {0};
|
||||||
|
|
||||||
@@ -38,7 +40,7 @@ bool TruncateTask::run()
|
|||||||
truncate_cmd *cmd = (truncate_cmd *) buf;
|
truncate_cmd *cmd = (truncate_cmd *) buf;
|
||||||
|
|
||||||
#ifdef SM_TRACE
|
#ifdef SM_TRACE
|
||||||
syslog(LOG_DEBUG, "truncate %s newlength %i.",cmd->filename,cmd->length);
|
logger->log(LOG_DEBUG,"truncate %s newlength %i.",cmd->filename,cmd->length);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int err = ioc->truncate(cmd->filename, cmd->length);
|
int err = ioc->truncate(cmd->filename, cmd->length);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "UnlinkTask.h"
|
#include "UnlinkTask.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ UnlinkTask::~UnlinkTask()
|
|||||||
|
|
||||||
bool UnlinkTask::run()
|
bool UnlinkTask::run()
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
bool success;
|
bool success;
|
||||||
uint8_t buf[1024] = {0};
|
uint8_t buf[1024] = {0};
|
||||||
|
|
||||||
@@ -39,7 +41,7 @@ bool UnlinkTask::run()
|
|||||||
unlink_cmd *cmd = (unlink_cmd *) buf;
|
unlink_cmd *cmd = (unlink_cmd *) buf;
|
||||||
|
|
||||||
#ifdef SM_TRACE
|
#ifdef SM_TRACE
|
||||||
syslog(LOG_DEBUG, "unlink %s.",cmd->filename);
|
logger->log(LOG_DEBUG,"unlink %s.",cmd->filename);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int err = ioc->unlink(cmd->filename);
|
int err = ioc->unlink(cmd->filename);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "WriteTask.h"
|
#include "WriteTask.h"
|
||||||
#include "messageFormat.h"
|
#include "messageFormat.h"
|
||||||
#include "IOCoordinator.h"
|
#include "IOCoordinator.h"
|
||||||
|
#include "SMLogging.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -28,6 +29,7 @@ WriteTask::~WriteTask()
|
|||||||
|
|
||||||
bool WriteTask::run()
|
bool WriteTask::run()
|
||||||
{
|
{
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
bool success;
|
bool success;
|
||||||
uint8_t cmdbuf[1024] = {0};
|
uint8_t cmdbuf[1024] = {0};
|
||||||
|
|
||||||
@@ -44,7 +46,7 @@ bool WriteTask::run()
|
|||||||
check_error("WriteTask read", false);
|
check_error("WriteTask read", false);
|
||||||
|
|
||||||
#ifdef SM_TRACE
|
#ifdef SM_TRACE
|
||||||
syslog(LOG_DEBUG, "write filename %s offset %i count %i.",cmd->filename,cmd->offset,cmd->count);
|
logger->log(LOG_DEBUG,"write filename %s offset %i count %i.",cmd->filename,cmd->offset,cmd->count);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t readCount = 0, writeCount = 0;
|
size_t readCount = 0, writeCount = 0;
|
||||||
|
|||||||
10
src/main.cpp
10
src/main.cpp
@@ -8,10 +8,10 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <syslog.h>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#include "SMLogging.h"
|
||||||
#include "SessionManager.h"
|
#include "SessionManager.h"
|
||||||
|
|
||||||
using namespace storagemanager;
|
using namespace storagemanager;
|
||||||
@@ -25,18 +25,14 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
//TODO: make this configurable
|
SMLogging* logger = SMLogging::get();
|
||||||
setlogmask (LOG_UPTO (LOG_DEBUG));
|
|
||||||
|
|
||||||
openlog ("StorageManager", LOG_PID | LOG_NDELAY, LOG_LOCAL2);
|
logger->log(LOG_NOTICE,"StorageManager started.");
|
||||||
|
|
||||||
syslog(LOG_NOTICE, "StorageManager started.");
|
|
||||||
|
|
||||||
SessionManager* sm = SessionManager::get();
|
SessionManager* sm = SessionManager::get();
|
||||||
|
|
||||||
ret = sm->start();
|
ret = sm->start();
|
||||||
|
|
||||||
closelog ();
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user