WO2021169280A1 - 虚拟磁盘校验码生成方法、装置、设备及存储介质 - Google Patents

虚拟磁盘校验码生成方法、装置、设备及存储介质 Download PDF

Info

Publication number
WO2021169280A1
WO2021169280A1 PCT/CN2020/118230 CN2020118230W WO2021169280A1 WO 2021169280 A1 WO2021169280 A1 WO 2021169280A1 CN 2020118230 W CN2020118230 W CN 2020118230W WO 2021169280 A1 WO2021169280 A1 WO 2021169280A1
Authority
WO
WIPO (PCT)
Prior art keywords
virtual disk
data
check
command
size
Prior art date
Application number
PCT/CN2020/118230
Other languages
English (en)
French (fr)
Inventor
刘仁仕
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2021169280A1 publication Critical patent/WO2021169280A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/08Error detection or correction by redundancy in data representation, e.g. by using checking codes
    • G06F11/10Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's
    • G06F11/1008Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's in individual solid state devices
    • G06F11/1048Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's in individual solid state devices using arrangements adapted for a specific error detection or correction feature
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/11File system administration, e.g. details of archiving or snapshots
    • G06F16/128Details of file system snapshots on the file-level, e.g. snapshot creation, administration, deletion
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0662Virtualisation aspects
    • G06F3/0664Virtualisation aspects at device level, e.g. emulation of a storage device or system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45575Starting, stopping, suspending or resuming virtual machine instances

