Control method of storage device and electronic device

By locking the storage device after a data operation fails, temporarily storing subsequent operation instructions, and waiting for the host to read the error information, the problem of the storage device error state being overwritten is solved, and timely error handling of the storage device is achieved.

CN122337409APending Publication Date: 2026-07-03INSPUR SUZHOU INTELLIGENT TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
INSPUR SUZHOU INTELLIGENT TECH CO LTD
Filing Date
2026-06-02
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

During read/write operations on storage devices, error codes may fail to be transmitted back to the host in a timely manner due to storage media issues, resulting in the error status being overwritten and unable to be processed promptly.

Method used

After a data operation on the storage device fails, it enters a locked state, temporarily stores subsequent operation instructions, and waits for the host to read the error information before executing them, ensuring that the error information is not overwritten.

Benefits of technology

This ensures that errors in storage devices are handled promptly, preventing error codes from being overwritten, and ensuring that errors in storage devices are always addressed in a timely manner.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122337409A_ABST
    Figure CN122337409A_ABST
Patent Text Reader

Abstract

This application discloses a control method and electronic device for a storage device, relating to the field of storage technology. The method includes: responding to a data operation instruction from a host device and executing a corresponding data operation; generating a corresponding error message and performing a locking operation when the data operation fails and a locking condition is met; the locking operation is used to put the storage device into a locked state; while the storage device is in a locked state, it temporarily stores other received data operation instructions in a task queue and does not execute the data operation instructions in the task queue; when the error message is read by the host device and the locked state is exited, other data operation instructions in the task queue are executed sequentially based on the receiving order. This disclosed embodiment can avoid the situation where error states and error codes are overwritten by other instructions, achieving the technical effect that errors in the storage device can always be handled promptly.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of storage technology, and in particular to a control method and electronic device for a storage device. Background Technology

[0002] In related technologies, a storage system includes an initiator and a target, where the initiator is the host and the target is the storage device. During the instruction exchange between the initiator and the target, if the target storage device cannot complete a read / write operation due to storage media issues, such as bad sectors on the disk, it will generate a corresponding error code. At this point, the target storage device needs to wait for the initiator's host to retrieve the error code via instruction exchange.

[0003] When a single logical volume is mapped to multiple hosts, if the host that triggered the read / write error fails to send back the error code in a timely manner, subsequent read / write operations from other hosts may overwrite the current error state of the storage device. In this case, the host that triggered the error will be unable to obtain the error code, resulting in the storage device error going unhandled. Summary of the Invention

[0004] This application provides a control method and electronic device for a storage device, to at least solve the problem in the related art where the error state of the storage device is overwritten, causing the host to be unable to obtain the error code, and thus the error of the storage device cannot be processed.

[0005] This application provides a method for controlling a storage device, including: In response to data operation commands from the host device, execute the corresponding data operations; If a data operation fails and the locking condition is met, a corresponding error message is generated and a locking operation is performed. The locking operation is used to put the storage device into a locked state. When the storage device is in a locked state, the storage device will temporarily store other received data operation instructions in the task queue and will not execute the data operation instructions in the task queue. When the error message is read by the host device and the locked state is released, other data operation instructions in the task queue are executed sequentially based on the receiving order.

[0006] This application also provides a control device for a storage device, including: The execution module is used to respond to data operation commands from the host device and execute the corresponding data operations. In addition, if a data operation fails and the locking condition is met, a locking operation is performed; the locking operation is used to put the storage device into a locked state; while the storage device is in a locked state, the storage device temporarily stores other received data operation instructions to the task queue and does not execute the data operation instructions in the task queue; when exiting the locked state, other data operation instructions in the task queue are executed sequentially based on the receiving order.

[0007] This application also provides an electronic device, including: a memory for storing a computer program; and a processor for implementing the control method of any of the above-described memory devices when executing the computer program.

[0008] This application also provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, it implements the steps of the control method of any of the above-described storage devices.

[0009] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the control method for any of the above-described storage devices.

[0010] This application addresses the issue of locking the storage device after a data operation fails, placing it in a locked state. In this locked state, the storage device does not respond to data operation commands from other host devices or the current host. Instead, it temporarily stores subsequent received data operation commands in a task queue. This prevents error states and error codes from being overwritten by other commands, thus resolving the problem in related technologies where the storage device's error state is overwritten, preventing the host from obtaining error codes and thus hindering error handling. The application achieves the technical effect of ensuring that storage device errors are always handled promptly. Attached Figure Description

