15 #ifndef __STDC_FORMAT_MACROS
16 #define __STDC_FORMAT_MACROS
19 #include "cvmfs_config.h"
26 #include <sys/socket.h>
28 #include <sys/types.h>
71 for (
unsigned i = 0; i < list.size(); ++i) {
72 list_str += list[i] +
"\n";
74 Answer(con_fd, list_str);
79 const string &socket_path,
84 talk_manager(
new TalkManager(socket_path, mount_point, remounter));
93 socket_path.c_str(), talk_manager->
socket_fd_);
100 vector<string> host_chain;
102 unsigned active_host;
104 download_mgr->
GetHostInfo(&host_chain, &rtt, &active_host);
105 if (host_chain.size() == 0)
106 return "No hosts defined\n";
109 for (
unsigned i = 0; i < host_chain.size(); ++i) {
110 host_str +=
" [" +
StringifyInt(i) +
"] " + host_chain[i] +
" (";
112 host_str +=
"unprobed";
114 host_str +=
"host down";
116 host_str +=
"geographically ordered";
121 host_str +=
"Active host " +
StringifyInt(active_host) +
": " +
122 host_chain[active_host] +
"\n";
127 vector< vector<download::DownloadManager::ProxyInfo> > proxy_chain;
128 unsigned active_group;
129 unsigned fallback_group;
131 download_mgr->
GetProxyInfo(&proxy_chain, &active_group, &fallback_group);
133 if (proxy_chain.size()) {
134 proxy_str +=
"Load-balance groups:\n";
135 for (
unsigned i = 0; i < proxy_chain.size(); ++i) {
137 for (
unsigned j = 0; j < proxy_chain[i].size(); ++j) {
138 urls.push_back(proxy_chain[i][j].Print());
143 proxy_str +=
"Active proxy: [" +
StringifyInt(active_group) +
"] " +
144 proxy_chain[active_group][0].url +
"\n";
145 if (fallback_group < proxy_chain.size())
146 proxy_str +=
"First fallback group: [" +
149 proxy_str =
"No proxies defined\n";
166 struct sockaddr_un remote;
167 socklen_t socket_size =
sizeof(remote);
171 shutdown(con_fd, SHUT_RDWR);
177 (
struct sockaddr *)&remote,
185 char buf[kMaxCommandSize];
187 if ((bytes_read = recv(con_fd, buf,
sizeof(buf), 0)) <= 0)
190 if (buf[bytes_read-1] ==
'\0')
192 const string line = string(buf, bytes_read);
194 line.c_str(), line.length());
196 if (line ==
"tracebuffer flush") {
198 talk_mgr->
Answer(con_fd,
"OK\n");
199 }
else if (line ==
"cache size") {
202 talk_mgr->
Answer(con_fd,
"Cache cannot report its size\n");
204 uint64_t size_unpinned = quota_mgr->
GetSize();
206 const string size_str =
"Current cache size is " +
211 talk_mgr->
Answer(con_fd, size_str);
213 }
else if (line ==
"cache instance") {
215 }
else if (line ==
"cache list") {
218 talk_mgr->
Answer(con_fd,
"Cache cannot list its entries\n");
220 vector<string> ls = quota_mgr->
List();
223 }
else if (line ==
"cache list pinned") {
226 talk_mgr->
Answer(con_fd,
"Cache cannot list its entries\n");
228 vector<string> ls_pinned = quota_mgr->
ListPinned();
231 }
else if (line ==
"cache list catalogs") {
234 talk_mgr->
Answer(con_fd,
"Cache cannot list its entries\n");
239 }
else if (line.substr(0, 12) ==
"cleanup rate") {
242 talk_mgr->
Answer(con_fd,
"Unsupported by this cache\n");
244 if (line.length() < 14) {
245 talk_mgr->
Answer(con_fd,
"Usage: cleanup rate <period in mn>\n");
247 const uint64_t period_s =
String2Uint64(line.substr(13)) * 60;
252 }
else if (line.substr(0, 7) ==
"cleanup") {
255 talk_mgr->
Answer(con_fd,
"Cache cannot trigger eviction\n");
257 if (line.length() < 9) {
258 talk_mgr->
Answer(con_fd,
"Usage: cleanup <MB>\n");
261 if (quota_mgr->
Cleanup(size)) {
262 talk_mgr->
Answer(con_fd,
"OK\n");
264 talk_mgr->
Answer(con_fd,
"Not fully cleaned "
265 "(there might be pinned chunks)\n");
269 }
else if (line.substr(0, 5) ==
"evict") {
271 if (line.length() < 7) {
272 talk_mgr->
Answer(con_fd,
"Usage: evict <path>\n");
274 const string path = line.substr(6);
277 talk_mgr->
Answer(con_fd,
"OK\n");
279 talk_mgr->
Answer(con_fd,
"No such regular file\n");
281 }
else if (line.substr(0, 3) ==
"pin") {
283 if (line.length() < 5) {
284 talk_mgr->
Answer(con_fd,
"Usage: pin <path>\n");
286 const string path = line.substr(4);
289 talk_mgr->
Answer(con_fd,
"OK\n");
291 talk_mgr->
Answer(con_fd,
"No such regular file or pinning failed\n");
293 }
else if (line ==
"mountpoint") {
295 }
else if (line ==
"device id") {
299 talk_mgr->
Answer(con_fd,
"0:0\n");
300 }
else if (line.substr(0, 13) ==
"send mount fd") {
302 if (line.length() < 15) {
303 talk_mgr->
Answer(con_fd,
"EINVAL\n");
305 std::string socket_path = line.substr(14);
307 talk_mgr->
Answer(con_fd, retval ?
"OK\n" :
"Failed\n");
309 "Attempt to send fuse connection info to new mount (via %s)%s",
310 socket_path.c_str(), retval ?
"" :
" -- failed!");
312 }
else if (line.substr(0, 7) ==
"remount") {
314 if (line ==
"remount sync")
317 status = remounter->
Check();
320 talk_mgr->
Answer(con_fd,
"Failed\n");
323 talk_mgr->
Answer(con_fd,
"Failed (no space)\n");
326 talk_mgr->
Answer(con_fd,
"Catalog up to date\n");
329 talk_mgr->
Answer(con_fd,
"New revision applied\n");
332 talk_mgr->
Answer(con_fd,
"In maintenance mode\n");
335 talk_mgr->
Answer(con_fd,
"internal error\n");
337 }
else if (line.substr(0, 6) ==
"chroot") {
338 if (line.length() < 8) {
339 talk_mgr->
Answer(con_fd,
"Usage: chroot <hash>\n");
341 std::string root_hash =
Trim(line.substr(7),
true );
346 talk_mgr->
Answer(con_fd,
"OK\n");
349 talk_mgr->
Answer(con_fd,
"Failed\n");
353 }
else if (line ==
"detach nested catalogs") {
355 talk_mgr->
Answer(con_fd,
"OK\n");
356 }
else if (line ==
"revision") {
358 talk_mgr->
Answer(con_fd, revision +
"\n");
359 }
else if (line ==
"max ttl info") {
360 const unsigned max_ttl = mount_point->
GetMaxTtlMn();
362 talk_mgr->
Answer(con_fd,
"unset\n");
364 const string max_ttl_str =
StringifyInt(max_ttl) +
" minutes\n";
365 talk_mgr->
Answer(con_fd, max_ttl_str);
367 }
else if (line.substr(0, 11) ==
"max ttl set") {
368 if (line.length() < 13) {
369 talk_mgr->
Answer(con_fd,
"Usage: max ttl set <minutes>\n");
373 talk_mgr->
Answer(con_fd,
"OK\n");
375 }
else if (line.substr(0, 14) ==
"nameserver get") {
377 const string reply = !dns_server.empty() ?
378 std::string(
"DNS server address: ") + dns_server +
"\n":
379 std::string(
"DNS server not set.\n");
380 talk_mgr->
Answer(con_fd, reply);
381 }
else if (line.substr(0, 14) ==
"nameserver set") {
382 if (line.length() < 16) {
383 talk_mgr->
Answer(con_fd,
"Usage: nameserver set <host>\n");
385 const string host = line.substr(15);
387 talk_mgr->
Answer(con_fd,
"OK\n");
389 }
else if (line ==
"external host info") {
390 string external_host_info =
392 talk_mgr->
Answer(con_fd, external_host_info);
393 }
else if (line ==
"host info") {
395 talk_mgr->
Answer(con_fd, host_info);
396 }
else if (line ==
"host probe") {
398 talk_mgr->
Answer(con_fd,
"OK\n");
399 }
else if (line ==
"host probe geo") {
402 talk_mgr->
Answer(con_fd,
"OK\n");
404 talk_mgr->
Answer(con_fd,
"Failed\n");
405 }
else if (line ==
"external host switch") {
407 talk_mgr->
Answer(con_fd,
"OK\n");
408 }
else if (line ==
"host switch") {
410 talk_mgr->
Answer(con_fd,
"OK\n");
411 }
else if (line.substr(0, 17) ==
"external host set") {
412 if (line.length() < 19) {
413 talk_mgr->
Answer(con_fd,
"Usage: external host set <URL>\n");
415 const std::string host = line.substr(18);
417 talk_mgr->
Answer(con_fd,
"OK\n");
419 }
else if (line.substr(0, 8) ==
"host set") {
420 if (line.length() < 10) {
421 talk_mgr->
Answer(con_fd,
"Usage: host set <host list>\n");
423 const string hosts = line.substr(9);
425 talk_mgr->
Answer(con_fd,
"OK\n");
427 }
else if (line ==
"external proxy info") {
428 string external_proxy_info =
430 talk_mgr->
Answer(con_fd, external_proxy_info);
431 }
else if (line ==
"proxy info") {
434 talk_mgr->
Answer(con_fd, proxy_info);
435 }
else if (line ==
"proxy rebalance") {
437 talk_mgr->
Answer(con_fd,
"OK\n");
438 }
else if (line ==
"proxy group switch") {
440 talk_mgr->
Answer(con_fd,
"OK\n");
441 }
else if (line.substr(0, 18) ==
"external proxy set") {
442 if (line.length() < 20) {
443 talk_mgr->
Answer(con_fd,
"Usage: external proxy set <proxy list>\n");
445 string external_proxies = line.substr(19);
448 talk_mgr->
Answer(con_fd,
"OK\n");
450 }
else if (line.substr(0, 9) ==
"proxy set") {
451 if (line.length() < 11) {
452 talk_mgr->
Answer(con_fd,
"Usage: proxy set <proxy list>\n");
454 string proxies = line.substr(10);
459 talk_mgr->
Answer(con_fd,
"Failed, no valid proxies\n");
463 talk_mgr->
Answer(con_fd,
"OK\n");
466 }
else if (line.substr(0, 14) ==
"proxy fallback") {
467 if (line.length() < 15) {
468 talk_mgr->
Answer(con_fd,
"Usage: proxy fallback <proxy list>\n");
470 string fallback_proxies = line.substr(15);
473 talk_mgr->
Answer(con_fd,
"OK\n");
475 }
else if (line ==
"timeout info") {
477 unsigned timeout_direct;
479 string timeout_str =
"Timeout with proxy: ";
483 timeout_str +=
"no timeout\n";
484 timeout_str +=
"Timeout without proxy: ";
488 timeout_str +=
"no timeout\n";
489 talk_mgr->
Answer(con_fd, timeout_str);
490 }
else if (line.substr(0, 11) ==
"timeout set") {
491 if (line.length() < 13) {
492 talk_mgr->
Answer(con_fd,
"Usage: timeout set <proxy> <direct>\n");
495 uint64_t timeout_direct;
498 talk_mgr->
Answer(con_fd,
"OK\n");
500 }
else if (line ==
"open catalogs") {
502 }
else if (line ==
"internal affairs") {
563 result +=
"\nCache Mode: ";
566 result +=
"read-write";
569 result +=
"read-only";
576 bool maintenance_mode;
578 result +=
"\nDrainout Mode: " +
StringifyBool(drainout_mode) +
"\n";
579 result +=
"Maintenance Mode: " +
StringifyBool(maintenance_mode) +
"\n";
582 result +=
"\nNFS Map Statistics:\n";
586 result +=
"SQlite Statistics:\n";
587 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, ¤t, &highwater, 0);
588 result +=
" Number of allocations " +
StringifyInt(current) +
"\n";
590 sqlite3_status(SQLITE_STATUS_MEMORY_USED, ¤t, &highwater, 0);
591 result +=
" General purpose allocator " +
StringifyInt(current/1024) +
594 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, ¤t, &highwater, 0);
595 result +=
" Largest malloc " +
StringifyInt(highwater) +
" Bytes\n";
597 sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, ¤t, &highwater, 0);
598 result +=
" Page cache allocations " +
StringifyInt(current) +
" / " +
601 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW,
602 ¤t, &highwater, 0);
603 result +=
" Page cache overflows " +
StringifyInt(current/1024) +
606 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, ¤t, &highwater, 0);
607 result +=
" Largest page cache allocation " +
StringifyInt(highwater) +
610 sqlite3_status(SQLITE_STATUS_SCRATCH_USED, ¤t, &highwater, 0);
611 result +=
" Scratch allocations " +
StringifyInt(current) +
" / " +
614 sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, ¤t, &highwater, 0);
615 result +=
" Scratch overflows " +
StringifyInt(current) +
" / " +
618 sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, ¤t, &highwater, 0);
619 result +=
" Largest scratch allocation " +
StringifyInt(highwater/1024)
622 result +=
"\nPer-Connection Memory Statistics:\n" +
625 result +=
"\nLatency distribution of system calls:\n";
629 result +=
"Multi-Forget\n"
640 result +=
"\nRaw Counters:\n" +
643 talk_mgr->
Answer(con_fd, result);
644 }
else if (line ==
"reset error counters") {
646 talk_mgr->
Answer(con_fd,
"OK\n");
647 }
else if (line ==
"pid") {
649 talk_mgr->
Answer(con_fd, pid_str);
650 }
else if (line ==
"pid cachemgr") {
651 const string pid_str =
653 talk_mgr->
Answer(con_fd, pid_str);
654 }
else if (line ==
"pid watchdog") {
656 talk_mgr->
Answer(con_fd, pid_str);
657 }
else if (line ==
"parameters") {
659 }
else if (line ==
"hotpatch history") {
662 " (start of CernVM-FS loader " +
664 for (loader::EventList::const_iterator i =
669 " (loaded CernVM-FS Fuse Module " +
670 (*i)->so_version +
")\n";
672 talk_mgr->
Answer(con_fd, history_str);
673 }
else if (line ==
"vfs inodes") {
682 talk_mgr->
Answer(con_fd, result);
683 }
else if (line ==
"vfs entries") {
687 uint64_t inode_parent;
690 &cursor, &inode_parent, &name))
696 talk_mgr->
Answer(con_fd, result);
697 }
else if (line ==
"version") {
698 string version_str = string(VERSION) +
" (CernVM-FS Fuse Module)\n" +
700 talk_mgr->
Answer(con_fd, version_str);
701 }
else if (line ==
"version patchlevel") {
702 talk_mgr->
Answer(con_fd,
string(CVMFS_PATCH_LEVEL) +
"\n");
703 }
else if (line ==
"tear down to read-only") {
705 talk_mgr->
Answer(con_fd,
"not supported\n");
710 talk_mgr->
Answer(con_fd,
"In read-only mode\n");
712 }
else if (line ==
"latency") {
714 talk_mgr->
Answer(con_fd, result);
716 talk_mgr->
Answer(con_fd,
"unknown command\n");
726 const unsigned int bufSize = 300;
727 char buffer[bufSize];
746 string repo(mount_point.
fqrn());
748 unsigned int format_index =
749 snprintf(buffer, bufSize,
"\"%s\",\"%s\",\"%s\",\"%s\"",
"repository",
750 "action",
"total_count",
"time_unit");
751 for (
unsigned int i = 0; i < qs.size(); i++) {
752 format_index += snprintf(buffer + format_index, bufSize - format_index,
755 format_index += snprintf(buffer + format_index, bufSize - format_index,
"\n");
756 assert(format_index < bufSize);
759 memset(buffer, 0,
sizeof(buffer));
762 vector<Log2Histogram *> hist;
763 vector<string> names;
765 names.push_back(
"lookup");
767 names.push_back(
"forget");
769 names.push_back(
"forget_multi");
771 names.push_back(
"getattr");
773 names.push_back(
"readlink");
775 names.push_back(
"opendir");
777 names.push_back(
"releasedir");
779 names.push_back(
"readdir");
781 names.push_back(
"open");
783 names.push_back(
"read");
785 names.push_back(
"release");
787 for (
unsigned int j = 0; j < hist.size(); j++) {
789 unsigned int format_index =
790 snprintf(buffer, bufSize,
"\"%s\",\"%s\",%" PRIu64
",\"nanoseconds\"",
791 repo.c_str(), names[j].c_str(), h->
N());
792 for (
unsigned int i = 0; i < qs.size(); i++) {
793 format_index += snprintf(buffer + format_index, bufSize - format_index,
797 snprintf(buffer + format_index, bufSize - format_index,
"\n");
798 assert(format_index < bufSize);
801 memset(buffer, 0,
sizeof(buffer));
808 const string &socket_path,
814 , remounter_(remounter)
824 if ((retval != 0) && (errno != ENOENT)) {
826 "Could not remove cvmfs_io socket from cache directory (%d)",
OptionsManager * options_mgr()
void UnregisterQuotaListener()
int MakeSocket(const std::string &path, const int mode)
FileSystem * file_system()
atomic_int64 num_hits_inode
Log2Histogram * hist_fs_opendir()
atomic_int64 num_misses_path
Statistics GetStatistics()
virtual uint64_t GetCleanupRate(uint64_t period_s)=0
void SetHostChain(const std::string &host_list)
perf::Statistics * statistics()
virtual std::vector< std::string > List()=0
static const int kProbeGeo
string Trim(const string &raw, bool trim_newline)
virtual bool Cleanup(const uint64_t leave_size)=0
string JoinStrings(const vector< string > &strings, const string &joint)
std::string PrintInodeGeneration()
const history::History * history() const
void SetProxyChain(const std::string &proxy_list, const std::string &fallback_proxy_list, const ProxySetModes set_mode)
MountPoint * mount_point_
FuseRemounter * remounter_
std::string FormatProxyInfo(download::DownloadManager *download_mgr)
std::string FormatLatencies(const MountPoint &mount_point, FileSystem *file_system)
virtual std::vector< std::string > ListPinned()=0
assert((mem||(size==0))&&"Out Of Memory")
MountPoint * mount_point_
Log2Histogram * hist_fs_read()
virtual std::vector< std::string > ListCatalogs()=0
std::string loader_version
virtual uint64_t GetSize()=0
string StringifyTime(const time_t seconds, const bool utc)
void EndEnumerate(Cursor *cursor)
void SetDnsServer(const std::string &address)
virtual CacheManagerIds id()=0
void SetTimeout(const unsigned seconds_proxy, const unsigned seconds_direct)
bool Pin(const string &path)
unsigned int GetQuantile(float n)
static TalkManager * Create(const std::string &socket_path, MountPoint *mount_point, FuseRemounter *remounter)
string StringifyBool(const bool value)
void Answer(int con_fd, const std::string &msg)
static uint64_t num_instances()
Counter * Lookup(const std::string &name) const
glue::PageCacheTracker * page_cache_tracker()
void SetMaxTtlMn(unsigned value_minutes)
void GetProxyInfo(std::vector< std::vector< ProxyInfo > > *proxy_chain, unsigned *current_group, unsigned *fallback_group)
catalog::ClientCatalogManager * catalog_mgr()
void Set(const int64_t val)
Log2Histogram * hist_fs_forget_multi()
Status CheckSynchronously()
Log2Histogram * hist_fs_release()
const loader::LoaderExports * loader_exports_
Statistics GetStatistics()
Statistics GetStatistics()
TalkManager(const std::string &socket_path, MountPoint *mount_point, FuseRemounter *remounter)
virtual std::string GetStatistics()
Log2Histogram * hist_fs_releasedir()
const char kSuffixCatalog
bool NextEntry(Cursor *cursor, uint64_t *inode_parent, NameString *name)
CacheManager * cache_mgr()
bool NextInode(Cursor *cursor, uint64_t *inode)
bool SendFuseFd(const std::string &socket_path)
download::DownloadManager * download_mgr()
virtual uint64_t GetSizePinned()=0
Status ChangeRoot(const shash::Any &root_hash)
Log2Histogram * hist_fs_readlink()
string StringifyInt(const int64_t value)
glue::DentryTracker * dentry_tracker()
Log2Histogram * hist_fs_readdir()
atomic_int64 num_references
std::string FormatHostInfo(download::DownloadManager *download_mgr)
Log2Histogram * hist_fs_open()
std::string GetDnsServer() const
std::string ToString() const
QuotaManager * quota_mgr()
uint64_t GetRevision() const
Log2Histogram * hist_fs_lookup()
string ResolveProxyDescription(const string &cvmfs_proxies, const std::string &path_fallback_cache, DownloadManager *download_manager)
uint64_t String2Uint64(const string &value)
static void * MainResponder(void *data)
void ResetErrorCounters()
bool Evict(const string &path)
std::string PrintList(const PrintOptions print_options)
void GetTimeout(unsigned *seconds_proxy, unsigned *seconds_direct)
void GetReloadStatus(bool *drainout_mode, bool *maintenance_mode)
Any MkFromHexPtr(const HexPtr hex, const char suffix)
static const int kProbeUnprobed
Log2Histogram * hist_fs_forget()
static const int kProbeDown
atomic_int64 num_hits_path
static uint64_t num_overflows()
Log2Histogram * hist_fs_getattr()
void GetHostInfo(std::vector< std::string > *host_chain, std::vector< int > *rtt, unsigned *current_host)
std::string PrintHierarchy() const
glue::InodeTracker * inode_tracker()
std::string PrintAllMemStatistics() const
virtual std::string Describe()=0
void AnswerStringList(int con_fd, const std::vector< std::string > &list)
virtual bool HasCapability(Capabilities capability)=0
download::DownloadManager * external_download_mgr()
void String2Uint64Pair(const string &value, uint64_t *a, uint64_t *b)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)