Definitions

  • This application relates to the field of data backup technology, and in particular to a method, device, device, and storage medium for generating a virtual disk checksum.
  • a virtual disk is used as a persistent data carrier of a virtual machine.
  • a virtual disk backup mechanism is indispensable.
  • the backup of a virtual disk is by taking a snapshot of the virtual disk at a certain moment, and then exporting the incremental or full snapshot data to the backup storage (secondary storage).
  • the incremental Merge into the full amount or directly pull the full amount of data back to the main storage.
  • the existence of silent errors of storage media, file system layer bugs and other issues make users face a problem that is how to confirm whether the backed up data and the data rolled back after the backup are the data that the user wants to back up at the time. This problem is usually solved by a check code mechanism.
  • various formats have their own data distribution mechanism, and on the other hand, the back end also supports various access protocols. Therefore, the existing method cannot support the direct export of the check code of the virtual disk.
  • the main purpose of this application is to provide a method, device, device, and storage medium for generating a virtual disk check code, which aims to solve the technical problem that the prior art cannot generate a virtual disk check code.
  • the present application provides a method for generating a virtual disk check code.
  • the method for generating a virtual disk check code includes the following steps: obtaining a virtual disk management command input by a user; if the virtual disk management command is a checksum Code generation command, the check code generation command is parsed to obtain the command parameters of the check code generation command; according to the command parameters, the value of the intermediate parameter check_size is set and the data to be checked are determined; If the check data is the data in the virtual disk, the virtual disk is opened in read-only mode according to the virtual disk path specified in the command parameter, and the capacity of the virtual disk is obtained; if the value of check_size is the preset threshold, Then let the value of check_size be equal to the capacity of the virtual disk, and start from the pointer offset parameter offset equal to the threshold, and read the data in the virtual disk in sequence according to the data read granularity specified in the command parameter , Until the offset is equal to the value of check_size; according to the information digest algorithm,
  • the present application also provides a virtual disk check code generation device
  • the virtual disk check code generation device includes: a command acquisition module for acquiring a virtual disk management command input by a user; a parsing module , Used to parse the check code generation command if the virtual disk management command is a check code generation command to obtain each command parameter of the check code generation command; the setting module is used to Command parameter, set the value of the intermediate parameter check_size and determine the data to be verified; the information acquisition module is used to read only the virtual disk path specified in the command parameter if the data to be verified is the data in the virtual disk
  • the virtual disk is opened in the method and the capacity of the virtual disk is obtained; the data reading module is used to make the value of check_size equal to the capacity of the virtual disk and offset from the pointer if the value of check_size is a preset threshold.
  • the amount parameter offset is equal to the threshold value, and the data in the virtual disk is read sequentially according to the data reading granularity specified in the command parameter until the offset is equal to the value of check_size; the check code generation module is used to follow
  • the information digest algorithm calculates and outputs a hash value of all data in the virtual disk, where the hash value is the check code of the virtual disk.
  • the present application also provides a virtual disk check code generation device, the virtual disk check code generation device including a memory, a processor, and stored on the memory and available on the processor.
  • the virtual disk check code generation program running on the computer when the virtual disk check code generation program is executed by the processor, the steps of the virtual disk check code generation program method described below are also implemented: obtain the virtual disk input by the user Management command; if the virtual disk management command is a check code generation command, the check code generation command is parsed to obtain the command parameters of the check code generation command; according to the command parameters, the middle is set The value of the parameter check_size and the data to be verified are determined; if the data to be verified is data in the virtual disk, the virtual disk is opened in read-only mode according to the virtual disk path specified in the command parameter, and the virtual disk is obtained If the value of check_size is the preset threshold, set the value of check_size to be equal to the capacity of the virtual disk, and start from the pointer offset parameter offset equal to the threshold, in
  • the present application also provides a computer-readable storage medium having a virtual disk check code generation program stored on the computer-readable storage medium, and the virtual disk check code generation program is executed by the processor During execution, the steps of the virtual disk check code generation program method described below are also implemented: obtain the virtual disk management command input by the user; if the virtual disk management command is a check code generation command, generate the check code The command is parsed to obtain the command parameters of the check code generation command; according to the command parameters, the value of the intermediate parameter check_size is set and the data to be checked are determined; if the data to be checked is the data in the virtual disk, then according to The virtual disk path specified in the command parameter opens the virtual disk in a read-only manner, and obtains the capacity of the virtual disk; if the value of check_size is a preset threshold, the value of check_size is made equal to the capacity of the virtual disk Start from the pointer offset parameter offset equal to the threshold, and read the data in the virtual disk according to the data read gran
  • This application adds a method of obtaining information digest hash value to virtual disk management commands.
  • the virtual disk is read from the beginning to the end according to the virtual disk that the user needs to verify and the verification length.
  • the hash value is calculated according to the information digest algorithm as the check code of the virtual disk, and finally the check code is output.
  • the verification code of the virtual disk can be easily obtained, thereby meeting the data error detection requirements required in scenarios such as virtual disk backup.
  • FIG. 1 is a schematic structural diagram of the operating environment of the virtual disk check code generation device involved in the solution of the embodiment of the application;
  • FIG. 2 is a schematic flowchart of a first embodiment of a method for generating a verification code for a virtual disk according to this application;
  • FIG. 3 is a schematic flowchart of a second embodiment of a method for generating a verification code for a virtual disk according to this application;
  • FIG. 4 is a schematic flowchart of a third embodiment of a method for generating a verification code for a virtual disk according to this application;
  • FIG. 5 is a schematic flowchart of a fourth embodiment of a method for generating a verification code for a virtual disk according to this application;
  • FIG. 6 is a schematic diagram of functional modules of an embodiment of an apparatus for generating a verification code for a virtual disk according to the present application.
  • This application provides a virtual disk verification code generation device.
  • FIG. 1 is a schematic structural diagram of the operating environment of the virtual disk verification code generation device involved in the solution of the embodiment of the application.
  • the virtual disk check code generation device includes: a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005.
  • the communication bus 1002 is used to implement connection and communication between these components.
  • the user interface 1003 may include a display screen (Display) and an input unit such as a keyboard (Keyboard), and the network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).
  • the memory 1005 may be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as a magnetic disk memory.
  • the memory 1005 may also be a storage device independent of the aforementioned processor 1001.
  • the hardware structure of the virtual disk verification code generation device shown in FIG. 1 does not constitute a limitation on the virtual disk verification code generation device, and may include more or less components than shown in the figure. Or some parts are combined, or different parts are arranged.
  • the memory 1005 which is a computer-readable storage medium, may include an operating system, a network communication module, a user interface module, and a computer program.
  • the operating system is a program that manages and controls the virtual disk check code generation device and software resources, and supports the operation of the virtual disk check code generation program and other software and/or programs.
  • the network interface 1004 is mainly used to access the network; the user interface 1003 is mainly used to detect and confirm instructions and edit instructions.
  • the processor 1001 may be used to call the virtual disk check code generation program stored in the memory 1005, and execute the operations of the following embodiments of the virtual disk check code generation method.
  • FIG. 2 is a schematic flowchart of a first embodiment of a method for generating a verification code for a virtual disk according to the present application.
  • the method for generating a virtual disk check code includes the following steps:
  • Step S110 Obtain the virtual disk management command input by the user
  • the virtual disk management commands used to generate the virtual disk check code are not limited, and may be various commands supported by tools for managing virtual disks.
  • the preferred virtual disk management command is the qemu-img command.
  • qemu-img as a virtualized disk tool of qemu-kvm, natively supports various virtual disk formats and back-end access protocols.
  • qemu-img only supports functions such as converting the virtual disk format, modifying the size of the virtual disk, exporting the virtual disk or its snapshot data, and does not support generating the check code of the virtual disk data. Therefore, in this embodiment, a command to export the check code is added to qemu-img in advance, so that the check code of the virtual disk data is generated when the command is input.
  • Step S120 if the virtual disk management command is a check code generation command, the check code generation command is parsed to obtain each command parameter of the check code generation command;
  • the parameters in the command are first generated for the check code
  • Test object virtual disk or disk file snapshot. Among them, the virtual disk is directly determined by the disk path, and the disk file snapshot is determined by the name.
  • the length of the data to be verified can be further selected to be specified.
  • the parsed command parameters mainly include:
  • the disk format is qcow2, raw, vmdk or other formats
  • bufsize is used to specify the granularity of data read and calculate the md5 value, that is, read data from the virtual disk and calculate the md5 value in the unit of bufsize each time;
  • the qemu-img command entered is as follows:
  • the virtual disk format is: qcow2, the data reading granularity is 65536 bufsize, the check length length is 10G, and the virtual disk file for which the check code is to be generated is /var/lib/libvirt/images/test. Snapshot snap1 of qcow2.
  • Step S130 according to the command parameter, set the value of the intermediate parameter check_size and determine the data to be checked;
  • the intermediate parameter check_size is an internal variable introduced to facilitate the generation of the check code, and length is used to identify the length of the data interval corresponding to the md5 check code of the data in the virtual disk.
  • the check length entered by the user shall prevail, as the length of the interval starting from 0 for the md5 check code of the virtual disk, and the value of check_size shall be set Is length. If the user does not enter length, that is, when the check length is not specified, all data in the disk will be checked by default, and the value of check_size is set to 0.
  • the virtual disk supports the resize operation
  • its virtual capacity that is, img_size
  • img_size the virtual capacity
  • the original 10G virtual disk is resized to 15G
  • its capacity will be changed to 15G
  • the increased 5G data is all 0s at this time.
  • the md5sum of the virtual disk with a size of 15G and the md5sum of the virtual disk with a size of 10G are different.
  • test.qcow2 on the secondary storage will also be 15G, otherwise Unable to back up the difference.
  • the value of the intermediate parameter check_size is set in the following manner:
  • check_size If the check length is specified in the command parameter, set the value of check_size equal to the check length
  • check_size If the check length is not specified in the command parameter, set the value of check_size equal to the threshold
  • the data to be verified is determined in the following manner:
  • Step S140 If the data to be verified is data in the virtual disk, open the virtual disk in a read-only mode according to the virtual disk path specified in the command parameter, and obtain the capacity of the virtual disk;
  • the processing flow of generating the verification code can be executed. If the command parameter specifies to verify the virtual disk, that is, if the data to be verified is the data in the virtual disk, the virtual disk is opened in read-only mode according to the virtual disk path specified in the command parameter, and then the virtual disk is obtained. The capacity of the disk img_size.
  • Step S150 if the value of check_size is a preset threshold, the value of check_size is set to be equal to the size of the virtual disk, and starting from the pointer offset parameter offset being equal to the threshold, the data specified in the command parameter is followed in sequence Reading granularity to read the data in the virtual disk until the offset is equal to the value of check_size;
  • the pointer offset parameter offset is a preset intermediate parameter introduced to facilitate the generation of the check code.
  • Step S160 Calculate and output the hash value of all data in the virtual disk according to the information digest algorithm, where the hash value is the check code of the virtual disk.
  • the hash value of all data in the virtual disk is calculated and output according to the md5sum hash algorithm, and the calculated hash value is the check code of the virtual disk.
  • qemu-img as a virtualized disk tool of qemu-kvm, natively supports various virtual disk formats and back-end access protocols.
  • This embodiment adds the md5 value method to qemu-img.
  • the data of the virtual disk is read from the beginning to the end according to the verified virtual disk and the verification length required by the user.
  • the md5 check code generation algorithm calculates the check code, and finally the check code is output.
  • the improvement of this embodiment can easily obtain the check code of the virtual disk, and is compatible with various virtual disk formats such as qcow2, vmdk, iscsi, rbd, and back-end access protocols, so as to meet the requirements in scenarios such as virtual disk backup. Data error detection requirements.
  • FIG. 3 is a schematic flowchart of a second embodiment of a method for generating a verification code for a virtual disk according to the present application. Based on the foregoing first embodiment of the method of the present application, in this embodiment, after the foregoing step S120, the method further includes:
  • Step S210 judging the validity of the command parameter, the command parameter including the virtual disk format
  • the parsed command parameters are further judged on the validity of each command parameter. If it is valid, continue to the next step, otherwise an error is reported, which specifically includes:
  • FIG. 4 is a schematic flowchart of a third embodiment of a method for generating a verification code for a virtual disk according to the present application. Based on the foregoing first embodiment of the method of the present application, in this embodiment, after the foregoing step S140, the method further includes:
  • step S310 if the value of check_size is equal to the check length specified in the command parameter, starting from the pointer offset parameter offset being equal to check_size, read the data in the virtual disk or disk file snapshot in sequence until the offset is equal to the virtual disk. End when the disk capacity is large;
  • Step S320 it is judged whether all the read data are all 0;
  • Step S330 if yes, start from the pointer offset parameter offset equal to the threshold, and read the data in the virtual disk according to the data read granularity specified in the command parameter in sequence, until the offset is equal to the value of check_size. ; If not, return and report an error.
  • FIG. 5 is a schematic flowchart of a fourth embodiment of a method for generating a verification code for a virtual disk according to the present application. Based on the foregoing first, second, or third embodiment of the method of the present application, in this embodiment, after the foregoing step S130, the method further includes:
  • Step S410 if the data to be verified is a disk file snapshot, open the disk file snapshot in read-only mode according to the name of the disk file snapshot specified in the command parameter;
  • Step S420 Obtain the data size of the disk file snapshot
  • Step S440 Calculate and output a hash value of all data in the disk file snapshot according to the information digest algorithm, where the hash value is the check code of the disk file snapshot.
  • the verification code of the disk file snapshot can also be generated.
  • the disk file snapshot is opened in read-only mode according to the disk file snapshot name specified in the command parameter, and the data size data_size of the disk file snapshot is obtained at the same time;
  • the application also provides a virtual disk verification code generation device.
  • FIG. 6 is a schematic diagram of functional modules of an embodiment of an apparatus for generating a virtual disk verification code according to the present application.
  • the virtual disk verification code generation device includes:
  • the command obtaining module 10 is used to obtain the virtual disk management command input by the user;
  • the parsing module 20 is configured to, if the virtual disk management command is a check code generation command, analyze the check code generation command to obtain various command parameters of the check code generation command;
  • the setting module 30 is configured to set the value of the intermediate parameter check_size and determine the data to be verified according to the command parameter;
  • the information acquisition module 40 is configured to, if the data to be verified is data in a virtual disk, open the virtual disk in a read-only manner according to the virtual disk path specified in the command parameter, and obtain the capacity of the virtual disk;
  • the data reading module 50 is configured to, if the value of check_size is a preset threshold, make the value of check_size equal to the size of the virtual disk, and start from the pointer offset parameter offset equal to the threshold, and follow the commands in sequence
  • the data read granularity specified in the parameter reads the data in the virtual disk until the offset is equal to the value of check_size;
  • the check code generation module 60 is configured to calculate and output a hash value of all data in the virtual disk according to an information digest algorithm, where the hash value is the check code of the virtual disk.
  • qemu-img is a virtualized disk tool of qemu-kvm, which natively supports various virtual disk formats and back-end access protocols.
  • This embodiment adds the md5 value method to qemu-img.
  • the data of the virtual disk is read from the beginning to the end according to the verified virtual disk and the verification length required by the user.
  • the md5 check code generation algorithm calculates the check code, and finally the check code is output.
  • the improvement of this embodiment can easily obtain the check code of the virtual disk, and is compatible with various virtual disk formats such as qcow2, vmdk, iscsi, rbd, and back-end access protocols, so as to meet the requirements in scenarios such as virtual disk backup. Data error detection requirements.
  • the setting module is specifically used for:
  • check_size is set equal to the check length; if the check length is not specified in the command parameter, the value of check_size is set equal to the threshold;
  • the data to be verified is the data in the virtual disk; if the disk file snapshot name is specified in the command parameter, it is determined that the data to be verified is a disk file snapshot.
  • the virtual disk verification code generation device further includes:
  • the parameter verification module is used for judging the legality of the command parameters, the command parameters including the virtual disk format;
  • the data reading module is further used for:
  • check_size If the value of check_size is equal to the check length specified in the command parameter, starting from the pointer offset parameter offset equal to check_size, read the data in the virtual disk or disk file snapshot in sequence until the offset is equal to the capacity of the virtual disk The end of the big hour
  • the information acquisition module is further configured to: if the data to be verified is a disk file snapshot, open the disk file snapshot in read-only mode according to the disk file snapshot name specified in the command parameter; and obtain the disk file snapshot.
  • the data size of the file snapshot is a disk file snapshot, open the disk file snapshot in read-only mode according to the disk file snapshot name specified in the command parameter; and obtain the disk file snapshot.
  • the check code generation module is also used to calculate and output a hash value of all data in the disk file snapshot according to an information digest algorithm, where the hash value is the check code of the disk file snapshot.
  • the computer-readable storage medium may be non-volatile or volatile, which is not specifically limited by this application.
  • a virtual disk check code generation program is stored on the computer-readable storage medium, and when the virtual disk check code generation program is executed by the processor, the program as described in any of the above embodiments is also implemented.
  • the steps of the virtual disk check code generation program method can refer to the various embodiments of the virtual disk check code generation method of the present application, so the details are not repeated here.

