WO2015051641A1 - 一种磁盘镜像空间回收的方法及装置 - Google Patents

一种磁盘镜像空间回收的方法及装置 Download PDF

Info

Publication number
WO2015051641A1
WO2015051641A1 PCT/CN2014/078364 CN2014078364W WO2015051641A1 WO 2015051641 A1 WO2015051641 A1 WO 2015051641A1 CN 2014078364 W CN2014078364 W CN 2014078364W WO 2015051641 A1 WO2015051641 A1 WO 2015051641A1
Authority
WO
WIPO (PCT)
Prior art keywords
disk image
sector
file
identifier
offset
Prior art date
Application number
PCT/CN2014/078364
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 WO2015051641A1 publication Critical patent/WO2015051641A1/zh

Links

Classifications

    • 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/0668Interfaces specially adapted for storage systems adopting a particular infrastructure
    • G06F3/0671In-line storage system
    • G06F3/0673Single storage device
    • G06F3/0674Disk device
    • 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/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1415Saving, restoring, recovering or retrying at system level
    • G06F11/1433Saving, restoring, recovering or retrying at system level during software upgrading
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • 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/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0608Saving storage space on storage systems
    • 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/0646Horizontal data movement in storage systems, i.e. moving data in between storage devices or systems
    • G06F3/0652Erasing, e.g. deleting, data cleaning, moving of data to a wastebasket
    • 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/4401Bootstrapping
    • G06F9/4418Suspend and resume; Hibernate and awake
    • 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
    • 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/45579I/O management, e.g. providing access to device drivers or storage

