Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the tgt server process?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

What is the tgt server process? in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Overall process

Figure1 tgt flow chart

Basic operation

Install the tgt package:

Yum-- enablerepo=epel-y install scsi-target-utils

After the installation is complete, start the TGT service:

# service tgtd start

If you want to start the TGT service automatically when the system starts, you can use the following command:

# chkconfig tgtd on

If you want to confirm whether the TGT service is started, you can use # servicetgtd status to check the service status; of course, you can query the port occupied by the TGT service:

# netstat-anlpt | grep 3260

Where 3260 is the listening port for the TGT service. The results are as follows:

Create a Target:

Tgtadm-- lld iscsi-- mode target-- op new-- tid 2--targetname iqn.2012-12.com.example:server.target

Query Target:

Tgtadm-lld iscsi--mode target-op show

Query details:

Tgtadm-lld iscsi--mode target-op show-tid 2

Create a file to use as a LUN:

Ddif=/dev/zero of=/home/lun.bin count=0 obs=1 seek=1G

Add LUN: (SELinux needs to be closed, otherwise an error invalid is reported)

Tgtadm-lld iscsi--mode logicalunit-op new-tid 2-lun 1-backing-store / home/lun.bin

Restarting the machine is required to modify the configuration file:

Modify / etc/selinux/config file

Change SELINUX=enforcing to SELINUX=disabled

Just restart the machine.

Set access permission all: (the server permission should be set to a specific IP, otherwise the client discover fails)

Tgtadm-- lldiscsi-- mode target-- op bind-- tid 2-I all

Tgtadm-lld iscsi--mode target-op bind-tid 2-I 192.168.56.103

Iscsi initiator connection (server firewall needs to be turned off)

Systemctl stop firewalld.service

Systemctl disable firewalld.service

Iscsiadm-m discovery-t sendtargets-p 192.168.56.102

Login:

Iscsiadm-m node-- login

# Log in to one

# iscsiadm-mode node-targetname iqn.2012-10.net.cpd:san.target01-portal 172.16.201.200-login

Check login information

Iscsiadm-m session-o show

After logging in, fdisk-l can see the server device mounted by iscsi, which can then be used as a normal disk device.

Configure the tgt compilation environment:

Remove the compilation related to doc and the network connection problem will get stuck.

Find-name Makefile | xargs grep O2-R--colour

Make DEBUG=yes

Make install

Then you can debug with gdb.

Tgt process Analysis:

Http://www.sysnote.org/2014/08/23/tgt-arch/

/ usr/sbin/tgtd-f

Tgt lock:

/ var/run/tgtd/socket.0.lock

Clean the lock:

Rm-f / var/run/tgtd/*

Kill the tgtd process:

Kill-9 pid

Debug with debug information:

Gdb-args / usr/sbin/tgtd-f-d 1

Detailed description of process to create target

Execute:

Tgtadm-- lld iscsi-- mode target-- op new-- tid 2--targetname iqn.2012-12.com.example:server.target

Trigger:

Mgmt_event_handler

Main-> ipc_init-> tgt_event_add (mgmt_event_handler)

Trigger the event through socket: / var/run/tgtd/socket.0

Tgtadm's ipc_mgmt_connect triggers tgtd's event mgmt_event_handler

Main-> ipc_mgmt_req-> ipc_mgmt_connect

Ipc_mgmt_req-> ipc_mgmt_rsp-> ipc_mgmt_connect

Used to connect processes.

Multiple triggers:

Mtask_recv_send_handler for interprocess communication.

Mtask_recv_send_handler-> mtask_received- > mtask_execute-> target_mgmt-> tgt_target_create- > tgt_device_create

If backing is 0, the bs worker thread will not be started

Used to carry out specific operations.

Create back-end storage

Execute:

Tgtadm-lld iscsi-mode logicalunit-op new-tid 2--lun 1-backing-store / home/lun.bin

Trigger:

Mgmt_event_handler (administrative event handling added)

Mtask_recv_send_handler-> mtask_received- > mtask_execute-> device_mgmt-> tgt_device_create-> bs_rdwr_init-> bs_thread_open- > bs_thread_worker_fn

When the new backend is executed, bs_rdwr_init is called to open bs_thread_worker_fn.

When the device was created, 16 bs worker threads were created.

3260 is a listening port

Getaddrinfo to get the linked list of socketaddr structures

Https://baike.baidu.com/item/getaddrinfo/9021771

Block device related initialization

Main-> bs_init-> bs_init_signalfd (bs_sig_request_done)

The corresponding handler function for the semaphore is bs_sig_request_done.

After initialization, the corresponding operation cmd_perform can be found in the scsi_cmd_perform according to the opcode op.

The info in bs_thread_worker_fn and the info in bs_thread_cmd_submit point to the same memory x unit (confirmed by gdb)

Remove cmd from info- > pending_list in bs_thread_worker_fn

Bs_rdwr_request reads the information from the device handle fd to the buffer of scsi. This function should be the specific operation of the underlying block device.

Iscsi_tx_handler-> iscsi_task_tx_start- > iscsi_data_rsp_build stores the data to be read in conn- > rsp.data

The above is basically a complete server-side read operation that responds to the details of the process to the client.

The read or write of the data on the server is controlled by the client. The req- > cdb is passed to cmd- > scb.

In bs_rdwr_request, the block device is operated according to cmd- > scb [0].

The answer to the question about the tgt server process is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report