XrdCtaFilesystem.cpp 11.1 KB
Newer Older
1
/*
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2015  CERN
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

19
#include "castor/common/CastorConfiguration.hpp"
Steven Murray's avatar
Steven Murray committed
20
#include "catalogue/CatalogueFactory.hpp"
21
22
23
#include "common/admin/AdminHost.hpp"
#include "common/admin/AdminUser.hpp"
#include "common/archiveRoutes/ArchiveRoute.hpp"
24
#include "common/Configuration.hpp"
25
#include "common/exception/Exception.hpp"
26
#include "common/make_unique.hpp"
27
28
29
#include "common/TapePool.hpp"
#include "objectstore/RootEntry.hpp"
#include "objectstore/BackendFactory.hpp"
30
#include "remotens/MockRemoteNS.hpp"
Daniele Kruse's avatar
Daniele Kruse committed
31
#include "scheduler/LogicalLibrary.hpp"
32
#include "scheduler/OStoreDB/OStoreDB.hpp"
33
#include "scheduler/RetrieveRequestDump.hpp"
Daniele Kruse's avatar
Daniele Kruse committed
34
#include "scheduler/SchedulerDatabase.hpp"
35
36
37
#include "XrdOuc/XrdOucString.hh"
#include "XrdSec/XrdSecEntity.hh"
#include "XrdVersion.hh"
38
#include "xroot_plugins/XrdCtaFilesystem.hpp"
39
#include "xroot_plugins/XrdCtaFile.hpp"
40
#include "XrdCtaDir.hpp"
41

Daniele Kruse's avatar
Daniele Kruse committed
42
#include <memory>
43
44
45
46
47
#include <iostream>
#include <pwd.h>
#include <sstream>
#include <sys/types.h>

48
XrdVERSIONINFO(XrdSfsGetFileSystem,XrdCta)
49
50
51
52
53

extern "C"
{
  XrdSfsFileSystem *XrdSfsGetFileSystem (XrdSfsFileSystem* native_fs, XrdSysLogger* lp, const char* configfn)
  {
54
    try {
55
      return new cta::xrootPlugins::XrdCtaFilesystem();
56
    } catch (cta::exception::Exception &ex) {
57
      std::cerr << "[ERROR] Could not load the CTA xroot plugin. CTA exception caught: " << ex.getMessageValue() << "\n";
58
      return nullptr;
59
    } catch (std::exception &ex) {
60
      std::cerr << "[ERROR] Could not load the CTA xroot plugin. Exception caught: " << ex.what() << "\n";
61
      return nullptr;
62
    } catch (...) {
63
      std::cerr << "[ERROR] Could not load the CTA xroot plugin. Unknown exception caught!" << "\n";
64
      return nullptr;
65
    }
66
67
68
  }
}

69
70
namespace cta { namespace xrootPlugins {

71
72
73
//------------------------------------------------------------------------------
// FSctl
//------------------------------------------------------------------------------
74
int XrdCtaFilesystem::FSctl(const int cmd, XrdSfsFSctl &args, XrdOucErrInfo &eInfo, const XrdSecEntity *client)
75
{
76
77
78
  (void)cmd; (void)args; (void)eInfo; (void)client;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
79
80
}

Daniele Kruse's avatar
Daniele Kruse committed
81
82
83
//------------------------------------------------------------------------------
// newFile
//------------------------------------------------------------------------------
84
XrdSfsFile * XrdCtaFilesystem::newFile(char *user, int MonID)
Daniele Kruse's avatar
Daniele Kruse committed
85
{  
86
  return new cta::xrootPlugins::XrdCtaFile(m_catalogue.get(), m_scheduler.get(), m_log.get(), user, MonID);
Daniele Kruse's avatar
Daniele Kruse committed
87
88
}

89
90
91
//------------------------------------------------------------------------------
// newDir
//------------------------------------------------------------------------------
92
XrdSfsDirectory * XrdCtaFilesystem::newDir(char *user, int MonID)
93
{
94
  return new cta::xrootPlugins::XrdCtaDir(m_catalogue.get(), m_log.get(), user, MonID);;
95
96
}

97
98
99
//------------------------------------------------------------------------------
// fsctl
//------------------------------------------------------------------------------
100
int XrdCtaFilesystem::fsctl(const int cmd, const char *args, XrdOucErrInfo &eInfo, const XrdSecEntity *client)
101
102
103
104
105
106
107
108
109
{
  (void)cmd; (void)args; (void)eInfo; (void)client;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// getStats
//------------------------------------------------------------------------------
110
int XrdCtaFilesystem::getStats(char *buff, int blen)
111
112
113
114
115
116
117
118
{
  (void)buff; (void)blen;
  return SFS_OK;
}

//------------------------------------------------------------------------------
// getVersion
//------------------------------------------------------------------------------
119
const char * XrdCtaFilesystem::getVersion()
120
{
121
  return nullptr;
122
123
124
125
126
}

//------------------------------------------------------------------------------
// exists
//------------------------------------------------------------------------------
127
int XrdCtaFilesystem::exists(const char *path, XrdSfsFileExistence &eFlag, XrdOucErrInfo &eInfo, const XrdSecEntity *client, const char *opaque)
128
129
130
131
132
133
134
135
136
{
  (void)path; (void)eFlag; (void)eInfo; (void)client; (void)opaque;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// mkdir
//------------------------------------------------------------------------------
137
int XrdCtaFilesystem::mkdir(const char *path, XrdSfsMode mode, XrdOucErrInfo &eInfo, const XrdSecEntity *client, const char *opaque)
138
139
140
141
142
143
144
145
146
{
  (void)path; (void)mode; (void)eInfo; (void)client; (void)opaque;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// prepare
//------------------------------------------------------------------------------
147
int XrdCtaFilesystem::prepare(XrdSfsPrep &pargs, XrdOucErrInfo &eInfo, const XrdSecEntity *client)
148
149
150
151
152
153
154
155
156
{
  (void)pargs; (void)eInfo; (void)client;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// rem
//------------------------------------------------------------------------------
157
int XrdCtaFilesystem::rem(const char *path, XrdOucErrInfo &eInfo, const XrdSecEntity *client, const char *opaque)
158
159
160
161
162
163
164
165
166
{
  (void)path; (void)eInfo; (void)client; (void)opaque;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// remdir
//------------------------------------------------------------------------------
167
int XrdCtaFilesystem::remdir(const char *path, XrdOucErrInfo &eInfo, const XrdSecEntity *client, const char *opaque)
168
169
170
171
172
173
174
175
176
{
  (void)path; (void)eInfo; (void)client; (void)opaque;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// rename
//------------------------------------------------------------------------------
177
int XrdCtaFilesystem::rename(const char *oPath, const char *nPath, XrdOucErrInfo &eInfo, const XrdSecEntity *client, const char *opaqueO, const char *opaqueN)
178
179
180
181
182
183
184
185
186
{
  (void)oPath; (void)nPath; (void)eInfo; (void)client; (void)opaqueO; (void)opaqueN;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// stat
//------------------------------------------------------------------------------
187
int XrdCtaFilesystem::stat(const char *Name, struct ::stat *buf, XrdOucErrInfo &eInfo, const XrdSecEntity *client,const char *opaque)
188
189
190
191
192
193
194
195
196
{
  (void)Name; (void)buf; (void)eInfo; (void)client; (void)opaque;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// stat
//------------------------------------------------------------------------------
197
int XrdCtaFilesystem::stat(const char *path, mode_t &mode, XrdOucErrInfo &eInfo, const XrdSecEntity *client, const char *opaque)
198
199
200
201
202
203
204
205
206
{
  (void)path; (void)mode; (void)eInfo; (void)client; (void)opaque;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// truncate
//------------------------------------------------------------------------------
207
int XrdCtaFilesystem::truncate(const char *path, XrdSfsFileOffset fsize, XrdOucErrInfo &eInfo, const XrdSecEntity *client, const char *opaque)
208
209
210
211
212
213
214
215
216
{
  (void)path; (void)fsize; (void)eInfo; (void)client; (void)opaque;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// chksum
//------------------------------------------------------------------------------
217
int XrdCtaFilesystem::chksum(csFunc Func, const char *csName, const char *path, XrdOucErrInfo &eInfo, const XrdSecEntity *client,const char *opaque)
218
219
220
221
222
223
224
225
226
{
  (void)Func; (void)csName; (void)path; (void)eInfo; (void)client; (void)opaque;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// chmod
//------------------------------------------------------------------------------
227
int XrdCtaFilesystem::chmod(
228
229
230
231
232
  const char *path,
  XrdSfsMode mode,
  XrdOucErrInfo &eInfo,
  const XrdSecEntity *client,
  const char *opaque) {
233
234
235
236
237
238
239
240
  (void)path; (void)mode; (void)eInfo; (void)client; (void)opaque;
  eInfo.setErrInfo(ENOTSUP, "Not supported.");
  return SFS_ERROR;
}

//------------------------------------------------------------------------------
// Disc
//------------------------------------------------------------------------------
241
void XrdCtaFilesystem::Disc(const XrdSecEntity *client)
242
243
244
245
246
247
248
{
  (void)client;
}

//------------------------------------------------------------------------------
// EnvInfo
//------------------------------------------------------------------------------
249
void XrdCtaFilesystem::EnvInfo(XrdOucEnv *envP)
250
251
252
253
254
255
256
{
  (void)envP;
}

//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
257
XrdCtaFilesystem::XrdCtaFilesystem():
258
  m_ctaConf("/etc/cta/cta-frontend.conf"),
259
  m_backend(cta::objectstore::BackendFactory::createBackend(m_ctaConf.getConfEntString("ObjectStore", "BackendPath", nullptr)).release()),
260
  m_backendPopulator(*m_backend),
Steven Murray's avatar
Steven Murray committed
261
262
  m_scheddb(*m_backend, m_backendPopulator.getAgent()) {
  using namespace cta;
263
264
265
266
267
268
269
270
  
  // Try to instantiate the logging system API
  try {
    m_log.reset(new log::SyslogLogger(log::SOCKET_NAME, "cta-frontend", log::DEBUG));
  } catch(exception::Exception &ex) {
    throw cta::exception::Exception(std::string("Failed to instantiate object representing CTA logging system: ")+ex.getMessage().str());
  }
  
271
  const rdbms::Login catalogueLogin = rdbms::Login::parseFile("/etc/cta/cta_catalogue_db.conf");
272
  const uint64_t nbConns = 1;
273
  m_catalogue = catalogue::CatalogueFactory::create(catalogueLogin, nbConns);
274
  m_scheduler = make_unique<cta::Scheduler>(*m_catalogue, m_scheddb, 5, 2*1000*1000);
275

276
277
278
  // If the backend is a VFS, make sure we don't delete it on exit.
  // If not, nevermind.
  try {
Steven Murray's avatar
Steven Murray committed
279
    dynamic_cast<objectstore::BackendVFS &>(*m_backend).noDeleteOnExit();
280
  } catch (std::bad_cast &){}
281
}
282
283
284
285

//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
286
XrdCtaFilesystem::~XrdCtaFilesystem() {
287
}
288
289

}}