Data writing method and device

By reading the reserved fields of metadata in the cluster file system and returning error information or performing write operations, the read-only problem caused by metadata corruption is solved, the isolation of damaged metadata is achieved, and the availability of the system is improved.

CN118568064APending Publication Date: 2024-08-30NEW H3C CLOUD TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410620936.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-17
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

The metadata of the cluster file system is easily damaged, causing the file system to enter a read-only state, affecting the write operation of the virtual machine, and reducing the availability of the system.

Method used

By reading the reserved fields in the file's metadata, if a fault identification is found, an error message is returned; if there is no fault identification, a write operation is performed to isolate damaged metadata.

Benefits of technology

An error message is only returned when the metadata is damaged. Normal metadata files can still be read and written, reducing the impact on virtual machines and businesses and improving the availability of the cluster file system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118568064A
    Figure CN118568064A
Patent Text Reader

Abstract

The invention provides a data writing method and device. The method comprises the following steps: reading a reserved field in metadata of a file according to a write-in request of the file; if the reserved field contains the fault identifier, returning error information; and if the reserved field does not contain the fault identifier, performing write-in operation on the file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for writing data. Background Art

[0002] Cluster file systems (such as OCFS2) can be used in high-availability virtualization systems. Compared with stand-alone file systems (such as ext4, xfs, etc.), cluster file systems have a lot of metadata and a complex metadata layout, which makes the metadata of cluster file systems prone to corruption or errors. Once a cluster file system accesses any damaged metadata, it will trigger the file system to enter a read-only state and cannot be written. In virtualization application scenarios, the read-only state of a cluster file system will cause all virtual machines on the host to be unable to write data, which in turn makes the virtual machines unable to work properly, affecting the customer's production business and greatly reducing the availability of the cluster file system. Summary of the invention

[0003] In order to overcome the problems existing in the related art, this specification provides a data writing method and device.

[0004] According to the first aspect of an embodiment of the present specification, a data writing method is provided, the method comprising: reading a reserved field in the metadata of the file according to a write request of the file; if the reserved field contains a fault identifier, returning an error message; if the reserved field does not contain a fault identifier, performing a write operation on the file.

[0005] According to the second aspect of the embodiments of this specification, a data writing device is provided, comprising: a reading module, used to read a reserved field in the metadata of a file according to a write request of the file; an error reporting module, used to return an error message if the reserved field contains a fault identifier; and a writing module, used to perform a write operation on the file if the reserved field does not contain a fault identifier.

[0006] According to a third aspect of an embodiment of this specification, there is provided a data writing device, including:

[0007] processor;

[0008] a memory for storing processor-executable instructions;

[0009] The processor is configured to: read a reserved field in the metadata of the file according to a write request of the file; return error information if the reserved field contains a fault identifier; and perform a write operation on the file if the reserved field does not contain a fault identifier.

[0010] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:

[0011] In the embodiments of this specification, an error message is returned only when accessing a file with damaged metadata, and files with normal metadata can still be read and written normally, thereby isolating the damaged metadata, thereby reducing the impact on the virtual machine and the business, and improving the availability of the cluster file system.

[0012] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present specification. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the specification and, together with the description, serve to explain the principles of the specification.

[0014] Figure 1 The diagram is a schematic diagram showing a system architecture of a cluster file system according to an exemplary embodiment of the present specification.

[0015] Figure 2 is a flow chart of a data writing method according to an exemplary embodiment of the present specification.

[0016] Figure 3 It is a schematic diagram of metadata according to an exemplary embodiment of the present specification.

[0017] Figure 4 is a flow chart showing another data writing method according to an exemplary embodiment.

[0018] Figure 5 It is a hardware structure diagram of the computer device where the file processing device in the embodiment of this specification is located.

[0019] Figure 6 It is a block diagram of a data writing device according to an exemplary embodiment of the present specification. DETAILED DESCRIPTION

[0020] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.

[0021] The terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit this specification. The singular forms "a", "the" and "the" used in this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0022] It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, this 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 this specification, 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, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0023] Next, the embodiments of this specification are described in detail.

[0024] The following combination Figure 1 The cluster file system to which the data writing method and device are applicable in the embodiments of this specification is described. It should be noted that: Figure 1 What is shown is merely an example of a system architecture to which the embodiments of this specification can be applied, to help those skilled in the art understand the technical content of this specification, but it does not mean that the embodiments of this specification cannot be used in other devices, systems, environments or scenarios.

[0025] Figure 1 The diagram is a schematic diagram showing a system architecture of a cluster file system according to an exemplary embodiment of the present specification.

