XRootD
Loading...
Searching...
No Matches
XrdSfsNativeFile Class Reference

#include <XrdSfsNative.hh>

+ Inheritance diagram for XrdSfsNativeFile:
+ Collaboration diagram for XrdSfsNativeFile:

Public Member Functions

 XrdSfsNativeFile (char *user=0, int monid=0)
 
 ~XrdSfsNativeFile ()
 
int close ()
 
virtual int fctl (const int cmd, const char *args, XrdOucErrInfo &eInfo)=0
 
int fctl (const int cmd, const char *args, XrdOucErrInfo &out_error)
 
virtual int fctl (const int cmd, int alen, const char *args, const XrdSecEntity *client=0)
 
const char * FName ()
 
int getCXinfo (char cxtype[4], int &cxrsz)
 
int getMmap (void **Addr, off_t &Size)
 
int open (const char *fileName, XrdSfsFileOpenMode openMode, mode_t createMode, const XrdSecClientName *client=0, const char *opaque=0)
 
int read (XrdSfsAio *aioparm)
 
XrdSfsXferSize read (XrdSfsFileOffset fileOffset, char *buffer, XrdSfsXferSize buffer_size)
 
int read (XrdSfsFileOffset fileOffset, XrdSfsXferSize preread_sz)
 
XrdSfsXferSize readv (XrdOucIOVec *readV, int readCount)
 
int stat (struct stat *buf)
 
int sync ()
 
int sync (XrdSfsAio *aiop)
 
int truncate (XrdSfsFileOffset fileOffset)
 
int write (XrdSfsAio *aioparm)
 
XrdSfsXferSize write (XrdSfsFileOffset fileOffset, const char *buffer, XrdSfsXferSize buffer_size)
 
- Public Member Functions inherited from XrdSfsFile
 XrdSfsFile (const char *user=0, int MonID=0)
 
 XrdSfsFile (XrdOucErrInfo &eInfo)
 
 XrdSfsFile (XrdSfsFile &wrapF)
 
virtual ~XrdSfsFile ()
 Destructor.
 
virtual int checkpoint (cpAct act, struct iov *range=0, int n=0)
 
virtual int open (const char *fileName, XrdSfsFileOpenMode openMode, mode_t createMode, const XrdSecEntity *client=0, const char *opaque=0)=0
 
virtual int pgRead (XrdSfsAio *aioparm, uint64_t opts=0)
 
virtual XrdSfsXferSize pgRead (XrdSfsFileOffset offset, char *buffer, XrdSfsXferSize rdlen, uint32_t *csvec, uint64_t opts=0)
 
virtual int pgWrite (XrdSfsAio *aioparm, uint64_t opts=0)
 
virtual XrdSfsXferSize pgWrite (XrdSfsFileOffset offset, char *buffer, XrdSfsXferSize wrlen, uint32_t *csvec, uint64_t opts=0)
 
virtual int SendData (XrdSfsDio *sfDio, XrdSfsFileOffset offset, XrdSfsXferSize size)
 
virtual void setXio (XrdSfsXio *xioP)
 
virtual XrdSfsXferSize writev (XrdOucIOVec *writeV, int wdvCnt)
 

Additional Inherited Members

- Public Types inherited from XrdSfsFile
enum  cpAct {
  cpCreate =0 ,
  cpDelete ,
  cpRestore ,
  cpQuery ,
  cpTrunc ,
  cpWrite
}
 
- Public Attributes inherited from XrdSfsFile
XrdOucErrInfoerror
 
- Static Public Attributes inherited from XrdSfsFile
static const uint64_t Verify = 0x8000000000000000ULL
 Options for pgRead() and pgWrite() as noted below.
 

Detailed Description

Definition at line 87 of file XrdSfsNative.hh.

Constructor & Destructor Documentation

◆ XrdSfsNativeFile()

XrdSfsNativeFile::XrdSfsNativeFile ( char *  user = 0,
int  monid = 0 
)
inline

Definition at line 137 of file XrdSfsNative.hh.

138 : XrdSfsFile(user, monid)
139 {oh = -1; fname = 0;}