Definitions

  • the present invention relates to the field of computers, and in particular, to a method and apparatus for recovering a disk image space.
  • the virtualization software maps the corresponding disk image to the disk of the virtual machine through the corresponding disk driver. All the reading and writing of the internal files of the virtual machine during the running of the virtual machine can be finally converted into reading and writing to the disk image.
  • the disk image file is similar to an external storage device such as a hard disk in an actual computer, and holds all persistent data in the virtual machine. It can be saved as a file on a physical machine disk and read and write via physical machine system I/O. Using disk mirroring under the virtualization platform, combined with the driver, enables advanced features such as thin provisioning and snapshots. After the virtual machine runs for a period of time, the disk image is opened. After the VM is deleted, the space used by the VM is much smaller than the size of the disk image. The storage space exists. It must be wasted.
  • the disk image is zero-filled and reclaimed in the case of the virtual machine online and offline, respectively, thereby realizing the recovery of the virtual machine disk image space.
  • the virtual machine When the virtual machine is online, fill in the free sectors of the disk image, then suspend the virtual machine, read the source disk image content and discard all zero sectors, do not write the target disk image, and then shrink the disk.
  • the image file size, and finally the source disk image is replaced with the target disk image.
  • the virtual machine is offline, create a file on the virtual disk device, fill in the zeros of the free sectors of the disk image, and then read the source disk image content and discard all zero sectors, not write the target disk image, and then shrink The size of the disk image file.
  • the disk mirror free sector when the disk mirror free sector is filled in with zero, the disk image may be filled up and consume time; when space is reclaimed, additional space is required to generate the target disk image.
  • space recycling needs to be hung. The virtual machine was interrupted and the virtual machine business was interrupted.
  • the embodiment of the invention provides a method and a device for recovering a disk image space, which can improve the utilization of the storage space, avoid the disk image being filled, reduce the time consumption, and ensure the uninterrupted virtual machine service.
  • the content is released as a sector of the first identifier.
  • the releasing the content into the sector of the first identifier according to a preset rule includes:
  • the content is released as a sector of the first identification.
  • the searching for the content from the file offset of the disk image is the first identifier Sectors, including:
  • N is a minimum value of a first quantity value and a preset second quantity value
  • the first The quantity value is a value obtained by subtracting the disk image file offset variable from the sector number value of the disk image
  • the start position of the sector whose content is the first identifier and the length of the sector whose content is the first identifier are recorded.
  • the starting location of the sector that records the content as the first identifier and the content are After the length of the first identified sector, the method further includes:
  • the method Before finding the deleted file and the sector in which the deleted file is occupied in the disk image and the valid data is not saved, the method further includes:
  • the method before the mounting the disk image to the hypervisor hypervi sor, the method further includes:
  • the disk image is taken online, so that subsequent write requests are written to the snapshot.
  • the method further includes:
  • the disk image is unloaded from the hypervisor hypervi sor to effect release of the sector as the first identifier.
  • the method further includes: before releasing the content as the sector of the first identifier, according to a preset rule, the method further includes: If the virtual machine is online, create an online disk snapshot for the disk image to implement subsequent write requests to write to the snapshot.
  • the method further includes:
  • a marking unit configured to set a content of the first sector as a first identifier
  • a processing unit configured to release the content as a sector of the first identifier according to a preset rule.
  • the processing unit is configured to obtain a content of the disk image and a value of a sector of the disk image, and set a file offset of the disk image. Finding a sector whose content is the first identifier from a file offset of the disk image, and releasing the sector whose content is the first identifier.
  • the processing unit is configured to obtain and cache the file offset from the disk image Describe the contents of the N sectors of the disk mirror, set the offset of the N sectors in the buffer, and start searching for consecutive sectors whose content is the first identifier from the offset of the N sectors And if there is a sector whose content is the first identifier, record the start position of the sector whose content is the first identifier and the length of the sector whose content is the first identifier, where N is the first quantity a value and a minimum value of the preset second quantity value, the first quantity value being a value obtained by subtracting the disk image file offset variable from the sector number value of the disk image, the N number of fans
  • the offset of the zone is the offset from the disk image.
  • the processing unit is further configured to: in the recording the sector that the content is the first identifier After the starting position and the content are the length of the first identified sector, the system function is called to release the disk image starting from the first offset multiplied by 512, and the length is the fan whose content is the first identifier.
  • the space of the length of the area, the first offset being a variable of the sum of the disk image file offset and the start position of the first identified sector.
  • the search unit includes a first processing module
  • the first processing module is configured to mount the disk image to the virtual machine manager hypervi sor 0 before searching for the deleted file and the sector that the deleted file is occupied in the disk image and the valid data is not saved.
  • the searching unit further includes a pre-processing module
  • the pre-processing module is configured to perform online snapshot of the disk image, so that subsequent write requests are written to the snapshot, if the virtual machine is online, before the first processing module mounts the disk image to the hypervisor hypervi sor .
  • the marking unit includes a second processing module
  • the second processing module is configured to: after setting the content of the sector occupied by the deleted file and not saving valid data as the first identifier, uninstalling the disk image from the virtual machine manager hypervi sor, Implementing to release the content as the sector of the first identifier.
  • the processing unit is further configured to: before the virtual machine is online, create an online disk snapshot to implement subsequent write request writing, before releasing the content as the sector of the first identifier according to a preset rule. Into the snapshot.
  • the processing unit is further configured to: after releasing the content as the sector of the first identifier according to a preset rule, if the virtual machine is online, performing snapshot combination on the disk image, so that Subsequent read and write data of the virtual machine is written to the disk image.
  • An embodiment of the present invention provides a method and an apparatus for recovering a disk image space, by searching a preset primary file table for a deleted file and a first sector corresponding to the deleted file, where the first sector is The sector occupied by the file in the disk image and having no valid data is deleted, and then the content of the first sector is set as the first identifier, and finally, the sector whose content is the first identifier is released according to a preset rule.
  • FIG. 1 is a schematic diagram of a layout of a disk image supporting a thin allocation function
  • FIG. 2 is a schematic flowchart 1 of a method for recovering a disk mirror space according to an embodiment of the present invention
  • FIG. 3 is a schematic flow chart 2 of a method for recovering a disk mirror space according to an embodiment of the present invention
  • FIG. 4 is a schematic structural diagram of a disk mirror space recovery device according to an embodiment of the present invention.
  • FIG. 5 is a schematic structural diagram of a disk mirror space recovery device according to an embodiment of the present invention.
  • FIG. 6 is a schematic structural diagram of a disk mirror space recovery device according to an embodiment of the present invention.
  • FIG. 7 is a schematic structural diagram of a disk mirror space recovery device according to an embodiment of the present invention.
  • a virtual machine is a computer system that has full hardware system functionality and is isolated from the actual physical system. It has its own separate virtual CP memory, hard disk, and even network card, and the operating system can use these devices just like the actual physical resources.
  • NTFS NewTechnol ogy Fi Ie Syst em
  • NT Windows new technology
  • W ndov ⁇ s NT advanced server network operating system environment NTFS is the standard file system for W ndov ⁇ s ⁇ and later Windows 2000, Windows XP, ndows Server 2003, ndows Server 2008, W ndov ⁇ 6 Vi st a, and W ndov ⁇ s 7.
  • NTFS replaces the file allocation table (FAT, Fi I e Al I ocat i on Tabl e ) file system to provide a file system for the W ndov ⁇ s series of operating systems of M cr osof t.
  • FAT file allocation table
  • HPFS High Performance File System
  • Hi gh Perf or nance Fi Ie Syst em supporting metadata and using advanced data structures to improve performance, reliability and disk space. Utilization, and provides several additional extensions, such as access control lists and file system ambitions.
  • a disk image is a separate file that holds the entire contents and structure of a storage medium or device, makes a sector-to-sector copy of the source storage medium, and perfectly replicates the structure and content of the device.
  • disk mirroring also contains metadata for its own data management, enabling fast data reading by the driver for disk mirroring, and more advanced storage features.
  • Thin provisioning a thin provisioning, is a method of optimizing existing storage usage under a shared storage environment optimization that relies on an on-demand allocation of block allocation methods.
  • the format of the disk image is as follows.
  • the block application query table + block storage area deployment pattern is used, wherein the block application query table records the usage of each block, that is, whether data has been stored, and the starting logical address of a certain applied block, generally The sector is the basic unit.
  • the disk image of the thin disk is gradually larger.
  • the space used by the VM is much smaller than the size of the disk image file, which wastes storage space. .
  • the embodiment of the invention provides a method for recovering a disk image space, which is applied to the NTFS file system of the v ⁇ i ndov ⁇ s standard file system. As shown in FIG. 2, the method includes: S101.
  • the first sector is the sector in which the deleted file is occupied in the disk image and the valid data is not saved.
  • Each side of the disk is divided into a number of tracks, each of which is divided into equal parts in units of 512 bytes, which is a sector.
  • the disk image space collection device needs to find the deleted file in the disk image and the deleted file in the disk image in the preset master file table.
  • the sector and further according to the main file table, obtains the sector in which the deleted file is occupied in the disk image and the valid data is not saved, that is, the first sector corresponding to the deleted file.
  • the sector corresponding to the deleted file may be a continuous sector or a non-contiguous sector.
  • the size of the virtual machine disk mirroring space is 5M. After the VM is occupied with 2M files, the disk mirroring space is still 5M. However, the actual storage space is 3M. Space reclamation of the disk image of the virtual machine is required
  • a sector occupying a space of 2 files and occupying a disk image without saving valid data is the first sector corresponding to the deleted file.
  • the disk mirror space reclamation device sets the content of the first sector to be the first standard, and the first identifier may be 0, or may be other identifiers that can be read by a computer other than 0.
  • the disk mirror space collection device searches for the deleted file and the first sector corresponding to the deleted file, the first sector corresponding to the deleted file needs to be marked, so that when the space is recovered, the first sector can be directly found. Sector.
  • the content of the first sector is set to the first identifier when the marking operation is performed, since the space of the first sector is constant, time waste is avoided, and time consumption is reduced.
  • the disk mirroring space reclamation device directly fills the first sector with 0 after searching for the file with the deleted occupied space of 2 ⁇ and the first sector corresponding to the file, so that When space is recovered, the disk mirror space reclamation device can directly perform space recovery on the first sector that has been filled with 0.
  • the occupied space of the first sector is only 2 ⁇ , and only the space of 2 ⁇ is filled with 0, and it is not necessary to fill all the free sectors in the 5 ⁇ space, thereby avoiding waste of time.
  • the disk mirror space reclamation device releases the sector whose content is the first identifier according to a preset rule.
  • the disk mirror space recovery device After obtaining the first sector corresponding to the deleted file and identifying the first file, the disk mirror space recovery device performs space recovery on the identified first sector according to a preset rule.
  • the first identifier may be 0 or other identifiers that can be read by a computer other than 0.
  • the disk mirror space reclamation device finds the deleted occupied space as 2M. After the file and the first sector corresponding to the file, the first sector is directly filled with 0, and then, according to a preset rule, the first sector corresponding to the file with the occupied space of 2M filled with 0 is released. Space.
  • An embodiment of the present invention provides a method for recovering a disk image space.
  • the first sector is a sector in which the deleted file is occupied in the disk image and the valid data is not saved. Then, the content of the first sector is set as the first identifier, and finally, according to the preset rule, the content is released as the first The identified sector.
  • the embodiment of the invention provides a method for recovering a disk image space, which is applied to the NTFS file system of the v ⁇ i ndov ⁇ s standard file system, as shown in FIG. 3, the method includes:
  • the disk mirror space recovery device takes an online snapshot of the disk image, so that subsequent write requests are written into the snapshot.
  • the disk mirror space reclamation device takes an online snapshot of the disk image, the snapshot takes the virtual machine write I/O takeover, and the written data is written to the disk mirror snapshot. In the middle, the virtual machine service is guaranteed to be uninterrupted.
  • this step does not exist if the virtual machine is offline.
  • the disk mirror space reclamation device mounts the disk image to the virtual machine manager hypervi sor.
  • Hypervi sor is an intermediate software layer running between the underlying physical server and the operating system, allowing multiple operating systems and applications to share hardware. It can also be called a virtual machine monitor ( VIVM, vi ual ual nachi ne rnoni t or ) 0 hypervi sor is a "meta" operating system in a virtual environment that accesses all physical devices on the server, including disk and memory. Hypervi sor not only coordinates access to these hardware resources, but also protects between virtual machines. When the server starts and executes hypervi sor, it loads the operating system of all virtual machine clients and allocates the appropriate amount of memory, CPU, network and disk to each virtual machine. The disk mirror space reclamation device mounts the disk image to the virtual machine manager hypervi sor to complete the disk image read and write operations. The hypervi sor is parallel to the disk mirroring perspective and can be used for files or file systems contained in the disk image. deal with.
  • the first sector is the sector in which the deleted file is occupied in the disk image and the valid data is not saved.
  • the sector, and further according to the main file table ⁇ ⁇ , obtains the sector in which the deleted file is occupied in the disk image and the valid data is not saved, that is, the first sector corresponding to the deleted file.
  • the sector corresponding to the deleted file may be a continuous sector or a non-contiguous sector.
  • the sector occupied by the file in the disk image, and further according to the main file table ⁇ ⁇ , the file with the deleted occupied space of 2 ⁇ is occupied in the disk image and the valid data is not saved, that is, the first file corresponding to the deleted file Sector.
  • the disk mirror space reclamation device sets the content of the first sector to the first standard.
  • the content of the first sector includes all data of the storage medium or the device, and further includes metadata, and the metadata is used for data management of the device to implement fast data reading of the disk mirror by the driver.
  • the first identifier may be 0 or an identifier that can be read by the computer other than 0.
  • the disk mirror space collection device searches for the deleted file and the first sector corresponding to the deleted file, the first sector corresponding to the deleted file needs to be marked, so that when the space is recovered, the first sector can be directly found. Sector.
  • the content of the first sector is set to the first identifier when the marking operation is performed, since the space of the first sector is constant, time waste is avoided, and time consumption is reduced.
  • the disk mirror space reclamation device unloads the disk image from the hypervi sor. After the disk image space recovery device disk image is mounted on the hypervi sor, the content of the first sector is set to the first identifier by using hypervi sor, and then the disk image is unloaded from the hypervi sor to implement the disk mirroring space. After the release operation, the disk image is released from the hypervi sor and released as a separate entity.
  • Hypervi sor resources are invaluable. After the hypervi sor processes a disk image, the disk image space reclamation device unloads the disk image from the hypervi sor, and the hypervi sor resources can be utilized by other disk images.
  • the disk image space collection device creates an online disk snapshot for the disk image to implement subsequent write request write to the snapshot.
  • the disk image space reclamation device takes an online snapshot of the disk image.
  • the snapshot takes the virtual machine write I/O takeover, and the data written afterwards is written into the disk mirror snapshot. Guaranteed business is not interrupted.
  • the disk mirror space recovery device obtains the content of the disk image and the number of sectors of the disk image by using a disk mirroring tool.
  • the content of the disk image includes all data of the storage medium or device, and also includes metadata.
  • the disk mirror space recovery device After obtaining the first sector corresponding to the deleted file and identifying the first file, the disk mirror space recovery device performs space recovery on the identified first sector according to a preset rule.
  • the disk mirror space reclamation device When spatially recovering the identified first sector, the disk mirror space reclamation device first needs to obtain the content of the disk image for spatial processing and the number of sectors of the disk image through the disk mirroring tool, and the content of the disk image. Includes all data for storage media or devices, including metadata.
  • the value of the sector number of the disk image is obtained to ensure a certain sector selection range is obtained when the space is recovered.
  • the disk mirror space reclamation device obtains the content of the disk image and the number of sectors of the disk image through the disk mirroring tool.
  • the disk mirror space reclamation device sets a file offset of the disk mirror.
  • the disk mirror space reclamation device When the disk mirror space reclamation device reclaims the disk mirror space, it needs to release the space of the identified first sector. Since the identified first sector may be a contiguous sector or a discontinuous sector, a space release is required for space reclamation, and therefore, the file offset of the disk image is set to f set.
  • the file offset of f set is a variable whose initial value is 0, which varies with the number of times the space is released for different sectors.
  • the disk mirror space reclamation device acquires and caches the contents of the N sectors of the disk image from the file offset of the disk image.
  • N is the minimum of the first quantity value and the preset second quantity value
  • the first quantity value is a value obtained by subtracting the disk image file offset variable from the sector number value of the disk image.
  • the disk mirror space reclamation device reads the content of the N sectors of the disk mirror from the file offset of f set of the disk image, and caches the contents of the N sectors, where N is the first quantity.
  • the minimum value of the value and the preset second quantity value, the first number The value is the value of the number of sectors of the disk image minus the value of the disk image file offset variable.
  • the value of N varies with the file offset of the disk image of f set.
  • the preset second quantity value may be 4096, or may be other quantity values that enable all of the identified first sector space to be released.
  • the sector number of the disk image is M
  • the disk mirror space reclamation device sets an offset of the N sectors in the buffer, and starts searching for a continuous sector whose content is the first identifier from the offset of the N sectors.
  • the offset of each sector is an offset from the disk image.
  • the disk mirror space reclamation device In order to release the space of the identified first sector, after the disk mirror space reclamation device acquires and caches the contents of the disk mirroring sector, it searches for consecutive sectors in the sector that have the first identifier.
  • the disk mirror space reclamation device has buffered the contents of the sectors, and the content of the sectors needs to be processed.
  • the offset Q of the sectors in the buffer is set, where the offset is Q is an offset from the disk image, and then, starting from the offset Q, the contiguous sector whose content is the first identifier is searched.
  • the first identifier may be 0 or other identifiers that can be read by a computer other than 0.
  • the offset of the sector is a variable whose initial value is 0, which varies with the number of consecutive sectors in the sector and the number of spatial releases in the buffer.
  • the content of 70 sectors of the disk image is obtained and cached from the beginning of the disk image. .
  • the content of the 70 sectors in the buffer is processed.
  • the offset Q of the 70 sectors is set, and the initial value of the Q is 0.
  • the contiguous sector whose content is the first identifier is searched. . 521 1. If there is a sector whose content is the first identifier, the disk mirror space reclamation device records the start position of the sector whose content is the first identifier and the length of the sector whose content is the first identifier.
  • the disk mirror space reclamation device processes the buffer sector content
  • the contiguous sector whose content is the first identifier is searched from the offset of the sector in the buffer. If there is a sector in the buffer whose content is the first identifier, the starting position P of the consecutive sector and its length L 0 are recorded.
  • the first identifier may be 0 or other identifiers that can be read by a computer other than 0.
  • the starting position P of the contiguous sector and its length L are both variables, and vary as the number of consecutive sectors of the sector in the buffer are searched and the number of spatial releases changes.
  • the contiguous sector whose content is the first identifier is searched from the offset Q of the 70 sectors. If there is a contiguous sector whose content is the first identifier, its starting position and length are recorded.
  • the disk mirror space reclamation device invokes a system function, and the release of the disk image starts with the first offset multiplied by 512, and the length is the space of the length of the sector whose content is the first identifier.
  • the first offset is a variable of the sum of the disk image file offset and the start position of the first identified sector.
  • the calling system function can call the f al I ocat e function in the Li nux system. Specifically, after the disk mirror space reclamation device searches for the continuous sector whose content is the first identifier, the space of the continuous sector is released. If the f al I ocat e function in the Linux system is called and the FALLOC_FL_PUNCH_HOLE flag is set, the release disk image starts at the first offset multiplied by 512, and the length is the sector with the first identifier. The space of the length, ie (of f set +P) * 512 , the space of length L * 512 makes it a sparse file.
  • the space occupied by the sector is 512 bytes.
  • sparse files leave a lot of free space in the file for future data insertion.
  • Sparse files are generally not allocated with the corresponding disk space after they are created. Only when real data is written will the disk space be allocated.
  • the sector whose content is the first identifier is searched from the file offset of the moved disk image until the system function is called to release all the contents of the disk image as the first identifier.
  • the first identifier may be 0 or other identifiers that can be read by a computer other than 0.
  • the sector number of the disk image has a value M of 4098
  • MN( 4098- 0, 4096 ) 4096 is obtained from the beginning of the disk image.
  • MN( 4098- 0, 4096 ) 4096 is obtained from the beginning of the disk image.
  • MN( 4098- 0, 4096 ) 4096 is obtained from the beginning of the disk image.
  • the disk image space collection device performs snapshot merging on the disk image, so that subsequent read and write data of the virtual machine is written into the disk image.
  • the disk image snapshot records the data written at the time of space recovery of the disk image.
  • the disk mirror space recovery device The disk image is snapshot merged.
  • the merged disk image has the data written at the time of space reclamation, and also the space occupied before and the valid data is not saved.
  • this step does not exist if the virtual machine is offline.
  • An embodiment of the present invention provides a method for recovering a disk image space.
  • the first sector is a sector in which the deleted file is occupied in the disk image and the valid data is not saved. Then, the content of the first sector is set as the first identifier, and finally, according to the preset rule, the content is released as the first The identified sector.
  • the invention provides a disk mirror space recovery device, which is applied to the ⁇ i ndov ⁇ s standard file system NTFS file system, as shown in FIG. 4, comprising:
  • the marking unit 1 1 is configured to set the content of the first sector as the first identifier, and the processing unit 12 is configured to release the content as the sector of the first identifier according to a preset rule.
  • the processing unit 12 is specifically configured to acquire the content of the disk image and the number of sectors of the disk image, set a file offset of the disk image, and offset the file from the disk image. And searching for the content as the sector of the first identifier, and releasing the content as the sector of the first identifier.
  • the processing unit 12 is configured to acquire and cache content of the N sectors of the disk image from a file offset of the disk image, and set a bias of the N sectors in the buffer. Transmitting, and starting from the offset of the N sectors, searching for a contiguous sector whose content is the first identifier, and if there is a sector whose content is the first identifier, recording the content as the first identifier a starting position of the sector and a length of the sector whose content is the first identifier, where N is a minimum value of the first quantity value and a preset second quantity value, the first quantity value being the disk
  • N is a minimum value of the first quantity value and a preset second quantity value, the first quantity value being the disk
  • the number of sectors of the image is subtracted from the value of the disk image file offset variable, the offset of the N sectors being an offset from the disk image.
  • processing unit 12 is further configured to: after the starting position of the sector that records the content as the first identifier and the length of the sector whose content is the first identifier, invoke a system function to release
  • the disk image begins with a first offset multiplied by 512, and the length is a space in which the content is the length of the first identified sector, and the first offset is the disk image file offset and A variable of the sum of the starting positions of the first identified sectors.
  • the search unit 10 includes a first processing module 13 for searching for deleted files and the deleted files are occupied in the disk image. Mount the disk image to the sector before saving the valid data Virtual machine manager hypervi sor 0
  • the search unit 10 further includes a pre-processing module 14 configured to perform online snapshot of the disk image when the virtual machine is online, so that subsequent write requests are written. Snapshot.
  • the marking unit 11 includes a second processing module 15 for setting a content of a sector occupied by the deleted file and not storing valid data. After the first identification, the disk image is unloaded from the virtual machine manager hypervi sor to implement releasing the sector whose content is the first identifier.
  • processing unit 12 is further configured to: before the virtual machine is online, create an online disk snapshot to the disk image, before releasing the content as the first identified sector according to a preset rule, to A subsequent write request is written to the snapshot.
  • processing unit 12 is further configured to, after releasing the content as the sector of the first identifier according to a preset rule, if the virtual machine is online, perform snapshot combination on the disk image to make virtual Subsequent read and write data of the machine is written to the disk image.
  • Embodiments of the present invention provide a disk mirror space reclamation apparatus, which mainly includes a search unit, a marking unit, and a processing unit.
  • the utilization of the virtual machine storage space can be improved, and the disk image is prevented from being filled, which reduces the time consumption and ensures the uninterrupted virtual machine service.
  • the invention provides a disk mirror space recovery device, which is applied to the ⁇ i ndov ⁇ s standard file system NTFS file system, as shown in FIG. 6, and includes:
  • the processor 20 is configured to: in the preset master file table, search for the deleted file and the first sector corresponding to the deleted file, and release the content as the sector of the first identifier according to a preset rule.
  • the first sector is a sector occupied by the deleted file in a disk image and the valid data is not saved;
  • the memory 21 is configured to set the content of the first sector as the first identifier; Further, the processor 20 is configured to acquire the content of the disk image and the number of sectors of the disk image, set a file offset of the disk image, and offset the file from the disk image.
  • the processor 20 is further configured to: after the starting position of the sector that records the content as the first identifier and the length of the sector whose content is the first identifier, invoke a system function to release
  • the disk image begins with a first offset multiplied by 512, and the length is a space in which the content is the length of the first identified sector, and the first offset is the disk image file offset and a variable of the sum of the start positions of the first identified sectors, and also for mirroring the disk before looking for the deleted file and the sector in which the deleted file is occupied in the disk image and the valid data is not saved
  • Mounted to the virtual machine manager hypervi sor and also used to set the disk image from the virtual machine manager hypervi after setting the content of the sector occupied by the deleted file and not saving valid data as the first identifier Uninstalling on sor, and also for creating an online disk snapshot of the disk image, and also if the virtual machine is online, before releasing the content as the sector of the first identifier according to a preset rule, and
  • the processor 20 includes a pre-processor 22 for pre-installing a disk image to the hypervisor hypervi sor, if the virtual machine is online, Take an online snapshot of the disk image so that subsequent write requests are written to the snapshot.
  • Embodiments of the present invention provide a disk mirror space reclamation apparatus, which mainly includes a processor and a memory.
  • the disclosed systems, devices, and methods may be implemented in other ways.
  • the device embodiments described above are merely illustrative.
  • the division of the modules or units is only a logical function division.
  • there may be another division manner for example, multiple units or components may be used. Combinations can be integrated into another system, or some features can be ignored or not executed.
  • the coupling or direct coupling or communication connection shown or discussed herein can be an indirect coupling or communication connection through some interface, device or unit, and can be electrical, mechanical or otherwise.