[0026] like Figure 1 As shown, the system architecture may include, for example, multiple nodes. Each node may be a physical host (KVM host) running a KVM (kernel-based Virtual Machine) virtualization system. QEMU and OCFS2 modules may be deployed in each node. QEMU is an open source virtual machine monitoring program that provides simulation, control, and management functions for virtual machines. The OCFS2 module may be used to provide file system services, such as data storage, data indexing, metadata management, and the like. The OCFS2 module may provide shared storage support for a multi-node cluster, allowing multiple nodes to simultaneously access and share file system data.

[0027] Multiple nodes can be connected and exchange data based on SAN (Storage Area Network) In a SAN environment, nodes can use LUN to access storage resources in storage devices. Through LUN, nodes can directly perform block-level data read and write operations on storage devices, just like accessing local disks. LUN is the abbreviation of Logical Unit Number, which is used to uniquely identify and access logical units or logical volumes in storage devices. Each LUN corresponds to a logical storage unit in a storage device, which can be identified and accessed, just like an independent logical disk.

[0028] The data writing method provided in the embodiments of this specification is described in detail below. Figure 2 As shown, Figure 2 This is a flow chart of a data writing method according to an exemplary embodiment of this specification. The method can be applied to a cluster file system. The data writing method provided in the embodiment of this specification may include the following steps.

[0029] In step 210, according to a write request for the file, a reserved field in the metadata of the file is read.

[0030] According to an embodiment of the present specification, a write request may be used to request writing data into a file.

[0031] According to an embodiment of the present specification, metadata may include a reserved field, which is a field that is not used in the current version and is reserved for future use or a specific purpose. Metadata may include, for example, inode (index node) metadata, dinode (distributed index node) metadata, etc.

[0032] In step 220, if the reserved field contains a fault indicator, step 230 is executed. If the reserved field does not contain a fault indicator, step 240 is executed.

[0033] According to an embodiment of the present specification, for a file in a file system, it is possible to detect whether the metadata of the file is damaged. If it is detected that the metadata is damaged, a fault indicator is written into a reserved field of the metadata.

[0034] In step 230, an error message is returned.

[0035] According to an embodiment of the present specification, the error information may be used to indicate that an error has occurred in the metadata, for example, it may be an EIO (input output error).

[0036] In step 240, a write operation is performed on the file.

[0037] According to an embodiment of the present disclosure, for example, the data to be written corresponding to the write request may be written into the file.

[0038] According to the data writing method of the embodiment of the present specification, the read-only mechanism of the cluster file system is improved, and the cluster file system can continue to read and write normally after the metadata is damaged.

[0039] In virtualization application scenarios, after SAN storage anomalies or link anomalies are restored, the metadata of the cluster file system may be corrupted. Related technologies In the case of corruption of cluster file system metadata, when a user accesses this file and issues a write I / O operation, the cluster file system will first read the metadata block and then perform a metadata consistency check. If the check data is wrong, the file system will be remounted as read-only, which will affect all write operations of upper-layer services.

[0040] According to the embodiments of the present specification, an error message is returned only when accessing a file with damaged metadata, and files with normal metadata can still be read and written normally, thereby isolating the damaged metadata, thereby reducing the impact on the virtual machine and the business, and improving the availability of the cluster file system.

[0041] Figure 3 It is a schematic diagram of metadata according to an exemplary embodiment of the present specification.

[0042] like Figure 3 As shown, the metadata (ocfs2_dinode) may include, for example, i_signature (signature), i_generation (version identifier), alloc_slot (allocation slot), alloc_bit (allocation bit), i_clusters (clusters), i_uid (user identification number), i_gid (group identification number), i_size (size), i_blockno (block number), i_suballoc_loc (sub-allocation block location information), i_reserved2 (reserved field), I_tree_depth (tree depth), I_count (number), I_next_free_rec (next available record), etc.

[0043] In this embodiment, the error flag may be added in the i_reserved2 field, for example.

[0044] According to an embodiment of the present specification, writing the fault identifier into the reserved field of metadata includes: constructing a target structure, the target structure including the fault identifier and the fault time, and then writing the target structure into the reserved field of metadata.

[0045] For example, in this embodiment, a new structure can be designed as a damage mark. The structure can be filled into the reserved field i_reserved2[2] of the metadata. The definition of the structure is as follows.

[0046]

[0047]

[0048] The first member of the structure, _u8 i_corruption[8], can be an 8-byte fixed string "CORRUPT", which is a special signature (marker) used to indicate that the file's metadata is corrupted. The second member, i_ctime, can be used to record the time when the metadata is corrupted.

[0049] Optionally, after the fault identifier is written into the reserved field of the metadata, it is possible to detect whether the metadata of the file has returned to normal at predetermined intervals starting from the time of the fault. If the metadata of the file has returned to normal, the target structure in the reserved field of the metadata is deleted. The predetermined duration can be set according to actual needs.

[0050] For example, in this embodiment, a new function can be newly designed and implemented

