示例#1
0
文件: vz.c 项目: OpenVZ/libvzctl
int vzctl2_get_env_status_info(struct vzctl_env_handle *h,
		vzctl_env_status_t *status, int mask)
{
	int ret, exists = 0;
	char path[512];
	const char *ve_private = h->env_param->fs->ve_private;
	const char *ve_root = h->env_param->fs->ve_root;

	memset(status, 0, sizeof(vzctl_env_status_t));

	/* get running state */
	if (mask & ENV_STATUS_RUNNING) {
		if (is_env_run(h) == 1) {
			status->mask |= ENV_STATUS_RUNNING;
			get_env_ops()->env_get_cpt_state(h, &status->mask);
		}
	}
	/* do exit if only running status requested */
	if (mask == ENV_STATUS_RUNNING)
		return 0;

	if ((ret = check_var(ve_private, "VE_PRIVATE not set")))
		return ret;

	vzctl2_get_env_conf_path(EID(h), path, sizeof(path));
	if (stat_file(path) == 1 && stat_file(ve_private) == 1) {
		if (mask & ENV_SKIP_OWNER)
			exists = 1;
		else if (vzctl2_check_owner(ve_private) == 0)
			exists = 1;
	}

	if ((mask & ENV_STATUS_EXISTS) && exists)
		status->mask |= ENV_STATUS_EXISTS;

	/* get mounted state */
	if (mask & (ENV_STATUS_MOUNTED | ENV_STATUS_MOUNTED_FAST) && exists) {
		if ((ret = check_var(ve_root, "VE_ROOT not set")))
			return ret;
		ret = (mask & ENV_STATUS_MOUNTED) ? vzctl2_env_is_mounted(h) :
					 fs_is_mounted_check_by_target(ve_root);
		if (ret == 1)
			status->mask |= ENV_STATUS_MOUNTED;
	}
	/* get suspended state */
	if ((mask & ENV_STATUS_SUSPENDED) && exists && !(status->mask & ENV_STATUS_RUNNING)) {
		vzctl2_get_dump_file(h, path, sizeof(path));
		if (stat_file(path) == 1)
			status->mask |= ENV_STATUS_SUSPENDED;
	}
	read_env_transition(EID(h), h->env_param->opts->lockdir, status);

	return 0;
}
示例#2
0
/* rt_OneStep is called from a timer interrupt service routine. It is called at
 * the base-rate of the model.
 */
void rt_OneStep(MPC555_IRQ_LEVEL level)
{
  /* Clear the interrupt that triggered this function */
  ClearPitIRQ;

  /***********************************************
   * Check if base-rate step time is too fast    *
   ***********************************************/
  if (OverrunFlags[0] > BASE_RATE_MAX_OVERRUNS) {
    rtmSetErrorStatus(exp03_M, "Overrun");
  }

  /*************************************************
   * Check if an error status has been set *
   * by an overrun or by the generated code.       *
   *************************************************/
  if (rtmGetErrorStatus(exp03_M) != NULL) {
    return;
  }

  /***********************************************
   * Increment the overruns flag
   ***********************************************/
  if (OverrunFlags[0]++) {
    return;
  }

  while (OverrunFlags[0] > 0 ) {
    /* Re-enable interrupts here */
    EIE();

    /* Set model inputs here */

    /**************
     * Step model *
     **************/
    exp03_step();

    /* Get model outputs here */

    /* Get model outputs here */

    /* Service Watchdog Timer */
    SERVICE_WATCHDOG_TIMER;

    /* Disable interrupts */
    EID();

    /**************************
     * Decrement overrun flag *
     **************************/
    OverrunFlags[0]--;
  }
}
示例#3
0
文件: vz.c 项目: OpenVZ/libvzctl
static int unregister_env_conf(struct vzctl_env_handle *h)
{
	char veconf[PATH_MAX];

	get_env_conf_lockfile(h, veconf, sizeof(veconf));
	unlink(veconf);

	vzctl2_get_env_conf_path(EID(h), veconf, sizeof(veconf));
	if (unlink(veconf) && errno != ENOENT)
		return vzctl_err(VZCTL_E_SYSTEM, errno, "Failed to unlink %s", veconf);

	return 0;
}
void
BipartiteGraph::ConstructBG(Matrix& m){

  num_agents = m.size();
  num_tasks = m[0].size();
  bg_matrix = m;

  agents.resize(num_agents);
  tasks.resize(num_tasks);
  //bg_matrix.resize(num_agents, num_tasks);
  bg_matrix.resize(num_agents);
  for(unsigned int i = 0; i<num_agents; i++)
    bg_matrix[i].resize(num_tasks);

  //assign task VID and assign label to be 0;
  int _vid = 0;
  for(vector<Vertex>::iterator itr = tasks.begin(); itr != tasks.end(); itr++){
    itr->SetVID(_vid++);
    itr->SetObj("TASK");
    itr->SetLabel(0);
    itr->path.clear();
  }

  //assign agent VID and assign label to be max;
  _vid = 0;
  for(vector<Vertex>::iterator itr = agents.begin(); itr != agents.end(); itr++){
    itr->SetVID(_vid++);
    itr->SetObj("AGENT");
    itr->SetLabel(this->GetMaxWeightEdge(*itr).GetWeight());
    itr->path.clear();
  }
  
  //init all edges
  for(unsigned int i=0; i<num_agents; i++)
    for(unsigned int j=0; j<num_tasks; j++)
      bg_matrix[i][j].SetEID(EID(i,j));

}
示例#5
0
/*
 * main application method
 */
