syntax = "proto3";
package eos.fusex;

message md {
  enum OP { GET = 0; SET = 1; DELETE = 2; GETCAP = 3; LS = 4; GETLK = 5; SETLK = 6; SETLKW = 7; BEGINFLUSH = 8; ENDFLUSH = 9;}
  enum TYPE { MD = 0; MDLS = 1; EXCL = 2;}
  enum FLAG { NONE = 0; DELETEVERSIONS = 1; NORECYCLEBIN = 2; DELETEVERSIONSNORECYCLEBIN = 3;}

  fixed64 id = 1;        //< file/container id
  fixed64 pid = 2;       //< parent id
  fixed64 ctime = 3    ; //< change time
  fixed64 ctime_ns = 4 ; //< ns of creation time
  fixed64 mtime = 5    ; //< modification time | deletion time
  fixed64 mtime_ns = 6 ; //< ns of modification time
  fixed64 atime = 7    ; //< access time
  fixed64 atime_ns = 8 ; //< ns of access time
  fixed64 btime = 9    ; //< birth time
  fixed64 btime_ns = 10; //< ns of birth time
  fixed64 ttime = 11   ; //< tree modification time
  fixed64 ttime_ns = 12; //< ns of tree modification time
  fixed64 pmtime = 13   ; //< parent modification time
  fixed64 pmtime_ns = 14; //< ns of parent modification time
  fixed64 size = 15     ; //< size 
  sfixed32 uid = 16    ; //< user  id
  sfixed32 gid = 17    ; //< group id
  sfixed32 mode = 18   ; //< mode
  sfixed32 nlink = 19  ; //< nlink
  bytes name = 20     ; //< name
  bytes target = 21   ; //< symlink target
  string authid = 22   ; //< strong security auth id
  string clientid = 23 ; //< string identifying a client
  string clientuuid = 24; //< optional string of a temporary client id
  fixed64 clock = 25    ; //< vector clock
  fixed64 reqid = 26    ; //< request ID
  fixed64 md_ino = 27  ; //< central namespace inode
  fixed64 md_pino = 28 ; //< central namespace parent inode
  OP operation = 29    ; //< indicates operations to execute
  TYPE type = 30       ; //< indicates the content of this recored, just MD or MD+children
  sfixed32 err = 31  ; //< errno concerning md record
  map<string, bytes> attr = 32; //< xattribute map
  map<string, fixed64> children = 33; //< children's name and id 
  // children id is a virtual inode on when stored FUSE client side
  // children id is the physical inode when created on server side 
  cap capability = 34; //< optional response capability
  string implied_authid = 35; //< implied auth id from a create call
  lock flock = 36; //< file lock information
  sfixed32 nchildren = 37; //< number of children
  bytes fullpath = 38; //< current path to file/dir
  fixed64 pt_mtime = 39 ; //< modification time for the parent directory
  fixed64 pt_mtime_ns= 40 ; //< ns of modification time for the parent directory
  bool creator = 41; //< indicates we are the creator of this md record
  string mv_authid = 42; //< indicates the authid applying to the source directory of a mv
  fixed64 bc_time = 43; //< indicates the reception time of a broadcasted md record
  FLAG opflags = 44; //< indicates a flag for an operation
};

message md_state {	
  sfixed32 op = 1;		
  sfixed32 lookup_cnt = 2;
  sfixed32 cap_cnt = 3;
  sfixed32 opendir_cnt	= 4;
  bool lock_remote     = 5;
  bool refresh =   6;
  bool rmrf = 7; 
  fixed64 inline_size = 8;
  map<string, fixed64> todelete = 9;
  map<string, fixed64> children = 10;
  map<string, fixed64> enoent = 11;
};

message md_map {
  map<fixed64, md> md_map_ = 1;
};

message dir {
  fixed64 id = 1; //< container id
  repeated string linked = 2;
  repeated string unlinked = 3;
};

message io {
  fixed64 id = 1; //< file id
  fixed64 offset = 2; //< offset
  fixed64 length = 3; //< length
  fixed64 clock = 4; //< vector clock
};

message quota {
  fixed64 inode_quota = 1 ; //< free inode quota
  fixed64 volume_quota = 2; //< free bytes quota
  fixed64 quota_inode = 3; //< inode of the quota node
};

message cap {
  fixed64 id = 1; //< file/container 
  fixed32 mode = 2; //< granted mode
  fixed64 vtime = 3; //< valid until unix timestamp
  fixed64 vtime_ns = 4; //< valid ns resolution
  sfixed32 uid = 5    ; //< user  id
  sfixed32 gid = 6    ; //< group id
  string clientuuid = 7; //< client uuid
  string clientid = 8; //< client id
  string authid = 9; //< auth id
  fixed32 errc = 10; //< error code
  fixed64 clock = 11    ; //< vector clock of the file/container
  fixed64 max_file_size = 12; //< maximum file size
  quota _quota = 13; //< quota information for this cap
};



message cap_map {
   map<fixed64, cap> cap_map_ = 1;
};

message heartbeat {
  enum ProtVersion { PROTOCOLV1 = 0; PROTOCOLV2 = 1; PROTOCOLV3 = 2; PROTOCOLV4 = 3; PROTOCOLV5 = 4;}

  string name = 1; //< client chosen ID	
  string host = 2; //< client host
  string uuid = 3; //< client uuid
  string version = 4; //< client version
  fixed32 pid = 5; //< client pid
  fixed64 starttime = 6; //< client startup time
  fixed64 clock = 7; //< client clock ns when sending
  fixed64 clock_ns = 8; //< client clock ns when sending
  double delta = 9; //< client delta after arrival
  ProtVersion protversion = 10;
  map<string, fixed32> authextension = 11; // < map of authids to extend lifetime by seconds 
  map<string, fixed32> authrevocation = 12; // < map of authids to revoke - pair of authid/unused
  fixed32 leasetime = 13; 
  bool shutdown = 14;
  string mount = 15; //< client mount path
  bool automounted = 16; //< indicate if autofs mount or not  
  string log = 17; //< client logs
  string trace = 18; //< client stacktrace
  string appname = 19; // < client app name
}    