◆ ~XrdSfsNativeFile()

XrdSfsNativeFile::~XrdSfsNativeFile ( )
inline

Definition at line 140 of file XrdSfsNative.hh.

140{if (oh) close();}

References close().

+ Here is the call graph for this function:

Member Function Documentation

◆ close()

int XrdSfsNativeFile::close ( )
virtual

Close the file.

Returns
One of SFS_OK or SFS_ERROR.

Implements XrdSfsFile.

Definition at line 353 of file XrdSfsNative.cc.

361{
362 static const char *epname = "close";
363
364// Release the handle and return
365//
366 if (oh >= 0 && XrdSfsUFS::Close(oh))
367 return XrdSfsNative::Emsg(epname, error, errno, "close", fname);
368 oh = -1;
369 if (fname) {free(fname); fname = 0;}
370 return SFS_OK;
371}
#define SFS_OK
XrdOucErrInfo & error
static int Emsg(const char *, XrdOucErrInfo &, int, const char *x, const char *y="")
static int Close(int fd)

References XrdSfsUFS::Close(), XrdSfsNative::Emsg(), XrdSfsFile::error, and SFS_OK.

Referenced by ~XrdSfsNativeFile(), and open().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fctl() [1/3]

virtual int XrdSfsFile::fctl ( const int  cmd,
const char *  args,
XrdOucErrInfo eInfo 
)
virtual

Execute a special operation on the file (version 1)

Parameters
cmd- The operation to be performed (see below). SFS_FCTL_GETFD Return file descriptor if possible SFS_FCTL_STATV Reserved for future use.
args- specific arguments to cmd SFS_FCTL_GETFD Set to zero.
eInfo- The object where error info or results are to be returned. This is legacy and the error onject may be used as well.
Returns
If an error occurs or the operation is not support, SFS_ERROR should be returned with error.code set to errno. Otherwise, SFS_FCTL_GETFD error.code holds the real file descriptor number If the value is negative, sendfile() is not used. If the value is SFS_SFIO_FDVAL then the SendData() method is used for future read requests.

Implements XrdSfsFile.

◆ fctl() [2/3]

int XrdSfsNativeFile::fctl ( const int  cmd,
const char *  args,
XrdOucErrInfo eInfo 
)
virtual

Execute a special operation on the file (version 1)

Parameters
cmd- The operation to be performed (see below). SFS_FCTL_GETFD Return file descriptor if possible SFS_FCTL_STATV Reserved for future use.
args- specific arguments to cmd SFS_FCTL_GETFD Set to zero.
eInfo- The object where error info or results are to be returned. This is legacy and the error onject may be used as well.
Returns
If an error occurs or the operation is not support, SFS_ERROR should be returned with error.code set to errno. Otherwise, SFS_FCTL_GETFD error.code holds the real file descriptor number If the value is negative, sendfile() is not used. If the value is SFS_SFIO_FDVAL then the SendData() method is used for future read requests.

Implements XrdSfsFile.

Definition at line 377 of file XrdSfsNative.cc.

380{
381// See if we can do this
382//
383 if (cmd == SFS_FCTL_GETFD)
384 {out_error.setErrCode(oh);
385 return SFS_OK;
386 }
387
388// We don't support this
389//
390 out_error.setErrInfo(ENOTSUP, "fctl operation not supported");
391 return SFS_ERROR;
392}
#define SFS_ERROR
#define SFS_FCTL_GETFD

References XrdOucErrInfo::setErrCode(), XrdOucErrInfo::setErrInfo(), SFS_ERROR, SFS_FCTL_GETFD, and SFS_OK.

+ Here is the call graph for this function:

◆ fctl() [3/3]

int XrdSfsFile::fctl ( const int  cmd,
int  alen,
const char *  args,
const XrdSecEntity client = 0 
)
virtual

Execute a special operation on the file (version 2)

