XRootD
Loading...
Searching...
No Matches
XrdCephPosix.hh File Reference
#include <sys/types.h>
#include <stdarg.h>
#include <dirent.h>
#include <XrdOuc/XrdOucEnv.hh>
#include <XrdSys/XrdSysXAttr.hh>
+ Include dependency graph for XrdCephPosix.hh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void AioCB(XrdSfsAio *, size_t)
 

Functions

ssize_t ceph_aio_read (int fd, XrdSfsAio *aiop, AioCB *cb)
 
ssize_t ceph_aio_write (int fd, XrdSfsAio *aiop, AioCB *cb)
 
int ceph_posix_close (int fd)
 
int ceph_posix_closedir (DIR *dirp)
 
void ceph_posix_disconnect_all ()
 
int ceph_posix_fcntl (int fd, int cmd,...)
 
ssize_t ceph_posix_fgetxattr (int fd, const char *name, void *value, size_t size)
 
int ceph_posix_flistxattrs (int fd, XrdSysXAttr::AList **aPL, int getSz)
 
void ceph_posix_freexattrlist (XrdSysXAttr::AList *aPL)
 
int ceph_posix_fremovexattr (int fd, const char *name)
 
int ceph_posix_fsetxattr (int fd, const char *name, const void *value, size_t size, int flags)
 
int ceph_posix_fstat (int fd, struct stat *buf)
 
int ceph_posix_fsync (int fd)
 
int ceph_posix_ftruncate (int fd, unsigned long long size)
 
ssize_t ceph_posix_getxattr (XrdOucEnv *env, const char *path, const char *name, void *value, size_t size)
 
int ceph_posix_listxattrs (XrdOucEnv *env, const char *path, XrdSysXAttr::AList **aPL, int getSz)
 
off_t ceph_posix_lseek (int fd, off_t offset, int whence)
 
off64_t ceph_posix_lseek64 (int fd, off64_t offset, int whence)
 
int ceph_posix_open (XrdOucEnv *env, const char *pathname, int flags, mode_t mode)
 
DIR * ceph_posix_opendir (XrdOucEnv *env, const char *pathname)
 
ssize_t ceph_posix_pread (int fd, void *buf, size_t count, off64_t offset)
 
ssize_t ceph_posix_pwrite (int fd, const void *buf, size_t count, off64_t offset)
 
ssize_t ceph_posix_read (int fd, void *buf, size_t count)
 
int ceph_posix_readdir (DIR *dirp, char *buff, int blen)
 
int ceph_posix_removexattr (XrdOucEnv *env, const char *path, const char *name)
 
void ceph_posix_set_defaults (const char *value)
 
void ceph_posix_set_logfunc (void(*logfunc)(char *, va_list argp))
 
ssize_t ceph_posix_setxattr (XrdOucEnv *env, const char *path, const char *name, const void *value, size_t size, int flags)
 
int ceph_posix_stat (XrdOucEnv *env, const char *pathname, struct stat *buf)
 
int ceph_posix_statfs (long long *totalSpace, long long *freeSpace)
 
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_write (int fd, const void *buf, size_t count)
 

Typedef Documentation

◆ AioCB

typedef void AioCB(XrdSfsAio *, size_t)

Definition at line 39 of file XrdCephPosix.hh.

Function Documentation

◆ ceph_aio_read()

ssize_t ceph_aio_read ( int fd,
XrdSfsAio * aiop,
AioCB * cb )

Definition at line 953 of file XrdCephPosix.cc.

953 {
954 CephFileRef* fr = getFileRef(fd);
955 if (fr) {
956 // get the parameters from the Xroot aio object
957 size_t count = aiop->sfsAio.aio_nbytes;
958 size_t offset = aiop->sfsAio.aio_offset;
959 // TODO implement proper logging level for this plugin - this should be only debug
960 //logwrapper((char*)"ceph_aio_read: for fd %d, count=%d", fd, count);
961 if ((fr->flags & O_WRONLY) != 0) {
962 return -EBADF;
963 }
964 // get the striper object
965 libradosstriper::RadosStriper *striper = getRadosStriper(*fr);
966 if (0 == striper) {
967 return -EINVAL;
968 }
969 // prepare a bufferlist to receive data
970 ceph::bufferlist *bl = new ceph::bufferlist();
971 // get the poolIdx to use
972 int cephPoolIdx = getCephPoolIdxAndIncrease();
973 // Get the cluster to use
974 librados::Rados* cluster = checkAndCreateCluster(cephPoolIdx);
975 if (0 == cluster) {
976 return -EINVAL;
977 }
978 // prepare a ceph AioCompletion object and do async call
979 AioArgs *args = new AioArgs(aiop, cb, count, fd, bl);
980 librados::AioCompletion *completion =
981 cluster->aio_create_completion(args, ceph_aio_read_complete, NULL);
982 // do the read
983 int rc = striper->aio_read(fr->name, completion, bl, count, offset);
984 completion->release();
986 fr->asyncRdStartCount++;
987 return rc;
988 } else {
989 return -EBADF;
990 }
991}
static libradosstriper::RadosStriper * getRadosStriper(const CephFile &file)
CephFileRef * getFileRef(int fd)
look for a FileRef from its file descriptor
unsigned int getCephPoolIdxAndIncrease()
librados::Rados * checkAndCreateCluster(unsigned int cephPoolIdx, std::string userId=g_defaultParams.userId)
static void ceph_aio_read_complete(rados_completion_t c, void *arg)
off_t aio_offset
Definition XrdSfsAio.hh:49
size_t aio_nbytes
Definition XrdSfsAio.hh:48
struct aiocb sfsAio
Definition XrdSfsAio.hh:62
small struct for aio API callbacks
unsigned asyncRdStartCount
XrdSysMutex statsMutex
std::string name