message statistics {
  fixed64 inodes = 1; //< client inodes
  fixed64 inodes_todelete = 2; //< client inodes to delete
  fixed64 inodes_backlog = 3; //< client inodes backlog
  fixed64 inodes_ever = 4; //< client inodes ever used
  fixed64 inodes_ever_deleted = 5; //< client inodes ever deleted
  fixed32 threads = 6; //< client threads in use
  float vsize_mb = 7; //< client virtual memory usage in mb
  float rss_mb = 8; //< client resident memory usage in mb
  fixed32 open_files = 9; //< files currently open on a client
  float total_ram_mb = 10;//< total usable ram size
  float free_ram_mb = 11; //< total free ram size
  float load1 = 12; //< load value 1
  fixed64 rbytes = 13; //< number of bytes read since start
  fixed64 wbytes = 14; //< number of bytes written since start
  float rd_rate_60_mb = 15; //< read rate in 1m window in mb/s
  float wr_rate_60_mb = 16; //< write rate in 1m window in mb/s
  fixed64 nio = 17; //< total number of io's
  float iops_60 = 18; //< average ios in 1m window
  float wr_buf_mb = 19; //< write buffer in use
  float ra_buf_mb = 20; //< read-ahead buffer in use
  fixed64 xoff = 21; //< xoff conditions counter
  fixed64 raxoff = 22; //< read-ahead buffer xoff
  fixed64 ranobuf = 23; //< read-ahead buffer no buffer available
  fixed32 pid = 24; //< process ID of eosxd
  fixed64 logfilesize = 25; //< size of log file
  fixed64 wrnobuf = 26; //< write buffer no buffer available
  float blockedms = 27; //< max time in ms an inode tracking mutex is held in a lock
  string blockedfunc = 28; //< function with is blocked for ms
  fixed32 recovery_ok = 29; // < number of recoveries ok
  fixed32 recovery_fail = 30; // < number of recoveries failed
  fixed32 blockedops = 31; // < number of blocking operations
  bool blockedroot = 32; // < indicate if operation on / is blocking
}

message container {
  enum Type { HEARTBEAT = 0; STATISTICS = 1; MD = 2; DIR = 3; MDMAP = 4; CAP = 5; }

  // Identifies which field is filled in.
  Type type = 1;

  // One of the following will be filled in.
  heartbeat heartbeat_ = 2;
  statistics statistics_ = 3;
  md md_ = 4;
  dir dir_ = 5;
  md_map md_map_ = 6;
  fixed64 ref_inode_ = 7;
  cap cap_ = 8;
  cap_map cap_map_ = 9;
}

message evict {
  string reason = 1; //< reason given by server
}

message ack {
  enum Code { OK = 0; TMP_FAILURE = 1; PERMANENT_FAILURE = 2; }

  Code code = 1; //< ack code 
  fixed64 transactionid = 2; //< transaction id to ack
  fixed32 err_no = 3; //< error number
  fixed64 md_ino = 4; //< newly created inode number
  string err_msg = 5; //< error message
}

message lease {
  enum Type { RELEASECAP = 0; }

  Type type = 1;
  fixed64 md_ino = 2; //< inode number
  string clientid = 3; //< clientid
  string authid = 4; //< authid
}

message dentry {
  enum Type { ADD = 0; REMOVE = 1;}

  Type type = 1; 
  fixed64 md_ino = 2; //< inode number
  bytes name = 3; //< entry name to delete
  string clientid = 4; //< clientid
  string authid = 5; //< authid
  fixed64 pt_mtime = 6 ; //< modification time for the parent directory
  fixed64 pt_mtime_ns= 7 ; //< ns of modification time for the parent directory
}

message refresh {
  fixed64 md_ino = 1; //< inode number
}

message lock {
  enum Type { RDLCK = 0; WRLCK = 1; UNLCK = 2; }
  Type type = 1;   //< type of lock
  fixed64 start = 2; //< offset of lock area
  fixed64 len = 3; //< length of lock area
  fixed64 pid = 4; //< owner of the lock
  fixed32 err_no = 5; //< errno from locking call
}

message config {
  fixed32 hbrate = 1; //< heartbeat interval for this client
  bool dentrymessaging = 2; //< enables dentry invalidation by extra message
  bool writesizeflush = 3; //< allows clients to use writesize flush interval ~= infinite
  string serverversion = 4; //< software version of the server
  bool appname = 5; //< supports extended app names like fuse::smaba not only fuse
  bool mdquery = 6; //< supports fetchResponseQuery 
  bool hideversion = 7; //< supports clients hiding versions ( can delete version server side )
}

message response {
  enum Type { EVICT = 0; ACK = 1; LEASE = 2; LOCK = 3; MD = 4; DROPCAPS = 5; CONFIG = 6; NONE = 7; CAP = 8; DENTRY = 9; REFRESH = 10; }

  // Identifies which field is filled in.
  Type type = 1;
  // One of the following will be filled in.
  evict evict_ = 2;
  ack ack_ = 3;
  lease lease_ = 4;
  lock lock_ = 5;
  md md_ = 6;
  config config_ = 7;
  cap cap_ = 8;
  dentry dentry_ = 9;
  refresh refresh_ = 10;
}