Parameters
cmd- The operation to be performed: SFS_FCTL_SPEC1 Perform implementation defined action
alen- Length of data pointed to by args.
args- Data sent with request, zero if alen is zero.
client- Client's identify (see common description).
Returns
SFS_OK a null response is sent.
SFS_DATA error.code length of the data to be sent. error.message contains the data to be sent. o/w one of SFS_ERROR, SFS_REDIRECT, or SFS_STALL.

Reimplemented from XrdSfsFile.

Definition at line 489 of file XrdSfsInterface.cc.

84{
85 (void)cmd; (void)alen; (void)args; (void)client;
86 return SFS_OK;
87}

◆ FName()

const char * XrdSfsNativeFile::FName ( )
inlinevirtual

Get the file path.

Returns
Null terminated string of the path used in open().

Implements XrdSfsFile.

Definition at line 104 of file XrdSfsNative.hh.

104{return fname;}

◆ getCXinfo()

int XrdSfsNativeFile::getCXinfo ( char  cxtype[4],
int &  cxrsz 
)
inlinevirtual

Get compression information for the file.

Parameters
cxtype- Place where the compression algorithm name is to be placed
cxrsz- Place where the compression page size is to be returned
Returns
One of the valid SFS return codes described above. If the file is not compressed or an error is returned, cxrsz must be set to 0.

Implements XrdSfsFile.

Definition at line 135 of file XrdSfsNative.hh.

135{return cxrsz = 0;}

◆ getMmap()

int XrdSfsNativeFile::getMmap ( void **  Addr,
off_t &  Size 
)
inlinevirtual

Get file's memory mapping if one exists (memory mapped files only).

Parameters
Addr- Place where the starting memory address is returned.
Size- Place where the file's size is returned.
Returns
SFS_OK when the file is memory mapped or any other code otherwise.

Implements XrdSfsFile.

Definition at line 106 of file XrdSfsNative.hh.

107 {if (Addr) Addr = 0; Size = 0; return SFS_OK;}

References SFS_OK.

◆ open()

int XrdSfsNativeFile::open ( const char *  fileName,
XrdSfsFileOpenMode  openMode,
mode_t  createMode,
const XrdSecClientName client = 0,
const char *  opaque = 0 
)

Definition at line 267 of file XrdSfsNative.cc.

292{
293 static const char *epname = "open";
294 const int AMode = S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH; // 775
295 char *opname;
296 mode_t acc_mode = Mode & S_IAMB;
297 int retc, open_flag = 0;
298 struct stat buf;
299
300// Verify that this object is not already associated with an open file
301//
302 if (oh >= 0)
303 return XrdSfsNative::Emsg(epname,error,EADDRINUSE,"open file",path);
304 fname = strdup(path);
305
306// Set the actual open mode
307//
308 switch(open_mode & (SFS_O_RDONLY | SFS_O_WRONLY | SFS_O_RDWR))
309 {
310 case SFS_O_RDONLY: open_flag = O_RDONLY; break;
311 case SFS_O_WRONLY: open_flag = O_WRONLY; break;
312 case SFS_O_RDWR: open_flag = O_RDWR; break;
313 default: open_flag = O_RDONLY; break;
314 }
315
316// Prepare to create or open the file, as needed
317//
318 if (open_mode & SFS_O_CREAT)
319 {open_flag = O_RDWR | O_CREAT | O_EXCL;
320 opname = (char *)"create";
321 if ((Mode & SFS_O_MKPTH) && (retc = XrdSfsNative::Mkpath(path,AMode,info)))
322 return XrdSfsNative::Emsg(epname,error,retc,"create path for",path);
323 } else if (open_mode & SFS_O_TRUNC)
324 {open_flag = O_RDWR | O_CREAT | O_TRUNC;
325 opname = (char *)"truncate";
326 } else opname = (char *)"open";
327
328// Open the file and make sure it is a file
329//
330 if ((oh = XrdSfsUFS::Open(path, open_flag, acc_mode)) >= 0)
331 {do {retc = XrdSfsUFS::Statfd(oh, &buf);} while(retc && errno == EINTR);
332 if (!retc && !(buf.st_mode & S_IFREG))
333 {close(); oh = (buf.st_mode & S_IFDIR ? -EISDIR : -ENOTBLK);}
334 } else {
335 oh = -errno;
336 if (errno == EEXIST)
337 {do {retc = XrdSfsUFS::Statfn(path, &buf);}
338 while(retc && errno == EINTR);
339 if (!retc && (buf.st_mode & S_IFDIR)) oh = -EISDIR;
340 }
341 }
342
343// All done.
344//
345 if (oh < 0) return XrdSfsNative::Emsg(epname, error, oh, opname, path);
346 return SFS_OK;
347}
#define S_IAMB
Definition XrdConfig.cc:159
#define stat(a, b)
Definition XrdPosix.hh:96
int Mode
#define SFS_O_MKPTH
#define SFS_O_RDONLY
#define SFS_O_WRONLY
#define SFS_O_CREAT
#define SFS_O_RDWR
#define SFS_O_TRUNC
static int Mkpath(const char *path, mode_t mode, const char *info=0)
static int Open(const char *path, int oflag, mode_t omode)
static int Statfd(int fd, struct stat *buf)
static int Statfn(const char *fn, struct stat *buf)

