Equipment cloning method, storage equipment and storage medium
By obtaining the non-idle block number and physical address in the storage device, writing valid data to the target block, establishing an address mapping relationship, solving the problem of low reproduction efficiency and physical layout loss of storage device operation problems, and achieving efficient device cloning and problem solving.
Patent Information
- Application Number
- CN202310533762.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-11
- Publication Date
- 2024-11-12
AI Technical Summary
When solving the problem of the storage device operation, the efficiency of reproducing the device problem is inefficient, and the original physical layout may be lost after testing, which increases the difficulty of solving the problem.
By obtaining the non-idle blocks and their numbers in the storage device, determining the physical address of valid data, and writing it into the target block, establishing a mapping relationship between the logical address and the physical address, and reproducing the physical layout of the storage device.
It improves the efficiency of reproducing equipment problems, ensures the integrity of the physical layout of the storage device, and reduces the difficulty of solving equipment problems.
Smart Images

Figure CN118939174A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of storage technology, and in particular to a device cloning method, a storage device, and a storage medium. Background Art
[0002] Generally speaking, during the use of storage devices, a specific physical layout will be formed as data is written, erased, and other operations are performed. At the same time, as the storage device is used for a longer time, device problems such as performance degradation, increased latency, or command timeouts may occur, and these device problems may be related to the specific physical layout.
[0003] In the related art, to solve such device problems, a series of tests are usually performed on the storage device, such as reading data according to the logical address and then writing data according to the logical address, that is, imitating the reading and writing process of the storage device. However, such methods will change the physical layout of the data in the storage device. If the device problem is not solved after the test, the original physical layout will be lost, increasing the difficulty of reproducing and solving the device problem. Summary of the invention
[0004] The embodiment of the present application discloses a device cloning method, which solves the technical problem of low efficiency in reproducing device problems when device problems that affect the operation of storage devices occur.
[0005] The present application provides a device cloning method, which is applied to a storage device. The method includes: obtaining each non-free block in the storage device; obtaining a target block in a target device connected to the storage device, wherein the target block has a corresponding number with each non-free block; obtaining a physical address corresponding to valid data in each non-free block; and writing the valid data into the target block with the corresponding number based on the number and the physical address.
[0006] In some embodiments of the present application, the method also includes: obtaining the physical address of the last data written in the non-free block; determining the data storage area of the non-free block based on the physical address of the last data written; and determining the target storage area of the target block based on the data storage area.
[0007] In some embodiments of the present application, writing the valid data into a target block with a corresponding number based on the number and the physical address includes: determining the target block based on the number; determining the physical location of a page of the valid data in the target block based on the physical address; and writing the valid data into the physical location of the corresponding page.
[0008] In some embodiments of the present application, the method also includes: obtaining a position in the target storage area of the target block that is not the physical position, filling in virtual variables to replicate the position of invalid data in the data storage area; if there are other areas in the target block except the target storage area, setting the pages corresponding to the other areas to free pages.
[0009] In some embodiments of the present application, the method also includes: obtaining the logical address of the valid data, the logical address being the same as the target logical address for writing the valid data into the target device; after writing the valid data into the target block, triggering the target device to obtain the target physical address of the valid data in the target device, and establishing an address mapping relationship between the target logical address and the target physical address.
[0010] In some embodiments of the present application, the method further includes: obtaining block information of each data block in the storage device; if the block information of any data block does not include an idle indication mark, determining that any data block is the non-idle block.
[0011] In some embodiments of the present application, obtaining the physical address corresponding to the valid data in each non-free block includes: obtaining a bitmap identifier of the valid data in each non-free block, the bitmap identifier being used to indicate the storage position of the valid data in the non-free block; and obtaining the valid data and the physical address corresponding to the valid data based on the storage position of the valid data in the non-free block.
[0012] In some embodiments of the present application, the method further includes: each non-free block in the storage device does not include a bad block.
[0013] The present application also provides a storage medium, on which at least one instruction is stored, and when the at least one instruction is executed by a processor, the device cloning method is implemented.
[0014] The present application also provides a storage device, which includes a processor and a storage medium, and the processor is used to execute at least one instruction stored in the storage medium to implement the device cloning method.
[0015] In the device cloning method of the present application, first, each non-free block and the number corresponding to the non-free block are obtained in the storage device, so that when the target block is created in the target device, the target block has a number corresponding to the number of the non-free block; secondly, the physical address corresponding to the valid data in the non-free block is read, and the storage address of the valid data in the target block can be determined based on the physical address representing the storage location of the valid data; finally, according to the number and the physical address, the valid data can be written to the target block with the corresponding number, so that the physical layout of the storage device can be reproduced, and the efficiency of reproducing device problems can be improved to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 It is a schematic diagram of an application scenario of the device cloning method provided in an embodiment of the present application.
[0017] Figure 2 It is a flow chart of the device cloning method provided in an embodiment of the present application.
[0018] Figure 3 It is a schematic diagram of the data storage area and the target storage area provided in the embodiment of the present application.
[0019] Figure 4 This is a flowchart of a device cloning method provided by another embodiment of the present application. DETAILED DESCRIPTION
[0020] To facilitate understanding, some illustrations of concepts related to the embodiments of the present application are given by way of example for reference.
[0021] It should be noted that in this application, "at least one" means one or more, and "more than one" means two or more than two. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The terms "first", "second", "third", "fourth", etc. (if any) in the specification, claims and drawings of this application are used to distinguish similar objects, rather than to describe a specific order or sequence.
[0022] Generally speaking, during the use of storage devices, a specific physical layout will be formed as data is written, erased, and other operations are performed. At the same time, as the storage device is used for a longer time, device problems such as performance degradation, increased latency, or command timeouts may occur, and these device problems may be related to the specific physical layout.
[0023] In the related art, to solve such device problems, a series of tests are usually performed on the storage device, such as reading data according to the logical address and then writing data according to the logical address, that is, imitating the reading and writing process of the storage device. However, such methods will change the physical layout of the data in the storage device. If the device problem is not solved after the test, the original physical layout will be lost, increasing the difficulty of reproducing and solving the device problem.
[0024] In order to reduce the difficulty of reproducing device problems and improve the efficiency of reproducing device problems, embodiments of the present application provide a device cloning method, a storage device, and a storage medium.
[0025] In order to better understand the device cloning method, storage device, and storage medium provided in the embodiments of the present application, the application scenario of the device cloning method of the present application is first described below.
[0026] Figure 1 Schematic diagram of the application scenario of the device cloning method provided in the embodiment of the present application. The device cloning method provided in the embodiment of the present application is applied to a storage device 1, and the storage device 1 may be a Universal Flash Storage (UFS) device, an Embedded MultiMedia Card (eMMC), a Solid State Drive (SSD), a Secure Digital (SD) card and other devices. The storage device 1 includes, but is not limited to, a memory 12 connected via a communication bus 11 and at least one processor 13, wherein the memory 12 includes a plurality of data blocks (Blocks), each data block includes a plurality of pages (Pages), each page can be used to store written data, and the memory 12 may be a Nand flash, that is, the storage device uses Nand flash as a storage medium, and the processor 13 may also be referred to as a flash controller.
[0027] Storage device 1 and storage device 2 are connected to host 3. Storage device 2 can be a device of the same model as storage device 1. Storage device 2 includes, but is not limited to, a memory 22 and at least one processor 23 connected via a communication bus 21. Storage device 2 is used to clone the physical layout of storage device 1. First, host 3 is an electronic device provided with data reading software. It can read out valid data in storage device 1 according to the physical address of valid data and store it in host 3 in the form of a binary file. Host 3 can also be connected to a card reader to read valid data of storage device 1 using the card reader. Host 3 obtains the valid data through the card reader. When host 3 receives a cloning request from target device 2 or detects that it is connected to target device 2, it can write valid data stored in host 3 to target device 2, thereby cloning storage device 1. For the sake of distinction, in the embodiments of the present application, storage device 2 is described by taking target device as an example.
[0028] The indication Figure 1 It is only an example of the storage device 1 and does not constitute a limitation of the storage device 1. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the storage device 1 may also include input and output devices, network access devices, etc.
[0029] See also Figure 2 As shown, Figure 2 is a flowchart of a device cloning method provided in an embodiment of the present application, which is applied to a storage device (eg Figure 1 According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.
[0030] Step S201, obtaining each non-free block in the storage device.
[0031] In some embodiments of the present application, a mapping table is stored in a storage device, and the mapping table is used to record the mapping relationship between a logical address (Logical Block Address, LBA) (for example, a first logical address) and a physical address (Physics Block Address, PBA). The storage device can be connected to a host to receive data written by the host. The host may include, but is not limited to, a mobile phone, a tablet computer, a personal computer (Personal Computer, PC), a workstation, a server, and a personal digital assistant (Personal Digital Assistant, PDA). The host accesses the Nand flash in the storage device through the first logical address, and the Nand flash accesses the data block and the page in the data block through the physical address. When the host writes data to the storage device, it searches for the first logical address stored in the storage device, searches for the physical address of the written data block through the first logical address, and writes the data sent by the host into the page corresponding to the data block.
[0032] In some embodiments of the present application, Nand flash may include free blocks and non-free blocks. Free blocks may be data blocks that do not store data, and non-free blocks may be data blocks that store data. Pages in non-free blocks may store invalid data and valid data. When the host updates the data at a certain logical address, the device writes the new data on a new page, the physical address corresponding to the logical address is updated, and the data on the old physical address page becomes invalid data. Therefore, in each block of Nand flash, valid data and invalid data will be alternately distributed. In other embodiments, free pages may also be stored in non-free blocks, which is not limited by the present application. Free blocks may be provided with free indication marks. When cloning a storage device, free blocks may be excluded by searching for free indication marks, and data blocks that do not contain free indication marks may be retained as non-free blocks. For example, an integer "0" is used as a free indication mark of a free block. When a data block carrying the integer "0" is found, it is determined to be a free block. The free indication mark may also be marked in other ways, which is not limited by the present application.
[0033] In some embodiments of the present application, a non-free block may contain a bad block (BB), which refers to a data block in a solid state drive (SSD) and a NAND flash memory (Nand flash) where some flash areas cannot be erased or programmed. Since the Nand flash performs read and program operations in units of pages, and performs erase operations in units of blocks, and an erase operation needs to be performed before a programming operation, a minimum operable unit may be a block. If any unrepairable bit error occurs in the entire block, it can be determined that the block is a bad block.
[0034] In some embodiments of the present application, after all non-free blocks in the Nand flash are determined, bad blocks in the non-free blocks are excluded, and non-free blocks after the bad blocks are excluded are obtained.
[0035] Step S202, obtaining a target block in a target device connected to the storage device, wherein the target block and each non-free block have a corresponding number.
[0036] In some embodiments of the present application, the model of the storage device is obtained, and a target device with the same model is determined based on the model of the storage device, and the physical layout of the storage device is cloned using the target device. After determining that all non-free blocks in Nandflash do not contain bad blocks, these non-free blocks are numbered. The physical address of the storage device is usually intervals of Block. Therefore, each non-free block can be numbered according to the physical order of writing each Block, such as non-free block 1, non-free block 2, ..., non-free block n. Since the storage device and the target device are devices of the same model, and there are also multiple free target blocks in the target device, the target blocks in the target device can be numbered, and the number of the target blocks can be the same as the number of the non-free blocks of the storage device, such as target block 1, target block 2, ..., target block n.
[0037] In other embodiments, the target block numbering may also be different from the non-free block numbering of the storage device. The non-free blocks in the storage device may be numbered as non-free block 1, non-free block 2, ..., non-free block n, and the target blocks in the target device may be numbered as target block A1, target block A2, ..., target block An, wherein non-free block 1 corresponds to target block A1, non-free block 2 corresponds to target block A2, ..., and non-free block n corresponds to target block An.
[0038] In the embodiments of the present application, the numbers of the non-free blocks and the numbers of the target blocks may have the same relationship or a corresponding relationship, and the present application does not limit this.
[0039] Step S203, obtaining the physical address corresponding to the valid data in each non-free block.
[0040] In some embodiments of the present application, when recording the storage location of valid data, a valid data bitmap (VBM) can be used for recording. A non-free block refers to a data block whose bit is not 0. The valid data bitmap corresponding to a non-free block contains multiple binary bits, for example, 0100011101010…01010. The data length of the binary bit is about 262144. The non-free block contains irregularly distributed 0s and 1s. Each data block corresponds to a valid data bitmap, and each storage location of valid data corresponds to a bitmap identifier, so that the valid data bitmap can be used to quickly find and move valid data. Therefore, after determining the non-free block, the physical location of the valid data in the non-free block can be obtained by searching the bitmap identifier, so that the valid data can be obtained according to the physical location, and the physical address of the valid data can be further obtained.
[0041] Step S204, based on the number and the physical address, write the valid data into the target block with the corresponding number.
[0042] In some embodiments of the present application, based on the physical address of the valid data in the non-free block, the valid data corresponding to each physical address is read, but invalid data and free pages may also exist in the non-free block. However, the invalid data cannot generate an address mapping, but it will occupy the storage area in the non-free block. Therefore, in addition to determining the physical location of the valid data, the location of the invalid data needs to be filled on the target device.
[0043] Therefore, a non-free block may include a data storage area and other areas (e.g., an area containing free pages), and the data storage area of the non-free block can be determined based on the physical address of the last data written in the non-free block by obtaining the physical address of the last data written in the non-free block. Furthermore, based on the data storage area of the storage device, the target storage area of the target block in the target device can be determined.
[0044] For example, in some examples, Figure 3 is a schematic diagram of a data storage area and a target storage area provided in an embodiment of the present application, such as Figure 3 As shown, there are non-free blocks numbered 1 and non-free blocks numbered 2 in the storage device, wherein a pattern shown in one row and one column indicates that the page is valid data, a pattern shown in the intersection area of one row and three columns indicates that the page is invalid data, and a pattern shown in the intersection area of four rows and three columns indicates that the page is a free page. The free blocks in the target device are numbered, and based on the numbering of the non-free blocks by the storage device, free blocks numbered 1 and free blocks numbered 2 are established in the target device.
[0045] In some embodiments of the present application, the data storage area of valid data and invalid data is determined, specifically, as follows: Figure 3 As shown, the physical address of the last written data in the non-free block is obtained. For example, in the storage device, the page corresponding to the physical address of the last written data of the non-free block numbered 1 is the intersection area of four rows and two columns, indicating that the data of the non-free block numbered 1 is only stored in the intersection area of four rows and two columns, and the remaining intersection areas of four rows and three columns and four rows and four columns are free pages. Similarly, in the storage device, the page corresponding to the physical address of the last written data of the non-free block numbered 2 is the intersection area of four rows and four columns, indicating that there is no free page in numbered 2. After determining the data storage area of the storage device, the target storage area of the free block corresponding to the number of the target device can be determined. For example, the non-free block numbered 1 in the storage device corresponds to the free block numbered 1 in the target device, and the physical address of the last written data of the free block numbered 1 in the target device is also the intersection area of four rows and two columns. Since the data storage area is the same as the target storage area, the target storage area of the free block numbered 2 in the target device can be determined according to the data storage area of the non-free block numbered 2 in the storage device.
[0046] In some embodiments of the present application, after determining the target storage area of the target device, the valid data is written into the target block based on the physical address of the valid data. Specifically, Figure 3 As shown, read the valid data in the storage device, for example, read the valid data in the non-free block numbered 1 in the storage device, for example, read the valid data in the page corresponding to the pattern shown in one row and one column, and obtain the physical address of the valid data, determine the physical position of the page where the valid data is located in the target block, and write the valid data into the physical position corresponding to the target device. Then, obtain the position other than the non-physical position in the target storage area of the target block, that is, the intersection area of one row and three columns and the intersection area of three rows and two columns of the target block numbered 1 in the target device, fill in the intersection area of one row and three columns and the intersection area of three rows and two columns with virtual variables, which are used to represent invalid data in the storage device in the target device. After writing the valid data into the target device and filling in the virtual variables in the target device, if there are other areas in the target device, then the pages kept in the other areas are free pages, for example, the intersection area of four rows and three columns and the intersection area of four rows and four columns of the target block numbered 1 in the target device are free pages.
[0047] In some embodiments of the present application, the logical address of valid data in the storage device is consistent with the logical address of the target device. The logical address of the target device is used as the target logical address. After the valid data is written to the target block, the target physical address of the valid data in the target device is generated. An address mapping relationship between the target logical address and the target physical address can be established in the target device, and the address mapping relationship is stored in an address mapping relationship table. The address mapping relationship table also includes the numbering information of each block, which is usually expressed as a 32-bit integer. The target device can locate the target block corresponding to the target device by querying the address mapping relationship table.
[0048] In an embodiment of the present application, first, after determining the one-to-one correspondence between the non-free blocks of the storage device and the target blocks in the target device, based on the target storage area of the target device and the physical address of the valid data in the non-free blocks, read the valid data corresponding to each physical address, and write the read valid data into the target device, thereby reproducing the physical layout of the valid data in the storage device, and secondly, after writing the valid data into the target device, in the target storage area, the position where the valid data is not written is filled with a virtual variable to reproduce the physical layout of the invalid data in the storage device. The embodiment of the present application can ensure the complete cloning of the physical layout in the storage device, because when testing whether the storage device has a fault, it is necessary to simulate the operations of writing, reading, erasing, etc. of the data, at this time, the physical layout of the storage device will be changed. If the test is unsuccessful or other fault problems occur, then the original physical layout cannot be reproduced, and the device problem caused by the original physical layout may not be obtained, which increases the difficulty of detecting problems in the storage device.
[0049] Figure 4 is a flow chart of a device cloning method provided by another embodiment of the present application, such as Figure 4 The embodiment shown is described by taking the storage device as a UFS device, and provides a complete process flow of cloning a UFS device, including the following steps:
[0050] Step S401, obtaining each non-free block in the UFS device after excluding bad blocks.
[0051] Step S402: number each non-free block.
[0052] Step S403, obtaining a target block in a target device connected to the UFS device, and numbering the target block based on the number of each non-free block, so that the target block and each non-free block have corresponding numbers.
[0053] Step S404: determine the data storage area based on the physical address of the last written data in the non-free block.
[0054] Step S405 , reading valid data in the data storage area according to the bitmap identifier, and obtaining a physical address corresponding to the valid data.
[0055] Step S406, based on the number and the physical address, write the valid data into the target block with the corresponding number.
[0056] Step S407, determining a target storage area according to the data storage area, obtaining the location of the ineffective data in the target storage area, and filling in the dummy variable.
[0057] Please continue reading Figure 1 In this embodiment, the storage device 1 and the storage device 2 have the same function, that is, the memory 12 and the memory 22 have the same function, and the processor 13 and the processor 23 have the same function. Therefore, the memory 12 and the processor 13 of the storage device 1 are taken as an example for description. The memory 12 may be the internal memory of the storage device 1, that is, the memory built into the storage device 1. In other embodiments, the memory 12 may also be the external memory of the storage device 1, that is, the memory externally connected to the storage device 1.
[0058] In some embodiments, the memory 12 is used to store program codes and various data, and to achieve high-speed and automatic access to programs or data during the operation of the storage device 1.
[0059] The memory 12 may include a random access memory and may also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0060] In one embodiment, the processor 13 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor, or the processor may be any other conventional processor, etc.
[0061] If the program code and various data in the memory 12 are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, such as the device cloning method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device that can carry the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), etc.
[0062] It is understandable that the module division described above is a logical function division, and there may be other division methods in actual implementation. In addition, the functional modules in each embodiment of the present application may be integrated in the same processing unit, or each module may exist physically separately, or two or more modules may be integrated in the same unit. The above-mentioned integrated modules may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0063] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present application and are not intended to limit it. Although the present application has been described in detail with reference to the preferred embodiments, a person of ordinary skill in the art should understand that the technical solution of the present application may be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present application.
Claims
1. A device cloning method, applied to a storage device, characterized in that: The method comprises: Obtain each non-free block in the storage device; Acquire a target block in a target device connected to the storage device, wherein the target block has a corresponding number to each of the non-free blocks; Obtaining the physical address corresponding to the valid data in each non-free block; Based on the number and the physical address, the valid data is written into a target block with a corresponding number.
2. The method according to claim 1, characterized in that The method further comprises: Obtaining the physical address of the last written data in the non-free block; Determine the data storage area of the non-free block based on the physical address of the last written data; Based on the data storage area, a target storage area of the target block is determined.
3. The method according to claim 2, characterized in that The step of writing the valid data into a target block with a corresponding number based on the number and the physical address comprises: Based on the number, determining the target block; Based on the physical address, determining the physical location of the page of the valid data in the target block; The valid data is written into the physical location where the corresponding page is located.
4. The method according to claim 3, characterized in that The method further comprises: Acquire a position other than the physical position in the target storage area of the target block, and fill in a dummy variable to reproduce the position of the invalid data in the data storage area; If there are other areas except the target storage area in the target block, pages corresponding to the other areas are set as free pages.
5. The method according to claim 1, characterized in that The method further comprises: Acquire a logical address of the valid data, where the logical address is the same as a target logical address for writing the valid data into a target device; After the valid data is written into the target block, the target device is triggered to obtain the target physical address of the valid data in the target device, and an address mapping relationship between the target logical address and the target physical address is established.
6. The method according to claim 1, characterized in that The method further comprises: Obtaining block information of each data block in the storage device; If the block information of any data block does not include an idle indication mark, it is determined that the any data block is the non-idle block.
7. The method according to claim 1, characterized in that The obtaining of the physical address corresponding to the valid data in each non-idle block includes: Acquire a bitmap identifier of the valid data in each of the non-free blocks, wherein the bitmap identifier is used to indicate a storage location of the valid data in the non-free blocks; Based on the storage location of the valid data in the non-free block, the valid data and the physical address corresponding to the valid data are obtained.
8. The method according to claim 1, characterized in that The method further includes: each non-free block in the storage device does not include a bad block.
9. A storage medium, characterized in that: The storage medium stores at least one instruction, and when the at least one instruction is executed by the processor, the device cloning method according to any one of claims 1 to 8 is implemented.
10. A storage device, characterized in that: The storage device comprises: A processor and the storage medium as claimed in claim 9, wherein the processor is configured to execute at least one instruction stored in the storage medium to implement a device cloning method.
