Loading...
Searching...
No Matches
XrdCephOssFile.cc
Go to the documentation of this file.
//------------------------------------------------------------------------------
// Copyright (c) 2014-2015 by European Organization for Nuclear Research (CERN)
// Author: Sebastien Ponce <sebastien.ponce@cern.ch>
//------------------------------------------------------------------------------
// This file is part of the XRootD software suite.
//
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//
// In applying this licence, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
//------------------------------------------------------------------------------
#include <sys/types.h>
#include <unistd.h>
#include "XrdCeph/XrdCephPosix.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdOuc/XrdOucTrace.hh"
#include "XrdSfs/XrdSfsAio.hh"
#include "XrdCeph/XrdCephOssFile.hh"
#include "XrdCeph/XrdCephOss.hh"
extern XrdSysError XrdCephEroute;
XrdCephOssFile::XrdCephOssFile(XrdCephOss *cephOss) : m_fd(-1), m_cephOss(cephOss) {}
int XrdCephOssFile::Open(const char *path, int flags, mode_t mode, XrdOucEnv &env) {
try {
int rc = ceph_posix_open(&env, path, flags, mode);
if (rc < 0) return rc;
m_fd = rc;
return XrdOssOK;
} catch (std::exception &e) {
XrdCephEroute.Say("open : invalid syntax in file parameters");
return -EINVAL;
}
}
int XrdCephOssFile::Close(long long *retsz) {
return ceph_posix_close(m_fd);
}
ssize_t XrdCephOssFile::Read(off_t offset, size_t blen) {
return XrdOssOK;
}
ssize_t XrdCephOssFile::Read(void *buff, off_t offset, size_t blen) {
ssize_t retval;
if (m_cephOss->m_useDefaultPreadAlg) {
retval = ceph_posix_pread(m_fd, buff, blen, offset);
} else {
retval = ceph_posix_nonstriper_pread(m_fd, buff, blen, offset);
if (-ENOENT == retval || -ENOTSUP == retval) {
//This might be a sparse file or nbstripes > 1, so let's try striper read
retval = ceph_posix_pread(m_fd, buff, blen, offset);
if (retval >= 0) {
char err_str[100]; //99 symbols should be enough for the short message
snprintf(err_str, 100, "WARNING! The file (fd %d) seem to be sparse, this is not expected", m_fd);
XrdCephEroute.Say(err_str);
}
}
}
return retval;
}
static void aioReadCallback(XrdSfsAio *aiop, size_t rc) {
aiop->Result = rc;
aiop->doneRead();
}
int XrdCephOssFile::Read(XrdSfsAio *aiop) {
return ceph_aio_read(m_fd, aiop, aioReadCallback);
}
ssize_t XrdCephOssFile::ReadRaw(void *buff, off_t offset, size_t blen) {
return Read(buff, offset, blen);
}
ssize_t XrdCephOssFile::ReadV(XrdOucIOVec *readV, int n) {
ssize_t retval;
if (m_cephOss->m_useDefaultReadvAlg) {
retval = ceph_striper_readv(m_fd, readV, n);
} else {
retval = ceph_nonstriper_readv(m_fd, readV, n);
if (-ENOENT == retval || -ENOTSUP == retval) {
//This might be a sparse file or nbstripes > 1, so let's try striper read
retval = ceph_striper_readv(m_fd, readV, n);
if (retval >= 0) {
char err_str[100]; //99 symbols should be enough for the short message
snprintf(err_str, 100, "WARNING! The file (fd %d) seem to be sparse, this is not expected", m_fd);
XrdCephEroute.Say(err_str);
}
}
}
return retval;
}
int XrdCephOssFile::Fstat(struct stat *buff) {
return ceph_posix_fstat(m_fd, buff);
}
ssize_t XrdCephOssFile::Write(const void *buff, off_t offset, size_t blen) {
return ceph_posix_pwrite(m_fd, buff, blen, offset);
}
static void aioWriteCallback(XrdSfsAio *aiop, size_t rc) {
aiop->Result = rc;
aiop->doneWrite();
}
int XrdCephOssFile::Write(XrdSfsAio *aiop) {
return ceph_aio_write(m_fd, aiop, aioWriteCallback);
}
int XrdCephOssFile::Fsync() {
return ceph_posix_fsync(m_fd);
}
int XrdCephOssFile::Ftruncate(unsigned long long len) {
return ceph_posix_ftruncate(m_fd, len);
}
aioReadCallback
static void aioReadCallback(XrdSfsAio *aiop, size_t rc)
Definition XrdCephOssFile.cc:80
aioWriteCallback
static void aioWriteCallback(XrdSfsAio *aiop, size_t rc)
Definition XrdCephOssFile.cc:121
XrdCephOssFile.hh
XrdCephEroute
XrdSysError XrdCephEroute(0)
Definition XrdCephOss.cc:50
XrdCephOss.hh
ceph_aio_write
ssize_t ceph_aio_write(int fd, XrdSfsAio *aiop, AioCB *cb)
Definition XrdCephPosix.cc:903
ceph_aio_read
ssize_t ceph_aio_read(int fd, XrdSfsAio *aiop, AioCB *cb)
Definition XrdCephPosix.cc:1175
ceph_nonstriper_readv
ssize_t ceph_nonstriper_readv(int fd, XrdOucIOVec *readV, int n)
Definition XrdCephPosix.cc:947
ceph_posix_pread
ssize_t ceph_posix_pread(int fd, void *buf, size_t count, off64_t offset)
Definition XrdCephPosix.cc:1110
ceph_posix_fstat
int ceph_posix_fstat(int fd, struct stat *buf)
Definition XrdCephPosix.cc:1215
ceph_posix_fsync
int ceph_posix_fsync(int fd)
Definition XrdCephPosix.cc:1275
ceph_posix_close
int ceph_posix_close(int fd)
Definition XrdCephPosix.cc:760
ceph_posix_ftruncate
int ceph_posix_ftruncate(int fd, unsigned long long size)
Definition XrdCephPosix.cc:1525
ceph_posix_open
int ceph_posix_open(XrdOucEnv *env, const char *pathname, int flags, mode_t mode)
Definition XrdCephPosix.cc:664
ceph_posix_nonstriper_pread
ssize_t ceph_posix_nonstriper_pread(int fd, void *buf, size_t count, off64_t offset)
Definition XrdCephPosix.cc:1048
ceph_striper_readv
ssize_t ceph_striper_readv(int fd, XrdOucIOVec *readV, int n)
Definition XrdCephPosix.cc:1007
ceph_posix_pwrite
ssize_t ceph_posix_pwrite(int fd, const void *buf, size_t count, off64_t offset)
Definition XrdCephPosix.cc:847
XrdCephPosix.hh
XrdOssOK
#define XrdOssOK
Definition XrdOss.hh:50
XrdOucEnv.hh
XrdOucTrace.hh
stat
#define stat(a, b)
Definition XrdPosix.hh:101
XrdSfsAio.hh
XrdSysError.hh
XrdCephOssFile::Read
virtual ssize_t Read(off_t offset, size_t blen)
Definition XrdCephOssFile.cc:57
XrdCephOssFile::Open
virtual int Open(const char *path, int flags, mode_t mode, XrdOucEnv &env)
Definition XrdCephOssFile.cc:41
XrdCephOssFile::XrdCephOssFile
XrdCephOssFile(XrdCephOss *cephoss)
Definition XrdCephOssFile.cc:39
XrdCephOssFile::Write
virtual ssize_t Write(const void *buff, off_t offset, size_t blen)
Definition XrdCephOssFile.cc:117
XrdCephOssFile::Fstat
virtual int Fstat(struct stat *buff)
Definition XrdCephOssFile.cc:113
XrdCephOssFile::Ftruncate
virtual int Ftruncate(unsigned long long)
Definition XrdCephOssFile.cc:134
XrdCephOssFile::Fsync
virtual int Fsync(void)
Definition XrdCephOssFile.cc:130
XrdCephOssFile::ReadRaw
virtual ssize_t ReadRaw(void *, off_t, size_t)
Definition XrdCephOssFile.cc:89
XrdCephOssFile::ReadV
virtual ssize_t ReadV(XrdOucIOVec *readV, int n)
Definition XrdCephOssFile.cc:93
XrdCephOssFile::m_fd
int m_fd
Definition XrdCephOssFile.hh:74
XrdCephOssFile::Close
virtual int Close(long long *retsz=0)
Definition XrdCephOssFile.cc:53
XrdCephOssFile::m_cephOss
XrdCephOss * m_cephOss
Definition XrdCephOssFile.hh:75
XrdCephOss
Definition XrdCephOss.hh:55
XrdOucEnv
Definition XrdOucEnv.hh:42
XrdSfsAio
Definition XrdSfsAio.hh:59
XrdSfsAio::Result
ssize_t Result
Definition XrdSfsAio.hh:65
XrdSfsAio::doneRead
virtual void doneRead()=0
XrdSfsAio::doneWrite
virtual void doneWrite()=0
XrdSysError
Definition XrdSysError.hh:90
XrdOucIOVec
Definition XrdOucIOVec.hh:41