Method and storage medium for automatic discovery of block devices and real-time replication of changed data

By loading a real-time block device data replication kernel module into the Linux kernel, dynamically detecting disk changes and intercepting I/O system calls, the problem of automatically discovering new disks and real-time replication in existing technologies is solved. This enables real-time data replication without interrupting read and write operations, improving business continuity and flexibility.

CN115617263BActive Publication Date: 2026-03-17SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211141151.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-20
Publication Date
2026-03-17
Estimated Expiration
2042-09-20

AI Technical Summary

Technical Problem

Existing distributed block device replication technologies lack a mechanism for automatically discovering newly added disks, resulting in business interruptions and long RPO times, and making it impossible to achieve real-time replication of system disks without interrupting read and write operations.

Method used

By loading block device data into the Linux kernel and copying the kernel module in real time, registering disk information and listening for events, dynamically detecting disk changes, using udev to query and schedule tasks to discover newly added or unloaded disks, enabling or stopping the real-time copying function, and intercepting I/O system calls through hook functions, real-time copying without interrupting read and write operations is achieved.

Benefits of technology

It enables the automatic discovery and real-time replication of newly added disk data without interrupting user services, reducing the intrusiveness of server operations and improving business continuity and flexibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115617263B_ABST
    Figure CN115617263B_ABST
Patent Text Reader

Abstract

The application discloses a method for automatically discovering block devices and copying changed data in real time and a storage medium, belongs to the technical field of cloud computing, and aims to solve the technical problem of how to realize automatic discovery of block devices and real-time copying of data of newly added disks, reduce the invasiveness to user servers, and increase the continuity of user services. The technical scheme is as follows: the method is to load a block device data real-time copying kernel module into a linux kernel, register block device information, poll and scan or actively trigger by listening to block device events to query newly mounted / dismounted disks, enable / disable the real-time copying function of the corresponding disks, and simultaneously, in the case of not interrupting read-write I / O, real-time copy the disks in use.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of cloud computing technology, specifically to a method and storage medium for the automatic discovery of block devices and the real-time replication of changing data. Background Technology

[0002] Distributed Block Device Replication (DRBD) is a software-based, shared-nothing, replicated storage solution. Its core functionality is implemented through a Linux kernel module, located at the bottom of the Linux I / O stack—below the file system and above the I / O scheduling layer. After loading the distributed block device real-time data replication module, it creates a virtual block device / dev / drbdX based on the specified block device / dev / sdc on the server.

[0003] If users intend to utilize the block-level replication capabilities of distributed block device (DRB) real-time data replication technology, they need to switch to reading and writing data from the ` / dev / drbdX` virtual block device (previously from the ` / dev / sdc` block device). Furthermore, the virtual block device created for each block device by the DRB module must exclusively occupy the original block device; that is, when using DRBD, each block device cannot be mounted to a file directory. This introduces two problems: First, partitions originally mounted to file directories need to be unmounted, then the virtual block device `drbdX` needs to be created, and finally ` / dev / drbdx` needs to be mounted to the original file directory. This process interrupts block device read / write operations and requires renaming the block device being read / written. The second problem is that the root partition is already mounted to the root directory ` / `, making it impossible to unmount the root directory, thus preventing real-time replication based on block devices from being performed on the system disk's root partition.

[0004] In addition, the existing version of the distributed block device data real-time replication technology lacks a mechanism to actively discover newly added disks, which makes it impossible to automatically replicate newly added disks in real time.

[0005] Traditional hard drive backup functions typically involve users manually creating backups or creating backups on a schedule. When data is corrupted and cannot be recovered due to natural disasters, data center failures, or disk hardware failures that damage servers or hard drives, hard drive backup data can be used to restore the data at the time of backup. However, the Recovery Point Objective (RPO) is long, and business continuity cannot be guaranteed, meaning the Recovery Time Objective (RTO) is also long.

