Hard disk control method, system and equipment and storage medium

By obtaining and judging the udev event, the mount path of the NVMe hard disk is automatically removed, which solves the problem of disk letter drift caused by hot plugging of NVMe hard disk, and realizes the automation and compatibility of hard disk control.

CN120295823APending Publication Date: 2025-07-11INSPUR BUSINESS MACHINE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510421281.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-03
Publication Date
2025-07-11

AI Technical Summary

Technical Problem

The existing technology causes disk letters to drift when NVMe hard disk is hot-swap, causing Linux applications to fail to recognize hard disks normally. The existing solutions are cumbersome and have poor versatility.

Method used

By obtaining the udev event of the hard disk, we can determine whether the disk letter and event comply with the preset rules, automatically unmount the mount path, and use the udev rules and system files to achieve hard disk control.

Benefits of technology

After the NVMe hard disk is hot removed, the NVMe drive letter occupation is automatically released, and the newly inserted hard disk drive letters are kept consistent, improving the system reliability and maintenance efficiency, and having good compatibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120295823A_ABST
    Figure CN120295823A_ABST
Patent Text Reader

Abstract

The invention discloses a hard disk control method. The hard disk control method comprises the following steps: acquiring an udev event of a hard disk and determining a drive letter of the hard disk according to the udev event; judging whether the drive letter accords with a first preset rule or not; responding to the fact that the drive letter conforms to a first preset rule, and judging whether the udev event conforms to a second preset rule or not; in response to the situation that the udev event accords with a second preset rule, determining a mounting path of the hard disk based on the drive; and carrying out mounting release based on the mounting path. The invention further discloses a system, computer equipment and a readable storage medium. According to the scheme provided by the invention, after the NVMe hard disk is thermally removed, the occupation of the NVMe drive letter can be automatically relieved, and the drive letter of the newly inserted NVMe hard disk is kept consistent with the drive letter before hot plugging.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of servers, and particularly to a hard disk control method, system, device, and storage medium. Background Art

[0002] Under the Linux system, an NVMe (Non-Volatile Memory express) hard disk is uniquely identified by a drive letter, such as NVMe0, NVMe1, etc. To read and write to a certain NVMe hard disk, a Linux application needs to specify its drive letter. For example, by mounting NVMe0n1p1 to a certain directory and reading and writing files in that directory, the purpose of modifying the data stored on the NVMe hard disk can be achieved.

[0003] NVMe hot pluggability means that without shutting down the system or cutting off the power supply, users are allowed to insert and remove NVMe solid-state drives (SSDs). This function is crucial for improving the reliability, availability, and maintainability (RAS) of the system, especially in enterprise-level environments that require high availability and fast fault recovery. However, hot plugging also brings some negative impacts. When an NVMe has been mounted under a certain directory in Linux and a hot removal operation is performed on the NVMe hard disk, since the mounted directory is referencing this NVMe disk, the NVMe drive letter cannot be released. At this time, when a new NVMe hard disk is inserted into the slot where the NVMe was removed, the Linux system can only assign a new NVMe drive letter to the newly inserted hard disk. The change of the drive letter will cause many Linux applications to fail to recognize the disk normally, resulting in various anomalies in many applications.

[0004] Currently, for the problems of hard disk hot plugging drive letter drift and mounting management, existing solutions have many deficiencies. Some solutions solve the drive letter drift problem by manually configuring drive letter mappings or hard-coding drive letter information in applications. However, this method is not only cumbersome but also error-prone and cannot adapt to a dynamically changing hard disk environment. Other solutions rely on specific hardware devices or operating system features to implement hard disk management, with poor generality and difficulty in being popularized and applied on different computer systems and hardware platforms. Summary of the Invention

[0005] In view of this, in order to overcome at least one aspect of the above problems, an embodiment of the present invention provides a hard disk control method, including the following steps: Obtain a udev event of the hard disk and determine the drive letter of the hard disk according to the udev event; Judge whether the drive letter conforms to a first preset rule; In response to the drive letter conforming to the first preset rule, judge whether the udev event conforms to a second preset rule; In response to the udev event conforming to the second preset rule, determine the mounting path of the hard disk based on the drive letter; Unmount based on the mounting path.

[0006] In some embodiments, determining whether the drive letter conforms to the first preset rule further includes: Match the drive letter with the wildcards preset in the first preset rule to determine whether the drive letter conforms to the first preset rule.