[0011] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 A schematic diagram of the architecture of a storage device and a host according to some embodiments of this disclosure is shown; Figure 2 A flowchart illustrating a method for controlling a storage device according to some embodiments of the present disclosure is shown; Figure 3 A structural block diagram of a control device for a storage device according to some embodiments of the present disclosure is shown; Figure 4 Structural block diagrams of electronic devices according to some embodiments of the present disclosure are shown. Detailed Implementation

[0013] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.

[0014] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0015] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0016] The specific application environment architecture or specific hardware architecture on which the execution of the control method for the storage device depends is described here.

[0017] Figure 1 A schematic diagram of the architecture of a storage device and a host is shown for some embodiments of this disclosure. For example... Figure 1 As shown, in a SCSI (Small Computer System Interface) based storage architecture, a storage device 100 can be mapped to multiple host devices 102 simultaneously.

[0018] Some of the nouns or terms that appear in the description of the embodiments of this application shall be interpreted as follows: SCSI stands for Small Computer System Interface.

[0019] CHECK CONDITION: This is an error classification code, which is information defined in the SCSI specification for classifying Sense Data. It is used to prompt the host device to check the storage device and take appropriate actions based on the check results.

[0020] Read command: also known as REQUEST SENSE command. The host device can use the read command to read sense data from the storage device to find out the specific reason why the storage device returned the CHECK CONDITION state in a previous operation.

[0021] CLEAR TASK SET: A command used to manage the task queue of a storage device. It clears all currently unfinished tasks from the storage device's task queue.

[0022] LOG SELECT: A command in the SCSI specification used to configure the logging parameters of a storage device or to write log information to the storage device. The host device uses this command to set the logging behavior of the storage device.

[0023] LOG SENSE: A command in the SCSI specification used to read log information from storage devices. Host devices use this command to obtain various operating statuses, error statistics, and performance data recorded inside the storage device.

[0024] ABORT TASK: A command in the SCSI specification used to terminate a specific incomplete task on a device. The host device uses this command to specify the termination of a single task. WRITE: A write command in the SCSI specification. The host device uses this command to transfer data to SCSI storage devices (such as hard drives, storage arrays, etc.) and store it in the storage medium.

[0025] READ: The read command in the SCSI specification. The host device uses this command to retrieve data from the storage medium of SCSI storage devices (such as hard drives, storage arrays, etc.).

[0026] INQUIRY: A query command in the SCSI specification. Host devices use this command to query basic information and attributes of SCSI storage devices (such as hard drives, storage arrays, etc.).

[0027] TASK SET FULL: A status indicator in the SCSI specification, used to indicate that the task set of a certain logical unit has reached its maximum capacity and can no longer receive new task commands.

[0028] COMMAND ACCEPTED: A flag in the SCSI specification used to indicate the execution status of a command, signifying that the target storage has received the command and has begun execution.

[0029] Task Set: A collection of all incomplete tasks associated with a specific logical unit in the SCSI specification.

[0030] Sense Data: This refers to the status information returned by storage devices (such as hard drives, storage arrays, etc.) to host devices in the SCSI specification. It is used to report errors, warnings, or abnormal states that occur during operation.

[0031] Sense Key: A component of Sense Data that indicates the overall classification of error types.

[0032] ASC: Additional Sense Code, a component of Sense Data that includes a detailed description of the status information.

[0033] CDB: Command Descriptor Block, which is used in the SCSI specification to store the communication commands between the host and storage.

[0034] WWPN: World Wide Port Name, which is a globally unique port name and a unique identifier for the physical port on the adapter.

[0035] In related technologies, during SCSI interaction, when an error occurs while the target storage device is executing a read / write command, the storage device will enter a CHECK CONDITION state and wait for the initiating host device to send a command to relay the corresponding error status back to the host device. The host device then takes appropriate action based on the received error status. For example, when an unrecoverable read error exists on the storage device, the storage device must wait for the host device to actively initiate a command before the host device can obtain this error information. Upon receiving this error information, the host device will cease accessing the corresponding logical unit within the storage device.

[0036] If the host device fails to send the EQUEST SENSE command to retrieve error information (Sense Data) in a timely manner, subsequent commands from the same or other host devices will overwrite the current error status. When the error status is not retrieved by the host device, diagnostic data will be lost.

[0037] Meanwhile, since error states on storage devices are cleaned up after reading, when an error state is brought back to the host device by other non-EQUESTSENSE instructions, the host device may ignore the error in its processing logic, resulting in errors on the storage device not being processed in a timely manner.

