From ddf52016fa03ba192f242ad641a5c8e5a95035a1 Mon Sep 17 00:00:00 2001 From: "J. Eric Ivancich" Date: Tue, 6 Oct 2020 15:21:02 -0400 Subject: [PATCH] rgw: allow rgw-orphan-list to note when rados objects are in namespace Currently namespaces and locators are ignored when `rados ls` is run by rgw-orphan-list to record RADOS's known objects. However there have been cases where RADOS objects have a locator, and when one is included in the listing, the script does not handle it correctly. Now when objects have locators, we will prevent their output from entering the .intermediate file. Additionally we do not expect RGW data objects to be in RADOS namespaces, so when a namespaced object is detected, we'll error out with a message. Signed-off-by: J. Eric Ivancich --- src/rgw/rgw-orphan-list | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw-orphan-list b/src/rgw/rgw-orphan-list index bdb0a43ac1181..1ebd60c719d13 100755 --- a/src/rgw/rgw-orphan-list +++ b/src/rgw/rgw-orphan-list @@ -18,6 +18,9 @@ delta_out="${out_dir}/orphan-list-${timestamp}.out" error_out() { echo "An error was encountered while running '$1'. Aborting." + if [ $# -gt 2 ] ;then + echo "Error: $3" + fi if [ $# -gt 1 ] ;then echo "Review file '$2' for details." fi @@ -54,10 +57,21 @@ echo "Pool is \"$pool\"." echo "Note: output files produced will be tagged with the current timestamp -- ${timestamp}." echo "running 'rados ls' at $(date)" -rados ls --pool="$pool" >"$rados_out" 2>"$rados_err" +rados ls --pool="$pool" --format=json-pretty --all >"$rados_out" 2>"$rados_err" if [ "$?" -ne 0 ] ;then error_out "rados ls" "$rados_err" fi + +# check for namespaces and error out if any found +grep '^[[:blank:]]*"namespace":' "$rados_out" | grep --silent '[^:]*: "[^"]' +if [ "${PIPESTATUS[1]}" -eq 0 ] ;then + error_out "rados ls" "$rados_out" "Found one or more RADOS objects existing in a namespace." +fi + +# move from json to list of oids +grep '^[[:blank:]]*"name":' "$rados_out" | sed 's/[^:]*: "\(.*\)"$/\1/' >"$temp_file" +mv -f "$temp_file" "$rados_out" + sort -u "$rados_out" >"$temp_file" mv -f "$temp_file" "$rados_out" -- 2.39.5