References aiocb::aio_nbytes, aiocb::aio_offset, CephFileRef::asyncRdStartCount, ceph_aio_read_complete(), checkAndCreateCluster(), CephFileRef::flags, getCephPoolIdxAndIncrease(), getFileRef(), getRadosStriper(), CephFile::name, XrdSfsAio::sfsAio, and CephFileRef::statsMutex.

Referenced by XrdCephOssFile::Read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_aio_write()

ssize_t ceph_aio_write ( int fd,
XrdSfsAio * aiop,
AioCB * cb )

Definition at line 839 of file XrdCephPosix.cc.

839 {
840 CephFileRef* fr = getFileRef(fd);
841 if (fr) {
842 // get the parameters from the Xroot aio object
843 size_t count = aiop->sfsAio.aio_nbytes;
844 const char *buf = (const char*)aiop->sfsAio.aio_buf;
845 size_t offset = aiop->sfsAio.aio_offset;
846 // TODO implement proper logging level for this plugin - this should be only debug
847 //logwrapper((char*)"ceph_aio_write: for fd %d, count=%d", fd, count);
848 if ((fr->flags & (O_WRONLY|O_RDWR)) == 0) {
849 return -EBADF;
850 }
851 // get the striper object
852 libradosstriper::RadosStriper *striper = getRadosStriper(*fr);
853 if (0 == striper) {
854 return -EINVAL;
855 }
856 // prepare a bufferlist around the given buffer
857 ceph::bufferlist bl;
858 bl.append(buf, count);
859 // get the poolIdx to use
860 int cephPoolIdx = getCephPoolIdxAndIncrease();
861 // Get the cluster to use
862 librados::Rados* cluster = checkAndCreateCluster(cephPoolIdx);
863 if (0 == cluster) {
864 return -EINVAL;
865 }
866 // prepare a ceph AioCompletion object and do async call
867 AioArgs *args = new AioArgs(aiop, cb, count, fd);
868 librados::AioCompletion *completion =
869 cluster->aio_create_completion(args, ceph_aio_write_complete, NULL);
870 // do the write
871 int rc = striper->aio_write(fr->name, completion, bl, count, offset);
872 completion->release();
874 fr->asyncWrStartCount++;
875 ::gettimeofday(&fr->lastAsyncSubmission, nullptr);
876 fr->bytesAsyncWritePending+=count;
877 return rc;
878 } else {
879 return -EBADF;
880 }
881}
static void ceph_aio_write_complete(rados_completion_t c, void *arg)
void * aio_buf
Definition XrdSfsAio.hh:47
uint64_t bytesAsyncWritePending
unsigned asyncWrStartCount
::timeval lastAsyncSubmission

References aiocb::aio_buf, aiocb::aio_nbytes, aiocb::aio_offset, CephFileRef::asyncWrStartCount, CephFileRef::bytesAsyncWritePending, ceph_aio_write_complete(), checkAndCreateCluster(), CephFileRef::flags, getCephPoolIdxAndIncrease(), getFileRef(), getRadosStriper(), CephFileRef::lastAsyncSubmission, CephFile::name, XrdSfsAio::sfsAio, and CephFileRef::statsMutex.

Referenced by XrdCephOssFile::Write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_close()

int ceph_posix_close ( int fd)

Definition at line 696 of file XrdCephPosix.cc.

