The last storage log search method
By scanning the log blocks in the computer system and judging the storage status, and finding the last log encoding of the stored log, the problem of log header data loss and encoding tracking in the prior art is solved, and the continuity and stability of log encoding are achieved.
Patent Information
- Application Number
- CN202110036932.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-12
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2041-01-12
AI Technical Summary
In the prior art, in order to record a new log, the system needs to first track the log encoding of the last log, and store the log header in a permanent storage manner outside the non-volatile memory block to avoid the log header being accidentally overwritten or damaged, resulting in the inability to track the encoding of the last log.
By performing a series of steps in a computer system, including scanning the log block to obtain the current encoded maximum and minimum values, judging the storage state of non-volatile memory, and finding the last log encoding of the stored log in the overflow or normal state, avoiding occupancy of permanent storage space.
It realizes the correct tracking and recording of log encoding without occupying permanent storage space, avoiding the loss of log header data, ensuring the continuity of log encoding, and facilitating future maintenance and retrieval.
Smart Images

Figure CN114764305B_ABST
Abstract
Description
[Technical field]
[0001] The invention relates to a last storage log search method. [Background technology]
[0002] At present, in the prior art, when a central processing unit (CPU) records a log in a flash memory, according to the SCSI primary Commands-5 (SPC-5) specification, each log must correspond to a log code. When recording a new log, the system needs to first track the log code corresponding to the last log that has been recorded, so that the correct log code can be recorded for the new log. According to the prior art, the system will store a log header (log) having the log code corresponding to the last log that has been recorded in another non-volatile memory block different from the flash memory block where the log is recorded in a permanent storage manner. header) to avoid cyclically recording multiple logs in the same flash memory block. When the number of logs to be recorded exceeds the number of logs that can be stored in the flash memory, when the next log is recorded by overwriting the data already stored in the flash memory block, if the log header and the logs are stored in the same flash memory block, the data of the log header may be accidentally overwritten or damaged during the process of cyclically storing and recording the next log, resulting in the inability to track the log code of the last log and its recording location. In this way, when the next new log is to be recorded, it is impossible to find the new Before the next log is recorded, the log header has the log code of the last log recorded in the data stored in the flash memory block, but cannot find the log code corresponding to the last log recorded in the data stored in the flash memory block before the new next log is recorded, and cannot accumulate and calculate the log code of the new next log, resulting in the inability to continue to accumulate and calculate the log code that should correspond to the next log record by taking over the log code of the last log recorded, and thus cannot make the logs recorded in sequence have continuous rows of log codes to facilitate the computer / server maintenance personnel to simply read and retrieve the logs in the future. [Summary of the invention]
[0003] The technical problem to be solved by the present invention is to provide a method for searching the last stored log, which overcomes the disadvantage of the prior art that a permanent storage block must be used as a log header to obtain the log code of the last recorded log in the non-volatile memory block.
[0004] In order to solve the above technical problems, the present invention provides a method for searching the last stored log, which is implemented by a computer system. The computer system includes a processing device and a non-volatile memory electrically coupled to the processing device. The non-volatile memory includes a log block for storing logs. The processing device executes a firmware to sequentially generate a plurality of logs, and sequentially stores the logs in the log block. The number of logs that can be stored in the log block at the same time is at most an upper limit number, and each log corresponds to a log code, and the range of the log codes falls between an upper code limit value and a lower code limit value. The above method includes the following steps:
[0005] A. After the computer system is turned on, the processing device of the computer system executes the firmware to obtain storage space information of the log block for storing multiple logs in the non-volatile memory electrically coupled to the processing device, wherein the storage space information includes the size of the storage space of the log block, the address of the log block, and the upper limit number of logs that can be stored in the log block;
[0006] B. The processing device scans the log block to obtain a log code corresponding to a current code maximum value and a current code minimum value from among the log codes corresponding to all the logs stored in the log block, wherein the current code maximum value represents the log code with the largest value among the log codes corresponding to all the logs currently stored in the log block, and wherein the current code minimum value represents the log code with the smallest value among the log codes corresponding to all the logs currently stored in the log block;
[0007] C. The processing device determines whether the current storage state of the non-volatile memory is full, if yes, executes step D, if no, executes step E;
[0008] D. Find the log code corresponding to all logs stored in the log block that is smaller than the upper limit and closest to the upper limit, which is the last log stored in the log block; and
[0009] E. Find the log code with the current maximum value from the log codes corresponding to all logs stored in the log block. The log corresponding to the log code with the current maximum value is the last log stored in the log block.
[0010] Preferably, in step C, the difference between the current maximum value and the current minimum value of the code can be calculated, and compared to determine whether the difference between the current maximum value and the current minimum value of the code is greater than or equal to the upper limit value. If it is greater than or equal to, it means that the current storage status of the log block is overflowing.
[0011] Preferably, it is determined whether all logs stored in the log block include two logs corresponding to the log code as the upper limit value of the code and the lower limit value of the code. If both are included, it means that the current storage status of the log block is an overflow state; if both are not included, it means that the current storage status of the log block is a normal state.
[0012] Compared with the prior art, the computer system can also perform the process of step (A) to step (E) after booting to find the log code corresponding to the last stored log, and then temporarily store the log code corresponding to the last stored log in the form of firmware parameters or in a buffer. Each time the processing device generates a new log, the temporarily stored log code is accumulated as the log code of the generated new log and the temporarily stored log code is updated. In this way, the log code corresponding to the last log stored in the log block is found again by the last stored log search method after each booting, so as to continuously encode the log code corresponding to the new log by taking over the log code of the last stored log. In this way, the header can be recorded without occupying permanent storage space, and there is no need to worry about the problem of header data loss.
Brief Description of the Drawings
[0013] Figure 1 This is a flowchart of the steps of the last storage log search method of the present invention.
[0014] Figure 2 It is a diagram to help explain how to search for the last log in the overflow state.
[0015] Figure 3 This is a diagram to help explain how to search for the last log entry under normal conditions. [Specific implementation method]
[0016] See also Figure 1As shown, the present invention provides a method for searching the last stored log, which is implemented by a computer system (not shown). The computer system includes a processing device (not shown), a non-volatile memory (not shown) electrically coupled to the processing device, such as a flash memory, an EEPROM or a ROM, etc. The data stored in the non-volatile memory will not disappear due to power failure, that is, the memory can permanently store data. The non-volatile memory includes a log block for storing logs. The processing device executes a firmware to sequentially generate multiple logs and store the logs sequentially. In the log block, the number of logs that can be stored simultaneously in the log block is at most an upper limit number. The upper limit number is 10 as an example below. The upper limit number varies according to the size of the storage space of the log block of each computer system, and each log corresponds to a log code, and the range of the log codes falls between an upper limit value and a lower limit value, wherein the upper limit value defines the maximum possible value of the log code, such as 65535, and the lower limit value defines the minimum possible value of the log code, wherein the lower limit value is 0.
[0017] The last stored log search method of the present invention includes the following steps:
[0018] In step S1, after the computer system is turned on, the processing device of the computer system executes the firmware to obtain storage space information of a log block in the non-volatile memory electrically coupled to the processing device for storing multiple logs, wherein the storage space information is, for example, the size of the storage space of the log block, the address of the log block, and the upper limit number of logs that can be stored in the log block (taking 10 as an example).
[0019] In step S2, the processing device scans the log block to obtain a log code corresponding to a current code maximum value and a current code minimum value from among the log codes corresponding to all the logs stored in the log block, wherein the current code maximum value represents the log code with the largest value among the log codes corresponding to all the logs currently stored in the log block, and wherein the current code minimum value represents the log code with the smallest value among the log codes corresponding to all the logs currently stored in the log block.
[0020] In step S3, the processing device determines whether the current storage state of the non-volatile memory is an overflow state. If yes, step S4 is executed. If no, step S5 is executed. In this embodiment, the difference between the current maximum value and the current minimum value of the code is calculated, and compared to determine whether the difference between the current maximum value and the current minimum value of the code is greater than or equal to the upper limit value (10). If less than, it means that the current storage state of the log block is a normal state. If greater than or equal to, it means that the current storage state of the log block is an overflow state. In another embodiment, it is determined whether all logs stored in the log block include two logs corresponding to the log code of the upper limit value and the lower limit value. If both are included, it means that the current storage state of the log block is an overflow state. If not, it means that the current storage state of the log block is a normal state.
[0021] Step S4, among the log codes corresponding to all the logs stored in the log block, find the log corresponding to the log code that is less than the upper limit (the maximum number of logs that the log block can store) and closest to the upper limit, which is the last log stored in the log block. Please refer to Figure 2 In the log codes corresponding to all logs stored in the log block, the current maximum value (CurrentMax) = 65535, and the current minimum value (Current Min) = 0. The difference between the current maximum value and the current minimum value is greater than the upper limit value 10, which meets the judgment that the storage state of the log block is overflowing. Then, among the code values 66530, 66531 ... 0, 1 in the log codes corresponding to all logs stored in the log block, the code values of the log codes corresponding to all logs less than the upper limit are 0, 1, and 1 is the code value of the log code closest to the upper limit value 10. Then the log code Log1 corresponding to 1 is the last log stored in the log block.
[0022] Step S5, find the log code with the current maximum value from the log codes corresponding to all logs stored in the log block, and the log corresponding to the log code with the current maximum value is the last log stored in the log block. Figure 3 As shown, the current maximum value of the code (Current Max) = 9, the current minimum value of the code (Current Min) = 0, then the difference is 9, which is less than the upper limit value 10. At this time, the storage status of the log block is normal, and the last log stored in the log block is the log code Log9 corresponding to the current maximum value of 9.
[0023] In summary, when the computer system is turned on, the processing device executes the firmware to obtain the storage space information of the log block of the non-volatile memory, and further determines the current maximum code value and the current minimum code value of the log codes corresponding to all the logs currently stored in the log block, so as to determine whether the storage state of the log block is overflowing. When the storage state of the log block is overflowing, the log corresponding to the log code that is less than the upper limit and closest to the upper limit is then found, which is the last log stored in the log block. The log code corresponding to the last log stored in the log block is recorded in the buffer in the form of firmware parameters, without occupying a permanent storage space all the time to record the log code corresponding to the last log stored. When the log code corresponding to the last log stored is damaged or lost or has not been stored, according to the technology of the present invention, the log code corresponding to the last log stored in the log block can be monitored all the time by repeatedly executing steps (S2) to (S5). For example, when the processing device executes the firmware and generates a new log, the steps (S1) to (S5) or step (S1) can be executed again. (S2) to step (S5) are used to cumulatively calculate the log code corresponding to the currently generated log. That is, after executing the last stored log search method to obtain the log code corresponding to the last log stored in the log block, when the log code corresponding to the last stored log is not equal to the upper limit of the code, the log code corresponding to the last stored log is directly added by 1 as the log code of the log currently generated by the processing device. When the log code corresponding to the last stored log is equal to the upper limit of the code, the log code of the log currently generated by the processing device is 0, which is the lower limit of the code.
[0024] The computer system can also perform steps (S1) to (S5) after booting up, and then temporarily store the log code corresponding to the last stored log in the form of firmware parameters or in a buffer as a latest log code record, and each time the processing device generates a new log, accumulate the temporarily stored log code as the log code of the generated new log and update the temporarily stored log code, thereby finding the log code corresponding to the last log stored in the log block again by the last stored log search method after each booting up, so as to take over the last stored log. The processing device may further include a method for continuously encoding the log code corresponding to a new log by using the log code of the processing device, or after the processing device generates a new log each time, first determine whether the latest log code record exists in the firmware parameter or in the buffer. If so, directly accumulate the temporarily stored log code to serve as the log code of the generated new log and update the temporarily stored log code. If not, find the log code corresponding to the last log stored in the log block in real time by using the last stored log search method, so as to inherit the log code of the last stored log to encode the log code corresponding to the new log. The code is continuously encoded. In this way, the log header can be recorded without occupying permanent storage space, and there is no need to worry about the data loss of the log header. In another embodiment, each time the processing device generates a new log, the processing device first determines whether the temporarily stored log code exists in the firmware parameter or the buffer. The temporarily stored log code indicates the log code corresponding to the last stored log before the new log is recorded and stored. When the temporarily stored log code exists in the firmware parameter or the buffer, the temporarily stored log code is accumulated as the log code of the generated new log. encoding, and updating the log code of the new log to the temporarily stored log code; when the temporarily stored log code does not exist in the firmware parameter or the register, executing the process of step (A) to step (E) to find the log code corresponding to the last stored log, that is, temporarily storing the log code corresponding to the last log stored in the log block of the non-volatile memory in the form of firmware parameters or in the register, and accumulating the temporarily stored log code as the log code of the generated new log each time the processing device generates a new log subsequently and updating the temporarily stored log code;In another embodiment, each time the processing device generates a new log, the process of steps (A) to (E) is executed to find the log code corresponding to the last stored log, and the new log code corresponding to the new log is calculated by accumulating the log code corresponding to the last log stored in the log block of the non-volatile memory, and the generated new log is stored in the log block of the non-volatile memory with the new log code. ;
[0025] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A method for searching the last stored log, which is implemented by a computer system, the computer system comprising a processing device, a non-volatile memory electrically coupled to the processing device, the non-volatile memory comprising a log block for storing logs, the processing device executing a firmware to sequentially generate a plurality of logs, and sequentially store the logs in the log block, the number of logs that can be stored in the log block at the same time is at most an upper limit number, and each log corresponds to a log code, and the range of the log codes falls between an upper code limit value and a lower code limit value, characterized in that, The following steps are involved: A. After the computer system is turned on, the processing device of the computer system executes the firmware to obtain storage space information of the log block for storing multiple logs in the non-volatile memory electrically coupled to the processing device, wherein the storage space information includes the size of the storage space of the log block, the address of the log block, and the upper limit number of logs that can be stored in the log block; B. The processing device scans the log block to obtain a log code corresponding to a current code maximum value and a current code minimum value from among the log codes corresponding to all the logs stored in the log block, wherein the current code maximum value represents the log code with the largest value among the log codes corresponding to all the logs currently stored in the log block, and the current code minimum value represents the log code with the smallest value among the log codes corresponding to all the logs currently stored in the log block; C. The processing device determines whether the current storage state of the non-volatile memory is full, if yes, executes step D, if no, executes step E; D. Find the log code corresponding to all logs stored in the log block that is smaller than the upper limit and closest to the upper limit, which is the last log stored in the log block; and E. Find the log code with the current maximum value from the log codes corresponding to all logs stored in the log block. The log corresponding to the log code with the current maximum value is the last log stored in the log block.
2. The method for searching the last stored log according to claim 1, characterized in that: In step C, the difference between the current maximum value and the current minimum value of the code can be calculated, and compared to determine whether the difference between the current maximum value and the current minimum value of the code is greater than or equal to the upper limit. If it is greater than or equal to, it means that the current storage status of the log block is overflowing.
3. The method for searching the last stored log according to claim 1, characterized in that: By determining whether all logs stored in the log block include two logs corresponding to the log code as the upper limit value of the code and the lower limit value of the code, if both are included, it means that the current storage status of the log block is overflowing; if both are not included, it means that the current storage status of the log block is normal.
Citation Information
Patent Citations
System log query method
CN106940675A
Method for verifying SEL (System Event Log) entry amount capable of being stored by BMC (Baseboard Management Controller), and SEL coverage function
CN107656848A