~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to parrot/src/pfs_service.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
 
4
Copyright (C) 2005- The University of Notre Dame
 
5
This software is distributed under the GNU General Public License.
 
6
See the file COPYING for details.
 
7
*/
 
8
 
 
9
#include "pfs_service.h"
 
10
#include "pfs_dir.h"
 
11
#include "pfs_process.h"
 
12
 
 
13
extern "C" {
 
14
#include "chirp_reli.h"
 
15
#include "hash_table.h"
 
16
}
 
17
 
 
18
#include <stdio.h>
 
19
#include <unistd.h>
 
20
#include <errno.h>
 
21
#include <sys/stat.h>
 
22
#include <sys/statfs.h>
 
23
#include <time.h>
 
24
#include <string.h>
 
25
#include <stdlib.h>
 
26
 
 
27
pfs_service::pfs_service()
 
28
{
 
29
}
 
30
 
 
31
pfs_service::~pfs_service()
 
32
{
 
33
}
 
34
 
 
35
void * pfs_service::connect( pfs_name *name )
 
36
{
 
37
        errno = ENOSYS;
 
38
        return 0;
 
39
}
 
40
 
 
41
void pfs_service::disconnect( pfs_name *name, void *cxn )
 
42
{
 
43
}
 
44
 
 
45
int pfs_service::get_default_port()
 
46
{
 
47
        return 0;
 
48
}
 
49
 
 
50
int pfs_service::tilde_is_special()
 
51
{
 
52
        return 0;
 
53
}
 
54
 
 
55
int pfs_service::is_seekable()
 
56
{
 
57
        return 0;
 
58
}
 
59
 
 
60
int pfs_service::is_local()
 
61
{
 
62
        return 0;
 
63
}
 
64
 
 
65
pfs_file * pfs_service::open( pfs_name *name, int flags, mode_t mode )
 
66
{
 
67
        errno = ENOENT;
 
68
        return 0;
 
69
}
 
70
 
 
71
pfs_dir * pfs_service::getdir( pfs_name *name )
 
72
{
 
73
        errno = ENOTDIR;
 
74
        return 0;
 
75
}
 
76
 
 
77
int pfs_service::stat( pfs_name *name, struct pfs_stat *buf )
 
78
{
 
79
        pfs_service_emulate_stat(name,buf);
 
80
        return 0;
 
81
}
 
82
 
 
83
int pfs_service::statfs( pfs_name *name, struct pfs_statfs *buf )
 
84
{
 
85
        pfs_service_emulate_statfs(buf);
 
86
        return 0;
 
87
}
 
88
 
 
89
int pfs_service::lstat( pfs_name *name, struct pfs_stat *buf )
 
90
{
 
91
        pfs_service_emulate_stat(name,buf);
 
92
        return 0;
 
93
}
 
94
 
 
95
int pfs_service::access( pfs_name *name, mode_t mode ) 
 
96
{
 
97
        if( mode&X_OK ) {
 
98
                errno = EACCES;
 
99
                return -1;
 
100
        } else if( mode&W_OK ) {
 
101
                errno = EACCES;
 
102
                return -1;
 
103
        } else {
 
104
                return 0;
 
105
        }
 
106
}
 
107
 
 
108
/*
 
109
Strictly speaking, this should fail, but users get confused
 
110
about error messages from tools such as cp innocently
 
111
trying to set the right mode.  Same comments apply to
 
112
utime and such.
 
113
*/
 
114
 
 
115
int pfs_service::chmod( pfs_name *name, mode_t mode ) 
 
116
{
 
117
        return 0;
 
118
}
 
119
 
 
120
int pfs_service::chown( pfs_name *name, uid_t uid, gid_t gid )
 
121
{
 
122
        errno = ENOSYS;
 
123
        return -1;
 
124
}
 
125
 
 
126
int pfs_service::lchown( pfs_name *name, uid_t uid, gid_t gid )
 
127
{
 
128
        errno = ENOSYS;
 
129
        return -1;
 
130
}
 
131
 
 
132
int pfs_service::truncate( pfs_name *name, pfs_off_t length )
 
133
{
 
134
        errno = ENOSYS;
 
135
        return -1;
 
136
}
 
137
 
 
138
int pfs_service::utime( pfs_name *name, struct utimbuf *buf )
 
139
{
 
140
        return 0;
 
141
}
 
142
 
 
143
int pfs_service::unlink( pfs_name *name )
 
144
{
 
145
        errno = ENOSYS;
 
146
        return -1;
 
147
}
 
148
 
 
149
int pfs_service::rename( pfs_name *old_name, pfs_name *new_name )
 
150
{
 
151
        errno = ENOSYS;
 
152
        return -1;
 
153
}
 
154
 
 
155
int pfs_service::chdir( pfs_name *name, char *newpath )
 
156
{
 
157
        strcpy(newpath,name->path);
 
158
        return 0;
 
159
}
 
160
 
 
161
int pfs_service::link( pfs_name *old_name, pfs_name *new_name )
 
162
{
 
163
        errno = ENOSYS;
 
164
        return -1;
 
165
}
 