696 {
697 CephFileRef* fr = getFileRef(fd);
698 if (fr) {
699 ::timeval now;
700 ::gettimeofday(&now, nullptr);
702 double lastAsyncAge = 0.0;
703 // Only compute an age if the starting point was set.
704 if (fr->lastAsyncSubmission.tv_sec && fr->lastAsyncSubmission.tv_usec) {
705 lastAsyncAge = 1.0 * (now.tv_sec - fr->lastAsyncSubmission.tv_sec)
706 + 0.000001 * (now.tv_usec - fr->lastAsyncSubmission.tv_usec);
707 }
708 logwrapper((char*)"ceph_close: closed fd %d for file %s, read ops count %d, write ops count %d, "
709 "async write ops %d/%d, async pending write bytes %ld, "
710 "async read ops %d/%d, bytes written/max offset %ld/%ld, "
711 "longest async write %f, longest callback invocation %f, last async op age %f",
712 fd, fr->name.c_str(), fr->rdcount, fr->wrcount,
715 fr->longestAsyncWriteTime, fr->longestCallbackInvocation, (lastAsyncAge));
716 deleteFileRef(fd, *fr);
717 return 0;
718 } else {
719 return -EBADF;
720 }
721}
void deleteFileRef(int fd, const CephFileRef &fr)
deletes a FileRef from the global table of file descriptors
static void logwrapper(char *format,...)
uint64_t maxOffsetWritten
double longestCallbackInvocation
uint64_t bytesWritten
double longestAsyncWriteTime
unsigned wrcount
unsigned rdcount
unsigned asyncWrCompletionCount
unsigned asyncRdCompletionCount

References CephFileRef::asyncRdCompletionCount, CephFileRef::asyncRdStartCount, CephFileRef::asyncWrCompletionCount, CephFileRef::asyncWrStartCount, CephFileRef::bytesAsyncWritePending, CephFileRef::bytesWritten, deleteFileRef(), getFileRef(), CephFileRef::lastAsyncSubmission, logwrapper(), CephFileRef::longestAsyncWriteTime, CephFileRef::longestCallbackInvocation, CephFileRef::maxOffsetWritten, CephFile::name, CephFileRef::rdcount, CephFileRef::statsMutex, and CephFileRef::wrcount.

Referenced by XrdCephOssFile::Close().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_closedir()

int ceph_posix_closedir ( DIR * dirp)

Definition at line 1319 of file XrdCephPosix.cc.

1319 {
1320 delete ((DirIterator*)dirp);
1321 return 0;
1322}
small struct for directory listing

Referenced by XrdCephOssDir::Close().

+ Here is the caller graph for this function:

◆ ceph_posix_disconnect_all()

void ceph_posix_disconnect_all ( )

Definition at line 609 of file XrdCephPosix.cc.

609 {
611 for (unsigned int i= 0; i < g_maxCephPoolIdx; i++) {
612 for (StriperDict::iterator it2 = g_radosStripers[i].begin();
613 it2 != g_radosStripers[i].end();
614 it2++) {
615 delete it2->second;
616 }
617 for (IOCtxDict::iterator it2 = g_ioCtx[i].begin();
618 it2 != g_ioCtx[i].end();
619 it2++) {
620 delete it2->second;
621 }
622 delete g_cluster[i];
623 }
624 g_radosStripers.clear();
625 g_ioCtx.clear();
626 g_cluster.clear();
627}
std::vector< librados::Rados * > g_cluster
XrdSysMutex g_striper_mutex
mutex protecting the striper and ioctx maps
std::vector< IOCtxDict > g_ioCtx
unsigned int g_maxCephPoolIdx
std::vector< StriperDict > g_radosStripers

References g_cluster, g_ioCtx, g_maxCephPoolIdx, g_radosStripers, and g_striper_mutex.

Referenced by XrdCephOss::~XrdCephOss().

+ Here is the caller graph for this function:

◆ ceph_posix_fcntl()

int ceph_posix_fcntl ( int fd,
int cmd,
... )

Definition at line 1058 of file XrdCephPosix.cc.

1058 {
1059 CephFileRef* fr = getFileRef(fd);
1060 if (fr) {
1061 logwrapper((char*)"ceph_fcntl: fd %d cmd=%d", fd, cmd);
1062 // minimal implementation
1063 switch (cmd) {
1064 case F_GETFL:
1065 return fr->mode;
1066 default:
1067 return -EINVAL;
1068 }
1069 } else {
1070 return -EBADF;
1071 }
1072}

References getFileRef(), logwrapper(), and CephFileRef::mode.

+ Here is the call graph for this function:

◆ ceph_posix_fgetxattr()

ssize_t ceph_posix_fgetxattr ( int fd,
const char * name,
void * value,
size_t size )

Definition at line 1095 of file XrdCephPosix.cc.

1096 {
1097 CephFileRef* fr = getFileRef(fd);
1098 if (fr) {
1099 logwrapper((char*)"ceph_fgetxattr: fd %d name=%s", fd, name);
1100 return ceph_posix_internal_getxattr(*fr, name, value, size);
1101 } else {
1102 return -EBADF;
1103 }
1104}
static ssize_t ceph_posix_internal_getxattr(const CephFile &file, const char *name, void *value, size_t size)

References ceph_posix_internal_getxattr(), getFileRef(), and logwrapper().

Referenced by XrdCephXAttr::Get().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_flistxattrs()

int ceph_posix_flistxattrs ( int fd,
XrdSysXAttr::AList ** aPL,
int getSz )

