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 *import_vg_from_buffer(char *buf, struct format_instance *fid) { struct volume_group *vg = NULL; struct config_tree *cft; struct text_vg_version_ops **vsn; _init_text_import(); if (!(cft = create_config_tree_from_string(fid->fmt->cmd, buf))) return_NULL; for (vsn = &_text_vsn_list[0]; *vsn; vsn++) { if (!(*vsn)->check_version(cft)) continue; /* * The only path to this point uses cached vgmetadata, * so it can use cached PV state too. */ if (!(vg = (*vsn)->read_vg(fid, cft, 1))) stack; break; } destroy_config_tree(cft); return vg; }
void Rehash(int status) { sendto_logchan("Reloading configuration files"); destroy_config_tree(); config_load (CfgSettings.conf_name); //load the config Event("REHASH", 0, NULL); }
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; }
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; }
struct volume_group *import_vg_from_buffer(char *buf, struct format_instance *fid) { struct volume_group *vg = NULL; struct config_tree *cft; struct text_vg_version_ops **vsn; _init_text_import(); if (!(cft = create_config_tree_from_string(fid->fmt->cmd, buf))) return_NULL; for (vsn = &_text_vsn_list[0]; *vsn; vsn++) { if (!(*vsn)->check_version(cft)) continue; if (!(vg = (*vsn)->read_vg(fid, cft))) stack; break; } destroy_config_tree(cft); return vg; }
int persistent_filter_dump(struct dev_filter *f) { struct pfilter *pf = (struct pfilter *) f->private; char *tmp_file; struct stat info, info2; struct config_tree *cft = NULL; FILE *fp; int lockfd; int r = 0; if (!dm_hash_get_num_entries(pf->devices)) { log_very_verbose("Internal persistent device cache empty " "- not writing to %s", pf->file); return 0; } if (!dev_cache_has_scanned()) { log_very_verbose("Device cache incomplete - not writing " "to %s", pf->file); return 0; } log_very_verbose("Dumping persistent device cache to %s", pf->file); while (1) { if ((lockfd = fcntl_lock_file(pf->file, F_WRLCK, 0)) < 0) return_0; /* * Ensure we locked the file we expected */ if (fstat(lockfd, &info)) { log_sys_error("fstat", pf->file); goto out; } if (stat(pf->file, &info2)) { log_sys_error("stat", pf->file); goto out; } if (!memcmp(&info.st_ino, &info2.st_ino, sizeof(ino_t))) break; fcntl_unlock_file(lockfd); } /* * If file contents changed since we loaded it, merge new contents */ if (info.st_ctime != pf->ctime) /* Keep cft open to avoid losing lock */ persistent_filter_load(f, &cft); tmp_file = alloca(strlen(pf->file) + 5); sprintf(tmp_file, "%s.tmp", pf->file); if (!(fp = fopen(tmp_file, "w"))) { /* EACCES has been reported over NFS */ if (errno != EROFS && errno != EACCES) log_sys_error("fopen", tmp_file); goto out; } fprintf(fp, "# This file is automatically maintained by lvm.\n\n"); fprintf(fp, "persistent_filter_cache {\n"); _write_array(pf, fp, "valid_devices", PF_GOOD_DEVICE); /* We don't gain anything by remembering invalid devices */ /* _write_array(pf, fp, "invalid_devices", PF_BAD_DEVICE); */ fprintf(fp, "}\n"); if (fclose(fp)) { log_sys_error("fclose", tmp_file); goto out; } if (rename(tmp_file, pf->file)) log_error("%s: rename to %s failed: %s", tmp_file, pf->file, strerror(errno)); r = 1; out: fcntl_unlock_file(lockfd); if (cft) destroy_config_tree(cft); return r; }