]> sourceware.org Git - lvm2.git/commitdiff
cov: enum health status
authorZdenek Kabelac <zkabelac@redhat.com>
Tue, 7 May 2024 14:33:03 +0000 (16:33 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Tue, 7 May 2024 23:55:21 +0000 (01:55 +0200)
Cleanly map health char status to enum.

device_mapper/libdm-targets.c
libdm/libdm-targets.c

index c0a8f6669b801f09a03ead2d39c3efd58b307c4a..d8a247c138f8cb3e9b10c03a8356b7941eb3a857 100644 (file)
@@ -528,6 +528,21 @@ int dm_get_status_thin(struct dm_pool *mem, const char *params,
        return 1;
 }
 
+static dm_status_mirror_health_t _get_health(char c)
+{
+       switch (c) {
+       case 'A': return DM_STATUS_MIRROR_ALIVE;
+       case 'F': return DM_STATUS_MIRROR_FLUSH_FAILED;
+       case 'D': return DM_STATUS_MIRROR_WRITE_FAILED;
+       case 'S': return DM_STATUS_MIRROR_SYNC_FAILED;
+       case 'R': return DM_STATUS_MIRROR_READ_FAILED;
+       default:
+               log_warn("WARNING: Unknown mirror health status char: %c", c);
+               /* fallback */
+       case 'U': return DM_STATUS_MIRROR_UNCLASSIFIED;
+       }
+}
+
 /*
  * dm core parms:           0 409600 mirror
  * Mirror core parms:       2 253:4 253:5 400/400
@@ -581,7 +596,7 @@ int dm_get_status_mirror(struct dm_pool *mem, const char *params,
        pos += used;
 
        for (i = 0; i < num_devs ; ++i)
-               s->devs[i].health = pos[i];
+               s->devs[i].health = _get_health(pos[i]);
 
        if (!(pos = _skip_fields(pos, argc)))
                goto_out;
@@ -626,7 +641,7 @@ int dm_get_status_mirror(struct dm_pool *mem, const char *params,
                                        goto_out;
 
                        for (i = 0; i < s->log_count; ++i)
-                               s->logs[i].health = pos[i];
+                               s->logs[i].health = _get_health(pos[i]);
                }
        }
 
index a2f838f98c3786c9576be8d9a422198b6ba72e18..9eb11c700760efa46d4b93c550d91b87584f4d30 100644 (file)
@@ -469,6 +469,21 @@ int dm_get_status_thin(struct dm_pool *mem, const char *params,
        return 1;
 }
 
+static dm_status_mirror_health_t _get_health(char c)
+{
+       switch (c) {
+       case 'A': return DM_STATUS_MIRROR_ALIVE;
+       case 'F': return DM_STATUS_MIRROR_FLUSH_FAILED;
+       case 'D': return DM_STATUS_MIRROR_WRITE_FAILED;
+       case 'S': return DM_STATUS_MIRROR_SYNC_FAILED;
+       case 'R': return DM_STATUS_MIRROR_READ_FAILED;
+       default:
+               log_warn("WARNING: Unknown mirror health status char: %c", c);
+               /* fallback */
+       case 'U': return DM_STATUS_MIRROR_UNCLASSIFIED;
+       }
+}
+
 /*
  * dm core parms:           0 409600 mirror
  * Mirror core parms:       2 253:4 253:5 400/400
@@ -522,7 +537,7 @@ int dm_get_status_mirror(struct dm_pool *mem, const char *params,
        pos += used;
 
        for (i = 0; i < num_devs ; ++i)
-               s->devs[i].health = pos[i];
+               s->devs[i].health = _get_health(pos[i]);
 
        if (!(pos = _skip_fields(pos, argc)))
                goto_out;
@@ -567,7 +582,7 @@ int dm_get_status_mirror(struct dm_pool *mem, const char *params,
                                        goto_out;
 
                        for (i = 0; i < s->log_count; ++i)
-                               s->logs[i].health = pos[i];
+                               s->logs[i].health = _get_health(pos[i]);
                }
        }
 
This page took 0.045638 seconds and 5 git commands to generate.