166
 
 
167
int pfs_service::symlink( const char *linkname, pfs_name *new_name )
 
168
{
 
169
        errno = ENOSYS;
 
170
        return -1;
 
171
}
 
172
 
 
173
int pfs_service::readlink( pfs_name *name, char *buf, pfs_size_t size )
 
174
{
 
175
        errno = EINVAL;
 
176
        return -1;
 
177
}
 
178
 
 
179
int pfs_service::mknod( pfs_name *name, mode_t mode, dev_t dev )
 
180
{
 
181
        errno = ENOSYS;
 
182
        return -1;
 
183
}
 
184
 
 
185
int pfs_service::mkdir( pfs_name *name, mode_t mode )
 
186
{
 
187
        errno = ENOSYS;
 
188
        return -1;
 
189
}
 
190
 
 
191
int pfs_service::rmdir( pfs_name *name )
 
192
{
 
193
        errno = ENOSYS;
 
194
        return -1;
 
195
}
 
196
 
 
197
int pfs_service::mkalloc( pfs_name *name, pfs_ssize_t size, mode_t mode )
 
198
{
 
199
        errno = ENOSYS;
 
200
        return -1;
 
201
}
 
202
 
 
203
int pfs_service::lsalloc( pfs_name *name, char *alloc_name, pfs_ssize_t *size, pfs_ssize_t *inuse )
 
204
{
 
205
        errno = ENOSYS;
 
206
        return -1;
 
207
}
 
208
 
 
209
int pfs_service::whoami( pfs_name *name, char *buf, int size )
 
210
{
 
211
        errno = ENOSYS;
 
212
        return -1;
 
213
}
 
214
 
 
215
int pfs_service::getacl( pfs_name *name, char *buf, int size )
 
216
{
 
217
        errno = ENOSYS;
 
218
        return -1;
 
219
}
 
220
 
 
221
int pfs_service::setacl( pfs_name *name, const char *subject, const char *rights )
 
222
{
 
223
        errno = ENOSYS;
 
224
        return -1;
 
225
}
 
226
 
 
227
pfs_location* pfs_service::locate( pfs_name *name )
 
228
{
 
229
        errno = ENOSYS;
 
230
        return 0;
 
231
}
 
232
 
 
233
int pfs_service::putfile( pfs_name *source, pfs_name *target )
 
234
{
 
235
        errno = ENOSYS;
 
236
        return -1;
 
237
}
 
238
 
 
239
int pfs_service::getfile( pfs_name *source, pfs_name *target )
 
240
{
 
241
        errno = ENOSYS;
 
242
        return -1;
 
243
}
 
244
 
 
245
int pfs_service::thirdput( pfs_name *source, pfs_name *target )
 
246
{
 
247
        errno = ENOSYS;
 
248
        return -1;
 
249
}
 
250
 
 
251
int pfs_service::md5( pfs_name *source, unsigned char *digest )
 
252
{
 
253
        errno = ENOSYS;
 
254
        return -1;
 
255
}
 
256
 
 
257
pfs_service * pfs_service_lookup( const char *name )
 
258
{
 
259
        if(!strcmp(name,"chirp")) {
 
260
                extern pfs_service *pfs_service_chirp;
 
261
                return pfs_service_chirp;
 
262
        } else if(!strcmp(name,"multi")) {
 
263
                extern pfs_service *pfs_service_multi;
 
264
                return pfs_service_multi;
 
265
        } else if(!strcmp(name,"anonftp")) {
 
266
                extern pfs_service *pfs_service_anonftp;
 
267
                return pfs_service_anonftp;
 
268
        } else if(!strcmp(name,"ftp")) {
 
269
                extern pfs_service *pfs_service_ftp;
 
270
                return pfs_service_ftp;
 
271
        } else if(!strcmp(name,"http")) {
 
272
                extern pfs_service *pfs_service_http;
 
273
                return pfs_service_http;
 
274
        } else if(!strcmp(name,"grow")) {
 
275
                extern pfs_service *pfs_service_grow;
 
276
                return pfs_service_grow;
 
277
        } else if(!strcmp(name,"s3")) {
 
278
                extern pfs_service *pfs_service_s3;
 
279
                return pfs_service_s3;
 
280
#ifdef HAS_GLOBUS_GSS
 
281
        } else if(!strcmp(name,"gsiftp") || !strcmp(name,"gridftp") ) {
 
282
                extern pfs_service *pfs_service_gsiftp;
 
283
                return pfs_service_gsiftp;
 
284
#endif
 
285
#ifdef HAS_NEST
 
286
        } else if(!strcmp(name,"nest")) {
 
287
                extern pfs_service *pfs_service_nest;
 
288
                return pfs_service_nest;
 
289
#endif
 
290
#ifdef HAS_EGEE
 
291
        } else if(!strcmp(name,"gfal") || !strcmp(name,"lfn") || !strcmp(name,"guid") || !strcmp(name,"srm") || !strcmp(name,"rfio") ) {
 
292
                extern pfs_service *pfs_service_gfal;
 
293
                return pfs_service_gfal;
 
294
        } else if(!strcmp(name,"lfc")) {
 
295
                extern pfs_service *pfs_service_lfc;
 
296
                return pfs_service_lfc;
 
297
#endif
 
298
#ifdef HAS_RFIO
 
299
        } else if(!strcmp(name,"rfio")) {
 
300
                extern pfs_service *pfs_service_rfio;
 
301
                return pfs_service_rfio;
 
302
#endif
 
303
#ifdef HAS_DCAP
 
304
        } else if(!strcmp(name,"dcap")) {
 
305
                extern pfs_service *pfs_service_dcap;
 
306
                return pfs_service_dcap;
 
307
#endif
 
308
#ifdef HAS_IRODS
 
309
        } else if(!strcmp(name,"irods")) {
 
310
                extern pfs_service *pfs_service_irods;
 
311
                return pfs_service_irods;
 
312
#endif
 
313
        } else if(!strcmp(name,"hdfs")) {
 
314
                extern pfs_service *pfs_service_hdfs;
 
315
                return pfs_service_hdfs;
 
316
#ifdef HAS_BXGRID
 
317
        } else if(!strcmp(name,"bxgrid")) {
 
318
                extern pfs_service *pfs_service_bxgrid;
 
319
                return pfs_service_bxgrid;
 
320
#endif
 
321
#ifdef HAS_XROOTD
 
322
        } else if(!strcmp(name,"xrootd") || !strcmp(name,"root") ) {
 
323
                extern pfs_service *pfs_service_xrootd;
 
324
                return pfs_service_xrootd;
 
325
#endif
 
326
        } else {
 
327
                return 0;
 
328
        }
 
329
 
 
330
}
 