Definition at line 1207 of file XrdCephPosix.cc.

1207 {
1208 CephFileRef* fr = getFileRef(fd);
1209 if (fr) {
1210 logwrapper((char*)"ceph_flistxattrs: fd %d", fd);
1211 return ceph_posix_internal_listxattrs(*fr, aPL, getSz);
1212 } else {
1213 return -EBADF;
1214 }
1215}
static int ceph_posix_internal_listxattrs(const CephFile &file, XrdSysXAttr::AList **aPL, int getSz)

References ceph_posix_internal_listxattrs(), getFileRef(), and logwrapper().

Referenced by XrdCephXAttr::List().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_freexattrlist()

void ceph_posix_freexattrlist ( XrdSysXAttr::AList * aPL)

Definition at line 1217 of file XrdCephPosix.cc.

1217 {
1218 while (aPL) {
1219 free(aPL->Name);
1220 XrdSysXAttr::AList *cur = aPL;
1221 aPL = aPL->Next;
1222 free(cur);
1223 }
1224}
char Name[1]
Start of the name (size of struct is dynamic)
AList * Next
-> next element.

References XrdSysXAttr::AList::Name, and XrdSysXAttr::AList::Next.

Referenced by XrdCephXAttr::Free().

+ Here is the caller graph for this function:

◆ ceph_posix_fremovexattr()

int ceph_posix_fremovexattr ( int fd,
const char * name )

Definition at line 1158 of file XrdCephPosix.cc.

1158 {
1159 CephFileRef* fr = getFileRef(fd);
1160 if (fr) {
1161 logwrapper((char*)"ceph_fremovexattr: fd %d name=%s", fd, name);
1162 return ceph_posix_internal_removexattr(*fr, name);
1163 } else {
1164 return -EBADF;
1165 }
1166}
static int ceph_posix_internal_removexattr(const CephFile &file, const char *name)

References ceph_posix_internal_removexattr(), getFileRef(), and logwrapper().

+ Here is the call graph for this function:

◆ ceph_posix_fsetxattr()

int ceph_posix_fsetxattr ( int fd,
const char * name,
const void * value,
size_t size,
int flags )

Definition at line 1128 of file XrdCephPosix.cc.

1130 {
1131 CephFileRef* fr = getFileRef(fd);
1132 if (fr) {
1133 logwrapper((char*)"ceph_fsetxattr: fd %d name=%s value=%s", fd, name, value);
1134 return ceph_posix_internal_setxattr(*fr, name, value, size, flags);
1135 } else {
1136 return -EBADF;
1137 }
1138}
static ssize_t ceph_posix_internal_setxattr(const CephFile &file, const char *name, const void *value, size_t size, int flags)

References ceph_posix_internal_setxattr(), getFileRef(), and logwrapper().

Referenced by XrdCephXAttr::Set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_fstat()

int ceph_posix_fstat ( int fd,
struct stat * buf )

Definition at line 993 of file XrdCephPosix.cc.

993 {
994 CephFileRef* fr = getFileRef(fd);
995 if (fr) {
996 logwrapper((char*)"ceph_stat: fd %d", fd);
997 // minimal stat : only size and times are filled
998 // atime, mtime and ctime are set all to the same value
999 // mode is set arbitrarily to 0666 | S_IFREG
1000 libradosstriper::RadosStriper *striper = getRadosStriper(*fr);
1001 if (0 == striper) {
1002 logwrapper((char*)"ceph_stat: getRadosStriper failed");
1003 return -EINVAL;
1004 }
1005 memset(buf, 0, sizeof(*buf));
1006 int rc = striper->stat(fr->name, (uint64_t*)&(buf->st_size), &(buf->st_atime));
1007 if (rc != 0) {
1008 return -rc;
1009 }
1010 buf->st_mtime = buf->st_atime;
1011 buf->st_ctime = buf->st_atime;
1012 buf->st_mode = 0666 | S_IFREG;
1013 return 0;
1014 } else {
1015 return -EBADF;
1016 }
1017}

References getFileRef(), getRadosStriper(), logwrapper(), and CephFile::name.

Referenced by XrdCephOssFile::Fstat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_fsync()

int ceph_posix_fsync ( int fd)

Definition at line 1047 of file XrdCephPosix.cc.

1047 {
1048 CephFileRef* fr = getFileRef(fd);
1049 if (fr) {
1050 // no locking of fr as it is not used.
1051 logwrapper((char*)"ceph_sync: fd %d", fd);
1052 return 0;
1053 } else {
1054 return -EBADF;
1055 }
1056}

References getFileRef(), and logwrapper().

Referenced by XrdCephOssFile::Fsync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_ftruncate()

int ceph_posix_ftruncate ( int fd,
unsigned long long size )

Definition at line 1253 of file XrdCephPosix.cc.

