Skip to contentSkip to conversation

Resize online

PATCH New Zdenek Kabelac 1 participant 4 messages Nov 1, 2010

lore
Share & tools
lore
#0 lore raw

cover Resize online

Patchset tries to deal with online resize where we need from the user to instrument 'lvresize -r' tool to skip fsck part.

Now fsadm tool reports different status code for online mounted filesystem and updated exec_cmd() is able to pass return status code, so the new status code is recognized by lvresize and allows to continue with online resize operation.

Zdenek Kabelac (3):
Return different error value for check of mounted fs Document fsadm script return codes
Handle new return code from fsadm check

 lib/activate/activate.c |    2 +-
 lib/misc/lvm-exec.c     |   14 ++++++++++++--
 lib/misc/lvm-exec.h     |    4 ++--
 man/fsadm.8.in          |    6 ++++++
 scripts/fsadm.sh        |   14 ++++++++++++--
 tools/lvresize.c        |   20 +++++++++++++-------
 6 files changed, 46 insertions(+), 14 deletions(-)
 mode change 100644 => 100755 scripts/fsadm.sh
Signature · 1 line
1.7.3.2
#1 lore raw

PATCH 1/3 Return different error value for check of mounted fs

Patch modifies returns different error value for check requested for mounted filesystem if such operation is not supported.

Also makes a more consistent 'break' behavior and return exit code 2 for break inside the fsadm script.

---
 scripts/fsadm.sh |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 scripts/fsadm.sh
scripts/fsadm.sh +12 -2
old mode 100644
new mode 100755
index 945089a..9cee3c2
@@ -23,6 +23,11 @@
 # reiserfs: resize_reiserfs, reiserfstune
 # xfs: xfs_growfs, xfs_info
 #
+# Return values:
+#   0 success
+#   1 error
+#   2 break detected
+#   3 unsupported online filesystem check for given mounted fs
 
 TOOL=fsadm
 
