13 using namespace edm::storage;
22 m_library_handle(nullptr),
32 redd_strerror(nullptr) {
40 m_library_handle(nullptr),
50 redd_strerror(nullptr) {
55 : m_fd(nullptr), m_close(
false), m_is_loaded(
false) {
57 open(name, flags, perms);
61 : m_fd(nullptr), m_close(
false), m_is_loaded(
false) {
63 open(name.c_str(), flags, perms);
69 <<
"' but the file is still open";
76 #define REDD_LOAD_SYMBOL(NAME, TYPE) \
78 NAME = reinterpret_cast<TYPE>(reinterpret_cast<size_t>(dlsym(m_library_handle, #NAME))); \
79 if ((retval = dlerror())) { \
80 throw cms::Exception("LStoreFile::loadLibrary()") << "Failed to load dlsym LStore library: " << retval; \
83 throw cms::Exception("LStoreFile::loadLibrary()") << "Got a null pointer back from dlsym()\n"; \
87 edm::LogError(
"LStoreFile::loadLibrary()") <<
"Loading library\n";
98 throw cms::Exception(
"LStoreFile::loadLibrary()") <<
"Can't dlopen() LStore libraries: " << dlerror();
101 char *retval =
nullptr;
113 throw cms::Exception(
"LStoreFile::loadLibrary()") <<
"Error in redd_init: " << (*redd_strerror)();
128 throw cms::Exception(
"LStoreFile::closeLibrary()") <<
"Error in redd_term: " << (*redd_strerror)();
133 throw cms::Exception(
"LStoreFile::closeLibrary()") <<
"Error on dlclose(): " << dlerror();
137 edm::LogError(
"LStoreFileError") <<
"LStoreFile had an error in its destructor: " <<
e;
156 open(name.c_str(), flags, perms);
161 if ((name ==
nullptr) || (*name == 0))
162 throw cms::Exception(
"LStoreFile::open()") <<
"Cannot open a file without a name";
165 throw cms::Exception(
"LStoreFile::open()") <<
"Must open file '" << name <<
"' at least for read or write";
176 else if (flags & IOFlags::OpenRead)
177 openflags |= O_RDONLY;
178 else if (flags & IOFlags::OpenWrite)
179 openflags |= O_WRONLY;
185 openflags |= O_APPEND;
188 openflags |= O_CREAT;
194 openflags |= O_TRUNC;
196 void *newfd =
nullptr;
197 if ((newfd = (*
redd_open)(name, openflags, perms)) ==
nullptr)
199 <<
"redd_open(name='" << name <<
"', flags=0x" << std::hex << openflags <<
", permissions=0" << std::oct
200 << perms <<
std::dec <<
") => error '" << (*redd_strerror)() <<
"' (redd_errno=" << (*
redd_errno)() <<
")";
211 if (
m_fd ==
nullptr) {
212 edm::LogError(
"LStoreFileError") <<
"LStoreFile::close(name='" <<
m_name <<
"') called but the file is not open";
219 << (*redd_strerror)() <<
"' (redd_errno=" << (*
redd_errno)() <<
")";
239 ssize_t
s = (*redd_read)(
m_fd, (
char *)into + done, n - done);
243 <<
"' (redd_errno=" << (*
redd_errno)() <<
")";
252 ssize_t
s = (*redd_write)(
m_fd, (
const char *)from + done, n - done);
256 <<
"' (redd_errno=" << (*
redd_errno)() <<
")";
267 throw cms::Exception(
"LStoreFile::position()") <<
"LStoreFile::position() called on a closed file";
269 throw cms::Exception(
"LStoreFile::position()") <<
"LStoreFile::position() called with incorrect 'whence' parameter";
272 uint32_t mywhence = (whence ==
SET ? SEEK_SET : whence ==
CURRENT ? SEEK_CUR : SEEK_END);
273 if ((result = (*
redd_lseek)(
m_fd, (off_t)offset, (uint32_t)mywhence)) == -1)
275 <<
"redd_lseek64(name='" <<
m_name <<
"', offset=" << offset <<
", whence=" << mywhence
276 <<
") failed with error '" << (*redd_strerror)() <<
"' (redd_errno=" << (*
redd_errno)() <<
")";
281 throw cms::Exception(
"LStoreFile::resize()") <<
"LStoreFile::resize(name='" <<
m_name <<
"') not implemented";
288 pthread_mutex_lock(
m_lock);
293 if ((retval = pthread_mutex_unlock(m_lock))) {
301 edm::LogError(
"LStoreFileError") <<
"LStoreFile couldn't unlock a mutex. Not good."
302 << strerror_r(retval, buf, 1024);
IOSize write(const void *from, IOSize n) override
void close(void) override
int64_t(* redd_lseek)(void *, int64_t, uint32_t)
int64_t(* redd_read)(void *, char *, int64_t)
Log< level::Error, false > LogError
MutexWrapper(pthread_mutex_t *lock)
virtual void create(const char *name, bool exclusive=false, int perms=0666)
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
~LStoreFile(void) override
virtual IOOffset position() const
void *(* redd_open)(const char *, int32_t, int32_t)
void resize(IOOffset size) override
int32_t(* redd_close)(void *)
Log< level::Info, false > LogInfo
#define REDD_LOAD_SYMBOL(NAME, TYPE)
int64_t(* redd_write)(void *, const char *, int64_t)
Log< level::Warning, false > LogWarning
const std::string &(* redd_strerror)()
static pthread_mutex_t m_dlopen_lock