diff mbox

[v2,1/2] common/xfs: Check if write supports [-c|-d] option in xfs_db

Message ID 1515737783-2061-1-git-send-email-yangx.jy@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Xiao Yang Jan. 12, 2018, 6:16 a.m. UTC
Make sure _scratch_xfs_set_metadata_field() can be used on an
old xfsprogs-dev(e.g. v3.1.1).

The "-d" option was introduced since xfsprogs-dev v4.7.0 by commit
86769b3 ("xfs_db: allow recalculating CRCs on invalid metadata").

The special argument "--" is only used to end option-scanning
in getopt().  getopt() was introduced since xfsprogs-dev v3.2.3 by
commit c9f5e3d ("xfs_db: Allow writes of corrupted data")'.

Signed-off-by: xiao yang <yangx.jy@cn.fujitsu.com>
---
 common/xfs | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Eryu Guan Jan. 12, 2018, 7:44 a.m. UTC | #1
On Fri, Jan 12, 2018 at 02:16:22PM +0800, xiao yang wrote:
> Make sure _scratch_xfs_set_metadata_field() can be used on an
> old xfsprogs-dev(e.g. v3.1.1).
> 
> The "-d" option was introduced since xfsprogs-dev v4.7.0 by commit
> 86769b3 ("xfs_db: allow recalculating CRCs on invalid metadata").
> 
> The special argument "--" is only used to end option-scanning
> in getopt().  getopt() was introduced since xfsprogs-dev v3.2.3 by
> commit c9f5e3d ("xfs_db: Allow writes of corrupted data")'.
> 
> Signed-off-by: xiao yang <yangx.jy@cn.fujitsu.com>
> ---
>  common/xfs | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/common/xfs b/common/xfs
> index 45b84a0..59d6dd3 100644
> --- a/common/xfs
> +++ b/common/xfs
> @@ -658,8 +658,11 @@ _scratch_xfs_set_metadata_field()
>  	for arg in "$@"; do
>  		cmds+=("-c" "${arg}")
>  	done
> -	_scratch_xfs_db -x "${cmds[@]}" -c "write -d ${key} -- ${value}"
> -	echo

I'm not sure if any golden image depends on this extra newline..

> +
> +	local wr_cmd="write"
> +	_scratch_xfs_db -x -c "help write" | egrep -q "(-c|-d)" && value="-- $value"
> +	_scratch_xfs_db -x -c "help write" | egrep -q "(-d)" && wr_cmd="${wr_cmd} -d"
> +	_scratch_xfs_db -x "${cmds[@]}" -c "${wr_cmd} ${key} ${value}"

This looks OK, but I'd like Darrick to help review too.

Thanks,
Eryu

>  }
>  
>  _scratch_xfs_get_sb_field()
> -- 
> 1.8.3.1
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Darrick J. Wong Jan. 12, 2018, 4:43 p.m. UTC | #2
On Fri, Jan 12, 2018 at 02:16:22PM +0800, xiao yang wrote:
> Make sure _scratch_xfs_set_metadata_field() can be used on an
> old xfsprogs-dev(e.g. v3.1.1).
> 
> The "-d" option was introduced since xfsprogs-dev v4.7.0 by commit
> 86769b3 ("xfs_db: allow recalculating CRCs on invalid metadata").
> 
> The special argument "--" is only used to end option-scanning
> in getopt().  getopt() was introduced since xfsprogs-dev v3.2.3 by
> commit c9f5e3d ("xfs_db: Allow writes of corrupted data")'.
> 
> Signed-off-by: xiao yang <yangx.jy@cn.fujitsu.com>
> ---
>  common/xfs | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/common/xfs b/common/xfs
> index 45b84a0..59d6dd3 100644
> --- a/common/xfs
> +++ b/common/xfs
> @@ -658,8 +658,11 @@ _scratch_xfs_set_metadata_field()
>  	for arg in "$@"; do
>  		cmds+=("-c" "${arg}")
>  	done
> -	_scratch_xfs_db -x "${cmds[@]}" -c "write -d ${key} -- ${value}"
> -	echo
> +
> +	local wr_cmd="write"
> +	_scratch_xfs_db -x -c "help write" | egrep -q "(-c|-d)" && value="-- $value"

"${value}" at the end of this line, for consistency within the function?

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

> +	_scratch_xfs_db -x -c "help write" | egrep -q "(-d)" && wr_cmd="${wr_cmd} -d"
> +	_scratch_xfs_db -x "${cmds[@]}" -c "${wr_cmd} ${key} ${value}"
>  }
>  
>  _scratch_xfs_get_sb_field()
> -- 
> 1.8.3.1
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/common/xfs b/common/xfs
index 45b84a0..59d6dd3 100644
--- a/common/xfs
+++ b/common/xfs
@@ -658,8 +658,11 @@  _scratch_xfs_set_metadata_field()
 	for arg in "$@"; do
 		cmds+=("-c" "${arg}")
 	done
-	_scratch_xfs_db -x "${cmds[@]}" -c "write -d ${key} -- ${value}"
-	echo
+
+	local wr_cmd="write"
+	_scratch_xfs_db -x -c "help write" | egrep -q "(-c|-d)" && value="-- $value"
+	_scratch_xfs_db -x -c "help write" | egrep -q "(-d)" && wr_cmd="${wr_cmd} -d"
+	_scratch_xfs_db -x "${cmds[@]}" -c "${wr_cmd} ${key} ${value}"
 }
 
 _scratch_xfs_get_sb_field()