mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-30 17:18:21 +03:00
cleanup: replace strlen with sizeof
Use the string size from compile time.
This commit is contained in:
parent
eaa4882924
commit
e1fd179dc5
@ -264,19 +264,19 @@ static void format_info_r_action(char *line, char *r_name, char *r_type)
|
|||||||
|
|
||||||
static void format_info_line(char *line, char *r_name, char *r_type)
|
static void format_info_line(char *line, char *r_name, char *r_type)
|
||||||
{
|
{
|
||||||
if (!strncmp(line, "info=structs ", strlen("info=structs "))) {
|
if (!strncmp(line, "info=structs ", sizeof("info=structs ") - 1)) {
|
||||||
/* only print this in the raw info dump */
|
/* only print this in the raw info dump */
|
||||||
|
|
||||||
} else if (!strncmp(line, "info=client ", strlen("info=client "))) {
|
} else if (!strncmp(line, "info=client ", sizeof("info=client ") - 1)) {
|
||||||
save_client_info(line);
|
save_client_info(line);
|
||||||
|
|
||||||
} else if (!strncmp(line, "info=ls ", strlen("info=ls "))) {
|
} else if (!strncmp(line, "info=ls ", sizeof("info=ls ") - 1)) {
|
||||||
format_info_ls(line);
|
format_info_ls(line);
|
||||||
|
|
||||||
} else if (!strncmp(line, "info=ls_action ", strlen("info=ls_action "))) {
|
} else if (!strncmp(line, "info=ls_action ", sizeof("info=ls_action ") - 1)) {
|
||||||
format_info_ls_action(line);
|
format_info_ls_action(line);
|
||||||
|
|
||||||
} else if (!strncmp(line, "info=r ", strlen("info=r "))) {
|
} else if (!strncmp(line, "info=r ", sizeof("info=r ") - 1)) {
|
||||||
/*
|
/*
|
||||||
* r_name/r_type are reset when a new resource is found.
|
* r_name/r_type are reset when a new resource is found.
|
||||||
* They are reused for the lock and action lines that
|
* They are reused for the lock and action lines that
|
||||||
@ -286,11 +286,11 @@ static void format_info_line(char *line, char *r_name, char *r_type)
|
|||||||
memset(r_type, 0, MAX_NAME+1);
|
memset(r_type, 0, MAX_NAME+1);
|
||||||
format_info_r(line, r_name, r_type);
|
format_info_r(line, r_name, r_type);
|
||||||
|
|
||||||
} else if (!strncmp(line, "info=lk ", strlen("info=lk "))) {
|
} else if (!strncmp(line, "info=lk ", sizeof("info=lk ") - 1)) {
|
||||||
/* will use info from previous r */
|
/* will use info from previous r */
|
||||||
format_info_lk(line, r_name, r_type);
|
format_info_lk(line, r_name, r_type);
|
||||||
|
|
||||||
} else if (!strncmp(line, "info=r_action ", strlen("info=r_action "))) {
|
} else if (!strncmp(line, "info=r_action ", sizeof("info=r_action ") - 1)) {
|
||||||
/* will use info from previous r */
|
/* will use info from previous r */
|
||||||
format_info_r_action(line, r_name, r_type);
|
format_info_r_action(line, r_name, r_type);
|
||||||
} else {
|
} else {
|
||||||
|
@ -737,7 +737,7 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
|
|||||||
* list of devs used by this cmd
|
* list of devs used by this cmd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
keylen = strlen("hints_version:");
|
keylen = sizeof("hints_version:") - 1;
|
||||||
if (!strncmp(_hint_line, "hints_version:", keylen)) {
|
if (!strncmp(_hint_line, "hints_version:", keylen)) {
|
||||||
if (sscanf(_hint_line + keylen, "%d.%d", &hv_major, &hv_minor) != 2) {
|
if (sscanf(_hint_line + keylen, "%d.%d", &hv_major, &hv_minor) != 2) {
|
||||||
log_debug("ignore hints with unknown version %d.%d", hv_major, hv_minor);
|
log_debug("ignore hints with unknown version %d.%d", hv_major, hv_minor);
|
||||||
@ -754,7 +754,7 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
keylen = strlen("global_filter:");
|
keylen = sizeof("global_filter:") - 1;
|
||||||
if (!strncmp(_hint_line, "global_filter:", keylen)) {
|
if (!strncmp(_hint_line, "global_filter:", keylen)) {
|
||||||
_filter_to_str(cmd, devices_global_filter_CFG, &filter_str);
|
_filter_to_str(cmd, devices_global_filter_CFG, &filter_str);
|
||||||
if (!filter_str || strcmp(filter_str, _hint_line + keylen)) {
|
if (!filter_str || strcmp(filter_str, _hint_line + keylen)) {
|
||||||
@ -767,7 +767,7 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
keylen = strlen("filter:");
|
keylen = sizeof("filter:") - 1;
|
||||||
if (!strncmp(_hint_line, "filter:", keylen)) {
|
if (!strncmp(_hint_line, "filter:", keylen)) {
|
||||||
_filter_to_str(cmd, devices_filter_CFG, &filter_str);
|
_filter_to_str(cmd, devices_filter_CFG, &filter_str);
|
||||||
if (!filter_str || strcmp(filter_str, _hint_line + keylen)) {
|
if (!filter_str || strcmp(filter_str, _hint_line + keylen)) {
|
||||||
@ -780,7 +780,7 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
keylen = strlen("scan_lvs:");
|
keylen = sizeof("scan_lvs:") - 1;
|
||||||
if (!strncmp(_hint_line, "scan_lvs:", keylen)) {
|
if (!strncmp(_hint_line, "scan_lvs:", keylen)) {
|
||||||
unsigned scan_lvs = 0;
|
unsigned scan_lvs = 0;
|
||||||
if ((sscanf(_hint_line + keylen, "%u", &scan_lvs) != 1) ||
|
if ((sscanf(_hint_line + keylen, "%u", &scan_lvs) != 1) ||
|
||||||
@ -792,7 +792,7 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
keylen = strlen("devices_file:");
|
keylen = sizeof("devices_file:") - 1;
|
||||||
if (!strncmp(_hint_line, "devices_file:", keylen)) {
|
if (!strncmp(_hint_line, "devices_file:", keylen)) {
|
||||||
const char *df_hint = _hint_line + keylen;
|
const char *df_hint = _hint_line + keylen;
|
||||||
const char *df_config = find_config_tree_str(cmd, devices_devicesfile_CFG, NULL);
|
const char *df_config = find_config_tree_str(cmd, devices_devicesfile_CFG, NULL);
|
||||||
@ -811,7 +811,7 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
keylen = strlen("devs_hash:");
|
keylen = sizeof("devs_hash:") - 1;
|
||||||
if (!strncmp(_hint_line, "devs_hash:", keylen)) {
|
if (!strncmp(_hint_line, "devs_hash:", keylen)) {
|
||||||
if (sscanf(_hint_line + keylen, "%u %u", &read_hash, &read_count) != 2) {
|
if (sscanf(_hint_line + keylen, "%u %u", &read_hash, &read_count) != 2) {
|
||||||
log_debug("ignore hints with invalid devs_hash");
|
log_debug("ignore hints with invalid devs_hash");
|
||||||
@ -824,7 +824,7 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
|
|||||||
/*
|
/*
|
||||||
* Ignore any other line prefixes that we don't recognize.
|
* Ignore any other line prefixes that we don't recognize.
|
||||||
*/
|
*/
|
||||||
keylen = strlen("scan:");
|
keylen = sizeof("scan:") - 1;
|
||||||
if (strncmp(_hint_line, "scan:", keylen))
|
if (strncmp(_hint_line, "scan:", keylen))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -5050,7 +5050,7 @@ static int _clear_meta_lvs(struct logical_volume *lv)
|
|||||||
static int _rename_area_lvs(struct logical_volume *lv, const char *suffix)
|
static int _rename_area_lvs(struct logical_volume *lv, const char *suffix)
|
||||||
{
|
{
|
||||||
uint32_t s;
|
uint32_t s;
|
||||||
size_t sz = strlen("rimage") + (suffix ? strlen(suffix) : 0) + 1;
|
size_t sz = sizeof("rimage") - 1 + (suffix ? strlen(suffix) : 0) + 1;
|
||||||
char *sfx[SLV_COUNT] = { NULL, NULL };
|
char *sfx[SLV_COUNT] = { NULL, NULL };
|
||||||
struct lv_segment *seg = first_seg(lv);
|
struct lv_segment *seg = first_seg(lv);
|
||||||
|
|
||||||
|
22
tools/pvck.c
22
tools/pvck.c
@ -1756,69 +1756,69 @@ static int _dump_search(struct cmd_context *cmd, const char *dump, struct settin
|
|||||||
|
|
||||||
static int _get_one_setting(struct cmd_context *cmd, struct settings *set, char *key, char *val)
|
static int _get_one_setting(struct cmd_context *cmd, struct settings *set, char *key, char *val)
|
||||||
{
|
{
|
||||||
if (!strncmp(key, "metadata_offset", strlen("metadata_offset"))) {
|
if (!strncmp(key, "metadata_offset", sizeof("metadata_offset") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&set->metadata_offset) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&set->metadata_offset) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
set->metadata_offset_set = 1;
|
set->metadata_offset_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "seqno", strlen("seqno"))) {
|
if (!strncmp(key, "seqno", sizeof("seqno") - 1)) {
|
||||||
if (sscanf(val, "%u", &set->seqno) != 1)
|
if (sscanf(val, "%u", &set->seqno) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
set->seqno_set = 1;
|
set->seqno_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "backup_file", strlen("backup_file"))) {
|
if (!strncmp(key, "backup_file", sizeof("backup_file") - 1)) {
|
||||||
if ((set->backup_file = dm_pool_strdup(cmd->mem, val)))
|
if ((set->backup_file = dm_pool_strdup(cmd->mem, val)))
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "mda_offset", strlen("mda_offset"))) {
|
if (!strncmp(key, "mda_offset", sizeof("mda_offset") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&set->mda_offset) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&set->mda_offset) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
set->mda_offset_set = 1;
|
set->mda_offset_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "mda_size", strlen("mda_size"))) {
|
if (!strncmp(key, "mda_size", sizeof("mda_size") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&set->mda_size) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&set->mda_size) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
set->mda_size_set = 1;
|
set->mda_size_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "mda2_offset", strlen("mda2_offset"))) {
|
if (!strncmp(key, "mda2_offset", sizeof("mda2_offset") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&set->mda2_offset) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&set->mda2_offset) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
set->mda2_offset_set = 1;
|
set->mda2_offset_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "mda2_size", strlen("mda2_size"))) {
|
if (!strncmp(key, "mda2_size", sizeof("mda2_size") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&set->mda2_size) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&set->mda2_size) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
set->mda2_size_set = 1;
|
set->mda2_size_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "device_size", strlen("device_size"))) {
|
if (!strncmp(key, "device_size", sizeof("device_size") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&set->device_size) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&set->device_size) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
set->device_size_set = 1;
|
set->device_size_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "data_offset", strlen("data_offset"))) {
|
if (!strncmp(key, "data_offset", sizeof("data_offset") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&set->data_offset) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&set->data_offset) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
set->data_offset_set = 1;
|
set->data_offset_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "pv_uuid", strlen("pv_uuid"))) {
|
if (!strncmp(key, "pv_uuid", sizeof("pv_uuid") - 1)) {
|
||||||
if (strchr(val, '-') && (strlen(val) == 32)) {
|
if (strchr(val, '-') && (strlen(val) == 32)) {
|
||||||
memcpy(&set->pv_id, val, 32);
|
memcpy(&set->pv_id, val, 32);
|
||||||
set->pvid_set = 1;
|
set->pvid_set = 1;
|
||||||
@ -1832,7 +1832,7 @@ static int _get_one_setting(struct cmd_context *cmd, struct settings *set, char
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "mda_num", strlen("mda_num"))) {
|
if (!strncmp(key, "mda_num", sizeof("mda_num") - 1)) {
|
||||||
if (sscanf(val, "%u", (int *)&set->mda_num) != 1)
|
if (sscanf(val, "%u", (int *)&set->mda_num) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1405,7 +1405,7 @@ static int _get_one_writecache_setting(struct cmd_context *cmd, struct writecach
|
|||||||
char *key, char *val, uint32_t *block_size_sectors)
|
char *key, char *val, uint32_t *block_size_sectors)
|
||||||
{
|
{
|
||||||
/* special case: block_size is not a setting but is set with the --cachesettings option */
|
/* special case: block_size is not a setting but is set with the --cachesettings option */
|
||||||
if (!strncmp(key, "block_size", strlen("block_size"))) {
|
if (!strncmp(key, "block_size", sizeof("block_size") - 1)) {
|
||||||
uint32_t block_size = 0;
|
uint32_t block_size = 0;
|
||||||
if (sscanf(val, "%u", &block_size) != 1)
|
if (sscanf(val, "%u", &block_size) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
@ -1418,7 +1418,7 @@ static int _get_one_writecache_setting(struct cmd_context *cmd, struct writecach
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "high_watermark", strlen("high_watermark"))) {
|
if (!strncmp(key, "high_watermark", sizeof("high_watermark") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&settings->high_watermark) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&settings->high_watermark) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
if (settings->high_watermark > 100)
|
if (settings->high_watermark > 100)
|
||||||
@ -1427,7 +1427,7 @@ static int _get_one_writecache_setting(struct cmd_context *cmd, struct writecach
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "low_watermark", strlen("low_watermark"))) {
|
if (!strncmp(key, "low_watermark", sizeof("low_watermark") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&settings->low_watermark) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&settings->low_watermark) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
if (settings->low_watermark > 100)
|
if (settings->low_watermark > 100)
|
||||||
@ -1436,28 +1436,28 @@ static int _get_one_writecache_setting(struct cmd_context *cmd, struct writecach
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "writeback_jobs", strlen("writeback_jobs"))) {
|
if (!strncmp(key, "writeback_jobs", sizeof("writeback_jobs") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&settings->writeback_jobs) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&settings->writeback_jobs) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
settings->writeback_jobs_set = 1;
|
settings->writeback_jobs_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "autocommit_blocks", strlen("autocommit_blocks"))) {
|
if (!strncmp(key, "autocommit_blocks", sizeof("autocommit_blocks") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&settings->autocommit_blocks) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&settings->autocommit_blocks) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
settings->autocommit_blocks_set = 1;
|
settings->autocommit_blocks_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "autocommit_time", strlen("autocommit_time"))) {
|
if (!strncmp(key, "autocommit_time", sizeof("autocommit_time") - 1)) {
|
||||||
if (sscanf(val, "%llu", (unsigned long long *)&settings->autocommit_time) != 1)
|
if (sscanf(val, "%llu", (unsigned long long *)&settings->autocommit_time) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
settings->autocommit_time_set = 1;
|
settings->autocommit_time_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "fua", strlen("fua"))) {
|
if (!strncmp(key, "fua", sizeof("fua") - 1)) {
|
||||||
if (settings->nofua_set) {
|
if (settings->nofua_set) {
|
||||||
log_error("Setting fua and nofua cannot both be set.");
|
log_error("Setting fua and nofua cannot both be set.");
|
||||||
return 0;
|
return 0;
|
||||||
@ -1468,7 +1468,7 @@ static int _get_one_writecache_setting(struct cmd_context *cmd, struct writecach
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "nofua", strlen("nofua"))) {
|
if (!strncmp(key, "nofua", sizeof("nofua") - 1)) {
|
||||||
if (settings->fua_set) {
|
if (settings->fua_set) {
|
||||||
log_error("Setting fua and nofua cannot both be set.");
|
log_error("Setting fua and nofua cannot both be set.");
|
||||||
return 0;
|
return 0;
|
||||||
@ -1479,28 +1479,28 @@ static int _get_one_writecache_setting(struct cmd_context *cmd, struct writecach
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "cleaner", strlen("cleaner"))) {
|
if (!strncmp(key, "cleaner", sizeof("cleaner") - 1)) {
|
||||||
if (sscanf(val, "%u", &settings->cleaner) != 1)
|
if (sscanf(val, "%u", &settings->cleaner) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
settings->cleaner_set = 1;
|
settings->cleaner_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "max_age", strlen("max_age"))) {
|
if (!strncmp(key, "max_age", sizeof("max_age") - 1)) {
|
||||||
if (sscanf(val, "%u", &settings->max_age) != 1)
|
if (sscanf(val, "%u", &settings->max_age) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
settings->max_age_set = 1;
|
settings->max_age_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "metadata_only", strlen("metadata_only"))) {
|
if (!strncmp(key, "metadata_only", sizeof("metadata_only") - 1)) {
|
||||||
if (sscanf(val, "%u", &settings->metadata_only) != 1)
|
if (sscanf(val, "%u", &settings->metadata_only) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
settings->metadata_only_set = 1;
|
settings->metadata_only_set = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(key, "pause_writeback", strlen("pause_writeback"))) {
|
if (!strncmp(key, "pause_writeback", sizeof("pause_writeback") - 1)) {
|
||||||
if (sscanf(val, "%u", &settings->pause_writeback) != 1)
|
if (sscanf(val, "%u", &settings->pause_writeback) != 1)
|
||||||
goto_bad;
|
goto_bad;
|
||||||
settings->pause_writeback_set = 1;
|
settings->pause_writeback_set = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user