[0007] In some embodiments, it further includes: In response to the drive letter not matching the wildcards, ignore the udev event.

[0008] In some embodiments, determining whether the udev event conforms to the second preset rule further includes: Match the udev event of the hard disk according to the second rule, where the second matching rule is set according to the device removal event.

[0009] In some embodiments, in response to the udev event conforming to the second preset rule, determining the mounting path of the hard disk based on the drive letter further includes: Search for multiple data lines carrying the drive letter in a preset file; Screen the data lines carrying the mounting path from the multiple data lines according to the second string of each data line to obtain the mounting path of the hard disk.

[0010] In some embodiments, unmounting based on the mounting path further includes: Call the unmount command to unbind all block devices of the hard disk from the mounting path.

[0011] In some embodiments, it further includes: Record the operation information of the unmounting, where the operation information includes the time of unmounting, the drive letter of the hard disk, and the mounting path.

[0012] Based on the same inventive concept, according to another aspect of the present invention, an embodiment of the present invention further provides a hard disk control system, including: An acquisition module configured to acquire the udev event of the hard disk and determine the drive letter of the hard disk according to the udev event; A first judgment module configured to judge whether the drive letter conforms to the first preset rule; A second judgment module configured to, in response to the drive letter conforming to the first preset rule, judge whether the udev event conforms to the second preset rule; A determination module, configured to determine the mounting path of the hard disk based on the disk drive letter in response to the udev event conforming to a preset rule; A dismounting module, configured to perform dismounting based on the mounting path.

[0013] Based on the same inventive concept, according to another aspect of the present invention, an embodiment of the present invention further provides a computer device, including: At least one processor; and A memory, where the memory stores a computer program that can run on the processor, and when the processor executes the program, it performs the steps of any one of the above-mentioned hard disk control methods.

[0014] Based on the same inventive concept, according to another aspect of the present invention, an embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it performs the steps of any one of the above-mentioned hard disk control methods.

[0015] One of the beneficial technical effects of the present invention is as follows: The solution proposed by the present invention can automatically release the occupation of the NVMe disk drive letter after the NVMe hard disk is hot-removed, and the disk drive letter of the newly inserted NVMe hard disk is the same as that before hot plugging and unplugging. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention, and those of ordinary skill in the art can also obtain other embodiments based on these drawings without creative efforts.

[0017] Figure 1 A flowchart of the hard disk control method provided by the embodiment of the present invention; Figure 2 A schematic diagram of a data row provided by the embodiment of the present invention; Figure 3 A schematic diagram of the structure of the hard disk control system provided by the embodiment of the present invention; Figure 4 A schematic diagram of the structure of the computer device provided by the embodiment of the present invention; Figure 5 A schematic diagram of the structure of the computer-readable storage medium provided by the embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0018] To make the purpose, technical solutions, and advantages of the present invention clearer, the following further details the embodiments of the present invention in conjunction with specific embodiments and with reference to the accompanying drawings.

[0019] It should be noted that all the expressions using "first" and "second" in the embodiments of the present invention are for distinguishing two entities or parameters with the same name but different identities. It can be seen that "first" and "second" are only for the convenience of expression and should not be construed as a limitation on the embodiments of the present invention. This will not be elaborated one by one in the subsequent embodiments.

[0020] According to one aspect of the present invention, an embodiment of the present invention provides a hard disk control method, as Figure 1 shown, which may include the steps of: S1, obtaining the udev event of the hard disk and determining the drive letter of the hard disk according to the udev event; S2, determining whether the drive letter conforms to a first preset rule; S3, in response to the drive letter conforming to the first preset rule, determining whether the udev event conforms to a second preset rule; S4, in response to the udev event conforming to the second preset rule, determining the mounting path of the hard disk based on the drive letter; S5, unmounting based on the mounting path.

[0021] The solution proposed by the present invention can automatically release the occupation of the NVMe drive letter after the NVMe hard disk is hot removed, and the drive letter of the newly inserted NVMe hard disk is the same as that before hot plugging. Among them, the udev event refers to an event generated by the udev device manager when the device status changes in the Linux system. udev is responsible for managing the device nodes in the / dev directory and triggering corresponding events when a device is inserted, removed, or its status changes.

[0022] In some embodiments, determining whether the drive letter conforms to the first preset rule further includes: matching the drive letter with the wildcards preset in the first preset rule to determine whether the drive letter conforms to the first preset rule.

