/***************************************************************************** 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 : SetCpuHotplugFeature Description: write Cpu hotplug token Input : handle -- xenbus file handle Output : None Return : return OS support or not support cpu hotplug *****************************************************************************/ int SetCpuHotplugFeature(void * phandle) { int cpu_hotplug_status = XEN_FAIL; /* enter OS has been supported cpu hotplug */ cpu_hotplug_status = IsSupportCpuHotplug(); /* set CpuHotplug Feature flag */ (void)write_to_xenstore(phandle, CPU_HOTPLUG_FEATURE, \ cpu_hotplug_status == XEN_SUCC ? "1" : "0"); return cpu_hotplug_status; }
/***************************************************************************** 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 ; }
/***************************************************************************** Function : do_cpu_online Description: update cpu to online and wrtie state into xenstore Input : handle -- xenbus file handle Output : None Return : XEN_SUCC or XEN_ERROR *****************************************************************************/ int DoCpuHotplug(void * phandle) { char pszBuff[1024] = {0}; char pszCommand[1024] = {0}; int i = 0; int cpu_enable_num = 0; int cpu_nr = 0; char *cpu_online = NULL; int idelay = 0; int ret = -1; int rc = -1; cpu_nr = GetSupportMaxnumCpu(); if (cpu_nr <= 0) { INFO_LOG("This OS has unexpectable cpus: %d.", cpu_nr); goto out; } INFO_LOG("This OS has cpu hotplug and less than %d.", cpu_nr); /* obtain cpu numbers */ for(i = 0; i <= cpu_nr - 1; i++) { (void)snprintf_s(pszCommand, 1024, 1024, "cpu/%d/availability", i); cpu_online = read_from_xenstore(phandle, pszCommand); if((NULL != cpu_online) && (0 == strcmp(cpu_online, "online"))) { cpu_enable_num ++; } free(cpu_online); cpu_online = NULL; } i = 1; /* loop for upgrade cpu online */ while (i < cpu_enable_num ) { if (idelay >= 300) { i ++; idelay = 0; continue; } (void)memset_s(pszCommand, 1024, 0, 1024); (void)memset_s(pszBuff, 1024, 0, 1024); (void)snprintf_s(pszCommand, 1024, 1024, "if [ -d \"/sys/devices/system/cpu/cpu%d\" ]; then \n printf \"online\" \nfi", i); ret = uvpPopen(pszCommand, pszBuff, 1024); if (0 != ret) { ERR_LOG("Failed to call uvpPopen, ret=%d.", ret); idelay++; uvp_sleep(); continue; } if (0 != strcmp("online", pszBuff)) { idelay++; uvp_sleep(); continue; } /* 判断cpu当前是否online */ (void)memset_s(pszCommand, 1024, 0, 1024); (void)memset_s(pszBuff, 1024, 0, 1024); (void)snprintf_s(pszCommand, 1024, 1024, "cat /sys/devices/system/cpu/cpu%d/online", i); ret = uvpPopen(pszCommand, pszBuff, 1024); if (0 != ret) { ERR_LOG("Failed to call uvpPopen, ret=%d.", ret); idelay++; uvp_sleep(); continue; } if ('1' == pszBuff[0]) { INFO_LOG("Cpu%d is always online.", i); i++; idelay = 0; continue; } (void)memset_s(pszCommand, 1024, 0, 1024); (void)memset_s(pszBuff, 1024, 0, 1024); (void)snprintf_s(pszCommand, 1024, 1024, "echo 1 > /sys/devices/system/cpu/cpu%d/online", i); ret = uvpPopen(pszCommand, pszBuff, 1024); if (0 != ret) { ERR_LOG("Failed to call uvpPopen, ret=%d.", ret); idelay++; uvp_sleep(); continue; } idelay = 0; i++; } rc = XEN_SUCC; out: (void)write_to_xenstore(phandle, CPU_HOTPLUG_STATE, "0"); (void)write_to_xenstore(phandle, CPU_HOTPLUG_SIGNAL, "0"); return rc; }