[0038] In scenarios where multiple host devices share a storage device, the attribution of error states is unclear when multiple host devices send commands simultaneously. Therefore, error information may be captured by a host device that did not trigger the error. For example, a server cluster shares a disk array via the SCSI protocol. When a WRITE command sent by host device A fails due to bad sectors on the disk, if host device B initiates a READ command before host device A sends an EQUEST SENSE command to retrieve Sense Data, the storage device will clear the error state triggered by host device A's WRITE command. This results in the loss of error information, making it impossible to pinpoint the exact location of the bad sectors and delaying fault recovery.

[0039] To address the aforementioned issues, embodiments of this application provide a method for controlling a storage device. The method is described in detail below, taking into account the execution flow of the storage device control method.

[0040] In some embodiments of this disclosure, a method for controlling a storage device is provided. Figure 2 A flowchart illustrating a control method for a storage device according to some embodiments of the present disclosure is shown, such as... Figure 2 As shown, the method includes: S202, responding to the data operation command of the host device, executes the corresponding data operation.

[0041] In this embodiment of the disclosure, data operation instructions include, but are not limited to, read (READ) instructions and write (WRITE) instructions. For example, the data operation corresponding to a read instruction is to access the corresponding logical unit of the storage device to obtain the target data.

[0042] For example, the data operation corresponding to the write instruction is to write the target data into the target logical unit in the storage device.

[0043] S204 If the data operation fails and the locking condition is met, generate the corresponding error message and perform the locking operation.

[0044] In this embodiment of the disclosure, the locking operation is used to put the storage device into a locked state; when the storage device is in a locked state, the storage device temporarily stores other data operation instructions received into the task queue and does not execute the data operation instructions in the task queue.

[0045] In this case, a data operation failure means that the storage device failed to successfully execute the data operation sent by the host device. For example, the host device sends a read command to the storage device, instructing it to read data stored in logical unit A of the storage device. If an unrecoverable read error exists in logical unit A, the data in logical unit A cannot be read, and the read command fails.

[0046] For example, the host device sends a write command to the storage device, instructing it to write target data to logical unit B of the storage device. If the disk sector corresponding to logical unit B has bad sectors, the target data cannot be written to logical unit B, and the write command fails.

[0047] When a data operation fails, the storage device generates corresponding error messages. For example, it may generate information about bad sectors on the disk or errors in logical units.

[0048] When a data operation fails, it is determined whether the locking condition is met. For example, the locking condition can be used to determine whether the current storage device supports a locking state. If the locking condition is not met, such as when the current storage device does not support a locking state, the original control logic continues execution.

[0049] When the locking conditions are met, the storage device is controlled to perform a locking operation. After the locking operation is completed, the storage device will enter a locked state. In the locked state, the storage device will not respond to subsequent data operation commands, but will instead temporarily store these data operation commands in the task queue. Therefore, it can be guaranteed that the error status and error code will not be overwritten by other commands before the error information is read by the host device.

[0050] S206, when the error message is read by the host device and the locked state is exited, other data operation instructions in the task queue are executed sequentially based on the receiving order.

[0051] In this embodiment of the disclosure, when the error information is read by the correct host device, the storage device exits the locked state. At this time, the storage device executes the data operation instructions in the task queue in sequence according to the order of one or more received data operation instructions, thereby fulfilling the data operation requirements of other host devices.

[0052] In this embodiment, a locking operation is performed on the storage device after a data operation fails, causing the storage device to enter a locked state. In the locked state, the storage device will not respond to data operation commands from other host devices or other data operation commands from the current host. Instead, it temporarily stores subsequently received data operation commands in a task queue. Therefore, it can prevent error states and error codes from being overwritten by other commands. This solves the problem in related technologies where the error state of the storage device is overwritten, preventing the host from obtaining the error code and thus hindering the processing of errors in the storage device. This achieves the technical effect of ensuring that errors in the storage device are always processed promptly.

[0053] Optionally, in some embodiments of this disclosure, after performing the locking operation, the method further includes: Upon receiving a read command from the host device, the system responds to the read command by obtaining the read status of the error information being read by the host device. Once the error information has been read by the host device, the system performs an unlock operation. The unlock operation is used to release the storage device from the locked state, and the read command is used to read the error information corresponding to the data operation.

[0054] In this embodiment of the disclosure, the read instruction is the REQUEST SENSE instruction. The host device can obtain the error information corresponding to a data operation failure by reading the instruction. For example, the error information is SenseData.

[0055] For example, taking SCSI communication between a host device and a storage device as an example, after a data operation on the storage device fails, a CHECK CONDITION is generated in the storage device to prompt the host device to check the storage device. When the host device reads the CHECK CONDITION, it sends a REQUEST SENSE command to the storage device, and reads the Sense Data through the REQUEST SENSE command to obtain the error information that caused the data operation to fail.

