//! //! Destroy the backing store for a given instance //! //! @param[in] instance the instance identifier for which we will destroy the backing store //! @param[in] do_destroy_files set to TRUE if we need to destroy the content otherwise set to FALSE. //! //! @return EUCA_OK on success //! //! @pre The instance parameter must not be NULL and do_destroy_files must be a valid boolean. //! //! @note //! int destroy_instance_backing(ncInstance * instance, boolean do_destroy_files) { int i = 0; int ret = EUCA_OK; char path[EUCA_MAX_PATH] = ""; char work_regex[1024] = ""; // {userId}/{instanceId}/.* char scURL[512] = ""; if (get_localhost_sc_url(scURL) != EUCA_OK || strlen(scURL) == 0) { LOGWARN("[%s] could not obtain SC URL (is SC enabled?)\n", instance->instanceId); scURL[0] = '\0'; } // find and detach iSCSI targets, if any for (i = 0; i < EUCA_MAX_VOLUMES; ++i) { ncVolume *volume = &instance->volumes[i]; if (!is_volume_used(volume)) continue; if (disconnect_ebs_volume (scURL, localhost_config.use_ws_sec, localhost_config.ws_sec_policy_file, volume->attachmentToken, volume->connectionString, localhost_config.ip, localhost_config.iqn) != 0) { LOGERROR("[%s][%s] failed to disconnect volume\n", instance->instanceId, volume->volumeId); } } // see if instance directory is there (sometimes startup fails before it is created) set_path(path, sizeof(path), instance, NULL); if (check_path(path)) return (ret); if (do_destroy_files) { set_id2(instance, "/.*", work_regex, sizeof(work_regex)); if (blobstore_delete_regex(work_bs, work_regex) == -1) { LOGERROR("[%s] failed to remove some artifacts in %s\n", instance->instanceId, path); } for (i = 0; i < EUCA_MAX_VOLUMES; ++i) { ncVolume *volume = &instance->volumes[i]; snprintf(path, sizeof(path), EUCALYPTUS_VOLUME_XML_PATH_FORMAT, instance->instancePath, volume->volumeId); unlink(path); } // delete all non-blob files in the directory if (blobstore_delete_nonblobs(work_bs, instance->instancePath) < 0) { LOGERROR("[%s] failed to delete some non-blob files under %s\n", instance->instanceId, instance->instancePath); } } // Finally try to remove the directory. If either the user or our code introduced // any new files, this last step will fail. set_path(path, sizeof(path), instance, NULL); if (rmdir(path) && do_destroy_files) { LOGERROR("[%s] failed to remove backing directory %s\n", instance->instanceId, path); } return (ret); }
//! //! Do a clone of an instance backing store to another location. //! //! @param[in] instance pointer to the instance //! @param[in] filePrefix the //! @param[in] blockPath the path where we need to clone //! //! @return EUCA_OK on success or the following error codes: //! \li EUCA_IO_ERROR: if we fail to copy the data. //! \li EUCA_NOT_FOUND_ERROR: if we cannot find the blobstore to clone. //! \li EUCA_PERMISSION_ERROR: if we fail to create/open the destination blobstore //! //! @pre \li The instance parameter must not be NULL. //! \li The filePrefix and blockPath parameters must not be NULL and should be valid strings. //! //! @note //! int clone_bundling_backing(ncInstance * instance, const char *filePrefix, char *blockPath) { int ret = EUCA_OK; int found = -1; char path[EUCA_MAX_PATH] = ""; char work_regex[1024] = ""; char id[BLOBSTORE_MAX_PATH] = ""; char workPath[BLOBSTORE_MAX_PATH] = ""; blockblob *src_blob = NULL; blockblob *dest_blob = NULL; blockblob *bb = NULL; blockblob_meta *bm = NULL; blockblob_meta *next = NULL; blockblob_meta *matches = NULL; set_path(path, sizeof(path), instance, NULL); set_id2(instance, "/.*", work_regex, sizeof(work_regex)); if ((found = blobstore_search(work_bs, work_regex, &matches) <= 0)) { LOGERROR("[%s] failed to find blob in %s %d\n", instance->instanceId, path, found); return (EUCA_NOT_FOUND_ERROR); } for (bm = matches; bm; bm = bm->next) { bb = blockblob_open(work_bs, bm->id, 0, 0, NULL, FIND_TIMEOUT_USEC); if ((bb != NULL) && (bb->snapshot_type == BLOBSTORE_SNAPSHOT_DM) && (strstr(bb->blocks_path, "emi-") != NULL)) { // root image contains substr 'emi-' src_blob = bb; break; } else if (bb != NULL) { blockblob_close(bb); } } if (!src_blob) { LOGERROR("[%s] couldn't find the blob to clone from", instance->instanceId); ret = EUCA_NOT_FOUND_ERROR; goto error; } set_id(instance, NULL, workPath, sizeof(workPath)); snprintf(id, sizeof(id), "%s/bundle/%s", workPath, filePrefix); // open destination blob dest_blob = blockblob_open(work_bs, id, src_blob->size_bytes, BLOBSTORE_FLAG_CREAT | BLOBSTORE_FLAG_EXCL, NULL, FIND_TIMEOUT_USEC); if (!dest_blob) { LOGERROR("[%s] couldn't create the destination blob for bundling (%s)", instance->instanceId, id); ret = EUCA_PERMISSION_ERROR; goto error; } if (strlen(dest_blob->blocks_path) > 0) snprintf(blockPath, EUCA_MAX_PATH, "%s", dest_blob->blocks_path); // copy blob (will 'dd' eventually) if (blockblob_copy(src_blob, 0, dest_blob, 0, src_blob->size_bytes) != EUCA_OK) { LOGERROR("[%s] couldn't copy block blob for bundling (%s)", instance->instanceId, id); ret = EUCA_IO_ERROR; goto error; } error: // free the search results for (bm = matches; bm; bm = next) { next = bm->next; EUCA_FREE(bm); } // Close our blockblobs BLOCKBLOB_CLOSE(src_blob); BLOCKBLOB_CLOSE(dest_blob); return (ret); }
//! //! Destroy the backing store for a given instance //! //! @param[in] instance the instance identifier for which we will destroy the backing store //! @param[in] do_destroy_files set to TRUE if we need to destroy the content otherwise set to FALSE. //! //! @return EUCA_OK on success //! //! @pre The instance parameter must not be NULL and do_destroy_files must be a valid boolean. //! //! @note //! int destroy_instance_backing(ncInstance * instance, boolean do_destroy_files) { int i = 0; int ret = EUCA_OK; char path[EUCA_MAX_PATH] = ""; char work_regex[1024] = ""; // {userId}/{instanceId}/.* char scURL[512] = ""; ncVolume *volume = NULL; virtualMachine *vm = &(instance->params); virtualBootRecord *vbr = NULL; if (get_localhost_sc_url(scURL) != EUCA_OK || strlen(scURL) == 0) { LOGWARN("[%s] could not obtain SC URL (is SC enabled?)\n", instance->instanceId); scURL[0] = '\0'; } // find and detach iSCSI targets, if any for (i = 0; ((i < EUCA_MAX_VBRS) && (i < vm->virtualBootRecordLen)); i++) { vbr = &(vm->virtualBootRecord[i]); if (vbr->locationType == NC_LOCATION_SC) { if (disconnect_ebs_volume (scURL, localhost_config.use_ws_sec, localhost_config.ws_sec_policy_file, vbr->resourceLocation, vbr->preparedResourceLocation, localhost_config.ip, localhost_config.iqn) != 0) { LOGERROR("[%s] failed to disconnect volume attached to '%s'\n", instance->instanceId, vbr->backingPath); } } } // there may be iSCSI targets for volumes if instance disappeared or was migrated for (i = 0; i < EUCA_MAX_VOLUMES; ++i) { ncVolume *volume = &instance->volumes[i]; if (!is_volume_used(volume)) continue; if (disconnect_ebs_volume (scURL, localhost_config.use_ws_sec, localhost_config.ws_sec_policy_file, volume->attachmentToken, volume->connectionString, localhost_config.ip, localhost_config.iqn) != 0) { LOGERROR("[%s][%s] failed to disconnect volume\n", instance->instanceId, volume->volumeId); } } // see if instance directory is there (sometimes startup fails before it is created) set_path(path, sizeof(path), instance, NULL); if (check_path(path)) return (ret); // to ensure that we are able to delete all blobs, we chown files back to 'eucalyptus' // (e.g., libvirt on KVM on Maverick chowns them to libvirt-qemu while // VM is running and then chowns them to root after termination) { DIR *dir = NULL; if ((dir = opendir(path)) == NULL) { return (-1); } struct dirent *dir_entry; while ((dir_entry = readdir(dir)) != NULL) { char *entry_name = dir_entry->d_name; if (!strcmp(".", entry_name) || !strcmp("..", entry_name)) continue; // get the path of the directory item char entry_path[BLOBSTORE_MAX_PATH]; snprintf(entry_path, sizeof(entry_path), "%s/%s", path, entry_name); if (diskutil_ch(entry_path, EUCALYPTUS_ADMIN, NULL, BACKING_FILE_PERM)) { LOGWARN("[%s] failed to chown files before cleanup\n", instance->instanceId); } } closedir(dir); } if (do_destroy_files) { set_id2(instance, "/.*", work_regex, sizeof(work_regex)); if (blobstore_delete_regex(work_bs, work_regex) == -1) { LOGERROR("[%s] failed to remove some artifacts in %s\n", instance->instanceId, path); } for (i = 0; i < EUCA_MAX_VOLUMES; ++i) { volume = &instance->volumes[i]; snprintf(path, sizeof(path), EUCALYPTUS_VOLUME_XML_PATH_FORMAT, instance->instancePath, volume->volumeId); unlink(path); } // delete all non-blob files in the directory if (blobstore_delete_nonblobs(work_bs, instance->instancePath) < 0) { LOGWARN("[%s] failed to delete some non-blob files under %s\n", instance->instanceId, instance->instancePath); } } // Finally try to remove the directory. If either the user or our code introduced // any new files, this last step will fail. set_path(path, sizeof(path), instance, NULL); if (rmdir(path) && do_destroy_files) { LOGWARN("[%s] failed to remove backing directory %s\n", instance->instanceId, path); } return (ret); }
static void ripper_init_eventids2(void) { #define set_id2(name) ripper_scanner_ids.ripper_id_##name = rb_intern_const("on_"#name) set_id2(backref); set_id2(backtick); set_id2(comma); set_id2(const); set_id2(cvar); set_id2(embexpr_beg); set_id2(embexpr_end); set_id2(embvar); set_id2(float); set_id2(gvar); set_id2(ident); set_id2(imaginary); set_id2(int); set_id2(ivar); set_id2(kw); set_id2(lbrace); set_id2(lbracket); set_id2(lparen); set_id2(nl); set_id2(op); set_id2(period); set_id2(rbrace); set_id2(rbracket); set_id2(rparen); set_id2(semicolon); set_id2(symbeg); set_id2(tstring_beg); set_id2(tstring_content); set_id2(tstring_end); set_id2(words_beg); set_id2(qwords_beg); set_id2(qsymbols_beg); set_id2(symbols_beg); set_id2(words_sep); set_id2(rational); set_id2(regexp_beg); set_id2(regexp_end); set_id2(label); set_id2(label_end); set_id2(tlambda); set_id2(tlambeg); set_id2(ignored_nl); set_id2(comment); set_id2(embdoc_beg); set_id2(embdoc); set_id2(embdoc_end); set_id2(sp); set_id2(heredoc_beg); set_id2(heredoc_end); set_id2(__end__); set_id2(CHAR); }
int destroy_instance_backing (ncInstance * instance, int do_destroy_files) { int ret = OK; int total_prereqs = 0; char path [MAX_PATH]; virtualMachine * vm = &(instance->params); // find and detach iSCSI targets, if any for (int i=0; i<EUCA_MAX_VBRS && i<vm->virtualBootRecordLen; i++) { virtualBootRecord * vbr = &(vm->virtualBootRecord[i]); if (vbr->locationType==NC_LOCATION_IQN) { if (disconnect_iscsi_target (vbr->resourceLocation)) { logprintfl(EUCAERROR, "[%s] error: failed to disconnect iSCSI target attached to %s\n", instance->instanceId, vbr->backingPath); } } } // see if instance directory is there (sometimes startup fails before it is created) set_path (path, sizeof (path), instance, NULL); if (check_path (path)) return ret; // to ensure that we are able to delete all blobs, we chown files back to 'eucalyptus' // (e.g., libvirt on KVM on Maverick chowns them to libvirt-qemu while // VM is running and then chowns them to root after termination) set_path (path, sizeof (path), instance, "*"); if (diskutil_ch (path, EUCALYPTUS_ADMIN, NULL, BACKING_FILE_PERM)) { logprintfl (EUCAWARN, "[%s] error: failed to chown files before cleanup\n", instance->instanceId); } if (do_destroy_files) { char work_regex [1024]; // {userId}/{instanceId}/.* set_id2 (instance, "/.*", work_regex, sizeof (work_regex)); if (blobstore_delete_regex (work_bs, work_regex) == -1) { logprintfl (EUCAERROR, "[%s] error: failed to remove some artifacts in %s\n", instance->instanceId, path); } // remove the known leftover files unlink (instance->xmlFilePath); unlink (instance->libvirtFilePath); unlink (instance->consoleFilePath); if (strlen (instance->floppyFilePath)) { unlink (instance->floppyFilePath); } set_path (path, sizeof (path), instance, "instance.checkpoint"); unlink (path); for (int i=0; i < EUCA_MAX_VOLUMES; ++i) { ncVolume * volume = &instance->volumes[i]; snprintf (path, sizeof (path), EUCALYPTUS_VOLUME_XML_PATH_FORMAT, instance->instancePath, volume->volumeId); unlink (path); } // bundle instance will leave additional files // let's delete every file in the directory struct dirent **files; int n = scandir(instance->instancePath, &files, 0, alphasort); char toDelete[MAX_PATH]; if (n>0){ while (n--) { struct dirent *entry = files[n]; if( entry !=NULL && strncmp(entry->d_name, ".",1)!=0 && strncmp(entry->d_name, "..", 2)!=0){ snprintf(toDelete, MAX_PATH, "%s/%s", instance->instancePath, entry->d_name); unlink(toDelete); free(entry); } } free(files); } } // Finally try to remove the directory. // If either the user or our code introduced // any new files, this last step will fail. set_path (path, sizeof (path), instance, NULL); if (rmdir (path) && do_destroy_files) { logprintfl (EUCAWARN, "[%s] warning: failed to remove backing directory %s\n", instance->instanceId, path); } return ret; }
int clone_bundling_backing (ncInstance *instance, const char* filePrefix, char* blockPath) { char path[MAX_PATH]; char work_regex [1024]; char id [BLOBSTORE_MAX_PATH]; char workPath [BLOBSTORE_MAX_PATH]; int ret = OK; int found=-1; blockblob *src_blob = NULL, *dest_blob = NULL; blockblob_meta *matches = NULL; set_path (path, sizeof (path), instance, NULL); set_id2 (instance, "/.*", work_regex, sizeof (work_regex)); if( (found=blobstore_search (work_bs, work_regex, &matches) <= 0 ) ) { logprintfl (EUCAERROR, "[%s] error: failed to find blob in %s %d\n", instance->instanceId, path, found); return ERROR; } for (blockblob_meta * bm = matches; bm; bm=bm->next) { blockblob * bb = blockblob_open (work_bs, bm->id, 0, 0, NULL, FIND_TIMEOUT_USEC); if (bb!=NULL && bb->snapshot_type == BLOBSTORE_SNAPSHOT_DM && strstr(bb->blocks_path,"emi-") != NULL) { // root image contains substr 'emi-' src_blob = bb; break; } else if (bb!=NULL) { blockblob_close(bb); } } if (!src_blob) { logprintfl (EUCAERROR, "[%s] couldn't find the blob to clone from", instance->instanceId); goto error; } set_id (instance, NULL, workPath, sizeof (workPath)); snprintf (id, sizeof(id), "%s/%s", workPath, filePrefix); // open destination blob dest_blob = blockblob_open (work_bs, id, src_blob->size_bytes, BLOBSTORE_FLAG_CREAT | BLOBSTORE_FLAG_EXCL, NULL, FIND_TIMEOUT_USEC); if (!dest_blob) { logprintfl (EUCAERROR, "[%s] couldn't create the destination blob for bundling (%s)", instance->instanceId, id); goto error; } if (strlen (dest_blob->blocks_path) > 0) snprintf (blockPath, MAX_PATH, "%s", dest_blob->blocks_path); // copy blob (will 'dd' eventually) if (blockblob_copy (src_blob, 0, dest_blob, 0, src_blob->size_bytes) != OK) { logprintfl (EUCAERROR, "[%s] couldn't copy block blob for bundling (%s)", instance->instanceId, id); goto error; } goto free; error: ret = ERROR; free: // free the search results for (blockblob_meta * bm = matches; bm;) { blockblob_meta * next = bm->next; free (bm); bm = next; } if(src_blob) blockblob_close(src_blob); if(dest_blob) blockblob_close(dest_blob); return ret; }