Abstract

本申请公开了一种虚拟磁盘校验码生成方法,包括:获取虚拟磁盘管理命令并进行解析得到各命令参数;根据命令参数,设置中间参数check_size的值以及确定待校验数据;若校验虚拟磁盘中的数据,则根据指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取虚拟磁盘的容量大小;若check_size的值为预置阈值,则令check_size的值等于虚拟磁盘的容量大小,并从指针偏移量参数offset等于阈值开始,依次按照指定的数据读取粒度读取虚拟磁盘中的数据,直至offset等于check_size的值时结束;依据信息摘要算法,计算虚拟磁盘中所有数据的哈希值并输出。本申请还公开了一种虚拟磁盘校验码生成装置、设备及计算机可读存储介质。本申请满足了虚拟磁盘备份场景下所需的数据检错需求。

Description

虚拟磁盘校验码生成方法、装置、设备及存储介质
本申请要求于2020年2月26日提交中国专利局、申请号为202010119593.9、发明名称为“虚拟磁盘校验码生成方法、装置、设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在申请中。
技术领域
本申请涉及数据备份技术领域,尤其涉及一种虚拟磁盘校验码生成方法、装置、设备及存储介质。
背景技术
现有技术中,在大数据计算领域,虚拟磁盘作为虚拟机的持久化数据承载体,为支持用户数据回滚,虚拟磁盘的备份机制不可或缺。一般来说,虚拟磁盘的备份是通过在某一个时刻为虚拟磁盘打上一个快照,然后将增量或者全量的快照数据导出到备份存储中(二级存储),当需要回滚时,将增量合并成全量或者直接将全量的数据拉回主存储。存储介质的静默错误,文件系统层bug等问题的存在使得用户面临的一个问题即如何确认备份的数据、备份后回滚的数据是否是用户当时要备份的数据。通常通过校验码机制解决这一问题,然而,发明人意识到,当前的校验码生成方式通常只支持对文件的校验码识别。而对于虚拟磁盘,一方面各种格式都有一套自身的数据分配机制,另一方面后端也支持各种接入协议,因此,现有方式无法支持直接导出虚拟磁盘的校验码。
发明内容
本申请的主要目的在于提供一种虚拟磁盘校验码生成方法、装置、设备及存储介质,旨在解决现有技术无法生成虚拟磁盘的校验码的技术问题。
为实现上述目的,本申请提供一种虚拟磁盘校验码生成方法,所述虚拟磁盘校验码生成方法包括以下步骤:获取用户输入的虚拟磁盘管理命令;若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数;根据所述命令参数,设置中间参数check_size的值以及确定待校验数据;若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小;若check_size的值为预置阈值,则令check_size的值等于所述虚拟磁盘的容量大小,并从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直至offset等于check_size的值时结束;依据信息摘要算法,计算所述虚拟磁盘中所有数据的哈希值并输出,其中,所述哈希值为所述虚拟磁盘的校验码。
进一步地,为实现上述目的,本申请还提供一种虚拟磁盘校验码生成装置,所述虚拟磁盘校验码生成装置包括:命令获取模块,用于获取用户输入的虚拟磁盘管理命令;解析模块,用于若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数;设置模块,用于根据所述命令参数,设置中间参数check_size的值以及确定待校验数据;信息获取模块,用于若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小;数据读取模块,用于若check_size的值为预置阈值,则令check_size的值等于所述虚拟磁盘的容量大小,并从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直至offset等于check_size的值时结束;校验码生成模块,用于依据信息摘要算法,计算所述虚拟磁盘中所有数据的哈希值并输出,其中,所述哈希值为所述虚拟磁盘的校验码。
进一步地,为实现上述目的,本申请还提供一种虚拟磁盘校验码生成设备,所述虚拟磁盘校验码生成设备包括存储器、处理器以及存储在所述存储器上并可在所述处理器上运行的虚拟磁盘校验码生成程序,所述虚拟磁盘校验码生成程序被所述处理器执行时还实现如下所述的虚拟磁盘校验码生成程序方法的步骤:获取用户输入的虚拟磁盘管理命令;若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数;根据所述命令参数,设置中间参数check_size的值以及确定待校验数据;若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小;若check_size的值为预置阈值,则令check_size的值等于所述虚拟磁盘的容量大小,并从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直至offset等于check_size的值时结束;依据信息摘要算法,计算所述虚拟磁盘中所有数据的哈希值并输出,其中,所述哈希值为所述虚拟磁盘的校验码。
进一步地,为实现上述目的,本申请还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有虚拟磁盘校验码生成程序,所述虚拟磁盘校验码生成程序被处理器执行时还实现如下所述的虚拟磁盘校验码生成程序方法的步骤:获取用户输入的虚拟磁盘管理命令;若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数;根据所述命令参数,设置中间参数check_size的值以及确定待校验数据;若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小;若check_size的值为预置阈值,则令check_size的值等于所述虚拟磁盘的容量大小,并从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直至offset等于check_size的值时结束;依据信息摘要算法,计算所述虚拟磁盘中所有数据的哈希值并输出,其中,所述哈希值为所述虚拟磁盘的校验码。
本申请通过为虚拟磁盘管理命令增加求信息摘要哈希值的方法,当识别用户对虚拟磁盘求信息摘要哈希值时,根据用户需要校验的虚拟磁盘及校验长度从头到尾读取虚拟磁盘的数据,根据信息摘要算法计算哈希值作为虚拟磁盘的校验码,最后将校验码输出。本申请可以便捷得到虚拟磁盘的校验码,从而满足虚拟磁盘备份等场景下所需的数据检错需求。
附图说明
图1为本申请实施例方案涉及的虚拟磁盘校验码生成设备运行环境的结构示意图;
图2为本申请虚拟磁盘校验码生成方法第一实施例的流程示意图;
图3为本申请虚拟磁盘校验码生成方法第二实施例的流程示意图;
图4为本申请虚拟磁盘校验码生成方法第三实施例的流程示意图;
图5为本申请虚拟磁盘校验码生成方法第四实施例的流程示意图;
图6为本申请虚拟磁盘校验码生成装置一实施例的功能模块示意图。
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
具体实施方式
应当理解,此处所描述的具体实施例仅用以解释本申请,并不用于限定本申请。
本申请提供一种虚拟磁盘校验码生成设备。
参照图1,图1为本申请实施例方案涉及的虚拟磁盘校验码生成设备运行环境的结构示意图。
如图1所示,该虚拟磁盘校验码生成设备包括:处理器1001,例如CPU,通信总线1002、 用户接口1003,网络接口1004,存储器1005。其中,通信总线1002用于实现这些组件之间的连接通信。用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口)。存储器1005可以是高速RAM存储器,也可以是稳定的存储器(non-volatile memory),例如磁盘存储器。存储器1005可选的还可以是独立于前述处理器1001的存储装置。
本领域技术人员可以理解,图1中示出的虚拟磁盘校验码生成设备的硬件结构并不构成对虚拟磁盘校验码生成设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。
如图1所示,作为一种计算机可读存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及计算机程序。其中,操作系统是管理和控制虚拟磁盘校验码生成设备和软件资源的程序,支持虚拟磁盘校验码生成程序以及其它软件和/或程序的运行。
在图1所示的虚拟磁盘校验码生成设备的硬件结构中,网络接口1004主要用于接入网络;用户接口1003主要用于侦测确认指令和编辑指令等。而处理器1001可以用于调用存储器1005中存储的虚拟磁盘校验码生成程序,并执行以下虚拟磁盘校验码生成方法的各实施例的操作。
基于上述虚拟磁盘校验码生成设备硬件结构,提出本申请虚拟磁盘校验码生成方法的各个实施例。
参照图2,图2为本申请虚拟磁盘校验码生成方法第一实施例的流程示意图。本实施例中,所述虚拟磁盘校验码生成方法包括以下步骤:
步骤S110,获取用户输入的虚拟磁盘管理命令;
本实施例对于生成虚拟磁盘校验码所采用的虚拟磁盘管理命令不限,可以是用于管理虚拟磁盘的工具所支持的各类命令。在一实施例中优选虚拟磁盘管理命令为qemu-img命令。
qemu-img作为qemu-kvm虚拟化的磁盘工具,原生支持各种虚拟磁盘格式及后端接入协议。当前,qemu-img仅支持转换虚拟磁盘格式、修改虚拟磁盘大小、导出虚拟磁盘或其快照数据等功能,而并不支持生成虚拟磁盘数据的校验码。因此,本实施例预先在qemu-img中增加一个导出校验码的命令,以便在输入该命令时生成虚拟磁盘数据的校验码。
步骤S120,若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数;
本实施例中,若用户输入的qemu-img命令为校验码生成命令,也即若为用于生成虚拟磁盘数据的校验码的命令,则先对该校验码生成命令中的各参数进行解析,进而获得与生成虚拟磁盘校验码相关的参数信息,例如,待校验的虚拟磁盘的格式、生成校验码时读取待校验数据的数据读取粒度bufsize以及还包括待校验的对象:虚拟磁盘或磁盘文件快照。其中,虚拟磁盘直接通过磁盘路径进行确定,而磁盘文件快照则通过名称进行确定。
此外,为提升数据校验的灵活性,本实施例中,在生成校验码时,还可以进一步选择指定待校验的数据长度length。
本实施例中,当输入的命令为校验码生成命令时,解析的命令参数主要包括:
(1)解析虚拟磁盘格式,比如磁盘格式是qcow2、raw、vmdk或者其他格式;
(2)解析生成校验码的的虚拟磁盘路径或磁盘文件快照名称;
(3)解析数据读取粒度bufsize参数,bufsize用于指定数据读取并计算md5值的粒度,即每次以bufsize为单位从虚拟磁盘中读取数据并计算md5值;
(4)解析校验长度length参数;
例如,以求某个qcow2文件的校验码为例,输入的qemu-img命令如下所示:
qemu-img md5sum –f qcow2 –b 65536 –l 10G
–s snap1/var/lib/libvirt/images/test.qcow2
对命令参数进行解析,得到虚拟磁盘格式为:qcow2,数据读取粒度bufsize为65536,校验长度length为10G,所要生成校验码的虚拟磁盘文件为/var/lib/libvirt/images/test.qcow2的快照snap1。
步骤S130,根据所述命令参数,设置中间参数check_size的值以及确定待校验数据;
本实施例中,中间参数check_size为便于生成校验码而引入的内部使用变量,length用于标识求虚拟磁盘中数据的md5校验码对应的数据区间长度。当命令参数中指定校验长度length时,也即用户输入了length的情况下,以用户输入的校验长度为准,作为求虚拟磁盘md5校验码从0开始的区间长度,设置check_size的值为length。而若用户没有输入length,也即没有指定校验长度时,默认对磁盘中所有数据进行校验,设置check_size的值为0。
需要进一步说明的是,本实施例中上述设置length的原因在于:
由于虚拟磁盘是支持resize操作的,当虚拟磁盘执行resize操作之后,其虚拟容量大小也即img_size会相应发生变化,比如说,对于原来为10G的虚拟磁盘resize为15G,那么其容量会变更为15G,而增加的后5G数据此时为全0,然而,因而此时以15G为大小求该虚拟磁盘的md5sum和以10G为大小求该虚拟磁盘的md5sum是不同的。
例如,一个qcow2test.qcow2文件为10G,打快照snap1,将snap1备份到二级存储,并求md5sum记录到数据库,设为test@snap1.md5sum;
用户对虚拟磁盘执行resize操作进行扩容,扩容为15G,用户再打快照snap2,将snap2与snap1的差量部分备份到二级存储,此时二级存储上的test.qcow2也会为15G,否则无法将差量部分备份过来。
若用户此时要回滚到snap1,则回滚后以15G作为虚拟磁盘大小(这是用户最后所需磁盘容量),数据以snap1的为准,为检验磁盘回滚后数据是否正确,此时要求从二级存储以snap1为基准下载下来的虚拟磁盘校验码,并和之前记录的test@snap1.md5sum做比较,由于虚拟磁盘容量已发生变化,因此,后续扩容的5G不能用于计算md5sum,否则必然不一致,故加入length参数可用于求虚拟磁盘给定区间的md5sum,而对于虚拟磁盘超出给定区间的部分,需要保证数据全0即可。
可选的,在一具体实施例中,采用如下方式设置中间参数check_size的值:
A、若所述命令参数中指定校验长度,则设置check_size的值等于所述校验长度;
B、若所述命令参数中未指定校验长度,则设置check_size的值等于所述阈值;
可选的,在一具体实施例中,采用如下方式确定待校验数据:
C、若所述命令参数中指定虚拟磁盘路径,则确定待校验数据为虚拟磁盘中的数据;
D、若所述命令参数中指定磁盘文件快照名称,则确定待校验数据为磁盘文件快照。
步骤S140,若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小;
本实施例中,在解析完命令参数后即可执行生成校验码的处理流程。若命令参数中指定对虚拟磁盘进行校验,也即若待校验的数据为虚拟磁盘中的数据,则根据命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,然后获取该虚拟磁盘的容量大小img_size。
步骤S150,若check_size的值为预置阈值,则令check_size的值等于所述虚拟磁盘的容量大小,并从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直至offset等于check_size的值时结束;
本实施例中,若用户未指定要校验的数据长度,也即当check_size的值为0时,也即需要对虚拟磁盘中所有数据进行校验,因此令check_size=img_size,并从指针偏移量参数offset=0开始依次以bufsize为粒度读取虚拟磁盘中的数据,直至offset=check_size时结 束,也即需要计算[0,check_size)部分数据的md5sum值。其中,指针偏移量参数offset为预置的便于生成校验码所引入的中间参数。
步骤S160,依据信息摘要算法,计算所述虚拟磁盘中所有数据的哈希值并输出,其中,所述哈希值为所述虚拟磁盘的校验码。
本实施例中,在读取到磁盘中数据后,依据md5sum hash算法,计算虚拟磁盘中所有数据的hash值并输出,而该计算得到的hash值即为虚拟磁盘的校验码。
qemu-img作为qemu-kvm虚拟化的磁盘工具,原生支持各种虚拟磁盘格式及后端接入协议。本实施例通过为qemu-img增加求md5值的方法,当识别用户对虚拟磁盘求md5值时,根据用户需要的校验的虚拟磁盘及校验长度从头到尾读取虚拟磁盘的数据,根据md5校验码生成算法计算校验码,最后将校验码输出。本实施例的改进可以很便捷地得到虚拟磁盘的校验码,并兼容qcow2、vmdk、iscsi、rbd等各种虚拟磁盘格式和后端接入协议,从而满足虚拟磁盘备份等场景下所需的数据检错需求。
参照图3,图3为本申请虚拟磁盘校验码生成方法第二实施例的流程示意图。基于上述本申请方法第一实施例,本实施例中,在上述步骤S120之后,还包括:
步骤S210,对所述命令参数进行合法性判断,所述命令参数包括虚拟磁盘格式;
其中,所述合法性判断包括:
A、判断当前待校验的虚拟磁盘格式是否属于可生成校验码的虚拟磁盘格式,若否,则返回并报错;
B、判断数据读取粒度是否与虚拟磁盘扇区大小对齐,若否,则返回并报错;
C、判断所述命令参数中是否存在不支持的命令参数,若是,则返回并报错。
本实施例中,当用户输入用于生成校验码的qemu-img命令时,进一步对解析后的各命令参数进行合法性判断,若合法,则继续下一步处理,否则报错,具体包括:
A、判断当前待校验的虚拟磁盘格式是否属于可生成校验码的虚拟磁盘格式,若否,则返回并报错;虚拟磁盘的格式很多种,比如qcow2、raw、vmdk等,若虚拟磁盘格式不被支持,是无法读取其真实数据的,因此,直接返回错误。
B、判断数据读取粒度bufsize是否与虚拟磁盘扇区大小对齐,若否,则返回并报错;
C、判断所述命令参数中是否存在不支持的命令参数,若是,则返回并报错。比如恢复快照的命令参数-a,md5sum不支持这一参数。
参照图4,图4为本申请虚拟磁盘校验码生成方法第三实施例的流程示意图。基于上述本申请方法第一实施例,本实施例中,在上述步骤S140之后,还包括:
步骤S310,若check_size的值等于所述命令参数中指定的校验长度,则从指针偏移量参数offset等于check_size开始,依次读取虚拟磁盘或磁盘文件快照中的数据,直到offset等于所述虚拟磁盘的容量大小时结束;
步骤S320,判断读取的所有数据是否全部为0;
步骤S330,若是,则从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;若否,则返回并报错。
本实施例中,若用户指定了待校验数据的长度,也即若check_size的值为length,则从指针偏移量参数offset=check_size开始,依次读取虚拟磁盘或磁盘文件快照中的数据直到offset=img_size时结束,也即当check_size<img_size时,读取从check_size到img_size部分的数据。
需要说明的是,如果一个虚拟磁盘有过resize操作,其容量会发生变化,但是被扩容 的区间,此时为全0数据。对于用户给定length求虚拟磁盘md5值的场景,要求从length到虚拟机实际大小部分全部为0,表示用户对这部分数据没有用非0数据写过,只有这样,用户指定的校验长度length才有意义,因此,若从check_size到img_size部分的数据存在非0数据,则返回并报错,而若从check_size到img_size部分的数据全部为0,则可以生成[0,check_size)部分数据的md5值。
参照图5,图5为本申请虚拟磁盘校验码生成方法第四实施例的流程示意图。基于上述本申请方法第一、二或三实施例,本实施例中,在上述步骤S130之后,还包括:
步骤S410,若待校验数据为磁盘文件快照,则根据所述命令参数中指定的磁盘文件快照名称,以只读方式打开磁盘文件快照;
步骤S420,获取所述磁盘文件快照的数据量大小;
步骤S430,令check_size等于所述数据量大小,并从指针偏移量参数offset=0开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;
步骤S440,依据信息摘要算法,计算所述磁盘文件快照中所有数据的哈希值并输出,其中,该哈希值为所述磁盘文件快照的校验码。
本实施例中还可生成磁盘文件快照的校验码。本实施例中,若待校验的数据为磁盘文件快照,则根据命令参数中指定的磁盘文件快照名称,以只读方式打开磁盘文件快照,同时获取磁盘文件快照的数据量大小data_size;
令中间参数check_size=data_size,并从指针偏移量参数offset=0开始依次以bufsize为粒度读取所述虚拟磁盘中的数据直到offset=check_size时结束,依据md5sum hash算法,计算磁盘文件快照中所有数据的hash值并输出,该hash值即为该磁盘文件快照的校验码。
本申请还提供一种虚拟磁盘校验码生成装置。
参照图6,图6为本申请虚拟磁盘校验码生成装置一实施例的功能模块示意图。本实施例中,所述虚拟磁盘校验码生成装置包括:
命令获取模块10,用于获取用户输入的虚拟磁盘管理命令;
解析模块20,用于若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数;
设置模块30,用于根据所述命令参数,设置中间参数check_size的值以及确定待校验数据;
信息获取模块40,用于若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小;
数据读取模块50,用于若check_size的值为预置阈值,则令check_size的值等于所述虚拟磁盘的容量大小,并从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直至offset等于check_size的值时结束;
校验码生成模块60,用于依据信息摘要算法,计算所述虚拟磁盘中所有数据的哈希值并输出,其中,所述哈希值为所述虚拟磁盘的校验码。
基于与上述本申请虚拟磁盘校验码生成方法相同的实施例说明内容,因此本实施例对虚拟磁盘校验码生成装置的实施例内容不做过多赘述。
本实施例中,qemu-img作为qemu-kvm虚拟化的磁盘工具,原生支持各种虚拟磁盘格式及后端接入协议。本实施例通过为qemu-img增加求md5值的方法,当识别用户对虚拟磁盘求 md5值时,根据用户需要的校验的虚拟磁盘及校验长度从头到尾读取虚拟磁盘的数据,根据md5校验码生成算法计算校验码,最后将校验码输出。本实施例的改进可以很便捷地得到虚拟磁盘的校验码,并兼容qcow2、vmdk、iscsi、rbd等各种虚拟磁盘格式和后端接入协议,从而满足虚拟磁盘备份等场景下所需的数据检错需求。
可选地,所述设置模块具体用于:
若所述命令参数中指定校验长度,则设置check_size的值等于所述校验长度;若所述命令参数中未指定校验长度,则设置check_size的值等于所述阈值;
若所述命令参数中指定虚拟磁盘路径,则确定待校验数据为虚拟磁盘中的数据;若所述命令参数中指定磁盘文件快照名称,则确定待校验数据为磁盘文件快照。
可选地,所述虚拟磁盘校验码生成装置还包括:
参数校验模块,用于对所述命令参数进行合法性判断,所述命令参数包括虚拟磁盘格式;
其中,所述合法性判断包括:
A、判断当前待校验的虚拟磁盘格式是否属于可生成校验码的虚拟磁盘格式,若否,则返回并报错;
B、判断数据读取粒度是否与虚拟磁盘扇区大小对齐,若否,则返回并报错;
C、判断所述命令参数中是否存在不支持的命令参数,若是,则返回并报错。
可选地,所述数据读取模块还用于:
若check_size的值等于所述命令参数中指定的校验长度,则从指针偏移量参数offset等于check_size开始,依次读取虚拟磁盘或磁盘文件快照中的数据,直到offset等于所述虚拟磁盘的容量大小时结束;
判断读取的所有数据是否全部为0;
若是,则从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;
若否,则返回并报错。
可选地,所述信息获取模块还用于:若待校验数据为磁盘文件快照,则根据所述命令参数中指定的磁盘文件快照名称,以只读方式打开磁盘文件快照;获取所述磁盘文件快照的数据量大小;
所述数据读取模块还用于:令check_size等于所述数据量大小,并从指针偏移量参数offset=0开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;
所述校验码生成模块还用于:依据信息摘要算法,计算所述磁盘文件快照中所有数据的哈希值并输出,其中,该哈希值为所述磁盘文件快照的校验码。
基于与上述本申请虚拟磁盘校验码生成方法相同的实施例说明内容,因此本实施例对虚拟磁盘校验码生成装置的实施例内容不做过多赘述。
本申请还提供一种计算机可读存储介质,该计算机可读存储介质既可以是非易失性的,也可以是易失性的,具体本申请不做限定。
本实施例中,所述计算机可读存储介质上存储有虚拟磁盘校验码生成程序,所述虚拟磁盘校验码生成程序被处理器执行时还实现如上述任一项实施例中所述的虚拟磁盘校验码生成程序方法的步骤。其中,虚拟磁盘校验码生成程序被处理器执行时所实现的方法可参照本申请虚拟磁盘校验码生成方法的各个实施例,因此不再过多赘述。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可 借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM)中,包括若干指令用以使得一台终端(可以是手机,计算机,服务器或者网络设备等)执行本申请各个实施例所述的方法。
上面结合附图对本申请的实施例进行了描述,但是本申请并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本申请的启示下,在不脱离本申请宗旨和权利要求所保护的范围情况下,还可做出很多形式,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,这些均属于本申请的保护之内。

