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

refactor: update dm_strncpy to _dm_strncpy

For checked versions of dm_strncpy use inline wrapper _dm_strncpy.
This commit is contained in:
Zdenek Kabelac 2024-04-04 18:42:24 +02:00
parent 995ff58903
commit f9fefaaabe
18 changed files with 27 additions and 24 deletions

View File

@ -452,7 +452,7 @@ static int _clog_ctr(char *uuid, uint64_t luid,
lc->skip_bit_warning = region_count;
lc->disk_fd = -1;
lc->log_dev_failed = 0;
if (!dm_strncpy(lc->uuid, uuid, DM_UUID_LEN)) {
if (!_dm_strncpy(lc->uuid, uuid, DM_UUID_LEN)) {
LOG_ERROR("Cannot use too long UUID %s.", uuid);
r = -EINVAL;
goto fail;

View File

@ -641,7 +641,7 @@ static int _is_usable_uuid(const struct device *dev, const char *name, const cha
/* Recognize some older reserved LVs just from the LV name (snapshot, pvmove...) */
vgname = vg_name;
if (!dm_strncpy(vg_name, name, sizeof(vg_name)) ||
if (!_dm_strncpy(vg_name, name, sizeof(vg_name)) ||
!dm_split_lvm_name(NULL, NULL, &vgname, &lvname, &layer))
return_0;

View File

@ -861,7 +861,7 @@ static int _insert_dir(const char *dir)
char path[PATH_MAX];
size_t len;
if (!dm_strncpy(path, dir, sizeof(path) - 1)) {
if (!_dm_strncpy(path, dir, sizeof(path))) {
log_debug_devs("Dir path %s is too long", path);
return 0;
}
@ -876,7 +876,7 @@ static int _insert_dir(const char *dir)
if (dirent[n]->d_name[0] == '.')
continue;
if (!dm_strncpy(path + len, dirent[n]->d_name, sizeof(path) - len)) {
if (!_dm_strncpy(path + len, dirent[n]->d_name, sizeof(path) - len)) {
log_debug_devs("Path %s/%s is too long.", dir, dirent[n]->d_name);
r = 0;
continue;

View File

@ -278,7 +278,7 @@ int fs_mount_state_is_misnamed(struct cmd_context *cmd, struct logical_volume *l
continue;
if (stme.st_dev != st_lv.st_rdev)
continue;
if (!dm_strncpy(mtab_mntpath, me->mnt_dir, sizeof(mtab_mntpath)))
if (!_dm_strncpy(mtab_mntpath, me->mnt_dir, sizeof(mtab_mntpath)))
continue; /* Ignore too long unsupported paths */
break;
}

View File

@ -837,18 +837,18 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
vgname = split[3];
if (name && !strncmp(name, "scan:", 5))
if (!dm_strncpy(hint.name, name + 5, sizeof(hint.name)))
if (!_dm_strncpy(hint.name, name + 5, sizeof(hint.name)))
continue;
if (pvid && !strncmp(pvid, "pvid:", 5))
if (!dm_strncpy(hint.pvid, pvid + 5, sizeof(hint.pvid)))
if (!_dm_strncpy(hint.pvid, pvid + 5, sizeof(hint.pvid)))
continue;
if (devn && sscanf(devn, "devn:%d:%d", &major, &minor) == 2)
hint.devt = makedev(major, minor);
if (vgname && (strlen(vgname) > 3) && (vgname[4] != '-'))
if (!dm_strncpy(hint.vgname, vgname + 3, sizeof(hint.vgname)))
if (!_dm_strncpy(hint.vgname, vgname + 3, sizeof(hint.vgname)))
continue;
if (!(alloc_hint = zalloc(sizeof(struct hint)))) {

View File

@ -77,7 +77,7 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd,
/* Get lockfile directory from config file */
locking_dir = find_config_tree_str(cmd, global_locking_dir_CFG, NULL);
if (!dm_strncpy(_lock_dir, locking_dir, sizeof(_lock_dir))) {
if (!_dm_strncpy(_lock_dir, locking_dir, sizeof(_lock_dir))) {
log_error("Path for locking_dir %s is invalid.", locking_dir);
return 0;
}

View File

@ -206,7 +206,7 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str
if (!_blocking_supported)
flags |= LCK_NONBLOCK;
if (!dm_strncpy(resource, vol, sizeof(resource))) {
if (!_dm_strncpy(resource, vol, sizeof(resource))) {
log_error(INTERNAL_ERROR "Resource name %s is too long.", vol);
return 0;
}

View File

@ -887,7 +887,7 @@ int vg_remove_pool_metadata_spare(struct volume_group *vg)
lv_set_visible(lv);
/* Cut off suffix _pmspare */
if (!dm_strncpy(new_name, lv->name, sizeof(new_name)) ||
if (!_dm_strncpy(new_name, lv->name, sizeof(new_name)) ||
!(c = strchr(new_name, '_'))) {
log_error(INTERNAL_ERROR "LV %s has no suffix for pool metadata spare.",
display_lvname(lv));

View File

@ -146,7 +146,7 @@ static void _rename_detached_cvol(struct cmd_context *cmd, struct logical_volume
* Failing to rename is not really a problem, so we intentionally
* do not consider some things here as errors.
*/
if (!dm_strncpy(cvol_name, lv_fast->name, sizeof(cvol_name)) ||
if (!_dm_strncpy(cvol_name, lv_fast->name, sizeof(cvol_name)) ||
!(suffix = strstr(cvol_name, "_cvol"))) {
log_debug("LV %s has no suffix for cachevol (skipping rename).",
display_lvname(lv_fast));

View File

@ -302,7 +302,7 @@ int drop_lvname_suffix(char *new_name, const char *name, const char *suffix)
{
char *c;
if (!dm_strncpy(new_name, name, NAME_LEN)) {
if (!_dm_strncpy(new_name, name, NAME_LEN)) {
log_debug(INTERNAL_ERROR "Name is too long.");
return 0;
}

View File

@ -36,7 +36,7 @@ daemon_handle daemon_open(daemon_info i)
goto error;
}
if (!dm_strncpy(sockaddr.sun_path, i.socket, sizeof(sockaddr.sun_path))) {
if (!_dm_strncpy(sockaddr.sun_path, i.socket, sizeof(sockaddr.sun_path))) {
log_error("%s: Daemon socket path too long.", i.socket);
goto error;
}

View File

@ -249,7 +249,7 @@ static int _open_socket(daemon_state s)
fprintf(stderr, "setting O_NONBLOCK on socket fd %d failed: %s\n", fd, strerror(errno));
fprintf(stderr, "[D] creating %s\n", s.socket_path);
if (!dm_strncpy(sockaddr.sun_path, s.socket_path, sizeof(sockaddr.sun_path))) {
if (!_dm_strncpy(sockaddr.sun_path, s.socket_path, sizeof(sockaddr.sun_path))) {
fprintf(stderr, "%s: daemon socket path too long.\n", s.socket_path);
goto error;
}

View File

@ -6608,7 +6608,7 @@ static char *_parse_loop_device_name(const char *dev, const char *dev_dir)
device[strlen(dev_dir)] != '/')
goto_bad;
if (!dm_strncpy(buf, strrchr(device, '/') + 1, PATH_MAX))
if (!_dm_strncpy(buf, strrchr(device, '/') + 1, PATH_MAX))
goto_bad;
free(device);
} else {
@ -6616,7 +6616,7 @@ static char *_parse_loop_device_name(const char *dev, const char *dev_dir)
if (strncmp(dev, "loop", sizeof("loop") - 1))
goto_bad;
if (!dm_strncpy(buf, dev, PATH_MAX))
if (!_dm_strncpy(buf, dev, PATH_MAX))
goto_bad;
}

View File

@ -1916,7 +1916,7 @@ static char *_build_group_tag(struct dm_stats *dms, uint64_t group_id)
return NULL;
}
if (!dm_strncpy(buf, DMS_GROUP_TAG, DMS_GROUP_TAG_LEN + 1))
if (!_dm_strncpy(buf, DMS_GROUP_TAG, DMS_GROUP_TAG_LEN + 1))
goto_bad;
buf += DMS_GROUP_TAG_LEN;

View File

@ -64,6 +64,9 @@ static int dm_strncpy(char *dest, const char *src, size_t n)
return 0;
}
static inline int _dm_strncpy(char *dest, const char *src, size_t n) {
return dm_strncpy(dest, src, n);
}
static char *dm_pool_strdup(void *p, const char *str)
{
@ -347,7 +350,7 @@ static int _val_str_to_num(char *str)
/* compare the name before any suffix like _new or _<lvtype> */
if (!dm_strncpy(name, str, sizeof(name)))
if (!_dm_strncpy(name, str, sizeof(name)))
return 0; /* Buffer is too short */
if ((new = strchr(name, '_')))
@ -374,7 +377,7 @@ static int _opt_str_to_num(struct command *cmd, const char *str)
int i;
int first = 0, last = ARG_COUNT - 1, middle;
if (!dm_strncpy(long_name, str, sizeof(long_name)))
if (!_dm_strncpy(long_name, str, sizeof(long_name)))
goto err;
if ((p = strstr(long_name, "_long")))

View File

@ -155,7 +155,7 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv,
dm_list_init(&untrim_list);
if (!dm_strncpy(sublv_name, lv_name, sizeof(sublv_name))) {
if (!_dm_strncpy(sublv_name, lv_name, sizeof(sublv_name))) {
log_error(INTERNAL_ERROR "LV name %s is too long.", lv_name);
return 0;
}
@ -176,7 +176,7 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv,
idx++;
/* Copy idx to local buffer */
if (!dm_strncpy(idx_buf, idx, sizeof(idx_buf))) {
if (!_dm_strncpy(idx_buf, idx, sizeof(idx_buf))) {
log_error(INTERNAL_ERROR "Unexpected LV index %s.", idx);
return 0;
}

View File

@ -1059,7 +1059,7 @@ static int _set_report_prefix_and_name(struct report_args *args,
return 0;
}
if (!dm_strncpy(single_args->report_prefix, report_prefix, sizeof(single_args->report_prefix))) {
if (!_dm_strncpy(single_args->report_prefix, report_prefix, sizeof(single_args->report_prefix))) {
log_error("_set_report_prefix_and_name: dm_strncpy failed");
return 0;
}

View File

@ -52,7 +52,7 @@ static int _check_all_dm_devices(const char *vg_name, unsigned *found)
do {
/* TODO: Do we want to validate UUID LVM- prefix as well ? */
names = (struct dm_names *)((char *) names + next);
if (!dm_strncpy(vgname_buf, names->name, sizeof(vgname_buf))) {
if (!_dm_strncpy(vgname_buf, names->name, sizeof(vgname_buf))) {
r = 0;
goto_out;
}