master - vdo: fix parsing vdo status
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5cf0923e1840375d23c...
Commit: 5cf0923e1840375d23c4fd6035b919613ce6573b
Parent: e9d1f676b3768844471f8c6d3345a1b60bc2c94e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Jul 9 00:54:16 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 9 10:30:34 2018 +0200
vdo: fix parsing vdo status
Recent updates relay on zerod status structure memory (device ptr is
NULL) and also dm_strncpy need to count with '\0'.
---
device_mapper/vdo/status.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/device_mapper/vdo/status.c b/device_mapper/vdo/status.c
index 7323a35..a0eba49 100644
--- a/device_mapper/vdo/status.c
+++ b/device_mapper/vdo/status.c
@@ -188,7 +188,7 @@ bool vdo_status_parse(struct dm_pool *mem, const char *input,
const char *te;
struct vdo_status *s;
- s = (!mem) ? malloc(sizeof(*s)) : dm_pool_zalloc(mem, sizeof(*s));
+ s = (!mem) ? zalloc(sizeof(*s)) : dm_pool_zalloc(mem, sizeof(*s));
if (!s) {
_set_error(result, "out of memory");
@@ -206,7 +206,7 @@ bool vdo_status_parse(struct dm_pool *mem, const char *input,
_set_error(result, "out of memory");
goto bad;
}
- dm_strncpy(s->device, b, te - b);
+ dm_strncpy(s->device, b, te - b + 1);
b = _eat_space(te, e);
5 years, 9 months
master - tests: update vdo unit test to dm prefix
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5f3eff8eaecdb6e8f97...
Commit: 5f3eff8eaecdb6e8f97b3904d5c43d36700709f3
Parent: 9b6b4f14d89c661683b2095999126e652fb92f53
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Jul 9 10:05:06 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 9 10:30:34 2018 +0200
tests: update vdo unit test to dm prefix
Update prefix and reindent.
---
test/unit/vdo_t.c | 264 ++++++++++++++++++++++++++--------------------------
1 files changed, 132 insertions(+), 132 deletions(-)
diff --git a/test/unit/vdo_t.c b/test/unit/vdo_t.c
index 7355928..27ad26b 100644
--- a/test/unit/vdo_t.c
+++ b/test/unit/vdo_t.c
@@ -17,7 +17,7 @@
//----------------------------------------------------------------
-static bool _status_eq(struct vdo_status *lhs, struct vdo_status *rhs)
+static bool _status_eq(struct dm_vdo_status *lhs, struct dm_vdo_status *rhs)
{
return !strcmp(lhs->device, rhs->device) &&
(lhs->operating_mode == rhs->operating_mode) &&
@@ -29,49 +29,49 @@ static bool _status_eq(struct vdo_status *lhs, struct vdo_status *rhs)
}
#if 0
-static const char *_op_mode(enum vdo_operating_mode m)
+static const char *_op_mode(enum dm_vdo_operating_mode m)
{
- switch (m) {
- case VDO_MODE_RECOVERING:
- return "recovering";
- case VDO_MODE_READ_ONLY:
- return "read-only";
- case VDO_MODE_NORMAL:
- return "normal";
- }
-
- return "<unknown>";
+ switch (m) {
+ case DM_VDO_MODE_RECOVERING:
+ return "recovering";
+ case DM_VDO_MODE_READ_ONLY:
+ return "read-only";
+ case DM_VDO_MODE_NORMAL:
+ return "normal";
+ }
+
+ return "<unknown>";
}
-static const char *_index_state(enum vdo_index_state is)
+static const char *_index_state(enum dm_vdo_index_state is)
{
- switch (is) {
- case VDO_INDEX_ERROR:
- return "error";
- case VDO_INDEX_CLOSED:
- return "closed";
- case VDO_INDEX_OPENING:
- return "opening";
- case VDO_INDEX_CLOSING:
- return "closing";
- case VDO_INDEX_OFFLINE:
- return "offline";
- case VDO_INDEX_ONLINE:
- return "online";
- case VDO_INDEX_UNKNOWN:
- return "unknown";
- }
-
- return "<unknown>";
+ switch (is) {
+ case DM_VDO_INDEX_ERROR:
+ return "error";
+ case DM_VDO_INDEX_CLOSED:
+ return "closed";
+ case DM_VDO_INDEX_OPENING:
+ return "opening";
+ case DM_VDO_INDEX_CLOSING:
+ return "closing";
+ case DM_VDO_INDEX_OFFLINE:
+ return "offline";
+ case DM_VDO_INDEX_ONLINE:
+ return "online";
+ case DM_VDO_INDEX_UNKNOWN:
+ return "unknown";
+ }
+
+ return "<unknown>";
}
-static void _print_status(FILE *stream, struct vdo_status *s)
+static void _print_status(FILE *stream, struct dm_vdo_status *s)
{
fprintf(stream, "<status| %s ", s->device);
fprintf(stream, "%s ", _op_mode(s->operating_mode));
fprintf(stream, "%s ", s->recovering ? "recovering" : "-");
fprintf(stream, "%s ", _index_state(s->index_state));
- fprintf(stream, "%s ", s->compression_state == VDO_COMPRESSION_ONLINE ? "online" : "offline");
+ fprintf(stream, "%s ", s->compression_state == DM_VDO_COMPRESSION_ONLINE ? "online" : "offline");
fprintf(stream, "%llu ", (unsigned long long) s->used_blocks);
fprintf(stream, "%llu", (unsigned long long) s->total_blocks);
fprintf(stream, ">");
@@ -80,55 +80,55 @@ static void _print_status(FILE *stream, struct vdo_status *s)
struct example_good {
const char *input;
- struct vdo_status status;
+ struct dm_vdo_status status;
};
static void _check_good(struct example_good *es, unsigned count)
{
- unsigned i;
+ unsigned i;
- for (i = 0; i < count; i++) {
- struct example_good *e = es + i;
- struct vdo_status_parse_result pr;
+ for (i = 0; i < count; i++) {
+ struct example_good *e = es + i;
+ struct dm_vdo_status_parse_result pr;
- T_ASSERT(vdo_status_parse(NULL, e->input, &pr));
+ T_ASSERT(dm_vdo_status_parse(NULL, e->input, &pr));
#if 0
- _print_status(stderr, pr.status);
- fprintf(stderr, "\n");
- _print_status(stderr, &e->status);
- fprintf(stderr, "\n");
+ _print_status(stderr, pr.status);
+ fprintf(stderr, "\n");
+ _print_status(stderr, &e->status);
+ fprintf(stderr, "\n");
#endif
- T_ASSERT(_status_eq(&e->status, pr.status));
- free(pr.status);
- }
+ T_ASSERT(_status_eq(&e->status, pr.status));
+ free(pr.status);
+ }
}
struct example_bad {
- const char *input;
- const char *reason;
+ const char *input;
+ const char *reason;
};
static void _check_bad(struct example_bad *es, unsigned count)
{
- unsigned i;
+ unsigned i;
- for (i = 0; i < count; i++) {
- struct example_bad *e = es + i;
- struct vdo_status_parse_result pr;
+ for (i = 0; i < count; i++) {
+ struct example_bad *e = es + i;
+ struct dm_vdo_status_parse_result pr;
- T_ASSERT(!vdo_status_parse(NULL, e->input, &pr));
- T_ASSERT(!strcmp(e->reason, pr.error));
- }
+ T_ASSERT(!dm_vdo_status_parse(NULL, e->input, &pr));
+ T_ASSERT(!strcmp(e->reason, pr.error));
+ }
}
static void _test_device_names_good(void *fixture)
{
static struct example_good _es[] = {
- {"foo1234 read-only - error online 0 1234",
- {(char *) "foo1234", VDO_MODE_READ_ONLY, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"f read-only - error online 0 1234",
- {(char *) "f", VDO_MODE_READ_ONLY, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- };
+ {"foo1234 read-only - error online 0 1234",
+ {(char *) "foo1234", DM_VDO_MODE_READ_ONLY, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"f read-only - error online 0 1234",
+ {(char *) "f", DM_VDO_MODE_READ_ONLY, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ };
_check_good(_es, DM_ARRAY_SIZE(_es));
}
@@ -136,13 +136,13 @@ static void _test_device_names_good(void *fixture)
static void _test_operating_mode_good(void *fixture)
{
static struct example_good _es[] = {
- {"device-name recovering - error online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name read-only - error online 0 1234",
- {(char *) "device-name", VDO_MODE_READ_ONLY, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name normal - error online 0 1234",
- {(char *) "device-name", VDO_MODE_NORMAL, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- };
+ {"device-name recovering - error online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name read-only - error online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_READ_ONLY, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name normal - error online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_NORMAL, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ };
_check_good(_es, DM_ARRAY_SIZE(_es));
}
@@ -150,20 +150,20 @@ static void _test_operating_mode_good(void *fixture)
static void _test_operating_mode_bad(void *fixture)
{
static struct example_bad _es[] = {
- {"device-name investigating - error online 0 1234",
- "couldn't parse 'operating mode'"}};
+ {"device-name investigating - error online 0 1234",
+ "couldn't parse 'operating mode'"}};
- _check_bad(_es, DM_ARRAY_SIZE(_es));
+ _check_bad(_es, DM_ARRAY_SIZE(_es));
}
static void _test_recovering_good(void *fixture)
{
static struct example_good _es[] = {
- {"device-name recovering - error online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name read-only recovering error online 0 1234",
- {(char *) "device-name", VDO_MODE_READ_ONLY, true, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- };
+ {"device-name recovering - error online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name read-only recovering error online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_READ_ONLY, true, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ };
_check_good(_es, DM_ARRAY_SIZE(_es));
}
@@ -171,30 +171,30 @@ static void _test_recovering_good(void *fixture)
static void _test_recovering_bad(void *fixture)
{
static struct example_bad _es[] = {
- {"device-name normal fish error online 0 1234",
- "couldn't parse 'recovering'"}};
+ {"device-name normal fish error online 0 1234",
+ "couldn't parse 'recovering'"}};
- _check_bad(_es, DM_ARRAY_SIZE(_es));
+ _check_bad(_es, DM_ARRAY_SIZE(_es));
}
static void _test_index_state_good(void *fixture)
{
static struct example_good _es[] = {
- {"device-name recovering - error online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name recovering - closed online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_CLOSED, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name recovering - opening online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_OPENING, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name recovering - closing online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_CLOSING, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name recovering - offline online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_OFFLINE, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name recovering - online online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_ONLINE, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name recovering - unknown online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_UNKNOWN, VDO_COMPRESSION_ONLINE, 0, 1234}},
- };
+ {"device-name recovering - error online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name recovering - closed online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_CLOSED, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name recovering - opening online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_OPENING, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name recovering - closing online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_CLOSING, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name recovering - offline online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_OFFLINE, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name recovering - online online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_ONLINE, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name recovering - unknown online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_UNKNOWN, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ };
_check_good(_es, DM_ARRAY_SIZE(_es));
}
@@ -202,20 +202,20 @@ static void _test_index_state_good(void *fixture)
static void _test_index_state_bad(void *fixture)
{
static struct example_bad _es[] = {
- {"device-name normal - fish online 0 1234",
- "couldn't parse 'index state'"}};
+ {"device-name normal - fish online 0 1234",
+ "couldn't parse 'index state'"}};
- _check_bad(_es, DM_ARRAY_SIZE(_es));
+ _check_bad(_es, DM_ARRAY_SIZE(_es));
}
static void _test_compression_state_good(void *fixture)
{
static struct example_good _es[] = {
- {"device-name recovering - error online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name read-only - error offline 0 1234",
- {(char *) "device-name", VDO_MODE_READ_ONLY, false, VDO_INDEX_ERROR, VDO_COMPRESSION_OFFLINE, 0, 1234}},
- };
+ {"device-name recovering - error online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name read-only - error offline 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_READ_ONLY, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_OFFLINE, 0, 1234}},
+ };
_check_good(_es, DM_ARRAY_SIZE(_es));
}
@@ -223,24 +223,24 @@ static void _test_compression_state_good(void *fixture)
static void _test_compression_state_bad(void *fixture)
{
static struct example_bad _es[] = {
- {"device-name normal - error fish 0 1234",
- "couldn't parse 'compression state'"}};
+ {"device-name normal - error fish 0 1234",
+ "couldn't parse 'compression state'"}};
- _check_bad(_es, DM_ARRAY_SIZE(_es));
+ _check_bad(_es, DM_ARRAY_SIZE(_es));
}
static void _test_used_blocks_good(void *fixture)
{
static struct example_good _es[] = {
- {"device-name recovering - error online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name read-only - error offline 1 1234",
- {(char *) "device-name", VDO_MODE_READ_ONLY, false, VDO_INDEX_ERROR, VDO_COMPRESSION_OFFLINE, 1, 1234}},
- {"device-name read-only - error offline 12 1234",
- {(char *) "device-name", VDO_MODE_READ_ONLY, false, VDO_INDEX_ERROR, VDO_COMPRESSION_OFFLINE, 12, 1234}},
- {"device-name read-only - error offline 3456 1234",
- {(char *) "device-name", VDO_MODE_READ_ONLY, false, VDO_INDEX_ERROR, VDO_COMPRESSION_OFFLINE, 3456, 1234}},
- };
+ {"device-name recovering - error online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name read-only - error offline 1 1234",
+ {(char *) "device-name", DM_VDO_MODE_READ_ONLY, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_OFFLINE, 1, 1234}},
+ {"device-name read-only - error offline 12 1234",
+ {(char *) "device-name", DM_VDO_MODE_READ_ONLY, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_OFFLINE, 12, 1234}},
+ {"device-name read-only - error offline 3456 1234",
+ {(char *) "device-name", DM_VDO_MODE_READ_ONLY, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_OFFLINE, 3456, 1234}},
+ };
_check_good(_es, DM_ARRAY_SIZE(_es));
}
@@ -248,22 +248,22 @@ static void _test_used_blocks_good(void *fixture)
static void _test_used_blocks_bad(void *fixture)
{
static struct example_bad _es[] = {
- {"device-name normal - error online fish 1234",
- "couldn't parse 'used blocks'"}};
+ {"device-name normal - error online fish 1234",
+ "couldn't parse 'used blocks'"}};
- _check_bad(_es, DM_ARRAY_SIZE(_es));
+ _check_bad(_es, DM_ARRAY_SIZE(_es));
}
static void _test_total_blocks_good(void *fixture)
{
static struct example_good _es[] = {
- {"device-name recovering - error online 0 1234",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1234}},
- {"device-name recovering - error online 0 1",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 1}},
- {"device-name recovering - error online 0 0",
- {(char *) "device-name", VDO_MODE_RECOVERING, false, VDO_INDEX_ERROR, VDO_COMPRESSION_ONLINE, 0, 0}},
- };
+ {"device-name recovering - error online 0 1234",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1234}},
+ {"device-name recovering - error online 0 1",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 1}},
+ {"device-name recovering - error online 0 0",
+ {(char *) "device-name", DM_VDO_MODE_RECOVERING, false, DM_VDO_INDEX_ERROR, DM_VDO_COMPRESSION_ONLINE, 0, 0}},
+ };
_check_good(_es, DM_ARRAY_SIZE(_es));
}
@@ -271,18 +271,18 @@ static void _test_total_blocks_good(void *fixture)
static void _test_total_blocks_bad(void *fixture)
{
static struct example_bad _es[] = {
- {"device-name normal - error online 0 fish",
- "couldn't parse 'total blocks'"}};
+ {"device-name normal - error online 0 fish",
+ "couldn't parse 'total blocks'"}};
- _check_bad(_es, DM_ARRAY_SIZE(_es));
+ _check_bad(_es, DM_ARRAY_SIZE(_es));
}
static void _test_status_bad(void *fixture)
{
- struct example_bad _bad[] = {
- {"", "couldn't get token for device"},
- {"device-name read-only - error online 0 1000 lksd", "too many tokens"}
- };
+ struct example_bad _bad[] = {
+ {"", "couldn't get token for device"},
+ {"device-name read-only - error online 0 1000 lksd", "too many tokens"}
+ };
_check_bad(_bad, DM_ARRAY_SIZE(_bad));
}
@@ -295,8 +295,8 @@ static struct test_suite *_tests(void)
{
struct test_suite *ts = test_suite_create(NULL, NULL);
if (!ts) {
- fprintf(stderr, "out of memory\n");
- exit(1);
+ fprintf(stderr, "out of memory\n");
+ exit(1);
};
T("device-names", "parse various device names", _test_device_names_good);
5 years, 9 months
master - device_mapper: convert vdo to use dm_ prefix
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9b6b4f14d89c661683b...
Commit: 9b6b4f14d89c661683b2095999126e652fb92f53
Parent: 4a64bb9573bb3c54cfac0b4f588cd80dba01d60d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Jul 9 10:04:51 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 9 10:30:34 2018 +0200
device_mapper: convert vdo to use dm_ prefix
Keep using DM_/dm_ prefixes for device_mapper code.
---
device_mapper/vdo/status.c | 49 ++++++++++++++++++++++---------------------
device_mapper/vdo/target.h | 48 +++++++++++++++++++++---------------------
2 files changed, 49 insertions(+), 48 deletions(-)
diff --git a/device_mapper/vdo/status.c b/device_mapper/vdo/status.c
index a0eba49..6831195 100644
--- a/device_mapper/vdo/status.c
+++ b/device_mapper/vdo/status.c
@@ -3,6 +3,7 @@
// For DM_ARRAY_SIZE!
#include "device_mapper/all.h"
+#include "base/memory/zalloc.h"
#include <ctype.h>
#include <stdlib.h>
@@ -27,14 +28,14 @@ static bool _parse_operating_mode(const char *b, const char *e, void *context)
{
static const struct {
const char str[12];
- enum vdo_operating_mode mode;
+ enum dm_vdo_operating_mode mode;
} _table[] = {
- {"recovering", VDO_MODE_RECOVERING},
- {"read-only", VDO_MODE_READ_ONLY},
- {"normal", VDO_MODE_NORMAL}
+ {"recovering", DM_VDO_MODE_RECOVERING},
+ {"read-only", DM_VDO_MODE_READ_ONLY},
+ {"normal", DM_VDO_MODE_NORMAL}
};
- enum vdo_operating_mode *r = context;
+ enum dm_vdo_operating_mode *r = context;
unsigned i;
for (i = 0; i < DM_ARRAY_SIZE(_table); i++) {
if (_tok_eq(b, e, _table[i].str)) {
@@ -50,13 +51,13 @@ static bool _parse_compression_state(const char *b, const char *e, void *context
{
static const struct {
const char str[8];
- enum vdo_compression_state state;
+ enum dm_vdo_compression_state state;
} _table[] = {
- {"online", VDO_COMPRESSION_ONLINE},
- {"offline", VDO_COMPRESSION_OFFLINE}
+ {"online", DM_VDO_COMPRESSION_ONLINE},
+ {"offline", DM_VDO_COMPRESSION_OFFLINE}
};
- enum vdo_compression_state *r = context;
+ enum dm_vdo_compression_state *r = context;
unsigned i;
for (i = 0; i < DM_ARRAY_SIZE(_table); i++) {
if (_tok_eq(b, e, _table[i].str)) {
@@ -88,18 +89,18 @@ static bool _parse_index_state(const char *b, const char *e, void *context)
{
static const struct {
const char str[8];
- enum vdo_index_state state;
+ enum dm_vdo_index_state state;
} _table[] = {
- {"error", VDO_INDEX_ERROR},
- {"closed", VDO_INDEX_CLOSED},
- {"opening", VDO_INDEX_OPENING},
- {"closing", VDO_INDEX_CLOSING},
- {"offline", VDO_INDEX_OFFLINE},
- {"online", VDO_INDEX_ONLINE},
- {"unknown", VDO_INDEX_UNKNOWN}
+ {"error", DM_VDO_INDEX_ERROR},
+ {"closed", DM_VDO_INDEX_CLOSED},
+ {"opening", DM_VDO_INDEX_OPENING},
+ {"closing", DM_VDO_INDEX_CLOSING},
+ {"offline", DM_VDO_INDEX_OFFLINE},
+ {"online", DM_VDO_INDEX_ONLINE},
+ {"unknown", DM_VDO_INDEX_UNKNOWN}
};
- enum vdo_index_state *r = context;
+ enum dm_vdo_index_state *r = context;
unsigned i;
for (i = 0; i < DM_ARRAY_SIZE(_table); i++) {
if (_tok_eq(b, e, _table[i].str)) {
@@ -145,10 +146,10 @@ static const char *_next_tok(const char *b, const char *e)
return te == b ? NULL : te;
}
-static void _set_error(struct vdo_status_parse_result *result, const char *fmt, ...)
+static void _set_error(struct dm_vdo_status_parse_result *result, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));
-static void _set_error(struct vdo_status_parse_result *result, const char *fmt, ...)
+static void _set_error(struct dm_vdo_status_parse_result *result, const char *fmt, ...)
{
va_list ap;
@@ -160,7 +161,7 @@ static void _set_error(struct vdo_status_parse_result *result, const char *fmt,
static bool _parse_field(const char **b, const char *e,
bool (*p_fn)(const char *, const char *, void *),
void *field, const char *field_name,
- struct vdo_status_parse_result *result)
+ struct dm_vdo_status_parse_result *result)
{
const char *te;
@@ -180,13 +181,13 @@ static bool _parse_field(const char **b, const char *e,
}
-bool vdo_status_parse(struct dm_pool *mem, const char *input,
- struct vdo_status_parse_result *result)
+bool dm_vdo_status_parse(struct dm_pool *mem, const char *input,
+ struct dm_vdo_status_parse_result *result)
{
const char *b = b = input;
const char *e = input + strlen(input);
const char *te;
- struct vdo_status *s;
+ struct dm_vdo_status *s;
s = (!mem) ? zalloc(sizeof(*s)) : dm_pool_zalloc(mem, sizeof(*s));
diff --git a/device_mapper/vdo/target.h b/device_mapper/vdo/target.h
index edf72a6..3d8722b 100644
--- a/device_mapper/vdo/target.h
+++ b/device_mapper/vdo/target.h
@@ -20,51 +20,51 @@
//----------------------------------------------------------------
-enum vdo_operating_mode {
- VDO_MODE_RECOVERING,
- VDO_MODE_READ_ONLY,
- VDO_MODE_NORMAL
+enum dm_vdo_operating_mode {
+ DM_VDO_MODE_RECOVERING,
+ DM_VDO_MODE_READ_ONLY,
+ DM_VDO_MODE_NORMAL
};
-enum vdo_compression_state {
- VDO_COMPRESSION_ONLINE,
- VDO_COMPRESSION_OFFLINE
+enum dm_vdo_compression_state {
+ DM_VDO_COMPRESSION_ONLINE,
+ DM_VDO_COMPRESSION_OFFLINE
};
-enum vdo_index_state {
- VDO_INDEX_ERROR,
- VDO_INDEX_CLOSED,
- VDO_INDEX_OPENING,
- VDO_INDEX_CLOSING,
- VDO_INDEX_OFFLINE,
- VDO_INDEX_ONLINE,
- VDO_INDEX_UNKNOWN
+enum dm_vdo_index_state {
+ DM_VDO_INDEX_ERROR,
+ DM_VDO_INDEX_CLOSED,
+ DM_VDO_INDEX_OPENING,
+ DM_VDO_INDEX_CLOSING,
+ DM_VDO_INDEX_OFFLINE,
+ DM_VDO_INDEX_ONLINE,
+ DM_VDO_INDEX_UNKNOWN
};
-struct vdo_status {
+struct dm_vdo_status {
char *device;
- enum vdo_operating_mode operating_mode;
+ enum dm_vdo_operating_mode operating_mode;
bool recovering;
- enum vdo_index_state index_state;
- enum vdo_compression_state compression_state;
+ enum dm_vdo_index_state index_state;
+ enum dm_vdo_compression_state compression_state;
uint64_t used_blocks;
uint64_t total_blocks;
};
-void vdo_status_destroy(struct vdo_status *s);
+void dm_vdo_status_destroy(struct dm_vdo_status *s);
#define VDO_MAX_ERROR 256
-struct vdo_status_parse_result {
+struct dm_vdo_status_parse_result {
char error[VDO_MAX_ERROR];
- struct vdo_status *status;
+ struct dm_vdo_status *status;
};
struct dm_pool;
// Parses the status line from the kernel target.
-bool vdo_status_parse(struct dm_pool *mem, const char *input,
- struct vdo_status_parse_result *result);
+bool dm_vdo_status_parse(struct dm_pool *mem, const char *input,
+ struct dm_vdo_status_parse_result *result);
//----------------------------------------------------------------
5 years, 9 months
master - allocation: add check for passing log allocation
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e9d1f676b3768844471...
Commit: e9d1f676b3768844471f8c6d3345a1b60bc2c94e
Parent: 333eb8667e73439c71dc351a02612c1c7601e8ec
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Jul 9 00:54:16 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 9 00:59:34 2018 +0200
allocation: add check for passing log allocation
Updates previous commit.
---
lib/metadata/lv_manip.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 7674a3e..6bf851e 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -2966,7 +2966,9 @@ static int _find_some_parallel_space(struct alloc_handle *ah,
(*(alloc_state->areas + alloc_state->num_positional_areas + ix - 1 -
too_small_for_log_count)).used < ah->log_len)
too_small_for_log_count++;
- if (ah->mirror_logs_separate && (too_small_for_log_count >= devices_needed))
+ if (ah->mirror_logs_separate &&
+ too_small_for_log_count &&
+ (too_small_for_log_count >= devices_needed))
return 1;
if ((alloc_state->num_positional_areas + ix) < (too_small_for_log_count + ah->log_area_count))
return 1;
5 years, 9 months
master - tests: check how thin-pool allocation works
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=333eb8667e73439c71d...
Commit: 333eb8667e73439c71dc351a02612c1c7601e8ec
Parent: 6d1c983122bc2a17bbfbac234f9a73ee9c27f161
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 8 23:24:58 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 9 00:23:35 2018 +0200
tests: check how thin-pool allocation works
Check allocation of thin-pool works on 2PVs, when one is so full,
that even metadata do not fit there (as they need at least 2M,
while 99% of 63MB fills >62MB)
---
test/shell/lvcreate-thin.sh | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/test/shell/lvcreate-thin.sh b/test/shell/lvcreate-thin.sh
index 8e04c9e..9ca7f11 100644
--- a/test/shell/lvcreate-thin.sh
+++ b/test/shell/lvcreate-thin.sh
@@ -199,6 +199,17 @@ check vg_field $vg lv_count 6
lvremove -ff $vg
check vg_field $vg lv_count 0
+
+# Check how allocator works with 2PVs where one is nearly full
+lvcreate -l99%PV $vg "$dev1"
+lvs -a $vg
+# Check when separate metadata is required, allocation needs to fail
+fail lvcreate -L10 -T --poolmetadataspare n --config 'allocation/thin_pool_metadata_require_separate_pvs=1' $vg
+# Check when data and metadata may share the same PV, it shall pass
+lvcreate -L10 -T --poolmetadataspare n --config 'allocation/thin_pool_metadata_require_separate_pvs=0' $vg
+lvremove -f $vg
+
+
# Fail cases
# Too small pool size (1 extent 64KB) for given chunk size
not lvcreate --chunksize 256 -l1 -T $vg/pool1
5 years, 9 months
master - build: libdm preload dir is no longer needed
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a55d4b6051ed2edecf1...
Commit: a55d4b6051ed2edecf14549b8fef437023e1e272
Parent: c8b4f9414cf1f7dde8b73c7085e8c3628205b0eb
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Jul 3 11:12:04 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 9 00:23:32 2018 +0200
build: libdm preload dir is no longer needed
Since we do not build lvm code with libdm, drop preload.
---
WHATS_NEW | 2 ++
conf/Makefile.in | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 4919f24..54d6790 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,7 @@
Version 3.0.0
=============
+ Never send any discard ioctl with test mode.
+ Fix thin-pool alloc which needs same PV for data and metadata.
Extend list of non-memlocked areas with newly linked libs.
Enhance vgcfgrestore to check for active LVs in restored VG.
Configure supports --disable-silent-rules for verbose builds.
diff --git a/conf/Makefile.in b/conf/Makefile.in
index 5330c07..d47c759 100644
--- a/conf/Makefile.in
+++ b/conf/Makefile.in
@@ -32,8 +32,8 @@ include $(top_builddir)/make.tmpl
.PHONY: install_conf install_localconf install_profiles
generate:
- LD_LIBRARY_PATH=$(top_builddir)/libdm:$(LD_LIBRARY_PATH) $(top_builddir)/tools/lvm dumpconfig --type default --unconfigured --withgeneralpreamble --withcomments --ignorelocal --withspaces > example.conf.in
- LD_LIBRARY_PATH=$(top_builddir)/libdm:$(LD_LIBRARY_PATH) $(top_builddir)/tools/lvm dumpconfig --type default --unconfigured --withlocalpreamble --withcomments --withspaces local > lvmlocal.conf.in
+ $(top_builddir)/tools/lvm dumpconfig --type default --unconfigured --withgeneralpreamble --withcomments --ignorelocal --withspaces > example.conf.in
+ $(top_builddir)/tools/lvm dumpconfig --type default --unconfigured --withlocalpreamble --withcomments --withspaces local > lvmlocal.conf.in
install_conf: $(CONFSRC)
@if [ ! -e $(confdir)/$(CONFDEST) ]; then \
5 years, 9 months
master - cleanup: use last_seg
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6d1c983122bc2a17bbf...
Commit: 6d1c983122bc2a17bbfbac234f9a73ee9c27f161
Parent: a55d4b6051ed2edecf14549b8fef437023e1e272
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Jul 7 21:35:07 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 9 00:23:35 2018 +0200
cleanup: use last_seg
More readable code.
---
lib/metadata/lv_manip.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index b315a87..7674a3e 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -3149,9 +3149,8 @@ static int _allocate(struct alloc_handle *ah,
if (ah->alloc == ALLOC_CONTIGUOUS)
can_split = 0;
- if (lv && !dm_list_empty(&lv->segments))
- prev_lvseg = dm_list_item(dm_list_last(&lv->segments),
- struct lv_segment);
+ if (lv)
+ prev_lvseg = last_seg(lv);
/*
* Build the sets of available areas on the pv's.
*/
5 years, 9 months
master - dev_io: no discard in testmode
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c8b4f9414cf1f7dde8b...
Commit: c8b4f9414cf1f7dde8b73c7085e8c3628205b0eb
Parent: b697aa96466b6a5f479df41a213fc1fd583dc743
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 8 21:11:01 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 9 00:19:30 2018 +0200
dev_io: no discard in testmode
When lvm2 command is executed in test mode, discard ioctl is skipped.
This may cause even data-loose in case, issuing discard for released
areas was enabled and user 'tested' lvreduce.
---
lib/device/dev-io.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 43c2c2d..d4210a5 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -405,9 +405,11 @@ static int _dev_discard_blocks(struct device *dev, uint64_t offset_bytes, uint64
discard_range[0] = offset_bytes;
discard_range[1] = size_bytes;
- log_debug_devs("Discarding %" PRIu64 " bytes offset %" PRIu64 " bytes on %s.",
- size_bytes, offset_bytes, dev_name(dev));
- if (ioctl(dev->fd, BLKDISCARD, &discard_range) < 0) {
+ log_debug_devs("Discarding %" PRIu64 " bytes offset %" PRIu64 " bytes on %s. %s",
+ size_bytes, offset_bytes, dev_name(dev),
+ test_mode() ? " (test mode - suppressed)" : "");
+
+ if (!test_mode() && ioctl(dev->fd, BLKDISCARD, &discard_range) < 0) {
log_error("%s: BLKDISCARD ioctl at offset %" PRIu64 " size %" PRIu64 " failed: %s.",
dev_name(dev), offset_bytes, size_bytes, strerror(errno));
if (!dev_close_immediate(dev))
5 years, 9 months
master - allocator: fix thin-pool allocation
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b697aa96466b6a5f479...
Commit: b697aa96466b6a5f479df41a213fc1fd583dc743
Parent: c96400b6c7b8ba5124c045a2ae9475e3224ec284
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 8 18:34:38 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 9 00:19:30 2018 +0200
allocator: fix thin-pool allocation
When allocating thin-pool with more then 1 device - try to
allocate 'metadataLV' with reuse of log-type allocation for mirror LV.
It should be naturally place on other device then 'dataLV'.
However due to somewhat hard to follow allocation logic code,
it's been rejected allocation in cases where there was not
enough space for data or metadata on single PV, thus to successed,
usage of segments was mandatory.
While user may use:
allocation/thin_pool_metadata_require_separate_pvs=1
to enforce separe meta and data LV - on default settings, this is not
enable thus segment allocation is meant to work.
NOTE:
As already said - the original intention of this whole 'if()' is unclear,
so try to split this test into multiple more simple tests that are more readable.
TODO: more validation.
---
lib/metadata/lv_manip.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index a382e27..b315a87 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -2966,12 +2966,14 @@ static int _find_some_parallel_space(struct alloc_handle *ah,
(*(alloc_state->areas + alloc_state->num_positional_areas + ix - 1 -
too_small_for_log_count)).used < ah->log_len)
too_small_for_log_count++;
- ix_log_offset = alloc_state->num_positional_areas + ix - too_small_for_log_count - ah->log_area_count;
+ if (ah->mirror_logs_separate && (too_small_for_log_count >= devices_needed))
+ return 1;
+ if ((alloc_state->num_positional_areas + ix) < (too_small_for_log_count + ah->log_area_count))
+ return 1;
+ ix_log_offset = alloc_state->num_positional_areas + ix - (too_small_for_log_count + ah->log_area_count);
}
- if (ix + alloc_state->num_positional_areas < devices_needed +
- (alloc_state->log_area_count_still_needed ? alloc_state->log_area_count_still_needed +
- too_small_for_log_count : 0))
+ if (ix + alloc_state->num_positional_areas < devices_needed)
return 1;
/*
5 years, 9 months
master - vdo: enhance status parser
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c96400b6c7b8ba5124c...
Commit: c96400b6c7b8ba5124c045a2ae9475e3224ec284
Parent: c1a6b10d09aae6179e4f08c7d8c03d5e3068ad94
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Jun 27 16:18:53 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 2 10:25:35 2018 +0200
vdo: enhance status parser
Add support for using mempool for allocations inside status parser.
Convert some string pointers to arrays.
Reindent tabs.
---
device_mapper/vdo/status.c | 195 +++++++++++++++++++++-----------------------
device_mapper/vdo/target.h | 5 +-
test/unit/vdo_t.c | 4 +-
3 files changed, 98 insertions(+), 106 deletions(-)
diff --git a/device_mapper/vdo/status.c b/device_mapper/vdo/status.c
index f423ca1..7323a35 100644
--- a/device_mapper/vdo/status.c
+++ b/device_mapper/vdo/status.c
@@ -10,28 +10,14 @@
//----------------------------------------------------------------
-static char *_tok_cpy(const char *b, const char *e)
-{
- char *new = malloc((e - b) + 1);
- char *ptr = new;
-
- if (new) {
- while (b != e)
- *ptr++ = *b++;
- *ptr = '\0';
- }
-
- return new;
-}
-
static bool _tok_eq(const char *b, const char *e, const char *str)
{
while (b != e) {
if (!*str || *b != *str)
- return false;
+ return false;
- b++;
- str++;
+ b++;
+ str++;
}
return !*str;
@@ -39,22 +25,22 @@ static bool _tok_eq(const char *b, const char *e, const char *str)
static bool _parse_operating_mode(const char *b, const char *e, void *context)
{
- static struct {
- const char *str;
- enum vdo_operating_mode mode;
+ static const struct {
+ const char str[12];
+ enum vdo_operating_mode mode;
} _table[] = {
- {"recovering", VDO_MODE_RECOVERING},
- {"read-only", VDO_MODE_READ_ONLY},
- {"normal", VDO_MODE_NORMAL}
+ {"recovering", VDO_MODE_RECOVERING},
+ {"read-only", VDO_MODE_READ_ONLY},
+ {"normal", VDO_MODE_NORMAL}
};
- enum vdo_operating_mode *r = context;
+ enum vdo_operating_mode *r = context;
unsigned i;
for (i = 0; i < DM_ARRAY_SIZE(_table); i++) {
- if (_tok_eq(b, e, _table[i].str)) {
- *r = _table[i].mode;
- return true;
- }
+ if (_tok_eq(b, e, _table[i].str)) {
+ *r = _table[i].mode;
+ return true;
+ }
}
return false;
@@ -62,21 +48,21 @@ static bool _parse_operating_mode(const char *b, const char *e, void *context)
static bool _parse_compression_state(const char *b, const char *e, void *context)
{
- static struct {
- const char *str;
- enum vdo_compression_state state;
+ static const struct {
+ const char str[8];
+ enum vdo_compression_state state;
} _table[] = {
- {"online", VDO_COMPRESSION_ONLINE},
- {"offline", VDO_COMPRESSION_OFFLINE}
+ {"online", VDO_COMPRESSION_ONLINE},
+ {"offline", VDO_COMPRESSION_OFFLINE}
};
- enum vdo_compression_state *r = context;
+ enum vdo_compression_state *r = context;
unsigned i;
for (i = 0; i < DM_ARRAY_SIZE(_table); i++) {
- if (_tok_eq(b, e, _table[i].str)) {
- *r = _table[i].state;
- return true;
- }
+ if (_tok_eq(b, e, _table[i].str)) {
+ *r = _table[i].state;
+ return true;
+ }
}
return false;
@@ -84,55 +70,55 @@ static bool _parse_compression_state(const char *b, const char *e, void *context
static bool _parse_recovering(const char *b, const char *e, void *context)
{
- bool *r = context;
+ bool *r = context;
if (_tok_eq(b, e, "recovering"))
*r = true;
else if (_tok_eq(b, e, "-"))
- *r = false;
+ *r = false;
- else
- return false;
+ else
+ return false;
- return true;
+ return true;
}
static bool _parse_index_state(const char *b, const char *e, void *context)
{
- static struct {
- const char *str;
- enum vdo_index_state state;
- } _table[] = {
- {"error", VDO_INDEX_ERROR},
- {"closed", VDO_INDEX_CLOSED},
- {"opening", VDO_INDEX_OPENING},
- {"closing", VDO_INDEX_CLOSING},
- {"offline", VDO_INDEX_OFFLINE},
- {"online", VDO_INDEX_ONLINE},
- {"unknown", VDO_INDEX_UNKNOWN}
- };
-
- enum vdo_index_state *r = context;
+ static const struct {
+ const char str[8];
+ enum vdo_index_state state;
+ } _table[] = {
+ {"error", VDO_INDEX_ERROR},
+ {"closed", VDO_INDEX_CLOSED},
+ {"opening", VDO_INDEX_OPENING},
+ {"closing", VDO_INDEX_CLOSING},
+ {"offline", VDO_INDEX_OFFLINE},
+ {"online", VDO_INDEX_ONLINE},
+ {"unknown", VDO_INDEX_UNKNOWN}
+ };
+
+ enum vdo_index_state *r = context;
unsigned i;
for (i = 0; i < DM_ARRAY_SIZE(_table); i++) {
- if (_tok_eq(b, e, _table[i].str)) {
- *r = _table[i].state;
- return true;
- }
+ if (_tok_eq(b, e, _table[i].str)) {
+ *r = _table[i].state;
+ return true;
+ }
}
- return false;
+ return false;
}
static bool _parse_uint64(const char *b, const char *e, void *context)
{
- uint64_t *r = context, n;
+ uint64_t *r = context, n;
n = 0;
while (b != e) {
- if (!isdigit(*b))
- return false;
+ if (!isdigit(*b))
+ return false;
n = (n * 10) + (*b - '0');
b++;
@@ -145,81 +131,82 @@ static bool _parse_uint64(const char *b, const char *e, void *context)
static const char *_eat_space(const char *b, const char *e)
{
while (b != e && isspace(*b))
- b++;
+ b++;
- return b;
+ return b;
}
static const char *_next_tok(const char *b, const char *e)
{
- const char *te = b;
+ const char *te = b;
while (te != e && !isspace(*te))
- te++;
+ te++;
- return te == b ? NULL : te;
+ return te == b ? NULL : te;
}
static void _set_error(struct vdo_status_parse_result *result, const char *fmt, ...)
- __attribute__ ((format(printf, 2, 3)));
+__attribute__ ((format(printf, 2, 3)));
static void _set_error(struct vdo_status_parse_result *result, const char *fmt, ...)
{
- va_list ap;
+ va_list ap;
- va_start(ap, fmt);
+ va_start(ap, fmt);
vsnprintf(result->error, sizeof(result->error), fmt, ap);
- va_end(ap);
+ va_end(ap);
}
static bool _parse_field(const char **b, const char *e,
- bool (*p_fn)(const char *, const char *, void *),
- void *field, const char *field_name,
- struct vdo_status_parse_result *result)
+ bool (*p_fn)(const char *, const char *, void *),
+ void *field, const char *field_name,
+ struct vdo_status_parse_result *result)
{
- const char *te;
+ const char *te;
- te = _next_tok(*b, e);
- if (!te) {
- _set_error(result, "couldn't get token for '%s'", field_name);
- return false;
- }
+ te = _next_tok(*b, e);
+ if (!te) {
+ _set_error(result, "couldn't get token for '%s'", field_name);
+ return false;
+ }
- if (!p_fn(*b, te, field)) {
- _set_error(result, "couldn't parse '%s'", field_name);
- return false;
- }
+ if (!p_fn(*b, te, field)) {
+ _set_error(result, "couldn't parse '%s'", field_name);
+ return false;
+ }
*b = _eat_space(te, e);
- return true;
+ return true;
}
-bool vdo_status_parse(const char *input, struct vdo_status_parse_result *result)
+bool vdo_status_parse(struct dm_pool *mem, const char *input,
+ struct vdo_status_parse_result *result)
{
const char *b = b = input;
const char *e = input + strlen(input);
const char *te;
- struct vdo_status *s = malloc(sizeof(*s));
+ struct vdo_status *s;
+
+ s = (!mem) ? malloc(sizeof(*s)) : dm_pool_zalloc(mem, sizeof(*s));
if (!s) {
- _set_error(result, "out of memory");
- return false;
+ _set_error(result, "out of memory");
+ return false;
}
b = _eat_space(b, e);
te = _next_tok(b, e);
if (!te) {
- _set_error(result, "couldn't get token for device");
- free(s);
- return false;
+ _set_error(result, "couldn't get token for device");
+ goto bad;
}
- s->device = _tok_cpy(b, te);
- if (!s->device) {
+ if (!(s->device = (!mem) ? malloc((e - b) + 1) : dm_pool_alloc(mem, (e - b) + 1))) {
_set_error(result, "out of memory");
- free(s);
- return false;
+ goto bad;
}
+ dm_strncpy(s->device, b, te - b);
b = _eat_space(te, e);
@@ -237,12 +224,14 @@ bool vdo_status_parse(const char *input, struct vdo_status_parse_result *result)
goto bad;
}
- result->status = s;
- return true;
+ result->status = s;
+ return true;
bad:
- free(s->device);
- free(s);
+ if (s && !mem) {
+ free(s->device);
+ free(s);
+ }
return false;
}
diff --git a/device_mapper/vdo/target.h b/device_mapper/vdo/target.h
index 3137e2c..edf72a6 100644
--- a/device_mapper/vdo/target.h
+++ b/device_mapper/vdo/target.h
@@ -60,8 +60,11 @@ struct vdo_status_parse_result {
struct vdo_status *status;
};
+struct dm_pool;
+
// Parses the status line from the kernel target.
-bool vdo_status_parse(const char *input, struct vdo_status_parse_result *result);
+bool vdo_status_parse(struct dm_pool *mem, const char *input,
+ struct vdo_status_parse_result *result);
//----------------------------------------------------------------
diff --git a/test/unit/vdo_t.c b/test/unit/vdo_t.c
index a26c0b9..7355928 100644
--- a/test/unit/vdo_t.c
+++ b/test/unit/vdo_t.c
@@ -91,7 +91,7 @@ static void _check_good(struct example_good *es, unsigned count)
struct example_good *e = es + i;
struct vdo_status_parse_result pr;
- T_ASSERT(vdo_status_parse(e->input, &pr));
+ T_ASSERT(vdo_status_parse(NULL, e->input, &pr));
#if 0
_print_status(stderr, pr.status);
fprintf(stderr, "\n");
@@ -116,7 +116,7 @@ static void _check_bad(struct example_bad *es, unsigned count)
struct example_bad *e = es + i;
struct vdo_status_parse_result pr;
- T_ASSERT(!vdo_status_parse(e->input, &pr));
+ T_ASSERT(!vdo_status_parse(NULL, e->input, &pr));
T_ASSERT(!strcmp(e->reason, pr.error));
}
}
5 years, 9 months