[0056] After the storage device receives a read command from the host device, it indicates that the host device has obtained the necessary error information. At this point, the storage device performs an unlock operation and switches from the locked state to the normal operating state. When unlocking, the storage device executes the data operation commands that were temporarily stored in the task queue during the locked state in the order they were received.

[0057] This embodiment of the disclosure controls the storage device to exit the locked state only after receiving a read command sent by the host device. Therefore, it can ensure that error information triggered by the data operation command of the host device can be correctly obtained by the host device, so that errors on the storage device can be handled in a timely manner.

[0058] Optionally, in some embodiments of this disclosure, the method further includes, prior to performing the locking operation: In the event of a data operation failure, an error classification code is generated; the error classification code is used to instruct the host device to send a read command to the storage device; upon receiving any command from the host device, the host device reads the error classification code.

[0059] In this embodiment of the disclosure, the error classification code is referred to as CHECK CONDITION. The error classification code enables the definition of error information classification and prompts the host device that reads the error classification code to check the storage device.

[0060] For example, after the storage device fails to perform a data operation instructed by the host device, the storage device generates a CHECK CONDITION based on the type of problem that caused the data operation failure.

[0061] A CHECK CONDITION is generated in the storage device to prompt the host device to perform a check on the storage device. When the host device sends any command to the storage device, such as a read command, write command, or query command, the storage device returns a CHECK CONDITION to the host device. After reading the CHECK CONDITION, the host device further sends a REQUEST SENSE command to the storage device to read the Sense Data, thereby obtaining the error information that caused the data execution operation to fail.

[0062] For example, in order to ensure that the error information is received by the correct host device, that is, the host device that sent the data operation instruction that caused the data operation to fail to the storage device, the CHECK CONDITION can be linked to the host device based on the IP link.

[0063] For example, in the event of a data operation failure, the IP link that received the data operation instruction is identified; the IP link is a link between the host device and the storage device using an IP address; the host device is bound to the error classification code based on the IP link; when the error classification code is bound to the host device, the error classification code is only read by the bound host device.

[0064] By binding the host device to the error classification code via IP link, it can be ensured that the error classification code will only be read by the correct host device.

[0065] This embodiment of the disclosure generates an error classification code when a data operation fails on a storage device. The host device that sent the data operation instruction that caused the data operation to fail obtains the classification code, thereby further obtaining error information and performing corresponding repair operations, which can prevent the loss of error information.

[0066] In some embodiments of this disclosure, the locking conditions may optionally include: the storage device supports the locking operation, the host device instructs the storage device to enable the device function corresponding to the locking operation, and an error classification code is generated.

[0067] In this embodiment of the disclosure, when a data operation by the storage device fails, if a locking condition is met, the storage device performs a locking operation to enter a locked state. The locking condition includes that the storage device supports locking operations.

[0068] For example, a reserved custom field in the INQUIRY command of the SCSI protocol can be used to indicate whether the storage device supports locking operations, and whether the host device instructs the storage device to enable the device function corresponding to the locking operation. For example, a locking support bit is added to the INQUIRY command of the SCSI protocol. This locking support bit can be located in the storage device's Standard Inquiry Data, serving as a flag indicating to the initiating host device whether the storage device supports locking. A value of 0 indicates that the storage device does not support locking operations. A value of 1 indicates that the storage device supports locking operations.

[0069] The locking condition also includes the host device instructing the storage device to enable the device function corresponding to the locking operation. For example, the host device can communicate whether to enable the locking function to the storage device via the control byte bit 3 of the SCSI command description block (CDB). When the value of this field is 1, it indicates that the host device requests the storage device to perform a locking operation when an error is encountered during data operation. When the field is 0, it indicates that the device function corresponding to the locking operation is not enabled.

[0070] The locking condition also includes whether an error classification code has been generated. For example, when an error occurs during the execution of SCSI commands, such as READ, WRITE, and FORMAT commands on the storage device, causing the command execution to fail, it is determined whether the error type requires a CHECK CONDITION, i.e., whether an error classification code needs to be generated. If the error type requires a CHECK CONDITION, the corresponding error classification code is generated. For example, media errors, command parameter errors, and device busy are error types that require a CHECK CONDITION.

[0071] This embodiment of the disclosure determines whether the locking conditions are met before performing a locking operation. If the locking conditions are met, the storage device is controlled to perform a locking operation to ensure that error information can be obtained by the correct host device. If the locking conditions are not met, the locking operation is not performed, and the error handling mechanism in the SCSI specification is followed. Therefore, it is compatible with storage devices that do not support locking functionality, improving the compatibility of the storage device control method.

