Esempio n. 1
0
static int request_md5(int argc, char* argv[]) {
	int vmid = 0;
	size_t storage_size = 0;

	if(argc == 2) {
		if(!is_uint32(argv[1])) goto failure;
		vmid = parse_uint32(argv[1]);
	} else if(argc == 3) {
		if(!is_uint32(argv[1])) goto failure;
		vmid = parse_uint32(argv[1]);

		if(!is_uint32(argv[2])) goto failure;
		storage_size = parse_uint32(argv[2]);
	} else {
		goto failure;
	}

	// Request MD5 value & Register Response callback handler
	rpc_storage_md5(rpc, vmid, storage_size, response_md5, NULL);
	return 0;

failure:
	help();
	exit(1);
}
Esempio n. 2
0
static int upload(int argc, char** argv) {
	if(argc < 3 || argc > 4) {
		help();
		return -1;
	}

	if(!is_uint32(argv[1])) {
		help();
		return -2;
	}

	if(strlen(argv[2]) >= 256) {
		help();
		return -3;
	}

	if(argc == 4) {
		if(!is_uint32(argv[3])) {
			help();
			return -4;
		}
	}

	uint32_t vmid = parse_uint32(argv[1]);

	FileInfo* file_info = malloc(sizeof(FileInfo));
	if(file_info == NULL) {
		return -5;
	}
	memset(file_info, 0, sizeof(FileInfo));

	file_info->fd = open(argv[2], O_RDONLY);
	if(file_info->fd < 0) {
		free(file_info);

		return -6;
	}

	file_info->file_size = lseek(file_info->fd, 0, SEEK_END);
	lseek(file_info->fd, 0, SEEK_SET);
	file_info->offset = 0;

	if(argc == 4) {
		uint32_t size = parse_uint32(argv[3]);
		if(size > file_info->file_size) {
			printf("File size is smaller than paramter\n");
			return -7;
		}
		file_info->file_size = size;
	}

	struct timeval tv;
	gettimeofday(&tv, NULL);
	file_info->current_time = tv.tv_sec * 1000 * 1000 + tv.tv_usec;

	rpc_storage_upload(rpc, vmid, callback_storage_upload, file_info);

	return 0;
}
Esempio n. 3
0
static int download(int argc, char** argv) {
	if(argc < 3) {
		help();
		return -1;
	}

	if(!is_uint32(argv[1])) {
		help();
		return -2;
	}

	if(strlen(argv[2]) >= 256) {
		help();
		return -3;
	}

	uint32_t vmid = parse_uint32(argv[1]);

	FileInfo* file_info = (FileInfo*)malloc(sizeof(FileInfo));;
	if(file_info == NULL) {
		return -4;
	}
	memset(file_info, 0, sizeof(FileInfo));

	file_info->fd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0755);

	if(file_info->fd < 0) {
		free(file_info);
		return -5;
	}

	strcpy(file_info->path, argv[2]);
	lseek(file_info->fd, 0, SEEK_SET);
	uint64_t download_size = 0;
	if(argc == 4) {
		if(!is_uint32(argv[3]))
			return -6;

		download_size = parse_uint32(argv[3]);
	} else {
		download_size = 0;
	}

	file_info->offset = 0;

	struct timeval tv;
	gettimeofday(&tv, NULL);
	file_info->current_time = tv.tv_sec * 1000 * 1000 + tv.tv_usec;

	rpc_storage_download(rpc, vmid, download_size, callback_storage_download, file_info);

	return 0;
}
Esempio n. 4
0
/******************************************************************************
 *                                                                            *
 * Function: zbx_proc_get_processes                                           *
 *                                                                            *
 * Purpose: get system processes                                              *
 *                                                                            *
 * Parameters: processes - [OUT] the system processes                         *
 *             flags     - [IN] the flags specifying the process properties   *
 *                              that must be returned                         *
 *                                                                            *
 * Return value: SUCCEED - the system processes were retrieved successfully   *
 *               FAIL    - failed to open /proc directory                     *
 *                                                                            *
 ******************************************************************************/
int	zbx_proc_get_processes(zbx_vector_ptr_t *processes, unsigned int flags)
{
	const char		*__function_name = "zbx_proc_get_processes";

	DIR			*dir;
	struct dirent		*entries;
	int			ret = FAIL, pid;
	zbx_sysinfo_proc_t	*proc;

	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __function_name);

	if (NULL == (dir = opendir("/proc")))
		goto out;

	while (NULL != (entries = readdir(dir)))
	{
		/* skip entries not containing pids */
		if (FAIL == is_uint32(entries->d_name, &pid))
			continue;

		if (NULL == (proc = proc_create(pid, flags)))
			continue;

		zbx_vector_ptr_append(processes, proc);
	}

	closedir(dir);

	ret = SUCCEED;