[0006] Real-time data replication technology for block devices can meet the need for real-time replication of disk data to remote disks, solving the problem of long Recovery Point Objective (RPO) times. However, because real-time data replication technology requires exclusive access to the target block device, the target block device must first unmount its file system, which can lead to business interruptions and abnormal data read / write operations. Furthermore, the root file system of the system disk is already mounted to the root directory and cannot be unmounted without shutting down the server, thus preventing real-time data replication technology from being applied to the system disk.

[0007] Therefore, how to achieve automatic discovery of block devices and real-time replication of data from newly added disks, reduce the intrusion on user servers, and increase the continuity of user services are technical problems that urgently need to be solved. Summary of the Invention

[0008] The technical objective of this invention is to provide a method and storage medium for the automatic discovery of block devices and real-time replication of changed data, in order to solve the problem of how to achieve automatic discovery of block devices and real-time replication of data on newly added disks, reduce intrusion on user servers, and increase the continuity of user services.

[0009] The technical objective of this invention is achieved as follows: a method for automatically discovering and real-time copying changed data of block devices. This method involves loading the block device data real-time copying kernel module into the Linux kernel and registering the block device information. Then, it polls and scans or actively triggers by listening to block device events to query newly mounted / unmounted disks, and enables / disables the real-time copying function of the corresponding disk. At the same time, for disks that are in use, real-time copying is performed on the disks without interrupting read / write I / O.

[0010] As a preferred method, the specific details are as follows:

[0011] In the Linux kernel, block device data is loaded and copied in real time using modprobe or insmod.

[0012] Users register all disks on the server using the `register device` command. The block device data is copied in real time. The kernel module records information about all disks and starts a TCP listener for each disk.

[0013] When the block device data real-time replication kernel module detects a newly mounted / unmounted disk, it enables / stops the TCP service for the changed disk.

[0014] The udev loop query or disk addition / removal event triggering mechanism detects newly added or unloaded disks and starts / stops real-time replication;

[0015] By changing the Linux disk I / O-related system calls to the corresponding function call addresses, real-time copying of block device data can be achieved without interrupting read and write operations.

[0016] As a preferred option, after loading the block device data and copying it in real time into the kernel module, execute the following:

[0017] When a user executes the command "register device", the block device data real-time replication kernel module records all disk information in the current server to the disk_resource.json file in the specified directory, such as {"UUID":"xxx","size":100GB,"size":}; where disk information includes disk UUID, size, drive letter, serial number, manufacturer ID and product ID, and provider ID and product ID;

[0018] When the kernel module function 'up block device' is used to perform real-time data replication of the start block device, a TCP listening service is started for each disk on the local server to transmit disk change data;

[0019] By using scheduled tasks and the udev disk change monitoring mechanism, it can proactively detect and start / stop real-time disk replication;

[0020] After a three-way handshake, TCP clients on the local and remote disks establish a long connection and begin real-time data replication.

[0021] More preferably, when the block device data real-time copy kernel module is loaded, it calls udevadm monitor to monitor the addition and deletion of disks on the machine, and detects the mounting and unmounting of disks;

[0022] After the local server finishes processing, the remote server mounts a disk of the same size and starts a TCP client. The TCP client and server establish a TCP listener through a TCP three-way handshake and start real-time replication of disk data.

[0023] When a disk is detected to be unmounted, stop the TCP service for that device and record the disk's status as diskless in the disk_resource.json file.

[0024] More specifically, the methods for detecting disk mount and unmount are as follows:

[0025] ① In the real-time data replication kernel module for block devices, a scheduled task performs a check every 5 minutes, comparing the obtained disk information with the disk information in disk_resource.json:

[0026] If a new disk is added, the new disk information is recorded in the disk_resource.json file, the disk's metadata area is allocated, and the TCP listening service corresponding to the new disk is automatically started.

