From 6e51d8ac7ba3e72979d43efb2b2dec9f9664c623 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 17 May 2007 06:12:54 +0000 Subject: [PATCH] add sigar_file_system_ping util --- include/sigar.h | 4 ++++ src/sigar.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/sigar.h b/include/sigar.h index 13f4a0b8..6503ec09 100644 --- a/include/sigar.h +++ b/include/sigar.h @@ -458,6 +458,10 @@ sigar_file_system_usage_get(sigar_t *sigar, const char *dirname, sigar_file_system_usage_t *fsusage); +SIGAR_DECLARE(int) +sigar_file_system_ping(sigar_t *sigar, + sigar_file_system_t *fs); + typedef struct { enum { SIGAR_AF_UNSPEC, diff --git a/src/sigar.c b/src/sigar.c index 65346f54..d33807c7 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -682,6 +682,46 @@ sigar_file_system_list_destroy(sigar_t *sigar, return SIGAR_OK; } +#ifndef NFS_PROGRAM +#define NFS_PROGRAM 100003 +#endif + +#ifndef NFS_VERSION +#define NFS_VERSION 2 +#endif + +SIGAR_DECLARE(int) +sigar_file_system_ping(sigar_t *sigar, + sigar_file_system_t *fs) +{ + int status = SIGAR_OK; +#ifndef WIN32 + char *ptr; + + if ((fs->type == SIGAR_FSTYPE_NETWORK) && + strEQ(fs->sys_type_name, "nfs") && + (ptr = strchr(fs->dev_name, ':'))) + { + *ptr = '\0'; /* "hostname:/mount" -> "hostname" */ + + status = sigar_rpc_ping(fs->dev_name, + SIGAR_NETCONN_UDP, + NFS_PROGRAM, NFS_VERSION); + + if (SIGAR_LOG_IS_DEBUG(sigar)) { + sigar_log_printf(sigar, SIGAR_LOG_DEBUG, + "[fs_ping] %s -> %s: %s", + fs->dir_name, fs->dev_name, + ((status == SIGAR_OK) ? + "OK" : sigar_rpc_strerror(status))); + } + + *ptr = ':'; /* "hostname" -> "hostname:/mount" */ + } +#endif + return status; +} + int sigar_cpu_info_list_create(sigar_cpu_info_list_t *cpu_infos) { cpu_infos->number = 0;