// check if a file was transferred. // if so, fullname will have full path in working directory. // Otherwise, fullname will be same to file_name bool VMType::isTransferedFile(const char* file_name, MyString& fullname) { if( !file_name || m_initial_working_files.isEmpty() ) { return false; } // check if this file was transferred. MyString tmp_fullname; if( filelist_contains_file(file_name, &m_initial_working_files, true) ) { // this file was transferred. // make full path with workingdir tmp_fullname.formatstr("%s%c%s", m_workingpath.Value(), DIR_DELIM_CHAR, condor_basename(file_name)); fullname = tmp_fullname; return true; }else { // this file is not transferred if( fullpath(file_name) == false ) { vmprintf(D_ALWAYS, "Warning: The file(%s) doesn't have " "full path even though it is not " "transferred\n", file_name); } fullname = file_name; return false; } return false; }
bool VirshType::findCkptConfigAndSuspendFile(MyString &vmconfig, MyString &suspendfile) { if( m_transfer_intermediate_files.isEmpty() ) { return false; } vmconfig = ""; suspendfile = ""; MyString tmpconfig; MyString tmpsuspendfile; if( filelist_contains_file( XEN_CONFIG_FILE_NAME, &m_transfer_intermediate_files, true) ) { // There is a vm config file for checkpointed files tmpconfig.formatstr("%s%c%s",m_workingpath.Value(), DIR_DELIM_CHAR, XEN_CONFIG_FILE_NAME); } MyString tmp_name; makeNameofSuspendfile(tmp_name); if( filelist_contains_file(tmp_name.Value(), &m_transfer_intermediate_files, true) ) { // There is a suspend file that was created during vacate tmpsuspendfile = tmp_name; if( check_vm_read_access_file(tmpsuspendfile.Value(), true) == false) { return false; } } if( (tmpconfig.Length() > 0) && (tmpsuspendfile.Length() > 0 )) { // check if the timestamp of suspend file is same to // that of writable disk files // If timestamp differs between suspend file and writable disk file, // it means that there was a crash. // So we need to restart this VM job from the beginning. if( checkCkptSuspendFile(tmpsuspendfile.Value()) ) { vmconfig = tmpconfig; suspendfile = tmpsuspendfile; return true; } } return false; }
void VMType::createInitialFileList() { MyString intermediate_files; StringList intermediate_file_list(NULL, ","); MyString input_files; StringList input_file_list(NULL, ","); m_initial_working_files.clearAll(); m_transfer_intermediate_files.clearAll(); m_transfer_input_files.clearAll(); // Create m_initial_working_files find_all_files_in_dir(m_workingpath.Value(), m_initial_working_files, true); // Read Intermediate files from Job classAd m_classAd.LookupString( ATTR_TRANSFER_INTERMEDIATE_FILES, intermediate_files); if( intermediate_files.IsEmpty() == false ) { intermediate_file_list.initializeFromString(intermediate_files.Value()); } // Read Input files from Job classAd m_classAd.LookupString( ATTR_TRANSFER_INPUT_FILES, input_files); if( input_files.IsEmpty() == false ) { input_file_list.initializeFromString(input_files.Value()); } // Create m_transfer_intermediate_files and m_transfer_input_files with fullpath. const char *tmp_file = NULL; m_initial_working_files.rewind(); while( (tmp_file = m_initial_working_files.next()) != NULL ) { // Create m_transfer_intermediate_files if( filelist_contains_file(tmp_file, &intermediate_file_list, true) ) { m_transfer_intermediate_files.append(tmp_file); } // Create m_transfer_input_files if( filelist_contains_file(tmp_file, &input_file_list, true) ) { m_transfer_input_files.append(tmp_file); } } }
bool VirshType::parseXenDiskParam(const char *format) { if( !format || (format[0] == '\0') ) { return false; } vmprintf(D_FULLDEBUG, "format = %s\n", format); StringList working_files; find_all_files_in_dir(m_workingpath.Value(), working_files, true); StringList disk_files(format, ","); if( disk_files.isEmpty() ) { return false; } disk_files.rewind(); const char *one_disk = NULL; while( (one_disk = disk_files.next() ) != NULL ) { // found a disk file StringList single_disk_file(one_disk, ":"); int iNumParams = single_disk_file.number(); if( iNumParams < 3 || iNumParams > 4 ) { return false; } single_disk_file.rewind(); // name of a disk file MyString dfile = single_disk_file.next(); if( dfile.IsEmpty() ) { return false; } dfile.trim(); const char* tmp_base_name = condor_basename(dfile.Value()); if( !tmp_base_name ) { return false; } // Every disk file for Virsh must have full path name MyString disk_file; if( filelist_contains_file(dfile.Value(), &working_files, true) ) { // file is transferred disk_file = m_workingpath; disk_file += DIR_DELIM_CHAR; disk_file += tmp_base_name; m_has_transferred_disk_file = true; }else { // file is not transferred. if( fullpath(dfile.Value()) == false) { vmprintf(D_ALWAYS, "File(%s) for xen disk " "should have full path name\n", dfile.Value()); return false; } disk_file = dfile; } // device name MyString disk_device = single_disk_file.next(); disk_device.trim(); disk_device.lower_case(); // disk permission MyString disk_perm = single_disk_file.next(); disk_perm.trim(); if( !strcasecmp(disk_perm.Value(), "w") || !strcasecmp(disk_perm.Value(), "rw")) { // check if this disk file is writable if( check_vm_write_access_file(disk_file.Value(), false) == false ) { vmprintf(D_ALWAYS, "xen disk image file('%s') cannot be modified\n", disk_file.Value()); return false; } }else { // check if this disk file is readable if( check_vm_read_access_file(disk_file.Value(), false) == false ) { vmprintf(D_ALWAYS, "xen disk image file('%s') cannot be read\n", disk_file.Value()); return false; } } XenDisk *newdisk = new XenDisk; ASSERT(newdisk); newdisk->filename = disk_file; newdisk->device = disk_device; newdisk->permission = disk_perm; // only when a format is specified do we check if (iNumParams == 4 ) { newdisk->format = single_disk_file.next(); newdisk->format.trim(); newdisk->format.lower_case(); } m_disk_list.Append(newdisk); } if( m_disk_list.Number() == 0 ) { vmprintf(D_ALWAYS, "No valid Virsh disk\n"); return false; } return true; }