[0023] In some embodiments, it further includes: In response to the drive letter not matching the wildcards, ignoring the udev event.

[0024] In some embodiments, determining whether the udev event conforms to the second preset rule further includes: matching the udev event of the hard disk according to the second rule, where the second matching rule is set according to the device removal event.

[0025] Specifically, based on the obtained drive letter, set the first matching rule according to the drive letter, and then monitor the udev events of the hard disk according to the first rule. udev is a user space tool in the Linux system for managing device files. It can monitor events such as the plugging and unplugging of devices and changes in connection status in real time. By setting the first matching rule related to the drive letter, the system can accurately monitor the udev events of the target type of hard disk. Set the second matching rule according to the device removal event, and then match the udev events of the hard disk according to the second rule. In the hot pluggable scenario of the hard disk, by setting the second matching rule, the system can quickly identify the removal operation of the hard disk. For example, when it is detected that the udev event contains identification information related to device removal, it is determined that the event conforms to the preset rule, providing a basis for subsequent processing.

[0026] For example, Udev rules can be created to monitor NVMe hot removal events. The rules can include 2 matching keys. The first matching key KERNEL == "nvme*n*" means monitoring udev events generated by NVMe devices. When it is necessary to monitor NVMe hard disks, the wildcard (*nvme*n*) of this type of hard disk can be assigned to KERNEL. As long as the drive letter carried in the udev event matches this wildcard, the second pairing key will be matched. If not, the event will be directly ignored; The second matching key ACTION == "remove" means monitoring udev events generated by device removal; The combination of the 2 matching keys represents the udev events generated by the removal of the NVMe device to be monitored.

[0027] The rules can also include 1 action key, RUN+=" / etc / udev / rules.d / udev_nvme_remove.sh$kernel", which means that when the udev event of NVMe device removal is monitored, execute the external program: " / etc / udev / rules.d / udev_nvme_remove.sh $kernel". udev_nvme_remove.sh is the script called after the NVMe hot removal event is detected, and $kernel (drive letter) is the naming given by the Linux kernel to the NVMe partition and is passed as a parameter to the script.

[0028] The written Rules file is named 99-udev-nvme-remove.rules and saved in the / etc / udev / rules.d / directory.

[0029] In some embodiments, in response to the udev event conforming to the second preset rule, determining the mounting path of the hard disk based on the drive letter further includes: Search for multiple data lines carrying the said drive letter in a preset file; Filter out the data lines carrying the mount path from the multiple data lines according to the second string of each data line, so as to obtain the mount path of the hard disk.

[0030] In some embodiments, for unmounting based on the mount path, it further includes: Call the unmount command to unbind all block devices of the hard disk from the mount path.

[0031] Specifically, search for multiple data lines carrying the drive letter in a preset file, and then filter out the data lines carrying the mount path from the multiple data lines according to the second string of each data line, so as to obtain the mount path of the hard disk. In the Linux system, the preset file is usually the " / etc / mtab" file, which is automatically generated and dynamically maintained by the Linux system and records the relevant information of all mounted devices in the current system. By parsing the data lines containing the target drive letter in this file, the mount path of the hard disk can be accurately obtained. This method utilizes the existing file resources of the system to achieve the fast and accurate acquisition of the mount path, providing the necessary information for the subsequent unmount operation.

[0032] For example, the NVMe umount script can be used to release the NVMe occupation and free the NVMe drive letter. The NVMe umount script is the udev_nvme_remove.sh called by the action key included in Rules.

[0033] The passed $kernel parameter (i.e., the drive letter) is the partition name of NVMe, which is assigned to the variable name. Search for all data lines containing the name string in the / etc / mtab file, and the found data lines are the mount point information of the NVMe disk used. Extract the second string of the data line as the mount directory, and call the systemd-umount tool to unmount.

[0034] Such as Figure 2As shown in the figure, the boxed part is the mount information recorded in the mtab file when the NVMe hard disk is mounted to the system directory. nvme1n1p1 is the aforementioned $kernel parameter. The second string " / root / testDirA" is the specific mount path of the NVMe disk. Using it as the execution parameter of the systemd-umount command can unmount the nvme1n1p1 device from the / root / testDirA / directory. After all block devices related to nvme1 are unmounted, the drive letter nvme1 occupied by this NVMe disk is released. At this time, when a new NVMe hard disk is inserted into this slot, the Linux system will assign the drive letter nvme1 to the new NVMe hard disk, thus solving the problem of drive letter drift of the NVMe hard disk during Hotplug.