[0027] ② udev listens for disk add and remove events. When disk mounting and unmounting are detected, it automatically executes the probeDevice() function in the kernel module to copy block device data in real time, and the processing method is the same as ①.

[0028] Preferably, the block device data real-time replication kernel module changes the read-only attribute of the page table address where the virtual address is located to the read-write attribute, and modifies the disk I / O related system calls sys_read() and sys_write() to the I / O system call entry functions bd_read() and bd_write() specified by the block device data real-time replication kernel module. When the user executes read(fd,buffer,n_to_read) or write(fd,buffer,n_to_write) functions involving disk I / O, the system call is changed to call the function hook_device() specified by the block device data real-time replication kernel module.

[0029] Ideally, when using Linux kernel version 4.15.0, the specific details are as follows:

[0030] In the Linux I / O stack, each disk driver registers a make_request_fn() function for a specific device driver with the block layer in the Linux kernel. The make_request_fn() function is in the request_queue queue of each device.

[0031] When a write I / O request is executed to the make_request_fn() function registered by the block device data real-time copy kernel module, the bio is copied to the TCP send buffer and sent to the disk device on the other end. Then, the struct block_device*bi_bdev in struct bio is set to the actual disk partition. Subsequent I / O will continue to be executed along the original path and written to the target disk.

[0032] More preferably, the real-time copying of block device data in the Linux kernel using modprobe or insmod is performed as follows:

[0033] The user generates the .ko kernel file using `make && make install` and loads it into the Linux kernel using `modprobe` or `insmod`.

[0034] An electronic device, characterized in that it comprises: a memory and at least one processor;

[0035] The memory contains computer programs;

[0036] The at least one processor executes the computer program stored in the memory, causing the at least one processor to perform the method of automatic discovery of block devices and real-time copying of changed data as described above.

[0037] A computer-readable storage medium storing a computer program that can be executed by a processor to implement the method for automatic discovery of block devices and real-time replication of changed data as described above.

[0038] The method and storage medium for automatic discovery of block devices and real-time replication of changed data of the present invention have the following advantages:

[0039] (i) This invention can continuously detect and combine udev's capabilities to listen for disk addition and removal events. When a new disk is mounted or unmounted on the server, the replication function of the newly added disk is started or stopped in a timely manner. Compared with the original block device data real-time replication module technology, this invention reduces the need for users to manually enable and stop the replication function for new disks after mounting or unmounting disks on the server. It also avoids the risk of user misoperation and increases the flexibility and convenience of using this kernel module.

[0040] (ii) After the user disk creates a file system and mounts it to the mount point, the original block device data real-time copy kernel module needs to unmount the disk in order to create a virtual block device for it. The system disk cannot unmount the root file system yet. These operations will interrupt the disk I / O requests. The block device data real-time copy kernel module of the present invention intercepts I / O-related system calls through hook functions, which can achieve smooth switching of execution paths. After unloading the kernel module, the original I / O execution path is restored. It has low intrusiveness to the user server operating system and leaves no trace after unloading the kernel module, achieving the effect of hot-plugging.

[0041] (iii) This invention no longer creates a virtual block device to exclusively occupy the target block device. Users continue to read and write data to the original block storage, which reduces the complexity of using this invention and enables real-time collection of I / O data and replication to the remote block device without interrupting read and write services.

[0042] (iv) This invention provides a mechanism for dynamically detecting and discovering changes to server disks. After a new disk is added, the data on the new disk can be detected and copied in real time. Attached Figure Description

[0043] The invention will be further described below with reference to the accompanying drawings.

[0044] Appendix Figure 1 A diagram illustrating the automatic detection of disk mounting / unmounting and the start / stop of real-time copying functionality;

[0045] Appendix Figure 2 A diagram illustrating how disk I / O requests are copied in real time without interrupting business operations. Detailed Implementation

[0046] The method and storage medium for automatic discovery and real-time copying of changed data of the block device of the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.

[0047] Example 1:

[0048] As attached Figure 1 As shown, this embodiment provides a method for automatic discovery of block devices and real-time replication of changed data. This method involves loading the block device data real-time replication kernel module into the Linux kernel and registering the block device information. Then, it uses polling or active triggering by listening for block device events to query newly mounted / unmounted disks, and enables / disables the real-time replication function for the corresponding disk. Simultaneously, for disks currently in use, real-time replication is performed without interrupting read / write I / O. Specifically:

[0049] S1. Load block device data in the Linux kernel and copy it to the kernel module in real time using modprobe or insmod;

[0050] S2. Users register all disks on the server using the register device command. The block device data is copied in real time. The kernel module records the information of all disks and starts a TCP listener for each disk.

[0051] S3. When the block device data real-time replication kernel module detects a newly mounted / unmounted disk, enable / stop the TCP service for the changed disk;

[0052] S4. Discover newly added or unloaded disks and start / stop real-time replication by using udev loop query or disk addition / removal event triggering mechanism;

[0053] S5. Change the Linux disk I / O related system calls to the corresponding function call addresses to achieve real-time copying of block device data without interrupting read and write operations.

[0054] In this embodiment, after loading the block device data real-time copy kernel module, the following operations are performed:

[0055] (1) When the user executes the register device command, the block device data real-time copy kernel module records all disk information in the current server to the disk_resource.json file in the specified directory, such as {"UUID":"xxx","size":100GB,"size":}; where disk information includes disk UUID, size, drive letter, serial number, manufacturer ID and product ID number, as well as provider ID and product ID number;

[0056] (2) When the kernel module function 'up block device' is used to copy block device data in real time, a TCP listening service is started for each disk on the local server to transmit disk change data;

[0057] (3) Actively detect and start / stop real-time disk copying through scheduled tasks and udev disk change monitoring mechanism;

[0058] (4) After a three-way handshake, the TCP clients on the local disk and the remote disk establish a long connection and begin real-time data replication.

[0059] In this embodiment, when the block device data real-time copy kernel module is loaded, it calls udevadm monitor to monitor the addition and deletion of disks on the machine, and detects the mounting and unmounting of disks;

[0060] After the local server finishes processing, the remote server mounts a disk of the same size and starts a TCP client. The TCP client and server establish a TCP listener through a TCP three-way handshake and start real-time replication of disk data.

[0061] When a disk is detected to be unmounted, stop the TCP service for that device and record the disk's status as diskless in the disk_resource.json file.

[0062] In this embodiment, the specific methods for detecting disk mounting and unmounting are as follows:

[0063] ① In the real-time data replication kernel module for block devices, a scheduled task performs a check every 5 minutes, comparing the obtained disk information with the disk information in disk_resource.json:

[0064] If a new disk is added, the new disk information is recorded in the disk_resource.json file, the disk's metadata area is allocated, and the TCP listening service corresponding to the new disk is automatically started.

[0065] ② udev listens for disk add and remove events. When disk mounting and unmounting are detected, it automatically executes the probeDevice() function in the kernel module to copy block device data in real time, and the processing method is the same as ①.

[0066] As attached Figure 2 As shown in this embodiment, the block device data real-time replication kernel module changes the read-only attribute of the page table address where the virtual address is located to the read-write attribute, and modifies the disk I / O related system calls sys_read() and sys_write() to the I / O system call entry functions bd_read() and bd_write() specified by the block device data real-time replication kernel module. When the user executes read(fd,buffer,n_to_read) or write(fd,buffer,n_to_write) functions involving disk I / O, the system call is changed to call the function hook_device() specified by the block device data real-time replication kernel module.

[0067] In this embodiment, when the Linux kernel uses Linux kernel version 4.15.0, the specific details are as follows:

[0068] (1) In the Linux I / O stack, each disk driver will register a make_request_fn() function for a specific device driver in the block layer of the Linux kernel. The make_request_fn() function is in the request_queue queue of each device.

