1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-09-30 17:44:21 +03:00

Compare commits

...

3 Commits

Author SHA1 Message Date
David Teigland
2e1e61bfd6 lvresize: use script to call fs commands
Intead of calling each fs command directly, call a helper
script that will run those commands.
2022-09-02 16:45:36 -05:00
David Teigland
c2b31ee8d5 lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV.  --resizefs is the same as --fs resize.

Possible --fs values:

checksize
  Only used when reducing the size, does nothing when exending.
  Check the fs size, and reduce the LV if the fs is not using
  the affected space, i.e. the fs does not need to be shrunk.
  Fail the command without reducing the fs or LV if the fs is
  using the affected space.

resize_remount | resize
  Resize the fs if needed. Mounts or unmounts the fs as
  required (avoids mounting/unmounting when possible.)
  Attempts to restore the original mount state when finished.

resize_keepmount
  Resize the fs if needed, only if it can be done without
  changing the current mount state. Fail the command without
  resizing the fs or LV if an fs resize requires mounting or
  unmounting.

resize_unmount
  Resize the fs if needed, only while unmounted. Unmount the
  fs if needed.  Fail the command without resizing the fs
  or LV if an fs resize is needed that requires the the fs
  to be mounted.

resize_fsadm
  Use the old method of calling fsadm to do handle the fs
  (deprecated).

ignore
  Resize the LV without checking for or handling a file system.

Notes on lvreduce:

When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
  (includes activating the LV.)

With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-08-19 13:59:16 -05:00
David Teigland
7bcd93321d lvresize: restructure code
Rewrite top level resize function to prepare for adding
new fs resizing.
2022-08-19 13:59:16 -05:00
36 changed files with 4771 additions and 711 deletions

View File

@@ -1713,6 +1713,24 @@ 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.])
CRYPTSETUP_PATH="$SBINDIR/cryptsetup"
AC_DEFINE_UNQUOTED(CRYPTSETUP_PATH, ["$CRYPTSETUP_PATH"], [Path to cryptsetup binary.])
################################################################################
dnl -- dmeventd pidfile and executable path
if test "$BUILD_DMEVENTD" = yes; then
@@ -1882,6 +1900,12 @@ 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(CRYPTSETUP_PATH)
AC_SUBST(BLKDEACTIVATE)
AC_SUBST(HAVE_LIBDL)
AC_SUBST(HAVE_REALTIME)

View File

@@ -127,8 +127,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

View File

@@ -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
View 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

View File

@@ -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;

View File

