Example #1
0
bool attach_nbd(char *src, struct lxc_conf *conf)
{
	__do_free char *orig;
	char *p, path[50];
	int i = 0;

	orig = must_copy_string(src);
	/* if path is followed by a partition, drop that for now */
	p = strchr(orig, ':');
	if (p)
		*p = '\0';

	for (;;) {
		sprintf(path, "/dev/nbd%d", i);

		if (!file_exists(path))
			return false;

		if (nbd_busy(i)) {
			i++;
			continue;
		}

		if (!clone_attach_nbd(path, orig))
			return false;

		conf->nbd_idx = i;
		return true;
	}
}
Example #2
0
File: lxcnbd.c Project: 4b42/lxc
bool attach_nbd(char *src, struct lxc_conf *conf)
{
	char *orig = alloca(strlen(src)+1), *p, path[50];
	int i = 0;

	strcpy(orig, src);
	/* if path is followed by a partition, drop that for now */
	p = strchr(orig, ':');
	if (p)
		*p = '\0';
	while (1) {
		sprintf(path, "/dev/nbd%d", i);
		if (!file_exists(path))
			return false;
		if (nbd_busy(i)) {
			i++;
			continue;
		}
		if (!clone_attach_nbd(path, orig))
			return false;
		conf->nbd_idx = i;
		return true;
	}
}