GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/quota.cc
Date: 2024-04-28 02:33:07
Exec Total Coverage
Lines: 34 35 97.1%
Branches: 20 37 54.1%

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 "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 1008 void QuotaManager::BroadcastBackchannels(const string &message) {
22
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1008 times.
1008 assert(message.length() > 0);
23 1008 MutexLockGuard lock_guard(*lock_back_channels_);
24
25 2016 for (map<shash::Md5, int>::iterator i = back_channels_.begin(),
26
2/2
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 1008 times.
2025 iend = back_channels_.end(); i != iend; )
27 {
28
1/2
✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
9 LogCvmfs(kLogQuota, kLogDebug, "broadcasting %s to %s",
29
1/2
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
18 message.c_str(), i->first.ToString().c_str());
30
1/2
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
9 int written = write(i->second, message.data(), message.length());
31
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if (written < 0) written = 0;
32
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8 times.
9 if (static_cast<unsigned>(written) != message.length()) {
33 1 bool remove_backchannel = errno != EAGAIN;
34
1/5
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 LogCvmfs(kLogQuota, kLogDebug | kLogSyslogWarn,
35 "failed to broadcast '%s' to %s (written %d, error %d)",
36
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 message.c_str(), i->first.ToString().c_str(), written, errno);
37
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (remove_backchannel) {
38
1/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 LogCvmfs(kLogQuota, kLogDebug | kLogSyslogWarn,
39
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 "removing back channel %s", i->first.ToString().c_str());
40 1 map<shash::Md5, int>::iterator remove_me = i;
41 1 ++i;
42
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 close(remove_me->second);
43
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 back_channels_.erase(remove_me);
44 } else {
45 ++i;
46 }
47 } else {
48 8 ++i;
49 }
50 }
51 1008 }
52
53
54 407 QuotaManager::QuotaManager() : protocol_revision_(0) {
55 407 lock_back_channels_ =
56 407 reinterpret_cast<pthread_mutex_t *>(smalloc(sizeof(pthread_mutex_t)));
57 407 int retval = pthread_mutex_init(lock_back_channels_, NULL);
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 407 times.
407 assert(retval == 0);
59 407 }
60
61
62 704 QuotaManager::~QuotaManager() {
63 1408 for (map<shash::Md5, int>::iterator i = back_channels_.begin(),
64
2/2
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 352 times.
1410 iend = back_channels_.end(); i != iend; ++i)
65 {
66 2 close(i->second);
67 }
68 704 pthread_mutex_destroy(lock_back_channels_);
69 704 free(lock_back_channels_);
70 }
71