linux nbd源码学习 - maketr脚本分析

➜  nbd-master cat maketr                               
#!/bin/sh
#
# Example script to make a transaction log file
# Must be run as root. Remember to chown the file afterwards

# Insert the name of a tarfile here
tarfile=/home/amb/iptables/iptables_1.4.4.orig.tar.gz
tmpnam=`mktemp`   #创建临时文件,例如/tmp/tmp.R5JqZuHCkG
conffile=${tmpnam}.conf  #设置配置文件名称
pidfile=${tmpnam}.pid    #设置进程pid保存的文件名称
output=`pwd`/output.tr   #测试结果输出文件

ulimit -c unlimited

cat >${conffile} <<EOF
[generic]
[export1]
        exportname = $tmpnam
    transactionlog = $output
        flush = true
        fua = true
        rotational = true
EOF
./nbd-server -C ${conffile} -p ${pidfile} &   #启动nbd-server
PID=$!                                        #获取nbd-server启动的进程号
sleep 1
dd if=/dev/zero of=${tmpnam} bs=1M count=50   #bs(block size)为1M, count为50, 所以创建了一个50M的文件
./nbd-client -N export1 127.0.0.1 /dev/nbd0
mkfs.ext3 /dev/nbd0
mount -t ext3 -odata=journal,barrier=1 /dev/nbd0 /mnt
(cd /mnt ; tar xvzf ${tarfile} ; sync) 2>&1 >/dev/null #其中命令在()中的意思是另开命令组执行命令,也就是另开一个子shell执行命令,因此不会影响当前shell所处目录,下一条命令也不会出错。https://www.cnblogs.com/nkwy2012/p/9171414.html)
umount /mnt
mount -t ext3 -odata=journal,barrier=1 /dev/nbd0 /mnt
(cd /mnt ; tar cvzf /dev/null . ; sync) 2>&1 >/dev/null
dbench -D /mnt 1 &   #dbench是一个文件系统基准,产生良好的文件系统负载的测试工具 
sleep 10
killall dbench
sleep 2
killall -KILL dbench
sync
umount /mnt
./nbd-client -d /dev/nbd0
if [ -f ${pidfile} ]
then
        kill `cat ${pidfile}`
        rm -f ${pidfile}
else
        kill $PID
fi
rm -f $tmpnam ${conffile}
ls -la ${output}
posted @ 2020-01-08 15:05  kissrule  阅读(631)  评论(0编辑  收藏  举报