int main( int argc, char** argv )
{
	// catch process signals
	ibrcommon::SignalHandler sighandler(sighandler_func);
	sighandler.handle(SIGINT);
	sighandler.handle(SIGTERM);
#ifndef __WIN32__
	sighandler.handle(SIGUSR1);
#endif

	// configration object
	config_t conf;

	// read the configuration
	read_configuration(argc, argv, conf);

	init_logger(conf);

	// initialize sighandler after possible exit call
	sighandler.initialize();

	// init working directory
	if (conf.workdir.length() > 0)
	{
		ibrcommon::File blob_path(conf.workdir);

		if (blob_path.exists())
		{
			ibrcommon::BLOB::changeProvider(new ibrcommon::FileBLOBProvider(blob_path), true);
		}
	}

	// backoff for reconnect
	unsigned int backoff = 2;

	ibrcommon::File outbox_file(conf.outbox);

	// create new file lists
	fileset new_files, prev_files, deleted_files, files_to_send;
	filelist observed_files;
	hashlist sent_hashes;

	// observed root file
	io::ObservedFile root(ibrcommon::File("/"));

#ifdef HAVE_LIBTFFS
	io::FatImageReader *imagereader = NULL;
#endif

	if (outbox_file.exists() && !outbox_file.isDirectory())
	{
#ifdef HAVE_LIBTFFS
		conf.fat = true;
		imagereader = new io::FatImageReader(conf.outbox);
		const io::FATFile fat_root(*imagereader, conf.path);
		root = io::ObservedFile(fat_root);
#else
		IBRCOMMON_LOGGER_TAG(TAG,error) << "ERROR: image-file provided, but this tool has been compiled without libtffs support!" << IBRCOMMON_LOGGER_ENDL;
		return -1;
#endif
	}
	else
	{
		if (!outbox_file.exists()) {
			ibrcommon::File::createDirectory(outbox_file);
		}
		root = io::ObservedFile(outbox_file);
	}

	IBRCOMMON_LOGGER_TAG(TAG,info) << "-- dtnoutbox --" << IBRCOMMON_LOGGER_ENDL;

	// loop, if no stop if requested
	while (_running)
	{
		try
		{
			// Create a stream to the server using TCP.
			ibrcommon::vaddress addr("localhost", 4550);
			ibrcommon::socketstream conn(new ibrcommon::tcpsocket(addr));

			// Initiate a client for synchronous receiving
			dtn::api::Client client(conf.name, conn, dtn::api::Client::MODE_SENDONLY);

			// Connect to the server. Actually, this function initiate the
			// stream protocol by starting the thread and sending the contact header.
			client.connect();

			// reset backoff if connected
			backoff = 2;

			// check the connection
			while (_running)
			{
				// get all files
				fileset current_files;
				root.findFiles(current_files);

				// determine deleted files
				fileset deleted_files;
				std::set_difference(prev_files.begin(), prev_files.end(), current_files.begin(), current_files.end(), std::inserter(deleted_files, deleted_files.begin()));

				// remove deleted files from observation
				for (fileset::const_iterator iter = deleted_files.begin(); iter != deleted_files.end(); ++iter)
				{
					const io::ObservedFile &deletedFile = (*iter);

					// remove references in the sent_hashes
					for (hashlist::iterator hash_it = sent_hashes.begin(); hash_it != sent_hashes.end(); /* blank */) {
						if ((*hash_it).getPath() == deletedFile.getFile().getPath()) {
							sent_hashes.erase(hash_it++);
						} else {
							++hash_it;
						}
					}

					// remove from observed files
					observed_files.remove(deletedFile);

					// output
					IBRCOMMON_LOGGER_TAG(TAG,info) << "file removed: " << deletedFile.getFile().getBasename() << IBRCOMMON_LOGGER_ENDL;
				}

				// determine new files
				fileset new_files;
				std::set_difference(current_files.begin(), current_files.end(), prev_files.begin(), prev_files.end(), std::inserter(new_files, new_files.begin()));

				// add new files to observation
				for (fileset::const_iterator iter = new_files.begin(); iter != new_files.end(); ++iter)
				{
					const io::ObservedFile &of = (*iter);

					int reg_ret = regexec(&conf.regex, of.getFile().getBasename().c_str(), 0, NULL, 0);
					if (!reg_ret && !conf.invert)
						continue;
					if (reg_ret && conf.invert)
						continue;

					// print error message, if regex error occurs
					if (reg_ret && reg_ret != REG_NOMATCH)
					{
							char msgbuf[100];
							regerror(reg_ret,&conf.regex,msgbuf,sizeof(msgbuf));
							IBRCOMMON_LOGGER_TAG(TAG,info) << "ERROR: regex match failed : " << std::string(msgbuf) << IBRCOMMON_LOGGER_ENDL;
					}

					// add new file to the observed set
					observed_files.push_back(of);

					// log output
					IBRCOMMON_LOGGER_TAG(TAG, info) << "file found: " << of.getFile().getBasename() << IBRCOMMON_LOGGER_ENDL;
				}

				// store current files for the next round
				prev_files.clear();
				prev_files.insert(current_files.begin(), current_files.end());

				IBRCOMMON_LOGGER_TAG(TAG, notice)
						<< "file statistics: "
						<< observed_files.size() << " observed, "
						<< deleted_files.size() << " deleted, "
						<< new_files.size() << " new"
						<< IBRCOMMON_LOGGER_ENDL;

				// find files to send, create std::list
				files_to_send.clear();


				IBRCOMMON_LOGGER_TAG(TAG, notice) << "updating observed files:" << IBRCOMMON_LOGGER_ENDL;
				for (filelist::iterator iter = observed_files.begin(); iter != observed_files.end(); ++iter)
				{
					io::ObservedFile &of = (*iter);

					// tick and update all files
					of.update();

					if (of.getStableCounter() > conf.rounds)
					{
						if (sent_hashes.find(of.getHash()) == sent_hashes.end())
						{
							sent_hashes.insert(of.getHash());
							files_to_send.insert(*iter);
						}
					}

					IBRCOMMON_LOGGER_TAG(TAG, notice)
						<< "\t"
						<< of.getFile().getBasename() << ": "
						<< of.getStableCounter()
						<< IBRCOMMON_LOGGER_ENDL;
				}

				if (!files_to_send.empty())
				{
					std::stringstream ss;
					for (fileset::const_iterator it = files_to_send.begin(); it != files_to_send.end(); ++it) {
						ss << (*it).getFile().getBasename() << " ";
					}
					IBRCOMMON_LOGGER_TAG("dtnoutbox",info) << "files sent: " << ss.str() << IBRCOMMON_LOGGER_ENDL;

					try {
						// create a blob
						ibrcommon::BLOB::Reference blob = ibrcommon::BLOB::create();

						// write files into BLOB while it is locked
						{
							ibrcommon::BLOB::iostream stream = blob.iostream();
							io::TarUtils::write(*stream, root, files_to_send);
						}

						// create a new bundle
						dtn::data::EID destination = EID(conf.destination);

						// create a new bundle
						dtn::data::Bundle b;

						// set destination
						b.destination = destination;

						// add payload block using the blob
						b.push_back(blob);

						// set destination address to non-singleton, if configured
						if (conf.bundle_group)
							b.set(dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON, false);

						// send the bundle
						client << b;
						client.flush();
					} catch (const ibrcommon::IOException &e) {
						IBRCOMMON_LOGGER_TAG(TAG,error) << "send failed: " << e.what() << IBRCOMMON_LOGGER_ENDL;
					}
				}

				// wait defined seconds
				ibrcommon::MutexLock l(_wait_cond);
				IBRCOMMON_LOGGER_TAG(TAG, notice) << conf.interval <<" ms wait" << IBRCOMMON_LOGGER_ENDL;
				while (!_wait_abort && _running) {
					_wait_cond.wait(conf.interval);
				}
				_wait_abort = false;
			}

			// clean up regex
			regfree(&conf.regex);

			// close the client connection
			client.close();

			// close the connection
			conn.close();

		}
		catch (const ibrcommon::socket_exception&)
		{
			if (_running)
			{
				IBRCOMMON_LOGGER_TAG(TAG,error) << "Connection to bundle daemon failed. Retry in " << backoff << " seconds." << IBRCOMMON_LOGGER_ENDL;
				ibrcommon::Thread::sleep(backoff * 1000);

				// if backoff < 10 minutes
				if (backoff < 600)
				{
					// set a new backoff
					backoff = backoff * 2;
				}
			}
		}
		catch (const ibrcommon::IOException&)
		{
			if (_running)
			{
				IBRCOMMON_LOGGER_TAG(TAG,error) << "Connection to bundle daemon failed. Retry in " << backoff << " seconds." << IBRCOMMON_LOGGER_ENDL;
				ibrcommon::Thread::sleep(backoff * 1000);

				// if backoff < 10 minutes
				if (backoff < 600)
				{
					// set a new backoff
					backoff = backoff * 2;
				}
			}
		}
		catch (const std::exception&) { };
	}

	// clear observed files
	observed_files.clear();

#ifdef HAVE_LIBTFFS
	// clean-up
	if (imagereader != NULL) delete imagereader;
#endif

	return (EXIT_SUCCESS);
}
示例#6
0
		void TCPConnection::run() throw ()
		{
			try {
				if (_socket == NULL) {
					// connect to the peer
					connect();
				} else {
					// accept remote connection as server
					__setup_socket(_socket, true);
				}

				TCPConnection::safe_streamconnection sc = getProtocolStream();
				std::iostream &stream = (*sc);

				// do the handshake
				(*sc).handshake(dtn::core::BundleCore::local, _timeout, _flags);

				// start the sender
				_sender.start();

				// start keepalive sender
				_keepalive_sender.start();

				// create a deserializer for next bundle
				dtn::data::DefaultDeserializer deserializer(stream, dtn::core::BundleCore::getInstance());

				while (!(*sc).eof())
				{
					try {
						// create a new empty bundle
						dtn::data::Bundle bundle;

						// check if the stream is still good
						if (!stream.good()) throw ibrcommon::IOException("stream went bad");

						// enable/disable fragmentation support according to the contact header.
						deserializer.setFragmentationSupport(_peer._flags.getBit(dtn::streams::StreamContactHeader::REQUEST_FRAGMENTATION));

						// read the bundle (or the fragment if fragmentation is enabled)
						deserializer >> bundle;

						// check the bundle
						if ( ( bundle.destination == EID() ) || ( bundle.source == EID() ) )
						{
							// invalid bundle!
							throw dtn::data::Validator::RejectedException("destination or source EID is null");
						}

						// raise default bundle received event
						dtn::net::BundleReceivedEvent::raise(_peer._localeid, bundle, false);
					}
					catch (const dtn::data::Validator::RejectedException &ex)
					{
						// bundle rejected
						rejectTransmission();

						// display the rejection
						IBRCOMMON_LOGGER_TAG(TCPConnection::TAG, warning) << "bundle has been rejected: " << ex.what() << IBRCOMMON_LOGGER_ENDL;
					}
					catch (const dtn::InvalidDataException &ex) {
						// bundle rejected
						rejectTransmission();

						// display the rejection
						IBRCOMMON_LOGGER_TAG(TCPConnection::TAG, warning) << "invalid bundle-data received: " << ex.what() << IBRCOMMON_LOGGER_ENDL;
					}

					yield();
				}
			} catch (const ibrcommon::ThreadException &ex) {
				IBRCOMMON_LOGGER_TAG(TCPConnection::TAG, error) << "failed to start thread in TCPConnection\n" << ex.what() << IBRCOMMON_LOGGER_ENDL;
				try {
					(*getProtocolStream()).shutdown(dtn::streams::StreamConnection::CONNECTION_SHUTDOWN_ERROR);
				} catch (const ibrcommon::Exception&) {};
			} catch (const std::exception &ex) {
				IBRCOMMON_LOGGER_DEBUG_TAG(TCPConnection::TAG, 10) << "run(): std::exception (" << ex.what() << ")" << IBRCOMMON_LOGGER_ENDL;
				try {
					(*getProtocolStream()).shutdown(dtn::streams::StreamConnection::CONNECTION_SHUTDOWN_ERROR);
				} catch (const ibrcommon::Exception&) {};
			}
		}
