A network card management and control method and device
By synchronizing and pre-setting network card naming rules between the host machine and the virtual machine, the problem of network card name conflict in the virtual machine is solved, and the correct identification and management of physical network cards is achieved.
Patent Information
- Application Number
- CN202410472303.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-18
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2044-04-18
AI Technical Summary
After physical network cards are passed through in a virtual machine, the independent network card naming mechanism between the virtual machine and the host machine leads to network card name conflicts, making it difficult to correctly identify and manage physical network cards.
Synchronize and preset network card naming rules between the host machine and the virtual machine, so that the virtual machine can name the pass-through physical network card according to the rules, ensuring that the naming does not conflict with other network cards on the host machine.
By synchronizing and pre-setting naming rules, the possibility of network card name conflicts is reduced, ensuring the correct identification and effective management of physical network cards.
Smart Images

Figure CN118473915B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a network card management and control method and device. BACKGROUND
[0002] With the development and popularity of virtualization technology, a virtual machine is usually deployed in a host computer to realize corresponding functions through the virtual machine.
[0003] At present, in order to reduce the forwarding overhead of a virtual network, a network card pass-through technology is usually used to pass a physical network card in a host computer to a virtual machine for use. After the physical network card is passed to the virtual machine for use, the virtual machine will rename the corresponding physical network card based on its own network card naming mechanism. However, since the host computer and the virtual machine have independent network card naming mechanisms, the renamed network card name may conflict with the names of other physical network cards in the host computer. Thus, the host computer or a user will have difficulty in correctly identifying the corresponding physical network card based on the network card name, and thus it is difficult to manage and control the physical network card. SUMMARY
[0004] Therefore, the present application provides a network card management and control method and device, which aims to avoid the virtual machine from naming the passed-through physical network card with a network card name that cannot correctly identify the corresponding physical network card when the host computer passes a physical network card to a virtual machine.
[0005] To achieve the above purpose, the present application mainly provides the following technical solutions:
[0006] In a first aspect, the present application provides a network card management and control method applied to a virtual machine, wherein the virtual machine stores a preset network card naming rule synchronized by a host computer, and the network card management and control method comprises the following steps:
[0007] determining a target physical network card passed to the virtual machine by the host computer;
[0008] naming the target physical network card based on the preset network card naming rule.
[0009] In some embodiments of the present application, the preset network card naming rule is used to indicate that at least one network card attribute of a physical network card is combined in a preset order to obtain a network card name. Then, the network card management and control method further comprises the following steps: based on the preset network card naming rule, at least one network card attribute required for naming the target physical network card is obtained.
[0010] Then, naming the target physical network card based on the preset network card naming rule comprises the following steps: combining the at least one network card attribute in the preset order to obtain the corresponding network card name of the target physical network card.
[0011] In some embodiments of the present application, the virtual machine and the host computer have a shared memory in common, and the shared memory stores at least one network card attribute written by the host computer and required for naming the target physical network card;
[0012] Therefore, based on the preset network card naming rule, obtaining at least one network card attribute required for naming the target physical network card includes: based on the preset network card naming rule, reading at least one network card attribute required for naming the target physical network card from the shared memory.
[0013] In some embodiments of the present application, at least one network card attribute stored in the shared memory and required for naming the target physical network card is written when the target physical network card is directly connected to the virtual machine, or is written when the virtual machine requests the network card attribute of the target physical network card from the host computer.
[0014] In some embodiments of the present application, the preset network card naming rule is also used to indicate a separator between adjacent network card attributes, and after the at least one network card attribute is combined in the preset order, the network card management method further includes: based on the preset network card naming rule, adding a corresponding separator between adjacent network card attributes.
[0015] In some embodiments of the present application, the at least one network card attribute includes at least one of the following: physical location of the physical network card in the host computer, network card rate, network card type.
[0016] In some embodiments of the present application, the preset order is used to indicate that the network card attributes of the physical network card are combined in the following order: network card rate, network card type, and physical location of the physical network card in the host computer.
[0017] In some embodiments of the present application, the network card management method further includes: obtaining a target physical address allocated to the target physical network card in the virtual machine;
[0018] Therefore, determining the target physical network card directly connected to the virtual machine by the host computer includes: searching for the target physical address in the physical address of the virtual machine; and determining the physical network card corresponding to the target physical address as the target physical network card directly connected to the virtual machine by the host computer.
[0019] In some embodiments of the present application, the virtual machine and the host computer have a shared memory in common, and the shared memory stores a target physical address written by the host computer and allocated to the target physical network card in the virtual machine, the target physical address being allocated by the host computer when the target physical network card is directly connected to the virtual machine;
[0020] The target physical address allocated to the target physical network card in the virtual machine is obtained by reading the target physical address allocated to the target physical network card in the virtual machine from the shared memory.
[0021] In some embodiments of the present application, the shared memory is obtained by dividing the system memory of the host computer, and the network card management method further comprises: obtaining the start and end addresses of the shared memory in the system memory of the host computer; mapping the start and end addresses of the memory to the user process address space of the virtual machine; accessing the shared memory based on the start and end addresses of the memory in the user process address space, and reading corresponding data from the shared memory.
[0022] In some embodiments of the present application, the network card management method further comprises: driving the target physical network card based on the network card driver already deployed in the virtual machine; if the driving is successful, performing the step of naming the target physical network card based on the preset network card naming rule; if the driving fails, deploying a network card driver capable of driving the target physical network card, or issuing a prompt of the target physical network card pass-through failure.
[0023] In some embodiments of the present application, the preset network card naming rule is the same as the network card naming rule used for naming physical network cards in the host computer.
[0024] In a second aspect, the present application provides a network card management method applied to a host computer, wherein at least one virtual machine and at least one physical network card are deployed in the host computer, the host computer is used to pass through the physical network card to the virtual machine and synchronize a preset network naming rule to the virtual machine, and the network card management method comprises:
[0025] When the virtual machine needs to be managed, the preset network card naming rule is synchronized to the virtual machine, so that the virtual machine names the target physical network card passed through by the host computer based on the preset network card naming rule.
[0026] In some embodiments of the present application, the preset network card naming rule is used to indicate that at least one network card attribute of the physical network card is combined in a preset order to obtain a network card name; and the network card management method further comprises: based on the preset network card naming rule, synchronizing at least one network card attribute required for naming the target physical network card to the corresponding virtual machine, so that the virtual machine combines the at least one network card attribute in a preset order to name the target physical network card.
[0027] In some embodiments of the present application, the virtual machine and the host computer have a shared memory in common, and the shared memory is used to provide at least one network card attribute required for naming the target physical network card to the virtual machine;
[0028] According to the preset network card naming rule, at least one network card attribute required for naming the target physical network card is provided to the corresponding virtual machine, including: based on the preset network card naming rule, writing at least one network card attribute required for naming the target physical network card into the shared memory.
[0029] In some embodiments of the present application, the system memory of the host machine includes a continuous memory huge page, and the network card management method further includes: selecting a target memory huge page according to the paging storage amount of the memory huge page and the preset storage amount, and dividing the target memory huge page into the shared memory; mapping the target memory huge page to a preset process address space to obtain the memory start and end addresses of the shared memory.
[0030] According to the preset network card naming rule, at least one network card attribute required for naming the target physical network card is provided to the corresponding virtual machine, including: based on the preset network card naming rule, writing at least one network card attribute required for naming the target physical network card into the shared memory.
[0031] In a third aspect, the present application provides a network card management device applied to a virtual machine, wherein a preset network card naming rule synchronized by a host machine is stored in the virtual machine, and the network card management device comprises:
[0032] A determination module is configured to determine a target physical network card directly passed through by the host machine to the virtual machine.
[0033] A naming module is configured to name the target physical network card based on the preset network card naming rule.
[0034] In a fourth aspect, the present application provides a network card management device applied to a host machine, wherein at least one virtual machine and at least one physical network card are deployed in the host machine, the host machine is configured to directly pass through the physical network card to the virtual machine and synchronize a preset network naming rule to the virtual machine, and the network card management device comprises:
[0035] A synchronization module is configured to synchronize the preset network card naming rule to the virtual machine when the virtual machine needs to be managed, so that the virtual machine names a target physical network card directly passed through by the host machine based on the preset network card naming rule.
[0036] In a fifth aspect, the present application provides a computer readable storage medium, which comprises a stored program, wherein when the program runs, the device where the storage medium is located is controlled to execute the network card management method of the first aspect and / or the network card management method of the second aspect.
[0037] In a sixth aspect, the present application provides an electronic device, comprising: a memory for storing a program; and a processor coupled to the memory and configured to execute the program to perform the network card management method of the first aspect and / or the network card management method of the second aspect.
[0038] The network card management method and device provided by the present application store the preset network card naming rule synchronized by the host computer in the virtual machine, determine the target physical network card directly connected to the virtual machine by the host computer in the case that the host computer directly connects the physical network card to the virtual machine, and name the target physical network card based on the preset network card naming rule. In this way, since the virtual machine names the directly connected physical network card by using the preset network card naming rule synchronized by the host computer, the possibility of conflict between the named network card name and other physical network cards can be reduced, so that the corresponding physical network card can be correctly identified based on the network card name, and the physical network card can be normally managed and controlled.
[0039] The above description is only a summary of the technical solutions of the present application. In order to more clearly understand the technical means of the present application, the present application can be implemented according to the content of the description, and in order to make the above and other purposes, characteristics and advantages of the present application more obvious and easy to understand, the following will specifically describe the embodiments of the present application. BRIEF DESCRIPTION OF DRAWINGS
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiment or prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and those skilled in the art can also obtain other drawings according to these drawings without creative labor.
[0041] Figure 1 A flow chart of a network card management method provided by an embodiment of the present application is shown;
[0042] Figure 2 A flow chart of a network card management method provided by another embodiment of the present application is shown;
[0043] Figure 3 A structural schematic diagram of a network card management device provided by an embodiment of the present application is shown;
[0044] Figure 4 A structural schematic diagram of a network card management device provided by another embodiment of the present application is shown;
[0045] Figure 5 A structural schematic diagram of a network card management device provided by another embodiment of the present application is shown;
[0046] Figure 6A structural schematic diagram of a network card management and control device is shown. DETAILED DESCRIPTION
[0047] Exemplary embodiments of the present disclosure will be described in greater detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided so that the present disclosure can be more thoroughly understood and the scope of the present disclosure can be accurately conveyed to those skilled in the art.
[0048] Currently, after a physical network card in a host computer is directly used by a virtual machine, the virtual machine will use its own naming mechanism to rename the directly used physical network card. However, since the host computer and the virtual machine have independent network card naming mechanisms, the renamed network card name may conflict with the names of other physical network cards in the host computer, which makes it difficult to accurately identify the corresponding physical network card through the network card name, and thus it is difficult to manage and control the physical network card.
[0049] The inventors have found that if the host computer synchronizes its preset network card naming rules to the virtual machine, the virtual machine can name the directly used physical network card based on the preset network card naming rules in the case of directly using the physical network card in the host computer. In this way, since the virtual machine uses the preset network card naming rules synchronized from the host computer to name the directly used physical network card, the possibility of conflict between the named network card name and other physical network cards can be reduced, thereby ensuring that the corresponding physical network card can be correctly identified based on the network card name, and normal management and control of the physical network card can be achieved.
[0050] Based on the above finding, the embodiments of the present disclosure specifically provide a technical solution for network card management and control applied to a virtual machine. Specifically, the virtual machine stores preset network card naming rules synchronized from a host computer; a target physical network card directly used by the host computer is determined; and the target physical network card is named based on the preset network card naming rules.
[0051] Correspondingly, the embodiments of the present disclosure also provide a technical solution for network card management and control applied to a host computer. Specifically, the host computer is configured to directly use a physical network card to a virtual machine, and to synchronize preset network naming rules to the virtual machine; when the virtual machine needs to perform network card management and control, the preset network card naming rules are synchronized to the virtual machine, so that the virtual machine names a target physical network card directly used by the host computer based on the preset network card naming rules.
[0052] Based on the technical solution of the network card management and control, the embodiment specifically provides a network card management and control method and device applied to a virtual machine, and a network card management and control method and device applied to a host, and the network card management and control method and device applied to the virtual machine, the network card management and control method and device applied to the host are specifically described as follows.
[0053] The embodiment of the present application provides a network card management and control method, which is applied to a virtual machine, and a preset network card naming rule synchronized by a host is stored in the virtual machine, as shown in the figure, and the network card management and control method mainly includes the following steps 101 to 102. Figure 1
[0054] 101. Determine the target physical network card directly passed through from the host to the virtual machine.
[0055] The host is deployed with a virtual machine and a physical network card, and the host realizes network interaction through the physical network card and realizes corresponding business functions through the virtual machine. During use of the host, the virtual machine also needs to perform network interaction, and therefore, in order to reduce the network forwarding overhead of some virtual machines, the host will directly pass through the physical network card to the virtual machine for use.
[0056] In the case that the host directly passes through the physical network card to the virtual machine, the virtual machine needs to determine the target physical network card directly passed through from the host to the virtual machine, so that the virtual machine can name the target physical network card. In the case that the host directly passes through the physical network card to the virtual machine, in order to enable the virtual machine to use the directly passed-through physical network card as its own network card, the host usually allocates a physical address in the corresponding virtual machine to the directly passed-through physical network card. It is considered that the physical address and the physical network card are one-to-one in the virtual machine, and therefore, the target physical network card directly passed through from the host to the virtual machine can be determined through the target physical address allocated to the directly passed-through physical network card in the virtual machine.
[0057] Specifically, before determining the target physical network card directly passed through from the host to the virtual machine, the target physical address allocated to the target physical network card in the virtual machine is acquired. The specific process of determining the target physical network card directly passed through from the host to the virtual machine can include the following steps: searching for the target physical address in the physical address of the virtual machine; and determining the physical network card corresponding to the target physical address as the target physical network card directly passed through from the host to the virtual machine.
[0058] The target physical address is allocated by the host when the target physical network card is directly passed through to the virtual machine, in order to enable the virtual machine to acquire the target physical address, the virtual machine and the host have a shared memory in common, and the shared memory stores the target physical address allocated to the target physical network card in the virtual machine written by the host. In this way, the specific process of acquiring the target physical address allocated to the target physical network card in the virtual machine can include the following steps: reading the target physical address allocated to the target physical network card in the virtual machine from the shared memory.
[0059] Specifically, the target physical address allocated to the target physical network card in the virtual machine and stored in the shared memory can be written into the shared memory at the following two times based on the business needs: one is written when the target physical network card is directly connected to the virtual machine, so as to ensure that the virtual machine obtains the target physical address in time; the other is written when the virtual machine requests the physical address from the host, so as to avoid that the target physical address occupies the storage space of the shared memory for a long time, and to ensure that the virtual machine obtains the target physical address in time when the target physical network card is determined to be needed. In the embodiment, the physical address is determined based on a specific physical interface, which is not limited in the embodiment. For example, the physical address is a PCI address.
[0060] In order to allocate the physical address of the directly connected physical network card in the corresponding virtual machine, the virtual machine configuration program is preset in the host. The virtual machine configuration program is used to allocate the physical address of the physical network card directly connected to the virtual machine in the corresponding virtual machine. In addition, in order to ensure that the target physical address can be written into the shared memory at the above two times, the virtual machine configuration file is also preset in the host, which is used for the virtual machine configuration program to write the physical address of the physical network card allocated in the corresponding virtual machine. It should be noted that, in order to ensure the timeliness of the virtual machine configuration file, the virtual machine configuration file will be updated in real time based on the physical address allocation of the virtual machine configuration program, that is, once there is a physical network card directly connected to the virtual machine, the virtual machine configuration file must record the physical address of the physical network card allocated in the corresponding virtual machine.
[0061] In the embodiment, the virtual machine has corresponding physical addresses, which are used by the virtual machine to call corresponding physical devices. Therefore, after obtaining the target physical address of the target physical network card allocated in the virtual machine, the target physical address needs to be searched in the physical addresses of the virtual machine, and then the physical network card corresponding to the target physical address is determined as the target physical network card directly connected to the virtual machine by the host.
[0062] 102. Name the target physical network card based on the preset network card naming rule.
[0063] The preset network card naming rule is a network card naming rule used by the host to name the network card name of the physical network card in the host. Therefore, the virtual machine names the target physical network card based on the preset network card naming rule, which can avoid the conflict between the network card name named for the target physical network card and the name of other physical network cards in the host.
[0064] The preset network card naming rule is specifically used to instruct to combine at least one network card attribute of the physical network card in a preset order to obtain a network card name. The preset network card naming rule instructs to name the physical network card by using at least one network card attribute of the physical network card. The purpose of naming the physical network card by using at least one network card attribute of the physical network card is that the network card name obtained by naming can explicitly know the corresponding network card attribute of the physical network card, so as to facilitate the user to know the network card attribute of the physical network card.
[0065] In order to be able to name the network card based on the preset network card naming rule, the following steps can be performed before naming the target physical network card based on the preset network card naming rule: based on the preset network card naming rule, at least one network card attribute required for naming the target physical network card is obtained. Then, the step of naming the target physical network card based on the preset network card naming rule is performed. The specific implementation process of the step can be: combining at least one obtained network card attribute in a preset order to obtain the corresponding network card name of the target physical network card.
[0066] At least one network card attribute required for naming the target physical network card is provided by the host computer. Therefore, in order to be able to obtain the network card attribute provided by the host computer, the virtual machine and the host computer have a shared memory in common. The shared memory stores at least one network card attribute required for naming the target physical network card written by the host computer. Therefore, the specific process of obtaining at least one network card attribute required for naming the target physical network card based on the preset network card naming rule can include the following steps: based on the preset network card naming rule, at least one network card attribute required for naming the target physical network card is read from the shared memory.
[0067] Specifically, at least one network card attribute required for naming the target physical network card stored in the shared memory can be written into the shared memory based on business needs at the following two times: one is written when the target physical network card is directly connected to the virtual machine. In this way, the virtual machine can obtain at least one network card attribute required for naming the target physical network card in time. The other is written when the virtual machine requests the network card attribute of the target physical network card from the host computer. In this way, it can not only avoid that the network card attribute occupies the storage space of the shared memory for a long time, but also ensure that the virtual machine can obtain at least one network card attribute required for naming the target physical network card in time when it needs to name the target physical network card.
[0068] After obtaining at least one network card attribute required for naming the target physical network card based on the preset network card naming rule, the at least one obtained network card attribute is combined in a preset order to obtain a network card name corresponding to the target physical network card. The preset order is used to indicate the combination order of the network card attributes. The at least one network card attribute required for naming the target physical network card can include, but is not limited to, at least one of the following: a physical location of the physical network card in the host, a network card rate, and a network card type. For example, when the at least one network card attribute required for naming the target physical network card includes the physical location of the physical network card in the host, the network card rate, and the network card type, the preset order is used to indicate that the network card attributes of the physical network card are combined in the following order: the network card rate, the network card type, and the physical location of the physical network card in the host.
[0069] Further, in order to be able to distinguish each network card attribute through the network card name, the preset network card naming rule is further used to indicate a separator between adjacent network card attributes, and the separator is used to separate adjacent network card attributes, so as to be able to distinguish each network card attribute from the network card name through the separator. The specific type of the separator can be determined based on business requirements, which is not limited in the embodiment. For example, the separator can include, but is not limited to, a semicolon, a colon, and the like.
[0070] When the preset network card naming rule includes the separator, after the at least one obtained network card attribute is combined in the preset order, the corresponding separator is further added between adjacent network card attributes based on the preset network card naming rule, so that the obtained network card name corresponding to the target physical network card includes the separator, and each network card attribute of the target physical network card can be clearly known from the network card name through the separator.
[0071] The network card management method provided in the embodiment of the application stores the preset network card naming rule synchronized by the host in the virtual machine, determines the target physical network card directly connected to the virtual machine by the host, and names the target physical network card based on the preset network card naming rule. In this way, since the virtual machine uses the preset network card naming rule synchronized by the host to name the directly connected physical network card, the possibility of conflict between the named network card name and other physical network cards can be reduced, so that the corresponding physical network card can be correctly identified based on the network card name, and the physical network card can be normally managed and controlled.
[0072] In some embodiments of the present application, in order to make full use of the storage resources in the host computer, the shared memory commonly used by the host computer and the virtual machine is obtained by dividing the system memory of the host computer, and therefore, in order to obtain at least one network card attribute required for naming the target physical network card, the target physical address allocated to the target physical network card in the virtual machine and other data from the shared memory, the network card management method can further include the following steps: obtaining the corresponding memory start and end addresses of the shared memory in the system memory of the host computer; mapping the memory start and end addresses to the user process address space of the virtual machine; accessing the shared memory based on the memory start and end addresses in the user process address space, and reading the corresponding data from the shared memory.
[0073] The shared memory is obtained by dividing the system memory of the host computer, and therefore, in order to enable the virtual machine to access the shared memory, the corresponding memory start and end addresses of the shared memory in the system memory of the host computer need to be obtained to explicitly indicate the location of the shared memory in the system memory of the host computer. Then, the memory start and end addresses are mapped to the user process address space of the virtual machine to convert the memory start and end addresses into addresses that can be recognized and accessed by the virtual machine. After the mapping is completed, the shared memory can be accessed based on the memory start and end addresses in the user process address space, and the corresponding data can be read from the shared memory. The data can include, but is not limited to, at least one network card attribute required for naming the target physical network card, the target physical address allocated to the target physical network card in the virtual machine and other data.
[0074] In some embodiments of the present application, in the case where the host computer directly passes the physical network card to the virtual machine for use, in order to ensure that the virtual machine can successfully use the physical network card after the physical network card is directly passed to the virtual machine, the network card management method can further include the following steps: driving the target physical network card based on the network card driver already deployed in the virtual machine; if the driving is successful, performing the above-mentioned step 102 of naming the target physical network card based on the preset network card naming rule; if the driving fails, deploying a network card driver that can drive the target physical network card, or issuing a prompt of direct passing failure of the target physical network card.
[0075] The physical network card needs to be driven by the corresponding network card driver before it can be used, so after the physical network card is directly connected to the virtual machine, the target physical network card needs to be driven based on the network card driver deployed in the virtual machine. If the driving is successful, it means that the target physical network card directly connected to the virtual machine can be used in the virtual machine, so the above step 102 can be continued. If the driving fails, it means that the target physical network card directly connected to the virtual machine cannot be used in the virtual machine, at this time, the following two processing measures can be taken: one is to select a network card driver that can drive the target physical network card for deployment, so as to drive the target physical network card through the newly deployed network card driver. The second is to issue a prompt for the failure of the target physical network card to directly connect, so as to make the user know the fact that the target physical network card cannot be used in the virtual machine based on the prompt, so that the user can handle the exception based on the prompt. It should be noted that the prompt can be delivered to the host through the above shared memory, so that the host can prompt in the form of prompt text. In addition, if the driving is successful, and the corresponding network card name is named for the target physical network card through step 102, a feedback of the success of the virtual machine directly connected can be generated, and the feedback can be delivered to the host through the above shared memory, so that the host knows the fact that the target physical network card is directly connected successfully based on the feedback.
[0076] In some embodiments of the present application, the host or user usually controls the physical network card based on the network card name of the physical network card in the host. When the physical network card is renamed by the virtual machine, the host or user will not be able to identify the physical network card based on the network card name of the physical network card in the host. Therefore, it will be difficult for the host or user to control the physical network card. For example, the host directly connects the physical network card 1 with the network card name "eth0" to the virtual machine 1. After the physical network card 1 is directly connected to the virtual machine 1, the virtual machine 1 changes the network card name of the physical network card 1 from "eth0" to "ATH001" based on its own naming mechanism. At this time, when the host controls the physical network card based on the network card name of the physical network card in the host, it will be determined that the physical network card 1 with the network card name "eth0" disappears. The host will not be able to perceive the physical network card 1, so it cannot control the physical network card 1.
[0077] Considering that the host or user usually controls the physical network card based on the network card name of the physical network card in the host, in order to ensure that the virtual machine can name the physical network card with the same network card name as in the host after the physical network card is directly connected to the virtual machine, the preset network card naming rule is the same as the network card naming rule used to name the physical network card in the host. In this way, after the virtual machine names the target physical network card based on the preset network card naming rule, the name of the physical network card can be prevented from changing, so that the host or user can still control the target physical network card based on the network card name of the physical network card in the host.
[0078] In some embodiments of the present application, the following is an example to specifically describe the process of naming the target physical network card based on the preset network card naming rule. The preset network card naming rule specifically indicates the following: the network card attributes required for naming the physical network card include the physical location of the physical network card in the host, the network card rate, and the network card type; the preset order is used to indicate the combination of the network card attributes of the physical network card in the following order: the network card rate, the network card type, and the physical location of the physical network card in the host; and the separator between adjacent network card attributes is “+”.
[0079] It is determined that the target physical network card directly passed through by the host to the virtual machine is “physical network card 1”. Based on the preset network card naming rule, the network card attributes required for naming “physical network card 1” include: the physical location of physical network card 1 is the first on-board network card, the network card type is a wired network card, and the network card rate is 1 Gbps. Then, the network card name corresponding to “physical network card 1” is obtained by combining the obtained network card attributes in the preset order, which is: 1 Gbps+ wired network card+ the first on-board network card. It can be seen that the network card attributes of “physical network card 1” can be clearly known through the obtained network card name.
[0080] Further, the present embodiment considers that if the network card name is directly obtained by using the original data of the physical location of the physical network card in the host, the network card rate, and the network card type, the network card name will be too long. Therefore, the present application also proposes that the physical location of the physical network card in the host, the network card rate, and the network card type can be converted into corresponding specified characters through conversion operation, and then the network card name is obtained by using the corresponding specified characters. For example, for the conversion rule of the physical location of the physical network card in the host, please refer to Table-1. For the conversion rule of the network card rate, please refer to Table-2. For the conversion rule of the network card type, please refer to Table-3. For example, the physical location of physical network card 1 in the host is the first on-board network card, the network card type is a wired network card, and the network card rate is 1 Gbps. Then, the network card name named for physical network card 1 after conversion is: ge1.
[0081] Table-1
[0082] Designated character Physical location of physical network card in host machine N Nth on-board network card S P Bth network card on slot a
[0083] Table-2
[0084] Designated character Network card rate g 1 Gbps physical network card x 10 Gbps physical network card Qx 40 Gbps physical network card
[0085] Table-3
[0086] Designated character Network card type e Wired network card w Wireless network card
[0087] Further, the embodiment of the present application provides another network card management method, which is applied to a host computer, the host computer is deployed with at least one virtual machine and at least one physical network card, and the host computer is used to directly pass the physical network card to the virtual machine and synchronize preset network naming rules to the virtual machine, for example, as shown in the figure, the network card management method mainly includes the following step 201: Figure 2
[0088] 201. When the virtual machine needs to be managed, the preset network card naming rule is synchronized to the virtual machine, so that the virtual machine names the target physical network card directly passed by the host computer based on the preset network card naming rule.
[0089] In the embodiment, the method for determining that the virtual machine needs to be managed can include the following two methods: one is to determine that the virtual machine needs to be managed when the network card management instruction is received; the other is to determine that the virtual machine needs to be managed when the host computer directly passes the physical network card to the virtual machine.
[0090] When the virtual machine needs to be managed, the preset network card naming rule is synchronized to the virtual machine. The preset network card naming rule is the network card naming rule used by the host computer to name the network card name of the physical network card in the host computer. The preset network card naming rule is synchronized to the virtual machine, so that the virtual machine names the target physical network card directly passed by the host computer based on the preset network card naming rule, which can avoid the network card name named by the virtual machine for the target physical network card from conflicting with the name of other physical network cards in the host computer.
[0091] In the embodiment, the network device deployed in the host computer has at least one virtual machine and at least one physical network card, which realizes network interaction through the physical network card and realizes corresponding business functions through the virtual machine. The type of the host computer can be selected based on business needs, and the embodiment does not limit it. For example, the host computer is a network security device, and the virtual machine deployed in the host computer is used to run the core security detection function of the network security device to realize the isolation of the core security detection function and other functions in the host computer.
[0092] During the use of the host computer, the virtual machine also performs network interaction, and therefore, in order to reduce the network forwarding overhead of some virtual machines, the host computer can directly pass a physical network card to a virtual machine for use. The method for determining the target physical network card directly passed to the virtual machine by the host computer can include the following two methods: one is that the target physical network card directly passed to the virtual machine is specified by a user, and when there is a physical network card directly passed to the corresponding virtual machine, the host computer takes the specified physical network card as the target physical network card. The other is that the target physical network card directly passed to the virtual machine is selected based on the actual virtual network forwarding overhead of the virtual machine deployed in the host computer, that is, when it is detected that the virtual network forwarding overhead of any virtual machine reaches a corresponding preset threshold, the physical network card meeting the virtual network forwarding overhead of the virtual machine is determined as the target physical network card.
[0093] After the target physical network card is determined, the target physical network card can be directly passed to the corresponding virtual machine, so that the virtual machine can directly use the target physical network card, thereby reducing the network forwarding overhead of the corresponding virtual machine.
[0094] The network card management method provided in this embodiment can synchronize the preset network card naming rule to the virtual machine when the virtual machine needs to perform network card management, so that the virtual machine names the target physical network card directly passed by the host computer based on the preset network card naming rule. In this way, since the virtual machine names the directly passed physical network card based on the preset network card naming rule synchronized from the host computer, the possibility of conflict between the named network card name and other physical network cards can be reduced, thereby ensuring that the corresponding physical network card can be correctly identified based on the network card name, and normal management of the physical network card can be realized.
[0095] In some embodiments of the present application, the preset network card naming rule is used to indicate that at least one network card attribute of the physical network card is combined in a preset order to obtain a network card name. In order to enable the virtual machine to name the target physical network card based on the preset network card naming rule, the network card management method can further include the following steps: based on the preset network card naming rule, synchronizing at least one network card attribute required for naming the target physical network card to the corresponding virtual machine, so that the virtual machine combines the obtained at least one network card attribute in a preset order to name the target physical network card.
[0096] In this embodiment, in order to be able to provide at least one network card attribute required for naming the target physical network card to the virtual machine, the virtual machine and the host computer have a shared memory, and the shared memory is used to provide at least one network card attribute required for naming the target physical network card to the virtual machine. Therefore, the specific steps of providing at least one network card attribute required for naming the target physical network card to the corresponding virtual machine based on the preset network card naming rule can include: based on the preset network card naming rule, writing at least one network card attribute required for naming the target physical network card into the shared memory.
[0097] In this embodiment, each physical network card in the host computer has a corresponding network card description file, which is used to record the corresponding physical location, network card rate, network card type, physical address and other information of the physical network card. Therefore, at least one network card attribute required for naming the target physical network card can be obtained from the network card description file based on a preset network card naming rule.
[0098] Each network card attribute has a corresponding acquisition command, and the corresponding network card attribute can be obtained from the description file through the corresponding acquisition command. For example, for the network card attribute "physical location", the physical location of the network card in the host computer is obtained from the corresponding description file through the corresponding physical location acquisition instruction. For example, for the network card attribute "network card rate", the network card rate is obtained from the corresponding description file through the corresponding network card rate acquisition instruction. For example, for the network card attribute "network card type", the physical address corresponding to the network card (for example, the physical address is 0000:03:00.3) is first obtained from the description file, and then the corresponding description file is queried again through the command "lspci | grep 0000:03:00.3 | grep wireless". If the command query result output is empty, it is determined that the network card type of the physical network card is a wired network card, and if the command query result output is not empty, it is determined that the network card type of the physical network card is a wireless network card.
[0099] In some embodiments of the present application, in order to enable the virtual machine to determine the target physical network card directly passed through by the host computer to the virtual machine, the virtual machine and the host computer have a shared memory in common, and the shared memory is used to provide the virtual machine with a target physical address to which the target physical network card is allocated in the virtual machine. Therefore, the network card management method can further include: writing the target physical address to which the target physical network card is allocated in the virtual machine into the shared memory, so that the virtual machine determines the physical network card corresponding to the target physical address as the target physical network card directly passed through by the host computer to the virtual machine.
[0100] In some embodiments of the present application, in order to fully utilize the storage resources in the host computer, the shared memory in common between the host computer and the virtual machine is obtained by dividing the system memory of the host computer, and the system memory of the host computer includes continuous memory huge pages. Therefore, the specific division process of the shared memory can include the following steps: selecting a target memory huge page according to the paging storage amount of the memory huge page and a preset storage amount, and dividing the target memory huge page into the shared memory; and mapping the target memory huge page to a preset process address space to obtain the memory start and end addresses of the shared memory.
[0101] In this embodiment, in order to improve the memory access efficiency of the host computer and facilitate the use of system memory of the host computer, the memory management technology of large page memory divides the system memory of the host computer into continuous memory large pages based on a preset paging storage amount, that is, the system memory of the host computer includes continuous memory large pages. The paging storage amount is used to limit the size of each memory large page, for example, 2MB.
[0102] In order to manage the memory large pages of the system memory, the host computer mounts the memory large pages in the file system of the host computer, such as mounting the directory as / mnt / hugepage. In the mounting directory, there is a large page code corresponding to each memory large page. Then, according to the paging storage amount of the memory large page and the preset storage amount required by the shared memory, the target memory large page is selected in the memory large page, and the target memory large page is divided into shared memory with a preset storage amount. After the shared memory is divided, the shared memory can exist in the form of a folder under the mounting directory.
[0103] After the shared memory is divided, in order to be able to use the shared memory, the mmap system is called to map the target memory large page corresponding to the shared memory to the preset process address space of the host computer, so as to set the corresponding process address for each target memory large page in the process address space. The target memory large page is continuous, so the process address of the memory large page arranged in the first place in the target memory large page is obtained as the memory start address of the shared memory, and the process address of the memory large page arranged in the last place in the target memory large page is obtained as the memory end address of the shared memory, so that the memory start and end addresses of the shared memory are obtained based on the memory start address and the memory end address.
[0104] After obtaining the memory start and end addresses, if it is required to write at least one network card attribute required for naming the target physical network card into the shared memory, based on the memory start and end addresses, at least one network card attribute required for naming the target physical network card is written into the shared memory. If it is required to write the target physical address of the target physical network card into the shared memory, based on the memory start and end addresses, the target physical address of the target physical network card is written into the shared memory.
[0105] In some embodiments of the present application, generally, the host computer has a system default network card naming rule. Without external intervention, the host computer names each physical network card in the host computer based on the default network card naming rule. However, in some scenarios, the default network card naming rule may not meet the naming requirements of the user. For example, the network card name named by the default network card naming rule cannot explicitly indicate the network card attribute of the corresponding physical network card. Therefore, in order to meet the user's requirements, the user can formulate a network card naming rule, so that the host computer names each physical network card in the host computer based on the customized network card naming rule. The customized network card naming rule is used to indicate that at least one network card attribute of the physical network card is combined in a preset order to obtain the network card name.
[0106] In the present embodiment, the host computer has a system default network card naming rule. If the user accepts to use the default network card naming rule, the host computer names each physical network card in the host computer based on the default network card naming rule, and synchronizes the default network card naming rule to the virtual machine as a preset network card naming rule. If the user does not accept to use the default network card naming rule, in order to avoid confusion in the naming of the physical network card, the default network card naming rule can be disabled first, and then each physical network card in the host computer is named based on a customized network card naming rule, and the customized network card naming rule is synchronized to the virtual machine as a preset network card naming rule.
[0107] Further, one embodiment of the present application also provides a network card management device applied to a virtual machine, wherein the virtual machine stores a preset network card naming rule synchronized by a host computer, as shown in the figure, the network card management device mainly comprises: Figure 3
[0108] A determination module 31 is configured to determine a target physical network card directly passed through from the host computer to the virtual machine.
[0109] A naming module 32 is configured to name the target physical network card based on the preset network card naming rule.
[0110] The network card management device provided by the present application stores the preset network card naming rule synchronized by the host computer in the virtual machine. In the case that the host computer directly passes the physical network card to the virtual machine, the target physical network card directly passed through from the host computer to the virtual machine is determined, and the target physical network card is named based on the preset network card naming rule. In this way, since the virtual machine uses the preset network card naming rule synchronized from the host computer to name the directly passed physical network card, the possibility of conflict between the named network card name and other physical network cards can be reduced, so that the corresponding physical network card can be correctly identified based on the network card name, and the physical network card can be normally managed and controlled.
[0111] In some embodiments of the present application, as shown in the figure, the network card management device further comprises: Figure 4 As shown, the preset network card naming rule is used to instruct to combine at least one network card attribute of the physical network card in a preset order to obtain a network card name; and the network card management device further includes:
[0112] The first obtaining module 33 is configured to obtain at least one network card attribute required for naming the target physical network card based on the preset network card naming rule.
[0113] The naming module 32 is specifically configured to combine the at least one network card attribute obtained by the first obtaining module 33 in the preset order to obtain the corresponding network card name of the target physical network card.
[0114] In some embodiments of the present application, as shown in Figure 4 The virtual machine and the host have a shared memory in common, and the shared memory stores at least one network card attribute written by the host and required for naming the target physical network card; and the first obtaining module 33 is specifically configured to read at least one network card attribute required for naming the target physical network card from the shared memory based on the preset network card naming rule.
[0115] In some embodiments of the present application, at least one network card attribute stored in the shared memory and required for naming the target physical network card is written when the target physical network card is directly connected to the virtual machine, or is written when the virtual machine requests the network card attribute of the target physical network card from the host.
[0116] In some embodiments of the present application, as shown in Figure 4 The preset network card naming rule is further used to instruct a separator between adjacent network card attributes; and the naming module 32 is further configured to add a corresponding separator between adjacent network card attributes based on the preset network card naming rule after combining the at least one network card attribute obtained by the first obtaining module 33 in the preset order.
[0117] In some embodiments of the present application, as shown in Figure 4 The at least one network card attribute obtained by the first obtaining module 33 includes at least one of the following: a physical location of the physical network card in the host, a network card rate, and a network card type.
[0118] In some embodiments of the present application, the preset order is used to instruct to combine the network card attributes of the physical network card in the following order: the network card rate, the network card type, and the physical location of the physical network card in the host.
[0119] In some embodiments of the present application, as shown in Figure 4 The network card management device further includes a second obtaining module 34 configured to obtain a target physical address to which the target physical network card is allocated in the virtual machine.
[0120] The determining module 31 is specifically configured to search for the target physical address obtained by the second obtaining module 34 in the physical address of the virtual machine, and determine the physical network card corresponding to the target physical address as the target physical network card directly passed through from the host computer to the virtual machine.
[0121] In some embodiments of the present application, as shown in Figure 4 The virtual machine and the host computer have a shared memory, and the shared memory stores the target physical address of the target physical network card allocated in the virtual machine by the host computer, which is allocated by the host computer when the target physical network card is directly passed through to the virtual machine. The second obtaining module 34 is specifically configured to read the target physical address of the target physical network card allocated in the virtual machine from the shared memory.
[0122] In some embodiments of the present application, as shown in Figure 4 The shared memory is obtained by dividing the system memory of the host computer. The card management device further includes a first obtaining module 33 and / or a second obtaining module 34, which are specifically configured to obtain the memory start and end addresses of the shared memory in the system memory of the host computer, map the memory start and end addresses to the user process address space of the virtual machine, access the shared memory based on the memory start and end addresses in the user process address space, and read corresponding data from the shared memory.
[0123] In some embodiments of the present application, as shown in Figure 4 The card management device further includes:
[0124] The driving module 35 is configured to drive the target physical network card determined by the determining module 31 based on the network card driver already deployed in the virtual machine. If the driving is successful, the naming module 32 is triggered to perform the step of naming the target physical network card based on the preset network card naming rule. If the driving fails, the deployment module 36 is triggered to select a network card driver capable of driving the target physical network card for deployment, or the prompting module 37 is triggered to issue a prompt of direct pass failure of the target physical network card.
[0125] In some embodiments of the present application, the preset network card naming rule is the same as the network card naming rule used for naming the physical network card in the host computer.
[0126] In the card management device provided by the embodiments of the present application, the detailed descriptions of the running processes of the various functional modules can be referred to the corresponding detailed descriptions of the card management method embodiments described above, which will not be repeated here.
[0127] Further, an embodiment of the present application further provides a network card management and control device, which is applied to a host computer, at least one virtual machine and at least one physical network card are deployed in the host computer, the host computer is used for directly passing the physical network card to the virtual machine and synchronizing a preset network naming rule to the virtual machine, as shown in Figure 5 The network card management and control device mainly comprises:
[0128] A synchronization module 41 is configured to synchronize the preset network card naming rule to the virtual machine when the virtual machine needs to perform network card management and control, so that the virtual machine names a target physical network card directly passed by the host computer based on the preset network card naming rule.
[0129] The network card management and control device provided by the embodiment of the present application synchronizes the preset network card naming rule to the virtual machine when the virtual machine needs to perform network card management and control, so that the virtual machine names a target physical network card directly passed by the host computer based on the preset network card naming rule. In this way, since the virtual machine names the directly passed physical network card based on the preset network card naming rule synchronized from the host computer, the possibility of conflict between the named network card name and other physical network cards can be reduced, so that the corresponding physical network card can be correctly identified based on the network card name, and normal management and control of the physical network card is realized.
[0130] In some embodiments of the present application, as shown in Figure 6 The preset network card naming rule is used to indicate that at least one network card attribute of the physical network card is combined in a preset order to obtain a network card name, and
[0131] The synchronization module 41 is further configured to synchronize at least one network card attribute required for naming the target physical network card to the corresponding virtual machine based on the preset network card naming rule, so that the virtual machine combines the at least one network card attribute in a preset order to name the target physical network card.
[0132] In some embodiments of the present application, as shown in Figure 6 The virtual machine and the host computer have a shared memory, the shared memory is used to provide at least one network card attribute required for naming the target physical network card to the virtual machine, and then the synchronization module 41 is specifically configured to write the at least one network card attribute required for naming the target physical network card into the shared memory based on the preset network card naming rule.
[0133] In some embodiments of the present application, as shown in Figure 6 The system memory of the host computer comprises a continuous memory large page, and then the network card management and control device further comprises:
[0134] The dividing module 42 is configured to select a target memory huge page according to a paging storage amount of the memory huge page and a preset storage amount, divide the target memory huge page into the shared memory, and map the target memory huge page to a preset process address space to obtain a memory start and end address of the shared memory.
[0135] The synchronizing module 41 is configured to write at least one network card attribute required for naming the target physical network card into the shared memory based on the memory start and end address.
[0136] In the network card management and control device provided by the embodiments of the present application, the detailed descriptions of the operation of each functional module can refer to the corresponding descriptions of the network card management and control method embodiments, which will not be repeated here.
[0137] Further, one of the embodiments of the present application further provides a computer readable storage medium, which includes a stored program, wherein when the program runs, the device where the storage medium is located performs the network card management and control method applied to the virtual machine.
[0138] Further, one of the embodiments of the present application further provides a computer readable storage medium, which includes a stored program, wherein when the program runs, the device where the storage medium is located performs the network card management and control method applied to the host.
[0139] Further, another embodiment of the present application further provides an electronic device, which includes a memory configured to store a program, and a processor coupled to the memory and configured to run the program to perform the network card management and control method applied to the virtual machine.
[0140] Further, another embodiment of the present application further provides an electronic device, which includes a memory configured to store a program, and a processor coupled to the memory and configured to run the program to perform the network card management and control method applied to the host.
[0141] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can refer to the relevant description of other embodiments.
[0142] It can be understood that the related features in the above method and device can be mutually referred. In addition, the "first", "second" and the like in the above embodiments are used to distinguish the embodiments, and do not represent the advantages and disadvantages of the embodiments.
[0143] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system, device and unit described above can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.
[0144] The algorithms and displays presented herein are not inherently related to any particular computer, virtual system, or other apparatus. Various general purpose systems can be used with programs in accordance with the teachings herein, or it can prove convenient to construct more specialized apparatus to perform the required method steps. The required structure for a variety of these systems will be apparent from the description above. In addition, the present application is not described with reference to any particular programming language. It will be appreciated that a variety of programming languages can be used to implement the teachings of the application as described herein, and any references below to specific languages are provided for disclosure of enablement only.
[0145] Moreover, the memory can include non-transitory memory in a computer-readable medium, a random access memory (RAM), and / or a read only memory (ROM), such as flash, a hard drive, or any other form of storage, including at least one storage chip.
[0146] As will be appreciated by one of ordinary skill in the art, embodiments of the present application can be embodied as a method, system, or computer program product. Accordingly, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, magnetic disks, CD-ROMs, optical storage devices, and the like) embodying computer program code.
[0147] The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other processing device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other processing device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions specified in the flowchart block or blocks. Figure 1 The flowchart and / or block diagram in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart and / or block diagrams can represent a module, segment, or portion of code, which comprises one or more executable Figure 1 The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other processing device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other processing device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions specified in the flowchart block or blocks. The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other processing device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other processing device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions specified in the flowchart block or blocks.
[0148] The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other processing device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other processing device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions specified in the flowchart block or blocks. Figure 1 The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other processing device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other processing device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions specified in the flowchart block or blocks. Figure 1 The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other processing device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other processing device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions specified in the flowchart block or blocks. The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other processing device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other processing device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions specified in the flowchart block or blocks.
[0149] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 Figure 1
[0150] In one typical configuration, the computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0151] The memory can include non-persistent memory and / or volatile memory, such as random access memory (RAM) about which the processor can execute instructions. The memory can also include non-volatile memory, such as read only memory (ROM), electrically programmable read only memory (EPROM), electrically erasable programmable read only memory (EEPROM), programmable read only memory (PROM), erasable programmable read only memory (EPROM), flash memory, or a combination of non-volatile memories in different types. The memory can also include a compact disk read only memory (CD-ROM), digital versatile disk (DVD), Blu-ray, or another non-transitory computer readable medium, which is non-volatile and non-transitory in nature.
[0152] Computer readable media includes permanent and non-permanent, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), electrically programmable read only memory (EEPROM), flash memory or other memory technology, compact disk read only memory (CD-ROM), digital versatile disk (DVD), or other optical storage, magnetic cassette, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible to a computing device. According to the definition herein, computer readable media does not include transitory media such as modulated data signals and carrier waves.
[0153] It should also be noted that the terms "comprising," "including," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements recited, but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element preceded by "comprises a" does not, without more constraints, foreclose the existence of additional identical elements in the process, method, article, or apparatus that includes the element.
[0154] Those skilled in the art will appreciate that embodiments of the present application can be devised for a method, a system, or a computer program product. Accordingly, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) embodying computer-readable program code thereon for use by or in connection with an instruction execution system. For the purposes of this description, a computer-usable or computer readable storage medium can be any apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.
[0155] The foregoing is merely illustrative of the embodiments of this application, and is not intended to limit the application. The application can be practiced with variation within the spirit and scope of the application, which are delineated by the appended claims.
Claims
1. A network card management method, characterized in that, The method is applied to a virtual machine, the virtual machine stores preset network card naming rules synchronized with a host computer, the preset network card naming rules are same as network card naming rules used for naming physical network cards in the host computer, and the method comprises the following steps: A target physical network card directly connected to the virtual machine by the host computer is determined; The target physical network card is named based on the preset network card naming rules.
2. The method of claim 1, wherein, The preset network card naming rules are used for indicating that at least one network card attribute of the physical network card is combined in a preset order to obtain a network card name; then, the method further comprises the following steps: At least one network card attribute required for naming the target physical network card is obtained based on the preset network card naming rules; Then, naming the target physical network card based on the preset network card naming rules comprises the following steps: The at least one network card attribute is combined in the preset order to obtain a corresponding network card name of the target physical network card.
3. The method of claim 2, wherein, The virtual machine and the host computer have a shared memory, and the shared memory stores at least one network card attribute written by the host computer and required for naming the target physical network card; then, obtaining at least one network card attribute required for naming the target physical network card based on the preset network card naming rules comprises the following steps: At least one network card attribute required for naming the target physical network card is read from the shared memory based on the preset network card naming rules.
4. The method of claim 3, wherein, The at least one network card attribute stored in the shared memory and required for naming the target physical network card is written when the target physical network card is directly connected to the virtual machine or when the virtual machine requests network card attributes of the target physical network card from the host computer.
5. The method of claim 2, wherein, The preset network card naming rules are further used for indicating separators between adjacent network card attributes; then, after the at least one network card attribute is combined in the preset order, the method further comprises the following steps: Corresponding separators are added between adjacent network card attributes based on the preset network card naming rules.
6. The method according to any one of claims 2-5, characterized in that, The at least one network card attribute comprises at least one of the following: a physical position of the physical network card in the host computer, a network card rate, and a network card type.
7. The method of claim 6, wherein, The preset order is used for indicating that network card attributes of the physical network card are combined in the following order: the network card rate, the network card type, and the physical position of the physical network card in the host computer.
8. The method of claim 1, wherein, The method further comprises the following step: obtaining a target physical address allocated to the target physical network card in the virtual machine; Then, determining the target physical network card directly connected to the virtual machine by the host computer comprises the following steps: The target physical address is searched in a physical address of the virtual machine; A physical network card corresponding to the target physical address is determined as the target physical network card directly connected to the virtual machine by the host computer.
9. The method of claim 8, wherein, The virtual machine and the host computer have a shared memory, and the shared memory stores a target physical address allocated to the target physical network card in the virtual machine and written by the host computer, and the target physical address is allocated by the host computer when the target physical network card is directly connected to the virtual machine; then, obtaining the target physical address allocated to the target physical network card in the virtual machine comprises the following steps: reading, from the shared memory, a target physical address to which the target physical network card is allocated in the virtual machine.
10. The method according to claim 3 or 8, characterized in that, The shared memory is obtained by dividing the system memory of the host computer, and the method further comprises: obtaining a memory start and end address corresponding to the shared memory in the system memory of the host computer; mapping the memory start and end address to a user process address space of the virtual machine; accessing the shared memory based on the memory start and end address in the user process address space, and reading corresponding data from the shared memory.
11. The method according to any one of claims 1-5, 7-9, characterized in that, The method further comprises: driving the target physical network card based on a network card driver already deployed in the virtual machine; if the driving is successful, performing the step of naming the target physical network card based on the preset network card naming rule; if the driving fails, selecting a network card driver capable of driving the target physical network card for deployment, or issuing a prompt of a failure of the target physical network card pass-through.
12. A network card management method, characterized in that, The method is applied to a host computer, the host computer has at least one virtual machine and at least one physical network card deployed therein, the host computer is configured to pass through the physical network card to the virtual machine and synchronize a preset network naming rule to the virtual machine, the preset network naming rule is the same as a network card naming rule used for naming the physical network card in the host computer, and the method comprises: when the virtual machine needs to be controlled, synchronizing the preset network naming rule to the virtual machine, so that the virtual machine names a target physical network card passed through by the host computer based on the preset network naming rule.
13. The method of claim 12, wherein, The preset network naming rule is used to instruct to combine at least one network card attribute of the physical network card in a preset order to obtain a network card name, and the method further comprises: based on the preset network naming rule, synchronizing at least one network card attribute required for naming the target physical network card to a corresponding virtual machine, so that the virtual machine combines the at least one network card attribute in the preset order to name the target physical network card.
14. The method of claim 13, wherein, The virtual machine and the host computer have a shared memory in common, the shared memory is used to provide at least one network card attribute required for naming a target physical network card to the virtual machine, and based on the preset network naming rule, at least one network card attribute required for naming the target physical network card is provided to a corresponding virtual machine, which comprises: based on the preset network naming rule, writing the at least one network card attribute required for naming the target physical network card into the shared memory.
15. The method of claim 14, wherein, The system memory of the host computer comprises continuous memory huge pages, and the method further comprises: selecting a target memory huge page according to a paging storage amount of the memory huge page and a preset storage amount, and dividing the target memory huge page into the shared memory; mapping the target memory huge page to a preset process address space to obtain a memory start and end address of the shared memory; then, writing the at least one network card attribute required for naming the target physical network card into the shared memory comprises: based on the memory start and end address, writing the at least one network card attribute required for naming the target physical network card into the shared memory.
16. A network card management and control device, characterized in that, The application is applied to a virtual machine, the virtual machine stores preset network card naming rules synchronized by a host computer, the preset network card naming rules are same as network card naming rules used for naming physical network cards in the host computer, and the device comprises: A determining module is configured to determine a target physical network card directly passed through by the host computer to the virtual machine; A naming module is configured to name the target physical network card based on the preset network card naming rules.
17. A network card management and control device, characterized in that, The application is applied to a host computer, the host computer deploys at least one virtual machine and at least one physical network card, the host computer is used for directly passing the physical network card to the virtual machine and synchronizing preset network naming rules to the virtual machine, the preset network naming rules are same as network card naming rules used for naming physical network cards in the host computer, and the device comprises: A synchronizing module is configured to synchronize the preset network card naming rules to the virtual machine when the virtual machine needs to perform network card management and control, so that the virtual machine names a target physical network card directly passed through by the host computer based on the preset network card naming rules.
18. A computer-readable storage medium, characterized in that, The storage medium comprises a stored program, wherein the program controls a device where the storage medium is located to perform the network card management and control method in any one of claims 1 to 11 and / or perform the network card management and control method in any one of claims 12 to 15 when the program is running.
19. An electronic device, comprising: The electronic device comprises: A memory is configured to store a program; A processor is coupled to the memory and is configured to run the program to perform the network card management and control method in any one of claims 1 to 11 and / or perform the network card management and control method in any one of claims 12 to 15.
Citation Information
Patent Citations
Kvm virtual machine network card direct connection method and device used for host
CN106803794A
Network configuration method and device of virtual machine, storage medium and equipment
CN112994907A