1253 {
1254 CephFileRef* fr = getFileRef(fd);
1255 if (fr) {
1256 logwrapper((char*)"ceph_posix_ftruncate: fd %d, size %d", fd, size);
1257 return ceph_posix_internal_truncate(*fr, size);
1258 } else {
1259 return -EBADF;
1260 }
1261}
static int ceph_posix_internal_truncate(const CephFile &file, unsigned long long size)

References ceph_posix_internal_truncate(), getFileRef(), and logwrapper().

Referenced by XrdCephOssFile::Ftruncate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_getxattr()

ssize_t ceph_posix_getxattr ( XrdOucEnv * env,
const char * path,
const char * name,
void * value,
size_t size )

Definition at line 1088 of file XrdCephPosix.cc.

1090 {
1091 logwrapper((char*)"ceph_getxattr: path %s name=%s", path, name);
1092 return ceph_posix_internal_getxattr(getCephFile(path, env), name, value, size);
1093}
static CephFile getCephFile(const char *path, XrdOucEnv *env)

References ceph_posix_internal_getxattr(), getCephFile(), and logwrapper().

Referenced by XrdCephXAttr::Get().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_listxattrs()

int ceph_posix_listxattrs ( XrdOucEnv * env,
const char * path,
XrdSysXAttr::AList ** aPL,
int getSz )

Definition at line 1202 of file XrdCephPosix.cc.

1202 {
1203 logwrapper((char*)"ceph_listxattrs: path %s", path);
1204 return ceph_posix_internal_listxattrs(getCephFile(path, env), aPL, getSz);
1205}

References ceph_posix_internal_listxattrs(), getCephFile(), and logwrapper().

Referenced by XrdCephXAttr::List().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_lseek()

off_t ceph_posix_lseek ( int fd,
off_t offset,
int whence )

Definition at line 737 of file XrdCephPosix.cc.

737 {
738 CephFileRef* fr = getFileRef(fd);
739 if (fr) {
740 logwrapper((char*)"ceph_lseek: for fd %d, offset=%lld, whence=%d", fd, offset, whence);
741 return (off_t)lseek_compute_offset(*fr, offset, whence);
742 } else {
743 return -EBADF;
744 }
745}
static off64_t lseek_compute_offset(CephFileRef &fr, off64_t offset, int whence)

References getFileRef(), logwrapper(), and lseek_compute_offset().

+ Here is the call graph for this function:

◆ ceph_posix_lseek64()

off64_t ceph_posix_lseek64 ( int fd,
off64_t offset,
int whence )

Definition at line 747 of file XrdCephPosix.cc.

747 {
748 CephFileRef* fr = getFileRef(fd);
749 if (fr) {
750 logwrapper((char*)"ceph_lseek64: for fd %d, offset=%lld, whence=%d", fd, offset, whence);
751 return lseek_compute_offset(*fr, offset, whence);
752 } else {
753 return -EBADF;
754 }
755}

References getFileRef(), logwrapper(), and lseek_compute_offset().

+ Here is the call graph for this function:

◆ ceph_posix_open()

int ceph_posix_open ( XrdOucEnv * env,
const char * pathname,
int flags,
mode_t mode )
  • brief ceph_posix_open function opens a file for read or write
  • details This function either:
  • Opens a file for reading. If the file doesn't exist, this is an error.
  • Opens a file for writing. If the file already exists, check whether overwrite has been requested. If overwrite
  • hasn't been requested for an existing file, this is an error.
  • param env XrdOucEnv* Unused
  • param pathname const char* Specify the file to open.
  • param flags int Indicates whether reading or writing, and whether to overwrite an existing file.
  • param mode mode_t Unused
  • return int This is a file descriptor (non-negative) if the operation is successful,
  • or an error code (negative value) if the operation fails

Definition at line 649 of file XrdCephPosix.cc.

649 {
650
651 CephFileRef fr = getCephFileRef(pathname, env, flags, mode, 0);
652
653 struct stat buf;
654 libradosstriper::RadosStriper *striper = getRadosStriper(fr); //Get a handle to the RADOS striper API
655
656 if (NULL == striper) {
657 logwrapper((char*)"Cannot create striper");
658 return -EINVAL;
659 }
660
661 int rc = striper->stat(fr.name, (uint64_t*)&(buf.st_size), &(buf.st_atime)); //Get details about a file
662
663
664 bool fileExists = (rc != -ENOENT); //Make clear what condition we are testing
665
666 if ((flags&O_ACCMODE) == O_RDONLY) { // Access mode is READ
667
668 if (fileExists) {
669 int fd = insertFileRef(fr);
670 logwrapper((char*)"File descriptor %d associated to file %s opened in read mode", fd, pathname);
671 return fd;
672 } else {
673 return -ENOENT;
674 }
675
676 } else { // Access mode is WRITE
677 if (fileExists) {
678 if (flags & O_TRUNC) {
679 int rc = ceph_posix_unlink(env, pathname);
680 if (rc < 0 && rc != -ENOENT) {
681 return rc;
682 }
683 } else {
684 return -EEXIST;
685 }
686 }
687 // At this point, we know either the target file didn't exist, or the ceph_posix_unlink above removed it
688 int fd = insertFileRef(fr);
689 logwrapper((char*)"File descriptor %d associated to file %s opened in write mode", fd, pathname);
690 return fd;
691
692 }
693
694}
int ceph_posix_unlink(XrdOucEnv *env, const char *pathname)
int insertFileRef(CephFileRef &fr)
static CephFileRef getCephFileRef(const char *path, XrdOucEnv *env, int flags, mode_t mode, unsigned long long offset)
#define stat(a, b)
Definition XrdPosix.hh:96