out:
	zabbix_log(LOG_LEVEL_TRACE, "End of %s(): %s, processes:%d", __function_name, zbx_result_string(ret),
			processes->values_num);

	return ret;
}
Esempio n. 5
0
BufferOffset Assembler::Logical(const Register& rd, const Register& rn,
                                const Operand& operand, LogicalOp op)
{
  VIXL_ASSERT(rd.size() == rn.size());
  if (operand.IsImmediate()) {
    int64_t immediate = operand.immediate();
    unsigned reg_size = rd.size();

    VIXL_ASSERT(immediate != 0);
    VIXL_ASSERT(immediate != -1);
    VIXL_ASSERT(rd.Is64Bits() || is_uint32(immediate));

    // If the operation is NOT, invert the operation and immediate.
    if ((op & NOT) == NOT) {
      op = static_cast<LogicalOp>(op & ~NOT);
      immediate = rd.Is64Bits() ? ~immediate : (~immediate & kWRegMask);
    }

    unsigned n, imm_s, imm_r;
    if (IsImmLogical(immediate, reg_size, &n, &imm_s, &imm_r)) {
      // Immediate can be encoded in the instruction.
      return LogicalImmediate(rd, rn, n, imm_s, imm_r, op);
    } else {
      // This case is handled in the macro assembler.
      VIXL_UNREACHABLE();
    }
  } else {
    VIXL_ASSERT(operand.IsShiftedRegister());
    VIXL_ASSERT(operand.reg().size() == rd.size());
    Instr dp_op = static_cast<Instr>(op | LogicalShiftedFixed);
    return DataProcShiftedRegister(rd, rn, operand, LeaveFlags, dp_op);
  }
}
Esempio n. 6
0
static int vm_create(int argc, char* argv[]) {
	// Default value
	VMSpec vm = {};
	vm.core_size = 1;
	vm.memory_size = 0x1000000;	// 16MB
	vm.storage_size = 0x1000000;	// 16MB

	// Main options
	static struct option options[] = {
		{ "core", required_argument, 0, 'c' },
		{ "memory", required_argument, 0, 'm' },
		{ "storage", required_argument, 0, 's' },
		{ "nic", optional_argument, 0, 'n' },
		{ "args", required_argument, 0, 'a' },
		{ 0, 0, 0, 0 }
	};

	int opt;
	int index = 0;
	while((opt = getopt_long(argc, argv, "c:m:s:n::a:", options, &index)) != -1) {
		switch(opt) {
			case 'c' :
				if(!is_uint32(optarg)) goto failure;
				vm.core_size = strtol(optarg, NULL, 0);
				break;
			case 'm' :
				if(!is_uint32(optarg)) goto failure;
				vm.memory_size = strtol(optarg, NULL, 16);
				break;
			case 's' :
				if(!is_uint32(optarg)) goto failure;
				vm.storage_size = strtol(optarg, NULL, 16);
				break;
			case 'n' :;
				// Suboptions for NIC
				enum {
					EMPTY, MAC, DEV, IBUF, OBUF, IBAND, OBAND, HPAD, TPAD, POOL,
					INHERITMAC, NOARP, PROMISC, BROADCAST, MULTICAST, MULTIQUEUE,
				};

				const char* token[] = {
					[EMPTY] = "",
					[MAC]   = "mac",
					[DEV]   = "dev",
					[IBUF]	= "ibuf",
					[OBUF]	= "obuf",
					[IBAND]	= "iband",
					[OBAND]	= "oband",
					[HPAD]	= "hpad",
					[TPAD]	= "tpad",
					[POOL]	= "pool",
					[INHERITMAC] = "inheritmac",
					[NOARP] = "noarp",
					[PROMISC] = "promisc",
					[BROADCAST] = "broadcast",
					[MULTICAST] = "multicast",
					[MULTIQUEUE] = "multiqueue",
					NULL,
				};

				// Default NIC configuration
				NICSpec* nic = &vm.nics[vm.nic_count++];
				nic->mac = 0;
				nic->parent[0] = '\0';
				nic->budget = NICSPEC_DEFAULT_BUDGET_SIZE;
				nic->flags = NICSPEC_DEFAULT_FLAGS;
				nic->rx_buffer_size = 1024;
				nic->tx_buffer_size = 1024;
				nic->rx_bandwidth = 1000000000; /* 1 GB */
				nic->tx_bandwidth = 1000000000; /* 1 GB */
				nic->padding_head = 32;
				nic->padding_tail = 32;
				nic->pool_size = 0x400000; /* 4 MB */

				char* subopts = optarg;
				while(optarg && *subopts != '\0') {
					char* value = NULL;
					int subopt_index = getsubopt(&subopts, (char* const*)token, &value);
					if(subopt_index == -1) goto failure;

					switch(subopt_index) {
						case EMPTY:
							break;
						case MAC:
							if(!is_uint64(value)) goto failure;
							nic->mac = strtoll(value, NULL, 16);
							break;
						case DEV:
							strncpy(nic->parent, value, MAX_NIC_NAME_LEN);
							break;
						case IBUF:
							if(!is_uint32(value)) goto failure;
							nic->rx_buffer_size = strtoul(value, NULL, 0);
							break;
						case OBUF:
							if(!is_uint32(value)) goto failure;
							nic->tx_buffer_size = strtoul(value, NULL, 0);
							break;
						case IBAND:
							if(!is_uint64(value)) goto failure;
							nic->rx_bandwidth = strtoull(value, NULL, 0);
							break;
						case OBAND:
							if(!is_uint64(value)) goto failure;
							nic->tx_bandwidth = strtoull(value, NULL, 0);
							break;
						case HPAD:
							if(!is_uint8(value)) goto failure;
							nic->padding_head = strtoul(value, NULL, 0);
							break;
						case TPAD:
							if(!is_uint8(value)) goto failure;
							nic->padding_tail = strtoul(value, NULL, 0);
							break;
						case POOL:
							if(!is_uint32(value)) goto failure;
							nic->pool_size = strtoul(value, NULL, 16);
							break;
						case INHERITMAC:
							if(!strcmp("on", value)) {
								nic->flags |= NICSPEC_F_INHERITMAC;
							} else if(!strcmp("off", value)) {
								nic->flags |= NICSPEC_F_INHERITMAC;
								nic->flags ^= NICSPEC_F_INHERITMAC;
							} else goto failure;
							break;
						case NOARP:
							if(!strcmp("on", value)) {
								nic->flags |= NICSPEC_F_NOARP;
							} else if(!strcmp("off", value)) {
								nic->flags |= NICSPEC_F_NOARP;
								nic->flags ^= NICSPEC_F_NOARP;
							} else goto failure;
							break;
						case PROMISC:
							if(!strcmp("on", value)) {
								nic->flags |= NICSPEC_F_PROMISC;
							} else if(!strcmp("off", value)) {
								nic->flags |= NICSPEC_F_PROMISC;
								nic->flags ^= NICSPEC_F_PROMISC;
							} else goto failure;
							break;
						case BROADCAST:
							if(!strcmp("on", value)) {
								nic->flags |= NICSPEC_F_BROADCAST;
							} else if(!strcmp("off", value)) {
								nic->flags |= NICSPEC_F_BROADCAST;
								nic->flags ^= NICSPEC_F_BROADCAST;
							} else goto failure;
							break;
						case MULTICAST:
							if(!strcmp("on", value)) {
								nic->flags |= NICSPEC_F_MULTICAST;
							} else if(!strcmp("off", value)) {
								nic->flags |= NICSPEC_F_MULTICAST;
								nic->flags ^= NICSPEC_F_MULTICAST;
							} else goto failure;
							break;
						case MULTIQUEUE:
							if(!strcmp("on", value)) {
								nic->flags |= NICSPEC_F_MULTIQUEUE;
							} else if(!strcmp("off", value)) {
								nic->flags |= NICSPEC_F_MULTIQUEUE;
								nic->flags ^= NICSPEC_F_MULTIQUEUE;
							} else goto failure;
							break;
						default:
							goto failure;
							break;
					}
				}
				break;
			case 'a' :
				vm.argv[vm.argc++] = strdup(optarg);
				if(errno == ENOMEM) goto failure;
				break;

			default:
				goto failure;
		}
	}

	rpc_vm_create(rpc, &vm, callback_vm_create, NULL);

	return 0;

failure:
	printf("Malformed input were given\n");
	help();
	exit(EXIT_FAILURE);
}