References close(), XrdSfsNative::Emsg(), XrdSfsFile::error, XrdSfsNative::Mkpath(), Mode, XrdSfsUFS::Open(), S_IAMB, SFS_O_CREAT, SFS_O_MKPTH, SFS_O_RDONLY, SFS_O_RDWR, SFS_O_TRUNC, SFS_O_WRONLY, SFS_OK, stat, XrdSfsUFS::Statfd(), and XrdSfsUFS::Statfn().

+ Here is the call graph for this function:

◆ read() [1/3]

int XrdSfsNativeFile::read ( XrdSfsAio aioparm)
virtual

Read file bytes using asynchronous I/O.

Parameters
aioparm- Pointer to async I/O object controlling the I/O.
Returns
SFS_OK Request accepted and will be scheduled.
SFS_ERROR File could not be read, error holds the reason.

Implements XrdSfsFile.

Definition at line 478 of file XrdSfsNative.cc.

479{
480
481// Execute this request in a synchronous fashion
482//
483 aiop->Result = this->read((XrdSfsFileOffset)aiop->sfsAio.aio_offset,
484 (char *)aiop->sfsAio.aio_buf,
485 (XrdSfsXferSize)aiop->sfsAio.aio_nbytes);
486 aiop->doneRead();
487 return 0;
488}
#define read(a, b, c)
Definition XrdPosix.hh:77
long long XrdSfsFileOffset
int XrdSfsXferSize

References aiocb::aio_buf, aiocb::aio_nbytes, aiocb::aio_offset, XrdSfsAio::doneRead(), read, XrdSfsAio::Result, and XrdSfsAio::sfsAio.

+ Here is the call graph for this function:

◆ read() [2/3]

XrdSfsXferSize XrdSfsNativeFile::read ( XrdSfsFileOffset  offset,
char *  buffer,
XrdSfsXferSize  size 
)
virtual

Read file bytes into a buffer.

Parameters
offset- The offset where the read is to start.
buffer- pointer to buffer where the bytes are to be placed.
size- The number of bytes to read.
Returns
>= 0 The number of bytes that placed in buffer.
SFS_ERROR File could not be read, error holds the reason.

Implements XrdSfsFile.

Definition at line 398 of file XrdSfsNative.cc.

412{
413 static const char *epname = "read";
414 XrdSfsXferSize nbytes;
415
416// Make sure the offset is not too large
417//
418#if _FILE_OFFSET_BITS!=64
419 if (offset > 0x000000007fffffff)
420 return XrdSfsNative::Emsg(epname, error, EFBIG, "read", fname);
421#endif
422
423// Read the actual number of bytes
424//
425 do { nbytes = pread(oh, (void *)buff, (size_t)blen, (off_t)offset); }
426 while(nbytes < 0 && errno == EINTR);
427
428 if (nbytes < 0)
429 return XrdSfsNative::Emsg(epname, error, errno, "read", fname);
430
431// Return number of bytes read
432//
433 return nbytes;
434}
#define pread(a, b, c, d)
Definition XrdPosix.hh:75

