Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions SMBDiagnostics/README
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
Steps to collect the logs:
--------------------------
Copy smbclientlogs.sh (Shell script) to linux machine where we need to collect logs.
# Steps to collect the logs:

Dependencies:
Install packages trace-cmd, zip and ss. If debian-based distro, please install zgrep.
If using CaptureNetwork option (see below), install tcpdump.
Copy smbclientlogs.sh (Shell script) to the Linux machine where we need to collect logs.

If issue can be easily reproduced:
1) Open linux terminal or ssh to linux machine or the AKS node.
## Dependencies:
- Ensure the **ss** command is installed (usually provided by the **iproute2** or **iproute** package), and install **trace-cmd** and **zip**.
- On debian-based distros, also install **zgrep**.
- If using CaptureNetwork option (see below), install **tcpdump**.

## Usage:
**If issue can be easily reproduced:**
1) Open Linux terminal or ssh to Linux machine or the AKS node.
2) Run the command "sudo bash" to gain root privileges.
3) Cd to script location and run the command
"chmod +x ./smbclientlogs.sh"
`chmod +x ./smbclientlogs.sh`
4) Run the command
"./smbclientlogs.sh start"
(or)
"./smbclientlogs.sh start CaptureNetwork" (in case Microsoft instructs you to use this option)
`./smbclientlogs.sh start`
or
`./smbclientlogs.sh start CaptureNetwork` (in case Microsoft instructs you to use this option)
5) Repro the issue.
6) Run "./smbclientlogs.sh stop"
6) Run `./smbclientlogs.sh stop`
7) Above command generates output.zip
8) Send the output.zip file to Microsoft support against your support case.

Contents of Zip file:
## Contents of Zip file:
1) cifs_diag.txt - Internal debug data and stats from the SMB client.
2) cifs_dmesg - System logs since the last reboot.
3) cifs_trace - Output of trace-cmd, which contain the kernel event logs.
4) os_details.txt - Info about the operating system, which will help developers to understand which features/fixes are missing.
5) cifs_traffic.pcap - network capture of SMB traffic in case CaptureNetwork option was used.

62 changes: 32 additions & 30 deletions SMBDiagnostics/smbclientlogs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ CIFS_PORT=445
TRACE_CIFSBPF_ABS_PATH="$(cd "$(dirname "trace-cifsbpf")" && pwd)/$(basename "trace-cifsbpf")"
PYTHON_PROG='python'
STDLOG_FILE='/dev/null'
CIFS_FYI_ENABLED=0
VERBOSE_FLAG=".smbclientlogs_verbose.flag"

