CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cache_transport.h
Go to the documentation of this file.
1 
4 #ifndef CVMFS_CACHE_TRANSPORT_H_
5 #define CVMFS_CACHE_TRANSPORT_H_
6 
7 #include <stdint.h>
8 
9 #include <cstdlib>
10 
11 #include "cache.h"
12 #include "cache.pb.h"
13 #include "util/single_copy.h"
14 
15 namespace shash {
16 struct Any;
17 }
18 
19 inline const char *CacheTransportCode2Ascii(const cvmfs::EnumStatus code) {
20  switch (code) {
21  case cvmfs::STATUS_UNKNOWN:
22  return "unknown cache protocol error";
23  case cvmfs::STATUS_OK:
24  return "OK";
25  case cvmfs::STATUS_NOSUPPORT:
26  return "operation not implemented by cache plugin";
27  case cvmfs::STATUS_FORBIDDEN:
28  return "cache plugin denied the operation";
29  case cvmfs::STATUS_NOSPACE:
30  return "no space in cache";
31  case cvmfs::STATUS_NOENTRY:
32  return "object not found in cache";
33  case cvmfs::STATUS_MALFORMED:
34  return "malformed cache protocol message";
35  case cvmfs::STATUS_IOERR:
36  return "I/O error";
37  case cvmfs::STATUS_CORRUPTED:
38  return "corrupted data detected";
39  case cvmfs::STATUS_TIMEOUT:
40  return "multipart request timed out";
41  case cvmfs::STATUS_BADCOUNT:
42  return "invalid attempt to set negative reference count";
43  case cvmfs::STATUS_OUTOFBOUNDS:
44  return "out of bounds";
45  case cvmfs::STATUS_PARTIAL:
46  return "cache could not be cleaned up to the given limit";
47  default:
48  return "unexpected cache protocol error";
49  }
50 }
51 
57  public:
62  static const char *kEnvReadyNotifyFd; // __CVMFS_CACHE_EXTERNAL_PIPE_READY__
63  static const char kReadyNotification = 'C';
64  static const char kFailureNotification = 'F';
69  static const unsigned char kWireProtocolVersion = 0x01;
75  static const unsigned char kFlagHasAttachment = 0x80;
79  static const uint32_t kMaxMsgSize = (2 << 24) - 1; // 24MB (3 bytes)
85  static const unsigned kHeaderSize = 4;
91  static const unsigned kInnerHeaderSize = 2;
92 
93  static const uint32_t kFlagSendIgnoreFailure = 0x01;
94  static const uint32_t kFlagSendNonBlocking = 0x02;
95 
96 
105  class Frame : SingleCopy {
106  public:
107  Frame();
108  explicit Frame(google::protobuf::MessageLite *m);
109  ~Frame();
110  void MergeFrom(const Frame &other);
111  void Reset(uint32_t original_att_size);
112 
113  void *attachment() const { return attachment_; }
114  uint32_t att_size() const { return att_size_; }
115  void set_att_size(uint32_t size) { att_size_ = size; }
116  void set_attachment(void *attachment, uint32_t att_size) {
119  }
120 
121  bool ParseMsgRpc(void *buffer, uint32_t size);
122  cvmfs::MsgRpc *GetMsgRpc();
123  google::protobuf::MessageLite *GetMsgTyped();
124  // The Detach message does not follow the command-reply pattern
125  bool IsMsgOutOfBand();
126 
127  private:
128  void WrapMsg();
129  void UnwrapMsg();
130  void Release();
131 
132  cvmfs::MsgRpc msg_rpc_;
138  google::protobuf::MessageLite *msg_typed_;
139  void *attachment_;
140  uint32_t att_size_;
143  }; // class CacheTransport::Frame
144 
145 
146  explicit CacheTransport(int fd_connection);
147  CacheTransport(int fd_connection, uint32_t flags);
149 
150  void SendFrame(Frame *frame);
151  bool RecvFrame(Frame *frame);
152 
153  void FillMsgHash(const shash::Any &hash, cvmfs::MsgHash *msg_hash);
154  bool ParseMsgHash(const cvmfs::MsgHash &msg_hash, shash::Any *hash);
155  void FillObjectType(int object_flags, cvmfs::EnumObjectType *wire_type);
156  bool ParseObjectType(cvmfs::EnumObjectType wire_type, int *object_flags);
157 
158  int fd_connection() const { return fd_connection_; }
159 
160  private:
161  static const unsigned kMaxStackAlloc = 256 * 1024; // 256 kB
162 
163  void SendData(void *message,
164  uint32_t msg_size,
165  void *attachment = NULL,
166  uint32_t att_size = 0);
167  void SendNonBlocking(struct iovec *iov, unsigned iovcnt);
168  bool RecvHeader(uint32_t *size, bool *has_attachment);
169 
171  uint32_t flags_;
172 }; // class CacheTransport
173 
174 #endif // CVMFS_CACHE_TRANSPORT_H_
static const unsigned kMaxStackAlloc
static const unsigned char kWireProtocolVersion
void SendNonBlocking(struct iovec *iov, unsigned iovcnt)
void SendFrame(Frame *frame)
void FillObjectType(int object_flags, cvmfs::EnumObjectType *wire_type)
static const char kReadyNotification
static const uint32_t kFlagSendIgnoreFailure
void FillMsgHash(const shash::Any &hash, cvmfs::MsgHash *msg_hash)
void MergeFrom(const Frame &other)
static const uint32_t kMaxMsgSize
void * attachment() const
bool ParseMsgHash(const cvmfs::MsgHash &msg_hash, shash::Any *hash)
cvmfs::MsgRpc * GetMsgRpc()
uint32_t att_size() const
void set_att_size(uint32_t size)
google::protobuf::MessageLite * msg_typed_
static const unsigned char kFlagHasAttachment
google::protobuf::MessageLite * GetMsgTyped()
void SendData(void *message, uint32_t msg_size, void *attachment=NULL, uint32_t att_size=0)
static const char kFailureNotification
bool ParseMsgRpc(void *buffer, uint32_t size)
bool RecvFrame(Frame *frame)
void set_attachment(void *attachment, uint32_t att_size)
static const unsigned kInnerHeaderSize
void Reset(uint32_t original_att_size)
static void size_t size
Definition: smalloc.h:54
const char * CacheTransportCode2Ascii(const cvmfs::EnumStatus code)
static const unsigned kHeaderSize
int fd_connection() const
static const char * kEnvReadyNotifyFd
static const uint32_t kFlagSendNonBlocking
bool ParseObjectType(cvmfs::EnumObjectType wire_type, int *object_flags)
CacheTransport(int fd_connection)
bool RecvHeader(uint32_t *size, bool *has_attachment)