References XrdSfsNative::Emsg(), XrdSfsFile::error, and pread.

+ Here is the call graph for this function:

◆ read() [3/3]

int XrdSfsNativeFile::read ( XrdSfsFileOffset  offset,
XrdSfsXferSize  size 
)
inlinevirtual

Preread file blocks into the file system cache.

Parameters
offset- The offset where the read is to start.
size- The number of bytes to pre-read.
Returns
>= 0 The number of bytes that will be pre-read.
SFS_ERROR File could not be preread, error holds the reason.

Implements XrdSfsFile.

Definition at line 109 of file XrdSfsNative.hh.

110 {return SFS_OK;}

References SFS_OK.

◆ readv()

XrdSfsXferSize XrdSfsNativeFile::readv ( XrdOucIOVec readV,
int  rdvCnt 
)
virtual

Given an array of read requests (size rdvCnt), read them from the file and place the contents consecutively in the provided buffer. A dumb default implementation is supplied but should be replaced to increase performance.

Parameters
readVpointer to the array of read requests.
rdvCntthe number of elements in readV.
Returns
>=0 The numbe of bytes placed into the buffer.
SFS_ERROR File could not be read, error holds the reason.

Reimplemented from XrdSfsFile.

Definition at line 440 of file XrdSfsNative.cc.

454{
455 static const char *epname = "readv";
456 XrdSfsXferSize nbytes = 0;
457 ssize_t curCount;
458 int i;
459
460 for (i=0; i<int(readCount); i++)
461 {do {curCount = pread(oh, (void *)readV[i].data, (size_t)readV[i].size, (off_t)readV[i].offset);}
462 while(curCount < 0 && errno == EINTR);
463
464 if (curCount != readV[i].size)
465 {if (curCount > 0) errno = ESPIPE;
466 return XrdSfsNative::Emsg(epname, error, errno, "readv", fname);
467 }
468 nbytes += curCount;
469 }
470
471 return nbytes;
472}

References XrdSfsNative::Emsg(), XrdSfsFile::error, and pread.

+ Here is the call graph for this function:

◆ stat()

int XrdSfsNativeFile::stat ( struct stat *  buf)
virtual

Return state information on the file.

Parameters
buf- Pointer to the structure where info it to be returned.
Returns
One of SFS_OK, SFS_ERROR, SFS_REDIRECT, or SFS_STALL. When SFS_OK is returned, buf must hold stat information.

Implements XrdSfsFile.

Definition at line 555 of file XrdSfsNative.cc.

563{
564 static const char *epname = "stat";
565
566// Execute the function
567//
568 if (XrdSfsUFS::Statfd(oh, buf))
569 return XrdSfsNative::Emsg(epname, error, errno, "state", fname);
570
571// All went well
572//
573 return SFS_OK;
574}

References XrdSfsNative::Emsg(), XrdSfsFile::error, SFS_OK, and XrdSfsUFS::Statfd().

+ Here is the call graph for this function:

◆ sync() [1/2]

int XrdSfsNativeFile::sync ( )
virtual

Make sure all outstanding data is actually written to the file (sync).

Returns
One of SFS_OK, SFS_ERROR, SFS_REDIRECT, SFS_STALL, or SFS_STARTED

Implements XrdSfsFile.

Definition at line 580 of file XrdSfsNative.cc.

588{
589 static const char *epname = "sync";
590
591// Perform the function
592//
593 if (fsync(oh))
594 return XrdSfsNative::Emsg(epname,error,errno,"synchronize",fname);
595
596// All done
597//
598 return SFS_OK;
599}
#define fsync(a)
Definition XrdPosix.hh:59

References XrdSfsNative::Emsg(), XrdSfsFile::error, fsync, and SFS_OK.

Referenced by sync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sync() [2/2]

int XrdSfsNativeFile::sync ( XrdSfsAio aiop)
virtual

Make sure all outstanding data is actually written to the file (async).

Returns
SFS_OK Request accepted and will be scheduled.
SFS_ERROR Request could not be accepted, return error has reason.

Implements XrdSfsFile.

