Ejemplo n.º 1
0
struct config_tree *create_config_tree_from_string(const char *config_settings)
{
	struct cs *c;
	struct config_tree *cft;
	struct parser *p;

	if (!(cft = create_config_tree(NULL, 0)))
		return_NULL;

	c = (struct cs *) cft;
	if (!(p = dm_pool_alloc(c->mem, sizeof(*p)))) {
		log_error("Failed to allocate config tree parser.");
		destroy_config_tree(cft);
		return NULL;
	}

	p->mem = c->mem;
	p->fb = config_settings;
	p->fe = config_settings + strlen(config_settings);

	if (!_parse_config_file(p, cft)) {
		destroy_config_tree(cft);
		return_NULL;
	}

	return cft;
}
struct volume_group *text_vg_import_fd(struct format_instance *fid,
				       const char *file,
				       struct device *dev,
				       off_t offset, uint32_t size,
				       off_t offset2, uint32_t size2,
				       checksum_fn_t checksum_fn,
				       uint32_t checksum,
				       time_t *when, char **desc)
{
	struct volume_group *vg = NULL;
	struct config_tree *cft;
	struct text_vg_version_ops **vsn;

	_init_text_import();

	*desc = NULL;
	*when = 0;

	if (!(cft = create_config_tree(file, 0)))
		return_NULL;

	if ((!dev && !read_config_file(cft)) ||
	    (dev && !read_config_fd(cft, dev, offset, size,
				    offset2, size2, checksum_fn, checksum))) {
		log_error("Couldn't read volume group metadata.");
		goto out;
	}

	/*
	 * Find a set of version functions that can read this file
	 */
	for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
		if (!(*vsn)->check_version(cft))
			continue;

		if (!(vg = (*vsn)->read_vg(fid, cft, 0)))
			goto_out;

		(*vsn)->read_desc(vg->vgmem, cft, when, desc);
		break;
	}

      out:
	destroy_config_tree(cft);
	return vg;
}
Ejemplo n.º 3
0
int persistent_filter_load(struct dev_filter *f, struct config_tree **cft_out)
{
	struct pfilter *pf = (struct pfilter *) f->private;
	struct config_tree *cft;
        struct stat info;
	int r = 0;

        if (!stat(pf->file, &info))
		pf->ctime = info.st_ctime;
	else {
                log_very_verbose("%s: stat failed: %s", pf->file,
				 strerror(errno));
		return_0;
	}

	if (!(cft = create_config_tree(pf->file, 1)))
		return_0;

	if (!read_config_file(cft))
		goto_out;

	_read_array(pf, cft, "persistent_filter_cache/valid_devices",
		    PF_GOOD_DEVICE);
	/* We don't gain anything by holding invalid devices */
	/* _read_array(pf, cft, "persistent_filter_cache/invalid_devices",
	   PF_BAD_DEVICE); */

	/* Did we find anything? */
	if (dm_hash_get_num_entries(pf->devices)) {
		/* We populated dev_cache ourselves */
		dev_cache_scan(0);
		r = 1;
	}

	log_very_verbose("Loaded persistent filter cache from %s", pf->file);

      out:
	if (r && cft_out)
		*cft_out = cft;
	else
		destroy_config_tree(cft);
	return r;
}
const char *text_vgname_import(const struct format_type *fmt,
			       struct device *dev,
			       off_t offset, uint32_t size,
			       off_t offset2, uint32_t size2,
			       checksum_fn_t checksum_fn, uint32_t checksum,
			       struct id *vgid, uint64_t *vgstatus,
			       char **creation_host)
{
	struct config_tree *cft;
	struct text_vg_version_ops **vsn;
	const char *vgname = NULL;

	_init_text_import();

	if (!(cft = create_config_tree(NULL, 0)))
		return_NULL;

	if ((!dev && !read_config_file(cft)) ||
	    (dev && !read_config_fd(cft, dev, offset, size,
				    offset2, size2, checksum_fn, checksum)))
		goto_out;

	/*
	 * Find a set of version functions that can read this file
	 */
	for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
		if (!(*vsn)->check_version(cft))
			continue;

		if (!(vgname = (*vsn)->read_vgname(fmt, cft, vgid, vgstatus,
						   creation_host)))
			goto_out;

		break;
	}

      out:
	destroy_config_tree(cft);
	return vgname;
}