Thread (24 messages) 24 messages, 3 authors, 2019-01-17
STALE2751d
Revisions (3)
  1. v2 current
  2. v3 [diff vs current]
  3. v4 [diff vs current]

[PATCH blktests v2 10/16] common: Introduce _dd() helper function

From: Shin'ichiro Kawasaki <hidden>
Date: 2019-01-10 09:38:12
Subsystem: the rest · Maintainer: Linus Torvalds

To analyze dd command failures found by blktests, need to confirm dd
command options. Introduce the helper function which executes dd and
records dd command options in FULL file for quick analysis.

Signed-off-by: Shin'ichiro Kawasaki <redacted>
---
 common/rc | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
diff --git a/common/rc b/common/rc
index 0b99e84..190e450 100644
--- a/common/rc
+++ b/common/rc
@@ -246,3 +246,34 @@ set_scheduler() {
 		return 1
 	fi
 }
+
+# Issue dd command with five arguments and record command line in FULL file.
+# args: target device, r/w, start sector, sector len, block size in bytes
+_dd() {
+	local target_dev=${1}
+	local rw=${2}
+	local -i start_sector=${3}
+	local -i start_byte=$(( start_sector * 512 ))
+	local -i sector_count=${4}
+	local -i bs=${5}
+	local -i block_count=$(( sector_count * 512 / bs ))
+
+	local _cmd="dd bs=${bs} count=${block_count}"
+
+	if [[ ${rw} = "read" ]]; then
+		_cmd="${_cmd} if=${target_dev} of=/dev/null"
+		_cmd="${_cmd} iflag=skip_bytes skip=${start_byte}"
+	elif [[ ${rw} = "write" ]]; then
+		_cmd="${_cmd} if=/dev/zero of=${target_dev}"
+		_cmd="${_cmd} oflag=seek_bytes,direct seek=${start_byte}"
+	fi
+
+	echo "${_cmd}" >> "$FULL" 2>&1
+
+	if ! eval "${_cmd}" >> "$FULL" 2>&1 ; then
+		echo "dd command failed"
+		return 1
+	fi
+
+	sync
+}
-- 
2.20.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help