[0072] Optionally, in some embodiments of this disclosure, after performing the lock-exit operation, the method further includes: Receive repair commands sent by the host device; In response to a repair command, the corresponding repair operation is executed, and the corresponding repair result is returned to the host device.

[0073] In this embodiment of the disclosure, after the host device obtains error information through a read instruction, the storage device performs an unlock operation and exits the locked state. After the host device obtains the error information, it determines the repair method for fixing the error based on the error information and the error classification code, and sends the corresponding repair instruction to the storage device.

[0074] Upon receiving a repair instruction, the storage device performs the corresponding repair operation to attempt to fix the error. After the repair operation is completed, the storage device returns the repair result to the host device.

[0075] For example, the storage device executes a read command instructed by the host device. During the execution of the read command, the storage device detects bad blocks in the target storage area indicated by the read command, causing the data read operation indicated by the read command to fail. At this time, an error classification code is generated, indicating an unrecoverable read media error. After the host device reads the corresponding error information, it determines that the corresponding repair method is formatting, and then the host device sends a formatting command for the target storage area to the storage device. After receiving the formatting command, the storage device formats the target storage area and returns a successful formatting repair result to the host device after the formatting is completed.

[0076] The embodiments disclosed herein ensure that error information causing data operation instructions to fail can be obtained by the correct host device. Therefore, the host device can always issue repair instructions to the storage device in a timely manner to fix the error, so that problems on the storage device can be dealt with in the first instance.

[0077] Optionally, in some embodiments of this disclosure, corresponding data operations may be performed, including: The target storage block is determined based on the data manipulation instructions; the target storage block is used to store data. Perform data operations on the target storage block.

[0078] In this embodiment of the disclosure, the host device instructs the storage device to perform data operations corresponding to the data operation instructions by sending data operation instructions to the storage device. These data operation instructions include read operations and write operations.

[0079] Data manipulation instructions specify the target storage block. For example, the target storage block can be a specific logical unit or a specific sector on a disk.

[0080] Taking a read instruction as an example, a read instruction specifies that data should be read from a target storage block. Upon receiving a read instruction, the storage device determines the target block based on the instruction, performs a read operation on the target block, reads the data stored in the target block, and returns the result to the host device that sent the read instruction.

[0081] Taking a write instruction as an example, a write instruction specifies that target data should be written to a target storage block. Upon receiving a write instruction, the storage device determines the indicated target block based on the write instruction and writes the target data corresponding to the write instruction into the target block.

[0082] This disclosure's embodiments locate the corresponding target storage block based on data operation instructions. If a data operation on the target storage block fails, error information associated with the target storage block is generated, and a locking operation is performed when locking conditions are met. This ensures that the host device can obtain the error information of the target storage block and perform repair operations on it. The method provided by this disclosure enables timely handling of problems occurring in storage blocks within the storage device.

[0083] Optionally, in some embodiments of this disclosure, a data operation is determined to have failed if one or more of the following conditions are met: The target storage block is corrupted, the command parameters for data operations on the target storage block are incorrect, or the storage medium corresponding to the target storage block is busy.

[0084] In this embodiment of the disclosure, after the storage device receives a data operation instruction sent by the host device, the storage device performs a corresponding data operation, such as a read operation or a write operation, on the target storage block indicated by the data operation instruction.

[0085] For example, during a data operation, such as a read operation, if the target storage block is corrupted, the storage device will be unable to read the data stored in the target storage block. Similarly, during a write operation, if the target storage block is corrupted, the storage device will be unable to write the target data to the target storage block. In this case, the data operation is determined to have failed, the storage device generates a corresponding error classification code, and performs a locking operation.

[0086] For example, during data operations, errors at the logical, hardware, or software driver levels can cause command parameter errors. For instance, at the logical level, command parameter errors can occur when file system metadata is corrupted, such as a corrupted partition table, a corrupted master boot record, or an abnormal file allocation table. At the hardware level, command parameter errors can also occur when the storage medium is physically damaged, such as with bad sectors, worn-out heads, disk damage, interface damage, or mismatched interface parameters. At the software driver level, command parameter errors can also occur when a data operation instruction references an invalid memory pointer or when the disk driver malfunctions. In such cases, the data operation is determined to have failed, the storage device generates a corresponding error classification code, and performs a locking operation.