Definition at line 605 of file XrdSfsNative.cc.

606{
607
608// Execute this request in a synchronous fashion
609//
610 aiop->Result = this->sync();
611 aiop->doneWrite();
612 return 0;
613}
ssize_t Result
Definition XrdSfsAio.hh:65
virtual void doneWrite()=0

References XrdSfsAio::doneWrite(), XrdSfsAio::Result, and sync().

+ Here is the call graph for this function:

◆ truncate()

int XrdSfsNativeFile::truncate ( XrdSfsFileOffset  fsize)
virtual

Truncate the file.

Parameters
fsize- The size that the file is to have.
Returns
One of SFS_OK, SFS_ERROR, SFS_REDIRECT, or SFS_STALL

Implements XrdSfsFile.

Definition at line 619 of file XrdSfsNative.cc.

633{
634 static const char *epname = "trunc";
635
636// Make sure the offset is not too larg
637//
638 if (sizeof(off_t) < sizeof(flen) && flen > 0x000000007fffffff)
639 return XrdSfsNative::Emsg(epname, error, EFBIG, "truncate", fname);
640
641// Perform the function
642//
643 if (ftruncate(oh, flen))
644 return XrdSfsNative::Emsg(epname, error, errno, "truncate", fname);
645
646// All done
647//
648 return SFS_OK;
649}
#define ftruncate(a, b)
Definition XrdPosix.hh:65

References XrdSfsNative::Emsg(), XrdSfsFile::error, ftruncate, and SFS_OK.

+ Here is the call graph for this function:

◆ write() [1/2]

int XrdSfsNativeFile::write ( XrdSfsAio aioparm)
virtual

Write file bytes using asynchronous I/O.

Parameters
aioparm- Pointer to async I/O object controlling the I/O.
Returns
0 Request accepted and will be scheduled.
!0 Request not accepted, returned value is errno.

Implements XrdSfsFile.

Definition at line 539 of file XrdSfsNative.cc.

540{
541
542// Execute this request in a synchronous fashion
543//
544 aiop->Result = this->write((XrdSfsFileOffset)aiop->sfsAio.aio_offset,
545 (char *)aiop->sfsAio.aio_buf,
546 (XrdSfsXferSize)aiop->sfsAio.aio_nbytes);
547 aiop->doneWrite();
548 return 0;
549}
#define write(a, b, c)
Definition XrdPosix.hh:110

References aiocb::aio_buf, aiocb::aio_nbytes, aiocb::aio_offset, XrdSfsAio::doneWrite(), XrdSfsAio::Result, XrdSfsAio::sfsAio, and write.

+ Here is the call graph for this function:

◆ write() [2/2]

XrdSfsXferSize XrdSfsNativeFile::write ( XrdSfsFileOffset  offset,
const char *  buffer,
XrdSfsXferSize  size 
)
virtual

Write file bytes from a buffer.

Parameters
offset- The offset where the write is to start.
buffer- pointer to buffer where the bytes reside.
size- The number of bytes to write.
Returns
>= 0 The number of bytes that were written.
SFS_ERROR File could not be written, error holds the reason.

Implements XrdSfsFile.

Definition at line 494 of file XrdSfsNative.cc.

511{
512 static const char *epname = "write";
513 XrdSfsXferSize nbytes;
514
515// Make sure the offset is not too large
516//
517#if _FILE_OFFSET_BITS!=64
518 if (offset > 0x000000007fffffff)
519 return XrdSfsNative::Emsg(epname, error, EFBIG, "write", fname);
520#endif
521
522// Write the requested bytes
523//
524 do { nbytes = pwrite(oh, (void *)buff, (size_t)blen, (off_t)offset); }
525 while(nbytes < 0 && errno == EINTR);
526
527 if (nbytes < 0)
528 return XrdSfsNative::Emsg(epname, error, errno, "write", fname);
529
530// Return number of bytes written
531//
532 return nbytes;
533}
#define pwrite(a, b, c, d)
Definition XrdPosix.hh:102

References XrdSfsNative::Emsg(), XrdSfsFile::error, and pwrite.

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: