static void _get_key(SG_context* pCtx, const char* szRepoSpec, const char* szUserName, SG_string** ppstrKey)
{
	SG_string* pstrKey = NULL;
	SG_string* pstrHostname = NULL;

	SG_ERR_CHECK(  _get_host(pCtx, szRepoSpec, &pstrHostname)  );

	SG_ERR_CHECK(  SG_STRING__ALLOC__SZ(pCtx, &pstrKey, KEY_PREFIX KEY_SEPARATOR)  );
	SG_ERR_CHECK(  SG_string__append__sz(pCtx, pstrKey, SG_string__sz(pstrHostname))  );
	SG_ERR_CHECK(  SG_string__append__sz(pCtx, pstrKey, KEY_SEPARATOR)  );
	SG_ERR_CHECK(  SG_string__append__sz(pCtx, pstrKey, szUserName)  );

	*ppstrKey = pstrKey;
	pstrKey = NULL;

	/* fall through */
fail:
	SG_STRING_NULLFREE(pCtx, pstrKey);
	SG_STRING_NULLFREE(pCtx, pstrHostname);
}
Ejemplo n.º 2
0
/*
 * Allocates a new block device structure. See block.h for details.
 */
struct block_device *block_device_init(void *cntrl_list, const char *path)
{
	struct cntrl_device *cntrl;
	char link[PATH_MAX], *host;
	struct block_device *device = NULL;
	send_message_t send_fn = NULL;
	flush_message_t flush_fn = NULL;
	int host_id = -1;
	char *host_name;

	if (realpath(path, link)) {
		cntrl = block_get_controller(cntrl_list, link);
		if (cntrl == NULL)
			return NULL;
		host = _get_host(link, cntrl);
		if (host == NULL)
			return NULL;
		host_name = get_path_hostN(link);
		if (host_name) {
			sscanf(host_name, "host%d", &host_id);
			free(host_name);
		}
		flush_fn = _get_flush_fn(cntrl, link);
		send_fn = _get_send_fn(cntrl, link);
		if (send_fn  == NULL) {
			free(host);
			return NULL;
		}
		device = calloc(1, sizeof(*device));
		if (device) {
			struct _host_type *hosts = cntrl->hosts;

			device->cntrl = cntrl;
			device->sysfs_path = strdup(link);
			device->cntrl_path = host;
			device->ibpi = IBPI_PATTERN_UNKNOWN;
			device->ibpi_prev = IBPI_PATTERN_NONE;
			device->send_fn = send_fn;
			device->flush_fn = flush_fn;
			device->timestamp = timestamp;
			device->host = NULL;
			device->host_id = host_id;
			device->encl_index = -1;
			while (hosts) {
				if (hosts->host_id == host_id) {
					device->host = hosts;
					break;
				}
				hosts = hosts->next;
			}
			if (cntrl->cntrl_type == CNTRL_TYPE_SCSI) {
				if (dev_directly_attached(link))
					device->phy_index =
					    isci_cntrl_init_smp(link, cntrl);
				else {
					device->phy_index =
					    isci_cntrl_init_smp(link, cntrl);
					if (scsi_get_enclosure(device) == 0) {
						log_warning("Device " \
							    "initialization " \
							    "failed for '%s'",
									path);
						free(device->sysfs_path);
						free(device->cntrl_path);
						free(device);
						device = NULL;
					}
				}
			}
		} else
			free(host);
	}
	return device;
}