static int qcow2_probe(struct bdev *bdev, int dirfd, const char *pathname)
{
	int fd;
	struct {
	    uint32_t magic;
	    uint32_t version;
	} head;

	tcmu_dbg("%s\n", __func__);

	if (faccessat(dirfd, pathname, R_OK|W_OK, AT_EACCESS) == -1) {
		tcmu_err("faccessat failed dirfd %d, pathname %s, errno %d\n",
			 dirfd, pathname, errno);
		return -1;
	}
	if ((fd = openat(dirfd, pathname, O_RDONLY)) == -1) {
		tcmu_err("openat failed dirfd %d, pathname %s, errno %d\n",
			 dirfd, pathname, errno);
		return -1;
	}
	if (pread(fd, &head, sizeof(head), 0) == -1) {
		tcmu_err("pread failed dirfd %d, pathname %s, errno %d\n",
			 dirfd, pathname, errno);
		goto err;
	}
	if (be32toh(head.magic) != QCOW_MAGIC) {
		tcmu_warn("not qcow: will treat as raw: %s", pathname);
		goto err;
	}
	if (be32toh(head.version) < 2) {
		tcmu_err("version = %d, pathname %s\n", head.version, pathname);
		goto err;
	}
	close(fd);
	return 0;
err:
	close(fd);
	return -1;
}
static int qcow2_probe(struct bdev *bdev, int dirfd, const char *pathname)
{
	int fd;
	struct {
	    uint32_t magic;
	    uint32_t version;
	} head;

	tcmu_dbg("%s\n", __func__);

	if (faccessat(dirfd, pathname, R_OK|W_OK, AT_EACCESS) == -1) {
		tcmu_err("faccessat failed dirfd %d, pathname %s, errno %d\n",
			 dirfd, pathname, errno);
		return -1;
	}
	if ((fd = openat(dirfd, pathname, O_RDONLY)) == -1) {
		tcmu_err("openat failed dirfd %d, pathname %s, errno %d\n",
			 dirfd, pathname, errno);
		return -1;
	}
	if (pread(fd, &head, sizeof(head), 0) == -1) {
		tcmu_err("pread failed dirfd %d, pathname %s, errno %d\n",
			 dirfd, pathname, errno);
		goto err;
	}
	if (be32toh(head.magic) != QCOW_MAGIC) {
		tcmu_warn("not qcow: will treat as raw: %s", pathname);
		goto err;
	}
	if (be32toh(head.version) < 2) {
		tcmu_err("version = %d, pathname %s\n", head.version, pathname);
		goto err;
	}
	close(fd);
	return 0;
err:
	close(fd);
	return -1;
}