@@ -127,6 +132,8 @@ cleanup() {
 	IFS=$IFS_OLD
 	trap 2
 
+	test "$1" -eq 2 && verbose "Break detected"
+
 	if [ "$DO_LVRESIZE" -eq 2 ]; then
 		# start LVRESIZE with the filesystem modification flag
 		# and allow recursive call of fsadm
@@ -382,7 +389,6 @@ resize() {
 	# if the size parameter is missing use device size
 	#if [ -n "$NEWSIZE" -a $NEWSIZE <
 	test -z "$NEWSIZE" && NEWSIZE=${DEVSIZE}b
-	trap cleanup 2
 	IFS=$NL
 	case "$FSTYPE" in
 	  "ext3"|"ext2"|"ext4") resize_ext $NEWSIZE ;;
@@ -399,7 +405,10 @@ resize() {
 ###################
 check() {
 	detect_fs "$1"
-	detect_mounted && error "Cannot fsck device \"$VOLUME\", filesystem is mounted on $MOUNTED"
+	if detect_mounted ; then
+		verbose "Skipping filesystem check for device \"$VOLUME\" as the filesystem is mounted on $MOUNTED";
+		cleanup 3
+	fi
 	case "$FSTYPE" in
 	  "xfs") dry $XFS_CHECK "$VOLUME" ;;
 	  *)    # check if executed from interactive shell environment
@@ -414,6 +423,7 @@ check() {
 # start point of this script
 # - parsing parameters
 #############################
+trap "cleanup 2" 2
 
 # test if we are not invoked recursively
 test -n "$FSADM_RUNNING" && exit 0
Signature · 1 line
1.7.3.2
#2 lore raw

PATCH 2/3 Document fsadm script return codes

In reply to Zdenek Kabelac
---
 man/fsadm.8.in |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
man/fsadm.8.in +6 -0
index 40e6971..fe3d8d3 100644
@@ -37,6 +37,12 @@ It tries to use the same API for \fBext2/ext3/ext4\fR,
 or an absolute size using a suffix (in powers of 1024).
 If new_size is not supplied, the whole device is used.
 
+.SH "DIAGNOSTIC"
+Exit status is normally 0. If an error occurs, exit status is 1.
+If a user break occurs, exit status is 2. For check operation requested 
+for mounted filesystem which does not support online filesystem check, 
+exit status is 3.
+
 .SH "EXAMPLES"
 "fsadm \-e \-y resize /dev/vg/test 1000M" tries to resize the filesystem
 on logical volume /dev/vg/test. If /dev/vg/test contains ext2/ext3/ext4
Signature · 1 line
1.7.3.2
#3 lore raw

PATCH 3/3 Handle new return code from fsadm check

In reply to Zdenek Kabelac

Patch updated exec_cmd and adds 3rd parameter with pointer for status value, so caller might examine returned status from exec. If the passed arguments is NULL, behavior is unmodified.

---
 lib/activate/activate.c |    2 +-
 lib/misc/lvm-exec.c     |   14 ++++++++++++--
 lib/misc/lvm-exec.h     |    4 ++--
 tools/lvresize.c        |   20 +++++++++++++-------
 4 files changed, 28 insertions(+), 12 deletions(-)
lib/activate/activate.c +1 -1
index 40c0fde..474b70b 100644
@@ -425,7 +425,7 @@ int module_present(struct cmd_context *cmd, const char *target_name)
 	argv[1] = module;
 	argv[2] = NULL;
 
-	ret = exec_cmd(cmd, argv);
+	ret = exec_cmd(cmd, argv, NULL);
 #endif
 	return ret;
 }
lib/misc/lvm-exec.c +12 -2
index d332aaa..5cad79e 100644
@@ -46,7 +46,7 @@ static char *_verbose_args(const char *const argv[], char *buf, size_t sz)
 /*
  * Execute and wait for external command
  */
-int exec_cmd(struct cmd_context *cmd, const char *const argv[])
+int exec_cmd(struct cmd_context *cmd, const char *const argv[], int *rstatus)
 {
 	pid_t pid;
 	int status;
@@ -71,6 +71,9 @@ int exec_cmd(struct cmd_context *cmd, const char *const argv[])
 		_exit(errno);
 	}
 
+	if (rstatus)
+		*rstatus = -1;
+
 	/* Parent */
 	if (wait4(pid, &status, 0, NULL) != pid) {
 		log_error("wait4 child process %u failed: %s", pid,
@@ -84,9 +87,16 @@ int exec_cmd(struct cmd_context *cmd, const char *const argv[])
 	}
 
 	if (WEXITSTATUS(status)) {
-		log_error("%s failed: %u", argv[0], WEXITSTATUS(status));
+		if (rstatus) {
+			*rstatus = WEXITSTATUS(status);
+			log_verbose("%s failed: %u", argv[0], *rstatus);
+		} else
+			log_error("%s failed: %u", argv[0], WEXITSTATUS(status));
 		return 0;
 	}
 
+	if (rstatus)
+		*rstatus = 0;
+
 	return 1;
 }
lib/misc/lvm-exec.h +2 -2
index 6afc3a7..6d984f8 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.  
- * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved.
  *
  * This file is part of LVM2.
  *
@@ -19,6 +19,6 @@
 #include "lib.h"
 
 struct cmd_context;
-int exec_cmd(struct cmd_context *cmd, const char *const argv[]);
+int exec_cmd(struct cmd_context *cmd, const char *const argv[], int *rstatus);
 
 #endif
tools/lvresize.c +13 -7
index 018dfc2..ca707f4 100644
@@ -129,6 +129,7 @@ static int _request_confirmation(struct cmd_context *cmd,
 enum fsadm_cmd_e { FSADM_CMD_CHECK, FSADM_CMD_RESIZE };
 #define FSADM_CMD "fsadm"
 #define FSADM_CMD_MAX_ARGS 6
+#define FSADM_CHECK_FAILS_FOR_MOUNTED 3 /* shell exist status code */
 
 /*
  * FSADM_CMD --dry-run --verbose --force check lv_path
@@ -137,7 +138,8 @@ enum fsadm_cmd_e { FSADM_CMD_CHECK, FSADM_CMD_RESIZE };
 static int _fsadm_cmd(struct cmd_context *cmd,
 		      const struct volume_group *vg,
 		      const struct lvresize_params *lp,
-		      enum fsadm_cmd_e fcmd)
+		      enum fsadm_cmd_e fcmd,
+		      int *status)
 {
 	char lv_path[PATH_MAX];
 	char size_buf[SIZE_BUF];
@@ -177,7 +179,7 @@ static int _fsadm_cmd(struct cmd_context *cmd,
 
 	argv[i] = NULL;
 
-	return exec_cmd(cmd, argv);
+	return exec_cmd(cmd, argv, status);
 }
 
 static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
@@ -321,6 +323,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
 	struct lv_segment *seg, *uninitialized_var(mirr_seg);
 	uint32_t seg_extents;
 	uint32_t sz, str;
+	int status;
 	struct dm_list *pvh = NULL;
 	int use_policy = arg_count(cmd, use_policies_ARG);
 
@@ -637,13 +640,16 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
 
 	if (lp->resizefs) {
 		if (!lp->nofsck &&
-		    !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_CHECK)) {
-			stack;
-			return ECMD_FAILED;
+		    !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_CHECK, &status)) {
+			if (status != FSADM_CHECK_FAILS_FOR_MOUNTED) {
+				stack;
+				return ECMD_FAILED;
+			}
+                        /* some filesystems supports online resize */
 		}
 
 		if ((lp->resize == LV_REDUCE) &&
-		    !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_RESIZE)) {
+		    !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_RESIZE, NULL)) {
 			stack;
 			return ECMD_FAILED;
 		}
@@ -711,7 +717,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
 	log_print("Logical volume %s successfully resized", lp->lv_name);
 
 	if (lp->resizefs && (lp->resize == LV_EXTEND) &&
-	    !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_RESIZE)) {
+	    !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_RESIZE, NULL)) {
 		stack;
 		return ECMD_FAILED;
 	}
Signature · 1 line
1.7.3.2