References ceph_posix_unlink(), getCephFileRef(), getRadosStriper(), insertFileRef(), logwrapper(), CephFile::name, and stat.

Referenced by XrdCephOssFile::Open().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_opendir()

DIR * ceph_posix_opendir ( XrdOucEnv * env,
const char * pathname )

Definition at line 1281 of file XrdCephPosix.cc.

1281 {
1282 logwrapper((char*)"ceph_posix_opendir : %s", pathname);
1283 // only accept root dir, as there is no concept of dirs in object stores
1284 CephFile file = getCephFile(pathname, env);
1285 if (file.name.size() != 1 || file.name[0] != '/') {
1286 errno = -ENOENT;
1287 return 0;
1288 }
1289 librados::IoCtx *ioctx = getIoCtx(file);
1290 if (0 == ioctx) {
1291 errno = EINVAL;
1292 return 0;
1293 }
1294 DirIterator* res = new DirIterator();
1295 res->m_iterator = ioctx->nobjects_begin();
1296 res->m_ioctx = ioctx;
1297 return (DIR*)res;
1298}
static librados::IoCtx * getIoCtx(const CephFile &file)
librados::IoCtx * m_ioctx
librados::NObjectIterator m_iterator
small structs to store file metadata

References getCephFile(), getIoCtx(), logwrapper(), DirIterator::m_ioctx, DirIterator::m_iterator, and CephFile::name.

Referenced by XrdCephOssDir::Opendir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_pread()

ssize_t ceph_posix_pread ( int fd,
void * buf,
size_t count,
off64_t offset )

Definition at line 908 of file XrdCephPosix.cc.

908 {
909 CephFileRef* fr = getFileRef(fd);
910 if (fr) {
911 // TODO implement proper logging level for this plugin - this should be only debug
912 //logwrapper((char*)"ceph_read: for fd %d, count=%d", fd, count);
913 if ((fr->flags & O_WRONLY) != 0) {
914 return -EBADF;
915 }
916 libradosstriper::RadosStriper *striper = getRadosStriper(*fr);
917 if (0 == striper) {
918 return -EINVAL;
919 }
920 ceph::bufferlist bl;
921 int rc = striper->read(fr->name, &bl, count, offset);
922 if (rc < 0) return rc;
923 bl.begin().copy(rc, (char*)buf);
925 fr->rdcount++;
926 return rc;
927 } else {
928 return -EBADF;
929 }
930}

References CephFileRef::flags, getFileRef(), getRadosStriper(), CephFile::name, CephFileRef::rdcount, and CephFileRef::statsMutex.

Referenced by XrdCephOssFile::Read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_pwrite()

ssize_t ceph_posix_pwrite ( int fd,
const void * buf,
size_t count,
off64_t offset )

Definition at line 783 of file XrdCephPosix.cc.

783 {
784 CephFileRef* fr = getFileRef(fd);
785 if (fr) {
786 // TODO implement proper logging level for this plugin - this should be only debug
787 //logwrapper((char*)"ceph_write: for fd %d, count=%d", fd, count);
788 if ((fr->flags & (O_WRONLY|O_RDWR)) == 0) {
789 return -EBADF;
790 }
791 libradosstriper::RadosStriper *striper = getRadosStriper(*fr);
792 if (0 == striper) {
793 return -EINVAL;
794 }
795 ceph::bufferlist bl;
796 bl.append((const char*)buf, count);
797 int rc = striper->write(fr->name, bl, count, offset);
798 if (rc) return rc;
800 fr->wrcount++;
801 fr->bytesWritten+=count;
802 if (offset + count) fr->maxOffsetWritten = std::max(uint64_t(offset + count - 1), fr->maxOffsetWritten);
803 return count;
804 } else {
805 return -EBADF;
806 }
807}

References CephFileRef::bytesWritten, CephFileRef::flags, getFileRef(), getRadosStriper(), CephFileRef::maxOffsetWritten, CephFile::name, CephFileRef::statsMutex, and CephFileRef::wrcount.

Referenced by XrdCephOssFile::Write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_read()

ssize_t ceph_posix_read ( int fd,
void * buf,
size_t count )