Claims (20)

  1. 一种虚拟磁盘校验码生成方法,其中,所述虚拟磁盘校验码生成方法包括以下步骤:
    获取用户输入的虚拟磁盘管理命令;
    若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数;
    根据所述命令参数,设置中间参数check_size的值以及确定待校验数据;
    若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小;
    若check_size的值为预置阈值,则令check_size的值等于所述虚拟磁盘的容量大小,并从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直至offset等于check_size的值时结束;
    依据信息摘要算法,计算所述虚拟磁盘中所有数据的哈希值并输出,其中,所述哈希值为所述虚拟磁盘的校验码。
  2. 根据权利要求1所述的虚拟磁盘校验码生成方法,其中,所述根据所述命令参数,设置中间参数check_size的值以及确定待校验数据包括:
    若所述命令参数中指定校验长度,则设置check_size的值等于所述校验长度;若所述命令参数中未指定校验长度,则设置check_size的值等于所述阈值;
    若所述命令参数中指定虚拟磁盘路径,则确定待校验数据为虚拟磁盘中的数据;若所述命令参数中指定磁盘文件快照名称,则确定待校验数据为磁盘文件快照。
  3. 根据权利要求1所述的虚拟磁盘校验码生成方法,其中,在所述若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数的步骤之后,还包括:
    对所述命令参数进行合法性判断,所述命令参数包括虚拟磁盘格式;
    其中,所述合法性判断包括:
    A、判断当前待校验的虚拟磁盘格式是否属于可生成校验码的虚拟磁盘格式,若否,则返回并报错;
    B、判断数据读取粒度是否与虚拟磁盘扇区大小对齐,若否,则返回并报错;
    C、判断所述命令参数中是否存在不支持的命令参数,若是,则返回并报错。
  4. 根据权利要求2所述的虚拟磁盘校验码生成方法,其中,在所述若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小的步骤之后,还包括:
    若check_size的值等于所述命令参数中指定的校验长度,则从指针偏移量参数offset等于check_size开始,依次读取虚拟磁盘或磁盘文件快照中的数据,直到offset等于所述虚拟磁盘的容量大小时结束;
    判断读取的所有数据是否全部为0;
    若是,则从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;
    若否,则返回并报错。
  5. 根据权利要求1所述的虚拟磁盘校验码生成方法,其中,在所述根据所述命令参数,设置中间参数check_size的值以及确定待校验数据的步骤之后,还包括:
    若待校验数据为磁盘文件快照,则根据所述命令参数中指定的磁盘文件快照名称,以只读方式打开磁盘文件快照;
    获取所述磁盘文件快照的数据量大小;
    令check_size等于所述数据量大小,并从指针偏移量参数offset=0开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;
    依据信息摘要算法,计算所述磁盘文件快照中所有数据的哈希值并输出,其中,该哈希值为所述磁盘文件快照的校验码。
  6. 根据权利要求1-5中任一项所述的虚拟磁盘校验码生成方法,其中,所述虚拟磁盘管理命令为qemu-img命令。
  7. 一种虚拟磁盘校验码生成装置,其中,所述虚拟磁盘校验码生成装置包括:
    命令获取模块,用于获取用户输入的虚拟磁盘管理命令;
    解析模块,用于若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数;
    设置模块,用于根据所述命令参数,设置中间参数check_size的值以及确定待校验数据;
    信息获取模块,用于若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小;
    数据读取模块,用于若check_size的值为预置阈值,则令check_size的值等于所述虚拟磁盘的容量大小,并从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直至offset等于check_size的值时结束;
    校验码生成模块,用于依据信息摘要算法,计算所述虚拟磁盘中所有数据的哈希值并输出,其中,所述哈希值为所述虚拟磁盘的校验码。
  8. 根据权利要求7所述的虚拟磁盘校验码生成装置,其中,所述信息获取模块还用于:若待校验数据为磁盘文件快照,则根据所述命令参数中指定的磁盘文件快照名称,以只读方式打开磁盘文件快照;获取所述磁盘文件快照的数据量大小;
    所述数据读取模块还用于:令check_size等于所述数据量大小,并从指针偏移量参数offset=0开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;
    所述校验码生成模块还用于:依据信息摘要算法,计算所述磁盘文件快照中所有数据的哈希值并输出,其中,该哈希值为所述磁盘文件快照的校验码。
  9. 一种虚拟磁盘校验码生成设备,其中,所述虚拟磁盘校验码生成设备包括存储器、处理器以及存储在所述存储器上并可在所述处理器上运行的虚拟磁盘校验码生成程序,所述虚拟磁盘校验码生成程序被所述处理器执行如下所述的虚拟磁盘校验码生成程序方法的步骤:
    获取用户输入的虚拟磁盘管理命令;
    若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数;
    根据所述命令参数,设置中间参数check_size的值以及确定待校验数据;
    若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小;
    若check_size的值为预置阈值,则令check_size的值等于所述虚拟磁盘的容量大小,并从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直至offset等于check_size的值时结束;
    依据信息摘要算法,计算所述虚拟磁盘中所有数据的哈希值并输出,其中,所述哈希值为所述虚拟磁盘的校验码。
  10. 根据权利要求9所述的虚拟磁盘校验码生成设备,其中,所述虚拟磁盘校验码生成程序被所述处理器执行所述根据所述命令参数,设置中间参数check_size的值以及确定待校验数据的步骤时,包括如下步骤:
    若所述命令参数中指定校验长度,则设置check_size的值等于所述校验长度;若所述命令参数中未指定校验长度,则设置check_size的值等于所述阈值;
    若所述命令参数中指定虚拟磁盘路径,则确定待校验数据为虚拟磁盘中的数据;若所述命令参数中指定磁盘文件快照名称,则确定待校验数据为磁盘文件快照。
  11. 根据权利要求9所述的虚拟磁盘校验码生成设备,其中,所述虚拟磁盘校验码生成程序被所述处理器执行所述若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数的步骤之后,还包括如下步骤:
    对所述命令参数进行合法性判断,所述命令参数包括虚拟磁盘格式;
    其中,所述合法性判断包括:
    A、判断当前待校验的虚拟磁盘格式是否属于可生成校验码的虚拟磁盘格式,若否,则返回并报错;
    B、判断数据读取粒度是否与虚拟磁盘扇区大小对齐,若否,则返回并报错;
    C、判断所述命令参数中是否存在不支持的命令参数,若是,则返回并报错。
  12. 根据权利要求10所述的虚拟磁盘校验码生成设备,其中,所述虚拟磁盘校验码生成程序被所述处理器执行所述若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小的步骤之后,还包括如下步骤:
    若check_size的值等于所述命令参数中指定的校验长度,则从指针偏移量参数offset等于check_size开始,依次读取虚拟磁盘或磁盘文件快照中的数据,直到offset等于所述虚拟磁盘的容量大小时结束;
    判断读取的所有数据是否全部为0;
    若是,则从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;
    若否,则返回并报错。
  13. 根据权利要求9所述的虚拟磁盘校验码生成设备,其中,所述虚拟磁盘校验码生成程序被所述处理器执行所述根据所述命令参数,设置中间参数check_size的值以及确定待校验数据的步骤之后,还包括如下步骤:
    若待校验数据为磁盘文件快照,则根据所述命令参数中指定的磁盘文件快照名称,以只读方式打开磁盘文件快照;
    获取所述磁盘文件快照的数据量大小;
    令check_size等于所述数据量大小,并从指针偏移量参数offset=0开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;
    依据信息摘要算法,计算所述磁盘文件快照中所有数据的哈希值并输出,其中,该哈希值为所述磁盘文件快照的校验码。
  14. 根据权利要求9-13中任一项所述的虚拟磁盘校验码生成设备,其中,所述虚拟磁盘管理命令为qemu-img命令。
  15. 一种计算机可读存储介质,其中,所述计算机可读存储介质上存储有虚拟磁盘校验码生成程序,所述虚拟磁盘校验码生成程序被处理器执行时实现如下所述的虚拟磁盘校验码生成程序方法的步骤:
    获取用户输入的虚拟磁盘管理命令;
    若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数;
    根据所述命令参数,设置中间参数check_size的值以及确定待校验数据;
    若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小;
    若check_size的值为预置阈值,则令check_size的值等于所述虚拟磁盘的容量大小,并从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直至offset等于check_size的值时结束;
    依据信息摘要算法,计算所述虚拟磁盘中所有数据的哈希值并输出,其中,所述哈希值为所述虚拟磁盘的校验码。
  16. 根据权利要求15所述的计算机可读存储介质,其中,所述虚拟磁盘校验码生成程序被所述处理器执行所述根据所述命令参数,设置中间参数check_size的值以及确定待校验数据的步骤时,包括如下步骤:
    若所述命令参数中指定校验长度,则设置check_size的值等于所述校验长度;若所述命令参数中未指定校验长度,则设置check_size的值等于所述阈值;
    若所述命令参数中指定虚拟磁盘路径,则确定待校验数据为虚拟磁盘中的数据;若所述命令参数中指定磁盘文件快照名称,则确定待校验数据为磁盘文件快照。
  17. 根据权利要求15所述的计算机可读存储介质,其中,所述虚拟磁盘校验码生成程序被所述处理器执行所述若所述虚拟磁盘管理命令为校验码生成命令,则对所述校验码生成命令进行解析,得到所述校验码生成命令的各命令参数的步骤之后,还包括如下步骤:
    对所述命令参数进行合法性判断,所述命令参数包括虚拟磁盘格式;
    其中,所述合法性判断包括:
    A、判断当前待校验的虚拟磁盘格式是否属于可生成校验码的虚拟磁盘格式,若否,则返回并报错;
    B、判断数据读取粒度是否与虚拟磁盘扇区大小对齐,若否,则返回并报错;
    C、判断所述命令参数中是否存在不支持的命令参数,若是,则返回并报错。
  18. 根据权利要求16所述的计算机可读存储介质,其中,所述虚拟磁盘校验码生成程序被所述处理器执行所述若待校验数据为虚拟磁盘中的数据,则根据所述命令参数中指定的虚拟磁盘路径,以只读方式打开虚拟磁盘,并获取所述虚拟磁盘的容量大小的步骤之后,还包括如下步骤:
    若check_size的值等于所述命令参数中指定的校验长度,则从指针偏移量参数offset等于check_size开始,依次读取虚拟磁盘或磁盘文件快照中的数据,直到offset等于所述虚拟磁盘的容量大小时结束;
    判断读取的所有数据是否全部为0;
    若是,则从指针偏移量参数offset等于所述阈值开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;
    若否,则返回并报错。
  19. 据权利要求15所述的计算机可读存储介质,其中,所述虚拟磁盘校验码生成程序被所述处理器执行所述根据所述命令参数,设置中间参数check_size的值以及确定待校验数据的步骤之后,还包括如下步骤:
    若待校验数据为磁盘文件快照,则根据所述命令参数中指定的磁盘文件快照名称,以只读方式打开磁盘文件快照;
    获取所述磁盘文件快照的数据量大小;
    令check_size等于所述数据量大小,并从指针偏移量参数offset=0开始,依次按照所述命令参数中指定的数据读取粒度读取所述虚拟磁盘中的数据,直到offset等于check_size的值时结束;
    依据信息摘要算法,计算所述磁盘文件快照中所有数据的哈希值并输出,其中,该哈希值为所述磁盘文件快照的校验码。
  20. 据权利要求15-19中任一项所述的计算机可读存储介质,其中,所述虚拟磁盘管理命令为qemu-img命令。