Abstract

一种磁盘镜像空间回收的方法及装置,涉及计算机领域,能够提高虚拟化场景存储空间的利用率,同时避免磁盘镜像被填满,减少了时间消耗,保证了虚拟机业务的不中断。该方法包括:在预设的主文件表MFT中,査找已删除文件以及已删除文件对应的第一扇区,其中,第一扇区为已删除文件在磁盘镜像中占用的且未保存有效数据的扇区,然后,将第一扇区的内容设置为第一标识,最后,按照预设规则,释放内容为第一标识的扇区。

Description

一种磁盘镜像空间回收的方法及装置 本申请要求于 2013年 10月 12 曰提交中国专利局、 申请号为 201310476249. 5、发明名称为 一种磁盘镜像空间回收的方法及装置" 的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明涉及计算机领域,尤其涉及一种磁盘镜像空间回收的方法 及装置。
背景技术
虚拟化软件通过相应的磁盘驱动程序将对应的磁盘镜像映射为 虚拟机的磁盘,虚拟机运行过程中所有对虚拟机内部文件的读写,都 能够被驱动最终转换为对磁盘镜像的读写。
对于虚拟机而言,磁盘镜像文件类似于实际计算机中的硬盘等外 部存储设备 ,保存着虚拟机中一切持久性数据。 它可以以文件的形式 保存在物理机磁盘中 ,并且通过物理机系统 I / O实现读写功能。 在虚 拟化平台下使用磁盘镜像,结合驱动程序 ,可以实现瘦分配、 快照等 高级特性。 开启瘦分配特性的磁盘镜像,在虚拟机运行一段时间后 , 会逐渐变大;当虚拟机内部有规模的文件删除后 ,虚拟机内部使用的 空间会远远小于磁盘镜像文件大小,存储空间存在一定浪费。
在现有技术中 ,分别在虚拟机在线与离线两种情况时,对磁盘镜 像进行填零和回收,进而,实现在对虚拟机磁盘镜像空间的回收。 当 虚拟机在线时,对磁盘镜像的空闲扇区全部填写零,然后将虚拟机挂 起,读取源磁盘镜像内容并将全零扇区给予丟弃,不写入目标磁盘镜 像,进而缩小磁盘镜像文件大小,最后使用目标磁盘镜像替换源磁盘 镜像。 当虚拟机离线时,在虚拟磁盘设备创建文件,对磁盘镜像的空 闲扇区全部填写零 , 然后读取源磁盘镜像内容并将全零扇区给予丟 弃,不写入目标磁盘镜像,进而缩小磁盘镜像文件大小。
但是,无论虚拟机是在线还是离线,对磁盘镜像空闲扇区全部填 写零时,磁盘镜像有可能会被填满,消耗时间 ;空间回收时,生成目 标磁盘镜像需要额外的空间。 另外 ,虚拟机在线时,空间回收需要挂 起虚拟机, 中断了虚拟机业务。
发明内容
本发明的实施例提供一种磁盘镜像空间回收的方法及装置,能够 提高存储空间的利用率,同时避免磁盘镜像被填满,減少了时间消耗, 保证了虚拟机业务的不中断。
为达到上述目的 ,本发明的实施例采用如下技术方案:
第一方面,本发明的实施例提供一种磁盘镜像空间回收的方法, 应用于 vi ndov\s 标准文件系统 NTFS文件系统中 ,所述方法包括: 在预设的主文件表 M=T中 ,查找已删除文件以及所述已删除文件 对应的第一扇区 ,所述第一扇区为所述已删除文件在磁盘镜像中占用 的且未保存有效数据的扇区;
将所述第一扇区的内容设置为第一标识;
按照预设规则 ,释放所述内容为所述第一标识的扇区。
在第一方面的第一种可能的实现方式中 ,所述按照预设规则 ,释 放所述内容为所述第一标识的扇区 ,具体包括:
获取所述磁盘镜像的内容以及所述磁盘镜像的扇区数量值,所述 内容包括存储介质或设备的全部数据,还包括元数据;
设置所述磁盘镜像的文件偏移量;
从所述磁盘镜像的文件偏移量处查找所述内容为所述第一标识 的扇区;
释放所述内容为所述第一标识的扇区。
结合第一方面的第一种可能的实现方式,在第一方面的第二种可 能的实现方式中 ,所述从所述磁盘镜像的文件偏移量处查找所述内容 为所述第一标识的扇区,具体包括:
从所述磁盘镜像的文件偏移量处获取并缓存所述磁盘镜像的 N 个扇区的内容,所述 N为第一数量值和预设第二数量值中的最小值, 所述第一数量值为所述磁盘镜像的扇区数量值減去所述磁盘镜像文 件偏移变量后得到的数量值;
设置缓冲区中所述 N个扇区的偏移量,并从所述 N个扇区的偏移 量处开始查找内容为第一标识的连续扇区,所述 N个扇区的偏移量是 相对于所述磁盘镜像的偏移量;
若存在内容为第一标识的扇区,则记录所述内容为第一标识的扇 区的起始位置与所述内容为第一标识的扇区的长度。
结合第一方面的第二种可能的实现方式,在第一方面的第三种可 能的实现方式中 ,在所述记录所述内容为第一标识的扇区的起始位置 与所述内容为第一标识的扇区的长度之后,所述方法还包括:
调用系统函数,释放所述磁盘镜像起始于第一偏移量乘以 512 , 长度为所述内容为第一标识的扇区的长度的空间 ,所述第一偏移量是 所述磁盘镜像文件偏移量与所述第一标识扇区的起始位置之和的变 量。
结合前述的第一方面或第一方面的第一种可能的实现方式至第 三种可能的实现方式中的任一种实现方式,在第一方面的第四种可能 的实现方式中 ,所述在查找已删除文件和所述已删除文件在磁盘镜像 中占用的且未保存有效数据的扇区之前 ,所述方法还包括:
将磁盘镜像挂载至虚拟机管理器 hypervi sor。
结合第一方面的第四种可能的实现方式,在第一方面的第五种可 能的实现方式中 ,所述将磁盘镜像挂载至虚拟机管理器 hypervi sor 之前,所述方法还包括:
若虚拟机在线时,将磁盘镜像进行在线快照,使得后续的写请求 写入快照。
结合前述的第一方面或第一方面的第一种可能的实现方式至第 五种可能的实现方式中的任一种实现方式,在第一方面的第六种可能 的实现方式中 ,所述将所述第一扇区的内容设置为第一标识之后,所 述方法还包括:
将所述磁盘镜像从虚拟机管理器 hypervi sor上卸载, 以实现释 放所述内容为所述第一标识的扇区。
结合前述的第一方面或第一方面的第一种可能的实现方式至第 六种可能的实现方式中的任一种实现方式,在第一方面的第七种可能 的实现方式中 ,所述按照预设规则 ,释放所述内容为所述第一标识的 扇区之前,所述方法还包括: 若虚拟机在线时,对所述磁盘镜像创建在线磁盘快照,以实现后 续的写请求写入快照。
结合前述的第一方面或第一方面的第一种可能的实现方式至第 七种可能的实现方式中的任一种实现方式,在第一方面的第八种可能 的实现方式中 ,所述按照预设规则 ,释放所述内容为所述第一标识的 扇区之后,所述方法还包括:
若虚拟机在线时,对所述磁盘镜像进行快照合并,使得虚拟机后 续的读写数据写入所述磁盘镜像。 第二方面,本发明的实施例提供一种磁盘镜像空间回收装置,应 用于 v\i ndov^ 标准文件系统 NTFS文件系统中 ,所述装置包括: 查找单元,用于在预设的主文件表 M=T中 ,查找已删除文件以及 所述已删除文件对应的第一扇区,所述第一扇区为所述已删除文件在 磁盘镜像中占用的且未保存有效数据的扇区;
标记单元,用于将所述第一扇区的内容设置为第一标识; 处理单元,用于按照预设规则 ,释放所述内容为所述第一标识的 扇区。
在第二方面的第一种可能实现方式中 ,所述处理单元,具体用于 获取所述磁盘镜像的内容以及所述磁盘镜像的扇区数量值,设置所述 磁盘镜像的文件偏移量,从所述磁盘镜像的文件偏移量处查找所述内 容为所述第一标识的扇区 , 以及释放所述内容为所述第一标识的扇 区。
结合第二方面的第一种可能的实现方式,在第二方面的第二种可 能的实现方式中 ,所述处理单元,具体用于从所述磁盘镜像的文件偏 移量处获取并缓存所述磁盘镜像的 N个扇区的内容,设置缓冲区中所 述 N个扇区的偏移量,并从所述 N个扇区的偏移量处开始查找内容为 第一标识的连续扇区 ,以及若存在内容为第一标识的扇区 ,则记录所 述内容为第一标识的扇区的起始位置与所述内容为第一标识的扇区 的长度,所述 N为第一数量值和预设第二数量值中的最小值,所述第 一数量值为所述磁盘镜像的扇区数量值減去所述磁盘镜像文件偏移 变量后得到的数量值,所述 N个扇区的偏移量是相对于所述磁盘镜像 的偏移量。 结合第二方面的第二种可能的实现方式,在第二方面的第三种可 能的实现方式中 ,所述处理单元,还用于在所述记录所述内容为第一 标识的扇区的起始位置与所述内容为第一标识的扇区的长度之后,调 用系统函数,释放所述磁盘镜像起始于第一偏移量乘以 512 ,长度为 所述内容为第一标识的扇区的长度的空间 ,所述第一偏移量是所述磁 盘镜像文件偏移量与所述第一标识扇区的起始位置之和的变量。
结合前述的第二方面或第二方面的第一种可能的实现方式至第 三种可能的实现方式中的任一种实现方式,在第二方面的第四种可能 的实现方式中 ,所述查找单元包括第一处理模块;
所述第一处理模块用于在查找已删除文件和所述已删除文件在 磁盘镜像中占用的且未保存有效数据的扇区之前 ,将磁盘镜像挂载至 虚拟机管理器 hypervi sor0
结合第二方面的第四种可能的实现方式,在第二方面的第五种可 能的实现方式中 ,所述查找单元还包括预处理模块;
所述预处理模块,用于在所述第一处理模块将磁盘镜像挂载至虚 拟机管理器 hypervi sor之前,若虚拟机在线时,将磁盘镜像进行在 线快照,使得后续的写请求写入快照。
结合前述的第一方面或第一方面的第一种可能的实现方式至第 五种可能的实现方式中的任一种实现方式,在第二方面的第六种可能 的实现方式中 ,所述标记单元包括第二处理模块;
所述第二处理模块,用于在将所述已删除文件占用且未保存有效 数据的扇区的内容设置为第一标识之后 ,将所述磁盘镜像从虚拟机管 理器 hypervi sor上卸载, 以实现释放所述内容为所述第一标识的扇 区。
结合前述的第一方面或第一方面的第一种可能的实现方式至第 六种可能的实现方式中的任一种实现方式,在第二方面的第七种可能 的实现方式中 ,所述处理单元,还用于在按照预设规则 ,释放所述内 容为所述第一标识的扇区之前 ,若虚拟机在线时,对所述磁盘镜像创 建在线磁盘快照, 以实现后续的写请求写入快照。
结合前述的第一方面或第一方面的第一种可能的实现方式至第 七种可能的实现方式中的任一种实现方式,在第二方面的第八种可能 的实现方式中 ,所述处理单元,还用于在按照预设规则 ,释放所述内 容为所述第一标识的扇区之后 ,若虚拟机在线时,对所述磁盘镜像进 行快照合并,使得虚拟机后续的读写数据写入所述磁盘镜像。
本发明的实施例提供一种磁盘镜像空间回收的方法及装置,通过 在预设的主文件表 中 ,查找已删除文件以及已删除文件对应的第 一扇区 ,其中 ,第一扇区为已删除文件在磁盘镜像中占用的且未保存 有效数据的扇区 ,然后,将第一扇区的内容设置为第一标识,最后 , 按照预设规则 ,释放内容为第一标识的扇区。 通过该方案,能够提高 虚拟机存储空间的利用率,同时避免磁盘镜像被填满,減少了时间消 耗,保证了虚拟机业务的不中断。
附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面 将对实施例或现有技术描述中所需要使用的附图作简单地介绍 ,显而 易见地,下面描述中的附图仅仅是本发明的一些实施例 ,对于本领域 普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些 附图获得其他的附图。
图 1为支持瘦分配功能的磁盘镜像的布局示意图;
图 2 为本发明实施例提供的磁盘镜像空间回收的方法的流程示 意图一 ;
图 3 为本发明实施例提供的磁盘镜像空间回收的方法的流程示 意图二;
图 4 为本发明实施例提供的磁盘镜像空间回收装置的结构示意 图一;
图 5 为本发明实施例提供的磁盘镜像空间回收装置的结构示意 图二;
图 6 为本发明实施例提供的磁盘镜像空间回收装置的结构示意 图三;
图 7 为本发明实施例提供的磁盘镜像空间回收装置的结构示意 图四。
具体实施方式 下面将结合本发明实施例中的附图 ,对本发明实施例中的技术方 案进行清楚、 完整地描述,显然,所描述的实施例仅仅是本发明一部 分实施例 ,而不是全部的实施例。 基于本发明中的实施例 ,本领域普 通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例 , 都属于本发明保护的范围。
本文描述的各种技术适合 \i ndov\s虚拟机的标准文件系统 NTFS 分区的磁盘镜像,在采用瘦分配技术的情况下,对磁盘镜像进行空间 回收。
虚拟机是一种具有完整硬件系统功能,与实际物理系统相隔离的 计算机系统。 它拥有自己独立的虚拟 CP 内存、 硬盘、 乃至网卡, 而且操作系统可以像调用实际物理资源一样使用这些设备。
标准文件系统 ( NTFS , NewTechnol ogy Fi I e Syst em)是 W ndows 新技术( NT , New Tec hnol ogy )操作环境和 W ndov\s NT高级服务器 网络操作系统环境的文件系统。 NTFS 是 W ndov\s ΝΓ 以及之后的 W ndows 2000、 W ndows XP、 ndows Server 2003、 ndows Server 2008、 W ndov\6 Vi st a和 W ndov\s 7的标准文件系统。 NTFS取代了文 件分配表( FAT , Fi I e Al I ocat i on Tabl e )文件系统, 为 M cr osof t 的 W ndov\s系列操作系统提供文件系统。 NTFS对 FAT和高性能文件 系统 ( HPFS , Hi gh Perf or nance Fi I e Syst em)作了若干改进 ,例如 , 支持元数据,并且使用了高级数据结构 ,以便于改善性能、 可靠性和 磁盘空间利用率,并提供了若干附加扩展功能,如访问控制列表和文 件系统曰志。
磁盘镜像是一个单独的文件,存放着代表一个存储介质或设备的 全部内容和结构 ,针对源存储介质进行扇区到扇区的拷贝,并能够完 美地复制设备的结构和内容。磁盘镜像除包含存储介质或设备的全部 数据外 ,还包含元数据,用于自身的数据管理,实现驱动程序对磁盘 镜像的快速数据读取,以及更高级的存储特性实现。 在虚拟化平台下 使用磁盘镜像,结合驱动程序 ,可以实现瘦分配、 快照等高级特性。 瘦分配即精简配置,在共享存储环境优化下 ,优化现有存储使用率的 一种方法,它依赖于按需分配的块分配方法。 在磁盘镜像瘦分配场景 下,由于存储空间并不是立即分配,如图 1所示,磁盘镜像的格式一 般采用块申请查询表 +块存储区域的部署格局 ,其中块申请查询表中 记录着每个块的使用情况,即是否已经存储数据,以及某一个被申请 的块的起始逻辑地址,一般以扇区为基本单位。 开启瘦分配特性的磁 盘镜像,在虚拟机运行一段时间后,会逐渐变大;当虚拟机内部有规 模的文件删除后 ,虚拟机内部使用的空间会远远小于磁盘镜像文件大 小,浪费存储空间。
实施例一
本发明实施例提供一种磁盘镜像空间回收的方法 , 应用于 v\i ndov\s标准文件系统 NTFS文件系统中 ,如图 2所示,该方法包括: S101、 磁盘镜像空间回收装置在预设的主文件表 M=T中 ,查找已 删除文件以及该已删除文件对应的第一扇区。
其中 ,第一扇区为已删除文件在磁盘镜像中占用的且未保存有效 数据的扇区。
NTFS 中包含一个称为主文件表( M=T , ^st er Fi I e Tabl e)的文 件。 是一个映射磁盘中储存的所有对象的索引文件。 在 M=T中 , NTFS磁盘上的每个文件(包括 M=T自身)至少有一映射项。 M=T中的各 项包含大小、 时间及时间戳、 安全属性和数据位置。
磁盘的每一面被分为很多条磁道,每一个磁道又按 512个字节为 单位划分为等分, 即为扇区。
对虚拟机所需的磁盘镜像进行空间回收,首先需要判断虚拟机内 部磁盘镜像未使用的空间。
具体的 ,当需要对虚拟机的磁盘镜像进行空间回收时,磁盘镜像 空间回收装置需要在预设的主文件表 中 ,查找该磁盘镜像中已删 除文件以及该已删除文件在磁盘镜像中占用的扇区,并进一步根据主 文件表 ,获得已删除文件在磁盘镜像中占用且未保存有效数据的 扇区即已删除文件对应的第一扇区。
可选的 ,已删除文件对应的扇区可以为连续扇区 ,也可以为不连 续扇区。
例如 , 虚拟机磁盘镜像空间大小为 5M, 当虚拟机内部占有空间 为 2M的文件删除后 ,磁盘镜像占用空间还是 5M,但是实际使用了 3M , 存储空间存在一定浪费。 在需要对虚拟机的磁盘镜像进行空间回收 时,磁盘镜像空间回收装置在 中 ,查找该磁盘镜像中已删除占有 空间为 2Μ的文件以及该已删除文件在磁盘镜像中占用的扇区,并进 一步根据主文件表 Μ=Τ ,获得已删除占有空间为 2Μ的文件在磁盘镜 像中占用且未保存有效数据的扇区即已删除文件对应的第一扇区。
5102、 磁盘镜像空间回收装置将第一扇区的内容设置为第一标 可选的 ,第一标识可以为 0 ,也可以为除 0以外的计算机可以读 的其他标识。
具体的 ,在磁盘镜像空间回收装置查找获得已删除文件以及已删 除文件对应的第一扇区后 ,需要对已删除文件对应的第一扇区进行标 记,使得空间回收时,可以直接找到第一扇区。
现有技术中 ,在对磁盘镜像进行空间回收之前,将磁盘镜像的空 闲扇区全部填满 0 , 存在磁盘镜像被填满的情况, 造成了时间的浪 费,。
本发明中 ,进行标记操作时仅仅将第一扇区的内容设置为第一标 识,由于第一扇区的空间是一定的 ,避免了时间浪费,減少了时间消 耗。
例如 ,磁盘镜像的空间大小为 5Μ,磁盘镜像空间回收装置在查 找获得已删除占有空间为 2Μ的文件以及该文件对应的第一扇区后, 直接对该第一扇区进行填 0 ,以使得空间回收时,磁盘镜像空间回收 装置可以直接对已填 0的第一扇区进行空间回收。该第一扇区的占有 空间只有 2Μ ,仅对该 2Μ空间进行填 0 ,而不需要将 5Μ空间中的空闲 扇区全部填 0 ,避免了时间的浪费。
5103、 磁盘镜像空间回收装置按照预设规则 ,释放内容为第一标 识的扇区。
具体的 ,磁盘镜像空间回收装置在获得已删除文件对应的第一扇 区,并对其进行标识后 ,按照预设规则 ,对已标识的第一扇区进行空 间回收。
可选的 ,第一标识可以为 0 ,也可以为除 0以外的计算机可以读 的其他标识。
例如 ,磁盘镜像空间回收装置在查找获得已删除占有空间为 2M 的文件以及该文件对应的第一扇区后, 直接对该第一扇区进行填 0 , 然后 ,按照预设规则 ,释放该已填满 0的占有空间为 2M的文件对应 的第一扇区的空间。
本发明的实施例提供了一种磁盘镜像空间回收的方法,磁盘镜像 空间回收装置在预设的主文件表 M=T中 ,查找已删除文件以及已删除 文件对应的第一扇区 ,其中 ,第一扇区为已删除文件在磁盘镜像中占 用的且未保存有效数据的扇区 ,然后,将第一扇区的内容设置为第一 标识,最后,按照预设规则 ,释放内容为第一标识的扇区。 通过该方 案,能够提高虚拟机存储空间的利用率, 同时避免磁盘镜像被填满, 減少了时间消耗,保证了虚拟机业务的不中断。
实施例二
本发明实施例提供一种磁盘镜像空间回收的方法 , 应用于 v\i ndov\s标准文件系统 NTFS文件系统中 ,如图 3所示,该方法包括:
5201、 若虚拟机在线时,磁盘镜像空间回收装置将磁盘镜像进行 在线快照,使得后续的写请求写入快照。
虚拟机在线,对磁盘镜像中已删除文件占用的且未保存有效数据 的空间进行标记时,虚拟机处于工作状态,仍然会写入数据。 为了保 证在进行磁盘镜像扇区内容标记时写入数据的正确性,磁盘镜像空间 回收装置将磁盘镜像进行在线快照,快照将虚拟机写 I / O接管,之后 写入的数据写入磁盘镜像快照中 ,保证了虚拟机业务不中断。
需要说明的是,若虚拟机离线时,不存在这一步骤。
5202、 磁盘镜像空间回收装置将磁盘镜像挂载至虚拟机管理器 hypervi sor。
Hypervi sor 是一种运行在基础物理服务器和操作系统之间的中 间软件层,可允许多个操作系统和应用共享硬件, 也可叫做虚拟机监 视器 ( VIVM, vi rt ual nachi ne rnoni t or ) 0 hypervi sor 是一种在虚 拟环境中的" 元" 操作系统,它们可以访问服务器上包括磁盘和内存 在内的所有物理设备。 Hypervi sor不但协调着这些硬件资源的访问 , 也同时在各个虚拟机之间施加防护。 当服务器启动并执行 hypervi sor 时, 它会加载所有虚拟机客户端的操作系统同时会分配 给每一台虚拟机适量的内存, CPU , 网络和磁盘。 磁盘镜像空间回收装置将磁盘镜像挂载至虚拟机管理器 hypervi sor , 才能完成磁盘镜像的读写操作, hypervi sor 与磁盘镜 像视角是平行的 ,可对磁盘镜像内部所包含的文件或文件系统进行处 理。
5203、 磁盘镜像空间回收装置在预设的主文件表 M=T中 ,查找已 删除文件以及该已删除文件对应的第一扇区。
其中 ,第一扇区为已删除文件在磁盘镜像中占用的且未保存有效 数据的扇区。
NTFS 中包含一个称为主文件表( M=T , ^st er Fi I e Tabl e)的文 件。 是一个映射磁盘中储存的所有对象的索引文件。 在 M=T中 , NTFS磁盘上的每个文件(包括 M=T自身)至少有一映射项。 M=T中的各 项包含大小、 时间及时间戳、 安全属性和数据位置。
对虚拟机所需的磁盘镜像进行空间回收,首先需要判断虚拟机内 部磁盘镜像未使用的空间。
具体的 ,当需要对虚拟机的磁盘镜像进行空间回收时,磁盘镜像 空间回收装置需要在主文件表 M=T中 ,查找该磁盘镜像中已删除文件 以及该已删除文件在磁盘镜像中占用的扇区 ,并进一步根据主文件表 Μ=Τ , 获得已删除文件在磁盘镜像中占用且未保存有效数据的扇区即 已删除文件对应的第一扇区。
可选的 ,已删除文件对应的扇区可以为连续扇区 ,也可以为不连 续扇区。
例如 , 虚拟机磁盘镜像空间大小为 5M, 当虚拟机内部占有空间 为 2M的文件删除后 ,磁盘镜像占用空间还是 5M,但是实际使用了 3M , 存储空间存在一定浪费。 在需要对虚拟机的磁盘镜像进行空间回收 时,磁盘镜像空间回收装置将磁盘镜像挂载至 hypervi sor ,在 Μ=Τ 中 ,查找该磁盘镜像中已删除占有空间为 2Μ的文件以及该已删除文 件在磁盘镜像中占用的扇区,并进一步根据主文件表 Μ=Τ ,获得已删 除占有空间为 2Μ的文件在磁盘镜像中占用且未保存有效数据的扇区 即已删除文件对应的第一扇区。
5204、 磁盘镜像空间回收装置将第一扇区的内容设置为第一标 其中 ,第一扇区的内容包括存储介质或设备的全部数据,还包括 元数据,元数据用于自身的数据管理,实现驱动程序对磁盘镜像的快 速数据读取。
可选的 ,第一标识可以为 0 ,也可以为除 0以外计算机可以读的 标识。
具体的 ,在磁盘镜像空间回收装置查找获得已删除文件以及已删 除文件对应的第一扇区后 ,需要对已删除文件对应的第一扇区进行标 记,使得空间回收时,可以直接找到第一扇区。
现有技术中 ,在对磁盘镜像进行空间回收之前,将磁盘镜像的空 闲扇区全部填满 0 , 存在磁盘镜像被填满的情况, 造成了时间的浪 费,。
本发明中 ,进行标记操作时仅仅将第一扇区的内容设置为第一标 识,由于第一扇区的空间是一定的 ,避免了时间浪费,減少了时间消 耗。
5205、磁盘镜像空间回收装置将磁盘镜像从 hypervi sor上卸载。 磁盘镜像空间回收装置磁盘镜像挂载至 hypervi sor上后,利用 hypervi sor 将其第一扇区的内容设置为第一标识,然后,把磁盘镜 像从 hypervi sor上卸载, 以实现该磁盘镜像的空间释放操作,磁盘 镜像脱离 hypervi sor后,作为独立个体,进行空间释放。
Hypervi sor的资源十分宝贵,当 hypervi sor处理完某一磁盘镜 像后,磁盘镜像空间回收装置将该磁盘镜像从 hypervi sor上卸载后, hypervi sor的资源还能被其他磁盘镜像所利用。
5206、 若虚拟机在线时,磁盘镜像空间回收装置对该磁盘镜像创 建在线磁盘快照, 以实现后续的写请求写入快照。
同理,若虚拟机在线,对磁盘镜像进行空间回收时,虚拟机依旧 处于工作状态,仍然会写入数据。 为了保证在进行磁盘镜像空间回收 时写入数据的正确性,磁盘镜像空间回收装置将磁盘镜像进行在线快 照,快照将虚拟机写 I / O接管,之后写入的数据写入磁盘镜像快照中 , 保证了业务不中断。
需要说明的是,若虚拟机离线时,不存在这一步骤。 5207、 磁盘镜像空间回收装置通过磁盘镜像工具,获取磁盘镜像 的内容以及该磁盘镜像的扇区数量值。
其中 ,磁盘镜像的内容包括存储介质或设备的全部数据,还包括 元数据。
具体的 ,磁盘镜像空间回收装置在获得已删除文件对应的第一扇 区,并对其进行标识后 ,按照预设规则 ,对已标识的第一扇区进行空 间回收。
对已标识的第一扇区进行空间回收时,磁盘镜像空间回收装置首 先需要通过磁盘镜像工具,获取对其进行空间处理的磁盘镜像的内容 以及该磁盘镜像的扇区数量值,磁盘镜像的内容包括存储介质或设备 的全部数据,还包括元数据。
需要说明的是,获得磁盘镜像的扇区数量值是为了保证在空间回 收时获得一定的扇区选择范围。
例如 ,磁盘镜像空间回收装置通过磁盘镜像工具,获取磁盘镜像 的内容以及该磁盘镜像的扇区数量值 M
5208、 磁盘镜像空间回收装置设置磁盘镜像的文件偏移量。
磁盘镜像空间回收装置在对磁盘镜像空间回收时,需要对已标识 的第一扇区进行空间释放。 由于已标识的第一扇区可能为连续扇区 , 也可能为不连续扇区 ,所以在空间回收时,需要进行若干次空间释放, 因此,设置磁盘镜像的文件偏移量 of f set。
具体的 ,文件偏移量 of f set 是一个变量,其初始值为 0 , 随着 对不同扇区空间释放的次数的变化为变化。
5209、磁盘镜像空间回收装置从磁盘镜像的文件偏移量处获取并 缓存磁盘镜像的 N个扇区的内容。
其中 , N为第一数量值和预设第二数量值中的最小值,第一数量 值为磁盘镜像的扇区数量值減去所述磁盘镜像文件偏移变量后得到 的数量值。
具体的 , 磁盘镜像空间回收装置从磁盘镜像的文件偏移量 of f set 处, 向后读取磁盘镜像 N个扇区的内容,并将该 N个扇区的 内容缓存, N为第一数量值和预设第二数量值中的最小值,第一数 量值为磁盘镜像的扇区数量值減去所述磁盘镜像文件偏移变量后得 到的数量值。
具体的 , N的值随着磁盘镜像的文件偏移量 of f set 的变化而变 化。
可选的 ,预设第二数量值可以为 4096 , 也可以为能够使得已标 识的第一扇区空间全部释放的其他数量值。
例如 ,假设磁盘镜像的文件偏移量 of f set 取 0 ,该磁盘镜像的 扇区数量值 M为 70 ,则 N取 M N( 70- 0, 4096 ) =70 ,即从磁盘镜像的 起始位置处获取并缓存该磁盘镜像的 70个扇区的内容。
S210、磁盘镜像空间回收装置设置缓冲区中所述 N个扇区的偏移 量,并从该 N个扇区的偏移量处开始查找内容为第一标识的连续扇 区。
需要说明的是,Ν个扇区的偏移量是相对于所述磁盘镜像的偏移 量。
为了将已标识的第一扇区的空间释放,磁盘镜像空间回收装置在 获取并缓存磁盘镜像 Ν个扇区的内容后 ,查找该 Ν个扇区中内容为第 一标识的连续扇区。
具体的 ,磁盘镜像空间回收装置已经将 Ν个扇区的内容缓存,需 对该 Ν个扇区的内容进行处理,首先设置缓冲区内该 Ν个扇区的偏移 量 Q ,其中偏移量 Q是相对于磁盘镜像的偏移量,然后 ,从该偏移量 Q处开始查找内容为第一标识的连续扇区。
可选的 ,第一标识可以为 0 ,也可以为除 0以外的计算机可以读 的其他标识。
具体的 ,该 Ν个扇区的偏移量是一个变量,其初始值为 0 ,随着 对缓冲区中 Ν个扇区中连续扇区的查找与空间释放的次数的变化为 变化。
例如 ,假设磁盘镜像的文件偏移量 of f set 取 0 ,该磁盘镜像的 扇区数量值 M为 70 ,则从磁盘镜像的起始位置处获取并缓存该磁盘 镜像的 70个扇区的内容。 对缓冲区中该 70个扇区的内容进行处理, 首先,设置该 70个扇区的偏移量 Q ,该 Q初始值为 0 ,从该 Q处开始 查找内容为第一标识的连续扇区。 521 1、 若存在内容为第一标识的扇区,磁盘镜像空间回收装置则 记录内容为第一标识的扇区的起始位置与内容为第一标识的扇区的 长度。
具体的 ,磁盘镜像空间回收装置处理缓冲区扇区内容时,从缓冲 区中扇区的偏移量开始查找内容为第一标识的连续扇区。若缓冲区中 存在内容为第一标识的扇区,则记录该连续扇区的起始位置 P与其长 度 L0
可选的 ,第一标识可以为 0 ,也可以为除 0以外的计算机可以读 的其他标识。
具体的 ,该连续扇区的起始位置 P与其长度 L都是变量,随着对 缓冲区中扇区的连续扇区的查找与空间释放的次数的变化为变化。
例如 ,缓冲区中有 70个扇区的内容,则从该 70个扇区的偏移量 Q处开始查询内容为第一标识的连续扇区。 若存在内容为第一标识的 连续扇区,则记录其起始位置与长度。
5212、 磁盘镜像空间回收装置调用系统函数,释放磁盘镜像起始 于第一偏移量乘以 512 , 长度为内容为第一标识的扇区的长度的空 间。
其中 ,第一偏移量是磁盘镜像文件偏移量与第一标识扇区的起始 位置之和的变量。
可选的 ,调用系统函数可以调用 Li nux系统中 f al I ocat e函数。 具体的 ,磁盘镜像空间回收装置在查找获得内容为第一标识的连 续扇区后 , 对该连续扇区的空间进行释放。 若调用 Li nux 系统中 f al I ocat e函数,并设置 FALLOC—FL— PUNCH— HOLE标识位,释放磁盘 镜像起始于第一偏移量乘以 512 ,长度为内容为第一标识的扇区的长 度的空间 ,即(of f set +P) *512 ,长度为 L*512的空间 ,使其成为稀疏 文件。
需要说明的是,扇区所占用的空间是 512字节。
其中 ,稀疏文件是在文件中留有很多空余空间 ,以备将来插入数 据使用。 稀疏文件一般在建立后 ,并未分配相应的磁盘空间 ,只有真 正的数据写入时, 才会被分配磁盘空间。 具体的 ,磁盘镜像空间回收装置在释放内容为第一标识的 Ν个扇 区后 , 将磁盘镜像的文件偏移量后移 , 即磁盘镜像的文件偏移量 of f set =of f set +N ,从移动后的磁盘镜像的文件偏移量处开始查询内 容为第一标识的扇区 ,直至调用系统函数释放完该磁盘镜像中所有内 容为第一标识的扇区。
可选的 ,第一标识可以为 0 ,也可以为除 0以外的计算机可以读 的其他标识。
例如 ,假设磁盘镜像的文件偏移量 of f set 取 0 ,该磁盘镜像的 扇区数量值 M为 4098 ,则 M N( 4098- 0, 4096 ) =4096 ,则从磁盘镜 像的起始位置处获取并缓存该磁盘镜像的 4096个扇区的内容,对缓 冲区中该 4096个扇区的内容进行处理,设置该 4096个扇区的偏移量 Q ,该 Q初始值为 0 ,从该 Q处开始查找释放内容为第一标识的连续 扇区, 直至将该 4096个扇区中内容为第一标识的连续扇区的空间都 释放 , 然后 , 将磁盘镜像的文件偏移量 of f set 后移 , 即 of f set =0+4096=4096 ,从磁盘镜像中 4096个扇区开始查询内容为第 一标识的扇区,循环查找释放直至磁盘镜像中不存在内容为第一标识 的扇区。
S213、 若虚拟机在线时,磁盘镜像空间回收装置对磁盘镜像进行 快照合并,使得虚拟机后续的读写数据写入该磁盘镜像。
同理,若虚拟机在线,对磁盘镜像进行空间回收后,磁盘镜像快 照中记录了在对磁盘镜像进行空间回收时刻写入的数据,为了保证数 据的完整性和正确性,磁盘镜像空间回收装置对磁盘镜像进行快照合 并,合并后的磁盘镜像拥有在进行空间回收时刻写入的数据,也获得 了之前占用且未保存有效数据的空间。
需要说明的是,若虚拟机离线时,不存在这一步骤。
本发明的实施例提供了一种磁盘镜像空间回收的方法,磁盘镜像 空间回收装置在预设的主文件表 M=T中 ,查找已删除文件以及已删除 文件对应的第一扇区 ,其中 ,第一扇区为已删除文件在磁盘镜像中占 用的且未保存有效数据的扇区 ,然后,将第一扇区的内容设置为第一 标识,最后,按照预设规则 ,释放内容为第一标识的扇区。 通过该方 案,能够提高虚拟机存储空间的利用率, 同时避免磁盘镜像被填满, 減少了时间消耗,保证了虚拟机业务的不中断。
实施例三
本发明提供一种磁盘镜像空间回收装置,应用于 \i ndov\s 标准 文件系统 NTFS文件系统中 ,如图 4所示,包括:
查找单元 10 ,用于在预设的主文件表 M=T中 ,查找已删除文件 以及所述已删除文件对应的第一扇区,所述第一扇区为所述已删除文 件在磁盘镜像中占用的且未保存有效数据的扇区;
标记单元 1 1 ,用于将所述第一扇区的内容设置为第一标识; 处理单元 12 ,用于按照预设规则 ,释放所述内容为所述第一标 识的扇区。
进一步地,所述处理单元 12 ,具体用于获取所述磁盘镜像的内 容以及所述磁盘镜像的扇区数量值, 设置所述磁盘镜像的文件偏移 量,从所述磁盘镜像的文件偏移量处查找所述内容为所述第一标识的 扇区, 以及释放所述内容为所述第一标识的扇区。
进一步地,所述处理单元 12 ,具体用于从所述磁盘镜像的文件 偏移量处获取并缓存所述磁盘镜像的 N个扇区的内容,设置缓冲区中 所述 N个扇区的偏移量,并从所述 N个扇区的偏移量处开始查找内容 为第一标识的连续扇区,以及若存在内容为第一标识的扇区,则记录 所述内容为第一标识的扇区的起始位置与所述内容为第一标识的扇 区的长度,所述 N为第一数量值和预设第二数量值中的最小值,所述 第一数量值为所述磁盘镜像的扇区数量值減去所述磁盘镜像文件偏 移变量后得到的数量值,所述 N个扇区的偏移量是相对于所述磁盘镜 像的偏移量。
进一步地,所述处理单元 12 ,还用于在所述记录所述内容为第 一标识的扇区的起始位置与所述内容为第一标识的扇区的长度之后 , 调用系统函数,释放所述磁盘镜像起始于第一偏移量乘以 512 ,长度 为所述内容为第一标识的扇区的长度的空间 ,所述第一偏移量是所述 磁盘镜像文件偏移量与所述第一标识扇区的起始位置之和的变量。
进一步地,如图 5所示,所述查找单元 10包括第一处理模块 13 , 所述第一处理模块 13 ,用于在查找已删除文件和所述已删除文件在 磁盘镜像中占用的且未保存有效数据的扇区之前 ,将磁盘镜像挂载至 虚拟机管理器 hypervi sor0
进一步地,如图 5所示,所述查找单元 10还包括预处理模块 14 , 所述预处理模块 14 ,用于若虚拟机在线时,将磁盘镜像进行在线快 照,使得后续的写请求写入快照。
进一步地,如图 5所示,所述标记单元 11包括第二处理模块 15 , 所述第二处理模块 15 ,用于在将所述已删除文件占用且未保存有效 数据的扇区的内容设置为第一标识之后 ,将所述磁盘镜像从虚拟机管 理器 hypervi sor上卸载, 以实现释放所述内容为所述第一标识的扇 区。
进一步地,所述处理单元 12 ,还用于在按照预设规则 ,释放所 述内容为所述第一标识的扇区之前 ,若虚拟机在线时,对所述磁盘镜 像创建在线磁盘快照, 以实现后续的写请求写入快照。
进一步地,所述处理单元 12 ,还用于在按照预设规则 ,释放所 述内容为所述第一标识的扇区之后 ,若虚拟机在线时,对所述磁盘镜 像进行快照合并,使得虚拟机后续的读写数据写入所述磁盘镜像。
本发明的实施例提供了一种磁盘镜像空间回收装置,主要包括查 找单元、 标记单元和处理单元。 磁盘镜像空间回收装置在预设的主文 件表 M=T中 ,查找已删除文件以及已删除文件对应的第一扇区,其中 , 第一扇区为已删除文件在磁盘镜像中占用的且未保存有效数据的扇 区,然后 ,将第一扇区的内容设置为第一标识,最后,按照预设规则 , 释放内容为第一标识的扇区。 通过该方案,能够提高虚拟机存储空间 的利用率,同时避免磁盘镜像被填满,減少了时间消耗,保证了虚拟 机业务的不中断。
实施例四
本发明提供一种磁盘镜像空间回收装置,应用于 \i ndov\s 标准 文件系统 NTFS文件系统中 ,如图 6所示,包括:
处理器 20 ,用于在预设的主文件表 中 ,查找已删除文件以 及所述已删除文件对应的第一扇区 ,按照预设规则 ,释放所述内容为 所述第一标识的扇区 ,所述第一扇区为所述已删除文件在磁盘镜像中 占用的且未保存有效数据的扇区;
存储器 21 ,用于将所述第一扇区的内容设置为第一标识; 进一步地,所述处理器 20 ,具体用于获取所述磁盘镜像的内容 以及所述磁盘镜像的扇区数量值,设置所述磁盘镜像的文件偏移量, 从所述磁盘镜像的文件偏移量处查找所述内容为所述第一标识的扇 区,以及释放所述内容为所述第一标识的扇区,以及具体用于从所述 磁盘镜像的文件偏移量处获取并缓存所述磁盘镜像的 Ν个扇区的内 容,设置缓冲区中所述 Ν个扇区的偏移量,并从所述 Ν个扇区的偏移 量处开始查找内容为第一标识的连续扇区,以及若存在内容为第一标 识的扇区,则记录所述内容为第一标识的扇区的起始位置与所述内容 为第一标识的扇区的长度,所述 Ν为第一数量值和预设第二数量值中 的最小值,所述第一数量值为所述磁盘镜像的扇区数量值減去所述磁 盘镜像文件偏移变量后得到的数量值,所述 Ν个扇区的偏移量是相对 于所述磁盘镜像的偏移量。
进一步地,所述处理器 20 ,还用于在所述记录所述内容为第一 标识的扇区的起始位置与所述内容为第一标识的扇区的长度之后,调 用系统函数,释放所述磁盘镜像起始于第一偏移量乘以 512 ,长度为 所述内容为第一标识的扇区的长度的空间 ,所述第一偏移量是所述磁 盘镜像文件偏移量与所述第一标识扇区的起始位置之和的变量,以及 还用于在查找已删除文件和所述已删除文件在磁盘镜像中占用的且 未保存有效数据的扇区之前 , 将磁盘镜像挂载至虚拟机管理器 hypervi sor ,以及还用于在将所述已删除文件占用且未保存有效数据 的扇区的内容设置为第一标识之后 ,将所述磁盘镜像从虚拟机管理器 hypervi sor 上卸载, 以及还用于在按照预设规则 ,释放所述内容为 所述第一标识的扇区之前 ,若虚拟机在线时,对所述磁盘镜像创建在 线磁盘快照,以及还用于在按照预设规则 ,释放所述内容为所述第一 标识的扇区之后 ,若虚拟机在线时,对所述磁盘镜像进行快照合并, 使得虚拟机后续的读写数据写入所述磁盘镜像。
进一步地,如图 7所示,所述处理器 20包括预处理器 22 ,所述 预处理器 22 ,用于在将磁盘镜像挂载至虚拟机管理器 hypervi sor之 前,若虚拟机在线时,将磁盘镜像进行在线快照,使得后续的写请求 写入快照。
本发明的实施例提供了一种磁盘镜像空间回收装置,主要包括处 理器和存储器。 磁盘镜像空间回收装置在预设的主文件表 M=T中 ,查 找已删除文件以及已删除文件对应的第一扇区,其中 ,第一扇区为已 删除文件在磁盘镜像中占用的且未保存有效数据的扇区,然后 ,将第 一扇区的内容设置为第一标识,最后 ,按照预设规则 ,释放内容为第 一标识的扇区。 通过该方案,能够提高虚拟机存储空间的利用率,同 时避免磁盘镜像被填满,減少了时间消耗,保证了虚拟机业务的不中 断。
所属领域的技术人员可以清楚地了解到 , 为描述的方便和简洁, 仅以上述各功能模块的划分进行举例说明 ,实际应用中 ,可以根据需 要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划 分成不同的功能模块,以完成以上描述的全部或者部分功能。 上述描 述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中 的对应过程,在此不再赘述。
在本申请所提供的几个实施例中 ,应该理解到 ,所揭露的系统, 装置和方法,可以通过其它的方式实现。 例如 ,以上所描述的装置实 施例仅仅是示意性的 ,例如 ,所述模块或单元的划分,仅仅为一种逻 辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组 件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不 执行。 另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连 接可以是通过一些接口 ,装置或单元的间接耦合或通信连接,可以是 电性,机械或其它的形式。
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并 不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范 围内 ,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。 因此,本发明的保护范围应以所述权利要求的保护范围为准。