Definition at line 883 of file XrdCephPosix.cc.

883 {
884 CephFileRef* fr = getFileRef(fd);
885 if (fr) {
886 // TODO implement proper logging level for this plugin - this should be only debug
887 //logwrapper((char*)"ceph_read: for fd %d, count=%d", fd, count);
888 if ((fr->flags & O_WRONLY) != 0) {
889 return -EBADF;
890 }
891 libradosstriper::RadosStriper *striper = getRadosStriper(*fr);
892 if (0 == striper) {
893 return -EINVAL;
894 }
895 ceph::bufferlist bl;
896 int rc = striper->read(fr->name, &bl, count, fr->offset);
897 if (rc < 0) return rc;
898 bl.begin().copy(rc, (char*)buf);
900 fr->offset += rc;
901 fr->rdcount++;
902 return rc;
903 } else {
904 return -EBADF;
905 }
906}
uint64_t offset

References CephFileRef::flags, getFileRef(), getRadosStriper(), CephFile::name, CephFileRef::offset, CephFileRef::rdcount, and CephFileRef::statsMutex.

+ Here is the call graph for this function:

◆ ceph_posix_readdir()

int ceph_posix_readdir ( DIR * dirp,
char * buff,
int blen )

Definition at line 1300 of file XrdCephPosix.cc.

1300 {
1301 librados::NObjectIterator &iterator = ((DirIterator*)dirp)->m_iterator;
1302 librados::IoCtx *ioctx = ((DirIterator*)dirp)->m_ioctx;
1303 while (iterator->get_oid().compare(iterator->get_oid().size()-17, 17, ".0000000000000000") &&
1304 iterator != ioctx->nobjects_end()) {
1305 iterator++;
1306 }
1307 if (iterator == ioctx->nobjects_end()) {
1308 buff[0] = 0;
1309 } else {
1310 int l = iterator->get_oid().size()-17;
1311 if (l < blen) blen = l;
1312 strncpy(buff, iterator->get_oid().c_str(), blen-1);
1313 buff[blen-1] = 0;
1314 iterator++;
1315 }
1316 return 0;
1317}

References DirIterator::m_iterator.

Referenced by XrdCephOssDir::Readdir().

+ Here is the caller graph for this function:

◆ ceph_posix_removexattr()

int ceph_posix_removexattr ( XrdOucEnv * env,
const char * path,
const char * name )

Definition at line 1152 of file XrdCephPosix.cc.

1153 {
1154 logwrapper((char*)"ceph_removexattr: path %s name=%s", path, name);
1155 return ceph_posix_internal_removexattr(getCephFile(path, env), name);
1156}

References ceph_posix_internal_removexattr(), getCephFile(), and logwrapper().

Referenced by XrdCephXAttr::Del().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_set_defaults()

void ceph_posix_set_defaults ( const char * value)

sets the default userId, pool and file layout syntax is [user@]pool[,nbStripes[,stripeUnit[,objectSize]]] may throw std::invalid_argument or std::out_of_range in case of error

Definition at line 386 of file XrdCephPosix.cc.

386 {
387 if (value) {
388 CephFile newdefault;
389 fillCephFileParams(value, NULL, newdefault);
390 g_defaultParams = newdefault;
391 }
392}
CephFile g_defaultParams
global variable containing defaults for CephFiles
void fillCephFileParams(const std::string &params, XrdOucEnv *env, CephFile &file)

References fillCephFileParams(), and g_defaultParams.

Referenced by XrdOssGetStorageSystem(), and XrdSysGetXAttrObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_set_logfunc()

void ceph_posix_set_logfunc ( void(* logfunc )(char *, va_list argp))

Definition at line 629 of file XrdCephPosix.cc.

629 {
630 g_logfunc = logfunc;
631};
static void(* g_logfunc)(char *, va_list argp)=0
global variable for the log function

References g_logfunc.

Referenced by XrdOssGetStorageSystem().

+ Here is the caller graph for this function:

◆ ceph_posix_setxattr()

ssize_t ceph_posix_setxattr ( XrdOucEnv * env,
const char * path,
const char * name,
const void * value,
size_t size,
int flags )

Definition at line 1121 of file XrdCephPosix.cc.

1123 {
1124 logwrapper((char*)"ceph_setxattr: path %s name=%s value=%s", path, name, value);
1125 return ceph_posix_internal_setxattr(getCephFile(path, env), name, value, size, flags);
1126}

References ceph_posix_internal_setxattr(), getCephFile(), and logwrapper().

Referenced by XrdCephXAttr::Set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_stat()

int ceph_posix_stat ( XrdOucEnv * env,
const char * pathname,
struct stat * buf )

Definition at line 1019 of file XrdCephPosix.cc.

