environment decl_attributes::apply(environment env, io_state const & ios, name const & d) const { if (m_is_instance) { if (m_priority) { #if defined(__GNUC__) && !defined(__CLANG__) #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif env = add_instance(env, d, *m_priority, m_persistent); } else { env = add_instance(env, d, m_persistent); } } if (m_is_trans_instance) { if (m_priority) { #if defined(__GNUC__) && !defined(__CLANG__) #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif env = add_trans_instance(env, d, *m_priority, m_persistent); } else { env = add_trans_instance(env, d, m_persistent); } } if (m_is_coercion) env = add_coercion(env, ios, d, m_persistent); auto decl = env.find(d); if (decl && decl->is_definition()) { if (m_is_reducible) env = set_reducible(env, d, reducible_status::Reducible, m_persistent); if (m_is_irreducible) env = set_reducible(env, d, reducible_status::Irreducible, m_persistent); if (m_is_semireducible) env = set_reducible(env, d, reducible_status::Semireducible, m_persistent); if (m_is_quasireducible) env = set_reducible(env, d, reducible_status::Quasireducible, m_persistent); if (m_unfold_hint) env = add_unfold_hint(env, d, m_unfold_hint, m_persistent); if (m_unfold_full_hint) env = add_unfold_full_hint(env, d, m_persistent); } if (m_constructor_hint) env = add_constructor_hint(env, d, m_persistent); if (m_symm) env = add_symm(env, d, m_persistent); if (m_refl) env = add_refl(env, d, m_persistent); if (m_trans) env = add_trans(env, d, m_persistent); if (m_subst) env = add_subst(env, d, m_persistent); if (m_recursor) env = add_user_recursor(env, d, m_recursor_major_pos, m_persistent); if (m_is_class) env = add_class(env, d, m_persistent); if (m_rewrite) env = add_rewrite_rule(env, d, m_persistent); if (m_has_multiple_instances) env = mark_multiple_instances(env, d, m_persistent); return env; }
void GameInstSet::deserialize(GameState* gs, SerializeBuffer& serializer) { serializer.read_int(grid_w); serializer.read_int(grid_h); //Resize and clear unit_grid.resize(grid_w * grid_h); clear(); int amnt; serializer.read_int(amnt); serializer.read_int(next_id); for (int i = 0; i < amnt; i++) { InstType type; int id; serializer.read_int(type); serializer.read_int(id); printf("Deserializing id=%d\n", id); GameInst* inst = get_instance(id); bool has_inst = inst != NULL; if (!has_inst) { inst = from_inst_type(type); inst->deserialize(gs, serializer); inst->last_x = inst->x; inst->last_y = inst->y; inst->id = id; add_instance(inst, inst->id); } else { safe_deserialize(inst, gs, serializer); } LANARTS_ASSERT( serializer_equals_read(serializer, inst->integrity_hash())); } }
int CLAMAPI Scan_CreateInstance(CClamAVScanner **ppScanner) { instance *inst; INFN(); if(!ppScanner) FAIL(CL_ENULLARG, "NULL pScanner"); inst = (instance *)calloc(1, sizeof(*inst)); if(!inst) FAIL(CL_EMEM, "CreateInstance: OOM"); if(lock_engine()) { free(inst); FAIL(CL_ELOCK, "Failed to lock engine"); } if(!engine) { free(inst); unlock_engine(); FAIL(CL_ESTATE, "Create instance called with no engine"); } if(add_instance(inst)) { free(inst); unlock_engine(); FAIL(CL_EMEM, "add_instance failed"); } unlock_engine(); inst->scanopts = CL_SCAN_STDOPT; if (logg_verbose) inst->scanopts |= CL_SCAN_PERFORMANCE_INFO; *ppScanner = (CClamAVScanner *)inst; logg("Created new instance %p\n", inst); WIN(); }
//! //! Callback used when checking for the integrity of the work blobstore. //! //! @param[in] bb pointer to the blockblob to examine //! //! @return EUCA_OK on success or EUCA_ERROR on failure //! //! @see check_backing_store() //! @see blobstore_fsck() //! //! @pre The bb field must not be NULL. //! static int stale_blob_examiner(const blockblob * bb) { char *s = NULL; char *user_id = NULL; char *inst_id = NULL; char *file = NULL; char path[EUCA_MAX_PATH] = ""; char work_path[EUCA_MAX_PATH] = ""; int work_path_len = 0; ncInstance *instance = NULL; set_path(work_path, sizeof(work_path), NULL, NULL); work_path_len = strlen(work_path); assert(work_path_len > 0); s = strstr(bb->blocks_path, work_path); if ((s == NULL) || (s != bb->blocks_path)) { // blob not under work blobstore path return (EUCA_OK); } // parse the path past the work directory base euca_strncpy(work_path, bb->blocks_path, sizeof(work_path)); s = work_path + work_path_len + 1; user_id = strtok(s, "/"); inst_id = strtok(NULL, "/"); file = strtok(NULL, "/"); if (((instance = find_instance(instances, inst_id)) == NULL) // not found among instances => stale || instance->state == TEARDOWN) { // found among instances, but is already marked as terminated // if this instance is not among those we know about, // load it into memory and report it in Teardown state //! @TODO technically, disk state for this instance is not gone, //! but it soon will be, once this examiner function returns error if ((instance == NULL) && ((instance = load_instance_struct(inst_id)) != NULL)) { LOGINFO("marking non-running instance %s as terminated\n", inst_id); instance->terminationTime = time(NULL); // set time to now, so record won't get expired immediately change_state(instance, TEARDOWN); int err = add_instance(instances, instance); // we are not using locks because we assume the caller does if (err) { free_instance(&instance); } } // while we're here, try to delete extra files that aren't managed by the blobstore snprintf(path, sizeof(path), "%s/work/%s/%s", instances_path, user_id, inst_id); blobstore_delete_nonblobs(bb->store, path); return (EUCA_ERROR); } return (EUCA_OK); }
parse_state_t parse_data (token_t token, char *name, arff_info_t * info) { nom_val_t *x; parse_state_t r = PARSE_STATE_DATA2; if (curr_instance == NULL) { curr_instance = add_instance (info); curr_data = 0; curr_attr = first_attr; } if (curr_attr == NULL) { sprintf (error_string, "too many data values given"); r = PARSE_STATE_ERROR; } else { switch (curr_attr->type) { case ATTR_NUMERIC: curr_instance->data[curr_data++].fval = atof (name); DEBUGMSG ((" add numeric data, val = %f\n", atof (name))); break; case ATTR_NOMINAL: for (x = curr_attr->nom_info->first; x != NULL; x = x->next) { if (!strcmp (name, x->name)) { curr_instance->data[curr_data++]. ival = x->val; DEBUGMSG ((" add nominal data, val = %s, index = %i\n", x->name, x->val)); break; } } if (x == NULL) { sprintf (error_string, "unknown nominal class value: %s", name); r = PARSE_STATE_ERROR; } break; default: break; } curr_attr = curr_attr->next; } return r; }
int RmTest::init() { // set room properties /*set_width(3000); set_height(500); set_view(0, &vw_main); set_is_views_enabled(true);*/ // set backgrounds add_background(-1, bk_green, true, false, 0, 0, true, true, 10, 10, false); // set up instances add_instance(-1, obj_bee, 0, 0); return 0; }
int BEE::Room::load_instance_map(std::string fname) { if (game->get_is_ready()) { instance_map = fname; game->restart_room(); return 0; } std::vector<std::tuple<Object*,int,int>> data; std::string datastr = file_get_contents(fname); if (!datastr.empty()) { std::istringstream data_stream (datastr); while (!data_stream.eof()) { std::string tmp; getline(data_stream, tmp); if (tmp.empty()) { continue; } std::string v; std::stringstream vs (tmp); getline(vs, v, ','); v = trim(v); std::string d = tmp.substr(tmp.find(",")+1); d = trim(d); int x = std::stoi(d.substr(0, d.find(","))); int y = std::stoi(d.substr(d.find(",")+1)); data.push_back(std::make_tuple(game->get_object_by_name(v), x, y)); } for (auto& i : data) { add_instance(-1, std::get<0>(i), std::get<1>(i), std::get<2>(i)); } } else { std::cerr << "No instances loaded.\n"; return 1; } return 0; }
static int __init jool_init(void) { int error; log_debug("Inserting %s...", xlat_get_name()); /* Init Jool's submodules. */ error = xlator_init(); if (error) goto xlator_fail; error = logtime_init(); if (error) goto log_time_fail; error = nlhandler_init(); if (error) goto nlhandler_fail; /* This needs to be last! (except for the hook registering.) */ error = add_instance(); if (error) goto instance_fail; /* Hook Jool to Netfilter. */ error = nf_register_hooks(nfho, ARRAY_SIZE(nfho)); if (error) goto nf_register_hooks_fail; /* Yay */ log_info("%s v" JOOL_VERSION_STR " module inserted.", xlat_get_name()); return 0; nf_register_hooks_fail: xlator_rm(); instance_fail: nlhandler_destroy(); nlhandler_fail: logtime_destroy(); log_time_fail: xlator_destroy(); xlator_fail: return error; }
void trace_stat (int argc, char **argv) { struct buffer_instance *instance = &top_instance; int topt = 0; int c; for (;;) { c = getopt(argc-1, argv+1, "tB:"); if (c == -1) break; switch (c) { case 'h': usage(argv); break; case 'B': instance = create_instance(optarg); add_instance(instance); /* top instance requires direct access */ if (!topt && is_top_instance(first_instance)) first_instance = instance; break; case 't': /* Force to use top instance */ topt = 1; instance = &top_instance; break; default: usage(argv); } } update_first_instance(instance, topt); for_all_instances(instance) { stat_instance(instance); } exit(0); }
int BEE::Room::add_instance_grid(int index, Object* object, double x, double y) { double xg = x, yg = y; if (object->get_sprite() != NULL) { if (!object->get_sprite()->get_is_loaded()) { std::cerr << "Automatically loading the sprite for object " << object->get_name() << "\n"; object->get_sprite()->load(); } xg = 0.0; yg = 0.0; if (x >= 0) { xg = x*object->get_sprite()->get_subimage_width(); } else { xg = width + x*object->get_sprite()->get_subimage_width(); } if (y >= 0) { yg = y*object->get_sprite()->get_height(); } else { yg = height + y*object->get_sprite()->get_height(); } } return add_instance(index, object, (int)xg, (int)yg); }
//! //! Handles the instance migration request. //! //! @param[in] nc a pointer to the node controller (NC) state //! @param[in] pMeta a pointer to the node controller (NC) metadata structure //! @param[in] instances metadata for the instance to migrate to destination //! @param[in] instancesLen number of instances in the instance list //! @param[in] action IP of the destination Node Controller //! @param[in] credentials credentials that enable the migration //! //! @return EUCA_OK on success or EUCA_*ERROR on failure //! //! @pre //! //! @post static int doMigrateInstances(struct nc_state_t *nc, ncMetadata * pMeta, ncInstance ** instances, int instancesLen, char *action, char *credentials) { int ret = EUCA_OK; int credentials_prepared = 0; if (instancesLen <= 0) { LOGERROR("called with invalid instancesLen (%d)\n", instancesLen); pMeta->replyString = strdup("internal error (invalid instancesLen)"); return (EUCA_INVALID_ERROR); } LOGDEBUG("verifying %d instance[s] for migration...\n", instancesLen); for (int inst_idx = 0; inst_idx < instancesLen; inst_idx++) { LOGDEBUG("verifying instance # %d...\n", inst_idx); if (instances[inst_idx]) { ncInstance *instance_idx = instances[inst_idx]; LOGDEBUG("[%s] proposed migration action '%s' (%s > %s) [creds=%s]\n", SP(instance_idx->instanceId), SP(action), SP(instance_idx->migration_src), SP(instance_idx->migration_dst), (instance_idx->migration_credentials == NULL) ? "UNSET" : "present"); } else { pMeta->replyString = strdup("internal error (instance count mismatch)"); LOGERROR("Mismatch between migration instance count (%d) and length of instance list\n", instancesLen); return (EUCA_ERROR); } } // TO-DO: Optimize the location of this loop, placing it inside various conditionals below? for (int inst_idx = 0; inst_idx < instancesLen; inst_idx++) { ncInstance *instance_req = instances[inst_idx]; char *sourceNodeName = instance_req->migration_src; char *destNodeName = instance_req->migration_dst; LOGDEBUG("[%s] processing instance # %d (%s > %s)\n", instance_req->instanceId, inst_idx, instance_req->migration_src, instance_req->migration_dst); // this is a call to the source of migration if (!strcmp(pMeta->nodeName, sourceNodeName)) { // locate the instance structure ncInstance *instance; sem_p(inst_sem); { instance = find_instance(&global_instances, instance_req->instanceId); } sem_v(inst_sem); if (instance == NULL) { LOGERROR("[%s] cannot find instance\n", instance_req->instanceId); pMeta->replyString = strdup("failed to locate instance to migrate"); return (EUCA_NOT_FOUND_ERROR); } if (strcmp(action, "prepare") == 0) { sem_p(inst_sem); instance->migration_state = MIGRATION_PREPARING; euca_strncpy(instance->migration_src, sourceNodeName, HOSTNAME_SIZE); euca_strncpy(instance->migration_dst, destNodeName, HOSTNAME_SIZE); euca_strncpy(instance->migration_credentials, credentials, CREDENTIAL_SIZE); instance->migrationTime = time(NULL); save_instance_struct(instance); copy_instances(); sem_v(inst_sem); // Establish migration-credential keys if this is the first instance preparation for this host. LOGINFO("[%s] migration source preparing %s > %s [creds=%s]\n", SP(instance->instanceId), SP(instance->migration_src), SP(instance->migration_dst), (instance->migration_credentials == NULL) ? "UNSET" : "present"); if (!credentials_prepared) { if (generate_migration_keys(sourceNodeName, credentials, TRUE, instance) != EUCA_OK) { pMeta->replyString = strdup("internal error (migration credentials generation failed)"); return (EUCA_SYSTEM_ERROR); } else { credentials_prepared++; } } sem_p(inst_sem); instance->migration_state = MIGRATION_READY; save_instance_struct(instance); copy_instances(); sem_v(inst_sem); } else if (strcmp(action, "commit") == 0) { sem_p(inst_sem); if (instance->migration_state == MIGRATION_IN_PROGRESS) { LOGWARN("[%s] duplicate request to migration source to initiate %s > %s (already migrating)\n", instance->instanceId, instance->migration_src, instance->migration_dst); sem_v(inst_sem); return (EUCA_DUPLICATE_ERROR); } else if (instance->migration_state != MIGRATION_READY) { LOGERROR("[%s] request to commit migration %s > %s when source migration_state='%s' (not 'ready')\n", instance->instanceId, SP(sourceNodeName), SP(destNodeName), migration_state_names[instance->migration_state]); sem_v(inst_sem); return (EUCA_UNSUPPORTED_ERROR); } instance->migration_state = MIGRATION_IN_PROGRESS; outgoing_migrations_in_progress++; LOGINFO("[%s] migration source initiating %s > %s [creds=%s] (1 of %d active outgoing migrations)\n", instance->instanceId, instance->migration_src, instance->migration_dst, (instance->migration_credentials == NULL) ? "UNSET" : "present", outgoing_migrations_in_progress); save_instance_struct(instance); copy_instances(); sem_v(inst_sem); // since migration may take a while, we do them in a thread pthread_t tcb = { 0 }; if (pthread_create(&tcb, NULL, migrating_thread, (void *)instance)) { LOGERROR("[%s] failed to spawn a migration thread\n", instance->instanceId); return (EUCA_THREAD_ERROR); } set_corrid_pthread( get_corrid()!=NULL ? get_corrid()->correlation_id : NULL , tcb); if (pthread_detach(tcb)) { LOGERROR("[%s] failed to detach the migration thread\n", instance->instanceId); return (EUCA_THREAD_ERROR); } } else if (strcmp(action, "rollback") == 0) { if ((instance->migration_state == MIGRATION_READY) || (instance->migration_state == MIGRATION_PREPARING)) { LOGINFO("[%s] rolling back migration (%s > %s) on source\n", instance->instanceId, instance->migration_src, instance->migration_dst); sem_p(inst_sem); migration_rollback(instance); sem_v(inst_sem); } else { LOGINFO("[%s] ignoring request to roll back migration on source with instance in state %s(%s) -- duplicate rollback request?\n", instance->instanceId, instance->stateName, migration_state_names[instance->migration_state]); } } else { LOGERROR("[%s] action '%s' is not valid\n", instance->instanceId, action); return (EUCA_INVALID_ERROR); } } else if (!strcmp(pMeta->nodeName, destNodeName)) { // this is a migrate request to destination if (!strcmp(action, "commit")) { LOGERROR("[%s] action '%s' for migration (%s > %s) is not valid on destination node\n", instance_req->instanceId, action, SP(sourceNodeName), SP(destNodeName)); return (EUCA_UNSUPPORTED_ERROR); } else if (!strcmp(action, "rollback")) { LOGINFO("[%s] rolling back migration (%s > %s) on destination\n", instance_req->instanceId, SP(sourceNodeName), SP(destNodeName)); sem_p(inst_sem); { ncInstance *instance = find_instance(&global_instances, instance_req->instanceId); if (instance != NULL) { LOGDEBUG("[%s] marked for cleanup\n", instance->instanceId); change_state(instance, SHUTOFF); instance->migration_state = MIGRATION_CLEANING; save_instance_struct(instance); } } sem_v(inst_sem); return EUCA_OK; } else if (strcmp(action, "prepare") != 0) { LOGERROR("[%s] action '%s' is not valid or not implemented\n", instance_req->instanceId, action); return (EUCA_INVALID_ERROR); } // Everything from here on is specific to "prepare" on a destination. // allocate a new instance struct ncInstance *instance = clone_instance(instance_req); if (instance == NULL) { LOGERROR("[%s] could not allocate instance struct\n", instance_req->instanceId); goto failed_dest; } sem_p(inst_sem); instance->migration_state = MIGRATION_PREPARING; euca_strncpy(instance->migration_src, sourceNodeName, HOSTNAME_SIZE); euca_strncpy(instance->migration_dst, destNodeName, HOSTNAME_SIZE); euca_strncpy(instance->migration_credentials, credentials, CREDENTIAL_SIZE); save_instance_struct(instance); sem_v(inst_sem); // Establish migration-credential keys. LOGINFO("[%s] migration destination preparing %s > %s [creds=%s]\n", instance->instanceId, SP(instance->migration_src), SP(instance->migration_dst), (instance->migration_credentials == NULL) ? "UNSET" : "present"); // First, call config-file modification script to authorize source node. LOGDEBUG("[%s] authorizing migration source node %s\n", instance->instanceId, instance->migration_src); if (authorize_migration_keys("-a", instance->migration_src, instance->migration_credentials, instance, TRUE) != EUCA_OK) { goto failed_dest; } // Then, generate keys and restart libvirtd. if (generate_migration_keys(instance->migration_dst, instance->migration_credentials, TRUE, instance) != EUCA_OK) { goto failed_dest; } int error; if (vbr_parse(&(instance->params), pMeta) != EUCA_OK) { goto failed_dest; } // set up networking char *brname = NULL; if ((error = vnetStartNetwork(nc->vnetconfig, instance->ncnet.vlan, NULL, NULL, NULL, &brname)) != EUCA_OK) { LOGERROR("[%s] start network failed for instance, terminating it\n", instance->instanceId); EUCA_FREE(brname); goto failed_dest; } euca_strncpy(instance->params.guestNicDeviceName, brname, sizeof(instance->params.guestNicDeviceName)); EUCA_FREE(brname); // TODO: move stuff in startup_thread() into a function? set_instance_params(instance); if ((error = create_instance_backing(instance, TRUE)) // create files that back the disks || (error = gen_instance_xml(instance)) // create euca-specific instance XML file || (error = gen_libvirt_instance_xml(instance))) { // transform euca-specific XML into libvirt XML LOGERROR("[%s] failed to prepare images for migrating instance (error=%d)\n", instance->instanceId, error); goto failed_dest; } // attach any volumes for (int v = 0; v < EUCA_MAX_VOLUMES; v++) { ncVolume *volume = &instance->volumes[v]; if (strcmp(volume->stateName, VOL_STATE_ATTACHED) && strcmp(volume->stateName, VOL_STATE_ATTACHING)) continue; // skip the entry unless attached or attaching LOGDEBUG("[%s] volumes [%d] = '%s'\n", instance->instanceId, v, volume->stateName); // TODO: factor what the following out of here and doAttachVolume() in handlers_default.c int have_remote_device = 0; char *xml = NULL; char *remoteDevStr = NULL; char scUrl[512]; char localDevReal[32], localDevTag[256], remoteDevReal[132]; char *tagBuf = localDevTag; ebs_volume_data *vol_data = NULL; ret = convert_dev_names(volume->localDev, localDevReal, tagBuf); if (ret) goto unroll; //Do the ebs connect. LOGTRACE("[%s][%s] Connecting EBS volume to local host\n", instance->instanceId, volume->volumeId); get_service_url("storage", nc, scUrl); if (strlen(scUrl) == 0) { LOGERROR("[%s][%s] Failed to lookup enabled Storage Controller. Cannot attach volume %s\n", instance->instanceId, volume->volumeId, scUrl); have_remote_device = 0; goto unroll; } else { LOGTRACE("[%s][%s] Using SC URL: %s\n", instance->instanceId, volume->volumeId, scUrl); } //Do the ebs connect. LOGTRACE("[%s][%s] Connecting EBS volume to local host\n", instance->instanceId, volume->volumeId); int rc = connect_ebs_volume(scUrl, volume->attachmentToken, nc->config_use_ws_sec, nc->config_sc_policy_file, nc->ip, nc->iqn, &remoteDevStr, &vol_data); if (rc) { LOGERROR("Error connecting ebs volume %s\n", volume->attachmentToken); have_remote_device = 0; ret = EUCA_ERROR; goto unroll; } // update the volume struct with connection string obtained from SC euca_strncpy(volume->connectionString, vol_data->connect_string, sizeof(volume->connectionString)); if (!remoteDevStr || !strstr(remoteDevStr, "/dev")) { LOGERROR("[%s][%s] failed to connect to iscsi target\n", instance->instanceId, volume->volumeId); remoteDevReal[0] = '\0'; } else { LOGDEBUG("[%s][%s] attached iSCSI target of host device '%s'\n", instance->instanceId, volume->volumeId, remoteDevStr); snprintf(remoteDevReal, sizeof(remoteDevReal), "%s", remoteDevStr); have_remote_device = 1; } EUCA_FREE(remoteDevStr); // something went wrong above, abort if (!have_remote_device) { goto unroll; } // make sure there is a block device if (check_block(remoteDevReal)) { LOGERROR("[%s][%s] cannot verify that host device '%s' is available for hypervisor attach\n", instance->instanceId, volume->volumeId, remoteDevReal); goto unroll; } // generate XML for libvirt attachment request if (gen_volume_xml(volume->volumeId, instance, localDevReal, remoteDevReal) // creates vol-XXX.xml || gen_libvirt_volume_xml(volume->volumeId, instance)) { // creates vol-XXX-libvirt.xml via XSLT transform LOGERROR("[%s][%s] could not produce attach device xml\n", instance->instanceId, volume->volumeId); goto unroll; } // invoke hooks char path[EUCA_MAX_PATH]; char lpath[EUCA_MAX_PATH]; snprintf(path, sizeof(path), EUCALYPTUS_VOLUME_XML_PATH_FORMAT, instance->instancePath, volume->volumeId); // vol-XXX.xml snprintf(lpath, sizeof(lpath), EUCALYPTUS_VOLUME_LIBVIRT_XML_PATH_FORMAT, instance->instancePath, volume->volumeId); // vol-XXX-libvirt.xml if (call_hooks(NC_EVENT_PRE_ATTACH, lpath)) { LOGERROR("[%s][%s] cancelled volume attachment via hooks\n", instance->instanceId, volume->volumeId); goto unroll; } // read in libvirt XML, which may have been modified by the hook above if ((xml = file2str(lpath)) == NULL) { LOGERROR("[%s][%s] failed to read volume XML from %s\n", instance->instanceId, volume->volumeId, lpath); goto unroll; } continue; unroll: ret = EUCA_ERROR; // TODO: unroll all volume attachments goto failed_dest; } sem_p(inst_sem); instance->migration_state = MIGRATION_READY; instance->bootTime = time(NULL); // otherwise nc_state.booting_cleanup_threshold will kick in change_state(instance, BOOTING); // not STAGING, since in that mode we don't poll hypervisor for info LOGINFO("[%s] migration destination ready %s > %s\n", instance->instanceId, instance->migration_src, instance->migration_dst); save_instance_struct(instance); error = add_instance(&global_instances, instance); copy_instances(); sem_v(inst_sem); if (error) { if (error == EUCA_DUPLICATE_ERROR) { LOGINFO("[%s] instance struct already exists (from previous migration?), deleting and re-adding...\n", instance->instanceId); error = remove_instance(&global_instances, instance); if (error) { LOGERROR("[%s] could not replace (remove) instance struct, failing...\n", instance->instanceId); goto failed_dest; } error = add_instance(&global_instances, instance); if (error) { LOGERROR("[%s] could not replace (add) instance struct, failing...\n", instance->instanceId); goto failed_dest; } } else { LOGERROR("[%s] could not add instance struct, failing...\n", instance->instanceId); goto failed_dest; } } continue; failed_dest: sem_p(inst_sem); // Just making sure... if (instance != NULL) { LOGERROR("[%s] setting instance to Teardown(cleaning) after destination failure to prepare for migration\n", instance->instanceId); // Set state to Teardown(cleaning) so source won't wait until timeout to roll back. instance->migration_state = MIGRATION_CLEANING; instance->terminationTime = time(NULL); change_state(instance, TEARDOWN); save_instance_struct(instance); add_instance(&global_instances, instance); // OK if this fails--that should mean it's already been added. copy_instances(); } // If no remaining incoming or pending migrations, deauthorize all clients. // TO-DO: Consolidate with similar sequence in handlers.c into a utility function? if (!incoming_migrations_in_progress) { int incoming_migrations_pending = 0; LOGINFO("[%s] no remaining active incoming migrations -- checking to see if there are any pending migrations\n", instance->instanceId); bunchOfInstances *head = NULL; for (head = global_instances; head; head = head->next) { if ((head->instance->migration_state == MIGRATION_PREPARING) || (head->instance->migration_state == MIGRATION_READY)) { LOGINFO("[%s] is pending migration, state='%s', deferring deauthorization of migration keys\n", head->instance->instanceId, migration_state_names[head->instance->migration_state]); incoming_migrations_pending++; } } // TO-DO: Add belt and suspenders? if (!incoming_migrations_pending) { LOGINFO("[%s] no remaining incoming or pending migrations -- deauthorizing all migration client keys\n", instance->instanceId); authorize_migration_keys("-D -r", NULL, NULL, NULL, FALSE); } } sem_v(inst_sem); // Set to generic EUCA_ERROR unless already set to a more-specific error. if (ret == EUCA_OK) { ret = EUCA_ERROR; } } else { LOGERROR("unexpected migration request (node %s is neither source nor destination)\n", pMeta->nodeName); ret = EUCA_ERROR; } } return ret; }
// TODO don't leak shit. static PP_Bool vlc_did_create(PP_Instance instance, uint32_t _argc, const char *_argn[], const char *_argv[]) { vlc_setPPAPI_InitializingInstance(instance); VLC_UNUSED(_argc); VLC_UNUSED(_argn); VLC_UNUSED(_argv); if(vlc_PPAPI_InitializeInstance(instance) != VLC_SUCCESS) { return PP_FALSE; } PP_Bool ret = PP_FALSE; libvlc_instance_t* vlc_inst = NULL; libvlc_media_player_t* media_player = NULL; libvlc_media_list_player_t* media_list_player = NULL; libvlc_media_list_t* playlist = NULL; instance_t* new_inst = add_instance(instance); if(new_inst == NULL) { vlc_ppapi_log_error(instance, "failed to create the plugin instance object!\n"); goto error; } vlc_inst = libvlc_new(0, NULL); if(vlc_inst == NULL) { vlc_ppapi_log_error(instance, "failed to create the vlc instance!\n"); goto error; } else { new_inst->vlc = vlc_inst; } libvlc_log_set(vlc_inst, libvlc_logging_callback, (void*)new_inst); media_player = libvlc_media_player_new(vlc_inst); if(media_player == NULL) { vlc_ppapi_log_error(instance, "libvlc_media_player_t creation failed"); goto error; } else { new_inst->media_player = media_player; } var_Create(media_player, "ppapi-instance", VLC_VAR_INTEGER); var_SetInteger(media_player, "ppapi-instance", instance); var_SetString(media_player, "vout", "ppapi_vout_graphics3d"); if(-1 == libvlc_add_intf(vlc_inst, "ppapi_control")) { vlc_ppapi_log_error(instance, "failed to start `ppapi-control`"); goto error; } ret = PP_TRUE; goto done; error: ret = PP_FALSE; if(new_inst != NULL) { remove_instance(new_inst); } done: vlc_setPPAPI_InitializingInstance(0); return ret; }
//! //! Handles the instance migration request. //! //! @param[in] nc a pointer to the node controller (NC) state //! @param[in] pMeta a pointer to the node controller (NC) metadata structure //! @param[in] instances metadata for the instance to migrate to destination //! @param[in] instancesLen number of instances in the instance list //! @param[in] action IP of the destination Node Controller //! @param[in] credentials credentials that enable the migration //! //! @return EUCA_OK on success or EUCA_*ERROR on failure //! //! @pre //! //! @post static int doMigrateInstances(struct nc_state_t *nc, ncMetadata * pMeta, ncInstance ** instances, int instancesLen, char *action, char *credentials, char ** resourceLocations, int resourceLocationsLen) { int ret = EUCA_OK; int credentials_prepared = 0; char *libvirt_xml_modified = NULL; if (instancesLen <= 0) { LOGERROR("called with invalid instancesLen (%d)\n", instancesLen); pMeta->replyString = strdup("internal error (invalid instancesLen)"); return (EUCA_INVALID_ERROR); } LOGDEBUG("verifying %d instance[s] for migration...\n", instancesLen); for (int inst_idx = 0; inst_idx < instancesLen; inst_idx++) { LOGDEBUG("verifying instance # %d...\n", inst_idx); if (instances[inst_idx]) { ncInstance *instance_idx = instances[inst_idx]; LOGDEBUG("[%s] proposed migration action '%s' (%s > %s) [creds=%s]\n", SP(instance_idx->instanceId), SP(action), SP(instance_idx->migration_src), SP(instance_idx->migration_dst), (instance_idx->migration_credentials == NULL) ? "UNSET" : "present"); } else { pMeta->replyString = strdup("internal error (instance count mismatch)"); LOGERROR("Mismatch between migration instance count (%d) and length of instance list\n", instancesLen); return (EUCA_ERROR); } } // TO-DO: Optimize the location of this loop, placing it inside various conditionals below? for (int inst_idx = 0; inst_idx < instancesLen; inst_idx++) { ncInstance *instance_req = instances[inst_idx]; char *sourceNodeName = instance_req->migration_src; char *destNodeName = instance_req->migration_dst; LOGDEBUG("[%s] processing instance # %d (%s > %s)\n", instance_req->instanceId, inst_idx, instance_req->migration_src, instance_req->migration_dst); // this is a call to the source of migration if (!strcmp(pMeta->nodeName, sourceNodeName)) { // locate the instance structure ncInstance *instance; sem_p(inst_sem); { instance = find_instance(&global_instances, instance_req->instanceId); } sem_v(inst_sem); if (instance == NULL) { LOGERROR("[%s] cannot find instance\n", instance_req->instanceId); pMeta->replyString = strdup("failed to locate instance to migrate"); return (EUCA_NOT_FOUND_ERROR); } if (strcmp(action, "prepare") == 0) { sem_p(inst_sem); instance->migration_state = MIGRATION_PREPARING; euca_strncpy(instance->migration_src, sourceNodeName, HOSTNAME_SIZE); euca_strncpy(instance->migration_dst, destNodeName, HOSTNAME_SIZE); euca_strncpy(instance->migration_credentials, credentials, CREDENTIAL_SIZE); instance->migrationTime = time(NULL); update_resource_locations(&(instance->params), resourceLocations, resourceLocationsLen); save_instance_struct(instance); copy_instances(); sem_v(inst_sem); // Establish migration-credential keys if this is the first instance preparation for this host. LOGINFO("[%s] migration source preparing %s > %s [creds=%s]\n", SP(instance->instanceId), SP(instance->migration_src), SP(instance->migration_dst), (instance->migration_credentials == NULL) ? "UNSET" : "present"); if (!credentials_prepared) { if (generate_migration_keys(sourceNodeName, credentials, TRUE, instance) != EUCA_OK) { pMeta->replyString = strdup("internal error (migration credentials generation failed)"); return (EUCA_SYSTEM_ERROR); } else { credentials_prepared++; } } sem_p(inst_sem); instance->migration_state = MIGRATION_READY; save_instance_struct(instance); copy_instances(); sem_v(inst_sem); } else if (strcmp(action, "commit") == 0) { sem_p(inst_sem); if (instance->migration_state == MIGRATION_IN_PROGRESS) { LOGWARN("[%s] duplicate request to migration source to initiate %s > %s (already migrating)\n", instance->instanceId, instance->migration_src, instance->migration_dst); sem_v(inst_sem); return (EUCA_DUPLICATE_ERROR); } else if (instance->migration_state != MIGRATION_READY) { LOGERROR("[%s] request to commit migration %s > %s when source migration_state='%s' (not 'ready')\n", instance->instanceId, SP(sourceNodeName), SP(destNodeName), migration_state_names[instance->migration_state]); sem_v(inst_sem); return (EUCA_UNSUPPORTED_ERROR); } instance->migration_state = MIGRATION_IN_PROGRESS; outgoing_migrations_in_progress++; LOGINFO("[%s] migration source initiating %s > %s [creds=%s] (1 of %d active outgoing migrations)\n", instance->instanceId, instance->migration_src, instance->migration_dst, (instance->migration_credentials == NULL) ? "UNSET" : "present", outgoing_migrations_in_progress); save_instance_struct(instance); copy_instances(); sem_v(inst_sem); // since migration may take a while, we do them in a thread pthread_t tcb = { 0 }; if (pthread_create(&tcb, NULL, migrating_thread, (void *)instance)) { LOGERROR("[%s] failed to spawn a migration thread\n", instance->instanceId); return (EUCA_THREAD_ERROR); } set_corrid_pthread(get_corrid() != NULL ? get_corrid()->correlation_id : NULL, tcb); if (pthread_detach(tcb)) { LOGERROR("[%s] failed to detach the migration thread\n", instance->instanceId); return (EUCA_THREAD_ERROR); } } else if (strcmp(action, "rollback") == 0) { if ((instance->migration_state == MIGRATION_READY) || (instance->migration_state == MIGRATION_PREPARING)) { LOGINFO("[%s] rolling back migration (%s > %s) on source\n", instance->instanceId, instance->migration_src, instance->migration_dst); sem_p(inst_sem); migration_rollback(instance); sem_v(inst_sem); } else { LOGINFO("[%s] ignoring request to roll back migration on source with instance in state %s(%s) -- duplicate rollback request?\n", instance->instanceId, instance->stateName, migration_state_names[instance->migration_state]); } } else { LOGERROR("[%s] action '%s' is not valid\n", instance->instanceId, action); return (EUCA_INVALID_ERROR); } } else if (!strcmp(pMeta->nodeName, destNodeName)) { // this is a migrate request to destination if (!strcmp(action, "commit")) { LOGERROR("[%s] action '%s' for migration (%s > %s) is not valid on destination node\n", instance_req->instanceId, action, SP(sourceNodeName), SP(destNodeName)); return (EUCA_UNSUPPORTED_ERROR); } else if (!strcmp(action, "rollback")) { LOGINFO("[%s] rolling back migration (%s > %s) on destination\n", instance_req->instanceId, SP(sourceNodeName), SP(destNodeName)); sem_p(inst_sem); { ncInstance *instance = find_instance(&global_instances, instance_req->instanceId); if (instance != NULL) { LOGDEBUG("[%s] marked for cleanup\n", instance->instanceId); change_state(instance, SHUTOFF); instance->migration_state = MIGRATION_CLEANING; save_instance_struct(instance); } } sem_v(inst_sem); return EUCA_OK; } else if (strcmp(action, "prepare") != 0) { LOGERROR("[%s] action '%s' is not valid or not implemented\n", instance_req->instanceId, action); return (EUCA_INVALID_ERROR); } // Everything from here on is specific to "prepare" on a destination. // allocate a new instance struct ncInstance *instance = clone_instance(instance_req); if (instance == NULL) { LOGERROR("[%s] could not allocate instance struct\n", instance_req->instanceId); goto failed_dest; } sem_p(inst_sem); instance->migration_state = MIGRATION_PREPARING; instance->migrationTime = time(NULL); //In preparing state, so set migrationTime. euca_strncpy(instance->migration_src, sourceNodeName, HOSTNAME_SIZE); euca_strncpy(instance->migration_dst, destNodeName, HOSTNAME_SIZE); euca_strncpy(instance->migration_credentials, credentials, CREDENTIAL_SIZE); update_resource_locations(&(instance->params), resourceLocations, resourceLocationsLen); sem_v(inst_sem); // Establish migration-credential keys. LOGINFO("[%s] migration destination preparing %s > %s [creds=%s]\n", instance->instanceId, SP(instance->migration_src), SP(instance->migration_dst), (instance->migration_credentials == NULL) ? "UNSET" : "present"); // First, call config-file modification script to authorize source node. LOGDEBUG("[%s] authorizing migration source node %s\n", instance->instanceId, instance->migration_src); if (authorize_migration_keys("-a", instance->migration_src, instance->migration_credentials, instance, TRUE) != EUCA_OK) { goto failed_dest; } // Then, generate keys and restart libvirtd. if (generate_migration_keys(instance->migration_dst, instance->migration_credentials, TRUE, instance) != EUCA_OK) { goto failed_dest; } int error; //Fix for EUCA-10433, need instance struct in global_instances prior to doing volume ops //The monitor thread will now pick up the instance, so the migrationTime must be set sem_p(inst_sem); save_instance_struct(instance); error = add_instance(&global_instances, instance); copy_instances(); sem_v(inst_sem); if (error) { if (error == EUCA_DUPLICATE_ERROR) { LOGINFO("[%s] instance struct already exists (from previous migration?), deleting and re-adding...\n", instance->instanceId); error = remove_instance(&global_instances, instance); if (error) { LOGERROR("[%s] could not replace (remove) instance struct, failing...\n", instance->instanceId); goto failed_dest; } error = add_instance(&global_instances, instance); if (error) { LOGERROR("[%s] could not replace (add) instance struct, failing...\n", instance->instanceId); goto failed_dest; } } else { LOGERROR("[%s] could not add instance struct, failing...\n", instance->instanceId); goto failed_dest; } } if (vbr_parse(&(instance->params), pMeta) != EUCA_OK) { goto failed_dest; } // set up networking char brname[IF_NAME_LEN] = ""; if (!strcmp(nc->pEucaNet->sMode, NETMODE_MANAGED)) { snprintf(brname, IF_NAME_LEN, "%s", instance->groupIds[0]); } else { snprintf(brname, IF_NAME_LEN, "%s", nc->pEucaNet->sBridgeDevice); } euca_strncpy(instance->params.guestNicDeviceName, brname, sizeof(instance->params.guestNicDeviceName)); // TODO: move stuff in startup_thread() into a function? set_instance_params(instance); if ((error = create_instance_backing(instance, TRUE)) // create files that back the disks || (error = gen_instance_xml(instance)) // create euca-specific instance XML file || (error = gen_libvirt_instance_xml(instance))) { // transform euca-specific XML into libvirt XML LOGERROR("[%s] failed to prepare images for migrating instance (error=%d)\n", instance->instanceId, error); goto failed_dest; } // attach any volumes for (int v = 0; v < EUCA_MAX_VOLUMES; v++) { ncVolume *volume = &instance->volumes[v]; if (strcmp(volume->stateName, VOL_STATE_ATTACHED) && strcmp(volume->stateName, VOL_STATE_ATTACHING)) continue; // skip the entry unless attached or attaching LOGDEBUG("[%s] volumes [%d] = '%s'\n", instance->instanceId, v, volume->stateName); ebs_volume_data *vol_data = NULL; char *libvirt_xml = NULL; char serial[128]; char bus[16]; set_serial_and_bus(volume->volumeId, volume->devName, serial, sizeof(serial), bus, sizeof(bus)); if ((ret = connect_ebs(volume->devName, serial, bus, nc, instance->instanceId, volume->volumeId, volume->attachmentToken, &libvirt_xml, &vol_data)) != EUCA_OK) { goto unroll; } // update the volume struct with connection string obtained from SC euca_strncpy(volume->connectionString, vol_data->connect_string, sizeof(volume->connectionString)); // save volume info into vol-XXX-libvirt.xml for future detach if (create_vol_xml(instance->instanceId, volume->volumeId, libvirt_xml, &libvirt_xml_modified) != EUCA_OK) { goto unroll; } continue; unroll: ret = EUCA_ERROR; // @TODO: unroll all previous ones // for (int uv = v - 1; uv >= 0; uv--) { // disconnect_ebs(nc, instance->instanceId, volume->volumeId, ) // } goto failed_dest; } // build any secondary network interface xml files for (int w=0; w < EUCA_MAX_NICS; w++) { if (strlen(instance->secNetCfgs[w].interfaceId) == 0) continue; gen_libvirt_nic_xml(instance->instancePath, instance->secNetCfgs[w].interfaceId); } sem_p(inst_sem); instance->migration_state = MIGRATION_READY; instance->migrationTime = 0; //Reset the timer, to ensure monitoring thread handles this properly. This is required when setting BOOTING state instance->bootTime = time(NULL); // otherwise nc_state.booting_cleanup_threshold will kick in change_state(instance, BOOTING); // not STAGING, since in that mode we don't poll hypervisor for info LOGINFO("[%s] migration destination ready %s > %s\n", instance->instanceId, instance->migration_src, instance->migration_dst); save_instance_struct(instance); copy_instances(); sem_v(inst_sem); continue; failed_dest: sem_p(inst_sem); // Just making sure... if (instance != NULL) { LOGERROR("[%s] setting instance to Teardown(cleaning) after destination failure to prepare for migration\n", instance->instanceId); // Set state to Teardown(cleaning) so source won't wait until timeout to roll back. instance->migration_state = MIGRATION_CLEANING; instance->terminationTime = time(NULL); change_state(instance, TEARDOWN); save_instance_struct(instance); add_instance(&global_instances, instance); // OK if this fails--that should mean it's already been added. copy_instances(); } // If no remaining incoming or pending migrations, deauthorize all clients. // TO-DO: Consolidate with similar sequence in handlers.c into a utility function? if (!incoming_migrations_in_progress) { int incoming_migrations_pending = 0; LOGINFO("[%s] no remaining active incoming migrations -- checking to see if there are any pending migrations\n", instance->instanceId); bunchOfInstances *head = NULL; for (head = global_instances; head; head = head->next) { if ((head->instance->migration_state == MIGRATION_PREPARING) || (head->instance->migration_state == MIGRATION_READY)) { LOGINFO("[%s] is pending migration, state='%s', deferring deauthorization of migration keys\n", head->instance->instanceId, migration_state_names[head->instance->migration_state]); incoming_migrations_pending++; } } // TO-DO: Add belt and suspenders? if (!incoming_migrations_pending) { LOGINFO("[%s] no remaining incoming or pending migrations -- deauthorizing all migration client keys\n", instance->instanceId); authorize_migration_keys("-D -r", NULL, NULL, NULL, FALSE); } } sem_v(inst_sem); // Set to generic EUCA_ERROR unless already set to a more-specific error. if (ret == EUCA_OK) { ret = EUCA_ERROR; } } else { LOGERROR("unexpected migration request (node %s is neither source nor destination)\n", pMeta->nodeName); ret = EUCA_ERROR; } } return ret; }
int main (int argc, char **argv) { printf ("=====> testing misc.c\n"); test_command("date"); test_command("ls / -l | sort"); test_command("/foo"); { char c = 0; long l = 0; int i = 0; long long ll = 0; sscanf_lines ("a1\na\na2\n", "a%d", &i); assert (i==1); sscanf_lines ("a\nab3\na 4\na5", "a %d", &i); assert (i==4); sscanf_lines ("", "%d", &i); sscanf_lines ("\n\n\n", "%d", &i); sscanf_lines ("abcdefg6", "g%d", &i); assert (i!=6); sscanf_lines ("abcdefg", "ab%cdefg", &c); assert (c=='c'); sscanf_lines ("a\na 7\na\n", "a %ld", &l); assert (l==7L); sscanf_lines ("a\n8a\na9\n", "a %lld", &ll); assert (ll==9L); } printf ("=====> testing data.c\n"); { #define INSTS 50 bunchOfInstances * bag = NULL; ncInstance * inst = NULL; ncInstance * Insts[INSTS]; int i, n; printf ("========> testing instance struct management\n"); free_instance (NULL); free_instance (&inst); inst = allocate_instance ("the-uuid", "i1", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0); assert(inst!=NULL); free_instance (&inst); assert(inst==NULL); n = total_instances (&bag); assert(n==0); bag=NULL; inst = find_instance(&bag, "foo"); assert(inst==NULL); bag=NULL; n = remove_instance(&bag, NULL); assert(n!=0); bag=NULL; for (i=0; i<INSTS; i++) { char id[10]; sprintf(id, "i-%d", i); inst = Insts[i] = allocate_instance ("the-uuid", id, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0); assert (inst!=NULL); n = add_instance(&bag, inst); assert (n==0); } n = total_instances (&bag); assert (n==INSTS); n = remove_instance(&bag, Insts[0]); assert (n==0); n = remove_instance(&bag, Insts[INSTS-1]); assert (n==0); n = total_instances (&bag); assert (n==INSTS-2); printf ("========> testing volume struct management\n"); ncVolume * v; inst = allocate_instance ("the-uuid", "i2", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0); assert(inst!=NULL); for (i=0; i<EUCA_MAX_VOLUMES; i++) { char id[10]; sprintf (id, "v-%d", i); v = save_volume (inst, id, "rd", "ld", "ldr", VOL_STATE_ATTACHED); assert (v!=NULL); } assert (is_volume_used (v)); assert (save_volume (inst, "too-much", "rd", "ld", "ldr", VOL_STATE_ATTACHED)==NULL); assert (save_volume (inst, v->volumeId, NULL, NULL, NULL, NULL)!=NULL); assert (save_volume (inst, v->volumeId, "RD", NULL, NULL, NULL)!=NULL); assert (save_volume (inst, v->volumeId, NULL, "LD", NULL, NULL)!=NULL); assert (save_volume (inst, v->volumeId, NULL, NULL, "LDR", NULL)!=NULL); assert (save_volume (inst, v->volumeId, NULL, NULL, NULL, VOL_STATE_DETACHED)!=NULL); assert (strcmp (v->remoteDev, "RD") == 0); assert (save_volume (inst, "v-x1", NULL, NULL, NULL, VOL_STATE_ATTACHING)!=NULL); assert (save_volume (inst, "v-x2", NULL, NULL, NULL, VOL_STATE_ATTACHING)==NULL); assert (save_volume (inst, "v-x1", NULL, NULL, NULL, VOL_STATE_DETACHING)!=NULL); assert (save_volume (inst, "v-x2", NULL, NULL, NULL, VOL_STATE_ATTACHING)==NULL); assert (save_volume (inst, "v-x1", NULL, NULL, NULL, VOL_STATE_DETACHING_FAILED)!=NULL); assert (save_volume (inst, "v-x2", NULL, NULL, NULL, VOL_STATE_ATTACHING)==NULL); assert (free_volume (inst, "v-x1")!=NULL); for (i=0; i<EUCA_MAX_VOLUMES-1; i++) { char id[10]; sprintf (id, "v-%d", i); v = free_volume (inst, id); assert (v!=NULL); } free_instance (&inst); assert(inst==NULL); } printf ("OK\n"); return 0; }
void adopt_instances() { int dom_ids[MAXDOMS]; int num_doms = 0; int i; virDomainPtr dom = NULL; if (! check_hypervisor_conn()) return; logprintfl (EUCAINFO, "looking for existing domains\n"); virSetErrorFunc (NULL, libvirt_error_handler); num_doms = virConnectListDomains(nc_state.conn, dom_ids, MAXDOMS); if (num_doms == 0) { logprintfl (EUCAINFO, "no currently running domains to adopt\n"); return; } if (num_doms < 0) { logprintfl (EUCAWARN, "WARNING: failed to find out about running domains\n"); return; } for ( i=0; i<num_doms; i++) { int error; virDomainInfo info; const char * dom_name; ncInstance * instance; sem_p(hyp_sem); dom = virDomainLookupByID(nc_state.conn, dom_ids[i]); sem_v(hyp_sem); if (!dom) { logprintfl (EUCAWARN, "WARNING: failed to lookup running domain #%d, ignoring it\n", dom_ids[i]); continue; } sem_p(hyp_sem); error = virDomainGetInfo(dom, &info); sem_v(hyp_sem); if (error < 0 || info.state == VIR_DOMAIN_NOSTATE) { logprintfl (EUCAWARN, "WARNING: failed to get info on running domain #%d, ignoring it\n", dom_ids[i]); continue; } if (info.state == VIR_DOMAIN_SHUTDOWN || info.state == VIR_DOMAIN_SHUTOFF || info.state == VIR_DOMAIN_CRASHED ) { logprintfl (EUCADEBUG, "ignoring non-running domain #%d\n", dom_ids[i]); continue; } sem_p(hyp_sem); if ((dom_name = virDomainGetName(dom))==NULL) { sem_v(hyp_sem); logprintfl (EUCAWARN, "WARNING: failed to get name of running domain #%d, ignoring it\n", dom_ids[i]); continue; } sem_v(hyp_sem); if (!strcmp(dom_name, "Domain-0")) continue; if ((instance = scRecoverInstanceInfo (dom_name))==NULL) { logprintfl (EUCAWARN, "WARNING: failed to recover Eucalyptus metadata of running domain %s, ignoring it\n", dom_name); continue; } change_state (instance, info.state); sem_p (inst_sem); int err = add_instance (&global_instances, instance); sem_v (inst_sem); if (err) { free_instance (&instance); continue; } logprintfl (EUCAINFO, "- adopted running domain %s from user %s\n", instance->instanceId, instance->userId); /* TODO: try to look up IPs? */ sem_p(hyp_sem); virDomainFree (dom); sem_v(hyp_sem); } }
static int doRunInstance( struct nc_state_t *nc, ncMetadata *meta, char *instanceId, char *reservationId, virtualMachine *params, char *imageId, char *imageURL, char *kernelId, char *kernelURL, char *ramdiskId, char *ramdiskURL, char *keyName, // char *privMac, char *privIp, int vlan, netConfig *netparams, char *userData, char *launchIndex, char **groupNames, int groupNamesSize, ncInstance **outInst) { ncInstance * instance = NULL; * outInst = NULL; pid_t pid; netConfig ncnet; int error; memcpy(&ncnet, netparams, sizeof(netConfig)); /* check as much as possible before forking off and returning */ sem_p (inst_sem); instance = find_instance (&global_instances, instanceId); sem_v (inst_sem); if (instance) { logprintfl (EUCAFATAL, "Error: instance %s already running\n", instanceId); return 1; /* TODO: return meaningful error codes? */ } if (!(instance = allocate_instance (instanceId, reservationId, params, imageId, imageURL, kernelId, kernelURL, ramdiskId, ramdiskURL, instance_state_names[PENDING], PENDING, meta->userId, &ncnet, keyName, userData, launchIndex, groupNames, groupNamesSize))) { logprintfl (EUCAFATAL, "Error: could not allocate instance struct\n"); return 2; } change_state(instance, STAGING); sem_p (inst_sem); error = add_instance (&global_instances, instance); sem_v (inst_sem); if ( error ) { free_instance (&instance); logprintfl (EUCAFATAL, "Error: could not save instance struct\n"); return error; } instance->launchTime = time (NULL); /* instance->params.mem = params->mem; instance->params.cores = params->cores; instance->params.disk = params->disk; strcpy (instance->ncnet.privateIp, "0.0.0.0"); strcpy (instance->ncnet.publicIp, "0.0.0.0"); */ /* do the potentially long tasks in a thread */ pthread_attr_t* attr = (pthread_attr_t*) malloc(sizeof(pthread_attr_t)); if (!attr) { free_instance (&instance); logprintfl (EUCAFATAL, "Warning: out of memory\n"); return 1; } pthread_attr_init(attr); pthread_attr_setdetachstate(attr, PTHREAD_CREATE_DETACHED); if ( pthread_create (&(instance->tcb), attr, startup_thread, (void *)instance) ) { pthread_attr_destroy(attr); logprintfl (EUCAFATAL, "failed to spawn a VM startup thread\n"); sem_p (inst_sem); remove_instance (&global_instances, instance); sem_v (inst_sem); free_instance (&instance); if (attr) free(attr); return 1; } pthread_attr_destroy(attr); if (attr) free(attr); * outInst = instance; return 0; }
//! //! Main entry point of the application //! //! @param[in] argc the number of parameter passed on the command line //! @param[in] argv the list of arguments //! //! @return Always return 0 //! int main(int argc, char **argv) { printf("=====> testing misc.c\n"); test_command("date"); test_command("ls / -l | sort"); test_command("/foo"); { char c = 0; long l = 0; int i = 0; long long ll = 0; euca_lscanf("a1\na\na2\n", "a%d", &i); assert(i == 1); euca_lscanf("a\nab3\na 4\na5", "a %d", &i); assert(i == 4); euca_lscanf("", "%d", &i); euca_lscanf("\n\n\n", "%d", &i); euca_lscanf("abcdefg6", "g%d", &i); assert(i != 6); euca_lscanf("abcdefg", "ab%cdefg", &c); assert(c == 'c'); euca_lscanf("a\na 7\na\n", "a %ld", &l); assert(l == 7L); euca_lscanf("a\n8a\na9\n", "a %lld", &ll); assert(ll == 9L); } printf("=====> testing auth.c\n"); { //int decrypt_string_with_node_and_symmetric_key(char *in_buffer, char *key_buffer, char**out_buffer) euca_init_cert(); char *encrypted_symm_key = "YCvEugV7FynwQnyDbNX8hVFstseIpzhBCi6nxWZOUhVbivEf9Frkk7evxvQeSn9GUIvyNSE15Stts/CQmIGNsAKpAmjUoDzkkB/8EUCO9bgVi6IQl6SOzZCqX1hGCMZT1Ir32HXcwZcEbtDl0WpfLahjT9pZQAtDnnRT7H8+qysxUbEoL9Z2Yw5GneF5hRDWcA9Kce617oNbPFiZjLnnQr2iNsxyWb8LVj7KnBweJ8UJumgcWp26VsWoBUUCK/3adPAvOk/kalgrXZAk6fo/TqGUqdokjj1tz3rG7dcvTRuB0qwY1P8KfgRg3HABQcHjriKNvBYTVDhhEFDP2v0fiA=="; char *encrypted_string = "yuDM7HLybe+7DdkYFt+7zXYCeB/WHIdXSw7eF14L8YONEWmZdTEJwgXcGYdRpfDlY821xYi3asgURP6k9gFtPxjDHv/VcEKENJk9i/RbiAp0rEZ+gmkN3HQE9PjfNmS83AS1OyUnDiK2VcFRID7QKHcMdGrL6EXg/0QT1cDuwF0VbL71tdSddpFUHanaHQy2PzqKVPjfAqKWDBanMZWXckhYuHAMDCFkASvx8tU/7TrCJ7O697sScCBUQXqBZFY7930se2Jscg2u0tGlyKEK11gPNAnrIihAmgMVH2ZUzN1Ds9kFtGPrxoyLZbaxwYD5yzrd0qRBRrErZEWvj63nV4SUXKsmI7xmWBBUbosWmQzTp3mcsmnU40mowoCbOpoWt33XrlTJTfxA+dI1pnDWZY00lgISZe9IgQTAgF5o8GECw7uTZoK5b6LCTOSJPZPE57BjH9naeOnKMaXEe/Zl+s3j26hYhA8tP3IQIzOjqHcAhRGe/o2nkgVzLAYfBnaqsppKa8wJ2+qMUyh2f00c0W0GBHaSAAVh1PzcQiTOoLXYx9HDNxxtaZqL0TFfWxXkKm+/VjSQLqZ6HBqZAqiWIatHkD4UU83gCBlfvxw6ML8Z9A0VDUVbuuXTMCA1Z48e+gHK7/m1+S0/h0tW8wTBJeO9G1JkYdCNjaszey9Dl32v0jgGKw3BSgIwM+//lNL3yEdPx3pdhFxsYV0++bLxbFqZ2xpeFXupGmrVAEUyeqo5xcehMCpmKlJmQINTAav5vo2GtXBPvbNJOF7oIRakbr6jDF811V5jU5Dlwu6A9Yn8cPpZplB23Wo+1hsg3DjUCz3RxOwi5uIyF3IRbqqyt9mx3QlaxrXfjA0HweHE7O5TkeWnLWiPTefHR4ldHgKfDV9KScJLpmhEIznuwfEQaO855Z6JovWq6nKyPYXRToajiMwotrf6Sjkod9mQTZkbt/KSK4/PlIex3GhFHAFkUOwKJkI+Qenf1B8hPVDvoJ6PPZTUo7h127USsiUaZfUISgH2mep1YUyAdXlg+obK5iLprLhJqZwXh7dsR4Efn91YFcqEsVtO284CxWASh5Mid+pJD6FxVU8/pbX/EEi963fQgw42SiQxVXCaMySVB/9zlBfPg0dwP8yxwD+SiJz5In+oTDmr+OhpY0vQzkt/UnhORFpvJM7i1scY/rjAz2j6LjsHca4bt/x0JYkM+Vr+tZ90iiS01+fQX/fgFih6l9RoLWsbnilTx39dtwI8pOPitO90glIQ3EvLLmvZN9nvx9JfWTuinAkpOqrlkbc9ccKsAWa1zvvfCzGgqONoJ499rGFsY6H81jXR4h8K2o9n/Xs/8Sp8I8IqWfmS/JKH21JquJi4gLpmmZ38Kv6V4R7j5YcB9YwnIfav/uAJTN9VD9NKOyFwfhDA2YT4ErzMk5UL3sfQIX6UCzaKCiOeH3nKHzM7X4aHSqtSbvVNVxQ0tMYvm2oVEojmaXWGHmWyoylXJ1v0eaK38SDzwdpef6UKXESPEMpnR0krqH8bC7lZyMx2OyKpse9hJbjhzOvgv91lkUG3kidPxKraTUwXUmxVlUgxfcCgknO93U+kopjiffJDe/xILawvpEq0KWBFfbFN679znyz+8AEud2WSYdz7KnYuoX3RmViid/Oj0w=="; char *decrypted = NULL; int out_len = -1; if (decrypt_string_with_node_and_symmetric_key(encrypted_string, encrypted_symm_key, &decrypted, &out_len) != EUCA_OK) { printf("failed to decrypt using symmetric key\n"); } else { printf("decrypted length: %d\n", out_len); } } printf("=====> testing data.c\n"); { #define INSTS 50 bunchOfInstances *bag = NULL; ncInstance *inst = NULL; ncInstance *Insts[INSTS]; int i, n; printf("========> testing instance struct management\n"); free_instance(NULL); free_instance(&inst); inst = allocate_instance("the-uuid", "i1", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0); assert(inst != NULL); free_instance(&inst); assert(inst == NULL); n = total_instances(&bag); assert(n == 0); bag = NULL; inst = find_instance(&bag, "foo"); assert(inst == NULL); bag = NULL; n = remove_instance(&bag, NULL); assert(n != EUCA_OK); bag = NULL; for (i = 0; i < INSTS; i++) { char id[10]; sprintf(id, "i-%d", i); inst = Insts[i] = allocate_instance("the-uuid", id, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0); assert(inst != NULL); n = add_instance(&bag, inst); assert(n == EUCA_OK); } n = total_instances(&bag); assert(n == INSTS); n = remove_instance(&bag, Insts[0]); assert(n == EUCA_OK); n = remove_instance(&bag, Insts[INSTS - 1]); assert(n == EUCA_OK); n = total_instances(&bag); assert(n == INSTS - 2); printf("========> testing volume struct management\n"); ncVolume *v; inst = allocate_instance("the-uuid", "i2", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0); assert(inst != NULL); for (i = 0; i < EUCA_MAX_VOLUMES; i++) { char id[10]; sprintf(id, "v-%d", i); v = save_volume(inst, id, "tok", "rd", "ld", "ldr", VOL_STATE_ATTACHED); assert(v != NULL); } assert(is_volume_used(v)); assert(save_volume(inst, "too-much", "tok", "rd", "ld", "ldr", VOL_STATE_ATTACHED) == NULL); assert(save_volume(inst, v->volumeId, NULL, NULL, NULL, NULL, NULL) != NULL); assert(save_volume(inst, v->volumeId, NULL, "RD", NULL, NULL, NULL) != NULL); assert(save_volume(inst, v->volumeId, NULL, NULL, "LD", NULL, NULL) != NULL); assert(save_volume(inst, v->volumeId, NULL, NULL, NULL, "LDR", NULL) != NULL); assert(save_volume(inst, v->volumeId, NULL, NULL, NULL, NULL, VOL_STATE_DETACHED) != NULL); assert(strcmp(v->attachmentToken, "RD") == 0); assert(save_volume(inst, "v-x1", NULL, NULL, NULL, NULL, VOL_STATE_ATTACHING) != NULL); assert(save_volume(inst, "v-x2", NULL, NULL, NULL, NULL, VOL_STATE_ATTACHING) == NULL); assert(save_volume(inst, "v-x1", NULL, NULL, NULL, NULL, VOL_STATE_DETACHING) != NULL); assert(save_volume(inst, "v-x2", NULL, NULL, NULL, NULL, VOL_STATE_ATTACHING) == NULL); assert(save_volume(inst, "v-x1", NULL, NULL, NULL, NULL, VOL_STATE_DETACHING_FAILED) != NULL); assert(save_volume(inst, "v-x2", NULL, NULL, NULL, NULL, VOL_STATE_ATTACHING) == NULL); assert(free_volume(inst, "v-x1") != NULL); for (i = 0; i < EUCA_MAX_VOLUMES - 1; i++) { char id[10]; sprintf(id, "v-%d", i); v = free_volume(inst, id); assert(v != NULL); } free_instance(&inst); assert(inst == NULL); } printf("OK\n"); return 0; }
void check_for_enabling(Event_p instance_ptr, Node_p node_ptr, int type) {/* Init check_for_enabling */ int tr = GET_TRANSITION_INDEX(instance_ptr); Pred_p pred_ptr = GET_TRANSITION_PREDICATE(tr); #ifdef SYMBOLIC #ifdef SIMULATION int at_least_one_class_requires_presplit = tabt[tr].pre_split; #endif int enabled; Event_p next_ptr; #endif if(verify_predicate_constraint(pred_ptr,instance_ptr)) {/* Verifica il predicato */ #ifdef SYMBOLIC #ifdef SIMULATION if(at_least_one_class_requires_presplit) {/* Non si puo' fare solo preselection */ enabled = pre_split_instance(instance_ptr,TOTAL); if(enabled) {/* Se si sono prodotte delle istanze */ for( ; old_split != NULL ; ) {/* Per ogni istanza costruita */ next_ptr = old_split->next; if(verify_marking_constraint(node_ptr,old_split,tr,type)) {/* Verifica la marcatura */ old_split->next = new_enabled_list; new_enabled_list = old_split; }/* Verifica la marcatura */ else dispose_old_event(old_split); old_split = next_ptr; }/* Per ogni istanza costruita */ }/* Se si sono prodotte delle istanze */ }/* Non si puo' fare solo preselection */ else {/* Solo preselection */ if(verify_marking_constraint(node_ptr,instance_ptr,tr,type)) add_instance(instance_ptr); }/* Solo preselection */ #endif #ifdef REACHABILITY enabled = pre_split_instance(instance_ptr,TOTAL); if(enabled) {/* Se si sono prodotte delle istanze */ for( ; old_split != NULL ; ) {/* Per ogni istanza costruita */ next_ptr = old_split->next; if(verify_marking_constraint(node_ptr,old_split,tr,type)) {/* Verifica la marcatura */ old_split->next = new_enabled_list; new_enabled_list = old_split; }/* Verifica la marcatura */ else dispose_old_event(old_split); old_split = next_ptr; }/* Per ogni istanza costruita */ }/* Se si sono prodotte delle istanze */ #endif #endif #ifdef COLOURED if(verify_marking_constraint(node_ptr,instance_ptr,tr,type)) add_instance(instance_ptr); #endif }/* Verifica il predicato */ }/* End check_for_enabling */
int main( int argc, char *argv[] ) { command_options options; bool ret = parse_arguments( argc, argv, &options ); if ( !ret ) { usage(); exit( EXIT_FAILURE ); } init_log( basename( argv[ 0 ] ), LOG_OUTPUT_STDOUT ); init_vxlan_ctrl_client(); uint8_t status = SUCCEEDED; ret = false; switch ( options.type ) { case ADD_INSTANCE_REQUEST: { ret = add_instance( options.vni, options.ip_addr, options.port, options.aging_time, &status ); } break; case SET_INSTANCE_REQUEST: { ret = set_instance( options.vni, options.set_bitmap, options.ip_addr, options.port, options.aging_time, &status ); } break; case INACTIVATE_INSTANCE_REQUEST: { ret = inactivate_instance( options.vni, &status ); } break; case ACTIVATE_INSTANCE_REQUEST: { ret = activate_instance( options.vni, &status ); } break; case DEL_INSTANCE_REQUEST: { ret = delete_instance( options.vni, &status ); } break; case SHOW_GLOBAL_REQUEST: { ret = show_global( options.set_bitmap, &status ); } break; case LIST_INSTANCES_REQUEST: { ret = list_instances( options.vni, options.set_bitmap, &status ); } break; case SHOW_FDB_REQUEST: { ret = show_fdb( options.vni, &status ); } break; case ADD_FDB_ENTRY_REQUEST: { ret = add_fdb_entry( options.vni, options.eth_addr, options.ip_addr, options.aging_time, &status ); } break; case DEL_FDB_ENTRY_REQUEST: { ret = delete_fdb_entry( options.vni, options.eth_addr, &status ); } break; default: { printf( "Undefined command ( %#x ).\n", options.type ); status = OTHER_ERROR; ret = false; } break; } if ( !ret ) { printf( "Failed to execute a command ( %u ).\n", status ); } finalize_vxlan_ctrl_client(); finalize_log(); return status; }