[0087] For example, during instruction data operation, if the storage medium corresponding to the target storage block does not respond for an extended period, a message indicating that the storage medium is busy will be returned, meaning that the storage medium cannot respond to the data instruction operation in a timely manner. In this case, the data operation is also determined to have failed, the storage device generates a corresponding error classification code, and performs a locking operation.

[0088] When problems such as target storage block corruption, incorrect command parameters for data operations on target storage block, and / or the storage medium corresponding to target storage block being busy occur, a CHECK CONDITION must be returned, and a corresponding error classification code will be generated.

[0089] This embodiment of the disclosure generates an error classification code based on the specific error type when a data operation fails. The error classification code instructs the host device to retrieve the error information in a timely manner, thereby avoiding the loss of error information and ensuring that errors on the storage device can be processed promptly.

[0090] Optionally, in some embodiments of this disclosure, the method further includes: When a target instruction is received while the device is in a locked state, the device responds to the target instruction and executes the corresponding instruction operation. The target instruction includes a query instruction for querying device information and device attributes of the storage device, and a query instruction for querying logical units in the storage device that are available to the host device.

[0091] In this embodiment of the disclosure, after the storage device enters the locked state, the storage device will temporarily store the received data operation instructions in the task queue, and will not execute these data operations before exiting the locked state.

[0092] However, for target instructions, even if the storage device is locked, it will still respond to these target instructions and execute the corresponding instruction operations.

[0093] For example, the target instruction includes a query instruction for querying device information and device attributes of the storage device, namely the INQUIRY instruction.

[0094] For example, the target instruction also includes a query instruction for querying logical units in the storage device that are available to the host device, namely the REPORT LUN instruction.

[0095] The INQUIRY and REPORT LUN commands are key instructions used by host devices to discover storage devices. Their primary function is to detect whether the logical disks within the storage device are present. Receiving these commands indicates that one or more host devices are attempting to discover the storage device. Failure to execute the corresponding command might cause the sending host device to identify the storage device as offline or absent. Therefore, even if the storage device is locked, it will still respond to the command.

[0096] It is understandable that when a storage device enters a locked state, it will still respond to read commands from the host device, namely the REQUEST SENSE command, to ensure that the host device can obtain the error information corresponding to the failure of data operation through the read command.

[0097] This embodiment of the disclosure ensures that the storage device can still receive target instructions even when it is in a locked state, thereby ensuring that the storage device can be discovered by other host devices and that both the host device and the storage device can work normally.

[0098] Optionally, in some embodiments of this disclosure, before performing the corresponding data operation in response to a data operation instruction from the host device, the method further includes: Receive control commands sent by the host device; the control commands include a target field. Based on the target field, enable or disable the device function corresponding to the lock operation.

[0099] In this embodiment of the disclosure, the host device can instruct the storage device whether to enable the device function corresponding to the locking operation when performing the current data operation by sending control commands to the storage device.

[0100] For example, the control instruction is a SCSI command description block, which includes a target field. For example, the target field is the Control Byte bit 3 in the command description block. After the storage device receives the control instruction, it reads the value of the target field. If the value of the target field is 1, that is, the value of the Control Byte bit 3 field is 1, then the device function corresponding to the locking operation is enabled, and a locking operation is performed when an error is encountered during data operation.

[0101] If the value of the target field is 0, that is, the value of the Control Byte bit3 field is 0, the device function corresponding to the locking operation is disabled, and errors encountered during data operation are handled in accordance with the error handling method of the SCSI specification.

[0102] The embodiments of this disclosure can specify whether the target storage device should enable the locking function when performing data operations each time a data operation command is sent, thereby achieving precise control over the locking function and adapting to the compatible control of different storage devices.

[0103] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.

[0104] Embodiments of this application also provide a control device for a storage device. Figure 3 Structural block diagrams of the control apparatus for a storage device according to some embodiments of the present disclosure are shown, such as Figure 3 As shown, the control device 300 includes: Execution module 302 is used to execute corresponding data operations in response to data operation instructions from the host device; Furthermore, if a data operation fails and the locking condition is met, a corresponding error message is generated, and a locking operation is performed. The locking operation is used to put the storage device into a locked state. When the storage device is in a locked state, the storage device temporarily stores other received data operation instructions in the task queue and does not execute the data operation instructions in the task queue. When the error message is read by the host device and the locked state is exited, other data operation instructions in the task queue are executed sequentially based on the receiving order.

[0105] In this embodiment, a locking operation is performed on the storage device after a data operation fails, causing the storage device to enter a locked state. In the locked state, the storage device will not respond to data operation commands from other host devices or other data operation commands from the current host. Instead, it temporarily stores subsequently received data operation commands in a task queue. Therefore, it can prevent error states and error codes from being overwritten by other commands. This solves the problem in related technologies where the error state of the storage device is overwritten, preventing the host from obtaining the error code and thus hindering the processing of errors in the storage device. This achieves the technical effect of ensuring that errors in the storage device are always processed promptly.