Claims

权利要求
1、 一种磁盘镜像空间回收的方法,其特征在于 ,应用于 \i ndov\s 标准文件系统 NTFS文件系统中 ,所述方法包括:
在预设的主文件表 中 ,查找已删除文件以及所述已删除文件 对应的第一扇区 ,所述第一扇区为所述已删除文件在磁盘镜像中占用 的且未保存有效数据的扇区;
将所述第一扇区的内容设置为第一标识;
按照预设规则 ,释放所述内容为所述第一标识的扇区。
2、 根据权利要求 1所述的磁盘镜像空间回收的方法,其特征在 于, 所述按照预设规则 ,释放所述内容为所述第一标识的扇区 ,具 体包括:
获取所述磁盘镜像的内容以及所述磁盘镜像的扇区数量值,所述 内容包括存储介质或设备的全部数据,还包括元数据;
设置所述磁盘镜像的文件偏移量;
从所述磁盘镜像的文件偏移量处查找所述内容为所述第一标识 的扇区;
释放所述内容为所述第一标识的扇区。
3、 根据权利要求 2所述的磁盘镜像空间回收的方法,其特征在 于,所述从所述磁盘镜像的文件偏移量处查找所述内容为所述第一标 识的扇区,具体包括:
从所述磁盘镜像的文件偏移量处获取并缓存所述磁盘镜像的 N 个扇区的内容,所述 N为第一数量值和预设第二数量值中的最小值, 所述第一数量值为所述磁盘镜像的扇区数量值減去所述磁盘镜像文 件偏移变量后得到的数量值;
设置缓冲区中所述 N个扇区的偏移量,并从所述 N个扇区的偏移 量处开始查找内容为第一标识的连续扇区,所述 N个扇区的偏移量是 相对于所述磁盘镜像的偏移量;
若存在内容为第一标识的扇区 ,则记录所述内容为第一标识的扇 区的起始位置与所述内容为第一标识的扇区的长度。
4、 根据权利要求 3所述磁盘镜像空间回收的方法,其特征在于 , 在所述记录所述内容为第一标识的扇区的起始位置与所述内容为第 一标识的扇区的长度之后 ,所述方法还包括: 调用系统函数,释放所述磁盘镜像起始于第一偏移量乘以 512 , 长度为所述内容为第一标识的扇区的长度的空间 ,所述第一偏移量是 所述磁盘镜像文件偏移量与所述第一标识扇区的起始位置之和的变 量。
5、根据权利要求 1 - 4中任一项所述的磁盘镜像空间回收的方法, 其特征在于 ,所述在查找已删除文件和所述已删除文件对应的第一扇 区之前 ,所述方法还包括:
将所述磁盘镜像挂载至虚拟机管理器 hypervi sor0
6、 根据权利要求 5所述的磁盘镜像空间回收的方法,其特征在 于,所述将磁盘镜像挂载至虚拟机管理器 hypervi sor之前 ,所述方 法还包括:
若虚拟机在线时,将所述磁盘镜像进行在线快照,使得后续的写 请求写入快照。
7、根据权利要求 1 - 6中任一项所述的磁盘镜像空间回收的方法, 其特征在于 ,所述将所述第一扇区的内容设置为第一标识之后 ,所述 方法还包括:
将所述磁盘镜像从虚拟机管理器 hypervi sor上卸载, 以实现释 放所述内容为所述第一标识的扇区。
8、根据权利要求 1 - 7中任一项所述的磁盘镜像空间回收的方法, 其特征在于 ,所述按照预设规则 ,释放所述内容为所述第一标识的扇 区之前 ,所述方法还包括:
若虚拟机在线时,对所述磁盘镜像创建在线磁盘快照,以实现后 续的写请求写入快照。
9、根据权利要求 1 - 8中任一项所述的磁盘镜像空间回收的方法, 其特征在于 ,所述按照预设规则 ,释放所述内容为所述第一标识的扇 区之后 ,所述方法还包括:
若虚拟机在线时,对所述磁盘镜像进行快照合并,使得虚拟机后 续的读写数据写入所述磁盘镜像。
10、 一种磁盘镜像空间回收装置,其特征在于,应用于 \i ndov\s 标准文件系统 NTFS文件系统中 ,所述装置包括:
查找单元,用于在预设的主文件表 中 ,查找已删除文件以及 所述已删除文件对应的第一扇区,所述第一扇区为所述已删除文件在 磁盘镜像中占用的且未保存有效数据的扇区;
标记单元,用于将所述第一扇区的内容设置为第一标识; 处理单元,用于按照预设规则 ,释放所述内容为所述第一标识的 扇区。
11、 根据权利要求 10所述的磁盘镜像空间回收装置,其特征在 于,
所述处理单元,具体用于获取所述磁盘镜像的内容以及所述磁盘 镜像的扇区数量值,设置所述磁盘镜像的文件偏移量,从所述磁盘镜 像的文件偏移量处查找所述内容为所述第一标识的扇区,以及释放所 述内容为所述第一标识的扇区。
12、 根据权利要求 1 1所述的磁盘镜像空间回收装置,其特征在 于,
所述处理单元,具体用于从所述磁盘镜像的文件偏移量处获取并 缓存所述磁盘镜像的 N个扇区的内容,设置缓冲区中所述 N个扇区的 偏移量,并从所述 N个扇区的偏移量处开始查找内容为第一标识的连 续扇区 ,以及若存在内容为第一标识的扇区 ,则记录所述内容为第一 标识的扇区的起始位置与所述内容为第一标识的扇区的长度,所述 N 为第一数量值和预设第二数量值中的最小值,所述第一数量值为所述 磁盘镜像的扇区数量值減去所述磁盘镜像文件偏移变量后得到的数 量值,所述 N个扇区的偏移量是相对于所述磁盘镜像的偏移量。
13、 根据权利要求 12所述的磁盘镜像空间回收装置,其特征在 于,
所述处理单元,还用于在所述记录所述内容为第一标识的扇区的 起始位置与所述内容为第一标识的扇区的长度之后,调用系统函数, 释放所述磁盘镜像起始于第一偏移量乘以 512 ,长度为所述内容为第 一标识的扇区的长度的空间 ,所述第一偏移量是所述磁盘镜像文件偏 移量与所述第一标识扇区的起始位置之和的变量。
14、 根据权利要求 10- 13 中任一项所述的磁盘镜像空间回收装 置,其特征在于 ,所述查找单元包括第一处理模块;
所述第一处理模块,用于在查找已删除文件和所述已删除文件在 磁盘镜像中占用的且未保存有效数据的扇区之前 ,将磁盘镜像挂载至 虚拟机管理器 hypervi sor0
15、 根据权利要求 14所述的磁盘镜像空间回收装置,其特征在 于,所述查找单元还包括预处理模块;
所述预处理模块,用于在所述第一处理模块将磁盘镜像挂载至虚 拟机管理器 hypervi sor之前,若虚拟机在线时,将磁盘镜像进行在 线快照,使得后续的写请求写入快照。
16、 根据权利要 10- 15中任一项所述的磁盘镜像空间回收装置, 其特征在于 ,所述标记单元包括第二处理模块;
所述第二处理模块,用于在将所述已删除文件占用且未保存有效 数据的扇区的内容设置为第一标识之后 ,将所述磁盘镜像从虚拟机管 理器 hypervi sor上卸载, 以实现释放所述内容为所述第一标识的扇 区。
17、 根据权利要求 10- 16 中任一项所述的磁盘镜像空间回收装 置,其特征在于 ,
所述处理单元,还用于在按照预设规则 ,释放所述内容为所述第 一标识的扇区之前,在若虚拟机在线时,对所述磁盘镜像创建在线磁 盘快照, 以实现后续的写请求写入快照。
18、 根据权利要求 10- 17 中任一项所述的磁盘镜像空间回收装 置,其特征在于 ,
所述处理单元,还用于在按照预设规则 ,释放所述内容为所述第 一标识的扇区之后,若虚拟机在线时,对所述磁盘镜像进行快照合并, 使得虚拟机后续的读写数据写入所述磁盘镜像。
PCT/CN2014/078364 2013-10-12 2014-05-26 一种磁盘镜像空间回收的方法及装置 WO2015051641A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310476249.5A CN104572656B (zh) 2013-10-12 2013-10-12 一种磁盘镜像空间回收的方法及装置
CN201310476249.5 2013-10-12