示例#7
0
		bool EID::sameHost(const std::string& other) const
		{
			return ( EID(other) == getNode() );
		}
示例#8
0
		EID EID::operator+(const std::string& suffix) const
		{
			return EID(getString() + suffix);
		}
示例#9
0
		bool EID::operator==(const std::string &other) const
		{
			return ((*this) == EID(other));
		}
示例#10
0
char *subcmd_name(struct mbcmd *mb)
{
	unsigned char cmd_h = mb->cmd_h;
	unsigned char cmd_l = mb->cmd_l;
	char *s;

	switch (cmd_h) {
	case MBCMD(RUNLEVEL):
		s = (cmd_l == RLCMD(USER))     ? "USER":
		    (cmd_l == RLCMD(SUPER))    ? "SUPER":
		    (cmd_l == RLCMD(RECOVERY)) ? "RECOVERY":
		    NULL;
		break;
	case MBCMD(PM):
		s = (cmd_l == PMCMD(DISABLE)) ? "DISABLE":
		    (cmd_l == PMCMD(ENABLE))  ? "ENABLE":
		    NULL;
		break;
	case MBCMD(DSPCFG):
		{
			unsigned char cfgc = cmd_l & 0x7f;
			s = (cfgc == CFGCMD(REQ))     ? "REQ":
			    (cfgc == CFGCMD(SYSADRH)) ? "SYSADRH":
			    (cfgc == CFGCMD(SYSADRL)) ? "SYSADRL":
			    (cfgc == CFGCMD(ABORT))   ? "ABORT":
			    (cfgc == CFGCMD(PROTREV)) ? "PROTREV":
			    NULL;
			break;
		}
	case MBCMD(REGRW):
		s = (cmd_l == REGCMD(MEMR)) ? "MEMR":
		    (cmd_l == REGCMD(MEMW)) ? "MEMW":
		    (cmd_l == REGCMD(IOR))  ? "IOR":
		    (cmd_l == REGCMD(IOW))  ? "IOW":
		    (cmd_l == REGCMD(DATA)) ? "DATA":
		    NULL;
		break;
	case MBCMD(GETVAR):
	case MBCMD(SETVAR):
		s = (cmd_l == VICMD(ICRMASK))  ? "ICRMASK":
		    (cmd_l == VICMD(LOADINFO)) ? "LOADINFO":
		    NULL;
		break;
	case MBCMD(ERR):
		s = (cmd_l == EID(BADTID))     ? "BADTID":
		    (cmd_l == EID(BADTCN))     ? "BADTCN":
		    (cmd_l == EID(BADBID))     ? "BADBID":
		    (cmd_l == EID(BADCNT))     ? "BADCNT":
		    (cmd_l == EID(NOTLOCKED))  ? "NOTLOCKED":
		    (cmd_l == EID(STVBUF))     ? "STVBUF":
		    (cmd_l == EID(BADADR))     ? "BADADR":
		    (cmd_l == EID(BADTCTL))    ? "BADTCTL":
		    (cmd_l == EID(BADPARAM))   ? "BADPARAM":
		    (cmd_l == EID(FATAL))      ? "FATAL":
		    (cmd_l == EID(NOMEM))      ? "NOMEM":
		    (cmd_l == EID(NORES))      ? "NORES":
		    (cmd_l == EID(IPBFULL))    ? "IPBFULL":
		    (cmd_l == EID(TASKNOTRDY)) ? "TASKNOTRDY":
		    (cmd_l == EID(TASKBSY))    ? "TASKBSY":
		    (cmd_l == EID(TASKERR))    ? "TASKERR":
		    (cmd_l == EID(BADCFGTYP))  ? "BADCFGTYP":
		    (cmd_l == EID(DEBUG))      ? "DEBUG":
		    (cmd_l == EID(BADSEQ))     ? "BADSEQ":
		    (cmd_l == EID(BADCMD))     ? "BADCMD":
		    NULL;
		break;
	default:
		s = NULL;
	}

	return s;
}
示例#11
0
文件: vz.c 项目: OpenVZ/libvzctl
int vzctl2_env_unreg(struct vzctl_env_handle *h, int flags)
{
	char buf[STR_SIZE];
	char host[STR_SIZE];
	int ret;
	const char *ve_root;
	const char *ve_private = h->env_param->fs->ve_private;

	/* preserve compatibility
	 * VZ_REG_SKIP_HA_CLUSTER is alias for VZ_REG_SKIP_CLUSTER
	 */
	if (flags & VZ_REG_SKIP_HA_CLUSTER)
		flags |= VZ_REG_SKIP_CLUSTER;

	if (is_env_run(h))
		return vzctl_err(VZCTL_E_ENV_RUN, 0,
			"Container is running, Stop Container before proceeding.");

	if (access(ve_private, F_OK) && errno == ENOENT) {
		ret = unregister_env_conf(h);
		if (ret)
			return ret;
		goto out;
	}

	if (vzctl2_env_layout_version(ve_private) < VZCTL_LAYOUT_4)
		return 0;

	ret = vzctl_check_owner_quiet(ve_private, buf, sizeof(buf), host, sizeof(host));
	if (ret == VZCTL_E_ENV_MANAGE_DISABLED) {
		logger(0, 0, "Owner check failed on the server '%s':"
				" Container (%s) is registered for '%s'",
				buf, ve_private, host);
		ret = unregister_env_conf(h);
		if (ret)
			return ret;
		goto out;
	} else if (ret)
		return ret;

	ve_root = h->env_param->fs->ve_root;
	if (ve_root != NULL && vzctl2_env_is_mounted(h) == 1) {
		if (vzctl2_env_umount(h, 0))
			return vzctl_err(VZCTL_E_FS_MOUNTED, 0,
				"Container is mounted, Unmount Container "
				"before proceeding.");
	}

	if (!(flags & VZ_UNREG_PRESERVE)) {
		/* Remove VEID from /ve_private/ve.conf */
		vzctl2_env_set_param(h, "VEID", NULL);
		if (vzctl2_env_save(h))
			return VZCTL_E_UNREGISTER;

		/* Remove VE_PRIVATE/.owner */
		snprintf(buf, sizeof(buf), "%s/" VZCTL_VE_OWNER, ve_private);
		unlink(buf);
	}

	/* cleanup name */
	if (h->env_param->name->name != NULL) {
		char name_path[PATH_MAX];
		char veconf[PATH_MAX];

		snprintf(veconf, sizeof(veconf), "%s/" VZCTL_VE_CONF, ve_private);
		snprintf(name_path, sizeof(name_path), ENV_NAME_DIR "%s",
				h->env_param->name->name);
		if (is_same_file(name_path, veconf))
			unlink(name_path);
	}

	/* Remove /etc/vz/conf/VEID.conf */
	unregister_env_conf(h);

	if (!(flags & VZ_REG_SKIP_CLUSTER) &&
			is_shared_fs(ve_private) &&
			shaman_del_resource(EID(h)))
		logger(0, 0,"Warning: Failed to unregister the Container on HA cluster");

out:
	vzctl2_destroy_net_stat(h, 0);
	vzctl2_send_state_evt(EID(h), VZCTL_ENV_UNREGISTERED);
	logger(0, 0, "Container unregistered succesfully");

	return 0;
}