am_i_root() {
local euid=$(id -u)
if (( $euid != 0 ));
then
if (( $euid != 0 )); then
echo "Please run $0 as root";
exit
fi
Expand All @@ -35,7 +34,7 @@ main() {
}

init() {
check_utils
check_utils "$@"
if [[ -f $DIRNAME ]];
then
rm -rf "$DIRNAME"
Expand All @@ -44,55 +43,56 @@ init() {
}

check_utils() {
which trace-cmd > /dev/null
if [ $? == 1 ]; then
if ! command -v trace-cmd >/dev/null 2>&1; then
echo "trace-cmd is not installed, please install trace-cmd"
exit 1
fi

if (( ($(which apt |egrep -c apt) > 0) && ($(which zgrep |egrep -c zgrep) == 0) ));
then
echo "zgrep is not installed, please install zgrep"
if (command -v apt >/dev/null 2>&1) && (! command -v zgrep >/dev/null 2>&1); then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to your change: Why do we have apt as a dependency? This would not work for non-debian distros, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a precondition for using zgrep.

echo "apt-based package management is in use, but zgrep is not installed, please install zgrep"
exit 1
fi

which tcpdump > /dev/null
if [ $? != 0 ]; then
if ! command -v tcpdump >/dev/null 2>&1; then
echo "tcpdump is not installed. Please install tcpdump if you intend to capture network traces."
#Not exiting since packet capture is optional
fi

which zip > /dev/null
if [ $? == 1 ]; then
if ! command -v zip >/dev/null 2>&1; then
echo "zip is not installed, please install zip to continue"
exit 1
fi

which ss > /dev/null
if [ $? == 1 ]; then
if ! command -v ss >/dev/null 2>&1; then
echo "ss is not installed, please install ss to continue"
exit 1
fi

which python > /dev/null
if [ $? == 1 ]; then
which python3 > /dev/null
if [ $? == 1 ]; then
if [[ "$*" =~ "OnAnomaly" ]]; then
if command -v python3 >/dev/null 2>&1; then
PYTHON_PROG='python3'
elif ! command -v python >/dev/null 2>&1; then
echo "python is not installed, please install python to continue"
exit 1
else PYTHON_PROG='python3'
else PYTHON_PROG='python'
fi
fi
}

start_trace() {
if [[ "$*" =~ "VerboseLogs" ]]; then
echo "setting verbose logging for cifs module"
cat /proc/fs/cifs/cifsFYI 2>/dev/null > "${VERBOSE_FLAG}"
echo 'module cifs +p' > /sys/kernel/debug/dynamic_debug/control
echo 'file fs/cifs/* +p' > /sys/kernel/debug/dynamic_debug/control
echo 7 > /proc/fs/cifs/cifsFYI
CIFS_FYI_ENABLED=1
fi
trace-cmd start -e cifs
rc=$?

if [ $rc -ne 0 ]; then
echo "trace-cmd failed to start. cifs-trace will not be captured."
fi
}

dump_system_logs() {
Expand All @@ -115,7 +115,7 @@ dump_system_logs() {

dump_azfileauth_logs() {
local output_file=$1
if which azfilesauthmanager >/dev/null 2>&1; then
if command -v azfilesauthmanager >/dev/null 2>&1; then
echo -e "\nDumping azfileauth tickets" >> "$output_file"
azfilesauthmanager list >> "$output_file" 2>&1
else
Expand Down Expand Up @@ -143,14 +143,12 @@ dump_os_information() {
echo -e "\nSystem Uptime:" >> os_details.txt
cat /proc/uptime >> os_details.txt
echo -e "\npackage install details:" >> os_details.txt
if (( $(which rpm |egrep -c rpm) > 0));
then
if command -v rpm >/dev/null 2>&1; then
rpm -qa --last |grep keyutils >> os_details.txt
rpm -qa --last |grep cifs-utils >> os_details.txt
rpm -qi keyutils >> os_details.txt
rpm -qi cifs-utils >> os_details.txt
elif (( $(which apt |egrep -c apt) > 0 ));
then
elif command -v apt >/dev/null 2>&1; then
zgrep -B5 -A5 keyutils /var/log/apt/history.log* >> os_details.txt
zgrep -B5 -A5 cifs-utils /var/log/apt/history.log* >> os_details.txt
dpkg -s keyutils cifs-utils >> os_details.txt
Expand Down Expand Up @@ -196,8 +194,8 @@ trace_cifsbpf() {
}

start() {
init
start_trace $@
init "$@"
start_trace "$@"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is start_trace utilizing the args passed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, yes for VerboseLogs, but I found a bug. Let me submit another commit.

dump_os_information
echo "======= Dumping CIFS Debug Stats at start =======" > cifs_diag.txt
dump_debug_stats
Expand All @@ -216,6 +214,8 @@ start() {
if [[ "$*" =~ "OnAnomaly" ]]; then
trace_cifsbpf
fi

echo "started collecting smb client logs"
}

stop() {
Expand Down Expand Up @@ -249,8 +249,10 @@ stop_trace() {
trace-cmd report > "${DIRNAME}/cifs_trace"
trace-cmd stop
trace-cmd reset
if [ $CIFS_FYI_ENABLED -ne 0 ]; then
echo 0 > /proc/fs/cifs/cifsFYI
if [ -f "${VERBOSE_FLAG}" ]; then
prev_value=$(cat "${VERBOSE_FLAG}")
echo "${prev_value:-0}" > /proc/fs/cifs/cifsFYI
rm -f "${VERBOSE_FLAG}"
fi
rm -rf trace.dat*
}
Expand Down