PCT/CN2020/118230 2020-02-26 2020-09-28 虚拟磁盘校验码生成方法、装置、设备及存储介质 WO2021169280A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010119593.9A CN111338759A (zh) 2020-02-26 2020-02-26 虚拟磁盘校验码生成方法、装置、设备及存储介质
CN202010119593.9 2020-02-26

Publications (1)

Publication Number Publication Date
WO2021169280A1 true WO2021169280A1 (zh) 2021-09-02

Family

ID=71181972

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/118230 WO2021169280A1 (zh) 2020-02-26 2020-09-28 虚拟磁盘校验码生成方法、装置、设备及存储介质

Country Status (2)

Country Link
CN (1) CN111338759A (zh)
WO (1) WO2021169280A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117033084A (zh) * 2023-10-09 2023-11-10 武汉吧哒科技股份有限公司 虚拟机备份方法、装置、电子设备及存储介质

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111338759A (zh) * 2020-02-26 2020-06-26 平安科技(深圳)有限公司 虚拟磁盘校验码生成方法、装置、设备及存储介质
CN113254394B (zh) * 2021-05-14 2023-10-31 平安科技(深圳)有限公司 一种快照处理方法、系统、设备及存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105302486A (zh) * 2015-10-20 2016-02-03 山东乾云启创信息科技股份有限公司 一种虚拟化离线桌面块设备存储同步方法
CN106951345A (zh) * 2017-03-28 2017-07-14 上海爱数信息技术股份有限公司 一种虚拟机磁盘数据的一致性测试方法及装置
CN109032838A (zh) * 2018-06-28 2018-12-18 上海爱数信息技术股份有限公司 虚拟机备份恢复数据一致性的自动校验方法
US20190079875A1 (en) * 2017-09-14 2019-03-14 Citrix Systems, Inc. Efficient provisioning of virtual machines to endpoint computing environment
CN111338759A (zh) * 2020-02-26 2020-06-26 平安科技(深圳)有限公司 虚拟磁盘校验码生成方法、装置、设备及存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105302486A (zh) * 2015-10-20 2016-02-03 山东乾云启创信息科技股份有限公司 一种虚拟化离线桌面块设备存储同步方法
CN106951345A (zh) * 2017-03-28 2017-07-14 上海爱数信息技术股份有限公司 一种虚拟机磁盘数据的一致性测试方法及装置
US20190079875A1 (en) * 2017-09-14 2019-03-14 Citrix Systems, Inc. Efficient provisioning of virtual machines to endpoint computing environment
CN109032838A (zh) * 2018-06-28 2018-12-18 上海爱数信息技术股份有限公司 虚拟机备份恢复数据一致性的自动校验方法
CN111338759A (zh) * 2020-02-26 2020-06-26 平安科技(深圳)有限公司 虚拟磁盘校验码生成方法、装置、设备及存储介质

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117033084A (zh) * 2023-10-09 2023-11-10 武汉吧哒科技股份有限公司 虚拟机备份方法、装置、电子设备及存储介质
CN117033084B (zh) * 2023-10-09 2024-01-19 武汉吧哒科技股份有限公司 虚拟机备份方法、装置、电子设备及存储介质

