GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/quota.cc Lines: 31 32 96.9 %
Date: 2019-02-03 02:48:13 Branches: 12 16 75.0 %

Line Branch Exec Source
1
/**
2
 * This file is part of the CernVM File System.
3
 */
4
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 "logging.h"
14
#include "smalloc.h"
15
#include "util_concurrency.h"
16
17
using namespace std;  // NOLINT
18
19
const uint32_t QuotaManager::kProtocolRevision = 2;
20
21
1008
void QuotaManager::BroadcastBackchannels(const string &message) {
22
1008
  assert(message.length() > 0);
23
1008
  MutexLockGuard lock_guard(*lock_back_channels_);
24
25
3033
  for (map<shash::Md5, int>::iterator i = back_channels_.begin(),
26
1008
       iend = back_channels_.end(); i != iend; )
27
  {
28
    LogCvmfs(kLogQuota, kLogDebug, "broadcasting %s to %s",
29
9
             message.c_str(), i->first.ToString().c_str());
30
9
    int written = write(i->second, message.data(), message.length());
31
9
    if (written < 0) written = 0;
32
9
    if (static_cast<unsigned>(written) != message.length()) {
33
1
      bool remove_backchannel = errno != EAGAIN;
34
      LogCvmfs(kLogQuota, kLogDebug | kLogSyslogWarn,
35
               "failed to broadcast '%s' to %s (written %d, error %d)",
36
1
               message.c_str(), i->first.ToString().c_str(), written, errno);
37
1
      if (remove_backchannel) {
38
        LogCvmfs(kLogQuota, kLogDebug | kLogSyslogWarn,
39
1
                 "removing back channel %s", i->first.ToString().c_str());
40
1
        map<shash::Md5, int>::iterator remove_me = i;
41
1
        ++i;
42
1
        close(remove_me->second);
43
1
        back_channels_.erase(remove_me);
44
      } else {
45
        ++i;
46
      }
47
    } else {
48
8
      ++i;
49
    }
50
  }
51
1008
}
52
53
54
551
QuotaManager::QuotaManager() : protocol_revision_(0) {
55
  lock_back_channels_ =
56
551
    reinterpret_cast<pthread_mutex_t *>(smalloc(sizeof(pthread_mutex_t)));
57
551
  int retval = pthread_mutex_init(lock_back_channels_, NULL);
58
551
  assert(retval == 0);
59
551
}
60
61
62
479
QuotaManager::~QuotaManager() {
63
959
  for (map<shash::Md5, int>::iterator i = back_channels_.begin(),
64
479
       iend = back_channels_.end(); i != iend; ++i)
65
  {
66
1
    close(i->second);
67
  }
68
479
  pthread_mutex_destroy(lock_back_channels_);
69
479
  free(lock_back_channels_);
70
479
}