CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
quota.cc
Go to the documentation of this file.
1 
6 #include "quota.h"
7 
8 #include <errno.h>
9 #include <unistd.h>
10 
11 #include <cstdlib>
12 
13 #include "util/concurrency.h"
14 #include "util/logging.h"
15 #include "util/smalloc.h"
16 
17 using namespace std; // NOLINT
18 
19 const uint32_t QuotaManager::kProtocolRevision = 2;
20 
21 void QuotaManager::BroadcastBackchannels(const string &message) {
22  assert(message.length() > 0);
23  MutexLockGuard lock_guard(*lock_back_channels_);
24 
25  for (map<shash::Md5, int>::iterator i = back_channels_.begin(),
26  iend = back_channels_.end();
27  i != iend;) {
28  LogCvmfs(kLogQuota, kLogDebug, "broadcasting %s to %s", message.c_str(),
29  i->first.ToString().c_str());
30  int written = write(i->second, message.data(), message.length());
31  if (written < 0)
32  written = 0;
33  if (static_cast<unsigned>(written) != message.length()) {
34  bool remove_backchannel = errno != EAGAIN;
36  "failed to broadcast '%s' to %s (written %d, error %d)",
37  message.c_str(), i->first.ToString().c_str(), written, errno);
38  if (remove_backchannel) {
40  "removing back channel %s", i->first.ToString().c_str());
41  map<shash::Md5, int>::iterator remove_me = i;
42  ++i;
43  close(remove_me->second);
44  back_channels_.erase(remove_me);
45  } else {
46  ++i;
47  }
48  } else {
49  ++i;
50  }
51  }
52 }
53 
54 
55 QuotaManager::QuotaManager() : protocol_revision_(0) {
56  lock_back_channels_ = reinterpret_cast<pthread_mutex_t *>(
57  smalloc(sizeof(pthread_mutex_t)));
58  int retval = pthread_mutex_init(lock_back_channels_, NULL);
59  assert(retval == 0);
60 }
61 
62 
64  for (map<shash::Md5, int>::iterator i = back_channels_.begin(),
65  iend = back_channels_.end();
66  i != iend;
67  ++i) {
68  close(i->second);
69  }
70  pthread_mutex_destroy(lock_back_channels_);
71  free(lock_back_channels_);
72 }
pthread_mutex_t * lock_back_channels_
Definition: quota.h:96
void BroadcastBackchannels(const std::string &message)
Definition: quota.cc:21
static const uint32_t kProtocolRevision
Definition: quota.h:45
virtual ~QuotaManager()
Definition: quota.cc:63
assert((mem||(size==0))&&"Out Of Memory")
QuotaManager()
Definition: quota.cc:55
std::map< shash::Md5, int > back_channels_
Definition: quota.h:95
Definition: mutex.h:42
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:545