31 #include "XrdVersion.hh"
53 static std::string
ts() {
54 std::time_t t = std::time(
nullptr);
56 std::strftime(mbstr,
sizeof(mbstr),
"%y%m%d %H:%M:%S ", std::localtime(&t));
57 return std::string(mbstr);
76 char physCName[MAXPATHLEN+1];
77 int retc =
g_namelib->
lfn2pfn(logName.c_str(), physCName,
sizeof(physCName));
79 XrdCephEroute.
Say(__FUNCTION__,
" - failed to translate '", logName.c_str(),
"' using namelib plugin, using it as is");
82 XrdCephEroute.
Say(__FUNCTION__,
" - translated '", logName.c_str(),
"' to '", physCName,
"'");
104 ssize_t
getNumericAttr(
const char*
const path,
const char* attrName,
const int maxAttrLen)
108 char *attrValue = (
char*)malloc(maxAttrLen+1);
109 if (NULL == attrValue) {
118 attrValue[attrLen] =
'\0';
119 char *endPointer = (
char *)NULL;
120 retval = strtoll(attrValue, &endPointer, 10);
123 if (NULL != attrValue) {
136 const char* config_fn,
146 }
catch (std::exception &e) {
147 XrdCephEroute.
Say(
"CephOss loading failed with exception. Check the syntax of parameters : ", parms);
175 if (configfn && *configfn) {
178 if ((cfgFD =
open(configfn, O_RDONLY, 0)) < 0) {
179 Eroute.
Emsg(
"Config", errno,
"open config file", configfn);
185 while((var =
Config.GetMyFirstWord())) {
186 if (!strncmp(var,
"ceph.nbconnections", 18)) {
189 unsigned long value = strtoul(var, 0, 10);
190 if (value > 0 and value <= 100) {
193 Eroute.
Emsg(
"Config",
"Invalid value for ceph.nbconnections in config file (must be between 1 and 100)", configfn, var);
197 Eroute.
Emsg(
"Config",
"Missing value for ceph.nbconnections in config file", configfn);
201 if (!strncmp(var,
"ceph.namelib", 12)) {
204 std::string libname = var;
207 bool hasParms{
false};
208 if (!
Config.GetRest(parms,
sizeof(parms)) || parms[0]) {
212 XrdOucN2NLoader n2nLoader(&Eroute,configfn,(hasParms?parms:
""),NULL,NULL);
215 Eroute.
Emsg(
"Config",
"Unable to load library given in ceph.namelib : %s", var);
218 Eroute.
Emsg(
"Config",
"Missing value for ceph.namelib in config file ", configfn);
223 int pread_flag_set = !strncmp(var,
"ceph.usedefaultpreadalg", 24);
224 int readv_flag_set = !strncmp(var,
"ceph.usedefaultreadvalg", 24);
225 if (pread_flag_set or readv_flag_set) {
229 long value = strtol(var, &endptr, 10);
230 if ((value == 0 || value == 1) && (var != endptr)) {
231 if (pread_flag_set) {
233 }
else if(readv_flag_set) {
236 Eroute.
Emsg(
"Config",
"Bug encountered during parsing", var);
239 Eroute.
Emsg(
"Config",
"Invalid value for ceph.usedefault* in config file -- must be 0 or 1, got", var);
243 Eroute.
Emsg(
"Config",
"Missing value for ceph.usedefault* in config file");
248 if (!strncmp(var,
"ceph.aiowaitthresh", 19)) {
251 unsigned long value = strtoul(var, 0, 10);
252 if ((value > 0) && (value < INT_MAX)){
255 Eroute.
Emsg(
"Config",
"Invalid value for ceph.aiowaitthresh:", var);
258 Eroute.
Emsg(
"Config",
"Missing value for ceph.aiowaitthresh in config file");
263 if (!strncmp(var,
"ceph.usebuffer", 14)) {
266 unsigned long value = strtoul(var, 0, 10);
268 m_configBufferEnable = value;
269 Eroute.
Emsg(
"Config",
"ceph.usebuffer",std::to_string(m_configBufferEnable).c_str());
271 Eroute.
Emsg(
"Config",
"Invalid value for ceph.usebuffer in config file (must be 0 or 1)", configfn, var);
275 Eroute.
Emsg(
"Config",
"Missing value for ceph.usebuffer in config file", configfn);
279 if (!strncmp(var,
"ceph.buffersize", 15)) {
282 unsigned long value = strtoul(var, 0, 10);
283 if (value > 0 and value <= 1000000000L) {
284 m_configBufferSize = value;
285 Eroute.
Emsg(
"Config",
"ceph.buffersize", std::to_string(m_configBufferSize).c_str() );
287 Eroute.
Emsg(
"Config",
"Invalid value for ceph.buffersize in config file; enter in bytes (no units)", configfn, var);
291 Eroute.
Emsg(
"Config",
"Missing value for ceph.buffersize in config file", configfn);
295 if (!strncmp(var,
"ceph.buffermaxpersimul", 22)) {
298 unsigned long value = strtoul(var, 0, 10);
299 if (value > 0 and value <= 1000000000L) {
300 m_configMaxSimulBufferCount = value;
301 Eroute.
Emsg(
"Config",
"ceph.buffermaxpersimul", std::to_string(m_configMaxSimulBufferCount).c_str() );
303 Eroute.
Emsg(
"Config",
"Invalid value for ceph.buffermaxpersimul in config file; enter in bytes (no units)", configfn, var);
307 Eroute.
Emsg(
"Config",
"Missing value for ceph.buffermaxpersimul in config file", configfn);
312 if (!strncmp(var,
"ceph.usereadv", 13)) {
315 unsigned long value = strtoul(var, 0, 10);
317 m_configReadVEnable = value;
318 Eroute.
Emsg(
"Config",
"ceph.usereadvalg",std::to_string(m_configBufferEnable).c_str());
320 Eroute.
Emsg(
"Config",
"Invalid value for ceph.usereadv in config file (must be 0 or 1)", configfn, var);
324 Eroute.
Emsg(
"Config",
"Missing value for ceph.usereadv in config file", configfn);
328 if (!strncmp(var,
"ceph.readvalgname", 17)) {
334 if (!
Config.GetRest(parms,
sizeof(parms)) || parms[0]) {
335 Eroute.
Emsg(
"Config",
"readvalgname parameters will be ignored");
337 m_configReadVAlgName = var;
339 Eroute.
Emsg(
"Config",
"Missing value for ceph.readvalgname in config file", configfn);
343 if (!strncmp(var,
"ceph.bufferiomode", 17)) {
348 if (!
Config.GetRest(parms,
sizeof(parms)) || parms[0]) {
349 Eroute.
Emsg(
"Config",
"readvalgname parameters will be ignored");
351 m_configBufferIOmode = var;
353 Eroute.
Emsg(
"Config",
"Missing value for ceph.bufferiomode in config file", configfn);
358 if (!strcmp(var,
"ceph.reportingpools")) {
361 m_configPoolnames = var;
363 Eroute.
Emsg(
"Config",
"Missing value for ceph.reportingpools in config file", configfn);
371 int retc =
Config.LastError();
373 NoGo = Eroute.
Emsg(
"Config", -retc,
"read config file",
424 auto colonPos = possPool.find_first_of(
':');
427 pool = possPool.substr(0, colonPos);
461 std::string spath {path};
464 if (spath.back() ==
'/') {
468 XrdCephEroute.
Say(__FUNCTION__,
" - fake a return for stat'ing root element '/'");
475 memset(buff, 0,
sizeof(*buff));
477 buff->st_mode = S_IFDIR|S_IRWXU;
485 if (spath.find_first_of(
":") == spath.length()-1) {
492 if (m_configPoolnames.find(spath) != std::string::npos) {
494 XrdCephEroute.
Say(__FUNCTION__,
" - preparing spaceinfo report for '", path,
"'");
498 XrdCephEroute.
Say(__FUNCTION__,
" - cannot find pool '", path,
"' in ceph.reportingpools");
506 XrdCephEroute.
Say(__FUNCTION__,
" - found object ", spath.c_str(),
" via ceph_posix_stat");
513 XrdCephEroute.
Say(__FUNCTION__,
" - cannot find object '", spath.c_str(),
"'");
530 int rc =
StatVS(&sP, 0, 0);
534 int percentUsedSpace = (sP.
Usage*100)/sP.
Total;
535 blen = snprintf(buff, blen,
"%d %lld %d %d %lld %d",
536 1, sP.
Free, percentUsedSpace, 0, 0LL, 0);
557 long long usedSpace,
long long freeSpace,
long long quota,
long long maxFreeChunk)
559 return snprintf(buff, blen,
"oss.cgroup=%s&oss.space=%lld&oss.free=%lld&oss.maxf=%lld&oss.used=%lld&oss.quota=%lld",
560 cgroup, totalSpace, freeSpace, maxFreeChunk, usedSpace, quota);
585 std::string path(charPath);
587 std::string spath {path};
595 if (spath.back() ==
':') {
598 if (m_configPoolnames.find(spath) == std::string::npos) {
603 long long usedSpace, totalSpace, freeSpace;
611 std::string spaceInfoPath = spath +
":" + (
const char *)
"__spaceinfo__";
612 totalSpace =
getNumericAttr(spaceInfoPath.c_str(),
"total_space", 24);
613 if (totalSpace < 0) {
614 XrdCephEroute.
Say(
"Could not get 'total_space' attribute from ", spaceInfoPath.c_str());
623 freeSpace = totalSpace - usedSpace;
639 unsigned long long size,
643 }
catch (std::exception &e) {
652 }
catch (std::exception &e) {
669 if (m_configReadVEnable) {
673 if (m_configBufferEnable) {
675 m_configBufferIOmode, m_configMaxSimulBufferCount);
XrdOucName2Name * g_namelib
static std::string ts()
timestamp output for logging messages
int formatStatLSResponse(char *buff, int &blen, const char *cgroup, long long totalSpace, long long usedSpace, long long freeSpace, long long quota, long long maxFreeChunk)
unsigned int g_maxCephPoolIdx
static void logwrapper(char *format, va_list argp)
void m_translateFileName(std::string &physName, std::string logName)
converts a logical filename to physical one if needed
XrdOss * XrdOssGetStorageSystem(XrdOss *native_oss, XrdSysLogger *lp, const char *config_fn, const char *parms)
ssize_t getNumericAttr(const char *const path, const char *attrName, const int maxAttrLen)
Retrieve an integer-value extended attribute.
std::string extractPool(std::string possPool)
Extract a pool name (string before the first colon ':') from an object ID.
XrdVERSIONINFO(XrdOssGetStorageSystem, XrdCephOss)
unsigned int g_cephAioWaitThresh
XrdSysError XrdCephEroute(0)
void ceph_posix_set_logfunc(void(*logfunc)(char *, va_list argp))
int ceph_posix_truncate(XrdOucEnv *env, const char *pathname, unsigned long long size)
int ceph_posix_unlink(XrdOucEnv *env, const char *pathname)
ssize_t ceph_posix_getxattr(XrdOucEnv *env, const char *path, const char *name, void *value, size_t size)
void ceph_posix_disconnect_all()
int ceph_posix_statfs(long long *totalSpace, long long *freeSpace)
int ceph_posix_stat_pool(char const *poolName, long long *usedSpace)
Return the amount of space used in a pool.
void ceph_posix_set_defaults(const char *value)
int ceph_posix_stat(XrdOucEnv *env, const char *pathname, struct stat *buf)
int stat(const char *path, struct stat *buf)
int open(const char *path, int oflag,...)
virtual int Truncate(const char *, unsigned long long, XrdOucEnv *eP=0)
virtual int StatLS(XrdOucEnv &env, const char *path, char *buff, int &blen)
Report on disk space use in this pool.
virtual int Rename(const char *, const char *, XrdOucEnv *eP1=0, XrdOucEnv *eP2=0)
virtual int StatVS(XrdOssVSInfo *sP, const char *sname=0, int updt=0)
virtual int Remdir(const char *, int Opts=0, XrdOucEnv *eP=0)
virtual int Create(const char *, const char *, mode_t, XrdOucEnv &, int opts=0)
XrdCephOss(const char *, XrdSysError &)
virtual int Mkdir(const char *, mode_t mode, int mkpath=0, XrdOucEnv *eP=0)
virtual int Stat(const char *, struct stat *, int opts=0, XrdOucEnv *eP=0)
Return status information for an object ID.
virtual XrdOssDF * newDir(const char *tident)
virtual int Chmod(const char *, mode_t mode, XrdOucEnv *eP=0)
virtual int Unlink(const char *path, int Opts=0, XrdOucEnv *eP=0)
virtual int StatFS(const char *path, char *buff, int &blen, XrdOucEnv *eP=0)
virtual int Init(XrdSysLogger *, const char *)
virtual XrdOssDF * newFile(const char *tident)
int Configure(const char *, XrdSysError &)
static int Export(const char *Var, const char *Val)
XrdOucName2Name * Load(const char *libName, XrdVersionInfo &urVer, XrdOucEnv *envP=0)
virtual int lfn2pfn(const char *lfn, char *buff, int blen)=0
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
XrdSysLogger * logger(XrdSysLogger *lp=0)
const char * SetPrefix(const char *prefix)
static INT to(const char *buffer)