[0106] In some embodiments of this disclosure, optionally, the execution module is further configured to, upon receiving a read instruction sent by the host device, obtain the read status of the error information being read by the host device in response to the read instruction; and, upon the completion of the read of the error information by the host device, perform an exit lock operation; the exit lock operation is used to release the storage device from the locked state, and the read instruction is used to read the error information corresponding to the data operation.

[0107] This embodiment of the disclosure controls the storage device to exit the locked state only after receiving a read command sent by the host device. Therefore, it can ensure that error information triggered by the data operation command of the host device can be correctly obtained by the host device, so that errors on the storage device can be handled in a timely manner.

[0108] In some embodiments of this disclosure, the control device may optionally include a generation module for generating an error classification code in the event of a data operation failure; the error classification code is used to instruct the host device to send a read instruction to the storage device; and the host device reads the error classification code upon receiving any instruction from the host device.

[0109] This embodiment of the disclosure generates an error classification code when a data operation fails on a storage device. The host device that sent the data operation instruction that caused the data operation to fail obtains the classification code, thereby further obtaining error information and performing corresponding repair operations, which can prevent the loss of error information.

[0110] In some embodiments of this disclosure, the locking conditions may optionally include: the storage device supports the locking operation, the host device instructs the storage device to enable the device function corresponding to the locking operation, and an error classification code is generated.

[0111] This embodiment of the disclosure determines whether the locking conditions are met before performing a locking operation. If the locking conditions are met, the storage device is controlled to perform a locking operation to ensure that error information can be obtained by the correct host device. If the locking conditions are not met, the locking operation is not performed, and the error handling mechanism in the SCSI specification is followed. Therefore, it is compatible with storage devices that do not support locking functionality, improving the compatibility of the storage device control method.

[0112] Optionally, in some embodiments of this disclosure, the control device further includes a receiving module for receiving repair instructions sent by the host device; The execution module is also used to respond to repair commands, perform corresponding repair operations, and return the corresponding repair results to the host device.

[0113] The embodiments disclosed herein ensure that error information causing data operation instructions to fail can be obtained by the correct host device. Therefore, the host device can always issue repair instructions to the storage device in a timely manner to fix the error, so that problems on the storage device can be dealt with in the first instance.

[0114] Optionally, in some embodiments of this disclosure, the control device further includes a determining module for determining a target storage block according to data operation instructions; the target storage block is used to store data. The execution module is also used to perform data operations on the target storage block.

[0115] This disclosure's embodiments locate the corresponding target storage block based on data operation instructions. If a data operation on the target storage block fails, error information associated with the target storage block is generated, and a locking operation is performed when locking conditions are met. This ensures that the host device can obtain the error information of the target storage block and perform repair operations on it. The method provided by this disclosure enables timely handling of problems occurring in storage blocks within the storage device.

[0116] Optionally, in some embodiments of this disclosure, the determining module is further configured to determine that the data operation has failed if one or more of the following conditions are met: The target storage block is corrupted, the command parameters for data operations on the target storage block are incorrect, or the storage medium corresponding to the target storage block is busy.

[0117] This embodiment of the disclosure generates an error classification code based on the specific error type when a data operation fails. The error classification code instructs the host device to retrieve the error information in a timely manner, thereby avoiding the loss of error information and ensuring that errors on the storage device can be processed promptly.

[0118] In some embodiments of this disclosure, optionally, the execution module is further configured to respond to the target instruction and execute the instruction operation corresponding to the target instruction when the target instruction is received while in a locked state; wherein, the target instruction includes a query instruction for querying device information and device attributes of the storage device, and a query instruction for querying logical units in the storage device that are available to the host device.

[0119] This embodiment of the disclosure ensures that the storage device can still receive target instructions even when it is in a locked state, thereby ensuring that the storage device can be discovered by other host devices and that both the host device and the storage device can work normally.

[0120] Optionally, in some embodiments of this disclosure, the receiving module is further configured to receive control instructions sent by the host device; the control instructions include a target field; The control device also includes a control module for enabling or disabling the device function corresponding to the lock operation based on the target field.

[0121] The embodiments of this disclosure can specify whether the target storage device should enable the locking function when performing data operations each time a data operation command is sent, thereby achieving precise control over the locking function and adapting to the compatible control of different storage devices.

