Block device operation method, device, equipment and machine-readable storage medium
By dividing block devices into reserved block devices and target block devices, the problem that block devices cannot be directly operated after being managed by the file system is solved, efficient operation and customized use of original block devices are realized, and operation efficiency and availability are improved. Operability.
Patent Information
- Application Number
- CN202111015819.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-31
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2041-08-31
AI Technical Summary
After the existing block device is managed by the file system, other applications cannot directly operate it, making it impossible to implement operations such as data migration and mirroring.
Divide the original block device into a reserved block device and a target block device, provide the target block device for use by the file system, and allow other applications to directly operate on the reserved block device, thereby realizing operations on the original block device.
It improves the operating efficiency of block devices, enables other applications to directly operate on original block devices without going through the file system, and enhances the operability and variability of block devices.
Smart Images

Figure CN113741816B
Abstract
Description
Technical Field
[0001] The present application relates to the field of storage technology, and in particular to a method, apparatus, device and machine-readable storage medium for operating a block device. Background Art
[0002] I / O (Input / Output) devices are usually divided into two categories: block devices (Block Device Driver) and character devices (Character Device Drive). Character devices provide continuous data streams, and applications can read data from character devices sequentially. For example, keyboards, serial ports, modems, etc. are all character devices. For block devices, applications can read data from block devices randomly, and applications can determine the location of data by themselves. For example, hard disks, floppy disks, CD-ROMs (Compact Disc Read-Only Memory), disks, and flash memory are all block devices.
[0003] Block devices can store data in blocks of fixed size (such as 512B). Data can only be read and written in multiples of blocks. Each block of a block device can be read and written independently of other blocks. In order to achieve independent access to each block, each block has a physical address, and the data in the block can be accessed through the physical address.
[0004] Normally, block devices are provided to file systems for use. Once a block device is used by a file system, all storage space of the block device is managed by the file system. The file system occupies all storage space of the block device. The read and write operations on the block device are completed based on the file system. Other applications cannot directly operate on the block device and can only operate on the block device through the file system. For example, when writing data, the data is sent to the file system, and the file system writes the data to the block device. When data needs to be read from the block device, the read command is sent to the file system, and the file system reads the data from the block device. Summary of the invention
[0005] The present application provides a method for operating a block device, the method comprising:
[0006] Reserving part of the storage space from all the storage spaces of the original block device as a reserved block device, and forming a target block device with the remaining storage space in the original block device except the reserved block device;
[0007] Providing mapping information corresponding to the storage space of the target block device to the first application, so that the first application operates the target block device based on the mapping information;
[0008] If an operation request sent by a second application is received, and the operation request includes target data and address information of a reserved block device, the target data is written to the reserved block device corresponding to the address information, so that the second application operates the original block device based on the target data in the reserved block device.
[0009] Exemplarily, reserving part of the storage space from all the storage spaces of the original block device as the reserved block device includes: obtaining a configured reservation mode and obtaining a target storage capacity of the storage space to be reserved; selecting a reserved position matching the reservation mode from all the storage spaces of the original block device; and reserving, at the reserved position, a storage space matching the target storage capacity as the reserved block device.
[0010] Exemplarily, the reservation mode is header reservation, or tail reservation, or head and tail reservation, or specified reservation, or segment reservation; if the reservation mode is header reservation, the reserved position is the starting position of the original block device; or, if the reservation mode is tail reservation, the reserved position is the ending position of the original block device; or, if the reservation mode is head and tail reservation, the reserved position is the starting position and the ending position of the original block device; or, if the reservation mode is specified reservation, the reserved position is the specified position of the original block device; or, if the reservation mode is segment reservation, the reserved position is multiple positions of the original block device, and the interval between two adjacent positions is the same.
[0011] Exemplarily, the mapping information includes a mapping relationship between a logical address of a storage space of a target block device and a physical address of a storage space of an original block device; the first application operates the target block device based on the mapping information, including: if data needs to be written to a storage space corresponding to a first logical address of the target block device, determining a first physical address corresponding to the first logical address based on the mapping relationship, and writing the data to a storage space corresponding to the first physical address of the original block device; and / or, if data needs to be read from a storage space corresponding to a second logical address of the target block device, determining a second physical address corresponding to the second logical address based on the mapping relationship, and reading data from a storage space corresponding to the second physical address of the original block device.
[0012] Exemplarily, the second application is a DRBD application, and the target data includes metadata information corresponding to the DRBD application; the second application operates the original block device based on the target data in the reserved block device, including: the DRBD application performs a mirroring operation on the original block device based on the metadata information in the reserved block device to mirror the data in the original block device to another block device.
[0013] Exemplarily, the second application is a block device merging application, and the block device merging application is used to combine the original block device with other block devices other than the original block device to form a merged block device, and the target data includes the correspondence between the logical address of the storage space of the merged block device and the physical address of the storage space of the original block device; the second application operates the original block device based on the target data in the reserved block device, including: if it is necessary to write data to the storage space corresponding to the third logical address of the merged block device, and it is determined based on the correspondence that the third logical address corresponds to the third physical address of the original block device, then the data is written to the storage space corresponding to the third physical address of the original block device; and / or, if it is necessary to read data from the storage space corresponding to the fourth logical address of the merged block device, and it is determined based on the correspondence that the fourth logical address corresponds to the fourth physical address of the original block device, then the data is read from the storage space corresponding to the fourth physical address of the original block device.
[0014] Exemplarily, the second application is a defragmentation application, and the target data includes fragmented data in the target block device; the second application operates the original block device based on the target data in the reserved block device, including: after storing the fragmented data in the target block device in the reserved block device, if the total amount of data in the reserved block device reaches a preset threshold, the defragmentation application migrates the fragmented data in the reserved block device to the target storage area of the target block device.
[0015] The present application provides an operating device for a block device, the device comprising: a management module, used to reserve part of the storage space from all the storage spaces of an original block device as a reserved block device, and to form a target block device with the remaining storage space in the original block device except the reserved block device; a providing module, used to provide mapping information corresponding to the storage space of the target block device to a first application, so that the first application operates the target block device based on the mapping information; and an operating module, used to write the target data into the reserved block device corresponding to the address information if an operation request sent by a second application is received, the operation request including target data and address information of the reserved block device, so that the second application operates the original block device based on the target data in the reserved block device.
[0016] When the management module reserves part of the storage space from all the storage spaces of the original block device as the reserved block device, it is specifically used to: obtain the configured reservation mode, obtain the target storage capacity of the storage space to be reserved; select a reserved position matching the reservation mode from all the storage spaces of the original block device; at the reserved position, reserve the storage space matching the target storage capacity as the reserved block device; wherein the reservation mode is header reservation, or tail reservation, or head and tail reservation, or specified reservation, or segment reservation; if the reservation mode is header reservation, the target storage capacity of the storage space to be reserved is selected; and If the reservation mode is tail reservation, the reserved position is the starting position of the original block device; or, if the reservation mode is head and tail reservation, the reserved position is the starting position and the ending position of the original block device; or, if the reservation mode is designated reservation, the reserved position is the designated position of the original block device; or, if the reservation mode is segmented reservation, the reserved position is multiple positions of the original block device, and the interval between two adjacent positions is the same.
[0017] Exemplarily, the mapping information includes a mapping relationship between a logical address of a storage space of a target block device and a physical address of a storage space of an original block device; when the first application operates the target block device based on the mapping information, it is specifically used to: if data needs to be written to a storage space corresponding to a first logical address of the target block device, determine a first physical address corresponding to the first logical address based on the mapping relationship, and write the data to a storage space corresponding to the first physical address of the original block device; and / or, if data needs to be read from a storage space corresponding to a second logical address of the target block device, determine a second physical address corresponding to the second logical address based on the mapping relationship, and read data from a storage space corresponding to the second physical address of the original block device.
[0018] Exemplarily, the second application is a DRBD application, and the target data includes metadata information corresponding to the DRBD application; when the second application operates the original block device based on the target data in the reserved block device, it is specifically used to: based on the metadata information in the reserved block device, mirror the original block device to mirror the data in the original block device to another block device; or, the second application is a block device merging application, and the block device merging application is used to combine the original block device with other block devices other than the original block device to form a merged block device, and the target data includes the correspondence between the logical address of the storage space of the merged block device and the physical address of the storage space of the original block device; when the second application operates the original block device based on the target data in the reserved block device, it is specifically used to: if it is necessary to write data to the storage space corresponding to the third logical address of the merged block device, and based on the correspondence It is determined that the third logical address corresponds to the third physical address of the original block device, and the data is written to the storage space corresponding to the third physical address of the original block device; and / or, if it is necessary to read data from the storage space corresponding to the fourth logical address of the merged block device, and it is determined based on the corresponding relationship that the fourth logical address corresponds to the fourth physical address of the original block device, the data is read from the storage space corresponding to the fourth physical address of the original block device; or, the second application is a defragmentation application, and the target data includes the fragmented data in the target block device; when the second application operates the original block device based on the target data in the reserved block device, it is specifically used to: after storing the fragmented data in the target block device to the reserved block device, if the total amount of data in the reserved block device reaches a preset threshold, the defragmentation application migrates the fragmented data in the reserved block device to the target storage area of the target block device.
[0019] The present application provides an operating device for a block device, comprising: a processor and a machine-readable storage medium, wherein the machine-readable storage medium stores machine-executable instructions that can be executed by the processor; wherein the processor is used to execute the machine-executable instructions to implement the above-mentioned operating method for the block device.
[0020] The present application provides a machine-readable storage medium, on which a number of computer instructions are stored. When the computer instructions are executed by a processor, the above-mentioned block device operation method can be implemented.
[0021] It can be seen from the above technical solution that in the embodiment of the present application, the original block device can be divided into a reserved block device and a target block device, and the target block device is provided to the first application (such as a file system) for use, that is, the first application only operates on the target block device, and the first application occupies all the storage space of the target block device instead of occupying all the storage space of the original block device, that is, the first application does not occupy the reserved block device, so that the second application (any application except the first application) can operate on the reserved block device, so that the second application can directly operate on the original block device without having to operate on the original block device through the first application, thereby improving the operating efficiency of the original block device. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments of the present application or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings of the embodiments of the present application.
[0023] Figure 1 It is a flowchart of a method for operating a block device in one embodiment of the present application;
[0024] Figure 2A-2F is a schematic diagram of a reserved position of an original block device in one embodiment of the present application;
[0025] Figure 3 is an example of a block device merging application in one embodiment of the present application;
[0026] Figure 4 is a schematic diagram of the structure of an operating device of a block device in one embodiment of the present application;
[0027] Figure 5 It is a hardware structure diagram of an operating device of a block device in one implementation manner of the present application. DETAILED DESCRIPTION
[0028] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, rather than limiting the present application. The singular forms of "a", "said" and "the" used in the present application and claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to any or all possible combinations of one or more associated listed items.
[0029] It should be understood that, although the terms first, second, third, etc. may be used to describe various information in the embodiments of the present application, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, in addition, the word "if" used may be interpreted as "at..." or "when..." or "in response to determination".
[0030] Block devices include but are not limited to hard disks, floppy disks, CD-ROMs, magnetic disks, flash memory, USB flash drives, SD (Secure Digital) cards, etc. There is no restriction on the type of block devices. Block devices can store data in blocks of fixed size (such as 512B, etc.). Data can only be read and written in multiples of blocks. In order to achieve independent access to each block, each block has a physical address, and the data in the block can be accessed through the physical address.
[0031] Normally, block devices are provided to file systems for use. Once a block device is used by a file system, all storage space of the block device is managed by the file system. That is, the file system needs to occupy all storage space of the block device, and all read and write operations on the block device are completed based on the file system. As a result, other applications cannot directly operate on the block device and can only operate on the block device through the file system.
[0032] For example, block devices can store data using single disks, RAID (Redundant Arrays of Independent Disks), Ceph (distributed file system), etc., and block devices can store large amounts of data, such as several terabytes or even dozens of terabytes. In order to protect the large amount of data in block devices, data migration, disk expansion, and other operations can be performed. The DRBD (Distributed Replicated Block Device) application is a way to implement operations such as data migration. The DRBD application can implement remote replication and is a storage replication solution for mirroring block device contents.
[0033] In order to implement DRBD applications, it is necessary to store metadata information corresponding to the DRBD application in the block device. However, after the block device is used by the file system, all storage space of the block device is managed by the file system, resulting in a lack of storage space that can be managed by the DRBD application. That is, the metadata information corresponding to the DRBD application cannot be stored in the block device, which also results in the block device being unable to be used by the DRBD application. The DRBD application cannot directly operate on the block device and cannot implement operations such as data migration.
[0034] In view of the above findings, a method for operating a block device is proposed in an embodiment of the present application, which can divide the original block device into a reserved block device and a target block device, and provide the target block device for use by the file system, that is, the file system does not occupy the reserved block device in the original block device, so that other applications can operate on the reserved block device in the original block device, so that other applications can directly operate on the original block device.
[0035] For example, the DRBD application can store metadata information corresponding to the DRBD application in a reserved block device in the original block device, so that the original block device can be used by the DRBD application. The DRBD application can directly operate on the original block device and implement operations such as data migration.
[0036] The technical solution of the embodiments of the present application is described below in conjunction with specific embodiments.
[0037] See also Figure 1 FIG. 1 is a flow chart of a method for operating a block device, and the method may include:
[0038] Step 101: reserve part of the storage space from all the storage spaces of the original block device as a reserved block device, and form a target block device with the remaining storage space in the original block device except the reserved block device.
[0039] Among them, the reserved block device is a block device with a continuous logical address, and the target block device is a block device with a continuous logical address. For example, the physical address of the original block device is 0-100 (i.e., the physical address is continuous), and the physical addresses 0-3, 10-13, and 97-100 are used as reserved block devices, and the remaining physical addresses are used as target block devices. Then, the logical address of the reserved block device is 0-11 (i.e., the logical address of the reserved block device is continuous), the logical address 0-3 of the reserved block device corresponds to the physical address 0-3, the logical address 4-7 of the reserved block device corresponds to the physical address 10-13, and the logical address 8-11 of the reserved block device corresponds to the physical address 97-100. The logical address of the target block device is 0-88 (i.e., the logical address of the target block device is continuous, the logical address of the target block device is independent of the logical address of the reserved block device, and both start from logical address 0), the logical address 0-5 of the target block device corresponds to the physical address 4-9, and the logical address 6-88 of the target block device corresponds to the physical address 14-96.
[0040] Exemplarily, for the original block device, before providing the original block device to the first application (such as a file system) for use, the original block device needs to be divided into a reserved block device and a target block device, that is, a portion of the storage space is reserved from all the storage space of the original block device as the reserved block device, and the remaining storage space other than the reserved block device is used to form the target block device. On this basis, the target block device is provided to the first application for use, rather than the original block device. For the convenience of distinction, the complete block device before the division is called the original block device, and the portion of the block device other than the reserved block device after the division is called the target block device. For example, the original block device may include storage space a, storage space b, storage space c, ..., and storage space a may be used as a reserved block device, and the remaining storage space other than storage space a (such as storage space b, storage space c, etc.) may be used to form the target block device.
[0041] In a possible implementation, step 101 may be implemented by taking the following steps:
[0042] Step 1011, obtain the configured reservation mode, which includes but is not limited to: header reservation, tail reservation, head and tail reservation, designated reservation, and segment reservation. Of course, the above are just a few examples of reservation modes and are not limited to this. For example, if the configuration reservation mode is header reservation, obtain the configured reservation mode as header reservation; or, if the configuration reservation mode is tail reservation, obtain the configured reservation mode as tail reservation; or, if the configuration reservation mode is head and tail reservation, obtain the configured reservation mode as head and tail reservation; or, if the configuration reservation mode is designated reservation, obtain the configured reservation mode as designated reservation; or, if the configuration reservation mode is segment reservation, obtain the configured reservation mode as segment reservation.
[0043] For example, a reservation command issued by a user may be received, and the reservation command is used to indicate to reserve part of the storage space from the original block device as the reserved block device. Therefore, it is necessary to reserve part of the storage space from all the storage space of the original block device as the reserved block device, see step 101. In the reservation command, a reservation mode field may be included, and the reservation mode field includes a reservation mode configured by the user, such as header reservation, tail reservation, head and tail reservation, specified reservation, segment reservation, etc. Therefore, the reservation mode can be parsed from the reservation command. Of course, the above is only an example, and other methods can also be used to obtain the reservation mode.
[0044] Step 1012: Obtain the target storage capacity of the storage space to be reserved.
[0045] For example, the target storage capacity of the storage space to be reserved may be preconfigured, and on this basis, the configured target storage capacity may be obtained, and the target storage capacity is used to represent the size of the reserved block device, such as the target storage capacity is a. For example, in the above reservation command, a reserved size field may be included, and the reserved size field includes the target storage capacity of the storage space to be reserved, so the target storage capacity may be parsed from the reservation command.
[0046] For another example, the target storage capacity of the storage space to be reserved can be calculated based on a certain strategy. Under one strategy, the target storage capacity can be calculated based on the application scenario. For example, in this application scenario, the second application needs to use a bytes to store data, then the target storage capacity can be greater than or equal to a bytes. Under another strategy, the target storage capacity can be calculated based on the size of the original block device. For example, if the size of the original block device is m bytes, then the target storage capacity can be n*m bytes, where n is a value greater than 0 and less than 1. Under another strategy, the target storage capacity can be calculated based on the application scenario and the size of the original block device. For example, based on the size of the original block device, calculate how many bytes the second application needs to use to store data in the application scenario, and the calculated value is the target storage capacity. Of course, the above are just a few examples and there is no limitation to this.
[0047] In summary, the target storage capacity of the storage space to be reserved can be obtained, which is recorded as target storage capacity a.
[0048] Step 1013: Select a reserved position matching the reservation pattern from all storage spaces of the original block device. The reserved position may be the starting position of the reserved block device or the ending position of the reserved block device.
[0049] For example, see Figure 2A The figure shows a schematic diagram of all storage spaces of the original block device.
[0050] If the reservation mode is header reservation, the reserved position is the starting position of the original block device, see Figure 2B As shown, it is a schematic diagram of the reserved position, and the reserved position serves as the starting position of the reserved block device.
[0051] If the reservation mode is tail reservation, the reserved position is the end position of the original block device, see Figure 2C As shown, it is a schematic diagram of the reserved position, and the reserved position serves as the end position of the reserved block device.
[0052] If the reservation mode is head and tail reservation, the reserved position is the start and end position of the original block device, see Figure 2DAs shown, it is a schematic diagram of the reserved position, that is, there are two reserved positions, one reserved position is used as the starting position of the reserved block device, and the other reserved position is used as the ending position of the reserved block device.
[0053] If the reservation mode is specified reservation, the reserved position is the specified position of the original block device (it can be located at any position of the original block device), see Figure 2E As shown, it is a schematic diagram of the reserved position, and the reserved position can be used as the starting position of the reserved block device, the reserved position can also be used as the ending position of the reserved block device, and the reserved position can also be used as the middle position of the reserved block device, and there is no limitation on this.
[0054] If the reservation mode is segmented reservation, the reserved positions are multiple positions of the original block device. For multiple positions, the interval between two adjacent positions is the same. See Figure 2F As shown, it is a schematic diagram of the reserved position, that is, there are multiple reserved positions, each of which can be used as the starting position of the reserved block device, and of course, can also be used as the end position of the reserved block device or the middle position of the reserved block device. For example, the interval between the first position and the second position is k, the interval between the second position and the third position is k, the interval between the third position and the fourth position is k, and so on.
[0055] Step 1014: At the reserved position, a storage space matching the target storage capacity is reserved as a reserved block device, and the remaining storage space in the original block device except the reserved block device is used to form a target block device.
[0056] For example, see Figure 2B As shown, a storage space of target storage capacity a is selected from the reserved position backward, and the storage space of target storage capacity a is used as a reserved block device, and the remaining storage space is used as a target block device.
[0057] For example, see Figure 2C As shown, a storage space of target storage capacity a is selected from the reserved position forward, and the storage space of target storage capacity a is used as a reserved block device, and the remaining storage space is used as a target block device.
[0058] For example, see Figure 2D As shown, a storage space of size a / 2 is selected from the front reserved position backwards, and this storage space is used as the reserved block device, and a storage space of size a / 2 is selected from the rear reserved position forwards, and this storage space is also used as the reserved block device, and the remaining storage space is used as the target block device.
[0059] For example, see Figure 2EAs shown, if the reserved position is used as the starting position of the reserved block device, the storage space of the target storage capacity a is selected from the reserved position backwards, and the storage space of the target storage capacity a is used as the reserved block device, and the remaining storage space is used as the target block device. Or, if the reserved position is used as the ending position of the reserved block device, the storage space of the target storage capacity a is selected from the reserved position forwards as the reserved block device. Or, if the reserved position is used as the middle position of the reserved block device, the storage space of size a / 2 is selected from the reserved position backwards, and the storage space of size a / 2 is selected from the reserved position forwards.
[0060] For example, see Figure 2F As shown, assuming that there are p reserved positions, for each reserved position, a storage space of size a / p is selected from the reserved position backward as a reserved block device.
[0061] At this point, step 101 is completed, and the original block device can be divided into a reserved block device and a target block device.
[0062] Step 102: Provide mapping information corresponding to the storage space of the target block device to the first application, so that the first application operates the target block device based on the mapping information. It should be noted that by providing the mapping information corresponding to the storage space of the target block device to the first application, the first application only operates the target block device, and does not operate the reserved block device of the original block device.
[0063] Exemplarily, after the original block device is divided into the reserved block device and the target block device, the mapping relationship between the logical address of the storage space of the target block device and the physical address of the storage space of the original block device can also be determined (hereinafter referred to as mapping relationship 1), and the mapping relationship between the logical address of the storage space of the reserved block device and the physical address of the storage space of the original block device can be determined (hereinafter referred to as mapping relationship 2).
[0064] For example, the original block device includes a large number of blocks (called physical blocks or data blocks, and the following uses data blocks as an example), each data block is of a fixed size (such as 512B, etc.), and each data block corresponds to a physical address. Based on the physical address, the starting position of the data block can be known, and the data block can be found based on the physical address and the fixed size. For example, assuming that the physical address of the data block is P1, the data block is between physical address P1 and physical address P2 (that is, the sum of physical address P1 and the fixed size).
[0065] After the original block device is divided into the reserved block device and the target block device, the target block device includes a large number of logical blocks, each of which is of a fixed size (such as 512B, etc.), and each logical block corresponds to a logical address, based on which the starting position of the logical block can be known, and based on the logical address and the fixed size, the logical block can be found. For example, assuming that the logical address of the logical block is Q1, the logical block is between the logical address Q1 and the logical address Q2 (i.e., the sum of the logical address Q1 and the fixed size).
[0066] It should be noted that the logical block is not a real block, and data cannot be directly stored in the logical block. Instead, the logical block of the target block device needs to be mapped to the data block of the original block device, and the data is stored in the data block of the original block device. For example, if the logical block s1 of the target block device corresponds to the data block t1 of the original block device, then when the data needs to be stored in the logical block s1, the data is stored in the data block t1.
[0067] In order to implement the above functions, it is necessary to determine a mapping relationship 1 between the logical address of the storage space of the target block device and the physical address of the storage space of the original block device. See Table 1 for an example of mapping relationship 1.
[0068] Table 1
[0069] The logical address of the storage space of the target block device The physical address of the raw block device's storage space Q1 P1 Q3 P3 … …
[0070] Based on Table 1, it can be seen that if data needs to be stored starting from the logical address Q1 of the target block device, in fact, data is stored starting from the physical address P1 of the original block device. If data needs to be stored starting from the logical address Q3 of the target block device, in fact, data is stored starting from the physical address P3 of the original block device.
[0071] After the original block device is divided into the reserved block device and the target block device, the reserved block device includes a small number of logical blocks, each of which is a fixed size (such as 512B, etc.), and each logical block corresponds to a logical address, based on which the starting position of the logical block can be known, and based on the logical address and the fixed size, the logical block can be found. On this basis, it is necessary to determine the mapping relationship 2 between the logical address of the storage space of the reserved block device and the physical address of the storage space of the original block device, which will not be described in detail.
[0072] To summarize, after the original block device is divided into the reserved block device and the target block device, mapping relationship 1 and mapping relationship 2 can be determined. If the original block device needs to be provided to the first application (such as a file system) for use, mapping relationship 1 can be provided to the first application. Since mapping relationship 1 is a mapping relationship between the logical address of the storage space of the target block device and the physical address of the storage space of the original block device, the first application can only operate on the target block device based on mapping relationship 1 (i.e., the logical address of the storage space of the target block device), but not on the reserved block device. In other words, the first application only occupies the storage space of the target block device, but not the storage space of the reserved block device.
[0073] In a possible implementation, the first application operates the target block device based on the mapping information (the mapping information may include the above-mentioned mapping relationship 1), which may include but is not limited to: if data needs to be written to the storage space corresponding to the first logical address of the target block device, the first physical address corresponding to the first logical address is determined based on the mapping relationship 1, and the data is written to the storage space corresponding to the first physical address of the original block device. And / or, if data needs to be read from the storage space corresponding to the second logical address of the target block device, the second physical address corresponding to the second logical address is determined based on the mapping relationship 1, and the data is read from the storage space corresponding to the second physical address of the original block device.
[0074] For example, if data needs to be written to the storage space (i.e., logical block) corresponding to the logical address Q1 of the target block device, by querying the mapping relationship 1 in Table 1, it is determined that the logical address Q1 corresponds to the physical address P1. Therefore, the data is written to the storage space (i.e., data block) corresponding to the physical address P1 of the original block device.
[0075] For another example, if data needs to be read from the storage space (i.e., logical block) corresponding to the logical address Q3 of the target block device, by querying the mapping relationship 1 in Table 1, it is determined that the logical address Q3 corresponds to the physical address P3. Therefore, data is read from the storage space (i.e., data block) corresponding to the physical address P3 of the original block device.
[0076] Step 103: If an operation request sent by a second application is received, and the operation request includes target data and address information of a reserved block device, the target data is written to the reserved block device corresponding to the address information, so that the second application operates the original block device based on the target data in the reserved block device.
[0077] Exemplarily, the execution subject of step 101 to step 103 is called a target module, and the target module can be implemented by software or hardware, without limitation. The target module can be loaded into the operating system in a kernel driver manner, so that the target module executes the operation method of the block device, that is, executes steps 101 to step 103, that is, the operating method of the block device can be executed by the operating system.
[0078] Exemplarily, if the second application (i.e., any application other than the first application, such as a DRBD application, etc.) needs to operate the original block device, the second application can send an address request to the target module, and the address request is used to request the address information of the reserved block device. After receiving the address request, the target module can provide the address information of the reserved block device to the second application, so that the second application can operate the reserved block device based on the address information. Alternatively, the target module can also actively provide the address information of the reserved block device to the second application, so that the second application can operate the reserved block device based on the address information.
[0079] On this basis, if the second application needs to operate the original block device, based on the address information of the reserved block device that has been obtained, the second application can send an operation request (i.e., a write request) to the target module, and the operation request includes the target data and the address information of the reserved block device, indicating that the target data needs to be written to the reserved block device corresponding to the address information. After receiving the operation request sent by the second application, the target module can write the target data to the reserved block device corresponding to the address information.
[0080] If the second application needs to read data from the reserved block device, the second application can send a read request to the target module, and the read request includes the address information of the reserved block device, indicating that data needs to be read from the reserved block device corresponding to the address information. After receiving the read request sent by the second application, the target module can read data from the reserved block device corresponding to the address information and return the data to the second application.
[0081] Exemplarily, the address information of the reserved block device may include the logical address (indicating the first address) and the offset (indicating the address length) of the reserved block device. Based on the logical address and the offset, the logical block in the reserved block device can be determined (it can be one logical block or multiple logical blocks), and then the logical block in the reserved block device can be read and written, thereby realizing the read and write operations of the reserved block device.
[0082] For example, after receiving the operation request sent by the second application, the target module parses the target data and the address information of the reserved block device (such as the logical address a1 and the offset a2 of the reserved block device) from the operation request, and based on the above-mentioned mapping relationship 2, the physical address b1 corresponding to the logical address a1 can be determined, and the physical address b2 (that is, the sum of the offset a2 and the physical address b1) can be determined based on the offset a2 and the physical address b1, and the target data is written to the data block between the physical address b1 and the physical address b2 of the reserved block device, thereby realizing the write operation on the reserved block device and writing the target data to the reserved block device.
[0083] For another example, after receiving a read request sent by the second application, the target module parses the address information of the reserved block device (such as the logical address a3 and the offset a4) from the read request, and based on the above-mentioned mapping relationship 2, the physical address b3 corresponding to the logical address a3 can be determined, and the physical address b4 (that is, the sum of the offset a3 and the physical address b3) can be determined based on the offset a4 and the physical address b3, and data is read from the data block between the physical address b3 of the reserved block device and the physical address b3, thereby realizing the read operation on the reserved block device.
[0084] In one possible implementation, a message format may be agreed upon (for example, by agreeing on a message format through a specific interface, without limitation), and the second application may send an operation request or a read request that matches the message format to the target module, so that the target module can correctly parse the operation request or the read request.
[0085] In a possible implementation, the original block device is divided into a reserved block device and a target block device, and the target block device is provided to the first application for use, and the reserved block device is not provided to the first application for use. The second application can operate on the reserved block device, such as writing target data to the reserved block device. On this basis, the second application can operate on the original block device based on the target data in the reserved block device.
[0086] In a possible implementation, the reserved block device may also be released, that is, the reserved block device and the target block device may be restored to the original block device, and the original block device may be provided to the first application for use.
[0087] As can be seen from the above technical solutions, in the embodiment of the present application, the original block device can be divided into a reserved block device and a target block device, and the target block device is provided to the first application (such as a file system) for use, that is, the first application only operates the target block device, and the first application occupies the entire storage space of the target block device, rather than the entire storage space of the original block device, that is, the first application does not occupy the storage space of the reserved block device, so that the second application (any application except the first application) can operate the reserved block device in the original block device, so that the second application can directly operate the original block device without the need to operate the original block device through the first application, thereby improving the operating efficiency of the original block device. By reserving storage space for the original block device, the possibility and scalability of operating the original block device are realized, the ability to customize the use of the original block device is realized, and the operability and variability of the original block device are increased. For the pre-processed target block device, the reserved block device will be hidden from the outside, so that the user uses the target block device exactly the same as using an ordinary block device. When it is necessary to read and write the reserved block device, the reserved block device can be accessed and read and written through the access interface.
[0088] In the above embodiment, for step 103, the target data needs to be written into the reserved block device so that the second application can operate the original block device based on the target data in the reserved block device. The following describes the process in conjunction with several specific application scenarios. It should be noted that these are just a few examples of application scenarios, and there is no limitation to this, as long as the reserved block device in the original block device can be operated.
[0089] Application scenario 1: The second application is a DRBD application, and the target data includes metadata information corresponding to the DRBD application. On this basis, the DRBD application can mirror the original block device based on the metadata information in the reserved block device to mirror the data in the original block device to another block device.
[0090] For example, when the DRBD application needs to migrate data to the original block device, it will generate metadata information and send an operation request to the target module. The operation request may include the metadata information and the address information of the reserved block device. After receiving the operation request, the target module may write the metadata information to the reserved block device corresponding to the address information. On this basis, the DRBD application can perform a mirroring operation on the original block device based on the metadata information in the reserved block device to mirror the data in the original block device to another block device. This mirroring operation process is not limited in this embodiment.
[0091] Among them, the metadata information may include but is not limited to at least one of the following: Device size: The device size refers to the size of the original block device, not the size of the target block device. Generation identifier: used to indicate the new and old data information between two DRBD blocks, that is, which block device (that is, the original block device) has data before mirroring, and which block device (that is, the other block device after mirroring) has data after mirroring. Activity log: used to record block activities, such as disconnection and other actions. Synchronization bitmap: used to map each sector bit by bit to record whether the data of each sector is consistent. Internal metadata storage method. Of course, the above are just a few examples of metadata information, and there is no restriction on the content of this metadata information.
[0092] Among them, the DRBD application can mirror block devices, mirror two block devices into the same data blocks according to data bits, and realize storage replication between mirrored block devices through the management of metadata information.
[0093] The size of the metadata information can be obtained using the following formula: s =c*8+72, c represents the s / 2 18 Downward value, M s Represents metadata information, C s Indicates the size of the original block device. Therefore, in the DRBD application scenario, the size of the original block device C s Calculate the size of metadata information M s On this basis, the target storage capacity in the above embodiment (see step 1012) may be greater than or equal to the size M of the metadata information. s Of course, the above is only an example of the size of metadata information and there is no limitation on this.
[0094] The following describes the processing process under DRBD application with specific steps.
[0095] Step S11: Create a logical volume, which can be used as a raw block device.
[0096] Step S12: Calculate the size of the reserved block device based on the size of the original block device. For example, calculate the size of the metadata information based on the size of the original block device, and determine the target storage capacity of the storage space to be reserved based on the size of the metadata information. The target storage capacity is the size of the reserved block device.
[0097] Among them, the metadata information here is the metadata information corresponding to the DRBD application, that is, the metadata information generated by the DRBD application, which may include but is not limited to device size, generation identification, activity log, synchronization bitmap, internal metadata storage method, etc. For specific explanations, please refer to the above embodiments and will not be repeated here.
[0098] Step S13: based on the size of the reserved block device, the original block device is divided into a target block device and a reserved block device, and the sum of the size of the reserved block device and the size of the target block device is the size of the original block device.
[0099] Step S14: provide the target block device to the file system for use. For example, the target block device is provided to the client via iSCSI (Internet Small Computer System Interface). After the client connects to the target block device, the user performs read and write operations on the target block device in the file system.
[0100] Step S15: The DRBD application obtains metadata information and writes the metadata information to the reserved block device.
[0101] Step S16: The DRBD application mirrors the data in the original block device to another block device based on the metadata information in the reserved block device.
[0102] Application scenario 2: The second application is a DRBD application, and the target data includes metadata information corresponding to the DRBD application. On this basis, if the target module needs to provide the reserved block device to the DRBD application, the target module can merge the target block device and the reserved block device into the original block device (i.e., restore it to the original block device), and provide the mapping information corresponding to the storage space of the original block device to the DRBD application, so that the DRBD application operates on the original block device based on the mapping information. This process is similar to step 102, except that the mapping information corresponding to the storage space of the original block device (rather than the mapping information corresponding to the storage space of the target block device) is provided to the DRBD application, and the DRBD application operates on the original block device (rather than the target block device). The specific process will not be repeated here.
[0103] Exemplarily, after providing the mapping information corresponding to the storage space of the original block device to the DRBD application, the DRBD application can also obtain the target block device and the reserved block device in the original block device. For example, based on the reservation mode, the target storage capacity of the storage space to be reserved and other information, the reserved block device in the original block device is determined. The determination method is shown in step 101 and will not be repeated here.
[0104] On this basis, when the DRBD application operates on the original block device, the metadata information can be stored in the reserved block device. Moreover, the DRBD application can perform a mirroring operation on the original block device based on the metadata information in the reserved block device to mirror the data in the original block device to another block device.
[0105] Of course, the above is only an example of the DRBD application operating on the raw block device, and there is no limitation to this.
[0106] Application scenario 3: The second application is a block device merging application, which is used to combine the original block device with other block devices (such as at least one block device) other than the original block device into a merged block device, and the target data includes the correspondence between the logical address of the storage space of the merged block device and the physical address of the storage space of the original block device. On this basis, if it is necessary to write data to the storage space corresponding to the third logical address of the merged block device, and based on the correspondence, it is determined that the third logical address corresponds to the third physical address of the original block device, then the block device merging application writes the data to the storage space corresponding to the third physical address of the original block device. And / or, if it is necessary to read data from the storage space corresponding to the fourth logical address of the merged block device, and based on the correspondence, it is determined that the fourth logical address corresponds to the fourth physical address of the original block device, then the block device merging application reads data from the storage space corresponding to the fourth physical address of the original block device.
[0107] For example, the original block device 1 can be divided into the target block device 11 and the reserved block device 12, and the original block device 2 can be divided into the target block device 21 and the reserved block device 22. On this basis, the block device merging application can form a merged block device with the original block device 1, that is, the merged block device includes the original block device 1 and the original block device 2. The merged block device includes a logical block, while the original block device 1 and the original block device 2 include a data block. Then, the block device merging application can determine a correspondence 1 between the logical address of the storage space of the merged block device and the physical address of the storage space of the original block device 1, and determine a correspondence 2 between the logical address of the storage space of the merged block device and the physical address of the storage space of the original block device 2. Then, the block device merging application writes the correspondence 1 into the reserved block device 22 of the original block device 2, and writes the correspondence 2 into the reserved block device 12 of the original block device 1.
[0108] If data needs to be written to the storage space corresponding to the third logical address of the merged block device, the block device merge application queries the corresponding relationship 1 in the reserved block device 22 through the third logical address. If the third logical address exists in the corresponding relationship 1, and the third logical address corresponds to the physical address x in the original block device 1 (that is, the physical address x is used as the third physical address), the block device merge application writes the data to the storage space corresponding to the physical address x of the original block device 1. Alternatively, if the third logical address does not exist in the corresponding relationship 1, the block device merge application queries the corresponding relationship 2 in the reserved block device 12 through the third logical address. If the third logical address corresponds to the physical address y in the original block device 2 (that is, the physical address y is used as the third physical address), the block device merge application writes the data to the storage space corresponding to the physical address y of the original block device 2.
[0109] If data needs to be read from the storage space corresponding to the fourth logical address of the merged block device, the block device merge application queries the correspondence relationship 1 through the fourth logical address, and if the query finds that the fourth logical address corresponds to the physical address in the original block device 1, the data is read from the storage space corresponding to the physical address of the original block device 1. Alternatively, if the fourth logical address does not exist in the correspondence relationship 1, the block device merge application queries the correspondence relationship 2 through the fourth logical address, and if the query finds that the fourth logical address corresponds to the physical address in the original block device 2, the data is read from the storage space corresponding to the physical address of the original block device 2.
[0110] In addition to the block device merging application, for other applications that are accessing the original block device 1, the correspondence 2 can be read from the reserved block device 12 of the original block device 1, and then the correspondence between the logical address of the storage space of the merged block device and the physical address of the storage space of the original block device 2 can be obtained. In other words, data can be stored in the original block device 2, or data can be read from the original block device 2, that is, the original block device 2 can be accessed, thereby realizing access to the original block device 1 and the original block device 2.
[0111] In addition to the block device merging application, for other applications that are accessing the original block device 2, the correspondence 1 can be read from the reserved block device 22 of the original block device 2, and then the correspondence between the logical address of the storage space of the merged block device and the physical address of the storage space of the original block device 1 can be obtained. In other words, data can be stored in the original block device 1, or data can be read from the original block device 1, that is, the original block device 1 can be accessed, thereby realizing access to the original block device 1 and the original block device 2.
[0112] See also Figure 3As shown, it is an example of block device merging application. The connection operation of two original block devices (i.e., original block device 1 and original block device 2) can be realized by head and tail reservation, that is, the two original block devices are connected to be used as a large block device (i.e., merged block device), and the logical address of the merged block device is continuous. For example, space is reserved for the tail of the original block device 1 (i.e., the reserved block device is located at the tail of the original block device 1), and space is reserved for the head of the original block device 2 (i.e., the reserved block device is located at the head of the original block device 2). When executing the connection, the corresponding relationship 1 is recorded to the reserved block device at the head position of the original block device 2, and the corresponding relationship 2 is recorded to the reserved block device at the tail position of the original block device 1, and the reserved block device of the original block device 1 is connected with the reserved block device of the original block device 2.
[0113] Application scenario 4: The second application is a defragmentation application, and the target data includes fragmented data in the target block device (i.e., scattered data in different data blocks). On this basis, after storing the fragmented data in the target block device in the reserved block device, if the total amount of data in the reserved block device reaches a preset threshold, the defragmentation application migrates the fragmented data in the reserved block device to the target storage area of the target block device.
[0114] For example, during the use of the target block device, the target block device may be repeatedly written and deleted data, that is, the data may not occupy the entire target block device, resulting in the data in the target block device becoming fragmented data, and the fragmented data in the target block device needs to be defragmented. On this basis, the defragmentation application can send an operation request to the target module, and the operation request can include the address information of the fragmented data and the reserved block device. After receiving the operation request, the target module can write the fragmented data to the reserved block device corresponding to the address information. On this basis, since a large number of target block devices will have fragmented data, it is necessary to continuously write the fragmented data to the reserved block device, resulting in more and more fragmented data in the reserved block device. If the total amount of data in the reserved block device reaches a preset threshold (which can be configured based on experience, such as the total size of the reserved block device*m, where m is a value greater than 0 and less than or equal to 1), the defragmentation application can migrate all fragmented data in the reserved block device to the target storage area of the target block device, that is, integrate them into the same storage area of the target block device, and delete the fragmented data in the reserved block device, thereby releasing the storage space of the reserved block device, and can continue to write fragmented data to the reserved block device.
[0115] In summary, the reserved block device can be used as a temporary storage space for disk defragmentation, and the fragmented data can be temporarily copied to the reserved block device, thereby realizing the integration of the fragmented data through the reserved block device.
[0116] Based on the same application concept as the above method, an operation device of a block device is proposed in the embodiment of the present application, see Figure 4 As shown, it is a schematic diagram of the structure of the device, and the device includes: a management module 41, which is used to reserve part of the storage space from all the storage spaces of the original block device as a reserved block device, and the remaining storage space in the original block device except the reserved block device constitutes a target block device; a providing module 42, which is used to provide mapping information corresponding to the storage space of the target block device to the first application, so that the first application operates the target block device based on the mapping information; an operating module 43, which is used to write the target data into the reserved block device corresponding to the address information if an operation request sent by the second application is received, and the operation request includes the target data and the address information of the reserved block device, so that the second application operates the original block device based on the target data in the reserved block device.
[0117] Exemplarily, when reserving part of the storage space from all the storage spaces of the original block device as the reserved block device, the management module 41 is specifically used to: obtain a configured reservation mode, obtain a target storage capacity of the storage space to be reserved; select a reserved position matching the reservation mode from all the storage spaces of the original block device; and reserve a storage space matching the target storage capacity at the reserved position as the reserved block device. The reservation mode is header reservation, or tail reservation, or head and tail reservation, or specified reservation, or segment reservation; if the reservation mode is header reservation, the reserved position is the starting position of the original block device; or, if the reservation mode is tail reservation, the reserved position is the ending position of the original block device; or, if the reservation mode is head and tail reservation, the reserved position is the starting position and the ending position of the original block device; or, if the reservation mode is specified reservation, the reserved position is the specified position of the original block device; or, if the reservation mode is segment reservation, the reserved position is multiple positions of the original block device, and the interval between two adjacent positions is the same.
[0118] Exemplarily, the mapping information includes a mapping relationship between a logical address of a storage space of a target block device and a physical address of a storage space of an original block device; when the first application operates the target block device based on the mapping information, it is specifically used to: if data needs to be written to a storage space corresponding to a first logical address of the target block device, determine a first physical address corresponding to the first logical address based on the mapping relationship, and write the data to a storage space corresponding to the first physical address of the original block device; and / or, if data needs to be read from a storage space corresponding to a second logical address of the target block device, determine a second physical address corresponding to the second logical address based on the mapping relationship, and read data from a storage space corresponding to the second physical address of the original block device.
[0119] Exemplarily, the second application is a DRBD application, and the target data includes metadata information corresponding to the DRBD application; when the second application operates the original block device based on the target data in the reserved block device, it is specifically used to: based on the metadata information in the reserved block device, mirror the original block device to mirror the data in the original block device to another block device; or, the second application is a block device merging application, and the block device merging application is used to combine the original block device with other block devices other than the original block device to form a merged block device, and the target data includes the correspondence between the logical address of the storage space of the merged block device and the physical address of the storage space of the original block device; when the second application operates the original block device based on the target data in the reserved block device, it is specifically used to: if it is necessary to write data to the storage space corresponding to the third logical address of the merged block device, and based on the correspondence It is determined that the third logical address corresponds to the third physical address of the original block device, and the data is written to the storage space corresponding to the third physical address of the original block device; and / or, if it is necessary to read data from the storage space corresponding to the fourth logical address of the merged block device, and it is determined based on the corresponding relationship that the fourth logical address corresponds to the fourth physical address of the original block device, the data is read from the storage space corresponding to the fourth physical address of the original block device; or, the second application is a defragmentation application, and the target data includes the fragmented data in the target block device; when the second application operates the original block device based on the target data in the reserved block device, it is specifically used to: after storing the fragmented data in the target block device to the reserved block device, if the total amount of data in the reserved block device reaches a preset threshold, the defragmentation application migrates the fragmented data in the reserved block device to the target storage area of the target block device.
[0120] Based on the same application concept as the above method, an operation device for a block device is proposed in the embodiment of the present application, see Figure 5 As shown, the operating device of the block device includes: a processor 51 and a machine-readable storage medium 52, wherein the machine-readable storage medium 52 stores machine-executable instructions that can be executed by the processor 51; wherein the processor 51 is used to execute the machine-executable instructions to implement the operating method of the block device disclosed in the above example of this application.
[0121] For example, when the processor 51 executes the machine executable instruction, the following steps can be implemented:
[0122] Reserving part of the storage space from all the storage spaces of the original block device as a reserved block device, and forming a target block device with the remaining storage space in the original block device except the reserved block device;
[0123] Providing mapping information corresponding to the storage space of the target block device to the first application, so that the first application operates the target block device based on the mapping information;
[0124] If an operation request sent by a second application is received, and the operation request includes target data and address information of a reserved block device, the target data is written to the reserved block device corresponding to the address information, so that the second application operates the original block device based on the target data in the reserved block device.
[0125] Based on the same application concept as the above method, an embodiment of the present application also provides a machine-readable storage medium, on which a number of computer instructions are stored. When the computer instructions are executed by a processor, the operation method of the block device disclosed in the above example of the present application can be implemented.
[0126] For example, when the computer instructions are executed by the processor, the following steps are implemented:
[0127] Reserving part of the storage space from all the storage spaces of the original block device as a reserved block device, and forming a target block device with the remaining storage space in the original block device except the reserved block device;
[0128] Providing mapping information corresponding to the storage space of the target block device to the first application, so that the first application operates the target block device based on the mapping information;
[0129] If an operation request sent by a second application is received, and the operation request includes target data and address information of a reserved block device, the target data is written to the reserved block device corresponding to the address information, so that the second application operates the original block device based on the target data in the reserved block device.
[0130] The above-mentioned machine-readable storage medium may be any electronic, magnetic, optical or other physical storage device, which may contain or store information, such as executable instructions, data, etc. For example, the machine-readable storage medium may be: RAM (Radom Access Memory), volatile memory, non-volatile memory, flash memory, storage drive (such as hard disk drive), solid state drive, any type of storage disk (such as CD, DVD, etc.), or similar storage medium, or a combination thereof.
[0131] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0132] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0133] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the embodiments of the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0134] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0135] Moreover, these computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which is implemented in the process Figure 1 A process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0136] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0137] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A method for operating a block device, characterized in that: The method comprises: Reserving part of the storage space from all the storage spaces of the original block device as a reserved block device, and forming a target block device with the remaining storage space in the original block device except the reserved block device; Providing mapping information corresponding to the storage space of the target block device to the first application, so that the first application operates the target block device based on the mapping information; If an operation request sent by a second application is received, the operation request includes target data and address information of a reserved block device, the target data is written to the reserved block device corresponding to the address information, so that the second application operates the original block device based on the target data in the reserved block device; Wherein, if the second application is a block device merging application, and the block device merging application is used to form a merged block device by combining the original block device with other block devices other than the original block device, the target data includes a correspondence between a logical address of a storage space of the merged block device and a physical address of a storage space of the original block device; the second application operates the original block device based on the target data in the reserved block device, including: If it is necessary to write data to the storage space corresponding to the third logical address of the merged block device, and it is determined based on the corresponding relationship that the third logical address corresponds to the third physical address of the original block device, then the data is written to the storage space corresponding to the third physical address of the original block device; and / or, If it is necessary to read data from the storage space corresponding to the fourth logical address of the merged block device, and based on the corresponding relationship, it is determined that the fourth logical address corresponds to the fourth physical address of the original block device, then the data is read from the storage space corresponding to the fourth physical address of the original block device.
2. The method according to claim 1, characterized in that: The step of reserving part of the storage space from all the storage space of the original block device as the reserved block device includes: Obtain the configured reservation mode and obtain the target storage capacity of the storage space to be reserved; Selecting a reserved location matching the reservation mode from all storage spaces of the original block device; At the reserved position, a storage space matching the target storage capacity is reserved as a reserved block device.
3. The method according to claim 2, characterized in that The reservation mode is header reservation, tail reservation, head and tail reservation, designated reservation, or segment reservation; If the reservation mode is header reservation, the reserved position is the starting position of the original block device; or, if the reservation mode is tail reservation, the reserved position is the ending position of the original block device; or, if the reservation mode is head and tail reservation, the reserved position is the starting position and the ending position of the original block device; or, if the reservation mode is specified reservation, the reserved position is the specified position of the original block device; or, if the reservation mode is segmented reservation, the reserved position is multiple positions of the original block device, and the interval between two adjacent positions is the same.
4. The method according to claim 1, characterized in that: The mapping information includes a mapping relationship between a logical address of a storage space of a target block device and a physical address of a storage space of an original block device; The first application operates the target block device based on the mapping information, including: If data needs to be written to the storage space corresponding to the first logical address of the target block device, a first physical address corresponding to the first logical address is determined based on the mapping relationship, and the data is written to the storage space corresponding to the first physical address of the original block device; and / or, If data needs to be read from the storage space corresponding to the second logical address of the target block device, the second physical address corresponding to the second logical address is determined based on the mapping relationship, and data is read from the storage space corresponding to the second physical address of the original block device.
5. The method according to claim 1, characterized in that If the second application is a distributed replicated block device DRBD application, the target data includes metadata information corresponding to the DRBD application; The second application operates the original block device based on the target data in the reserved block device, including: The DRBD application performs a mirroring operation on the original block device based on the metadata information in the reserved block device to mirror the data in the original block device to another block device.
6. The method according to claim 1, characterized in that If the second application is a defragmentation application, the target data includes fragmented data in the target block device; The second application operates the original block device based on the target data in the reserved block device, including: After storing the fragmented data in the target block device in the reserved block device, if the total amount of data in the reserved block device reaches a preset threshold, the defragmentation application migrates the fragmented data in the reserved block device to the target storage area of the target block device.
7. An operating device for a block device, characterized in that: The device comprises: a management module, which is used to reserve part of the storage space from all the storage spaces of the original block device as a reserved block device, and to form a target block device with the remaining storage space in the original block device except the reserved block device; A providing module, configured to provide mapping information corresponding to the storage space of the target block device to a first application, so that the first application operates the target block device based on the mapping information; an operation module, configured to, if receiving an operation request sent by a second application, wherein the operation request includes target data and address information of the reserved block device, write the target data into the reserved block device corresponding to the address information, so that the second application operates the original block device based on the target data in the reserved block device; If the second application is a block device merging application, the block device merging application is used to form a merged block device by combining an original block device with other block devices other than the original block device, and the target data includes a correspondence between a logical address of a storage space of the merged block device and a physical address of a storage space of the original block device; when the second application operates the original block device based on the target data in the reserved block device, it is specifically used to: if data needs to be written to a storage space corresponding to a third logical address of the merged block device, and it is determined based on the correspondence that the third logical address corresponds to a third physical address of the original block device, then the data is written to a storage space corresponding to the third physical address of the original block device; and / or, if data needs to be read from a storage space corresponding to a fourth logical address of the merged block device, and it is determined based on the correspondence that the fourth logical address corresponds to a fourth physical address of the original block device, then the data is read from a storage space corresponding to the fourth physical address of the original block device.
8. The device according to claim 7, characterized in that When the management module reserves part of the storage space from all the storage spaces of the original block device as the reserved block device, it is specifically used to: obtain the configured reservation mode, obtain the target storage capacity of the storage space to be reserved; select a reserved position matching the reservation mode from all the storage spaces of the original block device; at the reserved position, reserve the storage space matching the target storage capacity as the reserved block device; wherein the reservation mode is header reservation, or tail reservation, or head and tail reservation, or specified reservation, or segment reservation; if the reservation mode is header reservation, the target storage capacity of the storage space to be reserved is selected; and If the reservation mode is tail reservation, the reserved position is the starting position of the original block device; or, if the reservation mode is head and tail reservation, the reserved position is the starting position and the ending position of the original block device; or, if the reservation mode is designated reservation, the reserved position is the designated position of the original block device; or, if the reservation mode is segmented reservation, the reserved position is multiple positions of the original block device, and the interval between two adjacent positions is the same; The mapping information includes a mapping relationship between a logical address of a storage space of a target block device and a physical address of a storage space of an original block device; when the first application operates the target block device based on the mapping information, it is specifically used to: if data needs to be written to a storage space corresponding to a first logical address of the target block device, determine a first physical address corresponding to the first logical address based on the mapping relationship, and write the data to a storage space corresponding to the first physical address of the original block device; and / or, if data needs to be read from a storage space corresponding to a second logical address of the target block device, determine a second physical address corresponding to the second logical address based on the mapping relationship, and read the data from the storage space corresponding to the second physical address of the original block device; If the second application is a DRBD application, the target data includes metadata information corresponding to the DRBD application; when the second application operates the original block device based on the target data in the reserved block device, it is specifically used to: based on the metadata information in the reserved block device, perform a mirroring operation on the original block device to mirror the data in the original block device to another block device; If the second application is a defragmentation application, the target data includes the fragmented data in the target block device; when the second application operates the original block device based on the target data in the reserved block device, it is specifically used to: after storing the fragmented data in the target block device in the reserved block device, if the total amount of data in the reserved block device reaches a preset threshold, the defragmentation application migrates the fragmented data in the reserved block device to the target storage area of the target block device.
9. A block device operating device, characterized in that: include: a processor and a machine-readable storage medium storing machine-executable instructions executable by the processor; Wherein: the processor is used to execute the machine executable instructions to implement the method steps described in any one of claims 1-6.
10. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores a plurality of computer instructions, and when the computer instructions are executed by a processor, the method steps described in any one of claims 1 to 6 can be implemented.
Citation Information
Patent Citations
Data writing method and electronic equipment
CN103714007A
Storage method and device of distributed file system, electronic equipment and storage medium
CN110019083A
Address mapping data backup method and device
CN110187999A
Metadata management method and device
CN110727403A
Data processing method and system
CN110895445A
