CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
quota.cc
Go to the documentation of this file.
1 
5 #include "cvmfs_config.h"
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(); i != iend; )
27  {
28  LogCvmfs(kLogQuota, kLogDebug, "broadcasting %s to %s",
29  message.c_str(), i->first.ToString().c_str());
30  int written = write(i->second, message.data(), message.length());
31  if (written < 0) written = 0;
32  if (static_cast<unsigned>(written) != message.length()) {
33  bool remove_backchannel = errno != EAGAIN;
35  "failed to broadcast '%s' to %s (written %d, error %d)",
36  message.c_str(), i->first.ToString().c_str(), written, errno);
37  if (remove_backchannel) {
39  "removing back channel %s", i->first.ToString().c_str());
40  map<shash::Md5, int>::iterator remove_me = i;
41  ++i;
42  close(remove_me->second);
43  back_channels_.erase(remove_me);
44  } else {
45  ++i;
46  }
47  } else {
48  ++i;
49  }
50  }
51 }
52 
53 
54 QuotaManager::QuotaManager() : protocol_revision_(0) {
56  reinterpret_cast<pthread_mutex_t *>(smalloc(sizeof(pthread_mutex_t)));
57  int retval = pthread_mutex_init(lock_back_channels_, NULL);
58  assert(retval == 0);
59 }
60 
61 
63  for (map<shash::Md5, int>::iterator i = back_channels_.begin(),
64  iend = back_channels_.end(); i != iend; ++i)
65  {
66  close(i->second);
67  }
68  pthread_mutex_destroy(lock_back_channels_);
69  free(lock_back_channels_);
70 }
pthread_mutex_t * lock_back_channels_
Definition: quota.h:95
void BroadcastBackchannels(const std::string &message)
Definition: quota.cc:21
static const uint32_t kProtocolRevision
Definition: quota.h:45
virtual ~QuotaManager()
Definition: quota.cc:62
assert((mem||(size==0))&&"Out Of Memory")
QuotaManager()
Definition: quota.cc:54
std::map< shash::Md5, int > back_channels_
Definition: quota.h:94
Definition: mutex.h:42
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:528