From: xiao yang Date: Tue, 16 Jan 2018 07:26:55 +0000 (+0800) Subject: common/xfs: Check if write supports [-c|-d] option in xfs_db X-Git-Tag: v2022.05.01~1698 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e33b0351dae375105680dd70582a43ad89ac4bb8;p=xfstests-dev.git common/xfs: Check if write supports [-c|-d] option in xfs_db 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 Reviewed-by: Darrick J. Wong Signed-off-by: Eryu Guan --- diff --git a/common/xfs b/common/xfs index 45b84a04..ab583640 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()