Linux SCSI target framework (tgt)源码解读一

测试环境执行读操作后,tgt程序的线程中有部分线程出现了pread64调用。对应线程的调用堆栈:
Thread 19 (Thread 0x7f2e6881a700 (LWP 23420)):
#0 0x000000317c40f063 in pread64 () from /lib64/libpthread.so.0
#1 0x0000000000432af7 in bs_rdwr_request ()
#2 0x000000000043649e in bs_thread_worker_fn ()
#3 0x000000317c4079d1 in start_thread () from /lib64/libpthread.so.0
#4 0x000000317c0e89dd in clone () from /lib64/libc.so.6
Thread 18 (Thread 0x7f2e67e19700 (LWP 23421)):
#0 0x000000317c40f063 in pread64 () from /lib64/libpthread.so.0
#1 0x0000000000432af7 in bs_rdwr_request ()
#2 0x000000000043649e in bs_thread_worker_fn ()
#3 0x000000317c4079d1 in start_thread () from /lib64/libpthread.so.0
#4 0x000000317c0e89dd in clone () from /lib64/libc.so.6

从bs_thread_worker_fn函数开始分析,在此之前先看看rdwr_bst

static struct backingstore_template rdwr_bst = {
.bs_name = “rdwr”,
.bs_datasize = sizeof(struct bs_thread_info),
.bs_open = bs_rdwr_open,
.bs_close = bs_rdwr_close,
.bs_init = bs_rdwr_init,
.bs_exit = bs_rdwr_exit,
.bs_cmd_submit = bs_thread_cmd_submit,
.bs_oflags_supported = O_SYNC | O_DIRECT,
};

bs_rdwr_init->bs_thread_open->pthread_create
bs_rdwr_request函数作为bs_thread_open的第二个参数传入
接着通过info->request_fn = rfn(bs_rdwr_request)作为pthread_create的第四个参数传给thread

bs_thread_worker_fn函数作为pthread_create的第三个参数是线程运行函数的地址。

在bs_thread_worker_fn函数中通过 info->request_fn(cmd);调用了bs_rdwr_request函数。
在bs_rdwr_request中通过判断 cmd->scb[0] 的值如果是读相关的cmd会调用
pread64 函数。
因为线程调用堆栈没用具体的文件行数,无法判断cmd的类型。

你可能感兴趣的:(tgt)