diff mbox series

[7/9] e2scrub_all: make sure there's enough free space for a snapshot

Message ID 20190321020218.5154-7-tytso@mit.edu
State Accepted, archived
Headers show
Series [1/9] e2scrub: check to make sure lvm2 is installed | expand

Commit Message

Theodore Ts'o March 21, 2019, 2:02 a.m. UTC
If there isn't, skip the volume so we don't spam the system
administrator with error messages.  It's quite commkon that there is
is zero free space in the volume group.

Addresses-Debian-Bug: #924301

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 scrub/e2scrub_all.in | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Darrick Wong March 21, 2019, 4:02 a.m. UTC | #1
On Wed, Mar 20, 2019 at 10:02:16PM -0400, Theodore Ts'o wrote:
> If there isn't, skip the volume so we don't spam the system
> administrator with error messages.  It's quite commkon that there is

'common'

> is zero free space in the volume group.
> 
> Addresses-Debian-Bug: #924301
> 
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  scrub/e2scrub_all.in | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/scrub/e2scrub_all.in b/scrub/e2scrub_all.in
> index 8bc868aa0..4cb90a0de 100644
> --- a/scrub/e2scrub_all.in
> +++ b/scrub/e2scrub_all.in
> @@ -21,6 +21,7 @@
>  PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
>  
>  scrub_all=0
> +snap_size_mb=256
>  conffile="@root_sysconfdir@/e2scrub.conf"
>  
>  test -f "${conffile}" && . "${conffile}"
> @@ -108,6 +109,9 @@ ls_scrub_targets() {
>  		eval "${lvm_vars}"
>  		echo "${LVM2_LV_ROLE}" | grep -q "snapshot" && continue
>  
> +		free_space="$(vgs -o vg_free --units m --noheadings --no-suffix "${LVM2_VG_NAME}" 2> /dev/null | sed -e 's/\..*//')"
> +		test "${snap_size_mb}" -gt "${free_space}" && continue
> +
>  		if [ -n "${MOUNTPOINT}" ]; then
>  			echo "${MOUNTPOINT}"
>  		else
> -- 
> 2.19.1
>
Lukas Czerner March 21, 2019, 11:18 a.m. UTC | #2
On Wed, Mar 20, 2019 at 10:02:16PM -0400, Theodore Ts'o wrote:
> If there isn't, skip the volume so we don't spam the system
> administrator with error messages.  It's quite commkon that there is
> is zero free space in the volume group.
> 
> Addresses-Debian-Bug: #924301
> 
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> ---
>  scrub/e2scrub_all.in | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/scrub/e2scrub_all.in b/scrub/e2scrub_all.in
> index 8bc868aa0..4cb90a0de 100644
> --- a/scrub/e2scrub_all.in
> +++ b/scrub/e2scrub_all.in
> @@ -21,6 +21,7 @@
>  PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
>  
>  scrub_all=0
> +snap_size_mb=256
>  conffile="@root_sysconfdir@/e2scrub.conf"
>  
>  test -f "${conffile}" && . "${conffile}"
> @@ -108,6 +109,9 @@ ls_scrub_targets() {
>  		eval "${lvm_vars}"
>  		echo "${LVM2_LV_ROLE}" | grep -q "snapshot" && continue
>  
> +		free_space="$(vgs -o vg_free --units m --noheadings --no-suffix "${LVM2_VG_NAME}" 2> /dev/null | sed -e 's/\..*//')"
> +		test "${snap_size_mb}" -gt "${free_space}" && continue

So you're going to be calling vgs for every lvs even though you can have
a whole bunch of them in the same vg. That's not very efficient.

You can just filter it out with the lvs at the start of the loop by
adding the proper select string.

-S vg_free\>${snap_size_mb}

-Lukas


> +
>  		if [ -n "${MOUNTPOINT}" ]; then
>  			echo "${MOUNTPOINT}"
>  		else
> -- 
> 2.19.1
>
Theodore Ts'o March 21, 2019, 2:26 p.m. UTC | #3
On Thu, Mar 21, 2019 at 12:18:56PM +0100, Lukas Czerner wrote:
> 
> So you're going to be calling vgs for every lvs even though you can have
> a whole bunch of them in the same vg. That's not very efficient.
> 
> You can just filter it out with the lvs at the start of the loop by
> adding the proper select string.
> 
> -S vg_free\>${snap_size_mb}

Good point.  BTW, that's why I had ignored one of your other
suggestions --- I needed LVM_VG_NAME, which means I needed more than
one output from lvs, so I use the output directly as you suggested.

        	   	     	  - Ted
diff mbox series

Patch

diff --git a/scrub/e2scrub_all.in b/scrub/e2scrub_all.in
index 8bc868aa0..4cb90a0de 100644
--- a/scrub/e2scrub_all.in
+++ b/scrub/e2scrub_all.in
@@ -21,6 +21,7 @@ 
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
 scrub_all=0
+snap_size_mb=256
 conffile="@root_sysconfdir@/e2scrub.conf"
 
 test -f "${conffile}" && . "${conffile}"
@@ -108,6 +109,9 @@  ls_scrub_targets() {
 		eval "${lvm_vars}"
 		echo "${LVM2_LV_ROLE}" | grep -q "snapshot" && continue
 
+		free_space="$(vgs -o vg_free --units m --noheadings --no-suffix "${LVM2_VG_NAME}" 2> /dev/null | sed -e 's/\..*//')"
+		test "${snap_size_mb}" -gt "${free_space}" && continue
+
 		if [ -n "${MOUNTPOINT}" ]; then
 			echo "${MOUNTPOINT}"
 		else