Publications (1)

Publication Number Publication Date
WO2015051641A1 true WO2015051641A1 (zh) 2015-04-16

Family

ID=52812499

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/078364 WO2015051641A1 (zh) 2013-10-12 2014-05-26 一种磁盘镜像空间回收的方法及装置

Country Status (2)

Country Link
CN (1) CN104572656B (zh)
WO (1) WO2015051641A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109117251A (zh) * 2018-08-09 2019-01-01 郑州云海信息技术有限公司 一种虚拟机回收站的实现方法、装置和可读存储介质
CN109710377A (zh) * 2018-12-14 2019-05-03 国云科技股份有限公司 一种从故障的分布式存储里恢复kvm虚拟机的方法
CN110399248A (zh) * 2018-04-25 2019-11-01 阿里巴巴集团控股有限公司 一种镜像文件创建、获取方法、装置及服务器
CN114356232A (zh) * 2021-12-30 2022-04-15 西北工业大学 数据读写方法和装置

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106919471B (zh) * 2015-12-25 2020-03-20 中国电信股份有限公司 用于快照建立的方法和系统
CN106598503B (zh) * 2016-12-23 2019-09-24 郑州云海信息技术有限公司 一种云平台下优化虚拟磁盘占用存储空间的方法和装置
CN107544834B (zh) * 2017-07-28 2020-09-25 新华三云计算技术有限公司 一种镜像文件收缩方法、装置和机器可读存储介质
CN108363552B (zh) * 2018-01-31 2020-06-02 华为技术有限公司 虚拟机磁盘空间回收方法和系统
CN109871183B (zh) * 2018-07-10 2022-04-15 四川中电启明星信息技术有限公司 一种虚拟机磁盘精简的方法及装置
CN114281239A (zh) * 2020-09-28 2022-04-05 华为云计算技术有限公司 一种镜像文件写入方法及装置
CN112148228A (zh) * 2020-09-29 2020-12-29 上海摩勤智能技术有限公司 存储空间的释放方法、终端及存储介质
CN113553142B (zh) * 2021-09-18 2022-01-25 云宏信息科技股份有限公司 云平台的存储空间整理方法、配置方法及可读存储介质

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101609419A (zh) * 2009-06-29 2009-12-23 北京航空航天大学 虚拟机持续在线迁移的数据备份方法及装置
CN101986284A (zh) * 2010-11-04 2011-03-16 华中科技大学 一种虚拟机镜像文件的废弃空间动态回收系统
CN102929788A (zh) * 2012-09-14 2013-02-13 浪潮(北京)电子信息产业有限公司 一种存储系统及存储空间回收的方法

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7818531B2 (en) * 2004-11-05 2010-10-19 Data Robotics, Inc. Storage system condition indicator and method
CN100456264C (zh) * 2006-03-02 2009-01-28 腾讯科技(深圳)有限公司 一种磁盘空间管理方法及系统
CN103092678B (zh) * 2013-01-22 2016-01-13 华中科技大学 一种多增量虚拟机内存管理系统和方法

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101609419A (zh) * 2009-06-29 2009-12-23 北京航空航天大学 虚拟机持续在线迁移的数据备份方法及装置
CN101986284A (zh) * 2010-11-04 2011-03-16 华中科技大学 一种虚拟机镜像文件的废弃空间动态回收系统
CN102929788A (zh) * 2012-09-14 2013-02-13 浪潮(北京)电子信息产业有限公司 一种存储系统及存储空间回收的方法

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110399248A (zh) * 2018-04-25 2019-11-01 阿里巴巴集团控股有限公司 一种镜像文件创建、获取方法、装置及服务器
CN110399248B (zh) * 2018-04-25 2023-08-15 阿里巴巴集团控股有限公司 一种镜像文件创建、获取方法、装置及服务器
CN109117251A (zh) * 2018-08-09 2019-01-01 郑州云海信息技术有限公司 一种虚拟机回收站的实现方法、装置和可读存储介质
CN109117251B (zh) * 2018-08-09 2020-10-30 郑州云海信息技术有限公司 一种虚拟机回收站的实现方法、装置和可读存储介质
CN109710377A (zh) * 2018-12-14 2019-05-03 国云科技股份有限公司 一种从故障的分布式存储里恢复kvm虚拟机的方法
CN109710377B (zh) * 2018-12-14 2023-06-30 国云科技股份有限公司 一种从故障的分布式存储里恢复kvm虚拟机的方法
CN114356232A (zh) * 2021-12-30 2022-04-15 西北工业大学 数据读写方法和装置
CN114356232B (zh) * 2021-12-30 2024-04-09 西北工业大学 数据读写方法和装置

