| Directory: | cvmfs/ |
|---|---|
| File: | cvmfs/quota.cc |
| Date: | 2025-10-19 02:35:28 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 38 | 39 | 97.4% |
| Branches: | 20 | 37 | 54.1% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * This file is part of the CernVM File System. | ||
| 3 | */ | ||
| 4 | |||
| 5 | |||
| 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 | 21301 | void QuotaManager::BroadcastBackchannels(const string &message) { | |
| 22 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 21301 times.
|
21301 | assert(message.length() > 0); |
| 23 | 21301 | const MutexLockGuard lock_guard(*lock_back_channels_); | |
| 24 | |||
| 25 | 42602 | for (map<shash::Md5, int>::iterator i = back_channels_.begin(), | |
| 26 | 21301 | iend = back_channels_.end(); | |
| 27 |
2/2✓ Branch 1 taken 341 times.
✓ Branch 2 taken 21301 times.
|
21642 | i != iend;) { |
| 28 |
1/2✓ Branch 3 taken 341 times.
✗ Branch 4 not taken.
|
341 | LogCvmfs(kLogQuota, kLogDebug, "broadcasting %s to %s", message.c_str(), |
| 29 |
1/2✓ Branch 2 taken 341 times.
✗ Branch 3 not taken.
|
682 | i->first.ToString().c_str()); |
| 30 |
1/2✓ Branch 4 taken 341 times.
✗ Branch 5 not taken.
|
341 | int written = write(i->second, message.data(), message.length()); |
| 31 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 301 times.
|
341 | if (written < 0) |
| 32 | 40 | written = 0; | |
| 33 |
2/2✓ Branch 1 taken 40 times.
✓ Branch 2 taken 301 times.
|
341 | if (static_cast<unsigned>(written) != message.length()) { |
| 34 | 40 | const bool remove_backchannel = errno != EAGAIN; | |
| 35 |
1/5✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
40 | LogCvmfs(kLogQuota, kLogDebug | kLogSyslogWarn, |
| 36 | "failed to broadcast '%s' to %s (written %d, error %d)", | ||
| 37 |
1/2✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
80 | message.c_str(), i->first.ToString().c_str(), written, errno); |
| 38 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | if (remove_backchannel) { |
| 39 |
1/4✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
40 | LogCvmfs(kLogQuota, kLogDebug | kLogSyslogWarn, |
| 40 |
1/2✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
80 | "removing back channel %s", i->first.ToString().c_str()); |
| 41 | 40 | const map<shash::Md5, int>::iterator remove_me = i; | |
| 42 | 40 | ++i; | |
| 43 |
1/2✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
40 | close(remove_me->second); |
| 44 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | back_channels_.erase(remove_me); |
| 45 | } else { | ||
| 46 | ✗ | ++i; | |
| 47 | } | ||
| 48 | } else { | ||
| 49 | 301 | ++i; | |
| 50 | } | ||
| 51 | } | ||
| 52 | 21301 | } | |
| 53 | |||
| 54 | |||
| 55 | 13360 | QuotaManager::QuotaManager() : protocol_revision_(0) { | |
| 56 | 13360 | lock_back_channels_ = reinterpret_cast<pthread_mutex_t *>( | |
| 57 | 13360 | smalloc(sizeof(pthread_mutex_t))); | |
| 58 | 13360 | const int retval = pthread_mutex_init(lock_back_channels_, NULL); | |
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13360 times.
|
13360 | assert(retval == 0); |
| 60 | 13360 | } | |
| 61 | |||
| 62 | |||
| 63 | 25114 | QuotaManager::~QuotaManager() { | |
| 64 | 50228 | for (map<shash::Md5, int>::iterator i = back_channels_.begin(), | |
| 65 | 25114 | iend = back_channels_.end(); | |
| 66 |
2/2✓ Branch 1 taken 40 times.
✓ Branch 2 taken 12557 times.
|
25194 | i != iend; |
| 67 | 80 | ++i) { | |
| 68 | 80 | close(i->second); | |
| 69 | } | ||
| 70 | 25114 | pthread_mutex_destroy(lock_back_channels_); | |
| 71 | 25114 | free(lock_back_channels_); | |
| 72 | } | ||
| 73 |