331
 
 
332
pfs_service * pfs_service_lookup_default()
 
333
{
 
334
        extern pfs_service *pfs_service_local;
 
335
        return pfs_service_local;
 
336
}
 
337
 
 
338
void pfs_service_emulate_statfs( struct pfs_statfs *buf )
 
339
{
 
340
        memset(buf,0,sizeof(*buf));
 
341
}
 
342
 
 
343
static int default_block_size = 65336;
 
344
 
 
345
void pfs_service_set_block_size( int bs )
 
346
{
 
347
        default_block_size = bs;
 
348
        chirp_reli_blocksize_set(bs);
 
349
}
 
350
 
 
351
int  pfs_service_get_block_size()
 
352
{
 
353
        if(!strcmp(pfs_current->name,"ld")) {
 
354
                return 4096;
 
355
        } else {
 
356
                return default_block_size;
 
357
        }
 
358
}
 
359
 
 
360
void pfs_service_emulate_stat( pfs_name *name, struct pfs_stat *buf )
 
361
{
 
362
        static time_t start_time = 0;
 
363
        memset(buf,0,sizeof(*buf));
 
364
        buf->st_dev = (dev_t) -1;
 
365
        if(name) {
 
366
                buf->st_ino = hash_string(name->rest);
 
367
        } else {
 
368
                buf->st_ino = 0;
 
369
        }
 
370
        buf->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO ;
 
371
        buf->st_uid = getuid();
 
372
        buf->st_gid = getgid();
 
373
        buf->st_nlink = 1;
 
374
        buf->st_size = 0;
 
375
        if(start_time==0) start_time = time(0);
 
376
        buf->st_ctime = buf->st_atime = buf->st_mtime = start_time;
 
377
        buf->st_blksize = default_block_size;
 
378
}
 
379
 
 
380
static struct hash_table *table = 0;
 
381
 
 
382
void * pfs_service_connect_cache( pfs_name *name )
 
383
{
 
384
        char key[PFS_PATH_MAX];
 
385
        void *cxn;
 
386
 
 
387
        if(!name->host[0]) {
 
388
                errno = ENOENT;
 
389
                return 0;
 
390
        }
 
391
 
 
392
        if(!table) table = hash_table_create(0,0);
 
393
 
 
394
        if(table) {
 
395
                sprintf(key,"/%s/%s:%d",name->service_name,name->host,name->port);
 
396
                cxn = hash_table_remove(table,key);
 
397
                if(cxn) return cxn;
 
398
        }
 
399
 
 
400
        return name->service->connect(name);
 
401
}
 
402
 
 
403
void pfs_service_disconnect_cache( pfs_name *name, void *cxn, int invalidate )
 
404
{
 
405
        char key[PFS_PATH_MAX];
 
406
        int save_errno = errno;
 
407
 
 
408
        if(!table) table = hash_table_create(0,0);
 
409
 
 
410
        if(table && !invalidate) {
 
411
                sprintf(key,"/%s/%s:%d",name->service_name,name->host,name->port);
 
412
                if(hash_table_lookup(table,key)) {
 
413
                        name->service->disconnect(name,cxn);
 
414
                } else {
 
415
                        hash_table_insert(table,key,cxn);
 
416
                }
 
417
        } else {
 
418
                name->service->disconnect(name,cxn);
 
419
        }
 
420
 
 
421
        errno = save_errno;
 
422
}
 
423