Also Published As

Publication number Publication date
CN104572656B (zh) 2019-02-19
CN104572656A (zh) 2015-04-29

Similar Documents

Publication Publication Date Title
WO2015051641A1 (zh) 一种磁盘镜像空间回收的方法及装置
US11726845B2 (en) Private page cache-based sharing of access to application image layers by application containers
US8805788B2 (en) Transactional virtual disk with differential snapshots
US8510499B1 (en) Solid state drive caching using memory structures to determine a storage space replacement candidate
US8924664B2 (en) Logical object deletion
US8407448B1 (en) Shared storage I/O elimination through mapping client integration into a hypervisor
CN102594849B (zh) 数据备份、恢复方法、虚拟机快照删除、回滚方法及装置
US10303499B2 (en) Application aware graph driver
US9015131B2 (en) Information management method, and computer for providing information
US8966188B1 (en) RAM utilization in a virtual environment
US9015417B2 (en) Deduplication-aware page cache
US9778860B2 (en) Re-TRIM of free space within VHDX
US20170206218A1 (en) Method and apparatus for data deduplication in cloud based storage system
US20180189176A1 (en) Graph driver layer management
CN109804359A (zh) 用于将数据回写到存储设备的系统和方法
US11520665B2 (en) Optimizing incremental backup for clients in a dedupe cluster to provide faster backup windows with high dedupe and minimal overhead
US9122689B1 (en) Recovering performance of a file system post-migration
EP3865992A2 (en) Distributed block storage system, method, apparatus and medium
WO2012164617A1 (en) Data management method for nas
EP3942428A1 (en) Techniques for snapshotting scalable multitier storage structures
US20180285212A1 (en) Using metadata extracted from proxy files to access data stored in secondary storage
US11669405B2 (en) Leveraging metadata to manage the expiration of objects storing incremental backup data
US10013201B2 (en) Region-integrated data deduplication
US11614999B2 (en) Efficient method to index scheduled backup of same target and the corresponding files
CN109343928B (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: 14851867

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: 14851867

Country of ref document: EP

Kind code of ref document: A1