1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

const: rework conversion to enum

Easier code with string and also avoids mixing enums.
This commit is contained in:
Zdenek Kabelac 2024-05-04 11:25:58 +02:00
parent 5d573cc91d
commit c140601cf6

View File

@ -5001,31 +5001,28 @@ uint64_t *dm_stats_update_regions_from_fd(struct dm_stats *dms, int fd,
#endif /* HAVE_LINUX_FIEMAP */ #endif /* HAVE_LINUX_FIEMAP */
#ifdef DMFILEMAPD #ifdef DMFILEMAPD
static const char *_filemapd_mode_names[] = { static const char _filemapd_mode_names[][8] = {
"inode", "inode",
"path", "path",
NULL
}; };
dm_filemapd_mode_t dm_filemapd_mode_from_string(const char *mode_str) dm_filemapd_mode_t dm_filemapd_mode_from_string(const char *mode_str)
{ {
dm_filemapd_mode_t mode = DM_FILEMAPD_FOLLOW_INODE; static const dm_filemapd_mode_t _mode[] = {
const char **mode_name; DM_FILEMAPD_FOLLOW_INODE,
DM_FILEMAPD_FOLLOW_PATH
};
unsigned i;
if (mode_str) { if (mode_str)
for (mode_name = _filemapd_mode_names; *mode_name; mode_name++) for (i = 0; i < DM_ARRAY_SIZE(_filemapd_mode_names); ++i)
if (!strcmp(*mode_name, mode_str)) if (!strcmp(_filemapd_mode_names[i], mode_str))
break; return _mode[i];
if (*mode_name)
mode = DM_FILEMAPD_FOLLOW_INODE log_error("Could not parse dmfilemapd mode: %s",
+ (mode_name - _filemapd_mode_names); (mode_str) ? mode_str : "");
else {
log_error("Could not parse dmfilemapd mode: %s", return DM_FILEMAPD_FOLLOW_NONE;
mode_str);
return DM_FILEMAPD_FOLLOW_NONE;
}
}
return mode;
} }
#define DM_FILEMAPD "dmfilemapd" #define DM_FILEMAPD "dmfilemapd"