struct json_object *util_mapping_to_json(struct ndctl_mapping *mapping) { struct json_object *jmapping = json_object_new_object(); struct ndctl_dimm *dimm = ndctl_mapping_get_dimm(mapping); struct json_object *jobj; if (!jmapping) return NULL; jobj = json_object_new_string(ndctl_dimm_get_devname(dimm)); if (!jobj) goto err; json_object_object_add(jmapping, "dimm", jobj); jobj = json_object_new_int64(ndctl_mapping_get_offset(mapping)); if (!jobj) goto err; json_object_object_add(jmapping, "offset", jobj); jobj = json_object_new_int64(ndctl_mapping_get_length(mapping)); if (!jobj) goto err; json_object_object_add(jmapping, "length", jobj); return jmapping; err: json_object_put(jmapping); return NULL; }
struct json_object *util_dimm_to_json(struct ndctl_dimm *dimm) { struct json_object *jdimm = json_object_new_object(); const char *id = ndctl_dimm_get_unique_id(dimm); struct json_object *jobj; if (!jdimm) return NULL; jobj = json_object_new_string(ndctl_dimm_get_devname(dimm)); if (!jobj) goto err; json_object_object_add(jdimm, "dev", jobj); if (id) { jobj = json_object_new_string(id); if (!jobj) goto err; json_object_object_add(jdimm, "id", jobj); } if (!ndctl_dimm_is_enabled(dimm)) { jobj = json_object_new_string("disabled"); if (!jobj) goto err; json_object_object_add(jdimm, "state", jobj); } return jdimm; err: json_object_put(jdimm); return NULL; }
int test_pmem_namespaces(int log_level) { struct ndctl_region *region, *pmem_region = NULL; struct ndctl_namespace *ndns; struct ndctl_dimm *dimm; struct ndctl_ctx *ctx; struct ndctl_bus *bus; char bdev[50]; int rc; rc = -ndctl_new(&ctx); if (rc) return rc; ndctl_set_log_priority(ctx, log_level); bus = ndctl_bus_get_by_provider(ctx, provider); if (!bus) { fprintf(stderr, "%s: failed to find NFIT-provider\n", comm); rc = 77; goto err; } else fprintf(stderr, "%s: found provider: %s\n", comm, ndctl_bus_get_provider(bus)); /* get the system to a clean state */ ndctl_region_foreach(bus, region) ndctl_region_disable_invalidate(region); ndctl_dimm_foreach(bus, dimm) { rc = -ndctl_dimm_zero_labels(dimm); if (rc) { fprintf(stderr, "failed to zero %s\n", ndctl_dimm_get_devname(dimm)); return rc; } }
int test_pmem_namespaces(int log_level, struct ndctl_test *test) { struct ndctl_region *region, *pmem_region = NULL; struct kmod_ctx *kmod_ctx = NULL; struct kmod_module *mod = NULL; struct ndctl_namespace *ndns; struct ndctl_dimm *dimm; struct ndctl_ctx *ctx; struct ndctl_bus *bus; char bdev[50]; int rc; if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 2, 0))) return 77; rc = ndctl_new(&ctx); if (rc < 0) return rc; ndctl_set_log_priority(ctx, log_level); bus = ndctl_bus_get_by_provider(ctx, "ACPI.NFIT"); if (!bus) { fprintf(stderr, "ACPI.NFIT unavailable falling back to nfit_test\n"); kmod_ctx = kmod_new(NULL, NULL); if (!kmod_ctx) goto err_kmod; kmod_set_log_priority(kmod_ctx, log_level); rc = kmod_module_new_from_name(kmod_ctx, "nfit_test", &mod); if (rc < 0) goto err_module; rc = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL); ndctl_invalidate(ctx); bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0"); if (rc < 0 || !bus) { rc = 77; ndctl_test_skip(test); fprintf(stderr, "nfit_test unavailable skipping tests\n"); goto err_module; } } fprintf(stderr, "%s: found provider: %s\n", comm, ndctl_bus_get_provider(bus)); /* get the system to a clean state */ ndctl_region_foreach(bus, region) ndctl_region_disable_invalidate(region); ndctl_dimm_foreach(bus, dimm) { rc = ndctl_dimm_zero_labels(dimm); if (rc < 0) { fprintf(stderr, "failed to zero %s\n", ndctl_dimm_get_devname(dimm)); goto err; } }