XRootD
XrdCephOss.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 <stdio.h>
26 #include <string>
27 #include <fcntl.h>
28 
29 #include "XrdVersion.hh"
30 #include "XrdCeph/XrdCephOss.hh"
31 #include "XrdCeph/XrdCephOssDir.hh"
33 #include "XrdCeph/XrdCephPosix.hh"
34 
35 #include "XrdOuc/XrdOucEnv.hh"
36 #include "XrdSys/XrdSysError.hh"
37 #include "XrdOuc/XrdOucTrace.hh"
38 #include "XrdOuc/XrdOucStream.hh"
41 
43 
45 XrdOucTrace XrdCephTrace(&XrdCephEroute);
46 
47 // log wrapping function to be used by ceph_posix interface
48 char g_logstring[1024];
49 static void logwrapper(char *format, va_list argp) {
50  vsnprintf(g_logstring, 1024, format, argp);
52 }
53 
58 
59 extern "C"
60 {
61  XrdOss*
63  XrdSysLogger* lp,
64  const char* config_fn,
65  const char* parms)
66  {
67  // Do the herald thing
68  XrdCephEroute.SetPrefix("ceph_");
70  XrdCephEroute.Say("++++++ CERN/IT-DSS XrdCeph");
71  // set parameters
72  try {
74  } catch (std::exception &e) {
75  XrdCephEroute.Say("CephOss loading failed with exception. Check the syntax of parameters : ", parms);
76  return 0;
77  }
78  // deal with logging
80  return new XrdCephOss(config_fn, XrdCephEroute);
81  }
82 }
83 
84 XrdCephOss::XrdCephOss(const char *configfn, XrdSysError &Eroute) {
85  Configure(configfn, Eroute);
86 }
87 
90 }
91 
92 // declared and used in XrdCephPosix.cc
93 extern unsigned int g_maxCephPoolIdx;
94 int XrdCephOss::Configure(const char *configfn, XrdSysError &Eroute) {
95  int NoGo = 0;
96  XrdOucEnv myEnv;
97  XrdOucStream Config(&Eroute, getenv("XRDINSTANCE"), &myEnv, "=====> ");
98  // If there is no config file, nothing to be done
99  if (configfn && *configfn) {
100  // Try to open the configuration file.
101  int cfgFD;
102  if ((cfgFD = open(configfn, O_RDONLY, 0)) < 0) {
103  Eroute.Emsg("Config", errno, "open config file", configfn);
104  return 1;
105  }
106  Config.Attach(cfgFD);
107  // Now start reading records until eof.
108  char *var;
109  while((var = Config.GetMyFirstWord())) {
110  if (!strncmp(var, "ceph.nbconnections", 18)) {
111  var = Config.GetWord();
112  if (var) {
113  unsigned long value = strtoul(var, 0, 10);
114  if (value > 0 and value <= 100) {
115  g_maxCephPoolIdx = value;
116  } else {
117  Eroute.Emsg("Config", "Invalid value for ceph.nbconnections in config file (must be between 1 and 100)", configfn, var);
118  return 1;
119  }
120  } else {
121  Eroute.Emsg("Config", "Missing value for ceph.nbconnections in config file", configfn);
122  return 1;
123  }
124  }
125  if (!strncmp(var, "ceph.namelib", 12)) {
126  var = Config.GetWord();
127  if (var) {
128  // Warn in case parameters were givne
129  char parms[1040];
130  if (!Config.GetRest(parms, sizeof(parms)) || parms[0]) {
131  Eroute.Emsg("Config", "namelib parameters will be ignored");
132  }
133  // Load name lib
134  XrdOucN2NLoader n2nLoader(&Eroute,configfn,NULL,NULL,NULL);
135  g_namelib = n2nLoader.Load(var, XrdVERSIONINFOVAR(XrdOssGetStorageSystem), NULL);
136  if (!g_namelib) {
137  Eroute.Emsg("Config", "Unable to load library given in ceph.namelib : %s", var);
138  }
139  } else {
140  Eroute.Emsg("Config", "Missing value for ceph.namelib in config file", configfn);
141  return 1;
142  }
143  }
144  }
145 
146  // Now check if any errors occurred during file i/o
147  int retc = Config.LastError();
148  if (retc) {
149  NoGo = Eroute.Emsg("Config", -retc, "read config file",
150  configfn);
151  }
152  Config.Close();
153  }
154  return NoGo;
155 }
156 
157 int XrdCephOss::Chmod(const char *path, mode_t mode, XrdOucEnv *envP) {
158  return -ENOTSUP;
159 }
160 
161 int XrdCephOss::Create(const char *tident, const char *path, mode_t access_mode,
162  XrdOucEnv &env, int Opts) {
163  return -ENOTSUP;
164 }
165 
166 int XrdCephOss::Init(XrdSysLogger *logger, const char* configFn) { return 0; }
167 
168 //SCS - lie to posix-assuming clients about directories [fixes brittleness in GFAL2]
169 int XrdCephOss::Mkdir(const char *path, mode_t mode, int mkpath, XrdOucEnv *envP) {
170  return 0;
171 }
172 
173 //SCS - lie to posix-assuming clients about directories [fixes brittleness in GFAL2]
174 int XrdCephOss::Remdir(const char *path, int Opts, XrdOucEnv *eP) {
175  return 0;
176 }
177 
178 int XrdCephOss::Rename(const char *from,
179  const char *to,
180  XrdOucEnv *eP1,
181  XrdOucEnv *eP2) {
182  return -ENOTSUP;
183 }
184 
185 int XrdCephOss::Stat(const char* path,
186  struct stat* buff,
187  int opts,
188  XrdOucEnv* env) {
189  try {
190  if (!strcmp(path, "/")) {
191  // special case of a stat made by the locate interface
192  // we intend to then list all files
193  memset(buff, 0, sizeof(*buff));
194  buff->st_mode = S_IFDIR | 0700;
195  return 0;
196  } else {
197  return ceph_posix_stat(env, path, buff);
198  }
199  } catch (std::exception &e) {
200  XrdCephEroute.Say("stat : invalid syntax in file parameters");
201  return -EINVAL;
202  }
203 }
204 
205 int XrdCephOss::StatFS(const char *path, char *buff, int &blen, XrdOucEnv *eP) {
206  XrdOssVSInfo sP;
207  int rc = StatVS(&sP, 0, 0);
208  if (rc) {
209  return rc;
210  }
211  int percentUsedSpace = (sP.Usage*100)/sP.Total;
212  blen = snprintf(buff, blen, "%d %lld %d %d %lld %d",
213  1, sP.Free, percentUsedSpace, 0, 0LL, 0);
214  return XrdOssOK;
215 }
216 
217 int XrdCephOss::StatVS(XrdOssVSInfo *sP, const char *sname, int updt) {
218  int rc = ceph_posix_statfs(&(sP->Total), &(sP->Free));
219  if (rc) {
220  return rc;
221  }
222  sP->Large = sP->Total;
223  sP->LFree = sP->Free;
224  sP->Usage = sP->Total-sP->Free;
225  sP->Extents = 1;
226  return XrdOssOK;
227 }
228 
229 int XrdCephOss::Truncate (const char* path,
230  unsigned long long size,
231  XrdOucEnv* env) {
232  try {
233  return ceph_posix_truncate(env, path, size);
234  } catch (std::exception &e) {
235  XrdCephEroute.Say("truncate : invalid syntax in file parameters");
236  return -EINVAL;
237  }
238 }
239 
240 int XrdCephOss::Unlink(const char *path, int Opts, XrdOucEnv *env) {
241  try {
242  return ceph_posix_unlink(env, path);
243  } catch (std::exception &e) {
244  XrdCephEroute.Say("unlink : invalid syntax in file parameters");
245  return -EINVAL;
246  }
247 }
248 
250  return new XrdCephOssDir(this);
251 }
252 
254  return new XrdCephOssFile(this);
255 }
256 
#define tident
XrdOucName2Name * g_namelib
unsigned int g_maxCephPoolIdx
static void logwrapper(char *format, va_list argp)
Definition: XrdCephOss.cc:49
XrdOss * XrdOssGetStorageSystem(XrdOss *native_oss, XrdSysLogger *lp, const char *config_fn, const char *parms)
Definition: XrdCephOss.cc:62
char g_logstring[1024]
Definition: XrdCephOss.cc:48
XrdVERSIONINFO(XrdOssGetStorageSystem, XrdCephOss)
XrdSysError XrdCephEroute(0)
Definition: XrdCephOss.cc:45
void ceph_posix_set_logfunc(void(*logfunc)(char *, va_list argp))
int ceph_posix_truncate(XrdOucEnv *env, const char *pathname, unsigned long long size)
int ceph_posix_unlink(XrdOucEnv *env, const char *pathname)
void ceph_posix_disconnect_all()
int ceph_posix_statfs(long long *totalSpace, long long *freeSpace)
void ceph_posix_set_defaults(const char *value)
int ceph_posix_stat(XrdOucEnv *env, const char *pathname, struct stat *buf)
#define XrdOssOK
Definition: XrdOss.hh:50
int stat(const char *path, struct stat *buf)
int open(const char *path, int oflag,...)
struct myOpts opts
virtual int Truncate(const char *, unsigned long long, XrdOucEnv *eP=0)
Definition: XrdCephOss.cc:229
virtual int Rename(const char *, const char *, XrdOucEnv *eP1=0, XrdOucEnv *eP2=0)
Definition: XrdCephOss.cc:178
virtual int StatVS(XrdOssVSInfo *sP, const char *sname=0, int updt=0)
Definition: XrdCephOss.cc:217
virtual int Remdir(const char *, int Opts=0, XrdOucEnv *eP=0)
Definition: XrdCephOss.cc:174
virtual int Create(const char *, const char *, mode_t, XrdOucEnv &, int opts=0)
Definition: XrdCephOss.cc:161
XrdCephOss(const char *, XrdSysError &)
Definition: XrdCephOss.cc:84
virtual int Mkdir(const char *, mode_t mode, int mkpath=0, XrdOucEnv *eP=0)
Definition: XrdCephOss.cc:169
virtual int Stat(const char *, struct stat *, int opts=0, XrdOucEnv *eP=0)
Definition: XrdCephOss.cc:185
virtual XrdOssDF * newDir(const char *tident)
Definition: XrdCephOss.cc:249
virtual int Chmod(const char *, mode_t mode, XrdOucEnv *eP=0)
Definition: XrdCephOss.cc:157
virtual int Unlink(const char *path, int Opts=0, XrdOucEnv *eP=0)
Definition: XrdCephOss.cc:240
virtual ~XrdCephOss()
Definition: XrdCephOss.cc:88
virtual int StatFS(const char *path, char *buff, int &blen, XrdOucEnv *eP=0)
Definition: XrdCephOss.cc:205
virtual int Init(XrdSysLogger *, const char *)
Definition: XrdCephOss.cc:166
virtual XrdOssDF * newFile(const char *tident)
Definition: XrdCephOss.cc:253
int Configure(const char *, XrdSysError &)
Definition: XrdCephOss.cc:94
long long LFree
Definition: XrdOssVS.hh:93
long long Usage
Definition: XrdOssVS.hh:94
long long Large
Definition: XrdOssVS.hh:92
long long Total
Definition: XrdOssVS.hh:90
long long Free
Definition: XrdOssVS.hh:91
XrdOucName2Name * Load(const char *libName, XrdVersionInfo &urVer, XrdOucEnv *envP=0)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
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
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition: XrdSysError.hh:141
const char * SetPrefix(const char *prefix)
Definition: XrdSysError.hh:160
XrdCmsConfig Config
int Opts
Definition: XrdMpxStats.cc:58
XrdOucEnv * envP
Definition: XrdPss.cc:109
static INT to(const char *buffer)
Definition: XrdZipUtils.hh:91