]>
Commit | Line | Data |
---|---|---|
a4b75251 TL |
1 | // SPDX-License-Identifier: BSD-3-Clause |
2 | /* Copyright 2020, Intel Corporation */ | |
3 | ||
4 | #include <errno.h> | |
5 | #include <ndctl/libndctl.h> | |
6 | ||
7 | #include "libpmem2.h" | |
8 | #include "out.h" | |
9 | #include "pmem2_utils.h" | |
10 | #include "region_namespace_ndctl.h" | |
11 | #include "source.h" | |
12 | ||
13 | /* | |
14 | * pmem2_device_dax_alignment -- checks the alignment of a given | |
15 | * dax device from given source | |
16 | */ | |
17 | int | |
18 | pmem2_device_dax_alignment(const struct pmem2_source *src, size_t *alignment) | |
19 | { | |
20 | int ret = 0; | |
21 | size_t size = 0; | |
22 | struct ndctl_ctx *ctx; | |
23 | struct ndctl_namespace *ndns; | |
24 | ||
25 | errno = ndctl_new(&ctx) * (-1); | |
26 | if (errno) { | |
27 | ERR("!ndctl_new"); | |
28 | return PMEM2_E_ERRNO; | |
29 | } | |
30 | ||
31 | ret = pmem2_region_namespace(ctx, src, NULL, &ndns); | |
32 | if (ret) { | |
33 | LOG(1, "getting region and namespace failed"); | |
34 | goto end; | |
35 | } | |
36 | ||
37 | struct ndctl_dax *dax = ndctl_namespace_get_dax(ndns); | |
38 | ||
39 | if (dax) | |
40 | size = ndctl_dax_get_align(dax); | |
41 | else | |
42 | ret = PMEM2_E_INVALID_ALIGNMENT_FORMAT; | |
43 | ||
44 | end: | |
45 | ndctl_unref(ctx); | |
46 | ||
47 | *alignment = size; | |
48 | LOG(4, "device alignment %zu", *alignment); | |
49 | ||
50 | return ret; | |
51 | } | |
52 | ||
53 | /* | |
54 | * pmem2_device_dax_size -- checks the size of a given | |
55 | * dax device from given source structure | |
56 | */ | |
57 | int | |
58 | pmem2_device_dax_size(const struct pmem2_source *src, size_t *size) | |
59 | { | |
60 | int ret = 0; | |
61 | struct ndctl_ctx *ctx; | |
62 | struct ndctl_namespace *ndns; | |
63 | ||
64 | errno = ndctl_new(&ctx) * (-1); | |
65 | if (errno) { | |
66 | ERR("!ndctl_new"); | |
67 | return PMEM2_E_ERRNO; | |
68 | } | |
69 | ||
70 | ret = pmem2_region_namespace(ctx, src, NULL, &ndns); | |
71 | if (ret) { | |
72 | LOG(1, "getting region and namespace failed"); | |
73 | goto end; | |
74 | } | |
75 | ||
76 | struct ndctl_dax *dax = ndctl_namespace_get_dax(ndns); | |
77 | ||
78 | if (dax) { | |
79 | *size = ndctl_dax_get_size(dax); | |
80 | } else { | |
81 | ret = PMEM2_E_DAX_REGION_NOT_FOUND; | |
82 | ERR("Issue while reading Device Dax size - cannot " | |
83 | "find dax region"); | |
84 | } | |
85 | ||
86 | end: | |
87 | ndctl_unref(ctx); | |
88 | LOG(4, "device size %zu", *size); | |
89 | ||
90 | return ret; | |
91 | } |