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  return ceph_posix_pread(m_fd, buff, blen, offset);
63 }
64 
65 static void aioReadCallback(XrdSfsAio *aiop, size_t rc) {
66  aiop->Result = rc;
67  aiop->doneRead();
68 }
69 
71  return ceph_aio_read(m_fd, aiop, aioReadCallback);
72 }
73 
74 ssize_t XrdCephOssFile::ReadRaw(void *buff, off_t offset, size_t blen) {
75  return Read(buff, offset, blen);
76 }
77 
78 int XrdCephOssFile::Fstat(struct stat *buff) {
79  return ceph_posix_fstat(m_fd, buff);
80 }
81 
82 ssize_t XrdCephOssFile::Write(const void *buff, off_t offset, size_t blen) {
83  return ceph_posix_pwrite(m_fd, buff, blen, offset);
84 }
85 
86 static void aioWriteCallback(XrdSfsAio *aiop, size_t rc) {
87  aiop->Result = rc;
88  aiop->doneWrite();
89 }
90 
92  return ceph_aio_write(m_fd, aiop, aioWriteCallback);
93 }
94 
96  return ceph_posix_fsync(m_fd);
97 }
98 
99 int XrdCephOssFile::Ftruncate(unsigned long long len) {
100  return ceph_posix_ftruncate(m_fd, len);
101 }
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_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_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 int Close(long long *retsz=0)
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