1019 {
1020 logwrapper((char*)"ceph_stat: %s", pathname);
1021 // minimal stat : only size and times are filled
1022 // atime, mtime and ctime are set all to the same value
1023 // mode is set arbitrarily to 0666 | S_IFREG
1024 CephFile file = getCephFile(pathname, env);
1025 libradosstriper::RadosStriper *striper = getRadosStriper(file);
1026 if (0 == striper) {
1027 return -EINVAL;
1028 }
1029 memset(buf, 0, sizeof(*buf));
1030 int rc = striper->stat(file.name, (uint64_t*)&(buf->st_size), &(buf->st_atime));
1031 if (rc != 0) {
1032 // for non existing file. Check that we did not open it for write recently
1033 // in that case, we return 0 size and current time
1034 if (-ENOENT == rc && isOpenForWrite(file.name)) {
1035 buf->st_size = 0;
1036 buf->st_atime = time(NULL);
1037 } else {
1038 return -rc;
1039 }
1040 }
1041 buf->st_mtime = buf->st_atime;
1042 buf->st_ctime = buf->st_atime;
1043 buf->st_mode = 0666 | S_IFREG;
1044 return 0;
1045}
bool isOpenForWrite(std::string &name)
check whether a file is open for write

References getCephFile(), getRadosStriper(), isOpenForWrite(), logwrapper(), and CephFile::name.

Referenced by XrdCephOss::Stat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_statfs()

int ceph_posix_statfs ( long long * totalSpace,
long long * freeSpace )

Definition at line 1226 of file XrdCephPosix.cc.

1226 {
1227 logwrapper((char*)"ceph_posix_statfs");
1228 // get the poolIdx to use
1229 int cephPoolIdx = getCephPoolIdxAndIncrease();
1230 // Get the cluster to use
1231 librados::Rados* cluster = checkAndCreateCluster(cephPoolIdx);
1232 if (0 == cluster) {
1233 return -EINVAL;
1234 }
1235 // call ceph stat
1236 librados::cluster_stat_t result;
1237 int rc = cluster->cluster_stat(result);
1238 if (0 == rc) {
1239 *totalSpace = result.kb * 1024;
1240 *freeSpace = result.kb_avail * 1024;
1241 }
1242 return rc;
1243}

References checkAndCreateCluster(), getCephPoolIdxAndIncrease(), and logwrapper().

Referenced by XrdCephOss::StatVS().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_truncate()

int ceph_posix_truncate ( XrdOucEnv * env,
const char * pathname,
unsigned long long size )

Definition at line 1263 of file XrdCephPosix.cc.

1263 {
1264 logwrapper((char*)"ceph_posix_truncate : %s", pathname);
1265 // minimal stat : only size and times are filled
1266 CephFile file = getCephFile(pathname, env);
1267 return ceph_posix_internal_truncate(file, size);
1268}

References ceph_posix_internal_truncate(), getCephFile(), and logwrapper().

Referenced by XrdCephOss::Truncate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_unlink()

int ceph_posix_unlink ( XrdOucEnv * env,
const char * pathname )

Definition at line 1270 of file XrdCephPosix.cc.

1270 {
1271 logwrapper((char*)"ceph_posix_unlink : %s", pathname);
1272 // minimal stat : only size and times are filled
1273 CephFile file = getCephFile(pathname, env);
1274 libradosstriper::RadosStriper *striper = getRadosStriper(file);
1275 if (0 == striper) {
1276 return -EINVAL;
1277 }
1278 return striper->remove(file.name);
1279}

References getCephFile(), getRadosStriper(), logwrapper(), and CephFile::name.

Referenced by ceph_posix_open(), and XrdCephOss::Unlink().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ceph_posix_write()

ssize_t ceph_posix_write ( int fd,
const void * buf,
size_t count )

Definition at line 757 of file XrdCephPosix.cc.

757 {
758 CephFileRef* fr = getFileRef(fd);
759 if (fr) {
760 logwrapper((char*)"ceph_write: for fd %d, count=%d", fd, count);
761 if ((fr->flags & (O_WRONLY|O_RDWR)) == 0) {
762 return -EBADF;
763 }
764 libradosstriper::RadosStriper *striper = getRadosStriper(*fr);
765 if (0 == striper) {
766 return -EINVAL;
767 }
768 ceph::bufferlist bl;
769 bl.append((const char*)buf, count);
770 int rc = striper->write(fr->name, bl, count, fr->offset);
771 if (rc) return rc;
772 fr->offset += count;
774 fr->wrcount++;
775 fr->bytesWritten+=count;
776 if (fr->offset) fr->maxOffsetWritten = std::max(fr->offset - 1, fr->maxOffsetWritten);
777 return count;
778 } else {
779 return -EBADF;
780 }
781}

References CephFileRef::bytesWritten, CephFileRef::flags, getFileRef(), getRadosStriper(), logwrapper(), CephFileRef::maxOffsetWritten, CephFile::name, CephFileRef::offset, CephFileRef::statsMutex, and CephFileRef::wrcount.

+ Here is the call graph for this function: