From cf9222f58c15e4e2d79eddd101221951ebf25a30 Mon Sep 17 00:00:00 2001 From: noaOrMlnx Date: Tue, 18 Nov 2025 23:08:55 +0200 Subject: [PATCH 1/2] [Mellanox] Fix generate_dump sysfs copy to copy only files with permission --- scripts/generate_dump | 52 ++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index 96278aefc11..8e1ef81ffd3 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -914,7 +914,7 @@ save_sys() { chmod ugo+rw -R $DUMPDIR/$BASE/sys } -save_sysfs() { +save_sdk_sysfs() { trap 'handle_error $? $LINENO' ERR local src="$1" local dest="$2" @@ -932,39 +932,55 @@ save_sysfs() { return 1 } + copy_file() { + local f="$1" + local target="$2" + if $NOOP; then + echo "cat $f > $target 2>/dev/null" + else + cat "$f" > "$target" 2>/dev/null + fi + } + # Copy files directly under src for f in "$src"/*; do - if [ -f "$f" ]; then + if [[ -f "$f" ]]; then local base="$(basename "$f")" should_skip "$base" && continue - local target="$dest/$base" - - if $NOOP; then - echo "cat $f > $target 2>/dev/null" - else - cat "$f" > "$target" 2>/dev/null - fi + copy_file "$f" "$dest/$base" fi done # Copy sub folders for d in "$src"/*; do - if [ -d "$d" ]; then + if [[ -d "$d" ]]; then local subdir_dest="$dest/$(basename "$d")" $MKDIR $V -p "$subdir_dest" + local present=0 hw_present="" frequency_support=0 only_copy_presence_files=false + [[ -f "$d/present" ]] && present=$(<"$d/present") + [[ -f "$d/hw_present" ]] && hw_present=$(<"$d/hw_present") + [[ -f "$d/frequency_support" ]] && frequency_support=$(<"$d/frequency_support") + + # if the module is unplugged, skip the rest of the files + if [[ -n "$hw_present" ]]; then + if [[ "$present" == "0" && "$hw_present" == "0" ]]; then + only_copy_presence_files=true + fi + else + [[ "$present" == "0" ]] && only_copy_presence_files=true + fi + # copy only files inside sub folder, not sub-sub folders for f in "$d"/*; do - if [ -f "$f" ]; then + if [[ -f "$f" ]]; then local base="$(basename "$f")" should_skip "$base" && continue - local target="$subdir_dest/$base" - if $NOOP; then - echo "cat $f > $target 2>/dev/null" - else - cat "$f" > "$target" 2>/dev/null - fi + [[ "$only_copy_presence_files" == true && "$base" != "present" && "$base" != "hw_present" ]] && continue + [[ "$frequency_support" == "0" && "$base" == "frequency" ]] && continue + + copy_file "$f" "$subdir_dest/$base" fi done fi @@ -1491,7 +1507,7 @@ collect_mellanox() { local sdk_sysfs_dest_path="$TARDIR/sdk_sysfs/sx_core/asic0" local excludes_sysfs_files=(rx_los tx_disable module_info module_latched_flag_info power_mode power_mode_policy reinsert reset) - save_sysfs "$sdk_sysfs_src_path" "$sdk_sysfs_dest_path" "${excludes_sysfs_files[@]}" & + save_sdk_sysfs "$sdk_sysfs_src_path" "$sdk_sysfs_dest_path" "${excludes_sysfs_files[@]}" & # Save CMIS-host-management related files local cmis_host_mgmt_path="cmis-host-mgmt" From 23fbfeab3f38178369b187327d5f14f5a1ce5d45 Mon Sep 17 00:00:00 2001 From: Noa Or <58519608+noaOrMlnx@users.noreply.github.com> Date: Tue, 25 Nov 2025 15:03:05 +0200 Subject: [PATCH 2/2] Rename copy_file function to copy_file_content in generate_dump --- scripts/generate_dump | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index 8e1ef81ffd3..40b392a7b19 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -932,7 +932,7 @@ save_sdk_sysfs() { return 1 } - copy_file() { + copy_file_content() { local f="$1" local target="$2" if $NOOP; then @@ -947,7 +947,7 @@ save_sdk_sysfs() { if [[ -f "$f" ]]; then local base="$(basename "$f")" should_skip "$base" && continue - copy_file "$f" "$dest/$base" + copy_file_content "$f" "$dest/$base" fi done @@ -980,7 +980,7 @@ save_sdk_sysfs() { [[ "$only_copy_presence_files" == true && "$base" != "present" && "$base" != "hw_present" ]] && continue [[ "$frequency_support" == "0" && "$base" == "frequency" ]] && continue - copy_file "$f" "$subdir_dest/$base" + copy_file_content "$f" "$subdir_dest/$base" fi done fi