[0035] In some embodiments, it further includes: Recording the operation information of unmounting, where the operation information includes the time of unmounting, the drive letter of the hard disk, and the mount path.

[0036] Specifically, by recording the operation information of unmounting, the system administrator can conveniently trace and analyze the hard disk operations. When a system failure occurs, the problem can be quickly located, the efficiency of system maintenance can be improved, the system downtime can be reduced, and the normal operation of the system can be guaranteed.

[0037] The solution proposed by the present invention can automatically release the occupation of the NVMe drive letter after the NVMe hard disk is hot-removed, and the drive letter of the newly inserted NVMe hard disk is the same as that before hot-plugging. Moreover, the solution proposed by the present invention is based on general system commands and file operations, and does not depend on specific hardware devices or operating system features, and has good compatibility and versatility.

[0038] Based on the same inventive concept, according to another aspect of the present invention, an embodiment of the present invention further provides a hard disk control system 400, as Figure 3 shown, including: An acquisition module 401, configured to acquire udev events of the hard disk and determine the drive letter of the hard disk according to the udev events; A first judgment module 402, configured to judge whether the drive letter conforms to a first preset rule; A second judgment module 403, configured to respond that the drive letter conforms to the first preset rule and judge whether the udev event conforms to a second preset rule; A determination module 404, configured to respond that the udev event conforms to the preset rule and determine the mount path of the hard disk based on the drive letter; An unmount module 405, configured to perform unmounting based on the mount path.

[0039] The solution proposed by the present invention can automatically release the occupation of the NVMe disk drive letter after the NVMe hard disk is hot-removed, and the disk drive letter of the newly inserted NVMe hard disk is the same as that before hot plugging and unplugging.

[0040] In some embodiments, determining whether the disk drive letter conforms to a first preset rule further includes: Matching the disk drive letter with wildcards preset in the first preset rule to determine whether the disk drive letter conforms to the first preset rule.

[0041] In some embodiments, it further includes: In response to the disk drive letter not matching the wildcards, ignoring the udev event.

[0042] In some embodiments, determining whether the udev event conforms to a second preset rule further includes: Matching the udev event of the hard disk according to the second rule, where the second matching rule is set according to the device removal event.

[0043] In some embodiments, in response to the udev event conforming to the second preset rule, determining the mounting path of the hard disk based on the disk drive letter further includes: Searching for multiple data lines carrying the disk drive letter in a preset file; Filtering the data lines carrying the mounting path from the multiple data lines according to the second string of each data line to obtain the mounting path of the hard disk.

[0044] In some embodiments, unmounting based on the mounting path further includes: Invoking an unmounting command to unbind all block devices of the hard disk from the mounting path.

[0045] In some embodiments, it further includes: Recording the operation information of unmounting, where the operation information includes the time of unmounting, the disk drive letter of the hard disk, and the mounting path.

[0046] The solution proposed by the present invention can automatically release the occupation of the NVMe disk drive letter after the NVMe hard disk is hot-removed, and the disk drive letter of the newly inserted NVMe hard disk is the same as that before hot plugging and unplugging.

[0047] Based on the same inventive concept, according to another aspect of the present invention, as Figure 4 shown, an embodiment of the present invention further provides a computer device 501, including: At least one processor 520; and A memory 510 stores a computer program 511 that can run on a processor. When the processor 520 executes the program, it performs the steps of any of the above hard disk control methods.

[0048] Based on the same inventive concept, according to another aspect of the present invention, as Figure 5 shown, an embodiment of the present invention further provides a computer-readable storage medium 601. The computer-readable storage medium 601 stores a computer program 610. When the computer program 610 is executed by a processor, it performs the steps of any of the above hard disk control methods.

[0049] Finally, it should be noted that those of ordinary skill in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods.

[0050] In addition, it should be understood that the computer-readable storage medium (e.g., memory) herein can be a volatile memory or a non-volatile memory, or can include both volatile memory and non-volatile memory.

