mirror of
git://sourceware.org/git/lvm2.git
synced 2025-10-04 05:44:18 +03:00
Compare commits
2 Commits
v2_03_24
...
dev-dct-lv
Author | SHA1 | Date | |
---|---|---|---|
|
40ed782077 | ||
|
3a1c12046f |
20
configure.ac
20
configure.ac
@@ -1713,6 +1713,21 @@ AC_DEFINE_UNQUOTED(FSADM_PATH, ["$FSADM_PATH"], [Path to fsadm binary.])
|
||||
LVMIMPORTVDO_PATH="$SBINDIR/lvm_import_vdo"
|
||||
AC_DEFINE_UNQUOTED(LVMIMPORTVDO_PATH, ["$LVMIMPORTVDO_PATH"], [Path to lvm_import_vdo script.])
|
||||
|
||||
MOUNT_PATH="/usr/bin/mount"
|
||||
AC_DEFINE_UNQUOTED(MOUNT_PATH, ["$MOUNT_PATH"], [Path to mount binary.])
|
||||
|
||||
UMOUNT_PATH="/usr/bin/umount"
|
||||
AC_DEFINE_UNQUOTED(UMOUNT_PATH, ["$UMOUNT_PATH"], [Path to umount binary.])
|
||||
|
||||
E2FSCK_PATH="$SBINDIR/e2fsck"
|
||||
AC_DEFINE_UNQUOTED(E2FSCK_PATH, ["$E2FSCK_PATH"], [Path to e2fsck binary.])
|
||||
|
||||
RESIZE2FS_PATH="$SBINDIR/resize2fs"
|
||||
AC_DEFINE_UNQUOTED(RESIZE2FS_PATH, ["$RESIZE2FS_PATH"], [Path to resize2fs binary.])
|
||||
|
||||
XFS_GROWFS_PATH="$SBINDIR/xfs_growfs"
|
||||
AC_DEFINE_UNQUOTED(XFS_GROWFS_PATH, ["$XFS_GROWFS_PATH"], [Path to xfs_growfs binary.])
|
||||
|
||||
################################################################################
|
||||
dnl -- dmeventd pidfile and executable path
|
||||
if test "$BUILD_DMEVENTD" = yes; then
|
||||
@@ -1882,6 +1897,11 @@ AC_SUBST(DM_LIB_PATCHLEVEL)
|
||||
AC_SUBST(ELDFLAGS)
|
||||
AC_SUBST(FSADM)
|
||||
AC_SUBST(FSADM_PATH)
|
||||
AC_SUBST(MOUNT_PATH)
|
||||
AC_SUBST(UMOUNT_PATH)
|
||||
AC_SUBST(E2FSCK_PATH)
|
||||
AC_SUBST(RESIZE2FS_PATH)
|
||||
AC_SUBST(XFS_GROWFS_PATH)
|
||||
AC_SUBST(BLKDEACTIVATE)
|
||||
AC_SUBST(HAVE_LIBDL)
|
||||
AC_SUBST(HAVE_REALTIME)
|
||||
|
@@ -132,8 +132,13 @@
|
||||
/* Define to 1 to include the LVM editline shell. */
|
||||
#undef EDITLINE_SUPPORT
|
||||
|
||||
/* Path to fsadm binary. */
|
||||
/* Paths to binaries. */
|
||||
#undef FSADM_PATH
|
||||
#undef MOUNT_PATH
|
||||
#undef UMOUNT_PATH
|
||||
#undef E2FSCK_PATH
|
||||
#undef RESIZE2FS_PATH
|
||||
#undef XFS_GROWFS_PATH
|
||||
|
||||
/* Define to use GNU versioning in the shared library. */
|
||||
#undef GNU_SYMVER
|
||||
|
@@ -40,6 +40,7 @@ SOURCES =\
|
||||
device/dev-luks.c \
|
||||
device/dev-dasd.c \
|
||||
device/dev-lvm1-pool.c \
|
||||
device/filesystem.c \
|
||||
device/online.c \
|
||||
device/parse_vpd.c \
|
||||
display/display.c \
|
||||
|
19
lib/commands/cmd_enum.h
Normal file
19
lib/commands/cmd_enum.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef _CMD_ENUM_H
|
||||
#define _CMD_ENUM_H
|
||||
|
||||
/*
|
||||
* tools/cmds.h is generated by the Makefile. For each command definition
|
||||
* in command-lines.in, cmds.h contains:
|
||||
* cmd(foo_CMD, foo)
|
||||
*
|
||||
* This header adds each of the foo_CMD's into an enum, so there's
|
||||
* a unique integer identifier for each command definition.
|
||||
*/
|
||||
|
||||
enum {
|
||||
#define cmd(a, b) a ,
|
||||
#include "../tools/cmds.h"
|
||||
#undef cmd
|
||||
};
|
||||
|
||||
#endif
|
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "lib/device/dev-cache.h"
|
||||
#include "lib/device/dev-type.h"
|
||||
#include "lib/commands/cmd_enum.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
@@ -94,6 +95,7 @@ struct cmd_context {
|
||||
const char *name; /* needed before cmd->command is set */
|
||||
struct command_name *cname;
|
||||
struct command *command;
|
||||
int command_enum; /* duplicate from command->command_enum for lib code */
|
||||
char **argv;
|
||||
struct arg_values *opt_arg_values;
|
||||
struct dm_list arg_value_groups;
|
||||
|
@@ -838,6 +838,86 @@ int get_fs_block_size(const char *pathname, uint32_t *fs_block_size)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int fs_get_blkid(const char *pathname, struct fs_info *fsi)
|
||||
{
|
||||
blkid_probe probe = NULL;
|
||||
const char *str;
|
||||
size_t len;
|
||||
uint64_t fslastblock = 0;
|
||||
unsigned int fsblocksize = 0;
|
||||
int no_block_size = 0, no_fslastblock = 0, no_fsblocksize = 0;
|
||||
int rc;
|
||||
|
||||
if (!(probe = blkid_new_probe_from_filename(pathname))) {
|
||||
log_error("Failed libblkid probe setup for %s", pathname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
blkid_probe_enable_superblocks(probe, 1);
|
||||
blkid_probe_set_superblocks_flags(probe,
|
||||
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_LABELRAW |
|
||||
BLKID_SUBLKS_UUID | BLKID_SUBLKS_UUIDRAW |
|
||||
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
|
||||
BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
|
||||
BLKID_SUBLKS_MAGIC | BLKID_SUBLKS_FSINFO);
|
||||
rc = blkid_do_safeprobe(probe);
|
||||
if (rc < 0) {
|
||||
log_error("Failed libblkid probe for %s", pathname);
|
||||
blkid_free_probe(probe);
|
||||
return 0;
|
||||
} else if (rc == 1) {
|
||||
/* no file system on the device */
|
||||
log_print("No file system found on %s.", pathname);
|
||||
fsi->nofs = 1;
|
||||
blkid_free_probe(probe);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!blkid_probe_lookup_value(probe, "TYPE", &str, &len) && len)
|
||||
strncpy(fsi->fstype, str, sizeof(fsi->fstype)-1);
|
||||
else {
|
||||
/* any difference from blkid_do_safeprobe rc=1? */
|
||||
log_print("No file system type on %s.", pathname);
|
||||
fsi->nofs = 1;
|
||||
blkid_free_probe(probe);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!blkid_probe_lookup_value(probe, "BLOCK_SIZE", &str, &len) && len)
|
||||
fsi->block_size_bytes = atoi(str);
|
||||
else
|
||||
no_block_size = 1;
|
||||
|
||||
if (!blkid_probe_lookup_value(probe, "FSLASTBLOCK", &str, &len) && len)
|
||||
fslastblock = strtoull(str, NULL, 0);
|
||||
else
|
||||
no_fslastblock = 1;
|
||||
|
||||
if (!blkid_probe_lookup_value(probe, "FSBLOCKSIZE", &str, &len) && len)
|
||||
fsblocksize = (unsigned int)atoi(str);
|
||||
else
|
||||
no_fsblocksize = 1;
|
||||
|
||||
blkid_free_probe(probe);
|
||||
|
||||
if (no_block_size || no_fslastblock || no_fsblocksize) {
|
||||
log_print("Missing libblkid %s%s%sfor %s",
|
||||
no_block_size ? "BLOCK_SIZE " : "",
|
||||
no_fslastblock ? "FSLASTBLOCK " : "",
|
||||
no_fsblocksize ? "FSBLOCKSIZE " : "",
|
||||
pathname);
|
||||
}
|
||||
|
||||
if (fslastblock && fsblocksize)
|
||||
fsi->fs_last_byte = fslastblock * fsblocksize;
|
||||
|
||||
log_debug("libblkid TYPE %s BLOCK_SIZE %d FSLASTBLOCK %llu FSBLOCKSIZE %u fs_last_byte %llu",
|
||||
fsi->fstype, fsi->block_size_bytes, (unsigned long long)fslastblock, fsblocksize,
|
||||
(unsigned long long)fsi->fs_last_byte);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else
|
||||
int get_fs_block_size(const char *pathname, uint32_t *fs_block_size)
|
||||
{
|
||||
@@ -845,6 +925,11 @@ int get_fs_block_size(const char *pathname, uint32_t *fs_block_size)
|
||||
*fs_block_size = 0;
|
||||
return 0;
|
||||
}
|
||||
int fs_get_blkid(const char *pathname, struct fs_info *fsi)
|
||||
{
|
||||
log_debug("Disabled blkid for fs info.");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BLKID_WIPING_SUPPORT
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include "lib/device/device.h"
|
||||
#include "lib/display/display.h"
|
||||
#include "lib/label/label.h"
|
||||
#include "lib/device/filesystem.h"
|
||||
|
||||
#define NUMBER_OF_MAJORS 4096
|
||||
|
||||
@@ -102,6 +103,7 @@ int dev_is_nvme(struct dev_types *dt, struct device *dev);
|
||||
int dev_is_lv(struct device *dev);
|
||||
|
||||
int get_fs_block_size(const char *pathname, uint32_t *fs_block_size);
|
||||
int fs_get_blkid(const char *pathname, struct fs_info *fsi);
|
||||
|
||||
int dev_is_used_by_active_lv(struct cmd_context *cmd, struct device *dev, int *used_by_lv_count,
|
||||
char **used_by_dm_name, char **used_by_vg_uuid, char **used_by_lv_uuid);
|
||||
|
284
lib/device/filesystem.c
Normal file
284
lib/device/filesystem.c
Normal file
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is part of LVM2.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use,
|
||||
* modify, copy, or redistribute it subject to the terms and conditions
|
||||
* of the GNU Lesser General Public License v.2.1.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "base/memory/zalloc.h"
|
||||
#include "lib/misc/lib.h"
|
||||
#include "lib/commands/toolcontext.h"
|
||||
#include "lib/device/device.h"
|
||||
#include "lib/device/dev-type.h"
|
||||
#include "lib/misc/lvm-exec.h"
|
||||
|
||||
#include <mntent.h>
|
||||
|
||||
static int _get_lv_path(struct logical_volume *lv, char *lv_path)
|
||||
{
|
||||
if (dm_snprintf(lv_path, PATH_MAX, "%s%s/%s", lv->vg->cmd->dev_dir,
|
||||
lv->vg->name, lv->name) < 0) {
|
||||
log_error("Couldn't create LV path for %s.", display_lvname(lv));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fs_get_info(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
struct fs_info *fsi, int include_mount)
|
||||
{
|
||||
char lv_path[PATH_MAX];
|
||||
FILE *fme = NULL;
|
||||
struct stat stlv;
|
||||
struct stat stme;
|
||||
struct mntent *me;
|
||||
int ret;
|
||||
|
||||
if (!_get_lv_path(lv, lv_path))
|
||||
return_0;
|
||||
|
||||
if (!fs_get_blkid(lv_path, fsi)) {
|
||||
log_error("Missing libblkid file system info for %s", display_lvname(lv));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fsi->nofs)
|
||||
return 1;
|
||||
|
||||
if (!include_mount)
|
||||
return 1;
|
||||
|
||||
if (stat(lv_path, &stlv) < 0)
|
||||
return_0;
|
||||
|
||||
if (!(fme = setmntent("/etc/mtab", "r")))
|
||||
return_0;
|
||||
|
||||
ret = 1;
|
||||
|
||||
while ((me = getmntent(fme))) {
|
||||
if (strcmp(me->mnt_type, fsi->fstype))
|
||||
continue;
|
||||
if (me->mnt_dir[0] != '/')
|
||||
continue;
|
||||
if (me->mnt_fsname[0] != '/')
|
||||
continue;
|
||||
if (stat(me->mnt_dir, &stme) < 0)
|
||||
continue;
|
||||
if (stme.st_dev != stlv.st_rdev)
|
||||
continue;
|
||||
|
||||
log_debug("fs_get_info %s is mounted \"%s\"", lv_path, me->mnt_dir);
|
||||
fsi->mounted = 1;
|
||||
strncpy(fsi->mount_dir, me->mnt_dir, PATH_MAX-1);
|
||||
}
|
||||
endmntent(fme);
|
||||
|
||||
fsi->unmounted = !fsi->mounted;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define FS_CMD_MAX_ARGS 6
|
||||
|
||||
int fs_fsck_command(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi)
|
||||
{
|
||||
char lv_path[PATH_MAX];
|
||||
const char *argv[FS_CMD_MAX_ARGS + 4];
|
||||
int args = 0;
|
||||
int status;
|
||||
|
||||
if (strncmp(fsi->fstype, "ext", 3)) {
|
||||
log_error("fsck not supported for %s.", fsi->fstype);
|
||||
return_0;
|
||||
}
|
||||
|
||||
if (!_get_lv_path(lv, lv_path))
|
||||
return_0;
|
||||
|
||||
/*
|
||||
* ext234: e2fsck -f -p path
|
||||
* TODO: replace -p with -y based on yes_ARG, or other?
|
||||
*/
|
||||
|
||||
argv[0] = E2FSCK_PATH; /* defined by configure */
|
||||
argv[++args] = "-f";
|
||||
argv[++args] = "-p";
|
||||
argv[++args] = lv_path;
|
||||
argv[++args] = NULL;
|
||||
|
||||
log_print("Checking file system %s with %s on %s...",
|
||||
fsi->fstype, E2FSCK_PATH, display_lvname(lv));
|
||||
|
||||
if (!exec_cmd(cmd, argv, &status, 1)) {
|
||||
log_error("e2fsck failed on %s.", display_lvname(lv));
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_print("Checked file system %s on %s.", fsi->fstype, display_lvname(lv));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fs_reduce_command(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
|
||||
uint64_t newsize_bytes)
|
||||
{
|
||||
char lv_path[PATH_MAX];
|
||||
char newsize_kb_str[16] = { 0 };
|
||||
const char *argv[FS_CMD_MAX_ARGS + 4];
|
||||
int args = 0;
|
||||
int status;
|
||||
|
||||
if (!_get_lv_path(lv, lv_path))
|
||||
return_0;
|
||||
|
||||
if (!strncmp(fsi->fstype, "ext", 3)) {
|
||||
if (dm_snprintf(newsize_kb_str, 16, "%lluk", (unsigned long long)(newsize_bytes/1024)) < 0)
|
||||
return_0;
|
||||
|
||||
/*
|
||||
* ext234 shrink: resize2fs path newsize
|
||||
*/
|
||||
argv[0] = RESIZE2FS_PATH; /* defined by configure */
|
||||
argv[++args] = lv_path;
|
||||
argv[++args] = newsize_kb_str;
|
||||
argv[++args] = NULL;
|
||||
|
||||
} else {
|
||||
log_error("fs reduce not supported for %s.", fsi->fstype);
|
||||
return_0;
|
||||
}
|
||||
|
||||
log_print("Reducing file system %s on %s...", fsi->fstype, display_lvname(lv));
|
||||
|
||||
if (!exec_cmd(cmd, argv, &status, 1)) {
|
||||
log_error("Failed to reduce %s file system on %s.", fsi->fstype, display_lvname(lv));
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_print("Reduced file system %s to %s (%llu bytes) on %s.",
|
||||
fsi->fstype, display_size(cmd, newsize_bytes/512),
|
||||
(unsigned long long)newsize_bytes, display_lvname(lv));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fs_extend_command(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi)
|
||||
{
|
||||
char lv_path[PATH_MAX];
|
||||
const char *argv[FS_CMD_MAX_ARGS + 4];
|
||||
int args = 0;
|
||||
int status;
|
||||
|
||||
if (!_get_lv_path(lv, lv_path))
|
||||
return_0;
|
||||
|
||||
if (!strncmp(fsi->fstype, "ext", 3)) {
|
||||
/* TODO: include -f if lvm command inclues -f ? */
|
||||
argv[0] = RESIZE2FS_PATH; /* defined by configure */
|
||||
argv[++args] = lv_path;
|
||||
argv[++args] = NULL;
|
||||
|
||||
} else if (!strcmp(fsi->fstype, "xfs")) {
|
||||
argv[0] = XFS_GROWFS_PATH; /* defined by configure */
|
||||
argv[++args] = lv_path;
|
||||
argv[++args] = NULL;
|
||||
|
||||
} else {
|
||||
log_error("Extend not supported for %s file system.", fsi->fstype);
|
||||
return_0;
|
||||
}
|
||||
|
||||
log_print("Extending file system %s on %s...", fsi->fstype, display_lvname(lv));
|
||||
|
||||
if (!exec_cmd(cmd, argv, &status, 1)) {
|
||||
log_error("Failed to extend %s file system on %s.", fsi->fstype, display_lvname(lv));
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_print("Extended file system %s on %s.", fsi->fstype, display_lvname(lv));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fs_mount_command(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
|
||||
int reuse_mount_dir)
|
||||
{
|
||||
char lv_path[PATH_MAX];
|
||||
char mountdir[PATH_MAX];
|
||||
const char *argv[FS_CMD_MAX_ARGS + 4];
|
||||
int args = 0;
|
||||
int status;
|
||||
|
||||
if (!_get_lv_path(lv, lv_path))
|
||||
return_0;
|
||||
|
||||
if (reuse_mount_dir) {
|
||||
if (!fsi->mount_dir[0]) {
|
||||
log_error("Cannot remount fs without previous mount dir.");
|
||||
return 0;
|
||||
}
|
||||
memcpy(mountdir, fsi->mount_dir, PATH_MAX);
|
||||
} else {
|
||||
if (dm_snprintf(mountdir, sizeof(mountdir), "/tmp/%s_XXXXXX", cmd->name) < 0)
|
||||
return_0;
|
||||
if (!mkdtemp(mountdir)) {
|
||||
log_error("Failed to create temp dir for mount: %s", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
memcpy(fsi->mount_dir, mountdir, PATH_MAX);
|
||||
fsi->temp_mount_dir = 1;
|
||||
}
|
||||
|
||||
argv[0] = MOUNT_PATH; /* defined by configure */
|
||||
argv[++args] = lv_path;
|
||||
argv[++args] = mountdir;
|
||||
argv[++args] = NULL;
|
||||
|
||||
log_print("Mounting %s.", display_lvname(lv));
|
||||
|
||||
if (!exec_cmd(cmd, argv, &status, 1)) {
|
||||
log_error("Failed to mount file system on %s at %s.", display_lvname(lv), mountdir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_print("Mounted %s at %s dir %s.", display_lvname(lv),
|
||||
reuse_mount_dir ? "original" : "temporary", mountdir);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fs_unmount_command(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi)
|
||||
{
|
||||
char lv_path[PATH_MAX];
|
||||
const char *argv[FS_CMD_MAX_ARGS + 4];
|
||||
int args = 0;
|
||||
int status;
|
||||
|
||||
if (!_get_lv_path(lv, lv_path))
|
||||
return_0;
|
||||
|
||||
argv[0] = UMOUNT_PATH; /* defined by configure */
|
||||
argv[++args] = lv_path;
|
||||
argv[++args] = NULL;
|
||||
|
||||
log_print("Unmounting %s.", display_lvname(lv));
|
||||
|
||||
if (!exec_cmd(cmd, argv, &status, 1)) {
|
||||
log_error("Failed to unmount file system on %s.", display_lvname(lv));
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_print("Unmounted %s.", display_lvname(lv));
|
||||
|
||||
if (fsi->temp_mount_dir) {
|
||||
if (rmdir(fsi->mount_dir) < 0)
|
||||
log_print("Error removing temp dir %s", fsi->mount_dir);
|
||||
fsi->mount_dir[0] = '\0';
|
||||
fsi->temp_mount_dir = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
46
lib/device/filesystem.h
Normal file
46
lib/device/filesystem.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is part of LVM2.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use,
|
||||
* modify, copy, or redistribute it subject to the terms and conditions
|
||||
* of the GNU Lesser General Public License v.2.1.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _FILESYSTEM_H
|
||||
#define _FILESYSTEM_H
|
||||
|
||||
struct fs_info {
|
||||
char fstype[16];
|
||||
char mount_dir[PATH_MAX];
|
||||
unsigned int block_size_bytes; /* 512 or 4k */
|
||||
uint64_t fs_last_byte; /* last byte on the device used by the fs */
|
||||
|
||||
unsigned nofs:1;
|
||||
unsigned unmounted:1;
|
||||
unsigned mounted:1;
|
||||
unsigned temp_mount_dir:1;
|
||||
/* for resizing */
|
||||
unsigned needs_reduce:1;
|
||||
unsigned needs_extend:1;
|
||||
unsigned needs_fsck:1;
|
||||
unsigned needs_unmount:1;
|
||||
unsigned needs_mount:1;
|
||||
};
|
||||
|
||||
int fs_get_info(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
struct fs_info *fsi, int include_mount);
|
||||
int fs_fsck_command(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi);
|
||||
int fs_reduce_command(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
|
||||
uint64_t newsize_bytes);
|
||||
int fs_extend_command(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi);
|
||||
int fs_mount_command(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
|
||||
int reuse_mount_dir);
|
||||
int fs_unmount_command(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi);
|
||||
|
||||
#endif
|
@@ -577,8 +577,9 @@ static int _extend_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg,
|
||||
(uint32_t)(new_size_sectors * SECTOR_SIZE));
|
||||
|
||||
lp.size = new_size_sectors;
|
||||
lp.pvh = &vg->pvs;
|
||||
|
||||
if (!lv_resize(lv, &lp, &vg->pvs)) {
|
||||
if (!lv_resize(cmd, lv, &lp)) {
|
||||
log_error("Extend sanlock LV %s to size %s failed.",
|
||||
display_lvname(lv), display_size(cmd, lp.size));
|
||||
return 0;
|
||||
@@ -2733,6 +2734,9 @@ int lockd_lv_resize(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
if (!_lvmlockd_connected)
|
||||
return 0;
|
||||
|
||||
if (lv_is_lockd_sanlock_lv(lv))
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* A special case for gfs2 where we want to allow lvextend
|
||||
* of an LV that has an existing shared lock, which is normally
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -297,6 +297,9 @@
|
||||
int lv_layout_and_role(struct dm_pool *mem, const struct logical_volume *lv,
|
||||
struct dm_list **layout, struct dm_list **role);
|
||||
|
||||
int lv_is_linear(struct logical_volume *lv);
|
||||
int lv_is_striped(struct logical_volume *lv);
|
||||
|
||||
/* Ordered list - see lv_manip.c */
|
||||
typedef enum {
|
||||
AREA_UNASSIGNED,
|
||||
@@ -661,50 +664,44 @@ struct pvcreate_params {
|
||||
};
|
||||
|
||||
struct lvresize_params {
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
const char *vg_name; /* only-used when VG is not yet opened (in /tools) */
|
||||
const char *lv_name;
|
||||
|
||||
const struct segment_type *segtype;
|
||||
|
||||
uint64_t poolmetadata_size;
|
||||
sign_t poolmetadata_sign;
|
||||
|
||||
/* Per LV applied parameters */
|
||||
|
||||
enum {
|
||||
LV_ANY = 0,
|
||||
LV_REDUCE = 1,
|
||||
LV_EXTEND = 2
|
||||
} resize;
|
||||
|
||||
int use_policies;
|
||||
|
||||
alloc_policy_t alloc;
|
||||
int yes;
|
||||
int force;
|
||||
int nosync;
|
||||
int nofsck;
|
||||
int resizefs;
|
||||
int use_policies;
|
||||
char fsopt[32]; /* set by --resizefs|--fs, empty for --fs ignore */
|
||||
|
||||
const struct segment_type *segtype;
|
||||
unsigned mirrors;
|
||||
uint32_t stripes;
|
||||
uint64_t stripe_size;
|
||||
|
||||
uint32_t extents;
|
||||
uint64_t size;
|
||||
uint32_t extents;
|
||||
sign_t sign;
|
||||
percent_type_t percent;
|
||||
percent_type_t percent; /* the type of percentage, not a value */
|
||||
uint32_t percent_value; /* 0 - 100 */
|
||||
uint64_t poolmetadata_size;
|
||||
sign_t poolmetadata_sign;
|
||||
uint32_t policy_percent_main;
|
||||
uint32_t policy_percent_meta;
|
||||
|
||||
int approx_alloc;
|
||||
int extents_are_pes; /* Is 'extents' counting PEs or LEs? */
|
||||
int size_changed; /* Was there actually a size change */
|
||||
int extend_fs_error; /* FS extend error after LV extend success */
|
||||
|
||||
const char *lockopt;
|
||||
char *lockd_lv_refresh_path; /* set during resize to use for refresh at the end */
|
||||
char *lockd_lv_refresh_uuid; /* set during resize to use for refresh at the end */
|
||||
|
||||
struct dm_list *pvh; /* list of pvs to use */
|
||||
};
|
||||
|
||||
void pvcreate_params_set_defaults(struct pvcreate_params *pp);
|
||||
@@ -745,9 +742,10 @@ int vgs_are_compatible(struct cmd_context *cmd,
|
||||
struct volume_group *vg_to);
|
||||
uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname);
|
||||
|
||||
int lv_resize(struct logical_volume *lv,
|
||||
struct lvresize_params *lp,
|
||||
struct dm_list *pvh);
|
||||
int lv_resize(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
struct lvresize_params *lp);
|
||||
int lv_extend_policy_calculate_percent(struct logical_volume *lv,
|
||||
uint32_t *amount, uint32_t *meta_amount);
|
||||
|
||||
struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const char *vgid,
|
||||
uint32_t read_flags, uint32_t lockd_state,
|
||||
|
@@ -4533,7 +4533,7 @@ void vg_write_commit_bad_mdas(struct cmd_context *cmd, struct volume_group *vg)
|
||||
* reread metadata.
|
||||
*/
|
||||
|
||||
static bool _scan_text_mismatch(struct cmd_context *cmd, const char *vgname, const char *vgid)
|
||||
bool scan_text_mismatch(struct cmd_context *cmd, const char *vgname, const char *vgid)
|
||||
{
|
||||
DM_LIST_INIT(mda_list);
|
||||
struct mda_list *mdal, *safe;
|
||||
@@ -4706,7 +4706,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
|
||||
* probably unnecessary; all commands could likely just check a single mda.
|
||||
*/
|
||||
|
||||
if (lvmcache_scan_mismatch(cmd, vgname, vgid) || _scan_text_mismatch(cmd, vgname, vgid)) {
|
||||
if (lvmcache_scan_mismatch(cmd, vgname, vgid) || scan_text_mismatch(cmd, vgname, vgid)) {
|
||||
log_debug_metadata("Rescanning devices for %s %s", vgname, writing ? "rw" : "");
|
||||
if (writing)
|
||||
lvmcache_label_rescan_vg_rw(cmd, vgname, vgid);
|
||||
@@ -5302,3 +5302,15 @@ int get_visible_lvs_using_pv(struct cmd_context *cmd, struct volume_group *vg, s
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lv_is_linear(struct logical_volume *lv)
|
||||
{
|
||||
struct lv_segment *seg = first_seg(lv);
|
||||
return segtype_is_linear(seg->segtype);
|
||||
}
|
||||
|
||||
int lv_is_striped(struct logical_volume *lv)
|
||||
{
|
||||
struct lv_segment *seg = first_seg(lv);
|
||||
return segtype_is_striped(seg->segtype);
|
||||
}
|
||||
|
||||
|
@@ -538,5 +538,7 @@ void set_pv_devices(struct format_instance *fid, struct volume_group *vg);
|
||||
int get_visible_lvs_using_pv(struct cmd_context *cmd, struct volume_group *vg, struct device *dev,
|
||||
struct dm_list *lvs_list);
|
||||
|
||||
bool scan_text_mismatch(struct cmd_context *cmd, const char *vgname, const char *vgid);
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -737,6 +737,7 @@ int handle_pool_metadata_spare(struct volume_group *vg, uint32_t extents,
|
||||
extents = MAX_SIZE;
|
||||
|
||||
if (!lv) {
|
||||
log_debug("Adding new pool metadata spare %u extents.", extents);
|
||||
if (!_alloc_pool_metadata_spare(vg, extents, pvh))
|
||||
return_0;
|
||||
|
||||
@@ -746,6 +747,8 @@ int handle_pool_metadata_spare(struct volume_group *vg, uint32_t extents,
|
||||
seg = last_seg(lv);
|
||||
seg_mirrors = lv_mirror_count(lv);
|
||||
|
||||
log_debug("Extending pool metadata spare from %u to %u extents.",
|
||||
lv->le_count, extents);
|
||||
/* Check spare LV is big enough and preserve segtype */
|
||||
if ((lv->le_count < extents) && seg &&
|
||||
!lv_extend(lv, seg->segtype,
|
||||
|
@@ -41,16 +41,15 @@ lvcreate -L2M -n $lv1 $vg
|
||||
"$LVM_TEST_THIN_RESTORE_CMD" -i data -o "$DM_DEV_DIR/mapper/$vg-$lv1"
|
||||
lvconvert -y --thinpool $vg/pool --poolmetadata $vg/$lv1
|
||||
|
||||
# active thin pool is needed to use policy
|
||||
not lvextend --use-policies $vg/pool 2>&1 | tee err
|
||||
|
||||
lvchange -ay $vg
|
||||
|
||||
# Cannot resize if set to 0%
|
||||
not lvextend --use-policies --config 'activation{thin_pool_autoextend_percent = 0}' $vg/pool 2>&1 | tee err
|
||||
grep "0%" err
|
||||
|
||||
# Locally active LV is needed
|
||||
not lvextend --use-policies $vg/pool 2>&1 | tee err
|
||||
grep "locally" err
|
||||
|
||||
lvchange -ay $vg
|
||||
|
||||
# Creation of new LV is not allowed when thinpool is over threshold
|
||||
not lvcreate -V10 $vg/pool
|
||||
|
||||
|
@@ -37,15 +37,18 @@ lvs -a $vg
|
||||
"$MKFS" "$lvdev"
|
||||
|
||||
# this should resolve to resize to same actual size
|
||||
lvreduce -r -f -l-100%FREE $vg/$lv1
|
||||
not lvreduce -l-100%FREE $vg/$lv1
|
||||
not lvreduce -r -f -l-100%FREE $vg/$lv1
|
||||
"$FSCK" -n "$lvdev"
|
||||
|
||||
# size should remain the same
|
||||
lvextend -r -f -l+100%FREE $vg/$lv1
|
||||
not lvextend -l+100%FREE $vg/$lv1
|
||||
not lvextend -r -f -l+100%FREE $vg/$lv1
|
||||
"$FSCK" -n "$lvdev"
|
||||
|
||||
#lvchange -an $vg/$lv1
|
||||
lvresize -r -f -l+100%FREE $vg/$lv1
|
||||
not lvresize -l+100%FREE $vg/$lv1
|
||||
not lvresize -r -f -l+100%FREE $vg/$lv1
|
||||
"$FSCK" -n "$lvdev"
|
||||
|
||||
# Check there is really file system resize happening
|
||||
@@ -55,7 +58,8 @@ lvresize -r -f -l+100%FREE $vg/$lv1
|
||||
grep "20000 blocks" out
|
||||
|
||||
SIZE=$(get lv_field $vg/$lv1 size)
|
||||
lvresize -r -f -l-100%FREE $vg/$lv1
|
||||
not lvresize -l-100%FREE $vg/$lv1
|
||||
not lvresize -r -f -l-100%FREE $vg/$lv1
|
||||
test "$SIZE" = "$(get lv_field $vg/$lv1 size)"
|
||||
|
||||
"$FSCK" -n "$lvdev" | tee out
|
||||
@@ -64,7 +68,10 @@ grep -v "20000 blocks" out
|
||||
|
||||
# Also check it fails when the user 'resize' volume without
|
||||
# resizing fs and then retries with '-r'.
|
||||
lvreduce -f -l50%VG $vg/$lv1
|
||||
fail lvresize -r -f -l50%VG $vg/$lv1
|
||||
# The first lvreduce intentionally ignores the fs and intentionally
|
||||
# corrupts the fs so that the second lvresize will fail when it runs
|
||||
# fsck.
|
||||
lvreduce -f --fs ignore -l50%VG $vg/$lv1
|
||||
fail lvresize -r -f -l20%VG $vg/$lv1
|
||||
|
||||
lvremove -ff $vg
|
||||
|
@@ -29,7 +29,7 @@ for deactivate in true false; do
|
||||
check mirror_images_contiguous $vg $lv1
|
||||
|
||||
# reduce 2-way mirror
|
||||
lvreduce -f -l-2 $vg/$lv1
|
||||
lvreduce -f --fs ignore -l-2 $vg/$lv1
|
||||
check mirror $vg $lv1 "$dev3"
|
||||
|
||||
# extend 2-way mirror (cling if not contiguous)
|
||||
|
@@ -52,7 +52,7 @@ lvcreate -an -Zn -l1 -n $lv1 -i3 $vg
|
||||
lvextend -l+100%FREE -i3 $vg/$lv1
|
||||
check vg_field $vg vg_free_count 2
|
||||
|
||||
lvreduce -f -l50%LV $vg/$lv1
|
||||
lvreduce -f --fs ignore -l50%LV $vg/$lv1
|
||||
vgremove -f $vg
|
||||
|
||||
vgcreate $SHARED -s 4M $vg "$dev1" "$dev2" "$dev3"
|
||||
@@ -72,21 +72,21 @@ lvextend -l+100%FREE $vg/lv
|
||||
check vg_field $vg vg_free_count 0
|
||||
|
||||
# Rounds up and should reduce just by 3 extents
|
||||
lvreduce -f -l-4 $vg/lv
|
||||
lvreduce -f --fs ignore -l-4 $vg/lv
|
||||
check vg_field $vg vg_free_count 3
|
||||
|
||||
# Should round up to 15 extents
|
||||
lvextend -f -l+1 $vg/lv
|
||||
check vg_field $vg vg_free_count 0
|
||||
|
||||
lvreduce -f -l-4 $vg/lv
|
||||
lvreduce -f --fs ignore -l-4 $vg/lv
|
||||
check vg_field $vg vg_free_count 3
|
||||
|
||||
lvextend -l90%VG $vg/lv
|
||||
check vg_field $vg vg_free_count 0
|
||||
|
||||
not lvreduce -f -l-10%LV $vg/lv
|
||||
not lvreduce -f --fs ignore -l-10%LV $vg/lv
|
||||
check vg_field $vg vg_free_count 0
|
||||
|
||||
lvreduce -f -l-20%LV $vg/lv
|
||||
lvreduce -f --fs ignore -l-20%LV $vg/lv
|
||||
check vg_field $vg vg_free_count 3
|
||||
|
24
tools/args.h
24
tools/args.h
@@ -301,6 +301,27 @@ arg(foreign_ARG, '\0', "foreign", 0, 0, 0,
|
||||
"Report/display foreign VGs that would otherwise be skipped.\n"
|
||||
"See \\fBlvmsystemid\\fP(7) for more information about foreign VGs.\n")
|
||||
|
||||
arg(fs_ARG, '\0', "fs", string_VAL, 0, 0,
|
||||
"File system handling when resizing an LV.\n"
|
||||
"\\fBchecksize\\fP: Only when reducing size, does nothing when extending.\n"
|
||||
"Check the fs size and reduce the LV if the fs is not using the affected\n"
|
||||
"space, i.e. the fs does not need to be shrunk. Fail the command without\n"
|
||||
"reducing the fs or LV if the fs is using the affected space.\n"
|
||||
"\\fBresize_remount\\fP: Resize the fs if needed. Mounts or unmounts the fs as\n"
|
||||
"required (avoids mounting/unmounting when possible.)\n"
|
||||
"Attempts to restore the original mount state when finished.\n"
|
||||
"\\fBresize_keepmount\\fP: Resize the fs if needed, only if it can be done without\n"
|
||||
"changing the current mount state. Fail the command without\n"
|
||||
"resizing the fs or LV if an fs resize requires mounting or unmounting\n"
|
||||
"\\fBresize_unmount\\fP: Resize the fs if needed, only while unmounted. Unmount the\n"
|
||||
"fs if needed. Fail the command without resizing the fs\n"
|
||||
"or LV if an fs resize is needed that requires the the fs to be mounted\n"
|
||||
"\\fBresize\\fP: Equivalent to resize_remount.\n"
|
||||
"\\fBresize_fsadm\\fP: Use the old method of calling fsadm to do handle the fs\n"
|
||||
"(deprecated).\n"
|
||||
"\\fBignore\\fP: Resize the LV without checking for or handling a file system.\n"
|
||||
"WARNING: using ignore when reducing the LV size may cause data loss.\n")
|
||||
|
||||
arg(handlemissingpvs_ARG, '\0', "handlemissingpvs", 0, 0, 0,
|
||||
"Allows a polling operation to continue when PVs are missing,\n"
|
||||
"e.g. for repairs due to faulty devices.\n")
|
||||
@@ -1447,7 +1468,8 @@ arg(readahead_ARG, 'r', "readahead", readahead_VAL, 0, 0,
|
||||
"\\fBnone\\fP is equivalent to zero.\n")
|
||||
|
||||
arg(resizefs_ARG, 'r', "resizefs", 0, 0, 0,
|
||||
"Resize underlying filesystem together with the LV using \\fBfsadm\\fP(8).\n")
|
||||
"Resize the file system on the LV.\n"
|
||||
"Equivalent to --fs resize_remount. See --fs for more options.\n")
|
||||
|
||||
/* Not used */
|
||||
arg(reset_ARG, 'R', "reset", 0, 0, 0, NULL)
|
||||
|
@@ -1379,35 +1379,35 @@ lvextend --size PSizeMB LV
|
||||
OO: --alloc Alloc, --autobackup Bool, --force, --mirrors Number,
|
||||
--nofsck, --nosync, --noudevsync, --reportformat ReportFmt, --resizefs,
|
||||
--stripes Number, --stripesize SizeKB, --poolmetadatasize PSizeMB,
|
||||
--type SegType
|
||||
--type SegType, --fs String
|
||||
OP: PV ...
|
||||
ID: lvextend_by_size
|
||||
ID: lvextend_size
|
||||
DESC: Extend an LV by a specified size.
|
||||
|
||||
lvextend LV PV ...
|
||||
OO: --alloc Alloc, --autobackup Bool, --force, --mirrors Number,
|
||||
--nofsck, --nosync, --noudevsync,
|
||||
--reportformat ReportFmt, --resizefs, --stripes Number, --stripesize SizeKB,
|
||||
--type SegType
|
||||
ID: lvextend_by_pv
|
||||
--type SegType, --fs String
|
||||
ID: lvextend_pv
|
||||
DESC: Extend an LV by specified PV extents.
|
||||
|
||||
lvextend --poolmetadatasize PSizeMB LV_thinpool
|
||||
lvextend --poolmetadatasize PSizeMB LV_thinpool_linear
|
||||
OO: --alloc Alloc, --autobackup Bool, --force, --mirrors Number,
|
||||
--nofsck, --nosync, --noudevsync,
|
||||
--reportformat ReportFmt, --stripes Number, --stripesize SizeKB,
|
||||
--type SegType
|
||||
OP: PV ...
|
||||
ID: lvextend_pool_metadata_by_size
|
||||
ID: lvextend_pool_metadata
|
||||
DESC: Extend a pool metadata SubLV by a specified size.
|
||||
|
||||
lvextend --usepolicies LV_thinpool_snapshot
|
||||
lvextend --usepolicies LV_snapshot_thinpool_vdopool
|
||||
OO: --alloc Alloc, --autobackup Bool, --force, --mirrors Number,
|
||||
--nofsck, --nosync, --noudevsync,
|
||||
--reportformat ReportFmt, --resizefs,
|
||||
--type SegType
|
||||
--type SegType, --fs String
|
||||
OP: PV ...
|
||||
ID: lvextend_by_policy
|
||||
ID: lvextend_policy
|
||||
DESC: Extend an LV according to a predefined policy.
|
||||
|
||||
---
|
||||
@@ -1454,8 +1454,8 @@ DESC: Remove the devices file entry for the given PVID.
|
||||
|
||||
lvreduce --size NSizeMB LV
|
||||
OO: --autobackup Bool, --force, --nofsck, --noudevsync,
|
||||
--reportformat ReportFmt, --resizefs
|
||||
ID: lvreduce_general
|
||||
--reportformat ReportFmt, --resizefs, --fs String
|
||||
ID: lvreduce_size
|
||||
|
||||
---
|
||||
|
||||
@@ -1484,17 +1484,17 @@ lvresize --size SSizeMB LV
|
||||
OO: --alloc Alloc, --autobackup Bool, --force,
|
||||
--nofsck, --nosync, --noudevsync, --reportformat ReportFmt, --resizefs,
|
||||
--stripes Number, --stripesize SizeKB, --poolmetadatasize PSizeMB,
|
||||
--type SegType
|
||||
--type SegType, --fs String
|
||||
OP: PV ...
|
||||
ID: lvresize_by_size
|
||||
ID: lvresize_size
|
||||
DESC: Resize an LV by a specified size.
|
||||
|
||||
lvresize LV PV ...
|
||||
OO: --alloc Alloc, --autobackup Bool, --force,
|
||||
--nofsck, --nosync, --noudevsync,
|
||||
--reportformat ReportFmt, --resizefs, --stripes Number, --stripesize SizeKB,
|
||||
--type SegType
|
||||
ID: lvresize_by_pv
|
||||
--type SegType, --fs String
|
||||
ID: lvresize_pv
|
||||
DESC: Resize an LV by specified PV extents.
|
||||
|
||||
lvresize --poolmetadatasize PSizeMB LV_thinpool
|
||||
@@ -1503,7 +1503,7 @@ OO: --alloc Alloc, --autobackup Bool, --force,
|
||||
--reportformat ReportFmt, --stripes Number, --stripesize SizeKB,
|
||||
--type SegType
|
||||
OP: PV ...
|
||||
ID: lvresize_pool_metadata_by_size
|
||||
ID: lvresize_pool_metadata
|
||||
DESC: Resize a pool metadata SubLV by a specified size.
|
||||
|
||||
---
|
||||
|
@@ -17,5 +17,5 @@
|
||||
|
||||
int lvextend(struct cmd_context *cmd, int argc, char **argv)
|
||||
{
|
||||
return lvresize(cmd, argc, argv);
|
||||
return lvresize_cmd(cmd, argc, argv);
|
||||
}
|
||||
|
@@ -165,6 +165,16 @@ static const struct command_function _command_functions[CMD_COUNT] = {
|
||||
|
||||
{ pvscan_display_CMD, pvscan_display_cmd },
|
||||
{ pvscan_cache_CMD, pvscan_cache_cmd },
|
||||
|
||||
/* lvextend/lvreduce/lvresize */
|
||||
{ lvextend_policy_CMD, lvextend_policy_cmd },
|
||||
{ lvextend_pool_metadata_CMD, lvresize_cmd },
|
||||
{ lvresize_pool_metadata_CMD, lvresize_cmd },
|
||||
{ lvextend_pv_CMD, lvresize_cmd },
|
||||
{ lvresize_pv_CMD, lvresize_cmd },
|
||||
{ lvextend_size_CMD, lvresize_cmd },
|
||||
{ lvreduce_size_CMD, lvresize_cmd },
|
||||
{ lvresize_size_CMD, lvresize_cmd },
|
||||
};
|
||||
|
||||
|
||||
@@ -3143,6 +3153,9 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
if (!(cmd->command = _find_command(cmd, cmd->name, &argc, argv)))
|
||||
return EINVALID_CMD_LINE;
|
||||
|
||||
/* avoid this by letting lib code use cmd->command */
|
||||
cmd->command_enum = cmd->command->command_enum;
|
||||
|
||||
/*
|
||||
* If option --foo is set which is listed in IO (ignore option) in
|
||||
* command-lines.in, then unset foo. Commands won't usually use an
|
||||
|
@@ -17,5 +17,5 @@
|
||||
|
||||
int lvreduce(struct cmd_context *cmd, int argc, char **argv)
|
||||
{
|
||||
return lvresize(cmd, argc, argv);
|
||||
return lvresize_cmd(cmd, argc, argv);
|
||||
}
|
||||
|
407
tools/lvresize.c
407
tools/lvresize.c
@@ -15,12 +15,133 @@
|
||||
|
||||
#include "tools.h"
|
||||
|
||||
static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
|
||||
struct lvresize_params *lp)
|
||||
static int _lvresize_params(struct cmd_context *cmd, struct lvresize_params *lp)
|
||||
{
|
||||
const char *cmd_name = command_name(cmd);
|
||||
const char *type_str = arg_str_value(cmd, type_ARG, NULL);
|
||||
int only_linear = 0;
|
||||
int set_fsopt = 0;
|
||||
int set_extents_and_size = 0;
|
||||
|
||||
memset(lp, 0, sizeof(struct lvresize_params));
|
||||
|
||||
switch (cmd->command->command_enum) {
|
||||
case lvextend_policy_CMD:
|
||||
lp->resize = LV_EXTEND;
|
||||
lp->size = 0;
|
||||
lp->extents = 0;
|
||||
lp->percent = PERCENT_LV;
|
||||
lp->sign = SIGN_PLUS;
|
||||
lp->poolmetadata_size = 0;
|
||||
lp->use_policies = 1;
|
||||
break;
|
||||
|
||||
case lvextend_pool_metadata_CMD:
|
||||
case lvresize_pool_metadata_CMD:
|
||||
lp->resize = LV_EXTEND;
|
||||
lp->size = 0;
|
||||
lp->extents = 0;
|
||||
lp->percent = PERCENT_NONE;
|
||||
lp->sign = SIGN_NONE;
|
||||
lp->poolmetadata_size = arg_uint64_value(cmd, poolmetadatasize_ARG, 0);
|
||||
lp->poolmetadata_sign = arg_sign_value(cmd, poolmetadatasize_ARG, SIGN_NONE);
|
||||
break;
|
||||
|
||||
case lvextend_pv_CMD:
|
||||
case lvresize_pv_CMD:
|
||||
lp->resize = LV_EXTEND;
|
||||
lp->size = 0;
|
||||
lp->extents = 0;
|
||||
lp->percent_value = 100;
|
||||
lp->percent = PERCENT_PVS;
|
||||
lp->sign = SIGN_PLUS;
|
||||
lp->poolmetadata_size = 0;
|
||||
set_fsopt = 1;
|
||||
break;
|
||||
|
||||
case lvextend_size_CMD:
|
||||
lp->resize = LV_EXTEND;
|
||||
if ((lp->poolmetadata_size = arg_uint64_value(cmd, poolmetadatasize_ARG, 0)))
|
||||
lp->poolmetadata_sign = arg_sign_value(cmd, poolmetadatasize_ARG, SIGN_NONE);
|
||||
set_extents_and_size = 1;
|
||||
set_fsopt = 1;
|
||||
break;
|
||||
|
||||
case lvreduce_size_CMD:
|
||||
lp->resize = LV_REDUCE;
|
||||
lp->poolmetadata_size = 0;
|
||||
set_extents_and_size = 1;
|
||||
set_fsopt = 1;
|
||||
break;
|
||||
|
||||
case lvresize_size_CMD:
|
||||
lp->resize = LV_ANY;
|
||||
lp->poolmetadata_size = arg_uint64_value(cmd, poolmetadatasize_ARG, 0);
|
||||
if ((lp->poolmetadata_size = arg_uint64_value(cmd, poolmetadatasize_ARG, 0)))
|
||||
lp->poolmetadata_sign = arg_sign_value(cmd, poolmetadatasize_ARG, SIGN_NONE);
|
||||
set_extents_and_size = 1;
|
||||
set_fsopt = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
log_error(INTERNAL_ERROR "unknown lvresize type");
|
||||
return 0;
|
||||
};
|
||||
|
||||
if (set_fsopt) {
|
||||
const char *str;
|
||||
if ((str = arg_str_value(cmd, fs_ARG, NULL))) {
|
||||
if (!strcmp(str, "checksize") ||
|
||||
!strcmp(str, "resize") ||
|
||||
!strcmp(str, "resize_remount") ||
|
||||
!strcmp(str, "resize_keepmount") ||
|
||||
!strcmp(str, "resize_unmount") ||
|
||||
!strcmp(str, "resize_fsadm")) {
|
||||
strncpy(lp->fsopt, str, sizeof(lp->fsopt)-1);
|
||||
} else if (!strcmp(str, "ignore")) {
|
||||
lp->fsopt[0] = '\0';
|
||||
} else {
|
||||
log_error("Unknown --fs value.");
|
||||
return 0;
|
||||
}
|
||||
} else if (arg_is_set(cmd, resizefs_ARG)) {
|
||||
/* --resizefs alone equates to --fs resize */
|
||||
strncpy(lp->fsopt, "resize", sizeof(lp->fsopt)-1);
|
||||
} else {
|
||||
/*
|
||||
* Use checksize when no fs option is specified.
|
||||
* checksize with extend does nothing: the LV
|
||||
* is extended and any fs is ignored.
|
||||
* checksize with reduce checks for an fs that
|
||||
* needs reducing: the LV is reduced only if the
|
||||
* fs does not need to be reduced (or no fs.)
|
||||
*/
|
||||
strncpy(lp->fsopt, "checksize", sizeof(lp->fsopt)-1);
|
||||
}
|
||||
|
||||
if (lp->fsopt[0])
|
||||
lp->nofsck = arg_is_set(cmd, nofsck_ARG);
|
||||
}
|
||||
|
||||
if (set_extents_and_size) {
|
||||
if ((lp->extents = arg_uint_value(cmd, extents_ARG, 0))) {
|
||||
lp->sign = arg_sign_value(cmd, extents_ARG, 0);
|
||||
lp->percent = arg_percent_value(cmd, extents_ARG, PERCENT_NONE);
|
||||
}
|
||||
if ((lp->size = arg_uint64_value(cmd, size_ARG, 0))) {
|
||||
lp->sign = arg_sign_value(cmd, size_ARG, 0);
|
||||
lp->percent = PERCENT_NONE;
|
||||
}
|
||||
if (lp->size && lp->extents) {
|
||||
log_error("Please specify either size or extents but not both.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
lp->alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, 0);
|
||||
lp->yes = arg_is_set(cmd, yes_ARG);
|
||||
lp->force = arg_is_set(cmd, force_ARG),
|
||||
lp->nosync = arg_is_set(cmd, nosync_ARG);
|
||||
lp->lockopt = arg_str_value(cmd, lockopt_ARG, NULL);
|
||||
|
||||
if (type_str) {
|
||||
if (!strcmp(type_str, "linear")) {
|
||||
@@ -32,104 +153,6 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
|
||||
return_0;
|
||||
}
|
||||
|
||||
if (!strcmp(cmd_name, "lvreduce"))
|
||||
lp->resize = LV_REDUCE;
|
||||
else if (!strcmp(cmd_name, "lvextend"))
|
||||
lp->resize = LV_EXTEND;
|
||||
else
|
||||
lp->resize = LV_ANY;
|
||||
|
||||
lp->sign = lp->poolmetadata_sign = SIGN_NONE;
|
||||
|
||||
if ((lp->use_policies = arg_is_set(cmd, usepolicies_ARG))) {
|
||||
/* do nothing; lv_resize will handle --use-policies itself */
|
||||
if (arg_from_list_is_set(cmd, NULL,
|
||||
chunksize_ARG, extents_ARG,
|
||||
poolmetadatasize_ARG,
|
||||
regionsize_ARG,
|
||||
size_ARG,
|
||||
stripes_ARG, stripesize_ARG,
|
||||
-1))
|
||||
log_print_unless_silent("Ignoring size parameters with --use-policies.");
|
||||
} else {
|
||||
/*
|
||||
* Allow omission of extents and size if the user has given us
|
||||
* one or more PVs. Most likely, the intent was "resize this
|
||||
* LV the best you can with these PVs"
|
||||
* If only --poolmetadatasize is specified with list of PVs,
|
||||
* then metadata will be extended there.
|
||||
*/
|
||||
if ((lp->extents = arg_uint_value(cmd, extents_ARG, 0))) {
|
||||
lp->sign = arg_sign_value(cmd, extents_ARG, SIGN_NONE);
|
||||
lp->percent = arg_percent_value(cmd, extents_ARG, PERCENT_NONE);
|
||||
}
|
||||
|
||||
if (arg_from_list_is_zero(cmd, "may not be zero",
|
||||
chunksize_ARG, extents_ARG,
|
||||
poolmetadatasize_ARG,
|
||||
regionsize_ARG,
|
||||
size_ARG,
|
||||
stripes_ARG, stripesize_ARG,
|
||||
virtualsize_ARG,
|
||||
-1))
|
||||
return_0;
|
||||
|
||||
if ((lp->poolmetadata_size = arg_uint64_value(cmd, poolmetadatasize_ARG, 0))) {
|
||||
lp->poolmetadata_sign = arg_sign_value(cmd, poolmetadatasize_ARG, SIGN_NONE);
|
||||
if (lp->poolmetadata_sign == SIGN_MINUS) {
|
||||
log_error("Can't reduce pool metadata size.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((lp->size = arg_uint64_value(cmd, size_ARG, 0))) {
|
||||
lp->sign = arg_sign_value(cmd, size_ARG, SIGN_NONE);
|
||||
lp->percent = PERCENT_NONE;
|
||||
}
|
||||
|
||||
if (lp->size && lp->extents) {
|
||||
log_error("Please specify either size or extents but not both.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!lp->extents &&
|
||||
!lp->size &&
|
||||
!lp->poolmetadata_size &&
|
||||
(argc >= 2)) {
|
||||
lp->extents = 100;
|
||||
lp->percent = PERCENT_PVS;
|
||||
lp->sign = SIGN_PLUS;
|
||||
}
|
||||
}
|
||||
|
||||
if (lp->resize == LV_EXTEND && lp->sign == SIGN_MINUS) {
|
||||
log_error("Negative argument not permitted - use lvreduce.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lp->resize == LV_REDUCE &&
|
||||
((lp->sign == SIGN_PLUS) ||
|
||||
(lp->poolmetadata_sign == SIGN_PLUS))) {
|
||||
log_error("Positive sign not permitted - use lvextend.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!argc) {
|
||||
log_error("Please provide the logical volume name.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
lp->lv_name = argv[0];
|
||||
|
||||
if (!validate_lvname_param(cmd, &lp->vg_name, &lp->lv_name))
|
||||
return_0;
|
||||
|
||||
/* Check for $LVM_VG_NAME */
|
||||
if (!lp->vg_name && !(lp->vg_name = extract_vgname(cmd, NULL))) {
|
||||
log_error("Please specify a logical volume path.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (arg_is_set(cmd, mirrors_ARG)) {
|
||||
if (arg_sign_value(cmd, mirrors_ARG, SIGN_NONE) != SIGN_NONE) {
|
||||
log_error("Mirrors argument may not be signed.");
|
||||
@@ -156,66 +179,153 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
|
||||
return 0;
|
||||
}
|
||||
|
||||
lp->argc = --argc;
|
||||
lp->argv = ++argv;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _lvresize_single(struct cmd_context *cmd, const char *vg_name,
|
||||
struct volume_group *vg, struct processing_handle *handle)
|
||||
/*
|
||||
* lvextend --use-policies is usually called by dmeventd, as a method of
|
||||
* "auto extending" an LV as it's used. It checks how full a snapshot cow or
|
||||
* thin pool is, and extends it if it's too full, based on threshold settings
|
||||
* in lvm.conf for when to auto extend it.
|
||||
*
|
||||
* The extension of a thin pool LV can involve extending either the data sub
|
||||
* LV, the metadata sub LV, or both, so there may be two LVs extended here.
|
||||
*/
|
||||
static int _lv_extend_policy(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
struct lvresize_params *lp, int *skipped)
|
||||
{
|
||||
struct lvresize_params *lp = (struct lvresize_params *) handle->custom_handle;
|
||||
struct dm_list *pvh;
|
||||
struct logical_volume *lv;
|
||||
int ret = ECMD_FAILED;
|
||||
struct lvresize_params lp_meta;
|
||||
uint32_t percent_main = 0;
|
||||
uint32_t percent_meta = 0;
|
||||
int is_active;
|
||||
|
||||
/* Does LV exist? */
|
||||
if (!(lv = find_lv(vg, lp->lv_name))) {
|
||||
log_error("Logical volume %s not found in volume group %s.",
|
||||
lp->lv_name, vg->name);
|
||||
goto out;
|
||||
memset(&lp_meta, 0, sizeof(lp_meta));
|
||||
|
||||
if (!lv_is_cow(lv) && !lv_is_thin_pool(lv) && !lv_is_vdo_pool(lv)) {
|
||||
log_error("lvextend policy is supported only for snapshot, thin pool and vdo pool volumes.");
|
||||
*skipped = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(pvh = lp->argc ? create_pv_list(cmd->mem, vg, lp->argc, lp->argv, 1) : &vg->pvs))
|
||||
goto_out;
|
||||
is_active = lv_is_active(lv);
|
||||
|
||||
if (!lv_resize(lv, lp, pvh))
|
||||
goto_out;
|
||||
if (vg_is_shared(lv->vg) && !is_active) {
|
||||
log_debug("lvextend policy requires LV to be active in a shared VG.");
|
||||
*skipped = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = ECMD_PROCESSED;
|
||||
out:
|
||||
return ret;
|
||||
if (lv_is_thin_pool(lv) && !is_active) {
|
||||
log_error("lvextend using policy requires the thin pool to be active.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the percent of extents to extend the LV based on current
|
||||
* usage info from the kernel and policy settings from lvm.conf, e.g.
|
||||
* autoextend_threshold, autoextend_percent. For thin pools, both the
|
||||
* thin pool data LV and thin pool metadata LV may need to be extended.
|
||||
* In this case, percent_main is the amount to extend the data LV, and
|
||||
* percent_meta is the amount to extend the metadata LV.
|
||||
*/
|
||||
if (!lv_extend_policy_calculate_percent(lv, &percent_main, &percent_meta))
|
||||
return_0;
|
||||
|
||||
if (!percent_main && !percent_meta) {
|
||||
log_debug("lvextend policy not needed.");
|
||||
*skipped = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*skipped = 0;
|
||||
lp->policy_percent_main = percent_main;
|
||||
lp->policy_percent_meta = percent_meta;
|
||||
|
||||
return lv_resize(cmd, lv, lp);
|
||||
}
|
||||
|
||||
int lvresize(struct cmd_context *cmd, int argc, char **argv)
|
||||
static int _lvextend_policy_single(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
struct processing_handle *handle)
|
||||
{
|
||||
struct processing_handle *handle;
|
||||
struct lvresize_params lp = {
|
||||
.alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, 0),
|
||||
.yes = arg_is_set(cmd, yes_ARG),
|
||||
.force = arg_is_set(cmd, force_ARG),
|
||||
.nofsck = arg_is_set(cmd, nofsck_ARG),
|
||||
.nosync = arg_is_set(cmd, nosync_ARG),
|
||||
.resizefs = arg_is_set(cmd, resizefs_ARG),
|
||||
.lockopt = arg_str_value(cmd, lockopt_ARG, NULL),
|
||||
};
|
||||
struct lvresize_params *lp = (struct lvresize_params *) handle->custom_handle;
|
||||
int skipped = 0;
|
||||
|
||||
if (cmd->position_argc > 1) {
|
||||
/* First pos arg is required LV, remaining are optional PVs. */
|
||||
if (!(lp->pvh = create_pv_list(cmd->mem, lv->vg, cmd->position_argc - 1, cmd->position_argv + 1, 0)))
|
||||
return_ECMD_FAILED;
|
||||
} else
|
||||
lp->pvh = &lv->vg->pvs;
|
||||
|
||||
if (!_lv_extend_policy(cmd, lv, lp, &skipped))
|
||||
return ECMD_FAILED;
|
||||
|
||||
if (!skipped)
|
||||
log_print_unless_silent("Logical volume %s successfully resized.", display_lvname(lv));
|
||||
return ECMD_PROCESSED;
|
||||
}
|
||||
|
||||
static int _lvresize_single(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
struct processing_handle *handle)
|
||||
{
|
||||
struct lvresize_params *lp = (struct lvresize_params *) handle->custom_handle;
|
||||
int ret;
|
||||
|
||||
if (!_lvresize_params(cmd, argc, argv, &lp)) {
|
||||
stack;
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
if (cmd->position_argc > 1) {
|
||||
/* First pos arg is required LV, remaining are optional PVs. */
|
||||
if (!(lp->pvh = create_pv_list(cmd->mem, lv->vg, cmd->position_argc - 1, cmd->position_argv + 1, 0)))
|
||||
return_ECMD_FAILED;
|
||||
} else
|
||||
lp->pvh = &lv->vg->pvs;
|
||||
|
||||
if (!(handle = init_processing_handle(cmd, NULL))) {
|
||||
log_error("Failed to initialize processing handle.");
|
||||
ret = lv_resize(cmd, lv, lp);
|
||||
|
||||
if (ret || lp->extend_fs_error)
|
||||
log_print_unless_silent("Logical volume %s successfully resized.",
|
||||
display_lvname(lv));
|
||||
if (!ret)
|
||||
return ECMD_FAILED;
|
||||
return ECMD_PROCESSED;
|
||||
}
|
||||
|
||||
int lvextend_policy_cmd(struct cmd_context *cmd, int argc, char **argv)
|
||||
{
|
||||
struct processing_handle *handle;
|
||||
struct lvresize_params lp;
|
||||
int ret;
|
||||
|
||||
if (!_lvresize_params(cmd, &lp))
|
||||
return EINVALID_CMD_LINE;
|
||||
|
||||
if (!(handle = init_processing_handle(cmd, NULL)))
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
handle->custom_handle = &lp;
|
||||
|
||||
ret = process_each_vg(cmd, 0, NULL, lp.vg_name, NULL, READ_FOR_UPDATE, 0, handle,
|
||||
&_lvresize_single);
|
||||
ret = process_each_lv(cmd, 1, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
|
||||
handle, NULL, &_lvextend_policy_single);
|
||||
|
||||
destroy_processing_handle(cmd, handle);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int lvresize_cmd(struct cmd_context *cmd, int argc, char **argv)
|
||||
{
|
||||
struct processing_handle *handle;
|
||||
struct lvresize_params lp;
|
||||
int ret;
|
||||
|
||||
if (!_lvresize_params(cmd, &lp))
|
||||
return EINVALID_CMD_LINE;
|
||||
|
||||
if (!(handle = init_processing_handle(cmd, NULL)))
|
||||
return ECMD_FAILED;
|
||||
|
||||
handle->custom_handle = &lp;
|
||||
|
||||
ret = process_each_lv(cmd, 1, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
|
||||
handle, NULL, &_lvresize_single);
|
||||
|
||||
destroy_processing_handle(cmd, handle);
|
||||
|
||||
@@ -224,3 +334,16 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* All lvresize command defs have their own function,
|
||||
* so the generic function name is unused.
|
||||
*/
|
||||
|
||||
int lvresize(struct cmd_context *cmd, int argc, char **argv)
|
||||
{
|
||||
log_error(INTERNAL_ERROR "Missing function for command definition %d:%s.",
|
||||
cmd->command->command_index, cmd->command->command_id);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
|
@@ -45,19 +45,18 @@
|
||||
#include "lib/notify/lvmnotify.h"
|
||||
#include "lib/label/hints.h"
|
||||
|
||||
/*
|
||||
* cmd_enum.h uses the generated cmds.h to create the enum with an ID
|
||||
* for each command definition in command-lines.in.
|
||||
*/
|
||||
#include "lib/commands/cmd_enum.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define CMD_LEN 256
|
||||
#define MAX_ARGS 64
|
||||
|
||||
/* define the enums for each unique ID in command defs in command-lines.in */
|
||||
enum {
|
||||
#define cmd(a, b) a ,
|
||||
#include "cmds.h"
|
||||
#undef cmd
|
||||
};
|
||||
|
||||
/* define the enums for the values accepted by command line --options, foo_VAL */
|
||||
enum {
|
||||
#define val(a, b, c, d) a ,
|
||||
@@ -295,4 +294,7 @@ int lvconvert_cachevol_attach_single(struct cmd_context *cmd,
|
||||
struct logical_volume *lv,
|
||||
struct processing_handle *handle);
|
||||
|
||||
int lvresize_cmd(struct cmd_context *cmd, int argc, char **argv);
|
||||
int lvextend_policy_cmd(struct cmd_context *cmd, int argc, char **argv);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user