int urj_param_push (const urj_param_list_t *params, const urj_param_t ***bp, const char *p) { int key; urj_param_t *new_p; int r = URJ_STATUS_OK; const char *eq; urj_param_type_t type; key = urj_param_parse_key(params, p); if (key == -1) return URJ_STATUS_FAIL; type = urj_param_type_of(params, key); if (type == -1) return URJ_STATUS_FAIL; eq = strchr(p, '='); if (type != URJ_PARAM_TYPE_BOOL && eq == NULL) { urj_error_set (URJ_ERROR_SYNTAX, "param should be of the form 'key=value', not '%s'", p); return URJ_STATUS_FAIL; } new_p = urj_param_increase (bp); if (new_p == NULL) return URJ_STATUS_FAIL; new_p->type = type; new_p->key = key; switch (new_p->type) { case URJ_PARAM_TYPE_LU: r = parse_param_lu(eq, &new_p->value.lu); break; case URJ_PARAM_TYPE_STRING: new_p->value.string = parse_param_string(eq); if (new_p->value.string == NULL) r = URJ_STATUS_FAIL; break; case URJ_PARAM_TYPE_BOOL: r = parse_param_bool(eq, &new_p->value.enabled); break; } if (r == URJ_STATUS_FAIL) urj_param_decrease (bp); return r; }
bool VMProc::process_vm_status_result(Gahp_Args *result_args) { // status result // argv[1] : should be 0, it means success. // From argv[2] : representing some info about VM if( !result_args || ( result_args->argc < 3) ) { dprintf(D_ALWAYS, "Bad Result for VM status\n"); vm_status_error(); return true; } int tmp_argv = (int)strtol(result_args->argv[1], (char **)NULL, 10); if( tmp_argv != 0 || !strcasecmp(result_args->argv[2], NULLSTRING)) { dprintf(D_ALWAYS, "Received VM status, result(%s,%s)\n", result_args->argv[1], result_args->argv[2]); vm_status_error(); return true; } // We got valid info about VM MyString vm_status; float cpu_time = 0; int vm_pid = 0; MyString vm_ip; MyString vm_mac; MyString tmp_name; MyString tmp_value; MyString one_arg; int i = 2; m_vm_utilization = 0.0; for( ; i < result_args->argc; i++ ) { one_arg = result_args->argv[i]; one_arg.trim(); if(one_arg.IsEmpty()) { continue; } parse_param_string(one_arg.Value(), tmp_name, tmp_value, true); if( tmp_name.IsEmpty() || tmp_value.IsEmpty() ) { continue; } if(!strcasecmp(tmp_name.Value(), VMGAHP_STATUS_COMMAND_STATUS)) { vm_status = tmp_value; }else if( !strcasecmp(tmp_name.Value(), VMGAHP_STATUS_COMMAND_CPUTIME) ) { cpu_time = (float)strtod(tmp_value.Value(), (char **)NULL); if( cpu_time <= 0 ) { cpu_time = 0; } }else if( !strcasecmp(tmp_name.Value(), VMGAHP_STATUS_COMMAND_PID) ) { vm_pid = (int)strtol(tmp_value.Value(), (char **)NULL, 10); if( vm_pid <= 0 ) { vm_pid = 0; } }else if( !strcasecmp(tmp_name.Value(), VMGAHP_STATUS_COMMAND_MAC) ) { vm_mac = tmp_value; }else if( !strcasecmp(tmp_name.Value(), VMGAHP_STATUS_COMMAND_IP) ) { vm_ip = tmp_value; }else if ( !strcasecmp(tmp_name.Value(),VMGAHP_STATUS_COMMAND_CPUUTILIZATION) ) { /* This is here for vm's which are spun via libvirt*/ m_vm_utilization = (float)strtod(tmp_value.Value(), (char **)NULL); } } if( vm_status.IsEmpty() ) { // We don't receive status of VM dprintf(D_ALWAYS, "No VM status in result\n"); vm_status_error(); return true; } if( vm_mac.IsEmpty() == false ) { setVMMAC(vm_mac.Value()); } if( vm_ip.IsEmpty() == false ) { setVMIP(vm_ip.Value()); } int old_status_error_count = m_status_error_count; // Reset status error count to 0 m_status_error_count = 0; if( !strcasecmp(vm_status.Value(),"Stopped") ) { dprintf(D_ALWAYS, "Virtual machine is stopped\n"); is_suspended = false; m_is_soft_suspended = false; is_checkpointed = false; // VM finished. setVMPID(0); // destroy the vmgahp server cleanup(); return false; }else { dprintf(D_FULLDEBUG, "Virtual machine status is %s, utilization is %f\n", vm_status.Value(), m_vm_utilization ); if( !strcasecmp(vm_status.Value(), "Running") ) { is_suspended = false; m_is_soft_suspended = false; is_checkpointed = false; if( cpu_time > 0 ) { // update statistics for Xen m_vm_cputime = cpu_time; } if( vm_pid > 0 ) { setVMPID(vm_pid); } // Update usage of process for a VM updateUsageOfVM(); }else if( !strcasecmp(vm_status.Value(), "Suspended") ) { if( !is_checkpointed ) { is_suspended = true; } m_is_soft_suspended = false; // VM is suspended setVMPID(0); }else if( !strcasecmp(vm_status.Value(), "SoftSuspended") ) { is_suspended = true; m_is_soft_suspended = true; is_checkpointed = false; }else { dprintf(D_ALWAYS, "Unknown VM status: %s\n", vm_status.Value()); // Restore status error count m_status_error_count = old_status_error_count; vm_status_error(); } } return true; }