[0051] Those skilled in the art will also understand that the various exemplary logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein can be implemented as electronic hardware, computer software, or a combination of both. To clearly illustrate this interchangeability of hardware and software, a general description of the functions of the various illustrative components, blocks, modules, circuits, and steps has been presented. Whether this function is implemented as software or hardware depends on the specific application and the design constraints imposed on the overall system. The functions that those skilled in the art can implement in various ways for each specific application, but this implementation decision should not be construed as causing a departure from the scope of the disclosure of the embodiments of the present invention.

[0052] The above are the exemplary embodiments disclosed by the present invention. However, it should be noted that various changes and modifications can be made without departing from the scope of the disclosure of the embodiments of the present invention defined by the claims. The functions, steps, and / or actions of the method claims according to the disclosed embodiments herein do not need to be performed in any specific order. In addition, although the elements disclosed in the embodiments of the present invention can be described or claimed in an individual form, they can also be understood as plural unless explicitly limited to the singular.

[0053] It should be understood that, as used herein, unless the context clearly supports an exception, the singular form "a" is also intended to include the plural form. It should also be understood that the "and / or" used herein refers to any and all possible combinations of one or more of the associated listed items.

[0054] The serial numbers of the disclosed embodiments of the present invention are only for description and do not represent the superiority or inferiority of the embodiments.

[0055] Those of ordinary skill in the art can understand that all or part of the steps to implement the above embodiments can be completed by hardware, or can be completed by instructing relevant hardware through a program. The program can be stored in a computer-readable storage medium, and the above-mentioned storage medium can be a read-only memory, a magnetic disk, an optical disk, etc.

[0056] Those of ordinary skill in the art should understand that the discussion of any of the above embodiments is only exemplary and is not intended to imply that the scope of the disclosure of the embodiments of the present invention (including the claims) is limited to these examples; under the concept of the embodiments of the present invention, the technical features in the above embodiments or different embodiments can also be combined, and there are many other variations in different aspects of the embodiments of the present invention as above, which are not provided in detail for the sake of brevity. Therefore, any omission, modification, equivalent replacement, improvement, etc. made within the spirit and principle of the embodiments of the present invention shall be included in the protection scope of the embodiments of the present invention.

Claims

1. A hard disk control method, characterized in that, Including the following steps: Obtain the udev event of the hard disk and determine the drive letter of the hard disk according to the udev event; Judge whether the drive letter conforms to the first preset rule; In response to the drive letter conforming to the first preset rule, judge whether the udev event conforms to the second preset rule; In response to the udev event conforming to the second preset rule, determine the mounting path of the hard disk based on the drive letter; Unmount based on the mounting path.

2. The method according to claim 1, wherein Judging whether the drive letter conforms to the first preset rule further includes: Match the drive letter with the wildcards preset in the first preset rule to judge whether the drive letter conforms to the first preset rule.

3. The method according to claim 2, characterized in that It also includes: In response to the drive letter not matching the wildcards, ignore the udev event.

4. The method according to claim 1, wherein Judging whether the udev event conforms to the second preset rule further includes: Match the udev event of the hard disk according to the second rule, where the second matching rule is set according to the device removal event.

5. The method according to claim 1, characterized in that, In response to the udev event conforming to the second preset rule, determining the mounting path of the hard disk based on the drive letter further includes: Search for multiple data lines carrying the drive letter in a preset file; Filter the data lines carrying the mounting path from the multiple data lines according to the second string of each data line to obtain the mounting path of the hard disk.

6. The method according to claim 1, wherein Unmounting based on the mounting path further includes: Call the unmount command to unbind all block devices of the hard disk from the mounting path.

7. The method according to claim 6, wherein It also includes: Record the operation information of unmounting, where the operation information includes the time of unmounting, the drive letter of the hard disk, and the mounting path.

8. A hard disk control system, characterized in that, Including: An acquisition module configured to obtain the udev event of the hard disk and determine the drive letter of the hard disk according to the udev event; A first judgment module configured to judge whether the drive letter conforms to the first preset rule; A second judgment module configured to, in response to the drive letter conforming to the first preset rule, judge whether the udev event conforms to the second preset rule; A determination module configured to, in response to the udev event conforming to the preset rule, determine the mounting path of the hard disk based on the drive letter; An unmounting module configured to unmount based on the mounting path.

9. A computer device, including: At least one processor; And A memory storing a computer program that can run on the processor, characterized in that when the processor executes the program, it executes the steps of the method according to any one of claims 1-7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it executes the steps of the method according to any one of claims 1-7.