[0069] (2) When the write I / O request is executed to the make_request_fn() function registered by the block device data real-time copy kernel module, the bio is copied to the TCP send buffer and sent to the disk device on the other end. Then, the struct block_device*bi_bdev in struct bio is set to the actual disk partition. Subsequent I / O will continue to be executed according to the original path and written to the target disk.

[0070] In this embodiment, the kernel module for real-time copying of block device data in the Linux kernel via modprobe or insmod is specifically described as follows:

[0071] The user generates the .ko kernel file using `make && make install` and loads it into the Linux kernel using `modprobe`.

[0072] Example 2:

[0073] This embodiment also provides an electronic device, including: a memory and a processor;

[0074] The memory stores the instructions executed by the computer.

[0075] The processor executes computer execution instructions stored in the memory, causing the processor to perform the method for automatic discovery of block devices and real-time copying of changed data in any embodiment of the present invention.

[0076] The processor can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), off-the-shelf programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor can be a microprocessor or any conventional processor.

[0077] Memory is used to store computer programs and / or modules. The processor implements various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory, and by accessing data stored in the memory. Memory can mainly include a program storage area and a data storage area. The program storage area can store the operating system, at least one application program required for a function, etc.; the data storage area can store data created based on the use of the terminal, etc. In addition, memory can also include high-speed random access memory, and can also include non-volatile memory, such as hard disks, RAM, plug-in hard disks, smart memory cards (SMC), secure digital cards (SD cards), flash memory cards, at least one disk storage device, flash memory devices, or other volatile solid-state storage devices.

[0078] Example 3:

[0079] This embodiment also provides a computer-readable storage medium storing multiple instructions, which are loaded by a processor to cause the processor to execute the method for automatic discovery and real-time copying of changed data of block devices in any embodiment of the present invention. Specifically, a system or apparatus equipped with a storage medium may be provided, on which software program code implementing the functions of any of the above embodiments is stored, and the computer (or CPU or MPU) of the system or apparatus may read and execute the program code stored in the storage medium.

[0080] In this case, the program code read from the storage medium can itself implement the function of any of the above embodiments, and therefore the program code and the storage medium storing the program code constitute part of the present invention.

[0081] Storage media embodiments for providing program code include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RYM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, program code can be downloaded from a server computer via a communication network.

[0082] Furthermore, it should be clear that not only can the program code read by the computer be executed, but also the operating system or other components operating on the computer can be instructed based on the program code to perform some or all of the actual operations, thereby realizing the function of any of the embodiments described above.

[0083] Furthermore, it is understood that the program code read from the storage medium is written to the memory set in the expansion board inserted into the computer or to the memory set in the expansion unit connected to the computer. Then, based on the instructions of the program code, the CPU or other components installed on the expansion board or expansion unit execute some and all of the actual operations, thereby realizing the function of any of the embodiments described above.

[0084] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for automatically discovering and real-time copying changed data of block devices, characterized in that, The method is to load the block device data real-time replication kernel module into the linux kernel and register the block device information, then poll scan or trigger actively by listening to the block device event to query the newly mounted / unmounted disk, and then enable / disable the real-time replication function of the corresponding disk, and at the same time, for the disk in use, the real-time replication of the disk is carried out without interrupting the read / write I / O; Among them, the block device data real-time replication kernel module changes the read-write attribute of the page table address where the virtual address is located to read-write attribute, modifies the disk I / O related system calls sys_read() and sys_write() to the I / O system call entry function bd_read() and bd_write() specified by the block device data real-time replication kernel module, and when the user executes read(fd, buffer, n_to_read) or write(fd, buffer, n_to_write) involving disk I / O function, the system call is changed to call the specified function hook_device() of the block device data real-time replication kernel module.

