From 29d1533a497be922dc114524b83e926cbb63c34a Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 9 Mar 2016 18:00:57 +0100 Subject: [PATCH] libdm: parse more info from cache status Parse Fail/Error/need_check/ro status info from cache. --- WHATS_NEW_DM | 1 + libdm/libdevmapper.h | 8 +++++++- libdm/libdm-targets.c | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 4cdd97c7e..274d1b965 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.120 - ================================= + Improve parsing of cache status and report Fail, Error, needs_check, ro. Version 1.02.119 - 4th March 2016 ================================= diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index 0b7d5ba9e..ac79a5788 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -361,8 +361,14 @@ struct dm_status_cache { char **core_argv; char *policy_name; - int policy_argc; + int policy_argc; char **policy_argv; + + unsigned error : 1; /* detected error (switches to fail soon) */ + unsigned fail : 1; /* all I/O fails */ + unsigned needs_check : 1; /* metadata needs check */ + unsigned read_only : 1; /* metadata may not be changed */ + uint32_t reserved : 28; }; int dm_get_status_cache(struct dm_pool *mem, const char *params, diff --git a/libdm/libdm-targets.c b/libdm/libdm-targets.c index 7428eba8a..bd6e5e267 100644 --- a/libdm/libdm-targets.c +++ b/libdm/libdm-targets.c @@ -194,6 +194,17 @@ int dm_get_status_cache(struct dm_pool *mem, const char *params, if (!(s = dm_pool_zalloc(mem, sizeof(struct dm_status_cache)))) return_0; + if (strstr(params, "Error")) { + s->error = 1; + s->fail = 1; /* This is also I/O fail state */ + goto out; + } + + if (strstr(params, "Fail")) { + s->fail = 1; + goto out; + } + /* Read in args that have definitive placement */ if (sscanf(params, " %" PRIu32 @@ -258,6 +269,13 @@ int dm_get_status_cache(struct dm_pool *mem, const char *params, (dm_split_words(str, s->policy_argc, 0, s->policy_argv) != s->policy_argc))) goto bad; + /* TODO: improve this parser */ + if (strstr(p, " ro")) + s->read_only = 1; + + if (strstr(p, " needs_check")) + s->needs_check = 1; +out: *status = s; return 1;