Disclosure of Invention
In view of this, embodiments of the present invention provide a method, a system, a computer device, and a computer readable storage medium for managing a control device, in which a single thread is used to process a command execution management array and a message queue layer by layer, so as to reduce the influence of a control data stream on a service data stream, and then, communication of control data between layers is implemented through an inter-thread communication mechanism, so as to implement management of a device based on a Linux system, and implement management and control of the device while avoiding the influence on a service.
In view of the above, an aspect of the embodiments of the present invention provides a method for managing a control device, including the following steps: applying for a memory space to set a command execution management array, setting the maximum information length of the command execution management array, applying for a message queue resource to create a message queue and defining the exclusive type of data sent by the message queue; in response to receiving control host information, adding the control host information to the command execution management array, and judging whether the length of the control host information is less than or equal to the maximum information length of the command execution management array; in response to the length of the control host information being less than or equal to the maximum information length of the command execution management array, sending an execution request and receiving a returned execution state and result by using the exclusive type through the message queue; and informing the host that the control host has completed executing the information, and initializing the command execution management array and the message queue in response to the host acquiring the execution state and result.
In some embodiments, the method further comprises: in response to the command execution management array setup being complete, enabling a new thread to listen to the message queue to detect whether there is an execution request.
In some embodiments, the method further comprises: in response to receiving the execution request, a fork function is called under the current process to create a sub-process, and an execute function is called in the sub-process to execute the execution request.
In some embodiments, the method further comprises: and setting a nameless pipeline between the current process and the subprocess, and redirecting to receive the execution state and result of the execute function.
In some embodiments, the method further comprises: dynamically applying for a memory space to store the executed state and result, and writing the address of the memory space into the command execution management array.
In some embodiments, the receiving the returned execution state and result comprises: judging whether the returned execution state and result belong to the exclusive type; and responding to the returned execution state and result not belonging to the exclusive type, and returning the returned execution state and result to an original address.
In some embodiments, the method further comprises: judging whether a command execution management array and/or a message queue needs to be created or not according to the current equipment model or scene; and in response to a need to create a command execution management array and/or message queue, sending an enable signal and creating a command processing thread.
In another aspect of the embodiments of the present invention, a system for managing a control device is provided, including: the system comprises a creating module, a memory space application module and a message queue resource application module, wherein the creating module is configured to apply for a memory space to set a command execution management array, set the maximum information length of the command execution management array, apply for a message queue resource to create a message queue and define the exclusive type of data sent by the message queue; the judging module is configured to respond to the received control host information, add the control host information into the command execution management array, and judge whether the length of the control host information is less than or equal to the maximum information length of the command execution management array; the message module is configured to respond that the length of the control host information is smaller than or equal to the maximum information length of the command execution management array, send an execution request by using the exclusive type through the message queue and receive a returned execution state and result; and an initialization module configured to notify a host that the control host has completed executing the information, and initialize the command execution management array and the message queue in response to the host obtaining the execution status and result.
In another aspect of the embodiments of the present invention, there is also provided a computer device, including: at least one processor; and a memory storing computer instructions executable on the processor, the instructions when executed by the processor implementing the steps of the method as above.
In a further aspect of the embodiments of the present invention, a computer-readable storage medium is also provided, in which a computer program for implementing the above method steps is stored when the computer program is executed by a processor.
The invention has the following beneficial technical effects: the single-thread scheme is adopted for processing layer by layer, the influence of control data flow on service data flow is reduced, then the communication of control data among layers is realized through an inter-thread communication mechanism, so that the management of equipment based on a Linux system is realized, and the management and the control of the equipment are realized while the influence on the service is avoided.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the following embodiments of the present invention are described in further detail with reference to the accompanying drawings.
It should be noted that all expressions using "first" and "second" in the embodiments of the present invention are used for distinguishing two entities with the same name but different names or different parameters, and it should be noted that "first" and "second" are merely for convenience of description and should not be construed as limitations of the embodiments of the present invention, and they are not described in any more detail in the following embodiments.
In view of the above objects, a first aspect of embodiments of the present invention proposes an embodiment of a method of managing a control device. Fig. 1 is a schematic diagram illustrating an embodiment of a method for managing a control device according to the present invention. As shown in fig. 1, the embodiment of the present invention includes the following steps:
s1, applying for a memory space to set a command execution management array, setting the maximum information length of the command execution management array, applying for a message queue resource to create a message queue and defining the exclusive type of data sent by the message queue;
s2, responding to the received control host information, adding the control host information into the command execution management array, and judging whether the length of the control host information is less than or equal to the maximum information length of the command execution management array;
s3, responding to the length of the control host information is smaller than or equal to the maximum information length of the command execution management array, sending an execution request by using the exclusive type through the message queue, and receiving a returned execution state and result; and
s4, informing the host that the control host has completed executing, and responding to the host obtaining the executing state and result, initializing the command execution management array and the message queue.
The embodiment of the invention adopts C high-level language to describe a control mechanism, uses a general processor CPU as a main program of a host end to operate, starts an independent thread in a certain single module to finish the processing of the control function, finishes the encapsulation or processing of control data in each module through a multithread processing mechanism in the whole system, and then carries out data interaction of each module through a communication mode among threads such as a message queue, thereby finishing the management and the control of a Linux system. By using the control management mechanism, a more diversified system control mechanism can be realized under the condition of avoiding the influence on the original working mechanism, the requirements on multiple industries and multiple scenes are met, and the product adaptability is improved.
In some embodiments, the method further comprises: judging whether a command execution management array and/or a message queue needs to be created or not according to the current equipment model or scene; and in response to a need to create a command execution management array and/or message queue, sending an enable signal and creating a command processing thread. Judging whether the current equipment model or scene needs to provide the service mechanism, if not, the function is not enabled, reducing CPU burden, if so, enabling the function, sending enabling information through the original information interaction channel, enabling the function, and creating a corresponding mechanism.
Applying for memory space to set command execution management array, setting maximum information length of the command execution management array, applying for message queue resource to create message queue and defining exclusive type of the message queue for sending data. Applying for memory space, setting command execution management array, limiting length of command execution management array, setting maximum information length according to actual situation, and maintaining by platform interaction module; applying for message queue resource, creating exclusive message queue and defining message queue to send exclusive type of data.
In some embodiments, the method further comprises: in response to the command execution management array setup being complete, enabling a new thread to listen to the message queue to detect whether there is an execution request. And informing the case control module through the original information interaction channel, and starting a new thread to monitor and execute the request.
And in response to receiving control host information, adding the control host information into the command execution management array, and judging whether the length of the control host information is less than or equal to the maximum information length of the command execution management array. After receiving the control host information, the controlled device platform analyzes and verifies the control host information, wherein the verification mode needs to be set according to an actual application scene, for example, whether an instruction is supported or not, and if the verification fails, a corresponding error is returned to the host end; and if the verification is passed, adding the control host information to the command execution management array. And assembling the shell execution command string, and checking the length validity, namely judging whether the length of the command string is less than or equal to the maximum information length of the command execution management array.
And in response to the length of the control host information being less than or equal to the maximum information length of the command execution management array, sending an execution request and receiving a returned execution state and result by using the exclusive type through the message queue.
In some embodiments, the method further comprises: in response to receiving the execution request, a fork function is called under the current process to create a sub-process, and an execute function is called in the sub-process to execute the execution request. The Fork () function is a system call to create a process that is almost identical to the original process, called the child process, and the original process called the parent process. After a process calls the fork () function, the system first allocates resources to the new process, such as space for storing data and code, and then copies all values of the original integration into the new process, only a few values are different from the values of the original process, which is equivalent to cloning an original process. One point to be noted is: after the fork function is called, the code segment executed by the parent process and the child process simultaneously is the code after the fork function, and the previous code is executed by the parent process.
After the fork function is executed, if the creation of a new process is successful, two processes appear, one is a child process and the other is a parent process. In the child process, the fork function returns 0, in the parent process, the fork function returns the process ID (identification) of the newly created child process, and whether the current process is the child process or the parent process can be judged by the value returned by the fork. Fork error may have two causes, the first, current number of processes has reached the upper limit specified by the system, when the value of errno is set to EAGAIN; second, the system memory is insufficient, and the value of errno is set to ENOMEM. After the child process is created successfully, two processes which are basically identical appear in the system, the two processes are executed without a fixed sequence, and the sequence of the process execution needs to be determined according to a process scheduling strategy of the system. Each process has a unique process identifier, which can be obtained through the getpid () function, and a variable that records the parent process pid, whose value can be obtained through the getppid () function.
The Exec family of functions provides a method for starting another program in a process, which can find an executable file according to the name of an executed file or directory and replace a data segment, a code segment and a stack segment of an original calling process, and after the execution is finished, the content of the original calling process is replaced by the content of the new program except for a process number. When a process calls an exec function, the process is completely replaced by the new program, which starts from its main function, and thus calling exec does not create a new process, so the process ID (also including parent process number, process group number, current working directory … …) before and after it is unchanged. Exec simply replaces the text, data, stack and stack segments of the current process with another new program. The fifth bit of Execve is v, which indicates that the parameter is passed in a pointer array construction mode, and the sixth bit of e indicates that a new process environment variable can be passed.
In some embodiments, the method further comprises: and setting a nameless pipeline between the current process and the subprocess, and redirecting to receive the execution state and result of the execute function.
The pipe is an interprocess communication mechanism inherited by Linux from unix, and the idea is to create a shared file (the file is a pseudo file, does not occupy the size of a disk, and is a buffer area) in an inner core, so that two communication parties can realize communication by using the shared file, and the shared file for transmitting messages is called as the pipe. The anonymous pipe has no file nodes in the file system and can be used for interprocess communication with affinity. The nameless pipe may be created using the pipe () function. Redirection is to put some erroneous or correct information output by the command into a specified file, so that the redirection is managed well.
In some embodiments, the receiving the returned execution state and result comprises: judging whether the returned execution state and result belong to the exclusive type; and responding to the returned execution state and result not belonging to the exclusive type, and returning the returned execution state and result to an original address.
And informing the host that the control host information is executed, and initializing the command execution management array and the message queue in response to the host acquiring the execution state and result.
In some embodiments, the method further comprises: dynamically applying for a memory space to store the executed state and result, and writing the address of the memory space into the command execution management array. The platform interaction module dynamically applies for space, stores execution states and results, and places memory addresses in corresponding command execution management arrays for maintenance and access. After taking the result away, the host releases the space for storing the result and initializes the command management matrix and the message queue.
The invention adopts a single-thread scheme to process layer by layer, reduces the influence of control data flow on service data flow, realizes the communication of control data among layers through an inter-thread communication mechanism, can improve the control flexibility and reduce the influence of the control data flow on other performances, expands the control mode of the storage equipment, widens the application scene, improves the competitiveness of the storage equipment, and realizes the management and control of the equipment while avoiding the influence on the service.
It should be particularly noted that, the steps in the embodiments of the method for managing a control device described above can be mutually intersected, replaced, added, or deleted, and therefore, these methods for managing a control device that are reasonably changed in permutation and combination also belong to the scope of the present invention, and the scope of the present invention should not be limited to the embodiments.
In view of the above object, a second aspect of an embodiment of the present invention provides a system for managing a control device, including: the system comprises a creating module, a memory space application module and a message queue resource application module, wherein the creating module is configured to apply for a memory space to set a command execution management array, set the maximum information length of the command execution management array, apply for a message queue resource to create a message queue and define the exclusive type of data sent by the message queue; the judging module is configured to respond to the received control host information, add the control host information into the command execution management array, and judge whether the length of the control host information is less than or equal to the maximum information length of the command execution management array; the message module is configured to respond that the length of the control host information is smaller than or equal to the maximum information length of the command execution management array, send an execution request by using the exclusive type through the message queue and receive a returned execution state and result; and an initialization module configured to notify a host that the control host has completed executing the information, and initialize the command execution management array and the message queue in response to the host obtaining the execution status and result.
In some embodiments, the system further comprises a listening module configured to: in response to the command execution management array setup being complete, enabling a new thread to listen to the message queue to detect whether there is an execution request.
In some embodiments, the system further comprises a second creation module configured to: in response to receiving the execution request, a fork function is called under the current process to create a sub-process, and an execute function is called in the sub-process to execute the execution request.
In some embodiments, the system further comprises a receiving module configured to: and setting a nameless pipeline between the current process and the subprocess, and redirecting to receive the execution state and result of the execute function.
In some embodiments, the system further comprises a storage module configured to: dynamically applying for a memory space to store the executed state and result, and writing the address of the memory space into the command execution management array.
In some embodiments, the message module is configured to: judging whether the returned execution state and result belong to the exclusive type; and responding to the returned execution state and result not belonging to the exclusive type, and returning the returned execution state and result to an original address.
In some embodiments, the system further comprises a second determining module configured to: judging whether a command execution management array and/or a message queue needs to be created or not according to the current equipment model or scene; and in response to a need to create a command execution management array and/or message queue, sending an enable signal and creating a command processing thread.
The invention adopts a single-thread scheme to process layer by layer, reduces the influence of control data flow on service data flow, realizes the communication of control data among layers through an inter-thread communication mechanism, can improve the control flexibility and reduce the influence of the control data flow on other performances, expands the control mode of the storage equipment, widens the application scene, improves the competitiveness of the storage equipment, and realizes the management and control of the equipment while avoiding the influence on the service.
In view of the above object, a third aspect of the embodiments of the present invention provides a computer device, including: at least one processor; and a memory storing computer instructions executable on the processor, the instructions being executable by the processor to perform the steps of: s1, applying for a memory space to set a command execution management array, setting the maximum information length of the command execution management array, applying for a message queue resource to create a message queue and defining the exclusive type of data sent by the message queue; s2, responding to the received control host information, adding the control host information into the command execution management array, and judging whether the length of the control host information is less than or equal to the maximum information length of the command execution management array; s3, responding to the length of the control host information is smaller than or equal to the maximum information length of the command execution management array, sending an execution request by using the exclusive type through the message queue, and receiving a returned execution state and result; and S4, informing the host that the control host has completed executing the information, and initializing the command execution management array and the message queue in response to the host acquiring the execution state and result.
In some embodiments, the steps further comprise: in response to the command execution management array setup being complete, enabling a new thread to listen to the message queue to detect whether there is an execution request.
In some embodiments, the steps further comprise: in response to receiving the execution request, a fork function is called under the current process to create a sub-process, and an execute function is called in the sub-process to execute the execution request.
In some embodiments, the steps further comprise: and setting a nameless pipeline between the current process and the subprocess, and redirecting to receive the execution state and result of the execute function.
In some embodiments, the steps further comprise: dynamically applying for a memory space to store the executed state and result, and writing the address of the memory space into the command execution management array.
In some embodiments, the receiving the returned execution state and result comprises: judging whether the returned execution state and result belong to the exclusive type; and responding to the returned execution state and result not belonging to the exclusive type, and returning the returned execution state and result to an original address.
In some embodiments, the steps further comprise: judging whether a command execution management array and/or a message queue needs to be created or not according to the current equipment model or scene; and in response to a need to create a command execution management array and/or message queue, sending an enable signal and creating a command processing thread.
Fig. 2 is a schematic diagram of a hardware structure of an embodiment of the computer device for managing and controlling devices according to the present invention.
Taking the apparatus shown in fig. 2 as an example, the apparatus includes a processor 201 and a memory 202, and may further include: an input device 203 and an output device 204.
The processor 201, the memory 202, the input device 203 and the output device 204 may be connected by a bus or other means, and fig. 2 illustrates the connection by a bus as an example.
The memory 202, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions/modules corresponding to the method for managing a control device in the embodiments of the present application. The processor 201 executes various functional applications of the server and data processing by running nonvolatile software programs, instructions, and modules stored in the memory 202, that is, implements the method of managing a control device of the above-described method embodiment.
The memory 202 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to use of a method of managing the control apparatus, and the like. Further, the memory 202 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some embodiments, memory 202 may optionally include memory located remotely from processor 201, which may be connected to local modules via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 203 may receive information such as a user name and a password that are input. The output device 204 may include a display device such as a display screen.
Program instructions/modules corresponding to one or more methods of managing a control device are stored in the memory 202 and, when executed by the processor 201, perform the method of managing a control device in any of the method embodiments described above.
Any embodiment of a computer device performing the method of managing a control device described above may achieve the same or similar effects as any of the preceding method embodiments corresponding thereto.
The invention also provides a computer readable storage medium storing a computer program which, when executed by a processor, performs the method as above.
Fig. 3 is a schematic diagram of an embodiment of a computer storage medium for managing a control device according to the present invention. Taking the computer storage medium as shown in fig. 3 as an example, the computer readable storage medium 3 stores a computer program 31 which, when executed by a processor, performs the method as described above.
Finally, it should be noted that, as one of ordinary skill in the art can appreciate that all or part of the processes of the methods of the above embodiments can be implemented by a computer program to instruct related hardware, and the program of the method for managing a control device can be stored in a computer readable storage medium, and when executed, the program can include the processes of the embodiments of the methods as described above. The storage medium of the program may be a magnetic disk, an optical disk, a Read Only Memory (ROM), a Random Access Memory (RAM), or the like. The embodiments of the computer program may achieve the same or similar effects as any of the above-described method embodiments.
The foregoing is an exemplary embodiment of the present disclosure, but it should be noted that various changes and modifications could be made herein without departing from the scope of the present disclosure as defined by the appended claims. The functions, steps and/or actions of the method claims in accordance with the disclosed embodiments described herein need not be performed in any particular order. Furthermore, although elements of the disclosed embodiments of the invention may be described or claimed in the singular, the plural is contemplated unless limitation to the singular is explicitly stated.
It should be understood that, as used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly supports the exception. It should also be understood that "and/or" as used herein is meant to include any and all possible combinations of one or more of the associated listed items.
The numbers of the embodiments disclosed in the embodiments of the present invention are merely for description, and do not represent the merits of the embodiments.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
Those of ordinary skill in the art will understand that: the discussion of any embodiment above is meant to be exemplary only, and is not intended to intimate that the scope of the disclosure, including the claims, of embodiments of the invention is limited to these examples; within the idea of an embodiment of the invention, also technical features in the above embodiment or in different embodiments may be combined and there are many other variations of the different aspects of the embodiments of the invention as described above, which are not provided in detail for the sake of brevity. Therefore, any omissions, modifications, substitutions, improvements, and the like that may be made without departing from the spirit and principles of the embodiments of the present invention are intended to be included within the scope of the embodiments of the present invention.