Also Published As

Publication number Publication date
CN111338759A (zh) 2020-06-26

Similar Documents

Publication Publication Date Title
WO2021169280A1 (zh) 虚拟磁盘校验码生成方法、装置、设备及存储介质
CN111104315A (zh) 一种测试脚本生成方法及装置、计算机可读存储介质
CN108459951B (zh) 测试方法和装置
CN110321339B (zh) 一种数据迁移方法、装置、设备和存储介质
CN104572422A (zh) 一种基于Linux系统开关机下内存监测实现方法
CN111552633A (zh) 接口的异常调用测试方法、装置、计算机设备及存储介质
WO2007061241A1 (en) Error test method for mobile communication terminals
CN114201408A (zh) 回归测试方法、装置、计算机设备及存储介质
WO2022228500A1 (zh) 一种bios的数据存储方法、装置、设备及存储介质
CN112100081A (zh) 基于双芯智能电表的升级测试方法、装置和计算机设备
CN112100070A (zh) 版本缺陷的检测方法、装置、服务器及存储介质
CN114880177A (zh) 固态硬盘的整机异常掉电测试方法、装置和计算机设备
CN116955207A (zh) 识别测试用例完成软硬件的自动化测试方法、系统及介质
CN111737933A (zh) 一种soc原型验证方法、系统、设备及介质
CN113688051A (zh) 一种电能表软件升级测试方法和存储介质
CN113011869A (zh) 测试数据生成方法、装置和计算机可读存储介质
CN115701591A (zh) 业务流程测试方法、装置、介质及电子设备
CN112947964A (zh) 一种芯片的固件更新方法、装置、设备及存储介质
CN112463491A (zh) 教育一体机进入测试模式的控制方法、装置及存储介质
CN112445761B (zh) 一种文件校验方法、装置及存储介质
CN112559255B (zh) 文件挂载恢复的测试方法、系统、装置及存储介质
CN114116291B (zh) 日志检测方法、日志检测装置、计算机设备及存储介质
CN111522737B (zh) 一种前端界面的自动化测试校验方法、装置及存储介质
CN113986742A (zh) 一种自动化测试方法、装置、设备及存储介质
CN115328356B (zh) 一种电气操作票镜像调试验收方法、装置及可读存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20922436

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20922436

Country of ref document: EP

Kind code of ref document: A1