Ejemplo n.º 1
0
/**
 * exec_command
 * send a command to a service processor
 * Commands are executed sequentially. One command (sp->current_command)
 * is sent to the service processor. Once the interrupt handler gets a
 * message of type command_response, the message is copied into
 * the current commands buffer, 
 */
void ibmasm_exec_command(struct service_processor *sp, struct command *cmd)
{
	unsigned long flags;
	char tsbuf[32];

	dbg("%s:%d at %s\n", __FUNCTION__, __LINE__, get_timestamp(tsbuf));

	spin_lock_irqsave(&sp->lock, flags);

	if (!sp->current_command) {
		sp->current_command = cmd;
		command_get(sp->current_command);
		spin_unlock_irqrestore(&sp->lock, flags);
		do_exec_command(sp);
	} else {
		enqueue_command(sp, cmd);
		spin_unlock_irqrestore(&sp->lock, flags);
	}
}
Ejemplo n.º 2
0
/* enable one or more DTrace probes for a given JVM */
int jvm_enable_dtprobes(jvm_t* jvm, int num_probe_types, const char** probe_types) {
    int fd, status = 0;
    char ch;
    const char* args[1];
    char buf[16];
    int probe_type = 0, index;
    int count = 0;

    if (jvm == NULL) {
        set_jvm_error(JVM_ERR_NULL_PARAM);
        print_debug("jvm_t* is NULL\n");
        return -1;
    }

    if (num_probe_types == 0 || probe_types == NULL ||
        probe_types[0] == NULL) {
        set_jvm_error(JVM_ERR_INVALID_PARAM);
        print_debug("invalid probe type argument(s)\n");
        return -1;
    }

    for (index = 0; index < num_probe_types; index++) {
        const char* p = probe_types[index];
        if (strcmp(p, JVM_DTPROBE_OBJECT_ALLOC) == 0) {
            probe_type |= DTRACE_ALLOC_PROBES;
            count++;
        } else if (strcmp(p, JVM_DTPROBE_METHOD_ENTRY) == 0 ||
                   strcmp(p, JVM_DTPROBE_METHOD_RETURN) == 0) {
            probe_type |= DTRACE_METHOD_PROBES;
            count++;
        } else if (strcmp(p, JVM_DTPROBE_MONITOR_ENTER) == 0   ||
                   strcmp(p, JVM_DTPROBE_MONITOR_ENTERED) == 0 ||
                   strcmp(p, JVM_DTPROBE_MONITOR_EXIT) == 0    ||
                   strcmp(p, JVM_DTPROBE_MONITOR_WAIT) == 0    ||
                   strcmp(p, JVM_DTPROBE_MONITOR_WAITED) == 0  ||
                   strcmp(p, JVM_DTPROBE_MONITOR_NOTIFY) == 0  ||
                   strcmp(p, JVM_DTPROBE_MONITOR_NOTIFYALL) == 0) {
            probe_type |= DTRACE_MONITOR_PROBES;
            count++;
        } else if (strcmp(p, JVM_DTPROBE_ALL) == 0) {
            probe_type |= DTRACE_ALL_PROBES;
            count++;
        }
    }

    if (count == 0) {
        return count;
    }
    sprintf(buf, "%d", probe_type);
    args[0] = buf;

    fd = enqueue_command(jvm, ENABLE_DPROBES_CMD, 1, args);
    if (fd < 0) {
        set_jvm_error(JVM_ERR_DOOR_CMD_SEND);
        return -1;
    }

    status = read_status(fd);
    // non-zero status is error
    if (status) {
        set_jvm_error(JVM_ERR_DOOR_CMD_STATUS);
        print_debug("%s command failed (status: %d) in target JVM\n",
                    ENABLE_DPROBES_CMD, status);
        file_close(fd);
        return -1;
    }
    // read from stream until EOF
    while (file_read(fd, &ch, sizeof(ch)) == sizeof(ch)) {
        if (libjvm_dtrace_debug) {
            printf("%c", ch);
        }
    }

    file_close(fd);
    clear_jvm_error();
    return count;
}
int
handle_gahp_command(char ** argv, int argc) {
	// Assume it's been verified

	if (strcasecmp (argv[0], GAHP_COMMAND_JOB_REMOVE)==0) {
		int req_id = 0;
		int cluster_id, proc_id;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_job_id (argv[3], &cluster_id, &proc_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createRemoveRequest(
				req_id,
				cluster_id,
				proc_id,
				argv[4]));
		return TRUE;
	} else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_HOLD)==0) {
		int req_id = 0;
		int cluster_id, proc_id;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_job_id (argv[3], &cluster_id, &proc_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createHoldRequest(
				req_id,
				cluster_id,
				proc_id,
				argv[4]));
		return TRUE;

	} else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_RELEASE)==0) {

		int req_id = 0;
		int cluster_id, proc_id;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_job_id (argv[3], &cluster_id, &proc_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createReleaseRequest(
				req_id,
				cluster_id,
				proc_id,
				argv[4]));
		return TRUE;

	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_STATUS_CONSTRAINED) ==0) {

		int req_id;

		if (!(argc == 4 &&
			get_int (argv[1], &req_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		char * constraint = argv[3];


		enqueue_command (
			SchedDRequest::createStatusConstrainedRequest(
				req_id,
				constraint));

		return TRUE;
	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_UPDATE_CONSTRAINED) ==0) {
		int req_id;
		ClassAd * classad;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_class_ad (argv[4], &classad))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		char * constraint = argv[3];

		enqueue_command (
			SchedDRequest::createUpdateConstrainedRequest(
				req_id,
				constraint,
				classad));

		delete classad;
		return TRUE;

	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_UPDATE) ==0) {

		int req_id;
		ClassAd * classad;
		int cluster_id, proc_id;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_job_id (argv[3], &cluster_id, &proc_id) &&
			get_class_ad (argv[4], &classad))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		//char * constraint = argv[3];

		enqueue_command (
			SchedDRequest::createUpdateRequest(
				req_id,
				cluster_id,
				proc_id,
				classad));

		delete classad;
		return TRUE;
	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_SUBMIT) ==0) {
		int req_id;
		ClassAd * classad;

		if (!(argc == 4 &&
			get_int (argv[1], &req_id) &&
			get_class_ad (argv[3], &classad))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createSubmitRequest(
				req_id,
				classad));

		delete classad;
		return TRUE;
	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_UPDATE_LEASE) ==0) {
		int req_id;
		int num_jobs;

		if (!(argc >= 4 &&
			get_int (argv[1], &req_id) &&
			get_int (argv[3], &num_jobs))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		job_expiration * expirations = new job_expiration[num_jobs];
		int i;
		for (i=0; i<num_jobs; i++) {
			if (!get_job_id(argv[4+i*2], 
							&(expirations[i].cluster),
							&(expirations[i].proc))) {
				delete[] expirations;
				return FALSE;
			}

			if (!get_ulong (argv[4+i*2+1], &(expirations[i].expiration))) {
				delete [] expirations;
				return FALSE;
			}
		}	

		enqueue_command (
			SchedDRequest::createUpdateLeaseRequest(
													req_id,
													num_jobs,
													expirations));

		delete [] expirations;
		return TRUE;
	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_STAGE_IN) ==0) {
		int req_id;
		ClassAd * classad;

		if (!(argc == 4 &&
			get_int (argv[1], &req_id) &&
			get_class_ad (argv[3], &classad))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createJobStageInRequest(
				req_id,
				classad));

		delete classad;
		return TRUE;
	} else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_STAGE_OUT) ==0) {
		int req_id;
		int cluster_id, proc_id;

		if (!(argc == 4 &&
			  get_int (argv[1], &req_id) &&
			  get_job_id (argv[3], &cluster_id, &proc_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createJobStageOutRequest(
				req_id,
				cluster_id,
				proc_id));

		return TRUE;
	} else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_REFRESH_PROXY)==0) {
		int req_id = 0;
		int cluster_id, proc_id;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_job_id (argv[3], &cluster_id, &proc_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createRefreshProxyRequest(
				req_id,
				cluster_id,
				proc_id,
				argv[4]));
		return TRUE;
	} else if (strcasecmp (argv[0], GAHP_COMMAND_INITIALIZE_FROM_FILE)==0) {
		static bool init_done = false;

		if ( init_done == false ) {
			SetEnv( "X509_USER_PROXY", argv[1] );
			UnsetEnv( "X509_USER_CERT" );
			UnsetEnv( "X509_USER_KEY" );
			proxySubjectName = x509_proxy_identity_name( argv[1] );
			if ( !proxySubjectName ) {
				dprintf( D_ALWAYS, "Failed to query certificate identity "
						 "from %s\n",  argv[1] );
				return TRUE;
			}
			Reconfig();
			init_done = true;
		}
		return TRUE;
	}

	dprintf (D_ALWAYS, "Invalid command %s\n", argv[0]);
	return FALSE;
}
Ejemplo n.º 4
0
//
// Top level order handler
//
void process_command()
{
  if (is_stopped && !stopped_is_acknowledged && order_code != ORDER_RESUME)
  {
    send_stopped_response();
    return;
  }

  // we allow a sequence of write configuration commands
  // to be set as configured as a group. For instance,
  // writing the following sequence:
  // device.stepper.0.enable_pin=48
  // device.stepper.0.enable_invert=1
  // ...
  // will only result in the stepper configuration being applied when all
  // attributes have been applied.
  if (firmware_configuration_change_made || !final_firmware_configuration_update_done)
  {
    if (!final_firmware_configuration_update_done
        && (order_code == ORDER_SET_HEATER_TARGET_TEMP
            || order_code == ORDER_SET_OUTPUT_SWITCH_STATE
            || order_code == ORDER_SET_PWM_OUTPUT_STATE
            || order_code == ORDER_SET_OUTPUT_TONE
            || order_code == ORDER_ACTIVATE_STEPPER_CONTROL
            || order_code == ORDER_ENABLE_DISABLE_STEPPERS
            || order_code == ORDER_QUEUE_COMMAND_BLOCKS))
    {
      // assume that once devices are activated then initial firmware
      // configuration is complete and EEPROM state should be updated
      firmware_configuration_change_made = false;
      final_firmware_configuration_update_done = true;
      update_firmware_configuration(true);
    }
    else if (firmware_configuration_change_made
        && order_code != ORDER_WRITE_FIRMWARE_CONFIG_VALUE)
    {
      // update individual device states once firmware configuration
      // block is done
      firmware_configuration_change_made = false;
      update_firmware_configuration(false);
    }
  }

  switch (order_code)
  {
  case ORDER_RESET:
    emergency_stop(PARAM_STOPPED_CAUSE_USER_REQUEST);
    die();
    break;
  case ORDER_RESUME:
    handle_resume_order();
    break;
  case ORDER_REQUEST_INFORMATION:
    handle_request_information_order();
    break;
  case ORDER_DEVICE_COUNT:
    handle_device_count_order();
    break;
  case ORDER_DEVICE_NAME:
    handle_device_name_order();
    break;
  case ORDER_DEVICE_STATUS:
    handle_device_status_order();
    break;
  case ORDER_REQUEST_TEMPERATURE_READING:
    handle_request_temperature_reading_order();
    break;
  case ORDER_GET_HEATER_CONFIGURATION:
    handle_get_heater_configuration_order();
    break;
  case ORDER_CONFIGURE_HEATER:
    handle_configure_heater_order();
    break;
  case ORDER_SET_HEATER_TARGET_TEMP:
    handle_set_heater_target_temperature_order();
    break;
  case ORDER_GET_INPUT_SWITCH_STATE:
    handle_get_input_switch_state_order();
    break;
  case ORDER_SET_OUTPUT_SWITCH_STATE:
    handle_set_output_switch_state_order();
    break;
  case ORDER_SET_PWM_OUTPUT_STATE:
    handle_set_pwm_output_state_order();
    break;
  case ORDER_SET_OUTPUT_TONE:
    handle_set_output_tone_order();
    break;
  case ORDER_WRITE_FIRMWARE_CONFIG_VALUE:
    firmware_configuration_change_made = true;
    handle_write_firmware_configuration_value_order();
    break;
  case ORDER_READ_FIRMWARE_CONFIG_VALUE:
    // note: get_command() already makes the end of the command (ie. name) null-terminated
    handle_firmware_configuration_request((const char *)&parameter_value[0], 0);
    break;
  case ORDER_TRAVERSE_FIRMWARE_CONFIG:
    // note: get_command() already makes the end of the command (ie. name) null-terminated
    handle_firmware_configuration_traversal((const char *)&parameter_value[0]);
    break;
  case ORDER_GET_FIRMWARE_CONFIG_PROPERTIES:
    // note: get_command() already makes the end of the command (ie. name) null-terminated
    handle_firmware_configuration_value_properties((const char *)&parameter_value[0]);
    break;
  case ORDER_EMERGENCY_STOP:
    emergency_stop(PARAM_STOPPED_CAUSE_USER_REQUEST);
    send_OK_response();
    break;
  case ORDER_ACTIVATE_STEPPER_CONTROL:
    handle_activate_stepper_control_order();
    break;
  case ORDER_CONFIGURE_ENDSTOPS:
    handle_configure_endstops_order();
    break;
  case ORDER_ENABLE_DISABLE_STEPPERS:
    handle_enable_disable_steppers_order();
    break;
  case ORDER_ENABLE_DISABLE_ENDSTOPS:
    handle_enable_disable_endstops_order();
    break;
  case ORDER_QUEUE_COMMAND_BLOCKS:
    enqueue_command();
    break;
  case ORDER_CLEAR_COMMAND_QUEUE:
    handle_clear_command_queue_order();
    break;
  case ORDER_CONFIGURE_AXIS_MOVEMENT_RATES:
    handle_configure_axis_movement_rates_order();
    break;
  case ORDER_CONFIGURE_UNDERRUN_PARAMS:
    handle_configure_underrun_params_order();
    break;
  default:
    send_app_error_response(PARAM_APP_ERROR_TYPE_UNKNOWN_ORDER, 0);
    break;
  }

}