@@ -26,6 +26,11 @@
#ifdef BLKID_WIPING_SUPPORT
#include <blkid.h>
/*
* FIXME: recent addition to blkid.h copied here.
* Remove this and require a recent libblkid version from configure.
*/
#define BLKID_SUBLKS_FSINFO (1 << 11) /* read and define fs properties from superblock */
#endif
#ifdef UDEV_SYNC_SUPPORT
@@ -838,6 +843,102 @@ int get_fs_block_size(const char *pathname, uint32_t *fs_block_size)
return 0;
}
}
int get_fs_type(const char *pathname, char *fstype)
{
char *str = NULL;
if ((str = blkid_get_tag_value(NULL, "TYPE", pathname))) {
log_debug("Found blkid TYPE %s on %s", str, pathname);
strncpy(fstype, str, FSTYPE_MAX);
free(str);
return 1;
} else {
log_debug("No blkid TYPE for fs on %s", pathname);
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);
/* We don't expect to get this info for luks */
if (strcmp(fsi->fstype, "crypto_LUKS") && (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 +946,16 @@ int get_fs_block_size(const char *pathname, uint32_t *fs_block_size)
*fs_block_size = 0;
return 0;
}
int get_fs_type(const char *pathname, char *fstype)
{
log_debug("Disabled blkid TYPE for fs.");
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

View File

@@ -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,8 @@ 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 get_fs_type(const char *pathname, char *fstype);
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);

450
lib/device/filesystem.c Normal file
View File

@@ -0,0 +1,450 @@
/*
* 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 <dirent.h>
#include <mntent.h>
#include <sys/ioctl.h>
/*
* crypt offset is usually the LUKS header size but can be larger.
* The LUKS header is usually 2MB for LUKS1 and 16MB for LUKS2.
* The offset needs to be subtracted from the LV size to get the
* size used to resize the crypt device.
*/
static int _get_crypt_table_offset(dev_t crypt_devt, uint32_t *offset_bytes)
{
struct dm_task *dmt = dm_task_create(DM_DEVICE_TABLE);
uint64_t start, length;
char *target_type = NULL;
void *next = NULL;
char *params = NULL;
char offset_str[32] = { 0 };
int copy_offset = 0;
int spaces = 0;
int i, i_off = 0;
if (!dmt)
return_0;
if (!dm_task_set_major_minor(dmt, (int)MAJOR(crypt_devt), (int)MINOR(crypt_devt), 0)) {
dm_task_destroy(dmt);
return_0;
}
/* Non-blocking status read */
if (!dm_task_no_flush(dmt))
log_warn("WARNING: Can't set no_flush for dm status.");
if (!dm_task_run(dmt)) {
dm_task_destroy(dmt);
return_0;
}
next = dm_get_next_target(dmt, next, &start, &length, &target_type, &params);
if (!target_type || !params || strcmp(target_type, "crypt")) {
dm_task_destroy(dmt);
return_0;
}
/*
* get offset from params string:
* <cipher> <key> <iv_offset> <device> <offset> [<#opt_params> <opt_params>]
* <offset> is reported in 512 byte sectors.
*/
for (i = 0; i < strlen(params); i++) {
if (params[i] == ' ') {
spaces++;
if (spaces == 4)
copy_offset = 1;
if (spaces == 5)
break;
continue;
}
if (!copy_offset)
continue;
offset_str[i_off++] = params[i];
if (i_off == sizeof(offset_str)) {
offset_str[0] = '\0';
break;
}
}
dm_task_destroy(dmt);
if (!offset_str[0])
return_0;
*offset_bytes = ((uint32_t)strtoul(offset_str, NULL, 0) * 512);
return 1;
}
/*
* Set the path of the dm-crypt device, i.e. /dev/dm-N, that is using the LV.
*/
static int _get_crypt_path(dev_t lv_devt, char *lv_path, char *crypt_path)
{
char holders_path[PATH_MAX];
char *holder_name;
DIR *dr;
struct stat st;
struct dirent *de;
int ret = 0;
if (dm_snprintf(holders_path, sizeof(holders_path), "%sdev/block/%d:%d/holders",
dm_sysfs_dir(), (int)MAJOR(lv_devt), (int)MINOR(lv_devt)) < 0)
return_0;
/* If the crypt dev is not active, there will be no LV holder. */
if (stat(holders_path, &st)) {
log_error("Missing %s for %s", crypt_path, lv_path);
return 0;
}
if (!(dr = opendir(holders_path))) {
log_error("Cannot open %s", holders_path);
return 0;
}
while ((de = readdir(dr))) {
if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
continue;
holder_name = de->d_name;
if (strncmp(holder_name, "dm", 2)) {
log_error("Unrecognized holder %s of %s", holder_name, lv_path);
ret = 0;
break;
}
/* We could read the holder's dm uuid to verify it's a crypt dev. */
if (dm_snprintf(crypt_path, PATH_MAX, "/dev/%s", holder_name) < 0) {
ret = 0;
stack;
break;
}
ret = 1;
break;
}
closedir(dr);
if (ret)
log_debug("Found holder %s of %s.", crypt_path, lv_path);
else
log_debug("No holder in %s", holders_path);
return ret;
}
int fs_get_info(struct cmd_context *cmd, struct logical_volume *lv,
struct fs_info *fsi, int include_mount)
{
char lv_path[PATH_MAX];
char crypt_path[PATH_MAX];
struct stat st_lv;
struct stat st_crypt;
struct stat st_top;
struct stat stme;
struct fs_info info;
FILE *fme = NULL;
struct mntent *me;
int ret;
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;
}
if (stat(lv_path, &st_lv) < 0) {
log_error("Failed to get LV path %s", lv_path);
return 0;
}
memset(&info, 0, sizeof(info));
if (!fs_get_blkid(lv_path, &info)) {
log_error("No file system info from blkid for %s", display_lvname(lv));
return 0;
}
if (fsi->nofs)
return 1;
/*
* If there's a LUKS dm-crypt layer over the LV, then
* return fs info from that layer, setting needs_crypt
* to indicate a crypt layer between the fs and LV.
*/
if (!strcmp(info.fstype, "crypto_LUKS")) {
if (!_get_crypt_path(st_lv.st_rdev, lv_path, crypt_path)) {
log_error("Cannot find active LUKS dm-crypt device using %s.",
display_lvname(lv));
return 0;
}
if (stat(crypt_path, &st_crypt) < 0) {
log_error("Failed to get crypt path %s", crypt_path);
return 0;
}
memset(&info, 0, sizeof(info));
log_print("File system found on crypt device %s on LV %s.",
crypt_path, display_lvname(lv));
if (!fs_get_blkid(crypt_path, &info)) {
log_error("No file system info from blkid for dm-crypt device %s on LV %s.",
crypt_path, display_lvname(lv));
return 0;
}
*fsi = info;
fsi->needs_crypt = 1;
fsi->crypt_devt = st_crypt.st_rdev;
memcpy(fsi->fs_dev_path, crypt_path, PATH_MAX);
st_top = st_crypt;
if (!_get_crypt_table_offset(st_crypt.st_rdev, &fsi->crypt_offset_bytes)) {
log_error("Failed to get crypt data offset.");
return 0;
}
} else {
*fsi = info;
memcpy(fsi->fs_dev_path, lv_path, PATH_MAX);
st_top = st_lv;
}
if (!include_mount)
return 1;
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 != st_top.st_rdev)
continue;
log_debug("fs_get_info %s is mounted \"%s\"", fsi->fs_dev_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 16
int crypt_resize_script(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
uint64_t newsize_bytes)
{
char crypt_path[PATH_MAX];
char newsize_bytes_str[16] = { 0 };
const char *argv[FS_CMD_MAX_ARGS + 4];
int args = 0;
int status;
if (dm_snprintf(newsize_bytes_str, sizeof(newsize_bytes_str), "%llu", (unsigned long long)newsize_bytes) < 0)
return_0;
if (dm_snprintf(crypt_path, sizeof(crypt_path), "/dev/dm-%d", (int)MINOR(fsi->crypt_devt)) < 0)
return_0;
argv[0] = "/usr/sbin/lvresize_fs_helper"; /* define in configure? */
argv[++args] = "--cryptresize";
argv[++args] = "--cryptpath";
argv[++args] = crypt_path;
argv[++args] = "--newsizebytes";
argv[++args] = newsize_bytes_str;
argv[++args] = NULL;
if (!exec_cmd(cmd, argv, &status, 1)) {
log_error("Failed to resize crypt dev with lvresize_fs_helper.");
return 0;
}
return 1;
}
/*
* The helper script does the following steps for reduce:
* devpath = $cryptpath ? $cryptpath : $lvpath
* if needs_unmount
* umount $mountdir
* if needs_fsck
* e2fsck -f -p $devpath
* if needs_mount
* mount $devpath $tmpdir
* if $fstype == "ext"
* resize2fs $devpath $newsize_kb
* if needs_crypt
* cryptsetup resize --size $newsize_sectors $cryptpath
*/
int fs_reduce_script(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
uint64_t newsize_bytes, char *fsopt)
{
char lv_path[PATH_MAX];
char crypt_path[PATH_MAX];
char newsize_bytes_str[16] = { 0 };
const char *argv[FS_CMD_MAX_ARGS + 4];
int args = 0;
int status;
if (dm_snprintf(newsize_bytes_str, sizeof(newsize_bytes_str), "%llu", (unsigned long long)newsize_bytes) < 0)
return_0;
if (dm_snprintf(lv_path, PATH_MAX, "%s%s/%s", lv->vg->cmd->dev_dir, lv->vg->name, lv->name) < 0)
return_0;
argv[0] = "/usr/sbin/lvresize_fs_helper"; /* define in configure? */
argv[++args] = "--fsreduce";
argv[++args] = "--fstype";
argv[++args] = fsi->fstype;
argv[++args] = "--lvpath";
argv[++args] = lv_path;
if (newsize_bytes) {
argv[++args] = "--newsizebytes";
argv[++args] = newsize_bytes_str;
}
if (fsi->mounted) {
argv[++args] = "--mountdir";
argv[++args] = fsi->mount_dir;
}
if (fsi->needs_unmount)
argv[++args] = "--unmount";
if (fsi->needs_mount)
argv[++args] = "--mount";
if (fsi->needs_fsck)
argv[++args] = "--fsck";
if (fsi->needs_crypt) {
if (dm_snprintf(crypt_path, sizeof(crypt_path), "/dev/dm-%d", (int)MINOR(fsi->crypt_devt)) < 0)
return_0;
argv[++args] = "--cryptresize";
argv[++args] = "--cryptpath";
argv[++args] = crypt_path;
}
/*
* --fs resize|resize_remount want the fs to be remounted after
* resizing if it was unmounted. (Not often applicable.)
*/
if (fsi->needs_unmount && (!strcmp(fsopt, "resize") || !strcmp(fsopt, "resize_remount")))
argv[++args] = "--remount";
argv[++args] = NULL;
if (!exec_cmd(cmd, argv, &status, 1)) {
log_error("Failed to resize file system with lvresize_fs_helper.");
return 0;
}
return 1;
}
/*
* The helper script does the following steps for extend:
* devpath = $cryptpath ? $cryptpath : $lvpath
* if needs_unmount
* umount $mountdir
* if needs_fsck
* e2fsck -f -p $devpath
* if needs_crypt
* cryptsetup resize $cryptpath
* if needs_mount
* mount $devpath $tmpdir
* if $fstype == "ext"
* resize2fs $devpath
* if $fstype == "xfs"
* xfs_growfs $devpath
*/
int fs_extend_script(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
char *fsopt)
{
char lv_path[PATH_MAX];
char crypt_path[PATH_MAX];
const char *argv[FS_CMD_MAX_ARGS + 4];
int args = 0;
int status;
if (dm_snprintf(lv_path, PATH_MAX, "%s%s/%s", lv->vg->cmd->dev_dir, lv->vg->name, lv->name) < 0)
return_0;
argv[0] = "/usr/sbin/lvresize_fs_helper"; /* define in configure? */
argv[++args] = "--fsextend";
argv[++args] = "--fstype";
argv[++args] = fsi->fstype;
argv[++args] = "--lvpath";
argv[++args] = lv_path;
if (fsi->mounted) {
argv[++args] = "--mountdir";
argv[++args] = fsi->mount_dir;
}
if (fsi->needs_unmount)
argv[++args] = "--unmount";
if (fsi->needs_mount)
argv[++args] = "--mount";
if (fsi->needs_fsck)
argv[++args] = "--fsck";
if (fsi->needs_crypt) {
if (dm_snprintf(crypt_path, sizeof(crypt_path), "/dev/dm-%d", (int)MINOR(fsi->crypt_devt)) < 0)
return_0;
argv[++args] = "--cryptresize";
argv[++args] = "--cryptpath";
argv[++args] = crypt_path;
}
/*
* --fs resize|resize_remount want the fs to be remounted after
* resizing if it was unmounted. (Not often applicable.)
*/
if (fsi->needs_unmount && (!strcmp(fsopt, "resize") || !strcmp(fsopt, "resize_remount")))
argv[++args] = "--remount";
argv[++args] = NULL;
if (!exec_cmd(cmd, argv, &status, 1)) {
log_error("Failed to resize file system with lvresize_fs_helper.");
return 0;
}
return 1;
}

51
lib/device/filesystem.h Normal file
View File

@@ -0,0 +1,51 @@
/*
* 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
#define FSTYPE_MAX 16
struct fs_info {
char fstype[FSTYPE_MAX];
char mount_dir[PATH_MAX];
char fs_dev_path[PATH_MAX]; /* usually lv dev, can be crypt dev */
unsigned int block_size_bytes; /* 512 or 4k */
uint64_t fs_last_byte; /* last byte on the device used by the fs */
uint32_t crypt_offset_bytes; /* offset in bytes of crypt data on LV */
dev_t crypt_devt; /* dm-crypt device between the LV and 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;
unsigned needs_crypt:1;
};
int fs_get_info(struct cmd_context *cmd, struct logical_volume *lv,
struct fs_info *fsi, int include_mount);
int fs_extend_script(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
char *fsopt);
int fs_reduce_script(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
uint64_t newsize_bytes_fs, char *fsopt);
int crypt_resize_script(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
uint64_t newsize_bytes_fs);
#endif

View File

@@ -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

View File

@@ -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,45 @@ 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;
int user_set_fs;
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 +743,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,

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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,

View File

@@ -21,7 +21,7 @@ ifeq ("@BUILD_DMEVENTD@", "yes")
LDFLAGS += -Wl,-rpath-link,$(top_builddir)/daemons/dmeventd
endif
LVM_SCRIPTS = lvmdump.sh
LVM_SCRIPTS = lvmdump.sh lvresize_fs_helper.sh
DM_SCRIPTS =
ifeq ("@FSADM@", "yes")

View File

@@ -164,7 +164,7 @@ cleanup() {
export _FSADM_YES _FSADM_EXTOFF
unset FSADM_RUNNING
test -n "${LVM_BINARY-}" && PATH=$_SAVEPATH
dry exec "$LVM" lvresize $VERB $FORCE -r -L"${NEWSIZE_ORIG}b" "$VOLUME_ORIG"
dry exec "$LVM" lvresize $VERB $FORCE $YES --fs resize_fsadm -L"${NEWSIZE_ORIG}b" "$VOLUME_ORIG"
fi
# error exit status for break

477
scripts/lvresize_fs_helper.sh Executable file
View File

@@ -0,0 +1,477 @@
#!/bin/bash
#
# 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 General Public License v.2.
#
# You should have received a copy of the GNU 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
errorexit() {
echo "$1" >&2
exit 1
}
logmsg() {
echo "$1"
logger "${SCRIPTNAME}: $1"
}
# Set to 1 while the fs is temporarily mounted on $TMPDIR
TMP_MOUNT_DONE=0
# Set to 1 if the fs resize command fails
RESIZEFS_FAILED=0
fsextend() {
if [ "$DO_UNMOUNT" -eq 1 ]; then
logmsg "unmount ${MOUNTDIR}"
umount "$MOUNTDIR"
if [ $? -eq 0 ]; then
logmsg "unmount done"
else
logmsg "unmount failed"
exit 1
fi
fi
if [ "$DO_FSCK" -eq 1 ]; then
logmsg "e2fsck ${DEVPATH}"
e2fsck -f -p "$DEVPATH"
if [ $? -eq 0 ]; then
logmsg "e2fsck done"
else
logmsg "e2fsck failed"
exit 1
fi
fi
if [ "$DO_CRYPTRESIZE" -eq 1 ]; then
logmsg "cryptsetup resize ${DEVPATH}"
cryptsetup resize "$DEVPATH"
if [ $? -eq 0 ]; then
logmsg "cryptsetup done"
else
logmsg "cryptsetup failed"
exit 1
fi
fi
if [ "$DO_MOUNT" -eq 1 ]; then
logmsg "mount ${DEVPATH} ${TMPDIR}"
mount -t "$FSTYPE" "$DEVPATH" "$TMPDIR"
if [ $? -eq 0 ]; then
logmsg "mount done"
TMP_MOUNT_DONE=1
else
logmsg "mount failed"
exit 1
fi
fi
if [[ "$FSTYPE" == "ext"* ]]; then
logmsg "resize2fs ${DEVPATH}"
resize2fs "$DEVPATH"
if [ $? -eq 0 ]; then
logmsg "resize2fs done"
else
logmsg "resize2fs failed"
RESIZEFS_FAILED=1
fi
elif [[ "$FSTYPE" == "xfs" ]]; then
logmsg "xfs_growfs ${DEVPATH}"
xfs_growfs "$DEVPATH"
if [ $? -eq 0 ]; then
logmsg "xfs_growfs done"
else
logmsg "xfs_growfs failed"
RESIZEFS_FAILED=1
fi
fi
# If the fs was temporarily mounted, now unmount it.
if [ $TMP_MOUNT_DONE -eq 1 ]; then
logmsg "cleanup unmount ${TMPDIR}"
umount "$TMPDIR"
if [ $? -eq 0 ]; then
logmsg "cleanup unmount done"
TMP_MOUNT_DONE=0
rmdir "$TMPDIR"
else
logmsg "cleanup unmount failed"
exit 1
fi
fi
# If the fs was temporarily unmounted, now remount it.
# Not considered a command failure if this fails.
if [[ $DO_UNMOUNT -eq 1 && $REMOUNT -eq 1 ]]; then
logmsg "remount ${DEVPATH} ${MOUNTDIR}"
mount -t "$FSTYPE" "$DEVPATH" "$MOUNTDIR"
if [ $? -eq 0 ]; then
logmsg "remount done"
else
logmsg "remount failed"
fi
fi
if [ $RESIZEFS_FAILED -eq 1 ]; then
logmsg "File system extend failed."
exit 1
fi
exit 0
}
fsreduce() {
if [ "$DO_UNMOUNT" -eq 1 ]; then
logmsg "unmount ${MOUNTDIR}"
umount "$MOUNTDIR"
if [ $? -eq 0 ]; then
logmsg "unmount done"
else
logmsg "unmount failed"
exit 1
fi
fi
if [ "$DO_FSCK" -eq 1 ]; then
logmsg "e2fsck ${DEVPATH}"
e2fsck -f -p "$DEVPATH"
if [ $? -eq 0 ]; then
logmsg "e2fsck done"
else
logmsg "e2fsck failed"
exit 1
fi
fi
if [ "$DO_MOUNT" -eq 1 ]; then
logmsg "mount ${DEVPATH} ${TMPDIR}"
mount -t "$FSTYPE" "$DEVPATH" "$TMPDIR"
if [ $? -eq 0 ]; then
logmsg "mount done"
TMP_MOUNT_DONE=1
else
logmsg "mount failed"
exit 1
fi
fi
if [[ "$FSTYPE" == "ext"* ]]; then
NEWSIZEKB=$(($NEWSIZEBYTES/1024))
logmsg "resize2fs ${DEVPATH} ${NEWSIZEKB}"
resize2fs "$DEVPATH" "$NEWSIZEKB"
if [ $? -eq 0 ]; then
logmsg "resize2fs done"
else
logmsg "resize2fs failed"
# will exit after cleanup unmount
RESIZEFS_FAILED=1
fi
fi
# If the fs was temporarily mounted, now unmount it.
if [ $TMP_MOUNT_DONE -eq 1 ]; then
logmsg "cleanup unmount ${TMPDIR}"
umount "$TMPDIR"
if [ $? -eq 0 ]; then
logmsg "cleanup unmount done"
TMP_MOUNT_DONE=0
rmdir "$TMPDIR"
else
logmsg "cleanup unmount failed"
exit 1
fi
fi
if [ $RESIZEFS_FAILED -eq 1 ]; then
logmsg "File system reduce failed."
exit 1
fi
if [ "$DO_CRYPTRESIZE" -eq 1 ]; then
NEWSIZESECTORS=$(($NEWSIZEBYTES/512))
logmsg "cryptsetup resize ${NEWSIZESECTORS} ${DEVPATH}"
cryptsetup resize --size "$NEWSIZESECTORS" "$DEVPATH"
if [ $? -eq 0 ]; then
logmsg "cryptsetup done"
else
logmsg "cryptsetup failed"
exit 1
fi
fi
# If the fs was temporarily unmounted, now remount it.
# Not considered a command failure if this fails.
if [[ $DO_UNMOUNT -eq 1 && $REMOUNT -eq 1 ]]; then
logmsg "remount ${DEVPATH} ${MOUNTDIR}"
mount -t "$FSTYPE" "$DEVPATH" "$MOUNTDIR"
if [ $? -eq 0 ]; then
logmsg "remount done"
else
logmsg "remount failed"
fi
fi
exit 0
}
cryptresize() {
NEWSIZESECTORS=$(($NEWSIZEBYTES/512))
logmsg "cryptsetup resize ${NEWSIZESECTORS} ${DEVPATH}"
cryptresize resize --size "$NEWSIZESECTORS" "$DEVPATH"
if [ $? -eq 0 ]; then
logmsg "cryptsetup done"
else
logmsg "cryptsetup failed"
exit 1
fi
exit 0
}
usage() {
echo "${SCRIPTNAME}: helper script called by lvresize to resize file systems."
echo ""
echo "${SCRIPTNAME} --fsextend --fstype name --lvpath path"
echo " [ --mountdir path ]"
echo " [ --mount ]"
echo " [ --unmount ]"
echo " [ --remount ]"
echo " [ --fsck ]"
echo " [ --cryptresize ]"
echo " [ --cryptpath path ]"
echo ""
echo "${SCRIPTNAME} --fsreduce --fstype name --lvpath path"
echo " [ --newsizebytes num ]"
echo " [ --mountdir path ]"
echo " [ --mount ]"
echo " [ --unmount ]"
echo " [ --remount ]"
echo " [ --fsck ]"
echo " [ --cryptresize ]"
echo " [ --cryptpath path ]"
echo ""
echo "${SCRIPTNAME} --cryptresize --cryptpath path --newsizebytes num"
echo ""
echo "Options:"
echo " --fsextend"
echo " Extend the file system."
echo " --fsreduce"
echo " Reduce the file system."
echo " --fstype name"
echo " The type of file system (ext*, xfs)."
echo " --lvpath path"
echo " The path to the LV being resized."
echo " --mountdir path"
echo " The file system is currently mounted here."
echo " --mount"
echo " Mount the file system on a temporary directory before resizing."
echo " --unmount"
echo " Unmount the file system before resizing."
echo " --remount"
echo " Remount the file system after resizing if unmounted."
echo " --fsck"
echo " Run fsck on the file system before resizing (only with ext*)."
echo " --newsizebytes num"
echo " The new size of the file system."
echo " --cryptresize"
echo " Resize the crypt device between the LV and file system."
echo " --cryptpath path"
echo " The path to the crypt device."
echo ""
}
#
# BEGIN SCRIPT
#
PATH="/sbin:/usr/sbin:/bin:/usr/sbin:$PATH"
SCRIPTNAME=$(basename "$0")
# These are the only commands that this script will run.
# Each is enabled (1) by the corresponding command options:
# --fsextend, --fsreduce, --cryptresize, --mount, --unmount, --fsck
DO_FSEXTEND=0
DO_FSREDUCE=0
DO_CRYPTRESIZE=0
DO_MOUNT=0
DO_UNMOUNT=0
DO_FSCK=0
# --remount: attempt to remount the fs if it was originally
# mounted and the script unmounted it.
REMOUNT=0
if [ "$UID" != 0 ] && [ "$EUID" != 0 ]; then
errorexit "${SCRIPTNAME} must be run as root."
fi
GETOPT="getopt"
OPTIONS=$("$GETOPT" -o hv -l help,debug,fsextend,fsreduce,cryptresize,mount,unmount,remount,fsck,fstype:,lvpath:,newsizebytes:,mountdir:,cryptpath: -n "${SCRIPTNAME}" -- "$@")
eval set -- "$OPTIONS"
while true
do
case $1 in
--fsextend)
DO_FSEXTEND=1
shift
;;
--fsreduce)
DO_FSREDUCE=1
shift
;;
--cryptresize)
DO_CRYPTRESIZE=1
shift
;;
--mount)
DO_MOUNT=1
shift
;;
--unmount)
DO_UNMOUNT=1
shift
;;
--fsck)
DO_FSCK=1
shift
;;
--remount)
REMOUNT=1
shift
;;
--fstype)
FSTYPE=$2;
shift; shift
;;
--lvpath)
LVPATH=$2;
shift; shift
;;
--newsizebytes)
NEWSIZEBYTES=$2;
shift; shift
;;
--mountdir)
MOUNTDIR=$2;
shift; shift
;;
--cryptpath)
CRYPTPATH=$2;
shift; shift
;;
--debug)
DEBUG=1
set -x
shift
;;
-h|--help)
usage
shift
exit 0
;;
-v)
VERBOSE=1
shift
;;
--)
shift
break
;;
*)
errorexit "Unknown option \"$1\."
exit 1
;;
esac
done
#
# Input arg checking
#
# There are three top level commands: --fsextend, --fsreduce, --cryptresize.
if [[ "$DO_FSEXTEND" -eq 0 && "$DO_FSREDUCE" -eq 0 && "$DO_CRYPTRESIZE" -eq 0 ]]; then
errorexit "Missing --fsextend|--fsreduce|--cryptresize."
fi
if [[ "$DO_FSEXTEND" -eq 1 || "$DO_FSREDUCE" -eq 1 ]]; then
case "$FSTYPE" in
ext[234]) ;;
"xfs") ;;
*) errorexit "Cannot resize --fstype \"$FSTYPE\"."
esac
if [ -z "$LVPATH" ]; then
errorexit "Missing required --lvpath."
fi
fi
if [[ "$DO_CRYPTRESIZE" -eq 1 && -z "$CRYPTPATH" ]]; then
errorexit "Missing required --cryptpath for --cryptresize."
fi
if [ "$DO_CRYPTRESIZE" -eq 1 ]; then
DEVPATH=$CRYPTPATH
else
DEVPATH=$LVPATH
fi
if [ -z "$DEVPATH" ]; then
errorexit "Missing path to device."
fi
if [ ! -e "$DEVPATH" ]; then
errorexit "Device does not exist \"$DEVPATH\"."
fi
if [[ "$DO_UNMOUNT" -eq 1 && -z "$MOUNTDIR" ]]; then
errorexit "Missing required --mountdir for --unmount."
fi
if [[ "$DO_FSREDUCE" -eq 1 && "$FSTYPE" == "xfs" ]]; then
errorexit "Cannot reduce xfs."
fi
if [[ "$DO_FSCK" -eq 1 && "$FSTYPE" == "xfs" ]]; then
errorexit "Cannot use --fsck with xfs."
fi
if [ "$DO_MOUNT" -eq 1 ]; then
TMPDIR=$(mktemp --suffix _lvresize_$$ -d -p /tmp)
if [ ! -e "$TMPDIR" ]; then
errorexit "Failed to create temp dir."
fi
# In case the script terminates without doing cleanup
function finish {
if [ "$TMP_MOUNT_DONE" -eq 1 ]; then
logmsg "exit unmount ${TMPDIR}"
umount "$TMPDIR"
rmdir "$TMPDIR"
fi
}
trap finish EXIT
fi
#
# Main program function:
# - the two main functions are fsextend and fsreduce.
# - one special case function is cryptresize.
#
echo "Resizing ${FSTYPE} on ${DEVPATH}"
if [ "$DO_FSEXTEND" -eq 1 ]; then
fsextend
elif [ "$DO_FSREDUCE" -eq 1 ]; then
fsreduce
elif [ "$DO_CRYPTRESIZE" -eq 1 ]; then
cryptresize
fi

View File

@@ -0,0 +1,612 @@
#!/usr/bin/env bash
# Copyright (C) 2008-2017 Red Hat, Inc. All rights reserved.
#
# 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 General Public License v.2.
#
# You should have received a copy of the GNU 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
test_description='Exercise fsadm filesystem resize on crypt devices'
SKIP_WITH_LVMPOLLD=1
# FIXME: cannot use brd (ramdisk) - lsblk is NOT listing it
# so lsblk usage should be replaced
export LVM_TEST_PREFER_BRD=0
. lib/inittest
aux prepare_vg 1 300
# set to "skip" to avoid testing given fs and test warning result
# i.e. check_reiserfs=skip
check_ext2=
check_ext3=
check_xfs=
check_reiserfs=
check_cryptsetup=
DROP_SYMLINK=
CRYPT_NAME="$PREFIX-tcrypt"
CRYPT_DEV="$DM_DEV_DIR/mapper/$CRYPT_NAME"
CRYPT_NAME2="$PREFIX-tcrypt2"
CRYPT_DEV2="$DM_DEV_DIR/mapper/$CRYPT_NAME2"
CRYPT_NAME_PLAIN="$PREFIX-tcryptp"
CRYPT_DEV_PLAIN="$DM_DEV_DIR/mapper/$CRYPT_NAME_PLAIN"
FORMAT_PARAMS="-i1"
PWD1="93R4P4pIqAH8"
PWD2="mymJeD8ivEhE"
PWD3="ocMakf3fAcQO"
SKIP_DETACHED=
if which cryptsetup ; then
# use older format luks1 - otherwise the test would need to pass password everywhere...
case $(cryptsetup --version) in
"cryptsetup 2"*) FORMAT_PARAMS="$FORMAT_PARAMS --type luks1" ;;
esac
else
check_cryptsetup=${check_cryptsetup:-cryptsetup}
fi
which mkfs.ext2 || check_ext2=${check_ext2:-mkfs.ext2}
which mkfs.ext3 || check_ext3=${check_ext3:-mkfs.ext3}
which fsck.ext3 || check_ext3=${check_ext3:-fsck.ext3}
which mkfs.xfs || check_xfs=${check_xfs:-mkfs.xfs}
which xfs_check || {
which xfs_repair || check_xfs=${check_xfs:-xfs_repair}
}
grep xfs /proc/filesystems || check_xfs=${check_xfs:-no_xfs}
which mkfs.reiserfs || check_reiserfs=${check_reiserfs:-mkfs.reiserfs}
which reiserfsck || check_reiserfs=${check_reiserfs:-reiserfsck}
modprobe reiserfs || true
grep reiserfs /proc/filesystems || check_reiserfs=${check_reiserfs:-no_reiserfs}
vg_lv=$vg/$lv1
vg_lv2=$vg/${lv1}bar
vg_lv3=$vg/${lv1}plain
dev_vg_lv="$DM_DEV_DIR/$vg_lv"
dev_vg_lv2="$DM_DEV_DIR/$vg_lv2"
dev_vg_lv3="$DM_DEV_DIR/$vg_lv3"
mount_dir="mnt"
test ! -d "$mount_dir" && mkdir "$mount_dir"
crypt_close() {
aux udev_wait
cryptsetup remove "$1"
if [ "$?" -eq 0 -a -n "$DROP_SYMLINK" ]; then
rm -f "$DM_DEV_DIR/mapper/$1"
fi
}
cleanup_mounted_and_teardown()
{
umount "$mount_dir" || true
crypt_close $CRYPT_NAME > /dev/null 2>&1 || true
crypt_close $CRYPT_NAME2 > /dev/null 2>&1 || true
crypt_close $CRYPT_NAME_PLAIN > /dev/null 2>&1 || true
aux teardown
}
fscheck_ext3()
{
fsck.ext3 -p -F -f "$1"
}
fscheck_xfs()
{
if which xfs_repair ; then
xfs_repair -n "$1"
else
xfs_check "$1"
fi
}
fscheck_reiserfs()
{
reiserfsck --check -p -f "$1" </dev/null
}
check_missing()
{
local t
eval "t=\$check_$1"
test -z "$t" && return 0
test "$t" = skip && return 1
echo "WARNING: fsadm test skipped $1 tests, $t tool is missing."
# trick to get test listed with warning
# should false;
return 1
}
get_crypt_kname() {
lsblk -r -n -o KNAME,NAME | grep "$1" | cut -d ' ' -f 1
}
# $1 device
# $2 pass
crypt_format() {
echo "$2" | cryptsetup luksFormat $FORMAT_PARAMS "$1"
}
# $1 device
# $2 pass
# $3 name
crypt_open() {
local kname=
echo "$2" | cryptsetup luksOpen "$1" "$3"
test -L "$DM_DEV_DIR/mapper/$3" || {
kname=$(get_crypt_kname $3)
ln -s "/dev/$kname" "$DM_DEV_DIR/mapper/$3"
DROP_SYMLINK=1
}
}
# $1 data device
# $2 pass
# $3 name
# $4 header
crypt_open_detached() {
local kname=
echo "$2" | cryptsetup luksOpen --header "$4" "$1" "$3" || return $?
test -L "$DM_DEV_DIR/mapper/$3" || {
kname=$(get_crypt_kname $3)
ln -s "/dev/$kname" "$DM_DEV_DIR/mapper/$3"
DROP_SYMLINK=1
}
}
# $1 device
# $2 pass
# $3 name
crypt_open_plain() {
local kname=
echo "$2" | cryptsetup create "$3" "$1"
test -L "$DM_DEV_DIR/mapper/$3" || {
kname=$(get_crypt_kname $3)
ln -s "/dev/$kname" "$DM_DEV_DIR/mapper/$3"
DROP_SYMLINK=1
}
}
# $1 device
# $2 type
create_crypt_device()
{
crypt_format "$dev_vg_lv" $PWD1
crypt_open "$dev_vg_lv" $PWD1 "$CRYPT_NAME"
crypt_format "$dev_vg_lv2" $PWD2
if crypt_open_detached "$dev_vg_lv3" "$PWD2" "$PREFIX-test" "$dev_vg_lv2"; then
crypt_close "$PREFIX-test"
else
SKIP_DETACHED=1
fi
}
which lsblk > /dev/null || skip
check_missing cryptsetup || skip
vgchange -s 128k
lvcreate -n $lv1 -L25M $vg
lvcreate -n ${lv1}bar -L35M $vg
lvcreate -n ${lv1}plain -L35M $vg
create_crypt_device
trap 'cleanup_mounted_and_teardown' EXIT
# $1 LVM backend (vg/lv name)
# $2 LVM backend device (/dev/vg/lv)
# $3 active dm-crypt device (/dev/mapper/some_name )
test_ext2_resize() {
mkfs.ext2 -b4096 -j "$3"
fsadm --lvresize resize $1 30M
# Fails - not enough space for 4M fs
not fsadm -y --lvresize resize "$2" 4M
lvresize -L+10M --fs resize $1
lvreduce -L10M --fs resize $1
fscheck_ext3 "$3"
mount "$3" "$mount_dir"
not fsadm -y --lvresize resize $1 4M
echo n | not lvresize -L4M --fs resize -n $1
lvresize -L+20M --fs resize -n $1
umount "$mount_dir"
fscheck_ext3 "$3"
}
test_ext2_small_shrink() {
mkfs.ext2 "$3"
lvresize -L-1 --fs resize $1
lvresize -L-1 --fs resize $1
fscheck_ext3 "$3"
}
test_ext3_resize() {
mkfs.ext3 -b4096 -j "$3"
fsadm --lvresize resize $1 30M
# Fails - not enough space for 4M fs
not fsadm -y --lvresize resize "$2" 4M
lvresize -L+10M --fs resize $1
lvreduce -L10M --fs resize $1
fscheck_ext3 "$3"
mount "$3" "$mount_dir"
lvresize -L+10M --fs resize $1
not fsadm -y --lvresize resize $1 4M
echo n | not lvresize -L4M --fs resize -n $1
lvresize -L+20M --fs resize -n $1
lvresize -L-10M --fs resize -y $1
umount "$mount_dir"
}
test_ext3_small_shrink() {
mkfs.ext3 "$3"
lvresize -L-1 --fs resize $1
lvresize -L-1 --fs resize $1
fscheck_ext3 "$3"
}
test_xfs_resize() {
mkfs.xfs -l internal,size=1536b -f "$3"
fsadm --lvresize resize $1 30M
# Fails - not enough space for 4M fs
lvresize -L+10M -y --fs resize $1
not lvreduce -L10M --fs resize $1
fscheck_xfs "$3"
mount "$3" "$mount_dir"
lvresize -L+10M -y --fs resize -n $1
umount "$mount_dir"
fscheck_xfs "$3"
}
test_xfs_small_shrink() {
mkfs.xfs -l internal,size=1536b -f "$3"
not lvresize -L-1 --fs resize $1
fscheck_xfs "$3"
}
test_reiserfs_resize() {
mkfs.reiserfs -s 513 -f "$3"
fsadm --lvresize resize $1 30M
lvresize -L+10M --fs resize $1
fsadm --lvresize -y resize $1 10M
fscheck_reiserfs "$3"
mount "$3" "$mount_dir"
fsadm -y --lvresize resize $1 30M
umount "$mount_dir"
fscheck_reiserfs "$3"
}
test_reiserfs_small_shrink() {
mkfs.reiserfs -s 513 -f "$3"
lvresize -y -L-1 --fs resize $1
lvresize -y -L-1 --fs resize $1
fscheck_reiserfs "$3"
}
# $1 LVM backend (vg/lv name)
# $2 LVM backend device (/dev/vg/lv)
# $3 active dm-crypt device (/dev/mapper/some_name )
# $4 active dm-crypt name ( some_name )
test_ext2_inactive() {
crypt_open "$2" $PWD2 "$4"
mkfs.ext2 -b4096 -j "$3"
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
crypt_open "$2" $PWD2 "$4"
fscheck_ext3 "$3"
crypt_close "$4"
}
test_ext3_inactive() {
crypt_open "$2" $PWD2 "$4"
mkfs.ext3 -b4096 -j "$3"
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
crypt_open "$2" $PWD2 "$4"
fscheck_ext3 "$3"
crypt_close "$4"
}
test_xfs_inactive() {
crypt_open "$2" $PWD2 "$4"
mkfs.xfs -l internal,size=1536b -f "$3"
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
crypt_open "$2" $PWD2 "$4"
fscheck_xfs "$3"
crypt_close "$4"
}
test_reiserfs_inactive() {
crypt_open "$2" $PWD2 "$4"
mkfs.reiserfs -s 513 -f "$3"
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
crypt_open "$2" $PWD2 "$4"
fscheck_reiserfs "$3"
crypt_close "$4"
}
# $1 LVM backend (vg/lv name)
# $2 LVM backend device (/dev/vg/lv)
# $3 active dm-crypt device (/dev/mapper/some_name )
# $4 active dm-crypt name ( some_name )
test_ext2_plain() {
mkfs.ext2 -b4096 -j "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
fscheck_ext3 "$3"
fsadm --cryptresize resize $3 30M
fsadm --cryptresize resize $3 35M
fscheck_ext3 "$3"
mount "$3" "$mount_dir"
not fsadm -y --cryptresize resize $3 4M
umount "$mount_dir"
fscheck_ext3 "$3"
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
crypt_open_plain "$2" $PWD3 "$4"
fscheck_ext3 "$3"
}
test_ext3_plain() {
mkfs.ext3 -b4096 -j "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
fscheck_ext3 "$3"
fsadm --cryptresize resize $3 30M
fsadm --cryptresize resize $3 35M
fscheck_ext3 "$3"
mount "$3" "$mount_dir"
not fsadm -y --cryptresize resize $3 4M
umount "$mount_dir"
fscheck_ext3 "$3"
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
crypt_open_plain "$2" $PWD3 "$4"
fscheck_ext3 "$3"
}
test_xfs_plain() {
mkfs.xfs -l internal,size=1536b -f "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
fscheck_xfs "$3"
lvresize -f -L+10M $1
fsadm --cryptresize resize $3 40M
# no shrink support in xfs
not fsadm --cryptresize resize $3 35M
fscheck_xfs "$3"
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
crypt_open_plain "$2" $PWD3 "$4"
fscheck_xfs "$3"
lvresize -f -L35M $1
}
test_reiserfs_plain() {
mkfs.reiserfs -s 513 -f "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L-10M --fs resize $1
fscheck_reiserfs "$3"
fsadm -y --cryptresize resize $3 30M
fsadm -y --cryptresize resize $3 35M
fscheck_reiserfs "$3"
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
crypt_open_plain "$2" $PWD3 "$4"
fscheck_reiserfs "$3"
}
# $1 LVM header backend (vg/lv name)
# $2 LVM hedaer backend device (/dev/vg/lv)
# $3 active dm-crypt device (/dev/mapper/some_name )
# $4 active dm-crypt name ( some_name )a
test_ext2_detached() {
mkfs.ext2 -b4096 -j "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
fscheck_ext3 "$3"
}
test_ext3_detached() {
mkfs.ext3 -b4096 -j "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
fscheck_ext3 "$3"
}
test_xfs_detached() {
mkfs.xfs -l internal,size=1536b -f "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
fscheck_xfs "$3"
}
test_reiserfs_detached() {
mkfs.reiserfs -s 513 -f "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M --fs resize $1
not lvreduce -L10M --fs resize $1
fscheck_reiserfs "$3"
}
if check_missing ext2; then
test_ext2_resize "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
test_ext2_inactive "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
crypt_open_plain "$dev_vg_lv3" $PWD3 "$CRYPT_NAME_PLAIN"
test_ext2_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
lvresize --fs ignore -y -L100M $vg_lv
cryptsetup resize $CRYPT_NAME
test_ext2_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
if [ -z "$SKIP_DETACHED" ]; then
crypt_open_detached "$dev_vg_lv3" $PWD2 "$CRYPT_NAME2" "$dev_vg_lv2"
test_ext2_detached "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
crypt_close "$CRYPT_NAME2"
fi
fi
if check_missing ext3; then
test_ext3_resize "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
test_ext3_inactive "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
crypt_open_plain "$dev_vg_lv3" $PWD3 "$CRYPT_NAME_PLAIN"
test_ext3_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
lvresize --fs ignore -y -L100M $vg_lv
cryptsetup resize $CRYPT_NAME
test_ext3_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
if [ -z "$SKIP_DETACHED" ]; then
crypt_open_detached "$dev_vg_lv3" $PWD2 "$CRYPT_NAME2" "$dev_vg_lv2"
test_ext3_detached "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
crypt_close "$CRYPT_NAME2"
fi
fi
if check_missing xfs; then
test_xfs_resize "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
test_xfs_inactive "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
crypt_open_plain "$dev_vg_lv3" $PWD3 "$CRYPT_NAME_PLAIN"
test_xfs_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
lvresize --fs ignore -y -L100M $vg_lv
cryptsetup resize $CRYPT_NAME
test_xfs_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
if [ -z "$SKIP_DETACHED" ]; then
crypt_open_detached "$dev_vg_lv3" $PWD2 "$CRYPT_NAME2" "$dev_vg_lv2"
test_xfs_detached "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
crypt_close "$CRYPT_NAME2"
fi
fi
if check_missing reiserfs; then
test_reiserfs_resize "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
test_reiserfs_inactive "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
crypt_open_plain "$dev_vg_lv3" $PWD3 "$CRYPT_NAME_PLAIN"
test_reiserfs_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
lvresize --fs ignore -y -L100M $vg_lv
cryptsetup resize $CRYPT_NAME
test_reiserfs_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
if [ -z "$SKIP_DETACHED" ]; then
crypt_open_detached "$dev_vg_lv3" $PWD2 "$CRYPT_NAME2" "$dev_vg_lv2"
test_reiserfs_detached "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
crypt_close "$CRYPT_NAME2"
fi
fi
crypt_close "$CRYPT_NAME"
vgremove -ff $vg

View File

@@ -215,14 +215,14 @@ test_ext2_resize() {
fsadm --lvresize resize $1 30M
# Fails - not enough space for 4M fs
not fsadm -y --lvresize resize "$2" 4M
lvresize -L+10M -r $1
lvreduce -L10M -r $1
lvresize -L+10M --fs resize_fsadm $1
lvreduce -L10M --fs resize_fsadm $1
fscheck_ext3 "$3"
mount "$3" "$mount_dir"
not fsadm -y --lvresize resize $1 4M
echo n | not lvresize -L4M -r -n $1
lvresize -L+20M -r -n $1
echo n | not lvresize -L4M --fs resize_fsadm -n $1
lvresize -L+20M --fs resize_fsadm -n $1
umount "$mount_dir"
fscheck_ext3 "$3"
}
@@ -230,8 +230,8 @@ test_ext2_resize() {
test_ext2_small_shrink() {
mkfs.ext2 "$3"
lvresize -L-1 -r $1
lvresize -L-1 -r $1
lvresize -L-1 --fs resize_fsadm $1
lvresize -L-1 --fs resize_fsadm $1
fscheck_ext3 "$3"
}
@@ -242,25 +242,25 @@ test_ext3_resize() {
fsadm --lvresize resize $1 30M
# Fails - not enough space for 4M fs
not fsadm -y --lvresize resize "$2" 4M
lvresize -L+10M -r $1
lvreduce -L10M -r $1
lvresize -L+10M --fs resize_fsadm $1
lvreduce -L10M --fs resize_fsadm $1
fscheck_ext3 "$3"
mount "$3" "$mount_dir"
lvresize -L+10M -r $1
lvresize -L+10M --fs resize_fsadm $1
not fsadm -y --lvresize resize $1 4M
echo n | not lvresize -L4M -r -n $1
lvresize -L+20M -r -n $1
lvresize -L-10M -r -y $1
echo n | not lvresize -L4M --fs resize_fsadm -n $1
lvresize -L+20M --fs resize_fsadm -n $1
lvresize -L-10M --fs resize_fsadm -y $1
umount "$mount_dir"
}
test_ext3_small_shrink() {
mkfs.ext3 "$3"
lvresize -L-1 -r $1
lvresize -L-1 -r $1
lvresize -L-1 --fs resize_fsadm $1
lvresize -L-1 --fs resize_fsadm $1
fscheck_ext3 "$3"
}
@@ -270,12 +270,12 @@ test_xfs_resize() {
fsadm --lvresize resize $1 30M
# Fails - not enough space for 4M fs
lvresize -L+10M -r $1
not lvreduce -L10M -r $1
lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
fscheck_xfs "$3"
mount "$3" "$mount_dir"
lvresize -L+10M -r -n $1
lvresize -L+10M --fs resize_fsadm -n $1
umount "$mount_dir"
fscheck_xfs "$3"
}
@@ -283,7 +283,7 @@ test_xfs_resize() {
test_xfs_small_shrink() {
mkfs.xfs -l internal,size=1536b -f "$3"
not lvresize -L-1 -r $1
not lvresize -L-1 --fs resize_fsadm $1
fscheck_xfs "$3"
}
@@ -291,7 +291,7 @@ test_reiserfs_resize() {
mkfs.reiserfs -s 513 -f "$3"
fsadm --lvresize resize $1 30M
lvresize -L+10M -r $1
lvresize -L+10M --fs resize_fsadm $1
fsadm --lvresize -y resize $1 10M
fscheck_reiserfs "$3"
@@ -305,8 +305,8 @@ test_reiserfs_resize() {
test_reiserfs_small_shrink() {
mkfs.reiserfs -s 513 -f "$3"
lvresize -y -L-1 -r $1
lvresize -y -L-1 -r $1
lvresize -y -L-1 --fs resize_fsadm $1
lvresize -y -L-1 --fs resize_fsadm $1
fscheck_reiserfs "$3"
}
@@ -321,8 +321,8 @@ test_ext2_inactive() {
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
crypt_open "$2" $PWD2 "$4"
fscheck_ext3 "$3"
@@ -335,8 +335,8 @@ test_ext3_inactive() {
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
crypt_open "$2" $PWD2 "$4"
fscheck_ext3 "$3"
@@ -349,8 +349,8 @@ test_xfs_inactive() {
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
crypt_open "$2" $PWD2 "$4"
fscheck_xfs "$3"
@@ -363,8 +363,8 @@ test_reiserfs_inactive() {
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
crypt_open "$2" $PWD2 "$4"
fscheck_reiserfs "$3"
@@ -379,8 +379,8 @@ test_ext2_plain() {
mkfs.ext2 -b4096 -j "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
fscheck_ext3 "$3"
fsadm --cryptresize resize $3 30M
@@ -394,8 +394,8 @@ test_ext2_plain() {
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
crypt_open_plain "$2" $PWD3 "$4"
fscheck_ext3 "$3"
}
@@ -404,8 +404,8 @@ test_ext3_plain() {
mkfs.ext3 -b4096 -j "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
fscheck_ext3 "$3"
fsadm --cryptresize resize $3 30M
@@ -419,8 +419,8 @@ test_ext3_plain() {
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
crypt_open_plain "$2" $PWD3 "$4"
fscheck_ext3 "$3"
}
@@ -429,8 +429,8 @@ test_xfs_plain() {
mkfs.xfs -l internal,size=1536b -f "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
fscheck_xfs "$3"
lvresize -f -L+10M $1
@@ -441,8 +441,8 @@ test_xfs_plain() {
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
crypt_open_plain "$2" $PWD3 "$4"
fscheck_xfs "$3"
@@ -453,8 +453,8 @@ test_reiserfs_plain() {
mkfs.reiserfs -s 513 -f "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L-10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L-10M --fs resize_fsadm $1
fscheck_reiserfs "$3"
fsadm -y --cryptresize resize $3 30M
@@ -463,8 +463,8 @@ test_reiserfs_plain() {
crypt_close "$4"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
crypt_open_plain "$2" $PWD3 "$4"
fscheck_reiserfs "$3"
}
@@ -477,8 +477,8 @@ test_ext2_detached() {
mkfs.ext2 -b4096 -j "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
fscheck_ext3 "$3"
}
@@ -486,8 +486,8 @@ test_ext3_detached() {
mkfs.ext3 -b4096 -j "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
fscheck_ext3 "$3"
}
@@ -495,8 +495,8 @@ test_xfs_detached() {
mkfs.xfs -l internal,size=1536b -f "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
fscheck_xfs "$3"
}
@@ -505,15 +505,15 @@ test_reiserfs_detached() {
mkfs.reiserfs -s 513 -f "$3"
not fsadm --lvresize resize $1 30M
not lvresize -L+10M -r $1
not lvreduce -L10M -r $1
not lvresize -L+10M --fs resize_fsadm $1
not lvreduce -L10M --fs resize_fsadm $1
fscheck_reiserfs "$3"
}
if check_missing ext2; then
test_ext2_resize "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize -f -L25M $vg_lv
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
test_ext2_inactive "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
@@ -522,10 +522,10 @@ if check_missing ext2; then
test_ext2_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
lvresize -f -L100M $vg_lv
lvresize --fs ignore -y -L100M $vg_lv
cryptsetup resize $CRYPT_NAME
test_ext2_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize -f -L25M $vg_lv
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
if [ -z "$SKIP_DETACHED" ]; then
@@ -537,7 +537,7 @@ fi
if check_missing ext3; then
test_ext3_resize "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize -f -L25M $vg_lv
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
test_ext3_inactive "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
@@ -546,10 +546,10 @@ if check_missing ext3; then
test_ext3_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
lvresize -f -L100M $vg_lv
lvresize --fs ignore -y -L100M $vg_lv
cryptsetup resize $CRYPT_NAME
test_ext3_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize -f -L25M $vg_lv
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
if [ -z "$SKIP_DETACHED" ]; then
@@ -561,7 +561,7 @@ fi
if check_missing xfs; then
test_xfs_resize "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize -f -L25M $vg_lv
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
test_xfs_inactive "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
@@ -570,10 +570,10 @@ if check_missing xfs; then
test_xfs_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
lvresize -f -L100M $vg_lv
lvresize --fs ignore -y -L100M $vg_lv
cryptsetup resize $CRYPT_NAME
test_xfs_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize -f -L25M $vg_lv
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
if [ -z "$SKIP_DETACHED" ]; then
@@ -585,7 +585,7 @@ fi
if check_missing reiserfs; then
test_reiserfs_resize "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize -f -L25M $vg_lv
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
test_reiserfs_inactive "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
@@ -594,10 +594,10 @@ if check_missing reiserfs; then
test_reiserfs_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
lvresize -f -L100M $vg_lv
lvresize --fs ignore -y -L100M $vg_lv
cryptsetup resize $CRYPT_NAME
test_reiserfs_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
lvresize -f -L25M $vg_lv
lvresize --fs ignore -y -L25M $vg_lv
cryptsetup resize $CRYPT_NAME
if [ -z "$SKIP_DETACHED" ]; then

View File

@@ -113,18 +113,18 @@ if check_missing ext2; then
fsadm --lvresize resize $vg_lv 30M
# Fails - not enough space for 4M fs
not fsadm -y --lvresize resize "$dev_vg_lv" 4M
lvresize -L+10M -r $vg_lv
lvreduce -L10M -r $vg_lv
lvresize -L+10M --fs resize_fsadm $vg_lv
lvreduce -L10M --fs resize_fsadm $vg_lv
fscheck_ext3
mount "$dev_vg_lv" "$mount_dir"
not fsadm -y --lvresize resize $vg_lv 4M
echo n | not lvresize -L4M -r -n $vg_lv
lvresize -L+20M -r -n $vg_lv
echo n | not lvresize -L4M --fs resize_fsadm -n $vg_lv
lvresize -L+20M --fs resize_fsadm -n $vg_lv
umount "$mount_dir"
fscheck_ext3
lvresize -f -L20M $vg_lv
lvresize --fs ignore -y -L20M $vg_lv
if which debugfs ; then
mkfs.ext2 -b4096 -j "$dev_vg_lv"
@@ -145,7 +145,7 @@ if check_missing ext2; then
mount "$dev_vg_lv" "$mount_dir"
fsadm -v -y --lvresize resize $vg_lv 10M
lvresize -L+10M -y -r -n $vg_lv
lvresize -L+10M -y --fs resize_fsadm -n $vg_lv
umount "$mount_dir" 2>/dev/null || true
fscheck_ext3
fi
@@ -158,24 +158,24 @@ if check_missing ext3; then
fsadm --lvresize resize $vg_lv 30M
# Fails - not enough space for 4M fs
not fsadm -y --lvresize resize "$dev_vg_lv" 4M
lvresize -L+10M -r $vg_lv
lvreduce -L10M -r $vg_lv
lvresize -L+10M --fs resize_fsadm $vg_lv
lvreduce -L10M --fs resize_fsadm $vg_lv
fscheck_ext3
mount "$dev_vg_lv" "$mount_dir"
lvresize -L+10M -r $vg_lv
lvresize -L+10M --fs resize_fsadm $vg_lv
mount "$dev_vg_lv2" "$mount_space_dir"
fsadm --lvresize -e -y resize $vg_lv2 25M
not fsadm -y --lvresize resize $vg_lv 4M
echo n | not lvresize -L4M -r -n $vg_lv
lvresize -L+20M -r -n $vg_lv
lvresize -L-10M -r -y $vg_lv
lvresize -L+20M --fs resize_fsadm -n $vg_lv
lvresize -L-10M --fs resize_fsadm -y $vg_lv
umount "$mount_dir"
umount "$mount_space_dir"
fscheck_ext3
lvresize -f -L20M $vg_lv
lvresize --fs ignore -y -L20M $vg_lv
fi
if check_missing xfs; then
@@ -183,23 +183,23 @@ if check_missing xfs; then
fsadm --lvresize resize $vg_lv 30M
# Fails - not enough space for 4M fs
lvresize -L+10M -r $vg_lv
not lvreduce -L10M -r $vg_lv
lvresize -L+10M --fs resize_fsadm $vg_lv
not lvreduce -L10M --fs resize_fsadm $vg_lv
fscheck_xfs
mount "$dev_vg_lv" "$mount_dir"
lvresize -L+10M -r -n $vg_lv
lvresize -L+10M --fs resize_fsadm -n $vg_lv
umount "$mount_dir"
fscheck_xfs
lvresize -f -L20M $vg_lv
lvresize --fs ignore -y -L20M $vg_lv
fi
if check_missing reiserfs; then
mkfs.reiserfs -s 513 -f "$dev_vg_lv"
fsadm --lvresize resize $vg_lv 30M
lvresize -L+10M -r $vg_lv
lvresize -L+10M --fs resize_fsadm $vg_lv
fsadm --lvresize -y resize $vg_lv 10M
fscheck_reiserfs
@@ -209,7 +209,7 @@ if check_missing reiserfs; then
umount "$mount_dir"
fscheck_reiserfs
lvresize -f -L20M $vg_lv
lvresize --fs ignore -y -L20M $vg_lv
fi
vgremove -ff $vg

View File

@@ -264,8 +264,8 @@ lvcreate -l1 -n $lv2 $vg1
lvcreate -l1 -an -n $lv3 $vg1
lvchange -an $vg1
lvremove $vg1/$lv3
lvresize -l+1 $vg1/$lv2
lvresize -l-1 $vg1/$lv2
lvresize --fs ignore -l+1 $vg1/$lv2
lvresize --fs ignore -l-1 $vg1/$lv2
lvdisplay
pvdisplay
vgdisplay

View File

@@ -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

View File

@@ -0,0 +1,131 @@
#!/usr/bin/env bash
# Copyright (C) 2007-2016 Red Hat, Inc. All rights reserved.
#
# 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 General Public License v.2.
#
# You should have received a copy of the GNU 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
SKIP_WITH_LVMPOLLD=1
. lib/inittest
aux prepare_vg 3 256
mount_dir="mnt"
mkdir -p "$mount_dir"
# dm-crypt device on lv
cr="$PREFIX-$lv-cr"
# lvextend ext4 on LUKS1
lvcreate -n $lv -L 256M $vg
echo 93R4P4pIqAH8 | cryptsetup luksFormat -i1 --type luks1 "$DM_DEV_DIR/$vg/$lv"
echo 93R4P4pIqAH8 | cryptsetup luksOpen "$DM_DEV_DIR/$vg/$lv" $cr
mkfs.ext4 /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
lvextend -L+200M --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "456.00m"
df --output=size "$mount_dir" |tee df2
not diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv
# lvreduce ext4 on LUKS1
lvcreate -n $lv -L 456M $vg
echo 93R4P4pIqAH8 | cryptsetup luksFormat -i1 --type luks1 "$DM_DEV_DIR/$vg/$lv"
echo 93R4P4pIqAH8 | cryptsetup luksOpen "$DM_DEV_DIR/$vg/$lv" $cr
mkfs.ext4 /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
lvresize -L-100M --yes --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "356.00m"
df --output=size "$mount_dir" |tee df2
not diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv
# lvextend xfs on LUKS1
lvcreate -n $lv -L 256M $vg
echo 93R4P4pIqAH8 | cryptsetup luksFormat -i1 --type luks1 "$DM_DEV_DIR/$vg/$lv"
echo 93R4P4pIqAH8 | cryptsetup luksOpen "$DM_DEV_DIR/$vg/$lv" $cr
mkfs.xfs /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
lvextend -L+200M --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "456.00m"
df --output=size "$mount_dir" |tee df2
not diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv
# lvreduce xfs on LUKS1
lvcreate -n $lv -L 456M $vg
echo 93R4P4pIqAH8 | cryptsetup luksFormat -i1 --type luks1 "$DM_DEV_DIR/$vg/$lv"
echo 93R4P4pIqAH8 | cryptsetup luksOpen "$DM_DEV_DIR/$vg/$lv" $cr
mkfs.xfs /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
# xfs cannot be reduced
not lvresize -L-100M --yes --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "456.00m"
df --output=size "$mount_dir" |tee df2
diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv
# lvextend ext4 on plain crypt (no header)
lvcreate -n $lv -L 256M $vg
echo 93R4P4pIqAH8 | cryptsetup create $cr "$DM_DEV_DIR/$vg/$lv"
mkfs.ext4 /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
# fails when no fs is found for --fs resize
not lvextend -L+200M --yes --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "256.00m"
df --output=size "$mount_dir" |tee df2
diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv
# lvreduce ext4 on plain crypt (no header)
lvcreate -n $lv -L 456M $vg
echo 93R4P4pIqAH8 | cryptsetup create $cr "$DM_DEV_DIR/$vg/$lv"
mkfs.ext4 /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
# fails when no fs is found for --fs resize
not lvresize -L-100M --yes --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "456.00m"
df --output=size "$mount_dir" |tee df2
diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv
# test with LUKS2?
vgremove -ff $vg

1186
test/shell/lvresize-fs.sh Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -37,15 +37,19 @@ 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
# lvresize fails with same result with or without -r
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 +59,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 +69,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

View File

@@ -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)

View File

@@ -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

View File

@@ -34,8 +34,8 @@ lvresize -y -l8 $vg/$lv1
lvresize -y -L16 $vg/$lv1
lvresize -y -l+1 $vg/$lv1
lvresize -y -L+1 $vg/$lv1
lvresize -y -l-1 $vg/$lv1
lvresize -y -L-1 $vg/$lv1
lvresize -y --fs ignore -l-1 $vg/$lv1
lvresize -y --fs ignore -L-1 $vg/$lv1
lvcreate -an -n $lv2 -l4 $vg
lvextend -y -l8 $vg/$lv2
@@ -46,12 +46,12 @@ not lvextend -y -l-1 $vg/$lv2
not lvextend -y -L-1 $vg/$lv2
lvcreate -an -n $lv3 -l64 $vg
lvreduce -y -l32 $vg/$lv3
lvreduce -y -L8 $vg/$lv3
lvreduce -y -l-1 $vg/$lv3
lvreduce -y -L-1 $vg/$lv3
not lvreduce -y -l+1 $vg/$lv3
not lvreduce -y -L+1 $vg/$lv3
lvreduce -y --fs ignore -l32 $vg/$lv3
lvreduce -y --fs ignore -L8 $vg/$lv3
lvreduce -y --fs ignore -l-1 $vg/$lv3
lvreduce -y --fs ignore -L-1 $vg/$lv3
not lvreduce -y --fs ignore -l+1 $vg/$lv3
not lvreduce -y --fs ignore -L+1 $vg/$lv3
# relative with percent extents

View File

@@ -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")
@@ -1452,7 +1473,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)

View File

@@ -1380,35 +1380,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.
---
@@ -1455,8 +1455,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
---
@@ -1485,17 +1485,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
@@ -1504,7 +1504,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.
---

View File

@@ -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);
}

View File

@@ -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 },
};
@@ -3144,6 +3154,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

View File

@@ -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);
}

View File

@@ -15,12 +15,135 @@
#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;
}
lp->user_set_fs = 1;
} else if (arg_is_set(cmd, resizefs_ARG)) {
/* --resizefs alone equates to --fs resize */
strncpy(lp->fsopt, "resize", sizeof(lp->fsopt)-1);
lp->user_set_fs = 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 +155,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 +181,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 +336,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;
}

View File

@@ -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