Changeset 3536
- Timestamp:
- 10/13/2009 07:59:24 PM (1 month ago)
- Files:
-
- XrdHdfs/GNUmakefile (modified) (1 diff)
- XrdHdfs/XrdHdfs.cc (modified) (33 diffs)
- XrdHdfs/XrdHdfs.hh (modified) (6 diffs)
- XrdHdfs/XrdHdfsAio.hh (deleted)
- XrdHdfs/XrdHdfsInterface.hh (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
XrdHdfs/GNUmakefile
r3116 r3536 64 64 $(ECHO)$(CC) $(CFLAGS) $(OBJECTS) $(OBJFS) $(LDSO) $(MORELIBS) $(LIBS) $(HADOOP_LIB) -o $(LIBRARY) 65 65 66 $(OBJDIR)/XrdHdfs.o: XrdHdfs Interface.hh XrdHdfs.hh XrdSecInterface.hh\66 $(OBJDIR)/XrdHdfs.o: XrdHdfs.hh \ 67 67 XrdSysError.hh XrdOucErrInfo.hh XrdSysLogger.hh \ 68 XrdHdfs.cc XrdHdfsAio.hh../XrdVersion.hh68 XrdHdfs.cc ../XrdVersion.hh 69 69 @echo Compiling XrdHdfs.cc 70 70 $(ECHO)$(CC) -c $(CFLAGS) $(INCLUDE) $(HADOOP_INCLUDE) -o $(OBJDIR)/XrdHdfs.o XrdHdfs.cc XrdHdfs/XrdHdfs.cc
r3116 r3536 29 29 #include "XrdSys/XrdSysHeaders.hh" 30 30 #include "XrdSys/XrdSysLogger.hh" 31 #include "XrdSys/XrdSysPlugin.hh" 31 32 #include "XrdSys/XrdSysPthread.hh" 32 33 #include "XrdSec/XrdSecInterface.hh" 33 #include "XrdHdfs/XrdHdfsAio.hh"34 34 #include "XrdHdfs/XrdHdfs.hh" 35 #include "XrdOss/XrdOssTrace.hh" 35 36 36 37 #ifdef AIX … … 47 48 48 49 /******************************************************************************/ 49 /* G l o b a l O b j e c t s */ 50 /******************************************************************************/ 51 52 XrdSysError *XrdHdfs::eDest; 53 54 /******************************************************************************/ 55 /* C o n s t r u c t o r */ 56 /******************************************************************************/ 57 58 XrdHdfs::XrdHdfs(XrdSysError *ep) 59 { 60 eDest = ep; 61 } 62 50 /* E r r o r R o u t i n g O b j e c t */ 51 /******************************************************************************/ 52 53 namespace XrdHdfs 54 { 55 56 XrdSysError OssEroute(0, "hdfs_"); 57 58 XrdOucTrace OssTrace(&OssEroute); 59 60 static XrdHdfsSys XrdHdfsSS; 61 62 } 63 64 using namespace XrdHdfs; 65 63 66 /******************************************************************************/ 64 67 /* G e t F i l e S y s t e m */ 65 68 /******************************************************************************/ 66 XrdSfsFileSystem *XrdSfsGetFileSystem(XrdSfsFileSystem *native_fs, 67 XrdSysLogger *lp, 68 const char * config) 69 { 70 static XrdSysError Eroute(lp, "XrdHdfs"); 71 static XrdHdfs myFS(&Eroute); 72 73 Eroute.Say("Copr. 2009 University of Nebraska-Lincoln " 74 "hdfs plugin v 1.0a"); 75 76 return &myFS; 69 extern "C" 70 { 71 XrdOss *XrdOssGetStorageSystem(XrdOss *native_oss, 72 XrdSysLogger *Logger, 73 const char *config_fn, 74 const char *parms) 75 { 76 return (XrdHdfsSS.Init(Logger, config_fn) ? 0 : (XrdOss *)&XrdHdfsSS); 77 } 77 78 } 78 79 … … 81 82 /******************************************************************************/ 82 83 /******************************************************************************/ 83 /* o p e n */ 84 /******************************************************************************/ 85 86 int XrdHdfsDirectory::open(const char *dir_path, // In 87 const XrdSecClientName *client, // In 88 const char *info) // In 84 /* O p e n d i r */ 85 /******************************************************************************/ 86 87 int XrdHdfsDirectory::Opendir(const char *dir_path) 89 88 /* 90 89 Function: Open the directory `path' and prepare for reading. 91 90 92 91 Input: path - The fully qualified name of the directory to open. 93 cred - Authentication credentials, if any. 94 info - Opaque information, if any. 95 96 Output: Returns SFS_OK upon success, otherwise SFS_ERROR. 97 */ 98 { 99 static const char *epname = "opendir"; 100 101 // Verify that this object is not already associated with an open directory 102 // 103 if (dh) return 104 XrdHdfs::Emsg(epname, error, EADDRINUSE, 105 "open directory", dir_path); 92 93 Output: Returns XrdOssOK upon success, otherwise (-errno). 94 */ 95 { 96 #ifndef NODEBUG 97 static const char *epname = "Opendir"; 98 #endif 99 100 // Return an error if we have already opened 101 if (isopen) return -XRDOSS_E8001; 106 102 107 103 // Set up values for this directory object … … 112 108 // Open the directory and get it's id 113 109 // 114 if (!(dh = hdfsListDirectory(fs, dir_path, &numEntries))) return 115 XrdHdfs::Emsg(epname,error,errno,"open directory",dir_path); 110 TRACE(Opendir, "path " << dir_path); 111 if (!(dh = hdfsListDirectory(fs, dir_path, &numEntries))) { 112 isopen = 0; 113 if (errno == 0) 114 return -1; 115 return -errno; 116 } 117 isopen = 1; 116 118 117 119 // All done 118 120 // 119 return SFS_OK;120 } 121 122 /******************************************************************************/ 123 /* n e x t E n t r y*/124 /******************************************************************************/ 125 126 const char *XrdHdfsDirectory::nextEntry()121 return XrdOssOK; 122 } 123 124 /******************************************************************************/ 125 /* R e a d d i r */ 126 /******************************************************************************/ 127 128 int XrdHdfsDirectory::Readdir(char * buff, int blen) 127 129 /* 128 130 Function: Read the next directory entry. … … 136 138 */ 137 139 { 138 static const char *epname = "nextEntry"; 140 #ifndef NODEBUG 141 static const char *epname = "Readdir"; 142 #endif 143 144 if (!isopen) return -XRDOSS_E8002; 139 145 140 146 // Lock the direcrtory and do any required tracing 141 147 // 142 if (!dh)143 {XrdHdfs::Emsg(epname,error,EBADF,"read directory",fname);144 return (const char *)0;145 }148 if (!dh) { 149 XrdHdfsSys::Emsg(epname,error,EBADF,"read directory",fname); 150 return 0; 151 } 146 152 147 153 // Check if we are at EOF (once there we stay there) 148 154 // 149 155 if (dirPos == numEntries-1) 150 return (const char *)0;156 return 0; 151 157 152 158 // Read the next directory entry … … 157 163 // Return the actual entry 158 164 // 159 return (const char *)(fileInfo.mName); 160 } 161 162 /******************************************************************************/ 163 /* c l o s e */ 164 /******************************************************************************/ 165 166 int XrdHdfsDirectory::close() 165 strlcpy(buff, (const char *)(fileInfo.mName), blen); 166 return XrdOssOK; 167 } 168 169 /******************************************************************************/ 170 /* C l o s e */ 171 /******************************************************************************/ 172 173 int XrdHdfsDirectory::Close(long long *retsz) 167 174 /* 168 175 Function: Close the directory object. … … 170 177 Input: cred - Authentication credentials, if any. 171 178 172 Output: Returns SFS_OK upon success and SFS_ERROR upon failure. 173 */ 174 { 179 Output: Returns XrdOssOK upon success and XRDOSS_E8002 upon failure. 180 */ 181 { 182 183 if (!isopen) return -XRDOSS_E8002; 175 184 176 185 // Release the handle 177 186 // 178 if (dh != NULL && numEntries > 0) hdfsFreeFileInfo(dh, numEntries); 187 if (dh != NULL && numEntries > 0) 188 hdfsFreeFileInfo(dh, numEntries); 179 189 180 190 // Do some clean-up … … 184 194 numEntries = 0; 185 195 dirPos = 0; 186 return SFS_OK; 196 isopen = 0; 197 return 0; 187 198 } 188 199 … … 191 202 /******************************************************************************/ 192 203 /******************************************************************************/ 193 /* o p e n */ 194 /******************************************************************************/ 195 196 int XrdHdfsFile::open(const char *path, // In 197 XrdSfsFileOpenMode open_mode, // In 198 mode_t Mode, // In 199 const XrdSecClientName *client, // In 200 const char *info) // In 201 /* 202 Function: Open the file `path' in the mode indicated by `open_mode'. 204 /* O p e n */ 205 /******************************************************************************/ 206 207 int XrdHdfsFile::Open(const char *path, // In 208 int openMode, // In 209 mode_t createMode,// In 210 XrdOucEnv &client) // In 211 /* 212 Function: Open the file `path' in the mode indicated by `openMode'. 203 213 204 214 Input: path - The fully qualified name of the file to open. 205 open _mode- One of the following flag values:215 openMode - One of the following flag values: 206 216 SFS_O_RDONLY - Open file for reading. 207 217 SFS_O_WRONLY - Open file for writing. … … 213 223 bits (e.g., 744 == "rwxr--r--"). Mode may also conatin 214 224 SFS_O_MKPTH is the full path is to be created. The 215 agument is ignored unless open _mode = SFS_O_CREAT.225 agument is ignored unless openMode = O_CREAT. 216 226 client - Authentication credentials, if any. 217 227 info - Opaque information to be used as seen fit. 218 228 219 Output: Returns OOSS_OK upon success, otherwise SFS_ERROR is returned. 220 */ 221 { 229 Output: Returns OOSS_OK upon success, otherwise -errno is returned. 230 */ 231 { 232 #ifndef NODEBUG 222 233 static const char *epname = "open"; 223 const int AMode = S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH; // 775 234 #endif 235 //const int AMode = S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH; // 775 224 236 char *opname; 225 int retc,open_flag = 0;237 int open_flag = 0; 226 238 227 239 // Verify that this object is not already associated with an open file 228 240 // 229 241 if (fh != NULL) 230 return XrdHdfs::Emsg(epname,error,EADDRINUSE,"open file",path);242 return -XRDOSS_E8003; 231 243 fname = strdup(path); 232 244 233 245 // Set the actual open mode 234 246 // 235 switch(open _mode & (SFS_O_RDONLY | SFS_O_WRONLY | SFS_O_RDWR))247 switch(openMode & (O_RDONLY | O_WRONLY | O_RDWR)) 236 248 { 237 case SFS_O_RDONLY: open_flag = O_RDONLY; break;238 case SFS_O_WRONLY: open_flag = O_WRONLY; break;239 case SFS_O_RDWR: open_flag = O_RDWR; break;249 case O_RDONLY: open_flag = O_RDONLY; break; 250 case O_WRONLY: open_flag = O_WRONLY; break; 251 case O_RDWR: open_flag = O_RDWR; break; 240 252 default: open_flag = O_RDONLY; break; 241 253 } 242 254 243 255 // HDFS does not support read-write mode. 244 if (open _mode & SFS_O_RDWR) {245 return XrdHdfs ::Emsg(epname,error,ENOTSUP, "Read-write mode not"256 if (openMode & O_RDWR) { 257 return XrdHdfsSys::Emsg(epname,error,ENOTSUP, "Read-write mode not" 246 258 " supported by HDFS.",path); 247 259 } … … 249 261 // Prepare to create or open the file, as needed 250 262 // 251 if (open_mode & SFS_O_CREAT) 252 { 263 if (openMode & O_CREAT) { 253 264 opname = (char *)"create"; 254 if ((Mode & SFS_O_MKPTH) && (retc = XrdHdfs::Mkpath(path,AMode,info))) 255 return XrdHdfs::Emsg(epname,error,retc,"create path for",path); 256 } else if (open_mode & SFS_O_TRUNC) 257 {open_flag = O_TRUNC; 265 } else if (openMode & O_TRUNC) { 266 open_flag = O_TRUNC; 258 267 opname = (char *)"truncate"; 259 } else opname = (char *)"open";268 } else opname = (char *)"open"; 260 269 261 270 // Open the file and make sure it is a file … … 282 291 // 283 292 if (err_code != 0) 284 return XrdHdfs::Emsg(epname, error, err_code, opname, path);285 286 return SFS_OK;287 } 288 289 /******************************************************************************/ 290 /* cl o s e */291 /******************************************************************************/ 292 293 int XrdHdfsFile:: close()293 return -err_code; 294 295 return XrdOssOK; 296 } 297 298 /******************************************************************************/ 299 /* C l o s e */ 300 /******************************************************************************/ 301 302 int XrdHdfsFile::Close(long long int *) 294 303 /* 295 304 Function: Close the file object. … … 297 306 Input: None 298 307 299 Output: Returns SFS_OK upon success and SFS_ERRORupon failure.308 Output: Returns XrdOssOK upon success and -errno upon failure. 300 309 */ 301 310 { … … 305 314 // 306 315 if (fh != NULL && hdfsCloseFile(fs, fh) != 0) 307 return XrdHdfs ::Emsg(epname, error, errno, "close", fname);316 return XrdHdfsSys::Emsg(epname, error, errno, "close", fname); 308 317 fh = NULL; 309 318 if (fname) {free(fname); fname = 0;} 310 return SFS_OK; 311 } 312 313 /******************************************************************************/ 314 /* f c t l */ 315 /******************************************************************************/ 316 317 int XrdHdfsFile::fctl(const int cmd, 318 const char *args, 319 XrdOucErrInfo &out_error) 320 { 321 322 // We don't support this 323 // 324 out_error.setErrInfo(EEXIST, "fctl operation not supported"); 325 return SFS_ERROR; 326 } 327 328 /******************************************************************************/ 329 /* r e a d */ 330 /******************************************************************************/ 331 332 XrdSfsXferSize XrdHdfsFile::read(XrdSfsFileOffset offset, // In 333 char *buff, // Out 334 XrdSfsXferSize blen) // In 319 return XrdOssOK; 320 } 321 322 323 /******************************************************************************/ 324 /* R e a d */ 325 /******************************************************************************/ 326 327 ssize_t XrdHdfsFile::Read(void *buff, // Out 328 off_t offset, // In 329 size_t blen) // In 335 330 /* 336 331 Function: Read `blen' bytes at `offset' into 'buff' and return the actual … … 342 337 of bytes that will be read from 'fd'. 343 338 344 Output: Returns the number of bytes read upon success and SFS_ERROR o/w. 345 */ 346 { 347 static const char *epname = "read"; 348 XrdSfsXferSize nbytes; 349 350 // Make sure the offset is not too large 351 // 352 #if _FILE_OFFSET_BITS!=64 353 if (offset > 0x000000007fffffff) 354 return XrdHdfs::Emsg(epname, error, EFBIG, "read", fname); 355 #endif 339 Output: Returns the number of bytes read upon success and -errno o/w. 340 */ 341 { 342 #ifndef NODEBUG 343 static const char *epname = "Read"; 344 #endif 345 size_t nbytes; 356 346 357 347 // Read the actual number of bytes … … 360 350 361 351 if (nbytes < 0) 362 return XrdHdfs ::Emsg(epname, error, errno, "read", fname);352 return XrdHdfsSys::Emsg(epname, error, errno, "read", fname); 363 353 364 354 // Return number of bytes read … … 368 358 369 359 /******************************************************************************/ 370 /* re a d A I O */371 /******************************************************************************/ 372 373 int XrdHdfsFile:: read(XrdSfsAio *aiop)360 /* R e a d A I O */ 361 /******************************************************************************/ 362 363 int XrdHdfsFile::Read(XrdSfsAio *aiop) 374 364 { 375 365 376 366 // Execute this request in a synchronous fashion 377 367 // 378 aiop->Result = this->read((XrdSfsFileOffset)aiop->sfsAio.aio_offset, 379 (char *)aiop->sfsAio.aio_buf, 380 (XrdSfsXferSize)aiop->sfsAio.aio_nbytes); 368 aiop->Result = this->Read((void *)aiop->sfsAio.aio_buf, aiop->sfsAio.aio_offset, 369 aiop->sfsAio.aio_nbytes); 381 370 aiop->doneRead(); 382 371 return 0; … … 384 373 385 374 /******************************************************************************/ 386 /* wr i t e */387 /******************************************************************************/ 388 389 XrdSfsXferSize XrdHdfsFile::write(XrdSfsFileOffset offset, // In390 const char *buff,// In391 XrdSfsXferSize blen)// In375 /* W r i t e */ 376 /******************************************************************************/ 377 378 ssize_t XrdHdfsFile::Write(const char *buff, // In 379 off_t offset, // In 380 size_t blen) // In 392 381 /* 393 382 Function: Write `blen' bytes at `offset' from 'buff' and return the actual … … 399 388 of bytes that will be written to 'fd'. 400 389 401 Output: Returns the number of bytes written upon success and SFS_ERRORo/w.390 Output: Returns the number of bytes written upon success and -errno o/w. 402 391 403 392 Notes: An error return may be delayed until the next write(), close(), or … … 414 403 #if _FILE_OFFSET_BITS!=64 415 404 if (offset > 0x000000007fffffff) 416 return XrdHdfs ::Emsg(epname, error, EFBIG, "write", fname);417 #endif 418 419 return XrdHdfs ::Emsg(epname,error,ENOTSUP, "Write mode not"405 return XrdHdfsSys::Emsg(epname, error, EFBIG, "write", fname); 406 #endif 407 408 return XrdHdfsSys::Emsg(epname,error,ENOTSUP, "Write mode not" 420 409 " supported by HDFS.",fname); 421 410 … … 423 412 424 413 /******************************************************************************/ 425 /* wr i t e A I O */426 /******************************************************************************/ 427 428 int XrdHdfsFile:: write(XrdSfsAio *aiop)414 /* W r i t e A I O */ 415 /******************************************************************************/ 416 417 int XrdHdfsFile::Write(XrdSfsAio *aiop) 429 418 { 430 419 431 420 // Execute this request in a synchronous fashion 432 421 // 433 aiop->Result = this->write((XrdSfsFileOffset)aiop->sfsAio.aio_offset, 434 (char *)aiop->sfsAio.aio_buf, 435 (XrdSfsXferSize)aiop->sfsAio.aio_nbytes); 422 aiop->Result = this->Write((const char *)aiop->sfsAio.aio_buf, aiop->sfsAio.aio_offset, 423 aiop->sfsAio.aio_nbytes); 436 424 aiop->doneWrite(); 437 425 return 0; … … 439 427 440 428 /******************************************************************************/ 441 /* s t a t */442 /******************************************************************************/ 443 444 int XrdHdfsFile:: stat(struct stat *buf) // Out429 /* F s t a t */ 430 /******************************************************************************/ 431 432 int XrdHdfsFile::Fstat(struct stat *buf) // Out 445 433 /* 446 434 Function: Return file status information … … 448 436 Input: buf - The stat structiure to hold the results 449 437 450 Output: Returns SFS_OK upon success and SFS_ERRORupon failure.438 Output: Returns XrdOssOK upon success and -errno upon failure. 451 439 */ 452 440 { … … 457 445 // 458 446 if (fileInfo == NULL) 459 return XrdHdfs ::Emsg(epname, error, errno, "state", fname);447 return XrdHdfsSys::Emsg(epname, error, errno, "state", fname); 460 448 461 449 buf->st_mode = (fileInfo->mKind == kObjectKindDirectory) ? (S_IFDIR | 0777):\ … … 476 464 // All went well 477 465 // 478 return SFS_OK; 479 } 480 481 /******************************************************************************/ 482 /* s y n c */ 483 /******************************************************************************/ 484 485 int XrdHdfsFile::sync() 486 /* 487 Function: Commit all unwritten bytes to physical media. 488 489 Input: None 490 491 Output: Returns SFS_OK upon success and SFS_ERROR upon failure. 492 */ 493 { 494 static const char *epname = "sync"; 495 496 return XrdHdfs::Emsg(epname,error,ENOTSUP, "Write mode not" 497 " supported by HDFS.",fname); 498 499 // All done 500 // 501 return SFS_OK; 502 } 503 504 /******************************************************************************/ 505 /* s y n c A I O */ 506 /******************************************************************************/ 507 508 int XrdHdfsFile::sync(XrdSfsAio *aiop) 509 { 510 511 // Execute this request in a synchronous fashion 512 // 513 aiop->Result = this->sync(); 514 aiop->doneWrite(); 515 return 0; 516 } 517 518 /******************************************************************************/ 519 /* t r u n c a t e */ 520 /******************************************************************************/ 521 522 int XrdHdfsFile::truncate(XrdSfsFileOffset flen) // In 523 /* 524 Function: Set the length of the file object to 'flen' bytes. 525 526 Input: flen - The new size of the file. 527 528 Output: Returns SFS_OK upon success and SFS_ERROR upon failure. 529 530 Notes: If 'flen' is smaller than the current size of the file, the file 531 is made smaller and the data past 'flen' is discarded. If 'flen' 532 is larger than the current size of the file, a hole is created 533 (i.e., the file is logically extended by filling the extra bytes 534 with zeroes). 535 */ 536 { 537 static const char *epname = "trunc"; 538 539 // Make sure the offset is not too larg 540 // 541 if (sizeof(off_t) < sizeof(flen) && flen > 0x000000007fffffff) 542 return XrdHdfs::Emsg(epname, error, EFBIG, "truncate", fname); 543 544 // Perform the function 545 // 546 return XrdHdfs::Emsg(epname,error,ENOTSUP, "Truncate not" 547 " supported by HDFS.",fname); 548 549 // All done 550 // 551 return SFS_OK; 466 return XrdOssOK; 552 467 } 553 468 … … 555 470 /* F i l e S y s t e m O b j e c t I n t e r f a c e s */ 556 471 /******************************************************************************/ 557 /******************************************************************************/558 /* c h m o d */559 /******************************************************************************/560 561 int XrdHdfs::chmod(const char *path, // In562 XrdSfsMode Mode, // In563 XrdOucErrInfo &error, // Out564 const XrdSecClientName *client, // In565 const char *info) // In566 /*567 Function: Change the mode on a file or directory.568 569 Input: path - Is the fully qualified name of the file to be removed.570 einfo - Error information object to hold error details.571 client - Authentication credentials, if any.572 info - Opaque information, if any.573 574 Output: Returns SFS_OK upon success and SFS_ERROR upon failure.575 */576 {577 static const char *epname = "chmod";578 mode_t acc_mode = Mode & S_IAMB;579 580 const char * groups[1] = {client->grps};581 hdfsFS fs = hdfsConnectAsUser("default", 0, client->name, groups, 1);582 583 // Perform the actual deletion584 //585 if (hdfsChmod(fs, path, acc_mode) )586 return XrdHdfs::Emsg(epname,error,errno,"change mode on",path);587 588 // All done589 //590 return SFS_OK;591 }592 593 /******************************************************************************/594 /* e x i s t s */595 /******************************************************************************/596 597 int XrdHdfs::exists(const char *path, // In598 XrdSfsFileExistence &file_exists, // Out599 XrdOucErrInfo &error, // Out600 const XrdSecClientName *client, // In601 const char *info) // In602 /*603 Function: Determine if file 'path' actually exists.604 605 Input: path - Is the fully qualified name of the file to be tested.606 file_exists - Is the address of the variable to hold the status of607 'path' when success is returned. The values may be:608 XrdSfsFileExistsIsDirectory - file not found but path is valid.609 XrdSfsFileExistsIsFile - file found.610 XrdSfsFileExistsIsNo - neither file nor directory.611 einfo - Error information object holding the details.612 client - Authentication credentials, if any.613 info - Opaque information, if any.614 615 Output: Returns SFS_OK upon success and SFS_ERROR upon failure.616 617 Notes: When failure occurs, 'file_exists' is not modified.618 */619 {620 static const char *epname = "exists";621 622 // Now try to find the file or directory623 //624 625 const char * groups[1] = {client->grps};626 hdfsFS fs = hdfsConnectAsUser("default", 0, client->name, groups, 1);627 628 hdfsFileInfo * fileInfo = hdfsGetPathInfo(fs, path);629 630 if (fileInfo == NULL)631 return XrdHdfs::Emsg(epname, error, errno, "locate", path);632 633 if (fileInfo->mKind == kObjectKindDirectory)634 file_exists = XrdSfsFileExistIsDirectory;635 else if (fileInfo->mKind == kObjectKindFile)636 file_exists = XrdSfsFileExistIsFile;637 else638 file_exists = XrdSfsFileExistNo;639 640 hdfsFreeFileInfo(fileInfo, 1);641 642 return SFS_OK;643 }644 645 /******************************************************************************/646 /* f s c t l */647 /******************************************************************************/648 649 int XrdHdfs::fsctl(const int cmd,650 const char *args,651 XrdOucErrInfo &out_error,652 const XrdSecClientName *client)653 {654 out_error.setErrInfo(ENOTSUP, "Operation not supported.");655 return SFS_ERROR;656 }657 472 658 473 /******************************************************************************/ … … 660 475 /******************************************************************************/ 661 476 662 const char *XrdHdfs::getVersion() {return XrdVERSION;} 663 664 /******************************************************************************/ 665 /* m k d i r */ 666 /******************************************************************************/ 667 668 int XrdHdfs::mkdir(const char *path, // In 669 XrdSfsMode Mode, // In 670 XrdOucErrInfo &error, // Out 671 const XrdSecClientName *client, // In 672 const char *info) // In 673 /* 674 Function: Create a directory entry. 675 676 Input: path - Is the fully qualified name of the file to be removed. 677 Mode - Is the POSIX mode setting for the directory. If the 678 mode contains SFS_O_MKPTH, the full path is created. 679 einfo - Error information object to hold error details. 680 client - Authentication credentials, if any. 681 info - Opaque information, if any. 682 683 Output: Returns SFS_OK upon success and SFS_ERROR upon failure. 684 */ 685 { 686 static const char *epname = "mkdir"; 687 mode_t acc_mode = Mode & S_IAMB; 688 689 const char * groups[1] = {client->grps}; 690 hdfsFS fs = hdfsConnectAsUser("default", 0, client->name, groups, 1); 691 692 // Create the path if it does not already exist 693 // 694 if (Mode & SFS_O_MKPTH) Mkpath(path, acc_mode, info); 695 696 // Perform the actual deletion 697 // 698 if (hdfsCreateDirectory(fs, path) == -1) 699 return XrdHdfs::Emsg(epname,error,errno,"create directory",path); 700 701 // All done 702 // 703 return SFS_OK; 704 } 705 706 /******************************************************************************/ 707 /* M k p a t h */ 708 /******************************************************************************/ 709 /* 710 Function: Create a directory path 711 712 Input: path - Is the fully qualified name of the new path. 713 mode - The new mode that each new directory is to have. 714 info - Opaque information, of any. 715 716 Output: Returns 0 upon success and -errno upon failure. 717 */ 718 719 int XrdHdfs::Mkpath(const char *path, mode_t mode, const char *info) 720 { 721 722 return -ENOTSUP; 723 724 } 725 726 /******************************************************************************/ 727 /* r e m */ 728 /******************************************************************************/ 729 730 int XrdHdfs::rem(const char *path, // In 731 XrdOucErrInfo &error, // Out 732 const XrdSecClientName *client, // In 733 const char *info) // In 734 /* 735 Function: Delete a file from the namespace. 736 737 Input: path - Is the fully qualified name of the file to be removed. 738 einfo - Error information object to hold error details. 739 client - Authentication credentials, if any. 740 info - Opaque information, if any. 741 742 Output: Returns SFS_OK upon success and SFS_ERROR upon failure. 743 */ 744 { 745 static const char *epname = "rem"; 746 const char * groups[1] = {client->grps}; 747 hdfsFS fs = hdfsConnectAsUser("default", 0, client->name, groups, 1); 748 749 // Perform the actual deletion 750 // 751 if (hdfsDelete(fs, path) == -1) 752 return XrdHdfs::Emsg(epname, error, errno, "remove", path); 753 754 // All done 755 // 756 return SFS_OK; 757 } 758 759 /******************************************************************************/ 760 /* r e m d i r */ 761 /******************************************************************************/ 762 763 int XrdHdfs::remdir(const char *path, // In 764 XrdOucErrInfo &error, // Out 765 const XrdSecClientName *client, // In 766 const char *info) // In 767 /* 768 Function: Delete a directory from the namespace. 769 770 Input: path - Is the fully qualified name of the dir to be removed. 771 einfo - Error information object to hold error details. 772 client - Authentication credentials, if any. 773 info - Opaque information, if any. 774 775 Output: Returns SFS_OK upon success and SFS_ERROR upon failure. 776 */ 777 { 778 static const char *epname = "remdir"; 779 const char * groups[1] = {client->grps}; 780 hdfsFS fs = hdfsConnectAsUser("default", 0, client->name, groups, 1); 781 782 // Perform the actual deletion 783 // 784 if (hdfsDelete(fs, path) == -1) 785 return XrdHdfs::Emsg(epname, error, errno, "remove", path); 786 787 // All done 788 // 789 return SFS_OK; 790 } 791 792 /******************************************************************************/ 793 /* r e n a m e */ 794 /******************************************************************************/ 795 796 int XrdHdfs::rename(const char *old_name, // In 797 const char *new_name, // In 798 XrdOucErrInfo &error, //Out 799 const XrdSecClientName *client, // In 800 const char *infoO, // In 801 const char *infoN) // In 802 /* 803 Function: Renames a file/directory with name 'old_name' to 'new_name'. 804 805 Input: old_name - Is the fully qualified name of the file to be renamed. 806 new_name - Is the fully qualified name that the file is to have. 807 error - Error information structure, if an error occurs. 808 client - Authentication credentials, if any. 809 info - old_name opaque information, if any. 810 info - new_name opaque information, if any. 811 812 Output: Returns SFS_OK upon success and SFS_ERROR upon failure. 813 */ 814 { 815 static const char *epname = "rename"; 816 const char * groups[1] = {client->grps}; 817 hdfsFS fs = hdfsConnectAsUser("default", 0, client->name, groups, 1); 818 819 // Perform actual rename operation 820 // 821 if (hdfsRename(fs, old_name, new_name) == -1) 822 return XrdHdfs::Emsg(epname, error, errno, "rename", old_name); 823 824 // All done 825 // 826 return SFS_OK; 827 } 828 829 /******************************************************************************/ 830 /* s t a t */ 831 /******************************************************************************/ 832 833 int XrdHdfs::stat(const char *path, // In 834 struct stat *buf, // Out 835 XrdOucErrInfo &error, // Out 836 const XrdSecClientName *client, // In 837 const char *info) // In 477 const char *XrdHdfsSys::getVersion() {return XrdVERSION;} 478 479 /******************************************************************************/ 480 /* S t a t */ 481 /******************************************************************************/ 482 483 int XrdHdfsSys::Stat(const char *path, // In 484 struct stat *buf, // Out 485 int ) // In 838 486 /* 839 487 Function: Get info on 'path'. … … 845 493 info - Opaque information, if any. 846 494 847 Output: Returns SFS_OK upon success and SFS_ERRORupon failure.495 Output: Returns XrdOssOK upon success and -errno upon failure. 848 496 */ 849 497 { 850 498 static const char *epname = "stat"; 851 const char * groups[1] = { client->grps};852 hdfsFS fs = hdfsConnectAsUser("default", 0, client->name, groups, 1);499 const char * groups[1] = {"nobody"}; 500 hdfsFS fs = hdfsConnectAsUser("default", 0, "nobody", groups, 1); 853 501 854 502 hdfsFileInfo * fileInfo = hdfsGetPathInfo(fs, path); … … 857 505 // 858 506 if (fileInfo == NULL) 859 return XrdHdfs ::Emsg(epname, error, errno, "state", path);507 return XrdHdfsSys::Emsg(epname, error, errno, "state", path); 860 508 861 509 buf->st_mode = (fileInfo->mKind == kObjectKindDirectory) ? (S_IFDIR | 0777):\ … … 876 524 // All went well 877 525 // 878 return SFS_OK; 879 } 880 881 /******************************************************************************/ 882 /* t r u n c a t e */ 883 /******************************************************************************/ 884 885 int XrdHdfs::truncate(const char *path, // In 886 XrdSfsFileOffset flen, // In 887 XrdOucErrInfo &error, // Out 888 const XrdSecClientName *client, // In 889 const char *info) // In 890 /* 891 Function: Set the length of the file object to 'flen' bytes. 892 893 Input: path - The path to the file. 894 flen - The new size of the file. 895 einfo - Error information object to hold error details. 896 client - Authentication credentials, if any. 897 info - Opaque information, if any. 898 899 Output: Returns SFS_OK upon success and SFS_ERROR upon failure. 900 901 Notes: If 'flen' is smaller than the current size of the file, the file 902 is made smaller and the data past 'flen' is discarded. If 'flen' 903 is larger than the current size of the file, a hole is created 904 (i.e., the file is logically extended by filling the extra bytes 905 with zeroes). 906 */ 907 { 908 static const char *epname = "trunc"; 909 910 return XrdHdfs::Emsg(epname,error,ENOTSUP, "Truncate not" 911 " supported by HDFS.",path); 912 } 526 return XrdOssOK; 527 } 528 913 529 914 530 /******************************************************************************/ … … 916 532 /******************************************************************************/ 917 533 918 int XrdHdfs ::Emsg(const char *pfx, // Message prefix value534 int XrdHdfsSys::Emsg(const char *pfx, // Message prefix value 919 535 XrdOucErrInfo &einfo, // Place to put text & error code 920 536 int ecode, // The error code … … 937 553 // 938 554 #ifndef NODEBUG 939 eDest->Emsg(pfx, buffer);555 OssEroute.Emsg(pfx, buffer); 940 556 #endif 941 557 … … 944 560 einfo.setErrInfo(ecode, buffer); 945 561 946 return SFS_ERROR; 947 } 562 if (errno != 0) 563 return -errno; 564 return -1; 565 } XrdHdfs/XrdHdfs.hh
r3116 r3536 16 16 #include <string.h> 17 17 #include <dirent.h> 18 19 #include "XrdSfs/XrdSfsInterface.hh" 18 19 #include "XrdOuc/XrdOucErrInfo.hh" 20 21 #include "XrdOss/XrdOssApi.hh" 22 #include "XrdSfs/XrdSfsAio.hh" 20 23 21 24 #include "hdfs.h" 22 25 23 class XrdS ysError;26 class XrdSfsAio; 24 27 class XrdSysLogger; 25 28 … … 28 31 /******************************************************************************/ 29 32 30 class XrdHdfsDirectory : public Xrd SfsDirectory33 class XrdHdfsDirectory : public XrdOssDF 31 34 { 32 35 public: 36 XrdOucErrInfo error; 33 37 34 int open(const char *dirName,35 const XrdSecClientName *client = 0,36 const char *opaque =0);38 int Opendir(const char *dirName); 39 int Readdir(char *buff, int blen); 40 int Close(long long *retsz=0); 37 41 38 const char *nextEntry(); 39 40 int close(); 41 42 const char *FName() {return (const char *)fname;} 43 44 XrdHdfsDirectory(char *user=0) : XrdSfsDirectory(user) 42 XrdHdfsDirectory(const char *tid=0) : XrdOssDF() 45 43 { 46 44 const char * groups[1] = {"nobody"}; 47 fs = hdfsConnectAsUser("default", 0, user,45 fs = hdfsConnectAsUser("default", 0, tid, 48 46 groups, 1); 49 47 dh = (hdfsFileInfo*)NULL; … … 60 58 int dirPos; 61 59 char *fname; 60 const char *tident; 61 int isopen; 62 62 63 63 }; … … 67 67 /******************************************************************************/ 68 68 69 class XrdHdfsFile : public Xrd SfsFile69 class XrdHdfsFile : public XrdOssDF 70 70 { 71 71 public: 72 72 73 int open(const char *fileName, 74 XrdSfsFileOpenMode openMode, 73 XrdOucErrInfo error; 74 75 int Open(const char *fileName, 76 int openMode, 75 77 mode_t createMode, 76 const XrdSecClientName *client = 0, 77 const char *opaque = 0); 78 XrdOucEnv &client); 78 79 79 int close();80 int Close(long long *retsz=0); 80 81 81 int fctl(const int cmd, 82 const char *args, 83 XrdOucErrInfo &out_error); 82 int Fstat(struct stat *); 84 83 85 const char *FName() {return fname;}84 int Fsync() {return -ENOTSUP;} 86 85 87 int getMmap(void **Addr, off_t &Size) 88 {if (Addr) Addr = 0; Size = 0; return SFS_OK;} 86 int Fsync(XrdSfsAio *a) {return -ENOTSUP;} 89 87 90 int read(XrdSfsFileOffset fileOffset,91 XrdSfsXferSize preread_sz) {return SFS_OK;}88 off_t getMmap(void **Addr) 89 {*Addr = 0; return 0;} 92 90 93 XrdSfsXferSize read(XrdSfsFileOffset fileOffset, 94 char *buffer, 95 XrdSfsXferSize buffer_size); 91 ssize_t Read(off_t fileOffset, 92 size_t preread_sz) {return XrdOssOK;} 96 93 97 int read(XrdSfsAio *aioparm); 94 ssize_t Read(void *buffer, 95 off_t fileOffset, 96 size_t buffer_size); 98 97 99 XrdSfsXferSize write(XrdSfsFileOffset fileOffset, 100 const char *buffer, 101 XrdSfsXferSize buffer_size); 98 int Read(XrdSfsAio *aioparm); 102 99 103 int write(XrdSfsAio *aioparm); 100 ssize_t ReadRaw(void *buffer, 101 off_t fileOffset, 102 size_t buffer_size) {return Read(buffer, fileOffset, buffer_size);} 104 103 105 int sync(); 104 ssize_t Write(const char *buffer, 105 off_t fileOffset, 106 size_t buffer_size); 106 107 107 int sync(XrdSfsAio *aiop);108 int Write(XrdSfsAio *aioparm); 108 109 109 int stat(struct stat *buf);110 int Ftruncate(unsigned long long) {return -ENOTSUP;} 110 111 111 int truncate(XrdSfsFileOffset fileOffset); 112 113 int getCXinfo(char cxtype[4], int &cxrsz) {return cxrsz = 0;} 114 115 XrdHdfsFile(char *user=0) : XrdSfsFile(user) 112 XrdHdfsFile(const char *user=0) : XrdOssDF() 116 113 { 117 114 const char * groups[1] = {"nobody"}; … … 134 131 /******************************************************************************/ 135 132 136 class XrdHdfs : public XrdSfsFileSystem133 class XrdHdfsSys : public XrdOss 137 134 { 138 135 public: 136 XrdOucErrInfo error; 139 137 140 138 // Object Allocation Functions 141 139 // 142 Xrd SfsDirectory *newDir(char *user=0)143 {return (Xrd SfsDirectory *)new XrdHdfsDirectory(user);}140 XrdOssDF *newDir(const char *user=0) 141 {return (XrdHdfsDirectory *)new XrdHdfsDirectory(user);} 144 142 145 Xrd SfsFile *newFile(char *user=0)146 {return (Xrd SfsFile *)new XrdHdfsFile(user);}143 XrdOssDF *newFile(const char *user=0) 144 {return (XrdHdfsFile *)new XrdHdfsFile(user);} 147 145 148 146 // Other Functions 149 147 // 150 int chmod(const char *Name, 151 XrdSfsMode Mode, 152 XrdOucErrInfo &out_error, 153 const XrdSecClientName *client = 0, 154 const char *opaque = 0); 148 int Chmod(const char *, mode_t) {return -ENOTSUP;} 155 149 156 int exists(const char *fileName, 157 XrdSfsFileExistence &exists_flag, 158 XrdOucErrInfo &out_error, 159 const XrdSecClientName *client = 0, 160 const char *opaque = 0); 150 int Create(const char *, const char *, mode_t, XrdOucEnv &, int opts=0) {return -ENOTSUP;} 161 151 162 int fsctl(const int cmd, 163 const char *args, 164 XrdOucErrInfo &out_error, 165 const XrdSecClientName *client = 0); 152 int Init(XrdSysLogger *, const char *) {return 0;} 166 153 167 154 int getStats(char *buff, int blen) {return 0;} … … 169 156 const char *getVersion(); 170 157 171 int mkdir(const char *dirName, 172 XrdSfsMode Mode, 173 XrdOucErrInfo &out_error, 174 const XrdSecClientName *client = 0, 175 const char *opaque = 0); 158 int Mkdir(const char *, mode_t, int) {return -ENOTSUP;} 176 159 177 int prepare( XrdSfsPrep &pargs, 178 XrdOucErrInfo &out_error, 179 const XrdSecClientName *client = 0) {return 0;} 160 int Remdir(const char *) {return -ENOTSUP;} 180 161 181 int rem(const char *path, 182 XrdOucErrInfo &out_error, 183 const XrdSecClientName *client = 0, 184 const char *opaque = 0); 162 int Rename(const char *, const char *) {return -ENOTSUP;} 185 163 186 int remdir(const char *dirName, 187 XrdOucErrInfo &out_error, 188 const XrdSecClientName *client = 0, 189 const char *opaque = 0); 164 int Stat(const char *, struct stat *, int resonly=0); 190 165 191 int rename(const char *oldFileName, 192 const char *newFileName, 193 XrdOucErrInfo &out_error, 194 const XrdSecClientName *client = 0, 195 const char *opaqueO = 0, 196 const char *opaqueN = 0); 166 int Truncate(const char *, unsigned long long) {return -ENOTSUP;} 197 167 198 int stat(const char *Name, 199 struct stat *buf, 200 XrdOucErrInfo &out_error, 201 const XrdSecClientName *client = 0, 202 const char *opaque = 0); 203 204 int stat(const char *Name, 205 mode_t &mode, 206 XrdOucErrInfo &out_error, 207 const XrdSecClientName *client = 0, 208 const char *opaque = 0) 209 {struct stat bfr; 210 int rc = stat(Name, &bfr, out_error, client); 211 if (!rc) mode = bfr.st_mode; 212 return rc; 213 } 214 215 int truncate(const char *Name, 216 XrdSfsFileOffset fileOffset, 217 XrdOucErrInfo &out_error, 218 const XrdSecEntity *client = 0, 219 const char *opaque = 0); 220 221 // Common functions 222 // 223 static int Mkpath(const char *path, mode_t mode, 224 const char *info=0); 168 int Unlink(const char *) {return -ENOTSUP;} 225 169 226 170 static int Emsg(const char *, XrdOucErrInfo&, int, const char *x, 227 171 const char *y=""); 228 172 229 XrdHdfs(XrdSysError *lp); 230 virtual ~XrdHdfs() {} 231 232 private: 233 234 static XrdSysError *eDest; 173 XrdHdfsSys() : XrdOss() {} 174 virtual ~XrdHdfsSys() {} 235 175 236 176 };
