From 8756f2f35a86ec0c4afefc5f489886c8cade7d50 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Fri, 24 Mar 2017 10:52:06 +0100 Subject: [PATCH 1/3] XrdCeph: fix ability to read back a file written with O_RDWR flags --- src/XrdCeph/XrdCephPosix.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/XrdCeph/XrdCephPosix.cc b/src/XrdCeph/XrdCephPosix.cc index eb8dc76e3d9..91ad3e6049f 100644 --- a/src/XrdCeph/XrdCephPosix.cc +++ b/src/XrdCeph/XrdCephPosix.cc @@ -742,7 +742,7 @@ ssize_t ceph_posix_read(int fd, void *buf, size_t count) { CephFileRef* fr = getFileRef(fd); if (fr) { logwrapper((char*)"ceph_read: for fd %d, count=%d", fd, count); - if ((fr->flags & (O_WRONLY|O_RDWR)) != 0) { + if ((fr->flags & O_WRONLY) != 0) { return -EBADF; } libradosstriper::RadosStriper *striper = getRadosStriper(*fr); @@ -764,7 +764,7 @@ ssize_t ceph_posix_pread(int fd, void *buf, size_t count, off64_t offset) { CephFileRef* fr = getFileRef(fd); if (fr) { logwrapper((char*)"ceph_read: for fd %d, count=%d", fd, count); - if ((fr->flags & (O_WRONLY|O_RDWR)) != 0) { + if ((fr->flags & O_WRONLY) != 0) { return -EBADF; } libradosstriper::RadosStriper *striper = getRadosStriper(*fr); From 99cdfc212924cadcd2c9a578927b1735cf49b6e0 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Fri, 24 Mar 2017 10:51:17 +0100 Subject: [PATCH 2/3] XrdCeph: disable logging of every read and write operation. A proper debug-level logging would be needed instead. --- src/XrdCeph/XrdCephPosix.cc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/XrdCeph/XrdCephPosix.cc b/src/XrdCeph/XrdCephPosix.cc index 91ad3e6049f..45c09c63632 100644 --- a/src/XrdCeph/XrdCephPosix.cc +++ b/src/XrdCeph/XrdCephPosix.cc @@ -577,7 +577,7 @@ static int ceph_posix_internal_truncate(const CephFile &file, unsigned long long int ceph_posix_open(XrdOucEnv* env, const char *pathname, int flags, mode_t mode) { CephFileRef fr = getCephFileRef(pathname, env, flags, mode, 0); int fd = insertFileRef(fr); - logwrapper((char*)"ceph_open : fd %d associated to %s", fd, pathname); + logwrapper((char*)"ceph_open: fd %d associated to %s", fd, pathname); if (flags & (O_WRONLY|O_RDWR)) { insertOpenForWrite(fr.name); } @@ -674,7 +674,8 @@ ssize_t ceph_posix_write(int fd, const void *buf, size_t count) { ssize_t ceph_posix_pwrite(int fd, const void *buf, size_t count, off64_t offset) { CephFileRef* fr = getFileRef(fd); if (fr) { - logwrapper((char*)"ceph_write: for fd %d, count=%d", fd, count); + // TODO implement proper logging level for this plugin - this should be only debug + //logwrapper((char*)"ceph_write: for fd %d, count=%d", fd, count); if ((fr->flags & (O_WRONLY|O_RDWR)) == 0) { return -EBADF; } @@ -706,11 +707,12 @@ ssize_t ceph_aio_write(int fd, XrdSfsAio *aiop, AioCB *cb) { size_t count = aiop->sfsAio.aio_nbytes; const char *buf = (const char*)aiop->sfsAio.aio_buf; size_t offset = aiop->sfsAio.aio_offset; - // get the striper object - logwrapper((char*)"ceph_aio_write: for fd %d, count=%d", fd, count); + // TODO implement proper logging level for this plugin - this should be only debug + //logwrapper((char*)"ceph_aio_write: for fd %d, count=%d", fd, count); if ((fr->flags & (O_WRONLY|O_RDWR)) == 0) { return -EBADF; } + // get the striper object libradosstriper::RadosStriper *striper = getRadosStriper(*fr); if (0 == striper) { return -EINVAL; @@ -741,7 +743,8 @@ ssize_t ceph_aio_write(int fd, XrdSfsAio *aiop, AioCB *cb) { ssize_t ceph_posix_read(int fd, void *buf, size_t count) { CephFileRef* fr = getFileRef(fd); if (fr) { - logwrapper((char*)"ceph_read: for fd %d, count=%d", fd, count); + // TODO implement proper logging level for this plugin - this should be only debug + //logwrapper((char*)"ceph_read: for fd %d, count=%d", fd, count); if ((fr->flags & O_WRONLY) != 0) { return -EBADF; } @@ -763,7 +766,8 @@ ssize_t ceph_posix_read(int fd, void *buf, size_t count) { ssize_t ceph_posix_pread(int fd, void *buf, size_t count, off64_t offset) { CephFileRef* fr = getFileRef(fd); if (fr) { - logwrapper((char*)"ceph_read: for fd %d, count=%d", fd, count); + // TODO implement proper logging level for this plugin - this should be only debug + //logwrapper((char*)"ceph_read: for fd %d, count=%d", fd, count); if ((fr->flags & O_WRONLY) != 0) { return -EBADF; } @@ -801,11 +805,12 @@ ssize_t ceph_aio_read(int fd, XrdSfsAio *aiop, AioCB *cb) { // get the parameters from the Xroot aio object size_t count = aiop->sfsAio.aio_nbytes; size_t offset = aiop->sfsAio.aio_offset; - // get the striper object - logwrapper((char*)"ceph_read: for fd %d, count=%d", fd, count); - if ((fr->flags & (O_WRONLY|O_RDWR)) != 0) { + // TODO implement proper logging level for this plugin - this should be only debug + //logwrapper((char*)"ceph_aio_read: for fd %d, count=%d", fd, count); + if ((fr->flags & O_WRONLY) != 0) { return -EBADF; } + // get the striper object libradosstriper::RadosStriper *striper = getRadosStriper(*fr); if (0 == striper) { return -EINVAL; @@ -858,7 +863,7 @@ int ceph_posix_fstat(int fd, struct stat *buf) { } int ceph_posix_stat(XrdOucEnv* env, const char *pathname, struct stat *buf) { - logwrapper((char*)"ceph_stat : %s", pathname); + logwrapper((char*)"ceph_stat: %s", pathname); // minimal stat : only size and times are filled // atime, mtime and ctime are set all to the same value // mode is set arbitrarily to 0666 From 4eb1f9368f2decddaa4a06dd2fbc2849b83863e7 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Fri, 24 Mar 2017 11:09:37 +0100 Subject: [PATCH 3/3] XrdCeph: added statistics about read/write operations in the close log --- src/XrdCeph/XrdCephPosix.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/XrdCeph/XrdCephPosix.cc b/src/XrdCeph/XrdCephPosix.cc index 45c09c63632..b60504872a3 100644 --- a/src/XrdCeph/XrdCephPosix.cc +++ b/src/XrdCeph/XrdCephPosix.cc @@ -61,6 +61,8 @@ struct CephFileRef : CephFile { int flags; mode_t mode; unsigned long long offset; + unsigned rdcount; + unsigned wrcount; }; /// small struct for directory listing @@ -405,6 +407,8 @@ static CephFileRef getCephFileRef(const char *path, XrdOucEnv *env, int flags, fr.flags = flags; fr.mode = mode; fr.offset = 0; + fr.rdcount = 0; + fr.wrcount = 0; return fr; } @@ -604,7 +608,8 @@ int ceph_posix_open(XrdOucEnv* env, const char *pathname, int flags, mode_t mode int ceph_posix_close(int fd) { CephFileRef* fr = getFileRef(fd); if (fr) { - logwrapper((char*)"ceph_close: closed fd %d", fd); + logwrapper((char*)"ceph_close: closed fd %d for file %s, read ops count %d, write ops count %d", + fd, fr->name.c_str(), fr->rdcount, fr->wrcount); if (fr->flags & (O_WRONLY|O_RDWR)) { deleteOpenForWrite(fr->name); } @@ -665,6 +670,7 @@ ssize_t ceph_posix_write(int fd, const void *buf, size_t count) { int rc = striper->write(fr->name, bl, count, fr->offset); if (rc) return rc; fr->offset += count; + fr->wrcount++; return count; } else { return -EBADF; @@ -687,6 +693,7 @@ ssize_t ceph_posix_pwrite(int fd, const void *buf, size_t count, off64_t offset) bl.append((const char*)buf, count); int rc = striper->write(fr->name, bl, count, offset); if (rc) return rc; + fr->wrcount++; return count; } else { return -EBADF; @@ -757,6 +764,7 @@ ssize_t ceph_posix_read(int fd, void *buf, size_t count) { if (rc < 0) return rc; bl.copy(0, rc, (char*)buf); fr->offset += rc; + fr->rdcount++; return rc; } else { return -EBADF; @@ -779,6 +787,7 @@ ssize_t ceph_posix_pread(int fd, void *buf, size_t count, off64_t offset) { int rc = striper->read(fr->name, &bl, count, offset); if (rc < 0) return rc; bl.copy(0, rc, (char*)buf); + fr->rdcount++; return rc; } else { return -EBADF;