[0122] For a description of the features in the embodiment corresponding to the control device of the storage device, please refer to the relevant description in the embodiment corresponding to the control method of the storage device, which will not be repeated here.

[0123] Embodiments of this application also provide an electronic device. Figure 4 Structural block diagrams of electronic devices according to some embodiments of the present disclosure are shown, such as Figure 4 As shown, the electronic device 400 includes a memory 402 and a processor 404. The memory 402 stores a computer program, and the processor 404 is configured to run the computer program to perform the steps in any of the above-described embodiments of the control method for the storage device.

[0124] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above-described embodiments of the control method for a storage device when it is run.

[0125] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0126] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above method embodiments.

[0127] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps in any of the above method embodiments.

[0128] Any of the components, modules, units, parts, methods, and operations described herein can be implemented using software, firmware, hardware (e.g., fixed logic circuitry), manual processing, or any combination thereof. Alternatively or additionally, any functionality described herein can be executed at least in part by one or more hardware logic components, such as, but not limited to, a central processing unit (CPU), a field-programmable gate array (FPGA), an application-specific integrated circuit (ASIC), an application-specific standard product (ASSP), a system-on-a-chip (SoC), a complex programmable logic device (CPLD), a microprocessor (MCU), etc. The terms "system," "computing device," or "apparatus" as used herein encompass various means, devices, and machines for processing data, including, for example, one or more programmable processors, computers, SoCs, or combinations thereof. The apparatus may also include code that creates an execution environment for the computer program in question, such as code constituting processor firmware, a protocol stack, a database management system, an operating system, a cross-platform runtime environment, a virtual machine, or one or more combinations thereof. The aforementioned computer program (also known as a program, software, software application, app, script, or code) can be written in any form of programming language, including compiled or interpreted languages, declarative or procedural languages, and can be deployed in any form, including as a standalone program or as a module, component, subroutine, object, or other unit suitable for a computing environment.

[0129] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0130] The control method and electronic device for a storage device provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and its core ideas. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.

Claims

1. A method for controlling a storage device, characterized in that, The method includes: In response to data operation commands from the host device, execute the corresponding data operations; If the data operation fails and the locking condition is met, a corresponding error message is generated and a locking operation is performed. The locking operation is used to put the storage device into a locked state. When the storage device is in the locked state, the storage device temporarily stores other received data operation instructions to the task queue and does not execute the data operation instructions in the task queue. When the error message is read by the host device and the locked state is exited, the data operation instructions in the task queue are executed sequentially based on the receiving order.

2. The method according to claim 1, characterized in that, After performing the locking operation, the method further includes: Upon receiving a read command from the host device, in response to the read command, the read status of the error information being read by the host device is obtained; If the error information is read by the host device, an exit lock operation is performed; the exit lock operation is used to release the storage device from the locked state, and the read instruction is used to read the error information corresponding to the data operation.

3. The method according to claim 2, characterized in that, Prior to performing the locking operation, the method further includes: In the event of a data operation failure, an error classification code is generated; the error classification code is used to instruct the host device to send the read instruction to the storage device; upon receiving any instruction from the host device, the host device reads the error classification code.

4. The method according to claim 3, characterized in that, The locking conditions include: the storage device supports the locking operation, the host device instructs the storage device to enable the device function corresponding to the locking operation, and the error classification code is generated.

5. The method according to claim 2, characterized in that, After performing the lock exit operation, the method further includes: Receive the repair command sent by the host device; In response to the repair command, the corresponding repair operation is executed, and the corresponding repair result is returned to the host device.

6. The method according to any one of claims 1 to 5, characterized in that, The execution of the corresponding data operations includes: The target storage block is determined according to the data operation instructions; the target storage block is used to store data. Perform the data operation on the target storage block.

7. The method according to claim 6, characterized in that, The data operation is determined to have failed if one or more of the following conditions are met: The target storage block is damaged, the command parameters for data operations on the target storage block are incorrect, or the storage medium corresponding to the target storage block is in a busy state.

8. The method according to any one of claims 1 to 5, characterized in that, The method further includes: If a target instruction is received while the device is in the locked state, the device responds to the target instruction and executes the instruction operation corresponding to the target instruction. The target instructions include query instructions for querying device information and device attributes of the storage device, and query instructions for querying logical units in the storage device that are available to the host device.

9. The method according to any one of claims 1 to 5, characterized in that, Before executing the corresponding data operation in response to the data operation command from the host device, the method further includes: Receives control commands sent by the host device; the control commands include a target field; Based on the target field, enable or disable the device function corresponding to the locking operation.

10. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the method as claimed in any one of claims 1 to 9.