Data transmission method and device, storage medium and electronic equipment
By starting the block device server and client on the output device and mapping the external device as the target network block device, the complexity of the transmissive operation of the external device is solved and the operation efficiency is improved.
Patent Information
- Application Number
- CN202411107730.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-12
- Publication Date
- 2024-12-10
AI Technical Summary
In the prior art, the transmissive operation process of external devices is complex, resulting in low operation efficiency and no effective solution has yet.
By starting the block device server on the output device, setting the external device as the target network block device, and sending a connection notification message to the input device, starting the block device client, and mapping the target network block device into the target local block device , to realize data transmission.
The process of remote control of external devices has been simplified, operating convenience and efficiency have been improved, and the problem of overly complex operational processes has been solved.
Smart Images

Figure CN119109999A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computers, and more specifically, to a data transmission method, device, storage medium, and electronic device. Background Art
[0002] At present, the relevant technology often adopts the method of adapting external devices by developing dedicated interface protocols to achieve access to files and other resources stored in the external devices and related operations. In the relevant technology, the protocol development of external devices is difficult and the adaptability is poor. In addition, when performing transparent operations on external devices, it is also necessary to develop system drivers. The entire implementation process is too complicated, resulting in technical problems such as low operating efficiency.
[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0004] The embodiments of the present application provide a data transmission method, device, storage medium and electronic device to at least solve the technical problem that when performing transparent transmission operations on external devices, the operation process is too complicated, resulting in low operation efficiency.
[0005] According to one aspect of the present application, a data transmission method is provided, comprising: when an external device is connected to an output device, starting a block device server on the output device to set the external device as a target network block device; sending a connection notification message to an input device on the output device, wherein the connection notification message is used to indicate that the external device has been connected to the output device; in response to the input device receiving the connection notification message, starting a block device client on the input device to map the target network block device to a target local block device of the input device, wherein a target host connected to the input device allows the external device to be regarded as the target local block device for data transmission.
[0006] According to another aspect of the present application, a data transmission device is provided, including: a startup module, which is used to start a block device server on an output device when an external device is connected to an output device, so as to set the external device as a target network block device; a notification module, which is used to send a connection notification message to an input device on the output device, wherein the connection notification message is used to indicate that the external device has been connected to the output device; and a mapping module, which is used to start a block device client on the input device in response to the input device receiving the connection notification message, so as to map the target network block device to a target local block device of the input device, wherein the target host connected to the input device allows the external device to be regarded as the target local block device for data transmission.
[0007] Optionally, the device is used to send a connection notification message to the input device through the following method: starting a notification service thread on the output device, wherein the notification service thread is used to send the connection notification message; when the output device has established a connection with the input device and the external device is connected to the output device, sending the connection notification message through the notification service thread.
[0008] Optionally, the apparatus is further used to: when the output device and the input device have established a connection and the external device is connected to the output device, before sending a connection notification message through the notification service thread, when the output device has started the notification service thread, control the input device to start a notification receiving thread; establish a connection between the output device and the input device through the notification receiving thread, and generate a target path on the input device, wherein the target path represents a path set for the target local block device.
[0009] Optionally, the apparatus is used to start a block device server on an output device when an external device is connected to an output device so as to set the external device as a target network block device in the following manner: when the external device is connected to the output device, start a block device server on the output device; set a target port on the output device, wherein the target port corresponds to the block device server; and set the external device as the target network block device.
[0010] Optionally, the apparatus is used to start a block device client on the input device in response to the input device receiving the connection notification message, so as to map the target network block device to the target local block device of the input device in the following manner: in response to the input device receiving the connection notification message, start the block device client on the input device; set the target port and the target network address on the input device, wherein the target port corresponds to the target network address; map the target network block device to the target local block device of the input device, wherein the target host transmits data with the external device through the target port and the target network address.
[0011] Optionally, the apparatus is also used to: when an external device is connected to an output device, start a block device server on the output device to start hot plug detection before setting the external device as a target network block device, wherein the hot plug detection is used to identify the external device, and before the hot plug detection is started, automatically enumerate the external devices connected to the output device in advance; and update the connection status of the external device when the insertion and removal of the external device is detected.
[0012] Optionally, the apparatus is further configured to: in a case where the external device cancels the connection with the output device, send a disconnection notification message on the output device to the input device, wherein the disconnection notification message is used to indicate that the external device has been disconnected from the output device; in response to the input device receiving the disconnection notification message, exit the block device client on the input device to cancel mapping the target network block device as the target local block device of the input device.
[0013] According to another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when run.
[0014] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0015] In an embodiment of the present application, when an external device is connected to an output device, a block device server is started on the output device to set the external device as a target network block device; a connection notification message is sent on the output device to the input device, wherein the connection notification message is used to indicate that the external device has been connected to the output device; in response to the input device receiving the connection notification message, a block device client is started on the input device to map the target network block device to a target local block device of the input device, wherein the target host connected to the input device allows the external device to be regarded as a target local block device for data transmission, thereby achieving the purpose of simplifying the process of remotely controlling external devices, and realizing the technical effect of improving the convenience and operating efficiency of remotely controlling external devices, thereby solving the technical problem that the operating process is too complicated and the operating efficiency is low when performing transparent transmission operations on external devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 is a hardware structure block diagram of a mobile terminal according to a data transmission method of an embodiment of the present application;
[0017] Figure 2 is a flow chart of a data transmission method according to an embodiment of the present application;
[0018] Figure 3 is a flow chart of a data transmission method according to an embodiment of the present application;
[0019] Figure 4 is a flowchart of another data transmission method according to an embodiment of the present application;
[0020] Figure 5 is a flowchart of another data transmission method according to an embodiment of the present application;
[0021] Figure 6 is a flowchart of another data transmission method according to an embodiment of the present application;
[0022] Figure 7 It is a structural block diagram of a data transmission device according to an embodiment of the present application. DETAILED DESCRIPTION
[0023] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0024] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0025] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 1 is a hardware structure block diagram of a mobile terminal of a data transmission method according to an embodiment of the present application. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and a terminal device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0026] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the data transmission method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0027] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0028] Optionally, in this embodiment, the above data transmission method may also be implemented by a server, or implemented by the terminal device and the server together.
[0029] The above is only an example and is not specifically limited in this embodiment.
[0030] Optionally, as an optional implementation, Figure 2 is a flow chart of a data transmission method according to an embodiment of the present application. Figure 2 As shown, the above data transmission method includes:
[0031] S202, when the external device is connected to the output device, starting the block device server on the output device to set the external device as a target network block device;
[0032] Optionally, in this embodiment, the above-mentioned external devices may include but are not limited to universal serial bus devices, storage devices, printers, keyboards, mice, cameras, etc., the above-mentioned output devices may include but are not limited to remote office equipment, etc., and the above-mentioned block device server may allow remote clients to access and operate block devices through the network, for example, an NBD Server based on the NBD (Network Block Device) protocol, that is, a server-side program that provides a network block device, wherein NBD is a protocol for transmitting block device data on a computer network, and block devices may include but are not limited to hard disks, partitions or mirror files, etc., and control of the remote system can be achieved in the above-mentioned target network block device, including but not limited to logging into the remote system, managing files stored on the remote system, etc.
[0033] Exemplarily, the output device is a remote office box, and the external device can be a U disk device inserted into the remote office boot box, which can achieve the purpose of setting the U disk device as the target network block device. That is, the output device can perform reading and writing operations on the U disk device, which is convenient for accessing and managing data stored on the external device on the network, and controlling and managing the external device by operating the target network block device.
[0034] Among them, cloud technology refers to a hosting technology that unifies hardware, software, network and other resources within a wide area network or local area network to achieve data calculation, storage, processing and sharing.
[0035] Cloud computing refers to the delivery and use model of IT infrastructure, which means obtaining required resources through the network in an on-demand and easily scalable manner; in a broad sense, cloud computing refers to the delivery and use model of services, which means obtaining required services through the network in an on-demand and easily scalable manner. This service can be IT and software, Internet-related, or other services. Cloud computing is the product of the development and integration of traditional computer and network technologies such as grid computing, distributed computing, parallel computing, utility computing, network storage technologies, virtualization, and load balancing.
[0036] With the development of the Internet, real-time data streams, and the diversification of connected devices, as well as the demand for search services, social networks, mobile commerce, and open collaboration, cloud computing has developed rapidly. Different from the previous parallel distributed computing, the emergence of cloud computing will promote revolutionary changes in the entire Internet model and enterprise management model from a conceptual perspective.
[0037] Cloud security refers to the general term for security software, hardware, users, organizations, and security cloud platforms based on cloud computing business model applications. Cloud security integrates emerging technologies and concepts such as parallel processing, grid computing, and unknown virus behavior judgment. Through a large number of networked clients, it monitors abnormal software behavior in the network, obtains the latest information on Trojans and malicious programs on the Internet, and sends it to the server for automatic analysis and processing, and then distributes virus and Trojan solutions to each client.
[0038] The main research directions of cloud security include: 1. Cloud computing security, which mainly studies how to ensure the security of the cloud itself and various applications on the cloud, including cloud computer system security, secure storage and isolation of user data, user access authentication, information transmission security, network attack protection, compliance auditing, etc.; 2. Cloudification of security infrastructure, which mainly studies how to use cloud computing to build and integrate security infrastructure resources and optimize security protection mechanisms, including building a large-scale security event, information collection and processing platform through cloud computing technology, realizing the collection and correlation analysis of massive information, and improving the control ability of security events and risk control capabilities of the entire network; 3. Cloud security services, which mainly studies various security services provided to users based on cloud computing platforms, such as antivirus services.
[0039] S204, sending a connection notification message to the input device on the output device, wherein the connection notification message is used to indicate that the external device has been connected to the output device;
[0040] Optionally, in this embodiment, the input-end device may include but is not limited to remote office equipment, etc. The input-end device may be informed through the connection notification message that the output-end device is connected to an external device.
[0041] Specifically, the above connection notification message can be implemented through threads. For example, in a Linux system, assuming that the external device is a USB flash drive, the output device sends a startup USB flash drive notification service thread based on the netlink mechanism, and sends the above connection notification message to the input device through the USB flash drive notification service thread.
[0042] Among them, the netlink mechanism allows user space processes and the kernel to communicate and exchange data, which can be achieved through the socket interface. User space processes can communicate with the kernel by creating a netlink socket. The Linux kernel also has a special netlink socket for processing requests and messages from user space. User space processes can send requests to the Linux kernel and receive notifications and information from the Linux kernel. The netlink communication protocol defines a set of message formats and operation codes to describe different types of communication content and actions. User space processes can implement different functions by sending different types of messages, such as configuring network devices, querying network status, and managing routing tables. The netlink mechanism provides a flexible and efficient communication method between user space processes and the kernel, which can meet various communication needs. It is widely used in network management, security monitoring, system configuration, etc. in the Linux system. The Linux kernel is the core part of the Linux operating system, responsible for managing the computer's hardware resources and providing basic system services. The Linux kernel contains the basic functions of the operating system, including process management, memory management, file system, device driver, etc.
[0043] For example, Figure 3 is a flow chart of a data transmission method according to an embodiment of the present application, such as Figure 3 As shown, it includes: an input end device 306 , an output end device 304 , and an external device 302 .
[0044] S206, in response to the input device receiving the connection notification message, starting a block device client on the input device to map the target network block device to a target local block device of the input device, wherein the target host connected to the input device allows the external device to be regarded as a target local block device for data transmission.
[0045] Optionally, in an embodiment of the present application, the above-mentioned block device client can be understood as being able to connect to the above-mentioned block device server, access and operate the remote block device through the network, just like accessing a local block device. For example, based on the NBD protocol, the above-mentioned block device client can be an NBD client, that is, a client program connected to the NBD server, which can map the remote block device to a local block device, and can read, write and perform other operations on it to achieve access and management of remote storage, as well as sharing of block device data between multiple computers. The above-mentioned target local block device may include but is not limited to a hard disk, a partition or an image file, etc.
[0046] For example, Figure 4 It is a flow chart of another data transmission method according to an embodiment of the present application. Taking the remote office scenario as an example, the above-mentioned input-end device and output-end device are both remote office boxes. The input-end device and the output-end device can be deployed in different locations. For example, the input-end device is deployed at the staff's home, and the output-end device is deployed in the company, at the staff's workstation. The staff can realize remote office at home through the input-end device and the output-end device to achieve functions such as remote access to the company's internal server. Among them, a U disk is inserted into the remote office box A (output device). An output device can establish connections with multiple external devices. The U disk represents the above-mentioned external device. The remote office box A can start the block device service. The remote office box A sends a connection notification message to the remote office box B (input device). At this time, the remote office box B can start the block device client to connect to the block device server started by the remote office box A. Then, the operation of the external device is realized through the target host connected to the remote office box B, which may include but is not limited to U disk partitioning, U disk formatting and other operations, such as Figure 4 The specific steps are as follows:
[0047] S402, the output device starts the USB notification service thread and waits for the input device to connect;
[0048] S404, the output device is plugged into an external device;
[0049] S406, the output device starts the block device service, for example, based on the netlink mechanism, using the following command to start: nbd-server port / dev / sdax, where x represents the partition of the USB flash drive;
[0050] S408, the output device sends a connection notification message to the input device, and the input device starts the block device client, for example, based on the netlink mechanism, using the following command to start: nbd-client port / dev / nbdx, where x represents the specific target path, and the value of x can be any character in [0,16], which can be flexibly set through code.
[0051] Through the embodiments of the present application, when an external device is connected to an output device, a block device server is started on the output device to set the external device as a target network block device; a connection notification message is sent to the input device on the output device, wherein the connection notification message is used to indicate that the external device has been connected to the output device; in response to the input device receiving the connection notification message, a block device client is started on the input device to map the target network block device to a target local block device of the input device, wherein the target host connected to the input device allows the external device to be regarded as a target local block device for data transmission, thereby achieving the purpose of simplifying the process of remotely controlling the external device, and realizing the technical effect of improving the convenience and operating efficiency of remotely controlling the external device, thereby solving the technical problem that the operating process is too complicated and the operating efficiency is low when performing remote operation on the external device.
[0052] As an optional solution, the above-mentioned sending of a connection notification message from the above-mentioned output-end device to the input-end device includes: starting a notification service thread on the above-mentioned output-end device, wherein the above-mentioned notification service thread is used to send the above-mentioned connection notification message; when the above-mentioned output-end device has established a connection with the above-mentioned input-end device and the above-mentioned external device is connected to the above-mentioned output-end device, sending the connection notification message through the above-mentioned notification service thread.
[0053] Optionally, in an embodiment of the present application, the above-mentioned notification service thread can be used for the transmission of data messages between output end devices. For example, the output end device informs the input end device through the notification service thread, the output end device establishes a connection with the external device, the output end device disconnects the external device, etc.
[0054] In an exemplary embodiment, Figure 5 is a schematic diagram of a network architecture of a data transmission method according to an embodiment of the present application, such as Figure 5As shown, taking the application scenario of remote office as an example, the input device 502 can realize the communication request between the output device 506 and the input device 502 by connecting to the notification service thread 504 initiated by the operating system of the output device 506. At this time, the output device has established a connection with the external device, that is, the notification service thread 504 can send a connection notification message 508 to the input device, indicating that the output device is connected to the external device and can access the resources stored in the external device.
[0055] Through the embodiment of the present application, a notification service thread is started on the above-mentioned output-end device, wherein the above-mentioned notification service thread is used to send the above-mentioned connection notification message. When the above-mentioned output-end device has established a connection with the above-mentioned input-end device, and the above-mentioned external device is connected to the above-mentioned output-end device, the connection notification message is sent through the above-mentioned notification service thread, thereby achieving the purpose of quickly establishing a communication connection between the input-end device and the output-end device, and further achieving the technical effect of real-time monitoring of the communication and connection status between devices.
[0056] As an optional solution, when the output device has established a connection with the input device and the external device is connected to the output device, before sending a connection notification message through the notification service thread, the method further includes: when the output device has started the notification service thread, controlling the input device to start a notification receiving thread; establishing a connection between the output device and the input device through the notification receiving thread, and generating a target path on the input device, wherein the target path represents a path set for the target local block device.
[0057] Optionally, in an embodiment of the present application, the above-mentioned input device can obtain communication messages from the output device by notifying the receiving thread, which may include but is not limited to establishing a connection between the output device and the external device, disconnecting the connection between the output device and the external device, etc. The above-mentioned target path can be understood as a path used to deploy the above-mentioned target local block device.
[0058] Specifically, taking the external device as a U disk as an example, a U disk notification service thread is started on the output device. At this time, the U disk notification service thread on the output device (that is, the above notification service thread) is used to realize the connection between the output device and the input device. After the connection is successfully established, the output device can send a connection notification message to the input device through the U disk notification service thread, indicating that the output device is inserted with a U disk, and the input device receives the connection notification message through the U disk notification receiving thread (the above notification receiving thread), and learns that the output device is inserted with a U disk, wherein the U disk notification receiving thread can be understood as a thread for receiving U disk insertion and removal events, and the U disk notification service thread can be understood as a thread for processing U disk insertion and removal events.
[0059] Exemplarily, the target path may include but is not limited to setting one or more specified paths as the above-mentioned target path through commands provided by the operating system. For example, taking the Linux system as an example, the above-mentioned target path may be / dev / nbdx, where x represents any character in [0,16]. For example, / dev / nbd0, / dev / nbd6, / dev / nbd16, indicating that there are 17 paths, and / dev / nbd0 can be used as the target path, and / dev / nbd5 can also be used as the target path.
[0060] Through the embodiment of the present application, when the output-end device has started the notification service thread, the input-end device is controlled to start the notification receiving thread; a connection between the output-end device and the input-end device is established through the notification receiving thread, and a target path is generated on the input-end device, thereby realizing the generation of the target path, and further establishing a communication connection between the output-end device and the input-end device.
[0061] As an optional solution, when the external device is connected to the output device, the block device server is started on the output device to set the external device as the target network block device, including: when the external device is connected to the output device, the block device server is started on the output device; a target port is set on the output device, wherein the target port corresponds to the block device server; and the external device is set as the target network block device.
[0062] Optionally, in an embodiment of the present application, the block device server can provide block-level data storage services for the output device, which is used to manage and store a large number of data blocks, and provide the functions of reading and writing data as needed. The target port can be flexibly set, and the present application does not limit it. The target port is set by the block device server.
[0063] Furthermore, after the output device establishes a connection with the external device, the external device can be set as a target network block device, that is, the external device can be accessed through a host connected to the output device to achieve management and control of the external device.
[0064] As an optional solution, in response to the input-end device receiving the connection notification message, starting a block device client on the input-end device to map the target network block device to the target local block device of the input-end device, including: in response to the input-end device receiving the connection notification message, starting the block device client on the input-end device; setting the target port and the target network address on the input-end device, wherein the target port corresponds to the target network address; mapping the target network block device to the target local block device of the input-end device, wherein the target host transmits data with the external device through the target port and the target network address.
[0065] Optionally, in an embodiment of the present application, the above-mentioned block device client can be understood as a client device connected to a block device (such as a hard disk, a solid-state drive, etc.). The client device may include but is not limited to a computer, a server, a storage device, etc., and reads and writes data by communicating with the block device. The block device client can interact with the block device through a file system or a direct block device access method, and send read and write requests to the block device to access the data stored on the block device. That is, the above-mentioned target port and target network address can be determined by the block device client, that is, the input-end device can specify the port number and network address of the block device server to be connected according to the block device client, and further, the operation of the above-mentioned target network block device is implemented according to the port number and the network address, that is, the resources stored in the external device are managed.
[0066] It should be noted that the above-mentioned target network address can be transmitted to the input-end device in advance by the business layer of the application system associated with the above-mentioned output-end device through a thread, and the above-mentioned target port is set by the block device server. That is, before the output-end device starts the block device server, the input-end device can include but is not limited to determining the target network address through a communication thread between the input-end device and the output-end device.
[0067] In an exemplary embodiment, mapping the target network block device to the target local block device may be achieved by including but not limited to the following steps:
[0068] S1, the block device client determines the target network address and target port of the target network block device;
[0069] S2, on the input device, may include but is not limited to using a command line or a graphical interface tool to open a storage device mapping management tool;
[0070] S3, in the Storage Device Mapping Management Tool, select Add New Storage Device Mapping;
[0071] S4, input the target network address and target port of the target network block device, login account, login password and other information in the storage device mapping management tool;
[0072] S5, saving the storage device mapping configuration, confirming the setting of the input device for mapping the target network block device;
[0073] S6, waiting for the storage device mapping management tool to complete the mapping, at which point the target network block device will be mapped to the target local block device of the input device;
[0074] S7, test whether the mapping is successful. You can check on the input device whether the newly mapped storage device can be accessed normally.
[0075] Among them, the storage device mapping management tool is a software tool used to manage and configure the mapping relationship of storage devices in a computer system. It is usually used to manage the mapping relationship of hard disks, solid-state drives, optical disks, network storage and other storage devices so that the computer system can correctly access and use these storage devices. The storage device mapping management tool may include but is not limited to providing the following functions:
[0076] S1, creating and deleting storage device mapping relationships: Users can use these tools to create new storage device mapping relationships or delete mapping relationships that are no longer needed;
[0077] S2, modify the storage device mapping relationship: the user can modify the storage device mapping relationship, such as changing the device name, path or other attributes;
[0078] S3, monitor the status of storage devices: These tools usually provide monitoring functions, which can display the status information of storage devices, such as usage, health status, error information, etc.;
[0079] S4, automated configuration: automatically configures the mapping relationship of storage devices according to user needs.
[0080] Specifically, the input device can load the network block device kernel module by entering a command in the command line to realize the addition and use of the block device on the input device. After successful loading, the block device client can be started. The block device client can connect to the block device server of the specified port and map the target network block device provided by the block device server to the target path, so as to achieve the purpose of accessing and operating the target network block device through the network.
[0081] In an exemplary embodiment, taking remote office as an example, assuming that the operating system is a Linux system, the input device can enter "insmod nbd.ko" in the command line to load the network block device kernel module to achieve the addition and use of block devices on the input device. The above-mentioned target local block device can be understood as one or more block devices in the block device on the input device. After successful loading, the command "nbd-client" can be used to connect to the remote NBD (network block device) server, and the command "mount" can be used to mount the target local block device to achieve access and use of external devices. In this embodiment of the present application, the block device client can be started by entering the command "nbd-client port / dev / sdax", where "port" represents the port number of the block device server (the above-mentioned target port), and " / dev / sdax" refers to the local location where the target network block device will be mapped (the above-mentioned target path), and the x here can be used to represent the partition of the external device.
[0082] For example, Figure 6 is a flow chart of another data transmission method according to an embodiment of the present application, such as Figure 6 As shown, the external device 602 is a USB flash drive. Then, when the USB flash drive is inserted into the output device 604, the output device 604 maps the USB flash drive to the above-mentioned target network block device 604. When the target network block device 604 includes two partitions, the target network block device 604 will be mapped to a target local block device 608 through the block device server on the output device and the block device client on the input device 606. The target local block device 608 is located under the above-mentioned target path. At this time, the target path shows that there are two partition paths, namely " / dev / sda0" and " / dev / sda1". Similarly, assuming that the target network block device has only one partition, the target path will be expressed as " / dev / sda0".
[0083] Furthermore, after mapping the above-mentioned target network block device as the target local block device of the input device, the relevant driver of the input device can also be loaded to simulate the target local block device into a USB flash drive to realize the USB flash drive function, which can include but is not limited to installing the corresponding driver in the operating system of the input device to identify and use the target local block device. After the driver is installed, the target local block device can be connected to the host, and the target local block device can be accessed and operated through the file manager or command line interface of the operating system.
[0084] Similarly, taking the Linux system as an operating system as an example, based on the NBD protocol, the target block device server can be an NBD server, and the target block device client can be an NBD client. Assume that the U disk (the above-mentioned external device) connected to the output device is mapped to / dev / nbd5 on the input device, and then the gadget driver (g_mass_storage.ko) of the input device is loaded, / dev / nbd5 is simulated into a U disk, and then connected to the host through a USB cable, it can be recognized by the host as a U disk and perform all operations of the U disk. Among them, the gadget driver is a driver program used to support the universal serial bus device simulation function in the Linux system, which is realized by implementing the USB gadget framework, allowing the Linux host device to simulate a variety of different types of universal serial bus devices, so as to expand the connectivity and functionality of the Linux host device, USB The gadget framework is a software framework for implementing USB device functions in embedded systems. It provides a set of interfaces and tools for creating various universal serial bus devices in embedded systems, including but not limited to storage devices, network devices, audio devices, etc. It provides the function of universal serial bus device simulation in the Linux kernel to convert the embedded system into a universal serial bus device so that it can communicate with other host devices.
[0085] That is, through the embodiment of the present application, the g_mass_storage driver that comes with the Linux system can be used to realize the function of simulating the target local block device into a USB flash drive, without the need to develop a windows driver again as proposed in the related art to simulate the target local block device into a USB flash drive.
[0086] Through the embodiments of the present application, in response to the input-end device receiving the connection notification message, the block device client is started on the input-end device; the target port and the target network address are set on the input-end device; the target network block device is mapped to the target local block device of the input-end device to realize the data transmission function between the input-end device and the external device, thereby realizing remote management and control of the external device and improving operation efficiency.
[0087] As an optional solution, when the external device is connected to the output device, before starting the block device server on the output device to set the external device as the target network block device, the method further includes: starting hot plug detection, wherein the hot plug detection is used to identify the external device, and before the hot plug detection is started, automatically enumerating the external devices connected to the output device in advance; and updating the connection status of the external device when the insertion and removal of the external device is detected.
[0088] Optionally, in an embodiment of the present application, the hot-plug detection can be used to scan the external device, that is, the output device can know with which external device a connection is established and with which external device data can be transmitted through hot-plug detection. Taking the Linux system as an example, hot-plug detection can be implemented by monitoring netlink messages to achieve real-time monitoring and processing of state changes of the output device. Hot-plug detection can be implemented in the following manner, and specific implementation steps may include but are not limited to:
[0089] S1, create a netlink socket: use the socket function to create a netlink socket and specify the protocol family as AF_NETLINK;
[0090] S2, bind socket: use the bind function to bind the netlink socket to the network address and port specified by the output device;
[0091] S3, monitor messages: monitor netlink messages through the recvfrom function. When the status of a network device changes, the corresponding netlink message will be received;
[0092] S4, message parsing: parse the received netlink message, obtain the device status change information, and perform corresponding processing and notification;
[0093] S5, processing status change: performing corresponding processing operations according to the received device status change information, such as reconfiguring network devices, notifying related applications, etc.
[0094] Among them, netlink message is a mechanism used for inter-process communication in the Linux kernel, which is used to transmit network-related information and configuration. The netlink message consists of a header and a payload. The header contains information such as the message type, flag, and sequence number, and the payload contains specific business function implementation data. Netlink messages are usually used to configure network devices, monitor network status, and transmit routing information.
[0095] Furthermore, before performing hot-plug detection, the external device connected to the above-mentioned output device can be automatically identified. In other words, before the output device performs hot-plug detection, the connection status of the external device of the output device can be detected first. At this time, if the output device and the external device have established a connection, after the above-mentioned pre-enumeration, the detailed configuration information of the external device can be obtained, including but not limited to model, manufacturer, size, weight, interface type, supported operating system, driver version, power consumption, etc.
[0096] Specifically, when the output device detects that an external device is plugged in or unplugged, it will immediately update the connection status of the external device. For example, when an external device is plugged in to the output device, the output device will automatically identify and update the connection status of the external device to "connected", and when the external device is unplugged, the system will update the connection status of the external device to "disconnected". Furthermore, the connection status of multiple external devices can be obtained through hot plug detection.
[0097] Through the embodiments of the present application, the above-mentioned external device is identified by starting hot plug detection. Before the above-mentioned hot plug detection is started, the external devices connected to the above-mentioned output end device are automatically enumerated in advance; when the insertion and removal of the above-mentioned external device are detected, the connection status of the above-mentioned external device is updated to achieve the purpose of timely obtaining the connection status of the external device. When the connection status of the external device is determined, the mapping operation of the external device is implemented on the output end device, thereby facilitating the re-mapping of the target network block device mapped by the external device into the target local block device on the input end device.
[0098] As an optional solution, the method further includes: in a case where the external device cancels the connection with the output device, sending a disconnection notification message to the input device on the output device, wherein the disconnection notification message is used to indicate that the external device has disconnected from the output device; in response to the input device receiving the disconnection notification message, exiting the block device client on the input device to cancel mapping the target network block device to the target local block device of the input device.
[0099] Optionally, in an embodiment of the present application, the above-mentioned disconnection notification message can be understood as that the connection between the above-mentioned external device and the above-mentioned output end device is terminated, and data communication cannot be performed. In other words, the output end device will not be able to recognize the external device. The output end device can transmit the disconnection notification message to the input end device through the notification service thread, and the input end device can obtain the disconnection notification message through the notification receiving thread.
[0100] Furthermore, after the input device receives the disconnect notification message, it can exit the block device client. At this time, the target local block device will no longer exist in the input device, that is, the target local block device has been successfully disconnected and exited, and the input device no longer uses the target local block device.
[0101] Through the embodiments of the present application, when the external device cancels the connection with the above-mentioned output-end device, a disconnection notification message is sent from the above-mentioned output-end device to the input-end device. In response to the above-mentioned input-end device receiving the above-mentioned disconnection notification message, the above-mentioned block device client is exited on the above-mentioned input-end device to cancel the mapping of the above-mentioned target network block device to the above-mentioned target local block device of the above-mentioned input-end device, so as to achieve the technical effect of remotely and automatically managing the external device, thereby achieving the purpose of improving the efficiency of data communication between the external device and the input-end device.
[0102] The above is only an example, and this application does not make any specific limitation.
[0103] Obviously, the embodiments described above are only part of the embodiments of the present application, rather than all the embodiments.
[0104] The present application is described in detail below with reference to specific embodiments:
[0105] In an exemplary embodiment, it can be applied to a KVM system (a keyboard, video and mouse system, a device for managing multiple computers), wherein the KVM system may include but is not limited to an output device and an input device, the output device is connected to a USB flash drive (the above-mentioned external device), and the input device is connected to a host via a universal serial bus. When a USB flash drive is inserted into the output device, the output device identifies the USB flash drive block device (the above-mentioned target network block device), the output device and the input device establish a USB flash drive block data read and write channel, and the USB flash drive block device of the output device is mapped to the local block device of the input device, the input device simulates the local block device into a USB flash drive and connects to the host via a universal serial bus, and uses a block device to network function based on NBD (network block device) to encapsulate the read and write operations of the block device into packets for transmission, and transmit the data of the block device through the network, so that the block device can be shared between different computers, and the specific implementation steps may include but are not limited to:
[0106] S1, the output device automatically enumerates the USB flash drive based on the universal serial bus controller driver of the Linux system, and sends the USB flash drive insertion message to the upper-layer application through the netlink mechanism. The application layer starts the netlink hot plug detection to detect the insertion and removal of the USB flash drive. Before starting the netlink, it is necessary to manually scan the universal serial bus device once to prevent the USB flash drive from being inserted before the netlink is started, resulting in the loss of the netlink message and the failure to identify the USB flash drive;
[0107] S2, the output device starts the U disk notification service thread again, waiting for the input device to connect. When the U disk is detected to be plugged in and out, the U disk notification service thread can send the U disk plug-in message to the block device client, which plays a role similar to hot plugging;
[0108] S3, the input device starts the U disk notification receiving thread, tries to connect to the output device based on the U disk notification service thread, and if the connection is successful, waits to receive the U disk plug-in message, otherwise an alarm is issued;
[0109] S4, the input device loads the nbd.ko driver and generates the target path / dev / nbdx locally. Here, x is any character in [0,16]. The target path can be used to map the remote block device.
[0110] S5, a USB flash drive is inserted into the output device, and netlink starts the NBD server (the block device server mentioned above) after receiving the message;
[0111] S6, the output device starts the NBD server, specifies the target port of the NBD server, and uses the / dev / sdax device corresponding to the USB flash drive, where x is used to represent the partition of the USB flash drive, as the device mapped by NBD, that is, the target network block device mentioned above;
[0112] S7, the output device sends a USB flash drive insertion message to the input device through the USB flash drive notification service thread;
[0113] S8, after receiving the USB flash drive insertion message, the input device starts the NBD client (the above-mentioned block device client), specifies the target network address and target port of the NBD server to be connected, and maps the USB flash drive of the output device to the local / dev / nbdx, that is, the target local block device. After the mapping is completed, operating the / dev / nbdx of the input device is just like directly operating the / dev / sdax of the output device, which can support operations such as USB flash drive partitioning and formatting;
[0114] S9, the input device can also load the gadget driver g_mass_storage.ko of the Linux system, simulate / dev / nbdx into a USB flash drive, and then connect it to the host through the universal serial bus. It is recognized as a USB flash drive by the host and can perform all operations of the USB flash drive;
[0115] S10, the U disk of the output device is unplugged. After receiving the message, the netlink of the output device sends the U disk unplugging message to the input device through the U disk notification service thread. After receiving the U disk unplugging message, the input device uninstalls the g_mass_storage driver and exits the NBD client.
[0116] It should be noted that, since the KVM system has an input device, it can be simulated into a U disk through the Linux g_mass_storage driver, without the need for Windows driver development. The entire U disk transparent transmission establishment process only uses the Linux system's own netlink mechanism and the open source independent software NBD. There is no need to develop a universal serial bus to network protocol. NBD is used to complete the conversion between the universal serial bus and network data. Only a small amount of user-state development is needed to realize the U disk transparent transmission function, which simplifies the operation process of U disk transparent transmission and ensures the confidentiality of the data transmission process.
[0117] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a front-end device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.
[0118] According to another aspect of the embodiments of the present application, a system access device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0119] Figure 7 is a structural block diagram of a data transmission device according to an embodiment of the present application, such as Figure 7 As shown, the device comprises:
[0120] The starting module 702 starts a block device server on the output end device to set the external device as a target network block device when the external device is connected to the output end device;
[0121] Notification module 704, sending a connection notification message to the input device on the output device, wherein the connection notification message is used to indicate that the external device has been connected to the output device;
[0122] The mapping module 706 starts a block device client on the input device in response to the input device receiving the connection notification message to map the target network block device to a target local block device of the input device, wherein the target host connected to the input device allows the external device to be regarded as the target local block device for data transmission.
[0123] As an optional solution, the above-mentioned device is used to send a connection notification message to the input-end device on the above-mentioned output-end device in the following manner: starting a notification service thread on the above-mentioned output-end device, wherein the above-mentioned notification service thread is used to send the above-mentioned connection notification message; when the above-mentioned output-end device has established a connection with the above-mentioned input-end device and the above-mentioned external device is connected to the above-mentioned output-end device, sending the connection notification message through the above-mentioned notification service thread.
[0124] As an optional solution, the above-mentioned device is also used for: when the above-mentioned output-end device has established a connection with the above-mentioned input-end device and the above-mentioned external device is connected to the above-mentioned output-end device, before sending a connection notification message through the above-mentioned notification service thread, when the above-mentioned output-end device has started the above-mentioned notification service thread, controlling the above-mentioned input-end device to start a notification receiving thread; establishing a connection between the above-mentioned output-end device and the above-mentioned input-end device through the above-mentioned notification receiving thread, and generating a target path on the above-mentioned input-end device, wherein the above-mentioned target path represents a path set for the above-mentioned target local block device.
[0125] As an optional solution, the above-mentioned device is used to start a block device server on the output-end device when the external device is connected to the output-end device in the following manner to set the above-mentioned external device as the target network block device: when the above-mentioned external device is connected to the above-mentioned output-end device, start the block device server on the above-mentioned output-end device; set a target port on the above-mentioned output-end device, wherein the above-mentioned target port corresponds to the above-mentioned block device server; and set the above-mentioned external device as the above-mentioned target network block device.
[0126] As an optional solution, the above-mentioned device is used to start the block device client on the above-mentioned input-end device in response to the above-mentioned input-end device receiving the above-mentioned connection notification message, so as to map the above-mentioned target network block device to the target local block device of the above-mentioned input-end device in the following manner: in response to the above-mentioned input-end device receiving the above-mentioned connection notification message, start the above-mentioned block device client on the above-mentioned input-end device; set the above-mentioned target port and target network address on the above-mentioned input-end device, wherein the above-mentioned target port corresponds to the above-mentioned target network address; map the above-mentioned target network block device to the target local block device of the above-mentioned input-end device, wherein the above-mentioned target host transmits data with the above-mentioned external device through the above-mentioned target port and the above-mentioned target network address.
[0127] As an optional solution, the above-mentioned device is also used to: when an external device is connected to an output device, start a block device server on the above-mentioned output device to start hot plug detection before setting the above-mentioned external device as a target network block device, wherein the above-mentioned hot plug detection is used to identify the above-mentioned external device, and before the above-mentioned hot plug detection is started, automatically enumerate the external devices connected to the above-mentioned output device in advance; when the insertion and removal of the above-mentioned external device are detected, update the connection status of the above-mentioned external device.
[0128] As an optional solution, the above-mentioned device is also used for: when the external device cancels the connection with the above-mentioned output-end device, sending a disconnection notification message to the input-end device on the above-mentioned output-end device, wherein the above-mentioned disconnection notification message is used to indicate that the above-mentioned external device has been disconnected from the above-mentioned output-end device; in response to the above-mentioned input-end device receiving the above-mentioned disconnection notification message, exiting the above-mentioned block device client on the above-mentioned input-end device to cancel the mapping of the above-mentioned target network block device to the above-mentioned target local block device of the above-mentioned input-end device.
[0129] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0130] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0131] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0132] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0133] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0134] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0135] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0136] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0137] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A data transmission method, characterized in that: include: When an external device is connected to an output device, starting a block device server on the output device to set the external device as a target network block device; Sending a connection notification message to the input device on the output device, wherein the connection notification message is used to indicate that the external device has been connected to the output device; In response to the input device receiving the connection notification message, a block device client is started on the input device to map the target network block device to a target local block device of the input device, wherein a target host connected to the input device allows the external device to be regarded as the target local block device for data transmission.
2. The method according to claim 1, characterized in that The sending of a connection notification message from the output end device to the input end device comprises: Starting a notification service thread on the output terminal device, wherein the notification service thread is used to send the connection notification message; When the output device and the input device have established a connection, and the external device is connected to the output device, a connection notification message is sent through the notification service thread.
3. The method according to claim 2, characterized in that In the case where the output device has established a connection with the input device and the external device is connected to the output device, before sending a connection notification message through the notification service thread, the method further includes: When the output terminal device has started the notification service thread, controlling the input terminal device to start the notification receiving thread; A connection is established between the output-end device and the input-end device through the notification receiving thread, and a target path is generated on the input-end device, wherein the target path represents a path set for the target local block device.
4. The method according to claim 1, characterized in that: When the external device is connected to the output device, starting the block device server on the output device to set the external device as a target network block device includes: When the external device is connected to the output device, starting a block device server on the output device; Setting a target port on the output device, wherein the target port corresponds to the block device server; The external device is set as the target network block device.
5. The method according to claim 4, characterized in that In response to the input-end device receiving the connection notification message, starting a block device client on the input-end device to map the target network block device to a target local block device of the input-end device includes: In response to the input-end device receiving the connection notification message, starting the block device client on the input-end device; Setting the target port and the target network address on the input-end device, wherein the target port corresponds to the target network address; The target network block device is mapped to a target local block device of the input device, wherein the target host performs data transmission with the external device through the target port and the target network address.
6. The method according to claim 1, characterized in that In the case where the external device is connected to the output device, before starting the block device server on the output device to set the external device as the target network block device, the method further includes: Starting a hot-plug detection, wherein the hot-plug detection is used to identify the external device, and before the hot-plug detection is started, the external devices connected to the output device are automatically enumerated in advance; When the insertion and removal of the external device is detected, the connection status of the external device is updated.
7. The method according to claim 1, characterized in that The method further comprises: In the case that the external device cancels the connection with the output device, the output device sends a disconnection notification message to the input device, wherein the disconnection notification message is used to indicate that the external device has been disconnected from the output device; In response to the input-end device receiving the disconnection notification message, the block device client is exited on the input-end device to cancel mapping the target network block device as the target local block device of the input-end device.
8. A data transmission device, characterized in that: include: A startup module, used for starting a block device server on the output end device when the external device is connected to the output end device, so as to set the external device as a target network block device; A notification module, used for sending a connection notification message to the input device on the output device, wherein the connection notification message is used to indicate that the external device has been connected to the output device; A mapping module is used for starting a block device client on the input device in response to the input device receiving the connection notification message to map the target network block device to a target local block device of the input device, wherein a target host connected to the input device allows the external device to be regarded as the target local block device for data transmission.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 7 when executed by a processor.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method described in any one of claims 1 to 7 are implemented.
