XRootD
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 
28 #include "XrdCeph/XrdCephPosix.hh"
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 
39 XrdCephOssFile::XrdCephOssFile(XrdCephOss *cephOss) : m_fd(-1), m_cephOss(cephOss) {}
40 
41 int 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 
53 int XrdCephOssFile::Close(long long *retsz) {
54  return ceph_posix_close(m_fd);
55 }
56 
57 ssize_t XrdCephOssFile::Read(off_t offset, size_t blen) {
58  return XrdOssOK;
59 }
60 
61 ssize_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 
80 static void aioReadCallback(XrdSfsAio *aiop, size_t rc) {
81  aiop->Result = rc;
82  aiop->doneRead();
83 }
84 
86  return ceph_aio_read(m_fd, aiop, aioReadCallback);
87 }
88 
89 ssize_t XrdCephOssFile::ReadRaw(void *buff, off_t offset, size_t blen) {
90  return Read(buff, offset, blen);
91 }
92 
93 ssize_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 
113 int XrdCephOssFile::Fstat(struct stat *buff) {
114  return ceph_posix_fstat(m_fd, buff);
115 }
116 
117 ssize_t XrdCephOssFile::Write(const void *buff, off_t offset, size_t blen) {
118  return ceph_posix_pwrite(m_fd, buff, blen, offset);
119 }
120 
121 static void aioWriteCallback(XrdSfsAio *aiop, size_t rc) {
122  aiop->Result = rc;
123  aiop->doneWrite();
124 }
125 
127  return ceph_aio_write(m_fd, aiop, aioWriteCallback);
128 }
129 
131  return ceph_posix_fsync(m_fd);
132 }
133 
134 int 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)
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
int stat(const char *path, struct stat *buf)
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)
Definition: XrdSysError.cc:141