2. The method for block device auto-discovery and real-time replication change data of claim 1, wherein, The method is as follows: Load the block device data real-time replication kernel module into the linux kernel through modprobe or insmod; Users register all disks on the server through the register device command, and the block device data real-time replication kernel module records the information of all disks and starts a tcp listener for each disk; When the block device data real-time replication kernel module identifies a newly mounted / unmounted disk, it enables / stops the tcp service of the changed disk; Discover new or unmounted disks and start / stop real-time replication through udev loop query or add / remove disk event triggering mechanism; Change the linux disk I / O related system call to the corresponding function call address to realize real-time replication of block device data without interrupting read / write business.

3. The method for block device auto-discovery and real-time replication change data of claim 1, wherein, After loading the block device data real-time replication kernel module, execute the following content: Users execute the register device command, and the block device data real-time replication kernel module records all disk information in the current server to the disk_resource.json file in the specified directory; wherein the disk information includes disk UUID, size, drive letter, serial number, manufacturer ID and product ID number, and provider ID and product ID number; When starting the block device data real-time replication kernel module function 'up block device', start a tcp listener service for each disk of the local server to transmit disk change data; Through the timing task and udev listening disk change mechanism, actively discover and start / stop the real-time replication of the disk; The tcp clients of the local disk and the remote disk establish a long connection and start real-time replication of data after three-way handshake.

4. The method for automatic discovery of block devices and real-time replication of changed data according to any of claims 1-3, characterized in that, The block device data real-time replication kernel module calls udevadm monitor to monitor the addition and deletion of disks on the machine and detect the mounting and unmounting of the disks when loaded; After the local server processing is completed, the remote server mounts a disk of the same size and starts a tcp client, and the tcp client and the server establish tcp monitoring through tcp three-way handshake to start real-time replication of disk data; When the disk is detected to be unmounted, the tcp service of the device is stopped, and the state of the disk in the disk_resource.json file is recorded as diskless.

5. The method for block device auto-discovery and real-time replication change data of claim 4, wherein, The detection of disk mounting and unmounting is specifically as follows: ①In the block device data real-time replication kernel module, a detection is performed every 5 minutes through a timing task, and the obtained disk information is compared with the disk information in the disk_resource.json file: If a new disk is added, the new disk information is recorded in the disk_resource.json file, the metadata area of the disk is allocated, and the tcp monitoring service corresponding to the new disk is automatically started; ②Udev listens to the add and remove events of the disk, and when the disk mounting and unmounting are detected, the function probeDevice() in the block device data real-time replication kernel module is automatically executed, and the processing manner is the same as ①.

6. The method for block device auto-discovery and real-time replication change data of claim 1, wherein, When the linux kernel uses the linux 4.15.0 kernel version, the following is specifically as follows: In the linux I / O stack, each kind of disk driver registers a make_request_fn() function for the device driver in the block layer of the linux kernel, and the make_request_fn() function is in the request_queue queue of each device; When the write I / O request executes to the make_request_fn() function registered by the block device data real-time replication kernel module, the bio is copied to the tcp send buffer buffer and sent to the disk device of the opposite end, and the struct block_device *bi_bdev in the struct bio is set to the actual disk partition, and the subsequent I / O continues to execute according to the original path and is written into the target disk.

7. The method for block device auto-discovery and real-time replication change data of claim 2, wherein, The block device data real-time replication kernel module is loaded into the linux kernel through modprobe or insmod as follows: The user generates a ko kernel file through make && make install, and loads it into the linux kernel through modprobe or insmod.

8. An electronic device, comprising: It includes: a memory and at least one processor; wherein the memory has stored thereon a computer program; the at least one processor executes the computer program stored in the memory, so that the at least one processor executes the method for automatically discovering a block device and replicating changed data in real time according to any one of claims 1 to 7.

9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program can be executed by the processor to implement the method for automatically discovering the block device and replicating the changed data in real time according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • System for synchronizing data of database

    CN103631903A

  • Drive letter drifting preventing and treating method and device

    CN103677650A