XRootD
Loading...
Searching...
No Matches
XrdCephOssFile.cc
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2014-2015 by European Organization for Nuclear Research (CERN)
3// Author: Sebastien Ponce <sebastien.ponce@cern.ch>
4//------------------------------------------------------------------------------
5// This file is part of the XRootD software suite.
6//
7// XRootD is free software: you can redistribute it and/or modify
8// it under the terms of the GNU Lesser General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// XRootD is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU Lesser General Public License
18// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19//
20// In applying this licence, CERN does not waive the privileges and immunities
21// granted to it by virtue of its status as an Intergovernmental Organization
22// or submit itself to any jurisdiction.
23//------------------------------------------------------------------------------
24
25#include <sys/types.h>
26#include <unistd.h>
27
29#include "XrdOuc/XrdOucEnv.hh"
30#include "XrdSys/XrdSysError.hh"
31#include "XrdOuc/XrdOucTrace.hh"
32#include "XrdSfs/XrdSfsAio.hh"
33
35#include "XrdCeph/XrdCephOss.hh"
36
38
39XrdCephOssFile::XrdCephOssFile(XrdCephOss *cephOss) : m_fd(-1), m_cephOss(cephOss) {}
40
41int XrdCephOssFile::Open(const char *path, int flags, mode_t mode, XrdOucEnv &env) {
42 try {
43 int rc = ceph_posix_open(&env, path, flags, mode);
44 if (rc < 0) return rc;
45 m_fd = rc;
46 return XrdOssOK;
47 } catch (std::exception &e) {
48 XrdCephEroute.Say("open : invalid syntax in file parameters");
49 return -EINVAL;
50 }
51}
52
53int XrdCephOssFile::Close(long long *retsz) {
54 return ceph_posix_close(m_fd);
55}
56
57ssize_t XrdCephOssFile::Read(off_t offset, size_t blen) {
58 return XrdOssOK;
59}
60
61ssize_t XrdCephOssFile::Read(void *buff, off_t offset, size_t blen) {
62 ssize_t retval;
64 retval = ceph_posix_pread(m_fd, buff, blen, offset);
65 } else {
66 retval = ceph_posix_nonstriper_pread(m_fd, buff, blen, offset);
67 if (-ENOENT == retval || -ENOTSUP == retval) {
68 //This might be a sparse file or nbstripes > 1, so let's try striper read
69 retval = ceph_posix_pread(m_fd, buff, blen, offset);
70 if (retval >= 0) {
71 char err_str[100]; //99 symbols should be enough for the short message
72 snprintf(err_str, 100, "WARNING! The file (fd %d) seem to be sparse, this is not expected", m_fd);
73 XrdCephEroute.Say(err_str);
74 }
75 }
76 }
77 return retval;
78}
79
80static void aioReadCallback(XrdSfsAio *aiop, size_t rc) {
81 aiop->Result = rc;
82 aiop->doneRead();
83}
84
88
89ssize_t XrdCephOssFile::ReadRaw(void *buff, off_t offset, size_t blen) {
90 return Read(buff, offset, blen);
91}
92
93ssize_t XrdCephOssFile::ReadV(XrdOucIOVec *readV, int n) {
94 ssize_t retval;
96 retval = ceph_striper_readv(m_fd, readV, n);
97 } else {
98 retval = ceph_nonstriper_readv(m_fd, readV, n);
99 if (-ENOENT == retval || -ENOTSUP == retval) {
100 //This might be a sparse file or nbstripes > 1, so let's try striper read
101 retval = ceph_striper_readv(m_fd, readV, n);
102 if (retval >= 0) {
103 char err_str[100]; //99 symbols should be enough for the short message
104 snprintf(err_str, 100, "WARNING! The file (fd %d) seem to be sparse, this is not expected", m_fd);
105 XrdCephEroute.Say(err_str);
106 }
107 }
108 }
109 return retval;
110}
111
112
113int XrdCephOssFile::Fstat(struct stat *buff) {
114 return ceph_posix_fstat(m_fd, buff);
115}
116
117ssize_t XrdCephOssFile::Write(const void *buff, off_t offset, size_t blen) {
118 return ceph_posix_pwrite(m_fd, buff, blen, offset);
119}
120
121static void aioWriteCallback(XrdSfsAio *aiop, size_t rc) {
122 aiop->Result = rc;
123 aiop->doneWrite();
124}
125
129
133
134int XrdCephOssFile::Ftruncate(unsigned long long len) {
135 return ceph_posix_ftruncate(m_fd, len);
136}
XrdSysError XrdCephEroute
static void aioReadCallback(XrdSfsAio *aiop, size_t rc)
static void aioWriteCallback(XrdSfsAio *aiop, size_t rc)
XrdSysError XrdCephEroute(0)
Definition XrdCephOss.cc:50
ssize_t ceph_aio_write(int fd, XrdSfsAio *aiop, AioCB *cb)
ssize_t ceph_aio_read(int fd, XrdSfsAio *aiop, AioCB *cb)
ssize_t ceph_nonstriper_readv(int fd, XrdOucIOVec *readV, int n)
ssize_t ceph_posix_pread(int fd, void *buf, size_t count, off64_t offset)
int ceph_posix_fstat(int fd, struct stat *buf)
int ceph_posix_fsync(int fd)
int ceph_posix_close(int fd)
int ceph_posix_ftruncate(int fd, unsigned long long size)
int ceph_posix_open(XrdOucEnv *env, const char *pathname, int flags, mode_t mode)
ssize_t ceph_posix_nonstriper_pread(int fd, void *buf, size_t count, off64_t offset)
ssize_t ceph_striper_readv(int fd, XrdOucIOVec *readV, int n)
ssize_t ceph_posix_pwrite(int fd, const void *buf, size_t count, off64_t offset)
#define XrdOssOK
Definition XrdOss.hh:50
#define stat(a, b)
Definition XrdPosix.hh:101
virtual ssize_t Read(off_t offset, size_t blen)
virtual int Open(const char *path, int flags, mode_t mode, XrdOucEnv &env)
XrdCephOssFile(XrdCephOss *cephoss)
virtual ssize_t Write(const void *buff, off_t offset, size_t blen)
virtual int Fstat(struct stat *buff)
virtual int Ftruncate(unsigned long long)
virtual int Fsync(void)
virtual ssize_t ReadRaw(void *, off_t, size_t)
virtual ssize_t ReadV(XrdOucIOVec *readV, int n)
virtual int Close(long long *retsz=0)
XrdCephOss * m_cephOss
int m_useDefaultPreadAlg
Definition XrdCephOss.hh:78
int m_useDefaultReadvAlg
Definition XrdCephOss.hh:80
ssize_t Result
Definition XrdSfsAio.hh:65
virtual void doneRead()=0
virtual void doneWrite()=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)