[0051] ocfs2_mark_inode_corrupt() is used to mark the error flag of metadata. You can write the error flag to the metadata by calling this function. The definition of this function is as follows.

[0052]

[0053] The above function implements filling error flags into metadata and writing them to disk.

[0054] For example, in this embodiment, a new error check function ocfs2_check_inode_corrupt() can be designed and implemented to determine whether the metadata is damaged. The function can be called to determine whether the metadata is damaged. If the metadata is judged to have an error mark, it means that the metadata has been damaged and isolated. For read and write I / O requests, an EIO error is returned instead of remounting the file system as read-only, so as to avoid affecting the write I / O requests of all files.

[0055]

[0056] Optionally, detecting whether the metadata of a file is damaged may include, for example: performing metadata structure detection, metadata content detection and logical consistency detection on the metadata of the file. If the metadata of the file fails to pass at least one of the metadata structure detection, metadata content detection and logical consistency detection, it is determined that the metadata is damaged. Metadata structure detection may include detecting whether the organization and structure of the metadata are correct, including the connection relationship of the directory tree, the pointing relationship between the various parts of the file, etc. Metadata content detection may include checking whether various attributes stored in the metadata are correct, and whether the physical data pointed to in the metadata exists, so as to ensure the correctness and integrity of the metadata content. Logical consistency detection of metadata may include checking whether the size of the file matches the allocated data blocks, checking whether the permissions of the file are correct, etc.

[0057] like Figure 4 FIG. 1 is a flowchart of another data writing method according to an exemplary embodiment. Based on the above-mentioned embodiment, this embodiment describes a data writing process, including the following steps:

[0058] In user space, a program sends a data write request to the kernel (eg, kernel) by calling a file operation system call (eg, write()).

[0059] In the kernel space, after the kernel receives a write request from a user program, it can check whether the file to be written exists, whether the user has the appropriate permissions, and whether the location to be written is legal. If the check is passed, the kernel will convert the request into a write request VFS_write of the virtual file system (VFS) layer. VFS is an abstract layer in the kernel space, which is responsible for managing different file systems in the system and converting operation requests of different file systems into general file operations. Exemplarily, in this embodiment, for VFS_write, an ocfs2 data write operation can be performed, including: reading the block block of metadata to obtain metadata. Determine whether the reserved field of the metadata contains an error identifier. If an error identifier is included, an error message EIO is returned. If an error identifier is not included, further detect whether the metadata of the file is damaged. If the metadata is not damaged, the data is written to the corresponding position of the disk according to the request. If metadata damage is detected, a fault identifier is written to the reserved field of the metadata, and an error message EIO is returned.

[0060] In the related art, when the file metadata in the cluster file system is damaged, the user business accesses the file and issues a write I / O operation. The cluster file system will first read the block corresponding to the metadata, and then detect whether the metadata is damaged. If a data error is detected, the file system will be remounted to a read-only state, affecting all write I / O operations of the upper-level business.

[0061] According to the embodiments of the present specification, an error message is returned only when accessing a file with damaged metadata, and files with normal metadata can still be read and written normally, thereby isolating the damaged metadata, thereby reducing the impact on the virtual machine and the business, and improving the availability of the cluster file system.

[0062] Corresponding to the embodiments of the aforementioned method, this specification also provides embodiments of a data writing device and a terminal to which it is applied.

[0063] The embodiments of the data writing device of this specification can be applied to computer devices, such as servers or terminal devices. The device embodiments can be implemented by software, hardware, or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory and running them. From the hardware level, if Figure 5 The figure is a hardware structure diagram of the computer device where the data writing device of the embodiment of this specification is located, except Figure 5 In addition to the processor 510, memory 530, network interface 520, and non-volatile memory 540 shown, the server or electronic device where the device 531 is located in the embodiment may also include other hardware according to the actual function of the computer device, which will not be described in detail.

[0064] like Figure 6 As shown, Figure 6 1 is a block diagram of a data writing device according to an exemplary embodiment of the present specification, the device comprising:

[0065] The reading module 610 is used to read the reserved field in the metadata of the file according to the write request of the file;

[0066] An error reporting module 620, configured to return an error message if the reserved field contains a fault identifier;

[0067] The writing module 630 is used to perform a writing operation on the file if the reserved field does not contain a fault indicator.

[0068] Optionally, the data writing device further includes

[0069] A corruption detection module is used to detect whether the metadata of a file is corrupted;

[0070] The fault identification module is used for writing a fault identification into a reserved field of the metadata if metadata corruption is detected.

[0071] Optionally, the fault identification module may include:

[0072] A construction submodule is used to construct a target structure, which includes a fault identifier and a fault time;

[0073] The writing submodule is used to write the target construct into the reserved field of the metadata.

[0074] Optionally, the damage detection module may include:

[0075] The detection submodule is used to perform metadata structure detection, metadata content detection and logical consistency detection on the metadata of the file;

[0076] The determination submodule is used to determine that the metadata is damaged if the metadata of the file fails to pass at least one of the metadata structure detection, the metadata content detection and the logical consistency detection.

[0077] Optionally, the data writing device may further include:

[0078] A normal detection module, used to detect whether the metadata of the file returns to normal at predetermined intervals starting from the time of the failure after the failure identifier is written into the reserved field of the metadata;

[0079] The deletion module is used to delete the target structure in the reserved field of the metadata if the metadata of the file returns to normal.

[0080] According to the embodiments of the present specification, an error message is returned only when accessing a file with damaged metadata, and files with normal metadata can still be read and written normally, thereby isolating the damaged metadata, thereby reducing the impact on the virtual machine and the business, and improving the availability of the cluster file system.

[0081] Correspondingly, the present specification also provides a data writing device, which includes a processor; a memory for storing processor executable instructions; wherein the processor is configured to: read a reserved field in the metadata of a file according to a write request of the file; if the reserved field contains a fault identifier, return an error message; if the reserved field does not contain a fault identifier, perform a write operation on the file.

[0082] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, which will not be repeated here.

[0083] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. A person of ordinary skill in the art can understand and implement it without paying creative labor.

[0084] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0085] Those skilled in the art will readily appreciate other embodiments of the specification after considering the specification and practicing the invention claimed herein. The specification is intended to cover any variations, uses or adaptations of the specification that follow the general principles of the specification and include common knowledge or customary techniques in the art that are not claimed in the specification. The specification and examples are to be considered exemplary only, and the true scope and spirit of the specification are indicated by the following claims.

[0086] It should be understood that the present description is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present description is limited only by the appended claims.

[0087] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.

Claims

1. A data writing method, characterized in that: The method comprises: Reading a reserved field in metadata of the file according to a write request of the file; If the reserved field contains a fault indicator, an error message is returned; If the reserved field does not contain a fault indicator, a write operation is performed on the file.

2. The method according to claim 1, characterized in that The method further comprises: Detecting whether metadata of the file is damaged; If the metadata is detected to be corrupted, a fault indicator is written into a reserved field of the metadata.

3. The method according to claim 2, characterized in that The step of writing the fault identification into the reserved field of the metadata comprises: Constructing a target structure, wherein the target structure includes a fault identifier and a fault time; The target construct is written into a reserved field of the metadata.

4. The method according to claim 2, characterized in that: The detecting whether the metadata of the file is damaged comprises: Performing metadata structure detection, metadata content detection and logical consistency detection on the metadata of the file; If the metadata of the file fails to pass at least one of the metadata structure check, the metadata content check, and the logical consistency check, it is determined that the metadata is damaged.

5. The method according to claim 3, characterized in that: After writing the fault identifier into the reserved field of the metadata, the method further includes: Starting from the moment of the failure, at predetermined intervals, detecting whether the metadata of the file returns to normal; If the metadata of the file returns to normal, the target structure in the reserved field of the metadata is deleted.

6. A data writing device, characterized in that: The device comprises: A reading module, used for reading a reserved field in metadata of a file according to a write request of the file; An error reporting module, configured to return an error message if the reserved field contains a fault identifier; A writing module is used for performing a writing operation on the file if the reserved field does not contain a fault identifier.

7. The device according to claim 6, characterized in that The device also includes A damage detection module, used to detect whether the metadata of the file is damaged; The fault identification module is used to write a fault identification into a reserved field of the metadata if the metadata is detected to be damaged.

8. The device according to claim 7, characterized in that The fault identification module comprises: A construction submodule, used for constructing a target structure, wherein the target structure includes a fault identifier and a fault time; The writing submodule is used to write the target structure into the reserved field of the metadata.

9. The device according to claim 7, characterized in that The damage detection module comprises: A detection submodule, used for performing metadata structure detection, metadata content detection and logical consistency detection on the metadata of the file; A determination submodule is used to determine that the metadata is damaged if the metadata of the file fails to pass at least one of the metadata structure detection, the metadata content detection and the logical consistency detection.

10. The device according to claim 8, characterized in that The device also includes: A normal detection module, configured to detect whether the metadata of the file returns to normal at predetermined intervals starting from the moment of the failure after the failure identifier is written into the reserved field of the metadata; The deletion module is used to delete the target structure in the reserved field of the metadata if the metadata of the file returns to normal.

Citation Information

Patent Citations

  • Data file writing method and system and data file reading method and system

    CN103605479A

  • File system maintenance and repairing method and apparatus

    CN105354102A

  • File aggregation compatible method and device, computer equipment and storage medium

    CN113704027A

  • File lock implementation method and device, equipment and storage medium

    CN116244034A