mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Move lvm_snprintf into libdevmapper.
This commit is contained in:
parent
9e063b223e
commit
0550c1b618
@ -1,6 +1,6 @@
|
|||||||
Version 2.02.10 -
|
Version 2.02.10 -
|
||||||
==================================
|
==================================
|
||||||
Move split_words() and split_dm_name() into libdevmapper.
|
Move lvm_snprintf(), split_words() and split_dm_name() into libdevmapper.
|
||||||
Add lvconvert man page.
|
Add lvconvert man page.
|
||||||
Add mirror options to man pages.
|
Add mirror options to man pages.
|
||||||
Prevent mirror renames.
|
Prevent mirror renames.
|
||||||
|
@ -39,7 +39,7 @@ int lvm1_present(struct cmd_context *cmd)
|
|||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
if (lvm_snprintf(path, sizeof(path), "%s/lvm/global", cmd->proc_dir)
|
if (dm_snprintf(path, sizeof(path), "%s/lvm/global", cmd->proc_dir)
|
||||||
< 0) {
|
< 0) {
|
||||||
log_error("LVM1 proc global snprintf failed");
|
log_error("LVM1 proc global snprintf failed");
|
||||||
return 0;
|
return 0;
|
||||||
@ -257,9 +257,9 @@ static int _passes_activation_filter(struct cmd_context *cmd,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* vgname/lvname */
|
/* vgname/lvname */
|
||||||
if (lvm_snprintf(path, sizeof(path), "%s/%s", lv->vg->name,
|
if (dm_snprintf(path, sizeof(path), "%s/%s", lv->vg->name,
|
||||||
lv->name) < 0) {
|
lv->name) < 0) {
|
||||||
log_error("lvm_snprintf error from %s/%s", lv->vg->name,
|
log_error("dm_snprintf error from %s/%s", lv->vg->name,
|
||||||
lv->name);
|
lv->name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -342,7 +342,7 @@ int target_present(const char *target_name, int use_modprobe)
|
|||||||
if (target_version(target_name, &maj, &min, &patchlevel))
|
if (target_version(target_name, &maj, &min, &patchlevel))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (lvm_snprintf(module, sizeof(module), "dm-%s", target_name)
|
if (dm_snprintf(module, sizeof(module), "dm-%s", target_name)
|
||||||
< 0) {
|
< 0) {
|
||||||
log_error("target_present module name too long: %s",
|
log_error("target_present module name too long: %s",
|
||||||
target_name);
|
target_name);
|
||||||
|
@ -30,7 +30,7 @@ static int _mk_dir(const char *dev_dir, const char *vg_name)
|
|||||||
{
|
{
|
||||||
char vg_path[PATH_MAX];
|
char vg_path[PATH_MAX];
|
||||||
|
|
||||||
if (lvm_snprintf(vg_path, sizeof(vg_path), "%s%s",
|
if (dm_snprintf(vg_path, sizeof(vg_path), "%s%s",
|
||||||
dev_dir, vg_name) == -1) {
|
dev_dir, vg_name) == -1) {
|
||||||
log_error("Couldn't construct name of volume "
|
log_error("Couldn't construct name of volume "
|
||||||
"group directory.");
|
"group directory.");
|
||||||
@ -53,7 +53,7 @@ static int _rm_dir(const char *dev_dir, const char *vg_name)
|
|||||||
{
|
{
|
||||||
char vg_path[PATH_MAX];
|
char vg_path[PATH_MAX];
|
||||||
|
|
||||||
if (lvm_snprintf(vg_path, sizeof(vg_path), "%s%s",
|
if (dm_snprintf(vg_path, sizeof(vg_path), "%s%s",
|
||||||
dev_dir, vg_name) == -1) {
|
dev_dir, vg_name) == -1) {
|
||||||
log_error("Couldn't construct name of volume "
|
log_error("Couldn't construct name of volume "
|
||||||
"group directory.");
|
"group directory.");
|
||||||
@ -87,7 +87,7 @@ static void _rm_blks(const char *dir)
|
|||||||
if (!strcmp(name, ".") || !strcmp(name, ".."))
|
if (!strcmp(name, ".") || !strcmp(name, ".."))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (lvm_snprintf(path, sizeof(path), "%s/%s", dir, name) == -1) {
|
if (dm_snprintf(path, sizeof(path), "%s/%s", dir, name) == -1) {
|
||||||
log_error("Couldn't create path for %s", name);
|
log_error("Couldn't create path for %s", name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -109,28 +109,28 @@ static int _mk_link(const char *dev_dir, const char *vg_name,
|
|||||||
char vg_path[PATH_MAX];
|
char vg_path[PATH_MAX];
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
if (lvm_snprintf(vg_path, sizeof(vg_path), "%s%s",
|
if (dm_snprintf(vg_path, sizeof(vg_path), "%s%s",
|
||||||
dev_dir, vg_name) == -1) {
|
dev_dir, vg_name) == -1) {
|
||||||
log_error("Couldn't create path for volume group dir %s",
|
log_error("Couldn't create path for volume group dir %s",
|
||||||
vg_name);
|
vg_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(lv_path, sizeof(lv_path), "%s/%s", vg_path,
|
if (dm_snprintf(lv_path, sizeof(lv_path), "%s/%s", vg_path,
|
||||||
lv_name) == -1) {
|
lv_name) == -1) {
|
||||||
log_error("Couldn't create source pathname for "
|
log_error("Couldn't create source pathname for "
|
||||||
"logical volume link %s", lv_name);
|
"logical volume link %s", lv_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(link_path, sizeof(link_path), "%s/%s",
|
if (dm_snprintf(link_path, sizeof(link_path), "%s/%s",
|
||||||
dm_dir(), dev) == -1) {
|
dm_dir(), dev) == -1) {
|
||||||
log_error("Couldn't create destination pathname for "
|
log_error("Couldn't create destination pathname for "
|
||||||
"logical volume link for %s", lv_name);
|
"logical volume link for %s", lv_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(lvm1_group_path, sizeof(lvm1_group_path), "%s/group",
|
if (dm_snprintf(lvm1_group_path, sizeof(lvm1_group_path), "%s/group",
|
||||||
vg_path) == -1) {
|
vg_path) == -1) {
|
||||||
log_error("Couldn't create pathname for LVM1 group file for %s",
|
log_error("Couldn't create pathname for LVM1 group file for %s",
|
||||||
vg_name);
|
vg_name);
|
||||||
@ -190,7 +190,7 @@ static int _rm_link(const char *dev_dir, const char *vg_name,
|
|||||||
struct stat buf;
|
struct stat buf;
|
||||||
char lv_path[PATH_MAX];
|
char lv_path[PATH_MAX];
|
||||||
|
|
||||||
if (lvm_snprintf(lv_path, sizeof(lv_path), "%s%s/%s",
|
if (dm_snprintf(lv_path, sizeof(lv_path), "%s%s/%s",
|
||||||
dev_dir, vg_name, lv_name) == -1) {
|
dev_dir, vg_name, lv_name) == -1) {
|
||||||
log_error("Couldn't determine link pathname.");
|
log_error("Couldn't determine link pathname.");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -67,7 +67,7 @@ static int _get_env_vars(struct cmd_context *cmd)
|
|||||||
|
|
||||||
/* Set to "" to avoid using any system directory */
|
/* Set to "" to avoid using any system directory */
|
||||||
if ((e = getenv("LVM_SYSTEM_DIR"))) {
|
if ((e = getenv("LVM_SYSTEM_DIR"))) {
|
||||||
if (lvm_snprintf(cmd->sys_dir, sizeof(cmd->sys_dir),
|
if (dm_snprintf(cmd->sys_dir, sizeof(cmd->sys_dir),
|
||||||
"%s", e) < 0) {
|
"%s", e) < 0) {
|
||||||
log_error("LVM_SYSTEM_DIR environment variable "
|
log_error("LVM_SYSTEM_DIR environment variable "
|
||||||
"is too long.");
|
"is too long.");
|
||||||
@ -167,7 +167,7 @@ static int _process_config(struct cmd_context *cmd)
|
|||||||
log_verbose("Set umask to %04o", cmd->default_settings.umask);
|
log_verbose("Set umask to %04o", cmd->default_settings.umask);
|
||||||
|
|
||||||
/* dev dir */
|
/* dev dir */
|
||||||
if (lvm_snprintf(cmd->dev_dir, sizeof(cmd->dev_dir), "%s/",
|
if (dm_snprintf(cmd->dev_dir, sizeof(cmd->dev_dir), "%s/",
|
||||||
find_config_tree_str(cmd, "devices/dir",
|
find_config_tree_str(cmd, "devices/dir",
|
||||||
DEFAULT_DEV_DIR)) < 0) {
|
DEFAULT_DEV_DIR)) < 0) {
|
||||||
log_error("Device directory given in config file too long");
|
log_error("Device directory given in config file too long");
|
||||||
@ -178,7 +178,7 @@ static int _process_config(struct cmd_context *cmd)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* proc dir */
|
/* proc dir */
|
||||||
if (lvm_snprintf(cmd->proc_dir, sizeof(cmd->proc_dir), "%s",
|
if (dm_snprintf(cmd->proc_dir, sizeof(cmd->proc_dir), "%s",
|
||||||
find_config_tree_str(cmd, "global/proc",
|
find_config_tree_str(cmd, "global/proc",
|
||||||
DEFAULT_PROC_DIR)) < 0) {
|
DEFAULT_PROC_DIR)) < 0) {
|
||||||
log_error("Device directory given in config file too long");
|
log_error("Device directory given in config file too long");
|
||||||
@ -319,7 +319,7 @@ static int _load_config_file(struct cmd_context *cmd, const char *tag)
|
|||||||
if (*tag)
|
if (*tag)
|
||||||
filler = "_";
|
filler = "_";
|
||||||
|
|
||||||
if (lvm_snprintf(config_file, sizeof(config_file), "%s/lvm%s%s.conf",
|
if (dm_snprintf(config_file, sizeof(config_file), "%s/lvm%s%s.conf",
|
||||||
cmd->sys_dir, filler, tag) < 0) {
|
cmd->sys_dir, filler, tag) < 0) {
|
||||||
log_error("LVM_SYSTEM_DIR or tag was too long");
|
log_error("LVM_SYSTEM_DIR or tag was too long");
|
||||||
return 0;
|
return 0;
|
||||||
@ -587,7 +587,7 @@ static int _init_filters(struct cmd_context *cmd)
|
|||||||
if (!(f3 = _init_filter_components(cmd)))
|
if (!(f3 = _init_filter_components(cmd)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (lvm_snprintf(cache_file, sizeof(cache_file),
|
if (dm_snprintf(cache_file, sizeof(cache_file),
|
||||||
"%s/.cache", cmd->sys_dir) < 0) {
|
"%s/.cache", cmd->sys_dir) < 0) {
|
||||||
log_error("Persistent cache filename too long ('%s/.cache').",
|
log_error("Persistent cache filename too long ('%s/.cache').",
|
||||||
cmd->sys_dir);
|
cmd->sys_dir);
|
||||||
@ -839,7 +839,7 @@ static int _init_backup(struct cmd_context *cmd)
|
|||||||
min = (uint32_t) find_config_tree_int(cmd, "backup/retain_min",
|
min = (uint32_t) find_config_tree_int(cmd, "backup/retain_min",
|
||||||
DEFAULT_ARCHIVE_NUMBER);
|
DEFAULT_ARCHIVE_NUMBER);
|
||||||
|
|
||||||
if (lvm_snprintf
|
if (dm_snprintf
|
||||||
(default_dir, sizeof(default_dir), "%s/%s", cmd->sys_dir,
|
(default_dir, sizeof(default_dir), "%s/%s", cmd->sys_dir,
|
||||||
DEFAULT_ARCHIVE_SUBDIR) == -1) {
|
DEFAULT_ARCHIVE_SUBDIR) == -1) {
|
||||||
log_err("Couldn't create default archive path '%s/%s'.",
|
log_err("Couldn't create default archive path '%s/%s'.",
|
||||||
@ -860,7 +860,7 @@ static int _init_backup(struct cmd_context *cmd)
|
|||||||
find_config_tree_bool(cmd, "backup/backup",
|
find_config_tree_bool(cmd, "backup/backup",
|
||||||
DEFAULT_BACKUP_ENABLED);
|
DEFAULT_BACKUP_ENABLED);
|
||||||
|
|
||||||
if (lvm_snprintf
|
if (dm_snprintf
|
||||||
(default_dir, sizeof(default_dir), "%s/%s", cmd->sys_dir,
|
(default_dir, sizeof(default_dir), "%s/%s", cmd->sys_dir,
|
||||||
DEFAULT_BACKUP_SUBDIR) == -1) {
|
DEFAULT_BACKUP_SUBDIR) == -1) {
|
||||||
log_err("Couldn't create default backup path '%s/%s'.",
|
log_err("Couldn't create default backup path '%s/%s'.",
|
||||||
|
@ -32,7 +32,7 @@ static int _locate_sysfs_blocks(const char *proc, char *path, size_t len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(proc_mounts, sizeof(proc_mounts),
|
if (dm_snprintf(proc_mounts, sizeof(proc_mounts),
|
||||||
"%s/mounts", proc) < 0) {
|
"%s/mounts", proc) < 0) {
|
||||||
log_error("Failed to create /proc/mounts string");
|
log_error("Failed to create /proc/mounts string");
|
||||||
return 0;
|
return 0;
|
||||||
@ -46,7 +46,7 @@ static int _locate_sysfs_blocks(const char *proc, char *path, size_t len)
|
|||||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||||
if (dm_split_words(buffer, 4, 0, split) == 4 &&
|
if (dm_split_words(buffer, 4, 0, split) == 4 &&
|
||||||
!strcmp(split[2], "sysfs")) {
|
!strcmp(split[2], "sysfs")) {
|
||||||
if (lvm_snprintf(path, len, "%s/%s", split[1],
|
if (dm_snprintf(path, len, "%s/%s", split[1],
|
||||||
"block") >= 0) {
|
"block") >= 0) {
|
||||||
r = 1;
|
r = 1;
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ static int _read_devs(struct dev_set *ds, const char *dir)
|
|||||||
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
|
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (lvm_snprintf(path, sizeof(path), "%s/%s", dir,
|
if (dm_snprintf(path, sizeof(path), "%s/%s", dir,
|
||||||
d->d_name) < 0) {
|
d->d_name) < 0) {
|
||||||
log_error("sysfs path name too long: %s in %s",
|
log_error("sysfs path name too long: %s in %s",
|
||||||
d->d_name, dir);
|
d->d_name, dir);
|
||||||
|
@ -145,7 +145,7 @@ static int _scan_proc_dev(const char *proc, const struct config_node *cn)
|
|||||||
/* All types unrecognised initially */
|
/* All types unrecognised initially */
|
||||||
memset(_max_partitions_by_major, 0, sizeof(int) * NUMBER_OF_MAJORS);
|
memset(_max_partitions_by_major, 0, sizeof(int) * NUMBER_OF_MAJORS);
|
||||||
|
|
||||||
if (lvm_snprintf(proc_devices, sizeof(proc_devices),
|
if (dm_snprintf(proc_devices, sizeof(proc_devices),
|
||||||
"%s/devices", proc) < 0) {
|
"%s/devices", proc) < 0) {
|
||||||
log_error("Failed to create /proc/devices string");
|
log_error("Failed to create /proc/devices string");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -103,7 +103,7 @@ int import_pv(struct dm_pool *mem, struct device *dev,
|
|||||||
static int _system_id(struct cmd_context *cmd, char *s, const char *prefix)
|
static int _system_id(struct cmd_context *cmd, char *s, const char *prefix)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (lvm_snprintf(s, NAME_LEN, "%s%s%lu",
|
if (dm_snprintf(s, NAME_LEN, "%s%s%lu",
|
||||||
prefix, cmd->hostname, time(NULL)) < 0) {
|
prefix, cmd->hostname, time(NULL)) < 0) {
|
||||||
log_error("Generated system_id too long");
|
log_error("Generated system_id too long");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -277,7 +277,7 @@ int archive_vg(struct volume_group *vg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
if (lvm_snprintf(archive_name, sizeof(archive_name),
|
if (dm_snprintf(archive_name, sizeof(archive_name),
|
||||||
"%s/%s_%05u.vg", dir, vg->name, ix) < 0) {
|
"%s/%s_%05u.vg", dir, vg->name, ix) < 0) {
|
||||||
log_error("Archive file name too long.");
|
log_error("Archive file name too long.");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -190,7 +190,7 @@ static int __backup(struct volume_group *vg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(name, sizeof(name), "%s/%s",
|
if (dm_snprintf(name, sizeof(name), "%s/%s",
|
||||||
vg->cmd->backup_params->dir, vg->name) < 0) {
|
vg->cmd->backup_params->dir, vg->name) < 0) {
|
||||||
log_error("Failed to generate volume group metadata backup "
|
log_error("Failed to generate volume group metadata backup "
|
||||||
"filename.");
|
"filename.");
|
||||||
@ -233,7 +233,7 @@ int backup_remove(struct cmd_context *cmd, const char *vg_name)
|
|||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
if (lvm_snprintf(path, sizeof(path), "%s/%s",
|
if (dm_snprintf(path, sizeof(path), "%s/%s",
|
||||||
cmd->backup_params->dir, vg_name) < 0) {
|
cmd->backup_params->dir, vg_name) < 0) {
|
||||||
log_err("Failed to generate backup filename (for removal).");
|
log_err("Failed to generate backup filename (for removal).");
|
||||||
return 0;
|
return 0;
|
||||||
@ -342,7 +342,7 @@ int backup_restore(struct cmd_context *cmd, const char *vg_name)
|
|||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
if (lvm_snprintf(path, sizeof(path), "%s/%s",
|
if (dm_snprintf(path, sizeof(path), "%s/%s",
|
||||||
cmd->backup_params->dir, vg_name) < 0) {
|
cmd->backup_params->dir, vg_name) < 0) {
|
||||||
log_err("Failed to generate backup filename (for restore).");
|
log_err("Failed to generate backup filename (for restore).");
|
||||||
return 0;
|
return 0;
|
||||||
@ -397,7 +397,7 @@ void check_current_backup(struct volume_group *vg)
|
|||||||
if ((vg->status & PARTIAL_VG) || (vg->status & EXPORTED_VG))
|
if ((vg->status & PARTIAL_VG) || (vg->status & EXPORTED_VG))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (lvm_snprintf(path, sizeof(path), "%s/%s",
|
if (dm_snprintf(path, sizeof(path), "%s/%s",
|
||||||
vg->cmd->backup_params->dir, vg->name) < 0) {
|
vg->cmd->backup_params->dir, vg->name) < 0) {
|
||||||
log_debug("Failed to generate backup filename.");
|
log_debug("Failed to generate backup filename.");
|
||||||
return;
|
return;
|
||||||
|
@ -233,7 +233,7 @@ static int _sectors_to_units(uint64_t sectors, char *buffer, size_t s)
|
|||||||
for (i = 0; (d > 1024.0) && _units[i]; i++)
|
for (i = 0; (d > 1024.0) && _units[i]; i++)
|
||||||
d /= 1024.0;
|
d /= 1024.0;
|
||||||
|
|
||||||
return lvm_snprintf(buffer, s, "# %g %s", d, _units[i]) > 0;
|
return dm_snprintf(buffer, s, "# %g %s", d, _units[i]) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -623,7 +623,7 @@ static int _build_pv_names(struct formatter *f, struct volume_group *vg)
|
|||||||
pv = pvl->pv;
|
pv = pvl->pv;
|
||||||
|
|
||||||
/* FIXME But skip if there's already an LV called pv%d ! */
|
/* FIXME But skip if there's already an LV called pv%d ! */
|
||||||
if (lvm_snprintf(buffer, sizeof(buffer), "pv%d", count++) < 0)
|
if (dm_snprintf(buffer, sizeof(buffer), "pv%d", count++) < 0)
|
||||||
return_0;
|
return_0;
|
||||||
|
|
||||||
if (!(name = dm_pool_strdup(f->mem, buffer)))
|
if (!(name = dm_pool_strdup(f->mem, buffer)))
|
||||||
|
@ -853,7 +853,7 @@ static int _scan_file(const struct format_type *fmt)
|
|||||||
tmp != dirent->d_name + strlen(dirent->d_name)
|
tmp != dirent->d_name + strlen(dirent->d_name)
|
||||||
- 4)) {
|
- 4)) {
|
||||||
vgname = dirent->d_name;
|
vgname = dirent->d_name;
|
||||||
if (lvm_snprintf(path, PATH_MAX, "%s/%s",
|
if (dm_snprintf(path, PATH_MAX, "%s/%s",
|
||||||
dl->dir, vgname) < 0) {
|
dl->dir, vgname) < 0) {
|
||||||
log_error("Name too long %s/%s",
|
log_error("Name too long %s/%s",
|
||||||
dl->dir, vgname);
|
dl->dir, vgname);
|
||||||
@ -1533,7 +1533,7 @@ static struct format_instance *_text_create_text_instance(const struct format_ty
|
|||||||
dir_list = &((struct mda_lists *) fmt->private)->dirs;
|
dir_list = &((struct mda_lists *) fmt->private)->dirs;
|
||||||
|
|
||||||
list_iterate_items(dl, dir_list) {
|
list_iterate_items(dl, dir_list) {
|
||||||
if (lvm_snprintf(path, PATH_MAX, "%s/%s",
|
if (dm_snprintf(path, PATH_MAX, "%s/%s",
|
||||||
dl->dir, vgname) < 0) {
|
dl->dir, vgname) < 0) {
|
||||||
log_error("Name too long %s/%s", dl->dir,
|
log_error("Name too long %s/%s", dl->dir,
|
||||||
vgname);
|
vgname);
|
||||||
|
@ -398,9 +398,9 @@ int lock_resource(struct cmd_context *cmd, const char *resource, int flags)
|
|||||||
case LCK_VG:
|
case LCK_VG:
|
||||||
/* If the VG name is empty then lock the unused PVs */
|
/* If the VG name is empty then lock the unused PVs */
|
||||||
if (!*resource)
|
if (!*resource)
|
||||||
lvm_snprintf(lockname, sizeof(lockname), "P_orphans");
|
dm_snprintf(lockname, sizeof(lockname), "P_orphans");
|
||||||
else
|
else
|
||||||
lvm_snprintf(lockname, sizeof(lockname), "V_%s",
|
dm_snprintf(lockname, sizeof(lockname), "V_%s",
|
||||||
resource);
|
resource);
|
||||||
|
|
||||||
cluster_cmd = CLVMD_CMD_LOCK_VG;
|
cluster_cmd = CLVMD_CMD_LOCK_VG;
|
||||||
|
@ -212,10 +212,10 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
|
|||||||
switch (flags & LCK_SCOPE_MASK) {
|
switch (flags & LCK_SCOPE_MASK) {
|
||||||
case LCK_VG:
|
case LCK_VG:
|
||||||
if (!*resource)
|
if (!*resource)
|
||||||
lvm_snprintf(lockfile, sizeof(lockfile),
|
dm_snprintf(lockfile, sizeof(lockfile),
|
||||||
"%s/P_orphans", _lock_dir);
|
"%s/P_orphans", _lock_dir);
|
||||||
else
|
else
|
||||||
lvm_snprintf(lockfile, sizeof(lockfile),
|
dm_snprintf(lockfile, sizeof(lockfile),
|
||||||
"%s/V_%s", _lock_dir, resource);
|
"%s/V_%s", _lock_dir, resource);
|
||||||
|
|
||||||
if (!_lock_file(lockfile, flags))
|
if (!_lock_file(lockfile, flags))
|
||||||
|
@ -189,7 +189,7 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname)
|
|||||||
if (!*vgname)
|
if (!*vgname)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (lvm_snprintf(path, sizeof(path), "%s/lvm/VGs/%s", cmd->proc_dir,
|
if (dm_snprintf(path, sizeof(path), "%s/lvm/VGs/%s", cmd->proc_dir,
|
||||||
vgname) < 0) {
|
vgname) < 0) {
|
||||||
log_error("LVM1 proc VG pathname too long for %s", vgname);
|
log_error("LVM1 proc VG pathname too long for %s", vgname);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -318,7 +318,7 @@ void print_log(int level, const char *file, int line, const char *format, ...)
|
|||||||
log_it:
|
log_it:
|
||||||
if (!_log_suppress) {
|
if (!_log_suppress) {
|
||||||
if (_verbose_level > _LOG_DEBUG)
|
if (_verbose_level > _LOG_DEBUG)
|
||||||
lvm_snprintf(locn, sizeof(locn), "#%s:%d ",
|
dm_snprintf(locn, sizeof(locn), "#%s:%d ",
|
||||||
file, line);
|
file, line);
|
||||||
else
|
else
|
||||||
locn[0] = '\0';
|
locn[0] = '\0';
|
||||||
@ -413,7 +413,7 @@ void print_log(int level, const char *file, int line, const char *format, ...)
|
|||||||
_already_logging = 1;
|
_already_logging = 1;
|
||||||
memset(&buf, ' ', sizeof(buf));
|
memset(&buf, ' ', sizeof(buf));
|
||||||
bufused = 0;
|
bufused = 0;
|
||||||
if ((n = lvm_snprintf(buf, sizeof(buf) - bufused - 1,
|
if ((n = dm_snprintf(buf, sizeof(buf) - bufused - 1,
|
||||||
"%s:%d %s%s", file, line, _cmd_name,
|
"%s:%d %s%s", file, line, _cmd_name,
|
||||||
_msg_prefix)) == -1)
|
_msg_prefix)) == -1)
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -1240,7 +1240,7 @@ char *generate_lv_name(struct volume_group *vg, const char *format,
|
|||||||
high = i;
|
high = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(buffer, len, format, high + 1) < 0)
|
if (dm_snprintf(buffer, len, format, high + 1) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
|
@ -428,7 +428,7 @@ static int _create_layers_for_mirror(struct alloc_handle *ah,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(img_name, len, "%s_mimage_%%d", lv->name) < 0) {
|
if (dm_snprintf(img_name, len, "%s_mimage_%%d", lv->name) < 0) {
|
||||||
log_error("img_name allocation failed. "
|
log_error("img_name allocation failed. "
|
||||||
"Remove new LV and retry.");
|
"Remove new LV and retry.");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -50,7 +50,7 @@ int create_temp_name(const char *dir, char *buffer, size_t len, int *fd)
|
|||||||
|
|
||||||
for (i = 0; i < 20; i++, num++) {
|
for (i = 0; i < 20; i++, num++) {
|
||||||
|
|
||||||
if (lvm_snprintf(buffer, len, "%s/.lvm_%s_%d_%d",
|
if (dm_snprintf(buffer, len, "%s/.lvm_%s_%d_%d",
|
||||||
dir, hostname, pid, num) == -1) {
|
dir, hostname, pid, num) == -1) {
|
||||||
log_err("Not enough space to build temporary file "
|
log_err("Not enough space to build temporary file "
|
||||||
"string.");
|
"string.");
|
||||||
|
@ -14,30 +14,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
#include "lvm-types.h"
|
|
||||||
#include "lvm-string.h"
|
#include "lvm-string.h"
|
||||||
|
|
||||||
/*
|
#include <ctype.h>
|
||||||
* On error, up to glibc 2.0.6, snprintf returned -1 if buffer was too small;
|
|
||||||
* From glibc 2.1 it returns number of chars (excl. trailing null) that would
|
|
||||||
* have been written had there been room.
|
|
||||||
*
|
|
||||||
* lvm_snprintf reverts to the old behaviour.
|
|
||||||
*/
|
|
||||||
int lvm_snprintf(char *buf, size_t bufsize, const char *format, ...)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
|
||||||
n = vsnprintf(buf, bufsize, format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (n < 0 || (n > bufsize - 1))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...)
|
int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
@ -23,15 +23,6 @@
|
|||||||
|
|
||||||
struct pool;
|
struct pool;
|
||||||
|
|
||||||
/*
|
|
||||||
* On error, up to glibc 2.0.6, snprintf returned -1 if buffer was too small;
|
|
||||||
* From glibc 2.1 it returns number of chars (excl. trailing null) that would
|
|
||||||
* have been written had there been room.
|
|
||||||
*
|
|
||||||
* lvm_snprintf reverts to the old behaviour.
|
|
||||||
*/
|
|
||||||
int lvm_snprintf(char *buf, size_t bufsize, const char *format, ...);
|
|
||||||
|
|
||||||
int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...);
|
int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...);
|
||||||
|
|
||||||
char *build_dm_name(struct dm_pool *mem, const char *vg,
|
char *build_dm_name(struct dm_pool *mem, const char *vg,
|
||||||
|
@ -32,7 +32,7 @@ void get_shared_library_path(struct cmd_context *cmd, const char *libname,
|
|||||||
* if present */
|
* if present */
|
||||||
if (libname[0] == '/' ||
|
if (libname[0] == '/' ||
|
||||||
!(lib_dir = find_config_tree_str(cmd, "global/library_dir", 0)) ||
|
!(lib_dir = find_config_tree_str(cmd, "global/library_dir", 0)) ||
|
||||||
(lvm_snprintf(path, path_len, "%s/%s", lib_dir,
|
(dm_snprintf(path, path_len, "%s/%s", lib_dir,
|
||||||
libname) == -1) || stat(path, &info) == -1)
|
libname) == -1) || stat(path, &info) == -1)
|
||||||
strncpy(path, libname, path_len);
|
strncpy(path, libname, path_len);
|
||||||
}
|
}
|
||||||
|
@ -172,9 +172,9 @@ static int _devices_disp(struct report_handle *rh, struct field *field,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(extent_str, sizeof(extent_str), "(%" PRIu32
|
if (dm_snprintf(extent_str, sizeof(extent_str), "(%" PRIu32
|
||||||
")", extent) < 0) {
|
")", extent) < 0) {
|
||||||
log_error("Extent number lvm_snprintf failed");
|
log_error("Extent number dm_snprintf failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ static int _int_disp(struct report_handle *rh, struct field *field,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(repstr, 12, "%d", value) < 0) {
|
if (dm_snprintf(repstr, 12, "%d", value) < 0) {
|
||||||
log_error("int too big: %d", value);
|
log_error("int too big: %d", value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -540,7 +540,7 @@ static int _lvname_disp(struct report_handle *rh, struct field *field,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(repstr, len, "[%s]", lv->name) < 0) {
|
if (dm_snprintf(repstr, len, "[%s]", lv->name) < 0) {
|
||||||
log_error("lvname snprintf failed");
|
log_error("lvname snprintf failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -784,7 +784,7 @@ static int _uint32_disp(struct report_handle *rh, struct field *field,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(repstr, 11, "%u", value) < 0) {
|
if (dm_snprintf(repstr, 11, "%u", value) < 0) {
|
||||||
log_error("uint32 too big: %u", value);
|
log_error("uint32 too big: %u", value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -813,7 +813,7 @@ static int _int32_disp(struct report_handle *rh, struct field *field,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(repstr, 12, "%d", value) < 0) {
|
if (dm_snprintf(repstr, 12, "%d", value) < 0) {
|
||||||
log_error("int32 too big: %d", value);
|
log_error("int32 too big: %d", value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -870,7 +870,7 @@ static int _snpercent_disp(struct report_handle *rh, struct field *field,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(repstr, 7, "%.2f", snap_percent) < 0) {
|
if (dm_snprintf(repstr, 7, "%.2f", snap_percent) < 0) {
|
||||||
log_error("snapshot percentage too large");
|
log_error("snapshot percentage too large");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -910,7 +910,7 @@ static int _copypercent_disp(struct report_handle *rh, struct field *field,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(repstr, 7, "%.2f", percent) < 0) {
|
if (dm_snprintf(repstr, 7, "%.2f", percent) < 0) {
|
||||||
log_error("copy percentage too large");
|
log_error("copy percentage too large");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1324,7 +1324,7 @@ static int _report_headings(void *handle)
|
|||||||
|
|
||||||
heading = _fields[fp->field_num].heading;
|
heading = _fields[fp->field_num].heading;
|
||||||
if (rh->flags & RH_ALIGNED) {
|
if (rh->flags & RH_ALIGNED) {
|
||||||
if (lvm_snprintf(buf, sizeof(buf), "%-*.*s",
|
if (dm_snprintf(buf, sizeof(buf), "%-*.*s",
|
||||||
fp->width, fp->width, heading) < 0) {
|
fp->width, fp->width, heading) < 0) {
|
||||||
log_error("snprintf heading failed");
|
log_error("snprintf heading failed");
|
||||||
dm_pool_end_object(rh->mem);
|
dm_pool_end_object(rh->mem);
|
||||||
@ -1467,7 +1467,7 @@ int report_output(void *handle)
|
|||||||
strlen(repstr)))
|
strlen(repstr)))
|
||||||
goto bad;
|
goto bad;
|
||||||
} else if (field->props->flags & FLD_ALIGN_LEFT) {
|
} else if (field->props->flags & FLD_ALIGN_LEFT) {
|
||||||
if (lvm_snprintf(buf, sizeof(buf), "%-*.*s",
|
if (dm_snprintf(buf, sizeof(buf), "%-*.*s",
|
||||||
width, width, repstr) < 0) {
|
width, width, repstr) < 0) {
|
||||||
log_error("snprintf repstr failed");
|
log_error("snprintf repstr failed");
|
||||||
dm_pool_end_object(rh->mem);
|
dm_pool_end_object(rh->mem);
|
||||||
@ -1476,7 +1476,7 @@ int report_output(void *handle)
|
|||||||
if (!dm_pool_grow_object(rh->mem, buf, width))
|
if (!dm_pool_grow_object(rh->mem, buf, width))
|
||||||
goto bad;
|
goto bad;
|
||||||
} else if (field->props->flags & FLD_ALIGN_RIGHT) {
|
} else if (field->props->flags & FLD_ALIGN_RIGHT) {
|
||||||
if (lvm_snprintf(buf, sizeof(buf), "%*.*s",
|
if (dm_snprintf(buf, sizeof(buf), "%*.*s",
|
||||||
width, width, repstr) < 0) {
|
width, width, repstr) < 0) {
|
||||||
log_error("snprintf repstr failed");
|
log_error("snprintf repstr failed");
|
||||||
dm_pool_end_object(rh->mem);
|
dm_pool_end_object(rh->mem);
|
||||||
|
@ -1188,7 +1188,7 @@ static int _hist_file(char *buffer, size_t size)
|
|||||||
{
|
{
|
||||||
char *e = getenv("HOME");
|
char *e = getenv("HOME");
|
||||||
|
|
||||||
if (lvm_snprintf(buffer, size, "%s/.lvm_history", e) < 0) {
|
if (dm_snprintf(buffer, size, "%s/.lvm_history", e) < 0) {
|
||||||
log_error("$HOME/.lvm_history: path too long");
|
log_error("$HOME/.lvm_history: path too long");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1311,7 +1311,7 @@ static void _exec_lvm1_command(char **argv)
|
|||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
if (lvm_snprintf(path, sizeof(path), "%s.lvm1", argv[0]) < 0) {
|
if (dm_snprintf(path, sizeof(path), "%s.lvm1", argv[0]) < 0) {
|
||||||
log_error("Failed to create LVM1 tool pathname");
|
log_error("Failed to create LVM1 tool pathname");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -480,14 +480,14 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lp->resizefs) {
|
if (lp->resizefs) {
|
||||||
if (lvm_snprintf(lv_path, PATH_MAX, "%s%s/%s", cmd->dev_dir,
|
if (dm_snprintf(lv_path, PATH_MAX, "%s%s/%s", cmd->dev_dir,
|
||||||
lp->vg_name, lp->lv_name) < 0) {
|
lp->vg_name, lp->lv_name) < 0) {
|
||||||
log_error("Couldn't create LV path for %s",
|
log_error("Couldn't create LV path for %s",
|
||||||
lp->lv_name);
|
lp->lv_name);
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(size_buf, SIZE_BUF, "%" PRIu64,
|
if (dm_snprintf(size_buf, SIZE_BUF, "%" PRIu64,
|
||||||
(uint64_t) lp->extents * vg->extent_size / 2)
|
(uint64_t) lp->extents * vg->extent_size / 2)
|
||||||
< 0) {
|
< 0) {
|
||||||
log_error("Couldn't generate new LV size string");
|
log_error("Couldn't generate new LV size string");
|
||||||
|
@ -268,7 +268,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
|
|||||||
} else {
|
} else {
|
||||||
vglv_sz = strlen(vgname) + strlen(lv_name) + 2;
|
vglv_sz = strlen(vgname) + strlen(lv_name) + 2;
|
||||||
if (!(vglv = dm_pool_alloc(cmd->mem, vglv_sz)) ||
|
if (!(vglv = dm_pool_alloc(cmd->mem, vglv_sz)) ||
|
||||||
lvm_snprintf(vglv, vglv_sz, "%s/%s", vgname,
|
dm_snprintf(vglv, vglv_sz, "%s/%s", vgname,
|
||||||
lv_name) < 0) {
|
lv_name) < 0) {
|
||||||
log_error("vg/lv string alloc failed");
|
log_error("vg/lv string alloc failed");
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
@ -1098,14 +1098,14 @@ int validate_vg_name(struct cmd_context *cmd, const char *vg_name)
|
|||||||
int generate_log_name_format(struct volume_group *vg __attribute((unused)),
|
int generate_log_name_format(struct volume_group *vg __attribute((unused)),
|
||||||
const char *lv_name, char *buffer, size_t size)
|
const char *lv_name, char *buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (lvm_snprintf(buffer, size, "%s_mlog", lv_name) < 0) {
|
if (dm_snprintf(buffer, size, "%s_mlog", lv_name) < 0) {
|
||||||
stack;
|
stack;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME I think we can cope without this. Cf. _add_lv_to_dtree()
|
/* FIXME I think we can cope without this. Cf. _add_lv_to_dtree()
|
||||||
if (find_lv_in_vg(vg, buffer) &&
|
if (find_lv_in_vg(vg, buffer) &&
|
||||||
lvm_snprintf(buffer, size, "%s_mlog_%%d",
|
dm_snprintf(buffer, size, "%s_mlog_%%d",
|
||||||
lv_name) < 0) {
|
lv_name) < 0) {
|
||||||
stack;
|
stack;
|
||||||
return 0;
|
return 0;
|
||||||
@ -1135,7 +1135,7 @@ int set_lv(struct cmd_context *cmd, struct logical_volume *lv, int value)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
|
if (dm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
|
||||||
lv->vg->name, lv->name) < 0) {
|
lv->vg->name, lv->name) < 0) {
|
||||||
log_error("Name too long - device not cleared (%s)", lv->name);
|
log_error("Name too long - device not cleared (%s)", lv->name);
|
||||||
return 0;
|
return 0;
|
||||||
@ -1183,7 +1183,7 @@ static int _write_log_header(struct cmd_context *cmd, struct logical_volume *lv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
|
if (dm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
|
||||||
lv->vg->name, lv->name) < 0) {
|
lv->vg->name, lv->name) < 0) {
|
||||||
log_error("Name too long - log header not written (%s)", lv->name);
|
log_error("Name too long - log header not written (%s)", lv->name);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user