/***************************************************************************** Function : memoryworkctlmon Description: 处理get请求,把free字节 + ":"+ total字节写入到xenstore Input :handle : handle of xenstore Output : None Return : 失败:-1,成功:0 *****************************************************************************/ int memoryworkctlmon(struct xs_handle *handle) { char tmp_buffer[TMP_BUFFER_SIZE + 1]; char tmp_swap_buffer[TMP_BUFFER_SIZE + 1]; if (NULL == handle) { return -1; } (void)GetMMUseRatio(PROC_MEMINFO, tmp_buffer, TMP_BUFFER_SIZE, tmp_swap_buffer); if(xb_write_first_flag == 0) { write_to_xenstore(handle, MEM_DATA_PATH, tmp_buffer); write_to_xenstore(handle, SWAP_MEM_DATA_PATH, tmp_swap_buffer); } else { write_weak_to_xenstore(handle, MEM_DATA_PATH, tmp_buffer); write_weak_to_xenstore(handle, SWAP_MEM_DATA_PATH, tmp_swap_buffer); } //write_to_xenstore(handle, MEM_DATA_PATH, tmp_buffer); return 0; }
/***************************************************************************** Function : Ipv6PrintInfo Description: print Ipv4/6 info Input : None Output : None Return : *****************************************************************************/ void Ipv6PrintInfo(void * handle) { unsigned int i = 0; char vif_path[NETINFO_PATH_LEN] = {0}; /*xenstore print info*/ for (i = 0; i < XENSTORE_COUNT; i++) { memset_s(vif_path,NETINFO_PATH_LEN,0,NETINFO_PATH_LEN); /*assemble xenstore path*/ if(i == 0) { (void)snprintf_s(vif_path, NETINFO_PATH_LEN, NETINFO_PATH_LEN, "%s", IPV6_VIF_DATA_PATH); } else { (void)snprintf_s(vif_path, NETINFO_PATH_LEN, NETINFO_PATH_LEN, "%s_%u", IPV6_VIF_DATA_PATH, i); } if(xb_write_first_flag == 0) { (void)write_to_xenstore(handle, vif_path, ArrRetNet[i]); } else { (void)write_weak_to_xenstore(handle, vif_path, ArrRetNet[i]); } } }
/***************************************************************************** Function : do_healthcheck Description: do update heatch check Input : handle -- xenbus file handle Output : None Return : XEN_SUCC or XEN_ERROR *****************************************************************************/ int do_healthcheck(void * handle) { int iSpaceRet = 0; //disksize int iKernelRet = 0; //UpKernel flag int iCommandRet = 0; //command flag char resStr[MAX_PATH] = {0}; if (NULL == handle) { return XEN_FAIL; } /*检查磁盘空间是否剩余*/ iSpaceRet = CheckDiskspace(); /*检查内核是否升级*/ iKernelRet = CheckUpKernel(); /*检查系统命令是否存在*/ iCommandRet = CheckCommand(); (void)snprintf_s(resStr, MAX_PATH, MAX_PATH, "%d:%d:%d", iSpaceRet, iKernelRet, iCommandRet); if(xb_write_first_flag == 0) { /*如果返回成功,写入磁盘利用率信息*/ write_to_xenstore(handle, HEALTH_CHECK_RESULT_PATH, resStr); } else { write_weak_to_xenstore(handle, HEALTH_CHECK_RESULT_PATH, resStr); } return XEN_SUCC; }
/***************************************************************************** Function : NetinfoNetworkctlmon Description: ip4/6 main entry Input : None Output : None Return : *****************************************************************************/ void NetinfoNetworkctlmon(void *handle) { char NetworkLoss[32] = {0}; int i = 0; int num = 0; int count = 0; int BuffLen = 0; long sumrecievedrop = 0; long sumsentdrop = 0; num = GetIpv6Info(); memset_s(ArrRetNet,sizeof(ArrRetNet),0,sizeof(ArrRetNet)); /*init ArrRetNet*/ for(i=0;i<XENSTORE_COUNT;i++) { (void)snprintf_s(ArrRetNet[i],sizeof("0"),sizeof("0"),"%s","0"); } if (ERROR == num) { write_to_xenstore(handle, IPV6_VIF_DATA_PATH, "error"); DEBUG_LOG("Num is ERROR."); return; } if (0 == num) { Ipv6PrintInfo(handle); write_to_xenstore(handle, IPV6_VIF_DATA_PATH, "0"); return; } memset_s(>NicIpv6InfoResult, sizeof(gtNicIpv6InfoResult), 0, sizeof(gtNicIpv6InfoResult)); gtNicIpv6InfoResult.count = 0; /*IP Prioritization: if interface has ip, then put on the front of array*/ for(i=0;i<num;i++) { if(IPADDR_LEN < strlen(gtNicIpv6Info.info[i].ipaddr)) { (void)memcpy_s(>NicIpv6InfoResult.info[gtNicIpv6InfoResult.count], sizeof(IPV6_VIF_DATA), >NicIpv6Info.info[i], sizeof(IPV6_VIF_DATA)); gtNicIpv6InfoResult.count++; } if(gtNicIpv6InfoResult.count >IPV6_IPNUM ) break; } for(i=0;i<num;i++) { if(gtNicIpv6InfoResult.count >IPV6_IPNUM ) break; if(IPADDR_LEN >= strlen(gtNicIpv6Info.info[i].ipaddr)) { (void)memcpy_s(>NicIpv6InfoResult.info[gtNicIpv6InfoResult.count], sizeof(IPV6_VIF_DATA), >NicIpv6Info.info[i], sizeof(IPV6_VIF_DATA)); gtNicIpv6InfoResult.count++; } } /*assemble array*/ for(i=0;i<gtNicIpv6InfoResult.count;i++) { /*The total number of packet loss statistics*/ if(g_exinfo_flag_value & EXINFO_FLAG_NET_LOSS) { sumsentdrop += gtNicIpv6InfoResult.info[i].sentdrop; sumrecievedrop += gtNicIpv6InfoResult.info[i].recievedrop; } /*6 xenstore info*/ count = i/XENSTORE_COUNT; if(i%XENSTORE_COUNT == 0) BuffLen = 0; else BuffLen = strlen(ArrRetNet[count]); if(0!=strlen(gtNicIpv6InfoResult.info[i].ipaddr)) { (void)snprintf_s(ArrRetNet[count] + BuffLen, sizeof(ArrRetNet[count]) - BuffLen, sizeof(ArrRetNet[count]) - BuffLen, "[%s-%d-%s-%s-<%s>-<%s>]", gtNicIpv6InfoResult.info[i].mac, gtNicIpv6InfoResult.info[i].netstatusflag, gtNicIpv6InfoResult.info[i].ipaddr, trim(gtNicIpv6InfoResult.info[i].gateway), gtNicIpv6InfoResult.info[i].tp, gtNicIpv6InfoResult.info[i].packs); } else { (void)snprintf_s(ArrRetNet[count] + BuffLen, sizeof(ArrRetNet[count]) - BuffLen, sizeof(ArrRetNet[count]) - BuffLen, "[%s-%d]", gtNicIpv6InfoResult.info[i].mac, gtNicIpv6InfoResult.info[i].netstatusflag); } } Ipv6PrintInfo(handle); if(g_exinfo_flag_value & EXINFO_FLAG_NET_LOSS) { (void)snprintf_s(NetworkLoss, sizeof(NetworkLoss), sizeof(NetworkLoss), "%ld:%ld",sumrecievedrop, sumsentdrop); } if(xb_write_first_flag == 0) { if(g_exinfo_flag_value & EXINFO_FLAG_NET_LOSS) { write_to_xenstore(handle, VIF_DROP_PATH, NetworkLoss); } } else { if(g_exinfo_flag_value & EXINFO_FLAG_NET_LOSS) { write_weak_to_xenstore(handle, VIF_DROP_PATH, NetworkLoss); } } return ; }