Exemplo n.º 1
0
static int emit_e820_device(int loglevel, struct ndctl_test *test)
{
	int err, fd;
	char path[256];
	const char *bdev;
	struct ndctl_ctx *ctx;
	struct ndctl_bus *bus;
	struct ndctl_region *region;
	struct ndctl_namespace *ndns;
	enum ndctl_namespace_mode mode;

	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 3, 0)))
		return 77;

	err = ndctl_new(&ctx);
	if (err < 0)
		return err;

	ndctl_set_log_priority(ctx, loglevel);
	err = -ENXIO;
	bus = ndctl_bus_get_by_provider(ctx, "e820");
	if (!bus)
		goto out;

	region = ndctl_region_get_first(bus);
	if (!region)
		goto out;

	ndns = ndctl_namespace_get_first(region);
	if (!ndns)
		goto out;

	mode = ndctl_namespace_get_mode(ndns);
	if (mode >= 0 && mode != NDCTL_NS_MODE_MEMORY)
		goto out;

	bdev = ndctl_namespace_get_block_device(ndns);
	if (!bdev)
		goto out;

	if (snprintf(path, sizeof(path), "/dev/%s", bdev) >= (int) sizeof(path))
		goto out;

	/*
	 * Note, if the bdev goes active after this check we'll still
	 * clobber it in the following tests, see test/dax.sh.
	 */
	fd = open(path, O_RDWR | O_EXCL);
	if (fd < 0)
		goto out;
	err = 0;
	fprintf(stdout, "%s\n", path);

 out:
	if (err)
		fprintf(stderr, "%s: failed to find usable victim device\n",
				__func__);
	ndctl_unref(ctx);
	return err;
}
Exemplo n.º 2
0
static int emit_e820_device(int loglevel, struct ndctl_test *test)
{
	int err, fd;
	char path[256];
	const char *bdev;
	struct ndctl_ctx *ctx;
	struct ndctl_bus *bus;
	struct ndctl_dax *dax;
	struct ndctl_pfn *pfn;
	struct ndctl_region *region;
	struct ndctl_namespace *ndns;
	enum ndctl_namespace_mode mode;

	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 3, 0)))
		return 77;

	err = ndctl_new(&ctx);
	if (err < 0)
		return err;

	ndctl_set_log_priority(ctx, loglevel);
	err = -ENXIO;
	bus = ndctl_bus_get_by_provider(ctx, "e820");
	if (!bus)
		goto out;

	region = ndctl_region_get_first(bus);
	if (!region)
		goto out;

	ndns = ndctl_namespace_get_first(region);
	if (!ndns)
		goto out;

	mode = ndctl_namespace_get_mode(ndns);
	if (mode >= 0 && mode != NDCTL_NS_MODE_MEMORY)
		goto out;

	/* if device-dax mode already established it might contain user data */
	pfn = ndctl_namespace_get_pfn(ndns);
	dax = ndctl_namespace_get_dax(ndns);
	if (dax || pfn)
		goto out;

	/* device is unconfigured, assume that was on purpose */
	bdev = ndctl_namespace_get_block_device(ndns);
	if (!bdev)
		goto out;

	if (snprintf(path, sizeof(path), "/dev/%s", bdev) >= (int) sizeof(path))
		goto out;

	/*
	 * Note, if the bdev goes active after this check we'll still
	 * clobber it in the following tests, see test/dax.sh and
	 * test/device-dax.sh.
	 */
	fd = open(path, O_RDWR | O_EXCL);
	if (fd < 0)
		goto out;
	err = 0;

 out:
	if (err) {
		fprintf(stderr, "%s: failed to find usable victim device\n",
				__func__);
		ndctl_test_skip(test);
		err = 77;
	} else
		fprintf(stdout, "%s\n", ndctl_namespace_get_devname(ndns));
	ndctl_unref(ctx);
	return err;
}