diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2015-12-03 15:25:09 +0100 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2015-12-03 18:00:38 +0100 |
commit | c15c44a4924e07d96cea04672fbcd45c7d8aa7ab (patch) | |
tree | 7f85f6e7f9158fdbff7b1cd075257ed6ca798e09 | |
parent | aec58c862064e2b9dd5b0ebb54473340ebd97f7f (diff) | |
download | lvm2-c15c44a4924e07d96cea04672fbcd45c7d8aa7ab.tar.gz |
uuid: add id_read_format_try
Provide id_read_format() functionality without log_error
when ID is not valid one - it will just return 0.
Does not need to use log_suppress() then.
-rw-r--r-- | WHATS_NEW | 1 | ||||
-rw-r--r-- | lib/uuid/uuid.c | 33 | ||||
-rw-r--r-- | lib/uuid/uuid.h | 4 |
3 files changed, 31 insertions, 7 deletions
@@ -1,5 +1,6 @@ Version 2.02.137 - ===================================== + Added internal id_read_format_try() function to check and read valid UUID. Use dm_get_status_mirror() instead of individual parsers. Add mem pool arg for check_transient_status() target function. Avoid misleading error with -m is omitted with lvconvert to raid types. diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c index 67162dd50..cfc58b0a9 100644 --- a/lib/uuid/uuid.c +++ b/lib/uuid/uuid.c @@ -132,7 +132,7 @@ static void _build_inverse(void) _inverse_c[(int) *ptr] = (char) 0x1; } -int id_valid(struct id *id) +static int _id_valid(struct id *id, int e) { int i; @@ -140,13 +140,20 @@ int id_valid(struct id *id) for (i = 0; i < ID_LEN; i++) if (!_inverse_c[id->uuid[i]]) { - log_error("UUID contains invalid character '%c'", id->uuid[i]); + if (e) + log_error("UUID contains invalid character '%c'", id->uuid[i]); return 0; } return 1; } +int id_valid(struct id *id) +{ + return _id_valid(id, 1); +} + + int id_equal(const struct id *lhs, const struct id *rhs) { return !memcmp(lhs->uuid, rhs->uuid, sizeof(lhs->uuid)); @@ -179,7 +186,7 @@ int id_write_format(const struct id *id, char *buffer, size_t size) return 1; } -int id_read_format(struct id *id, const char *buffer) +static int _id_read_format(struct id *id, const char *buffer, int e) { int out = 0; @@ -192,7 +199,8 @@ int id_read_format(struct id *id, const char *buffer) } if (out >= ID_LEN) { - log_error("Too many characters to be uuid."); + if (e) + log_error("Too many characters to be uuid."); return 0; } @@ -200,12 +208,23 @@ int id_read_format(struct id *id, const char *buffer) } if (out != ID_LEN) { - log_error("Couldn't read uuid: incorrect number of " - "characters."); + if (e) + log_error("Couldn't read uuid: incorrect number of " + "characters."); return 0; } - return id_valid(id); + return _id_valid(id, e); +} + +int id_read_format(struct id *id, const char *buffer) +{ + return _id_read_format(id, buffer, 1); +} + +int id_read_format_try(struct id *id, const char *buffer) +{ + return _id_read_format(id, buffer, 0); } char *id_format_and_copy(struct dm_pool *mem, const struct id *id) diff --git a/lib/uuid/uuid.h b/lib/uuid/uuid.h index d87de7374..8ca6352f6 100644 --- a/lib/uuid/uuid.h +++ b/lib/uuid/uuid.h @@ -56,6 +56,10 @@ int id_write_format(const struct id *id, char *buffer, size_t size); * Reads a formatted uuid. */ int id_read_format(struct id *id, const char *buffer); +/* + * Tries to read a formatted uuid without logging error for invalid ID + */ +int id_read_format_try(struct id *id, const char *buffer); char *id_format_and_copy(struct dm_pool *mem, const struct id *id); |