| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
* |
| 4 |
|
|
* Read-only, inode-based file system interface served by the NFS server. |
| 5 |
|
|
*/ |
| 6 |
|
|
|
| 7 |
|
|
#ifndef CVMFS_NFS4_BACKEND_H_ |
| 8 |
|
|
#define CVMFS_NFS4_BACKEND_H_ |
| 9 |
|
|
|
| 10 |
|
|
#include <stdint.h> |
| 11 |
|
|
#include <sys/types.h> |
| 12 |
|
|
|
| 13 |
|
|
#include <string> |
| 14 |
|
|
#include <vector> |
| 15 |
|
|
|
| 16 |
|
|
namespace nfs4 { |
| 17 |
|
|
|
| 18 |
|
|
struct Timespec { |
| 19 |
|
15210 |
Timespec() : sec(0), nsec(0) { } |
| 20 |
|
|
int64_t sec; |
| 21 |
|
|
uint32_t nsec; |
| 22 |
|
|
}; |
| 23 |
|
|
|
| 24 |
|
|
struct Attr { |
| 25 |
|
5070 |
Attr() : ino(0), mode(0), nlink(1), uid(0), gid(0), size(0), rdev(0) { } |
| 26 |
|
|
|
| 27 |
|
|
uint64_t ino; |
| 28 |
|
|
/** Includes the file type bits (S_IFDIR, ...) */ |
| 29 |
|
|
mode_t mode; |
| 30 |
|
|
uint32_t nlink; |
| 31 |
|
|
uint32_t uid; |
| 32 |
|
|
uint32_t gid; |
| 33 |
|
|
uint64_t size; |
| 34 |
|
|
uint64_t rdev; |
| 35 |
|
|
Timespec atime; |
| 36 |
|
|
Timespec mtime; |
| 37 |
|
|
Timespec ctime; |
| 38 |
|
|
}; |
| 39 |
|
|
|
| 40 |
|
|
struct DirEntry { |
| 41 |
|
|
DirEntry() : ino(0) { } |
| 42 |
|
6526 |
DirEntry(const std::string &n, uint64_t i) : name(n), ino(i) { } |
| 43 |
|
|
std::string name; |
| 44 |
|
|
uint64_t ino; |
| 45 |
|
|
}; |
| 46 |
|
|
|
| 47 |
|
|
struct FsStat { |
| 48 |
|
884 |
FsStat() |
| 49 |
|
884 |
: bytes_total(0) |
| 50 |
|
884 |
, bytes_free(0) |
| 51 |
|
884 |
, bytes_avail(0) |
| 52 |
|
884 |
, files_total(0) |
| 53 |
|
884 |
, files_free(0) |
| 54 |
|
884 |
, files_avail(0) { } |
| 55 |
|
|
uint64_t bytes_total; |
| 56 |
|
|
uint64_t bytes_free; |
| 57 |
|
|
uint64_t bytes_avail; |
| 58 |
|
|
uint64_t files_total; |
| 59 |
|
|
uint64_t files_free; |
| 60 |
|
|
uint64_t files_avail; |
| 61 |
|
|
}; |
| 62 |
|
|
|
| 63 |
|
|
struct Credentials { |
| 64 |
|
312 |
Credentials() : uid(65534), gid(65534) { } |
| 65 |
|
|
uint32_t uid; |
| 66 |
|
|
uint32_t gid; |
| 67 |
|
|
std::vector<uint32_t> gids; |
| 68 |
|
|
}; |
| 69 |
|
|
|
| 70 |
|
|
/** |
| 71 |
|
|
* Methods return 0 or a positive errno. They are called concurrently from the |
| 72 |
|
|
* server's worker threads. Inode numbers must stay valid for the lifetime of |
| 73 |
|
|
* the backend and should survive restarts, because they end up in persistent |
| 74 |
|
|
* NFS file handles. |
| 75 |
|
|
*/ |
| 76 |
|
|
class Backend { |
| 77 |
|
|
public: |
| 78 |
|
416 |
virtual ~Backend() { } |
| 79 |
|
|
|
| 80 |
|
|
virtual uint64_t RootInode() = 0; |
| 81 |
|
|
/** |
| 82 |
|
|
* Identifies the exported file system; part of every file handle so that |
| 83 |
|
|
* handles of a different export are rejected. |
| 84 |
|
|
*/ |
| 85 |
|
|
virtual uint64_t FsId() = 0; |
| 86 |
|
|
/** |
| 87 |
|
|
* Changes whenever the exported tree may have changed (for cvmfs: the root |
| 88 |
|
|
* catalog revision). Used as READDIR cookie verifier and as part of the |
| 89 |
|
|
* change attribute. |
| 90 |
|
|
*/ |
| 91 |
|
|
virtual uint64_t Generation() = 0; |
| 92 |
|
|
|
| 93 |
|
|
virtual int GetAttr(uint64_t ino, Attr *attr) = 0; |
| 94 |
|
|
virtual int Lookup(uint64_t parent, const std::string &name, Attr *attr) = 0; |
| 95 |
|
|
virtual int LookupParent(uint64_t ino, Attr *attr) = 0; |
| 96 |
|
|
virtual int ReadLink(uint64_t ino, std::string *target) = 0; |
| 97 |
|
|
virtual int ReadDir(uint64_t ino, std::vector<DirEntry> *entries) = 0; |
| 98 |
|
|
/** |
| 99 |
|
|
* Fills up to size bytes at offset. A short read means end of file. |
| 100 |
|
|
*/ |
| 101 |
|
|
virtual int Read(uint64_t ino, uint64_t offset, uint32_t size, |
| 102 |
|
|
std::string *data) = 0; |
| 103 |
|
|
/** Hint that a client stopped using the file; may release cached state. */ |
| 104 |
|
✗ |
virtual void Forget(uint64_t /* ino */) { } |
| 105 |
|
|
virtual int StatFs(FsStat *stat) = 0; |
| 106 |
|
|
|
| 107 |
|
|
virtual int ListXattr(uint64_t ino, std::vector<std::string> *names) = 0; |
| 108 |
|
|
virtual int GetXattr(uint64_t ino, const std::string &name, |
| 109 |
|
|
const Credentials &creds, std::string *value) = 0; |
| 110 |
|
|
}; |
| 111 |
|
|
|
| 112 |
|
|
} // namespace nfs4 |
| 113 |
|
|
|
| 114 |
|
|
#endif // CVMFS_NFS4_BACKEND_H_ |
| 115 |
|
|
|