WO2024078262A1 - 快照方法、电子设备、计算机程序产品及可读存储介质 - Google Patents
快照方法、电子设备、计算机程序产品及可读存储介质 Download PDFInfo
- Publication number
- WO2024078262A1 WO2024078262A1 PCT/CN2023/119212 CN2023119212W WO2024078262A1 WO 2024078262 A1 WO2024078262 A1 WO 2024078262A1 CN 2023119212 W CN2023119212 W CN 2023119212W WO 2024078262 A1 WO2024078262 A1 WO 2024078262A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- file
- metadata
- data
- image
- mirror
- Prior art date
Links
- 238000000034 method Methods 0.000 title claims abstract description 110
- 238000004590 computer program Methods 0.000 title claims abstract description 14
- 230000007246 mechanism Effects 0.000 claims abstract description 20
- 230000004044 response Effects 0.000 claims abstract description 5
- 238000004806 packaging method and process Methods 0.000 claims description 9
- 230000000694 effects Effects 0.000 abstract description 6
- 238000004904 shortening Methods 0.000 abstract description 2
- 238000004891 communication Methods 0.000 description 28
- 230000008569 process Effects 0.000 description 28
- 230000006870 function Effects 0.000 description 23
- 238000010586 diagram Methods 0.000 description 16
- 238000011161 development Methods 0.000 description 13
- 238000012423 maintenance Methods 0.000 description 10
- 238000010295 mobile communication Methods 0.000 description 10
- 238000005516 engineering process Methods 0.000 description 9
- 238000007726 management method Methods 0.000 description 7
- 238000012545 processing Methods 0.000 description 7
- 230000009286 beneficial effect Effects 0.000 description 4
- 230000008014 freezing Effects 0.000 description 4
- 238000007710 freezing Methods 0.000 description 4
- 229920001621 AMOLED Polymers 0.000 description 3
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000013500 data storage Methods 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 230000005236 sound signal Effects 0.000 description 3
- 101000827703 Homo sapiens Polyphosphoinositide phosphatase Proteins 0.000 description 2
- 102100023591 Polyphosphoinositide phosphatase Human genes 0.000 description 2
- 238000013461 design Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 230000005012 migration Effects 0.000 description 2
- 238000013508 migration Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 101001121408 Homo sapiens L-amino-acid oxidase Proteins 0.000 description 1
- 102100026388 L-amino-acid oxidase Human genes 0.000 description 1
- 101100012902 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) FIG2 gene Proteins 0.000 description 1
- 101100233916 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) KAR5 gene Proteins 0.000 description 1
- 238000009825 accumulation Methods 0.000 description 1
- 238000013459 approach Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 238000013528 artificial neural network Methods 0.000 description 1
- 230000003416 augmentation Effects 0.000 description 1
- 230000003190 augmentative effect Effects 0.000 description 1
- 230000006399 behavior Effects 0.000 description 1
- 230000008901 benefit Effects 0.000 description 1
- 230000015572 biosynthetic process Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 230000004927 fusion Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 230000007774 longterm Effects 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 238000007781 pre-processing Methods 0.000 description 1
- 239000002096 quantum dot Substances 0.000 description 1
- 238000009877 rendering Methods 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/11—File system administration, e.g. details of archiving or snapshots
- G06F16/128—Details of file system snapshots on the file-level, e.g. snapshot creation, administration, deletion
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/11—File system administration, e.g. details of archiving or snapshots
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/17—Details of further file system functions
- G06F16/176—Support for shared access to files; File sharing support
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/901—Indexing; Data structures therefor; Storage structures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/901—Indexing; Data structures therefor; Storage structures
- G06F16/9017—Indexing; Data structures therefor; Storage structures using directory or table look-up
Definitions
- the present application relates to the field of terminals, and in particular to a snapshot method, an electronic device, a computer program product, and a computer-readable storage medium.
- Application snapshots can refer to snapshot files that save the state of application data at a certain moment.
- users are usually not recommended to use the application, or are prohibited from using the application, to avoid the application snapshot file containing both new and old state file data.
- it is necessary to shorten the application snapshot time as much as possible.
- FIG. 1 An existing application snapshot method is shown in Figure 1, which traverses the original application files of the application, reads the metadata and data of each original application file, writes them from the kernel space to the temporary storage area in the user space, and then writes the metadata and data saved in the temporary storage area to the packaged file. That is, the snapshot of the metadata/data of the original application file involves two data copies between the kernel space and the user space, which makes the application snapshot time too long, and the data copy occupies a large amount of system resources, which has a great impact on system performance and affects the user experience.
- a first aspect of an embodiment of the present application discloses a snapshot method, comprising: generating a mirror file corresponding to the first file in response to a snapshot request for a first file; writing the mirror file metadata to a first preset storage area; writing the mirror file metadata stored in the first preset storage area to a packaged file, and saving the mirror file data to the packaged file based on a copy-on-write mechanism, wherein the mirror file metadata and the package file metadata point to different physical pages, and the mirror file data and the package file data point to the same physical page.
- the metadata of the file is written into the package file by reading the metadata of the mirror file from the kernel space and saving it to the first preset storage area of the user space.
- the first preset storage area is the metadata temporary storage area of the user space, and then the metadata of the mirror file saved in the first preset storage area is written into the package file.
- the image file metadata and the package file metadata point to different physical pages.
- the method of writing the package file can be to copy the image file data on write in the kernel space and save the image file data to the package file.
- the image file data and the package file data point to the same physical page. Since the image file data is saved to the package file by copying on write, it does not involve copying or writing the image file data. This process does not require reading the image file data from the storage device or writing the image file data to the storage device.
- the file snapshot is formed in a short time, has little impact on system performance, and has low development and maintenance costs.
- the mirror file metadata and the first file metadata point to different physical pages, and the mirror file data and the first file data point to the same physical page.
- the image file metadata and the first file metadata also point to different physical pages, and the image file data, the first file data and the reply file data all point to the same physical page.
- the first file data is saved to the image file using the copy-on-write method, and the image file data is saved to the package file using the copy-on-write method, and neither involves copying or writing operations on the file data. This process does not require reading file data from the storage device or writing file data to the storage device, shortening the time to form a file snapshot and having little impact on system performance.
- generating a mirror file corresponding to the first file includes: writing metadata of the first file to the mirror file, and saving data of the first file to the mirror file based on a copy-on-write mechanism.
- the metadata of the first file with a smaller volume is written to the mirror file, and the first file data with a larger volume is saved to the mirror file using the write-time copy mechanism. Since the first file data is saved to the mirror file using the write-time copy method, there is no need to copy or write the first file data. This process does not require reading the first file data from the storage device or writing the first file data to the storage device.
- the file snapshot is formed in a short time, has little impact on system performance, and has low development and maintenance costs.
- the first file metadata is written to the mirror file, and the first file data is saved to the mirror file based on a copy-on-write mechanism, including: creating a new first blank file, and writing the first file metadata to the first blank file; performing a copy-on-write on the first file data, and saving the first file data to the first blank file with the first file metadata written in it, to obtain a mirror file corresponding to the first file.
- a copy-on-write mechanism including: creating a new first blank file, and writing the first file metadata to the first blank file; performing a copy-on-write on the first file data, and saving the first file data to the first blank file with the first file metadata written in it, to obtain a mirror file corresponding to the first file.
- a blank file is constructed, the first file metadata is written into the blank file, and the first file data is copied on write to save the first file data into the blank file in which the first file metadata is written.
- the blank file in which the first file metadata is saved and the first file metadata is saved serves as a mirror file corresponding to the first file.
- the mirror file and the first file have the same metadata and data.
- the index structure of the mirror file and the index structure of the first file point to the same physical block, and share the data stored in the physical block.
- writing the first file metadata to the mirror file includes: writing the first file metadata to a second preset storage area; and writing the first file metadata stored in the second preset storage area to the mirror file.
- the method for writing the first file metadata of a smaller size into the mirror file can be to read the first file metadata from the kernel space and save it to the second preset storage area of the user space.
- the second preset storage area is the metadata temporary storage area of the user space, and then the first file metadata saved in the second preset storage area is written to the mirror file.
- the first file metadata and the mirror file metadata point to different physical pages.
- the second preset storage area is located in the user space, and the first file data is saved to the mirror file based on the write-time copy mechanism, including: copying the first file data on write in the kernel space and saving the first file data to the mirror file.
- the method for writing the first file metadata of a smaller volume into the mirror file can be to read the first file metadata from the kernel space and save it to the second preset storage area in the user space, and then write the first file metadata saved in the second preset storage area into the mirror file.
- the method for writing the first file data of a larger volume into the mirror file can be to save the first file data to the mirror file by copying the first file data on write in the kernel space. Since the first file data is saved to the mirror file by copying the first file data on write, no copying or writing operations of the first file data are involved. This process does not require reading the first file data from the storage device or writing the first file data to the storage device.
- the file snapshot is formed in a short time, has little impact on system performance, and has low development and maintenance costs.
- the first file includes multiple sub-files
- the image file corresponding to the first file includes multiple image sub-files
- writing the image file metadata to the first preset storage area includes: reorganizing the physical structure of the multiple image sub-file metadata based on a preset packaging standard format; writing the reorganized multiple image sub-file metadata to the first preset storage area.
- the metadata and data physical structure of multiple mirror sub-files can be set by the file system, and generally will not be sorted according to the association relationship between the metadata and the data.
- the metadata of multiple mirror sub-files is reorganized according to the preset packaging standard format.
- the default packaging standard format is the POSIX format
- the reorganized metadata is written from the kernel space to the first default storage area in the user space, so that the metadata and data in subsequent packaged files can be sorted according to the association between the metadata and the data, for example, the packaged file has the following physical structure: [file 1 metadata][file 1 data][file 2 metadata][file 2 data]...[file N metadata][file N data].
- generating a mirror file corresponding to the first file includes: calling a preset kernel interface to copy the first file metadata and perform write-time copy on the first file data to obtain the mirror file corresponding to the first file.
- a kernel interface can be customized to realize the functions of copying the metadata of the first file and performing copy-on-write on the data of the first file, so as to obtain a mirror file corresponding to the first file.
- calling a preset kernel interface to copy the first file metadata and perform write-time copy on the first file data includes: calling a preset kernel interface to copy the first file metadata and perform write-time copy on the first file data in kernel space.
- a kernel interface can be customized to realize the functions of copying the first file metadata and writing the first file data in the kernel space.
- Calling the kernel interface can realize the one-time copying of the first file metadata and writing the first file data in the kernel space.
- calling the kernel interface takes less time to copy the file metadata in the kernel space.
- the first file includes multiple sub-files
- calling a preset kernel interface to copy the first file metadata and perform write-time copy on the first file data includes: searching for the sub-file to be mirrored in the user space; calling a preset kernel interface to copy the sub-file metadata to be mirrored and perform write-time copy on the sub-file data to be mirrored in the kernel space.
- the search for the sub-file to be mirrored can be realized in the user space, and the kernel interface can be called in the kernel space to copy the metadata of the sub-file to be mirrored and to perform write-time copy on the data of the sub-file to be mirrored, so as to obtain the mirror file corresponding to the first file.
- the development difficulty and maintenance cost are reduced.
- the first preset storage area is located in the user space, and the image file data is saved to the package file based on the write-time copy mechanism, including: copying the image file data on write in the kernel space and saving the image file data to the package file.
- the image file data of the larger image file data is saved to the package file using the write-time copy mechanism. Since the image file data is saved to the package file using the write-time copy method, no copying or writing operations of the image file data are involved. This process does not require reading the image file data from the storage device or writing the image file data to the storage device.
- the file snapshot is formed in a short time, has little impact on system performance, and has low development and maintenance costs.
- the image file metadata stored in the first preset storage area is written to the packaged file, and the image file data is saved to the packaged file based on the write-time copy mechanism, including: creating a second blank file, writing the image file metadata stored in the first preset storage area to the second blank file; performing write-time copy on the image file data, saving the image file data to the second blank file with the image file metadata written therein, and obtaining the packaged file.
- a blank file is constructed, the image file metadata is written into the blank file, and the image file data is copied on write to save the image file data into the blank file in which the image file metadata is written.
- the blank file in which the image file metadata and the image file metadata are saved is used as a package file corresponding to the first file.
- the image file and the package file have the same metadata and data.
- the index structure of the image file and the index structure of the package file point to the same physical block, and share the data stored in the physical block.
- the first file is all files of the first application
- the further step includes: outputting prompt information associated with the first application, where the prompt information is used to prompt that the first application can be operated.
- the image file corresponding to the first application is By using an image file to generate a package file corresponding to the first application, the user can use the first application normally after the image file corresponding to the first file is generated. For example, a prompt message can be output to remind the user that the first application can be used normally, and the problem existing in the existing package file generation scheme will not be caused: before the package file is generated, if the user uses the first application, the package file will contain files in both new and old states. That is, unlike the existing package file generation scheme, it is not necessary to prohibit the user from using the first application before the package file is generated, which can improve the user experience.
- the first file is all files of the first application. Before generating the image file corresponding to the first file, it also includes: creating an image root directory corresponding to the root directory of the first application, and the image root directory is used to store the image file.
- the information of the root directory of the first application can be obtained, and a mirror root directory corresponding to the root directory of the first application can be created.
- the mirror root directory can be used to save the mirror file of the first application, so that a package file can be generated based on the directories and files under the mirror root directory in the future.
- the mirror root directory is the same as the root directory of the first application, or the mirror root directory is a subset of the root directory of the first application.
- the root directory of the first application and the mirror root directory of the first application can be the same, that is, the directories and files under the root directory of the first application and the mirror root directory of the first application are the same, and the mirror root directory of the first application can also be a subset of the root directory of the first application, that is, the mirror root directory of the first application has some directories and files of the root directory of the first application.
- an embodiment of the present application provides a computer-readable storage medium, including computer instructions.
- the computer instructions When the computer instructions are executed on an electronic device, the electronic device executes the snapshot method described in the first aspect.
- an embodiment of the present application provides an electronic device, the electronic device comprising a processor and a memory, the memory being used to store instructions, and the processor being used to call the instructions in the memory, so that the electronic device executes the snapshot method described in the first aspect.
- an embodiment of the present application provides a computer program product.
- the computer program product is executed on an electronic device (such as a computer)
- the electronic device executes the snapshot method described in the first aspect.
- a device wherein the device has the function of implementing the electronic device behavior in the method provided in the first aspect.
- the function can be implemented by hardware, or by hardware executing corresponding software.
- the hardware or software includes one or more modules corresponding to the above functions.
- the computer-readable storage medium described in the second aspect, the electronic device described in the third aspect, the computer program product described in the fourth aspect, and the device described in the fifth aspect all correspond to the method of the first aspect. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
- FIG1 is a schematic diagram of an architecture of an existing electronic device for implementing application snapshots
- FIG2 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application.
- FIG3 is a schematic diagram of a software structure of an electronic device provided in an embodiment of the present application.
- FIG4 is a schematic diagram of an application scenario of a snapshot method provided in an embodiment of the present application.
- FIG5 is a schematic diagram of an architecture of an electronic device implementing an application snapshot according to an embodiment of the present application
- FIG6a is a schematic diagram of the root directory structure of a first APP provided in an embodiment of the present application.
- FIG6b is a schematic diagram of the mirror root directory structure of the first APP provided in an embodiment of the present application.
- FIG7 is a schematic diagram of an architecture of an electronic device implementing an application snapshot according to another embodiment of the present application.
- FIG8 is a schematic diagram of file data stored in a shared physical block by original files, image files, and packaged files of a first APP provided by an embodiment of the present application;
- FIG9 is a schematic diagram of a process flow of a snapshot method provided in an embodiment of the present application.
- FIG. 10 is a schematic diagram of functional modules of a snapshot device provided in an embodiment of the present application.
- words such as “exemplary” or “for example” are used to indicate examples, illustrations or descriptions. Any embodiment or design described as “exemplary” or “for example” in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as “exemplary” or “for example” is intended to present related concepts in a specific way.
- OS Operating System
- Kernel It establishes a platform for communication between computer software and hardware.
- the kernel provides system services such as file management, virtual memory, and device input/output (I/O).
- User space also known as user state, the activity space of upper-level applications.
- the execution of applications depends on the resources provided by the kernel, such as CPU resources, storage resources, I/O resources, etc.
- Kernel space also known as kernel state, is used to control the computer's hardware resources and provide an environment for the running of upper-level applications.
- Snapshot It is a mirror image of a data set at a specific moment, also known as an instant copy. It is a complete and available copy of the data set.
- Copy on write also known as copy on write, is an optimization strategy in the field of computer programming. Its core idea is: if multiple callers request the same resource at the same time, they will jointly obtain the same pointer to the same resource. Until a caller attempts to modify the resource content, the system will actually copy a dedicated copy to the caller, while the original resource seen by other callers remains unchanged. This process is transparent to other callers. The main advantage of this approach is that if the caller does not modify the resource, no copy will be created, so multiple callers can share the same resource when they only read it.
- File system It is a method of storing and organizing computer data, which makes it easy to access and find computer data.
- the file system uses the abstract logical concepts of files and tree directories instead of the concept of data blocks used by physical devices such as hard disks and optical disks. Users use the file system to save data, and do not need to care about the address of the data block on the hard disk (or optical disk) where the data is actually saved. They only need to remember the directory and file name to which the file belongs. Before writing new data, users do not need to care about which block address on the hard disk is not in use. The storage space management (allocation and release, etc.) on the hard disk is automatically completed by the file system. Users only need to remember which file the data is written to.
- taking a snapshot of a file includes taking a snapshot of the file's metadata and taking a snapshot of the file's data.
- the file's metadata is data used to describe the file, and the file's metadata may include information such as the file name and the time when the file was last modified.
- the physical structure of the metadata may be reorganized in accordance with a preset packaging standard format (e.g., a portable operating system interface of unix (POSIX) format), and the standardized metadata may be written into a packaged file.
- POSIX portable operating system interface of unix
- a packaged file may refer to a file that stores multiple files or directories in a total file, which is called a packaged file.
- reading the file's metadata or data from the kernel space involves a copy from the kernel space to the user space
- writing the file's metadata or data into the packaged file from the user space involves a copy from the user space to the kernel space, that is, taking a snapshot of the file's metadata or data involves two data copies between the kernel space and the user space.
- the data copy between the kernel space and the user space requires that the file on the disk be first copied to the page cache, and then the file in the page cache be copied to the user's buffer.
- the user space and the kernel space are copied to the user space.
- Data copying between kernel spaces is the opposite.
- the data copying between kernel space and user space takes a long time, which results in a long time to form the file snapshot.
- the data copying occupies a large amount of system resources, which has a great impact on system performance and the user experience.
- a solution is developed to implement file snapshots only in kernel space, for example, by copying the data in the original file page cache to the page cache of the new file, or first copying the data in the original file page cache to a temporarily opened cache, and then saving it to the page cache of the new file, the above solution can avoid the problem of data copying between kernel space and user space when taking snapshots of the file metadata or data.
- kernel development cannot use higher-level programming languages. If C language or assembly language is used for kernel development, the development and maintenance costs are too high.
- the size of the file metadata is much smaller than the size of the file data in most cases.
- the size of the file metadata may be several KB to more than ten KB, and the size of the file data may be hundreds of M to several G bytes. Therefore, the performance overhead generated by copying the file data and metadata between the kernel space and the user space is mainly generated by copying the file data between the kernel space and the user space.
- the performance overhead generated by copying the file metadata between the kernel space and the user space is usually small.
- the embodiment of the present application provides a snapshot method, and the method for writing metadata of files with smaller volumes into a packaged file is to read the metadata of the file from the kernel space and save it to the metadata temporary storage area of the user space, and then write the metadata of the file saved in the metadata temporary storage area into the packaged file, and the method for writing the data of files with larger volumes into a packaged file is to copy the data of the file on write in the kernel space and save the copy-on-write copy to the packaged file. Since the data of the file is saved to the packaged file in a copy-on-write manner, it does not involve copying or writing operations on the data of the file. This process does not require reading the data of the file from the storage device or writing the data of the file to the storage device.
- the file snapshot is formed in a short time, has little impact on system performance, and has low development and maintenance costs.
- the snapshot method provided in the embodiment of the present application can be applied to electronic devices.
- the electronic devices of the present application may include but are not limited to mobile phones, foldable electronic devices, tablet computers, personal computers (PCs), laptop computers, handheld computers, notebook computers, ultra-mobile personal computers (UMPCs), netbooks, cellular phones, personal digital assistants (PDAs), augmented reality (AR) devices, virtual reality (VR) devices, artificial intelligence (AI) devices, wearable devices, smart home devices, car equipment, and at least one of smart city equipment.
- PDAs personal digital assistants
- AR augmented reality
- VR virtual reality
- AI artificial intelligence
- wearable devices smart home devices
- car equipment and at least one of smart city equipment.
- the embodiment of the present application does not impose any special restrictions on the specific type of electronic devices.
- the electronic device can also communicate with other electronic devices or servers through a communication network.
- the communication network can be a wired network or a wireless network.
- the communication network can be a local area network (LAN) or a wide area network (WAN), such as the Internet.
- LAN local area network
- WAN wide area network
- the communication network can be a short-range communication network such as a wireless fidelity (Wi-Fi) hotspot network, a Wi-Fi P2P network, a Bluetooth network, a zigbee network, or a near field communication (NFC) network.
- Wi-Fi wireless fidelity
- Wi-Fi P2P Wireless Fidelity
- the communication network can be a third-generation mobile communication technology (3rd-generation wireless telephone technology, 3G) network, a fourth-generation mobile communication technology (4G) network, a fifth-generation mobile communication technology (5G) network, a future evolved public land mobile network (PLMN) or the Internet, etc.
- 3G third-generation mobile communication technology
- 4G fourth-generation mobile communication technology
- 5G fifth-generation mobile communication technology
- PLMN future evolved public land mobile network
- the electronic device may be installed with one or more APPs (Applications).
- APPs may be referred to as applications, which are software programs that can implement one or more specific functions.
- instant messaging applications may include, for example, Image capture applications, such as camera applications (system camera or third-party camera applications).
- Video applications such as Huawei Video, Audio applications, such as Huawei Music,
- the applications mentioned in the following embodiments may be system applications installed when the electronic device leaves the factory, or may be system applications installed by the user during the use of the electronic device.
- Third-party applications downloaded from the Internet or obtained from other electronic devices.
- Electronic equipment includes but is not limited to Windows or other operating systems.
- FIG. 2 shows a schematic structural diagram of an electronic device 10 .
- the electronic device 10 may include a processor 110, an external memory interface 120, an internal memory 121, an antenna 1, an antenna 2, a mobile communication module 130, a wireless communication module 140, an audio module 150, a sensor module 160, a camera module 170, a display screen 180, and the like.
- the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 10.
- the electronic device 10 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently.
- the components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
- the processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and/or a neural-network processing unit (NPU), etc.
- AP application processor
- GPU graphics processor
- ISP image signal processor
- DSP digital signal processor
- NPU neural-network processing unit
- Different processing units may be independent devices or integrated in one or more processors.
- the processor 110 may also be provided with a memory for storing instructions and data.
- the memory in the processor 110 may be a cache memory.
- the memory may store instructions or data that have been used or are frequently used by the processor 110. If the processor 110 needs to use the instructions or data, it may be directly called from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
- the processor 110 may include one or more interfaces.
- the interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver/transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input/output (GPIO) interface, a subscriber identity module (SIM) interface, and/or a universal serial bus (USB) interface.
- the processor 110 may be connected to an audio module, a wireless communication module, a display, a camera, and other modules through at least one of the above interfaces.
- the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 10.
- the electronic device 10 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
- the wireless communication function of the electronic device 10 can be implemented through the antenna 1, the antenna 2, the mobile communication module 130, the wireless communication module 140, the modem processor and the baseband processor.
- the mobile communication module 130 can provide solutions for wireless communications including 2G/3G/4G/5G, etc., applied to the electronic device 10.
- the mobile communication module 130 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc.
- at least some functional modules of the mobile communication module 130 may be set in the processor 110.
- at least some functional modules of the mobile communication module 130 may be set in the same device as at least some modules of the processor 110.
- the wireless communication module 140 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), Bluetooth low energy (BLE), ultra wide band (UWB), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 10.
- WLAN wireless local area networks
- BT Bluetooth
- BLE Bluetooth low energy
- UWB ultra wide band
- GNSS global navigation satellite system
- FM frequency modulation
- NFC near field communication
- IR infrared
- the electronic device 10 can communicate with a network and other electronic devices through wireless communication technology.
- the wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and/or IR technology.
- GSM global system for mobile communications
- GPRS general packet radio service
- CDMA code division multiple access
- WCDMA wideband code division multiple access
- TD-SCDMA time-division code division multiple access
- LTE long term evolution
- BT GNSS
- WLAN wireless local area network
- the electronic device 10 can realize the display function through a GPU, a display screen 180, and an application processor.
- the GPU is a microprocessor for image processing, which connects the display screen 180 and the application processor.
- the GPU is used to perform mathematical and geometric calculations for graphics rendering.
- the processor 110 may include one or more GPUs, which execute program instructions to generate or change display information.
- the camera module 170 includes a camera.
- the display screen 180 is used to display images, videos, etc.
- the display screen 180 includes a display panel.
- the display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, quantum dot light-emitting diodes (QLED), etc.
- the electronic device 10 may include one or more display screens 180.
- the external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 10.
- the external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function.
- the internal memory 121 can be used to store computer executable program codes, which include instructions.
- the internal memory 121 may include a program storage area and a data storage area.
- the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.
- the data storage area may store data created during the use of the electronic device 10, etc.
- the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
- the processor 110 executes various functional methods or data processing of the electronic device 10 by running instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor.
- the audio module 150 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals.
- the audio module 150 can also be used to encode and decode audio signals.
- the audio module 150 can be arranged in the processor 110, or some functional modules of the audio module 150 can be arranged in the processor 110.
- the software system of the electronic device 10 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture.
- the embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 10.
- FIG. 3 is a software structure block diagram of the electronic device 10 according to an embodiment of the present application.
- the layered architecture divides the software into several layers, each with a clear role and division of labor.
- the layers communicate with each other through software interfaces.
- the Android system is divided into five layers, from top to bottom: application layer, application framework layer, Android runtime (Android runtime, ART) and native C/C++ library, hardware abstract layer (HAL) and kernel layer.
- the application layer can include a series of application packages.
- the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.
- the application framework layer provides application programming interface (API) and programming framework for the applications in the application layer.
- API application programming interface
- the application framework layer includes some predefined functions.
- the application framework layer may include a window manager, a content provider, a view system, a resource manager, a notification manager, an activity manager, an input manager, and the like.
- the window manager provides window management services (Window Manager Service, WMS).
- WMS can be used for window management, window animation management, surface management and as a transit station for the input system.
- Content providers are used to store and retrieve data and make it accessible to applications.
- the data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
- the view system includes visual controls, such as controls for displaying text, controls for displaying images, etc.
- the view system can be used to build applications.
- a display interface can be composed of one or more views.
- a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
- the resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
- the notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc.
- the notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
- the Activity Manager can provide Activity Manager Service (AMS).
- AMS can be used to start, switch, and schedule system components (such as activities, services, content providers, broadcast receivers) as well as manage and schedule application processes.
- the input manager can provide input management service (IMS), which can be used to manage the input of the system, such as touch screen input, key input, sensor input, etc.
- IMS input management service
- IMS takes events from input device nodes and distributes them to the appropriate window through interaction with WMS.
- the Android runtime includes the core library and the Android runtime.
- the Android runtime is responsible for converting source code into machine code.
- the Android runtime mainly uses the ahead-of-time (AOT) compilation technology and the just-in-time (JIT) compilation technology.
- the core library is mainly used to provide basic Java class library functions, such as basic data structures, mathematics, IO, tools, databases, networks, etc.
- the core library provides an API for users to develop Android applications.
- the native C/C++ library can include multiple functional modules, such as surface manager, media framework, libc, OpenGL ES, SQLite, Webkit, etc.
- the surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.
- the media framework supports playback and recording of multiple commonly used audio and video formats, as well as static image files, etc.
- the media library can support multiple audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
- OpenGL ES provides drawing and operation of 2D graphics and 3D graphics in applications. SQLite provides a lightweight relational database for applications of electronic devices 10.
- the hardware abstraction layer runs in user space, encapsulates kernel layer drivers, and provides a calling interface to the upper layer.
- the kernel layer is the layer between hardware and software.
- the kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
- the electronic device 10 is described by taking a mobile phone as an example.
- the electronic device 10 may be installed with one or more APPs. After the user clicks on an APP, the electronic device 10 may Create the corresponding application process, which can realize the various functions of the corresponding APP.
- the electronic device 10 For the APP installed on the electronic device 10, the electronic device 10 establishes a root directory for storing APP files.
- the electronic device 10 is installed with the Huawei Video APP, and the electronic device 10 establishes a root directory RT1 for storing Huawei Video APP files.
- Taking a snapshot of the Huawei Video APP file may refer to taking a snapshot of the file data and file metadata under the root directory RT1.
- the Huawei Video APP fails to run on the electronic device 10, or the Huawei Video APP file is damaged, the APP file can be quickly restored based on the previously established snapshot, so that the Huawei Video APP can be restored to the state at the time point when the snapshot was previously taken.
- a user has two electronic devices 10 (hereinafter referred to as the first electronic device and the second electronic device for easy distinction), the first electronic device has the Huawei Video APP installed, and the second electronic device does not have the Huawei Video APP installed, and the first electronic device establishes a communication connection with the second electronic device.
- the first electronic device and the second electronic device can establish a communication connection via Bluetooth or a wireless LAN. After the communication connection is successful, you can select the data to be migrated on the first electronic device, for example, select "Huawei Video APP", and then click the "Start Migration" icon, so that you can migrate the Huawei Video APP files to the second electronic device.
- FIG5 it is a schematic diagram of the architecture of the electronic device of the present application for implementing data snapshot.
- the operating system installed in the electronic device 10 is a system developed based on the Linux kernel as an example for explanation.
- the electronic device 10 can be installed with multiple APPs.
- the APP installed in the electronic device 10 can refer to the APP installed when the electronic device 10 leaves the factory, or it can be a third-party APP downloaded from the network or obtained by the user from other electronic devices during the use of the electronic device 10.
- the following is an example in which the electronic device 10 is installed with the first APP A1, and a snapshot of the file of the first APP A1 is taken.
- the snapshot of the file of the first APP A1 includes taking a snapshot of the file metadata of the first APP A1 and taking a snapshot of the file data of the first APP A1.
- the first APP A1 can be an instant messaging application, a video application, an audio application, an image capture application, a cloud desktop application, etc. This application does not limit the type of the first APP A1.
- the electronic device 10 has established a root directory d_0 for storing the files of the first APP A1.
- the electronic device 10 taking a snapshot of the files of the first APP A1 may refer to taking a snapshot of each file under the root directory d_0.
- the electronic device 10 may create a mirror root directory of the root directory d_0.
- the mirror root directory of the root directory d_0 is hereinafter referred to as the root directory d_0'.
- the root directory d_0' is used to store the mirror file of the first APP A1. Assuming that the directory structure of the root directory d_0 is as shown in FIG6a, the created root directory d_0' is as shown in FIG6b.
- root directory d_0 and root directory d_0’ if there is a file f11 in root directory d_0 and the save path of file f11 is “d_0/d1/d11/f11”, then there is also a file f11 in root directory d_0’, the file f11 in root directory d_0’ is a mirror file of the file f11 in root directory d_0, and the save path of file f11 in root directory d_0’ is “d_0’/d1/d11/f11”, the subdirectory d1 in root directory d_0’ is a mirror directory of the subdirectory d1 in root directory d_0, and the subdirectory d11 in root directory d_0’ is a mirror directory of the subdirectory d11 in root directory d_0.
- a mirror root directory is created for a certain root directory, and the mirror root directory is used to store mirror files.
- the root directory and its mirror root directory may be the same (i.e., the directories and files under the root directory and its mirror root directory are the same), or the mirror root directory is a subset of the root directory (i.e., the mirror root directory has some directories and files of its root directory).
- Creating a mirror file for a certain file may refer to: creating a new blank file, saving the metadata of the file to the blank file, the metadata of the file may include the file name, the file modification time, etc., and then calling a preset clone interface to copy the file data to the blank file storing the metadata of the file when writing, thereby forming a mirror file.
- the mirror file of the present application may also be called a clone file.
- the electronic device 10 may run a snapshot program, and the snapshot program may respond to a snapshot request for the first APP A1, and take a snapshot of the data and metadata of each file under the root directory d_0, so as to write the data and metadata of each file under the root directory d_0 to the package file PF.
- the first APP A1 includes n files f11, f12, ..., f1n (n is a positive integer greater than 1)
- the snapshot program adds the data and metadata of the files f11 to f1n of the first APP A1 to the package file PF, which may include the following implementation process.
- the snapshot program reads the metadata of files f11 ⁇ f1n from the file system and saves the metadata of files f11 ⁇ f1n to the snapshot program.
- the data is saved from the kernel space to the first metadata temporary storage area AR1 of the user space.
- the metadata of file f11 may refer to data used to describe file f11
- the metadata of file f1n may refer to data used to describe file f1n.
- the metadata of file f11 may include the file name of file f11, the last modification time of the file, the file extension attributes, etc.
- the first metadata temporary storage area AR1 of the user space may refer to a physical memory page used as a buffer in the user space.
- the snapshot program implements saving the metadata of the files f11-f1n from the kernel space to the first metadata temporary storage area AR1 of the user space, which may specifically include: a1 , the snapshot program copies the metadata of the files f11-f1n from the disk to the page cache (Page Cache) of the kernel space, for example, the snapshot program sequentially copies the metadata of the files f11-f1n from the disk to the page cache of the kernel space, the page cache is the physical page of the memory, or the snapshot program copies the metadata of the files f11-f1n from the disk to the page cache of the kernel space in parallel; a2 , the snapshot program copies the metadata of the files f11-f1n from the page cache to the first metadata temporary storage area AR1 of the user space, for example, the snapshot program sequentially copies the metadata of the files f11-f1n from the page cache to the first metadata temporary storage area AR1 of the user space, or the snapshot program copies the metadata of the files f11-f1n from the page cache
- the snapshot program performs a copy-on-write operation on the data of files f11 to f1n in the kernel space to save the data of files f11 to f1n to the clone file set CF.
- the data of files f11 to f1n can be saved to a clone file set CF.
- the clone file set CF has the same data and metadata as files f11 to f1n
- the clone file set CF includes mirror files f11' to f1n' corresponding to files f11 to f1n
- mirror file f11' has the same data and metadata as file f11
- mirror file f1n' has the same data and metadata as file f1n.
- Mirror file f11' shares the data of file f11, and mirror file f1n' shares the data of file f1n.
- the data shared by mirror file f11' may refer to the index structure of mirror file f11' and the index structure of file f11 pointing to the same physical block, and sharing the data stored in the physical block.
- the snapshot program can perform a copy-on-write operation on one file at a time to save the data of the file to the clone file set CF until the data of all files f11 to f1n are saved to the clone file set CF.
- saving the data of files f11 to f1n to the clone file set CF by copy-on-write does not involve reading/writing the data of files f11 to f1n on the disk, and the system overhead is small, that is, this process does not need to read the data of the file from the storage device or write the data of the file to the storage device, and the CPU does not need to perform the copy operation of the file data, which has little impact on system performance, takes less time, and has low power consumption of the CPU and the storage device during copy-on-write.
- the snapshot program writes the metadata of the files f11-f1n stored in the first metadata temporary storage area AR1 into the clone file set CF.
- the clone file set CF by writing the metadata of files f11 ⁇ f1n saved in the first metadata temporary area AR1 into the clone file set CF, the clone file set CF has both the same data and the same metadata as the files f11 ⁇ f1n, and the clone file set CF can be used as a file copy of the first APP A1.
- a package file PF corresponding to the first APP A1 is generated based on the clone file set CF, so that the user can use the first APP A1 normally after the clone file set CF is generated, and will not cause the problem existing in the existing package file generation scheme: before the package file is generated, if the user uses the first APP A1, the package file will cause the package file to contain files in both new and old states. That is, unlike the existing package file generation scheme, it is necessary to prohibit the user from using the first APP A1 before the package file PF is generated, which can improve the user experience.
- the electronic device 10 may output a prompt message after generating the clone file set CF to remind the user that the first APP A1 can be used normally.
- the snapshot program can copy the metadata of the files f11-f1n from the first metadata temporary storage area AR1 in the user space to the page cache in the kernel space to save the first metadata temporary storage area AR1.
- the metadata of the stored files f11 to f1n are written to the clone file set CF.
- the snapshot program reads metadata of the image files f11'-f1n' from the clone file set CF, pre-processes the metadata of the image files f11'-f1n', and saves them to the second metadata temporary storage area AR2 of the user space.
- the physical structure of metadata and data of files f11 to f1n, or the physical structure of metadata and data of image files f11' to f1n' is set by the file system, and generally will not be sorted according to the association relationship between metadata and data.
- Preprocessing the metadata of image files f11' to f1n' may refer to reorganizing the physical structure of metadata of image files f11' to f1n' in accordance with a preset packaging standard format, and writing the processed metadata from the kernel space to the second metadata temporary storage area AR2 located in the user space, so that the metadata and data in the subsequent packaged file PF can have the following physical structure: [file 1 metadata] [file 1 data] [file 2 metadata] [file 2 data] ...
- [file N metadata] [file N data], that is, sorting according to the association relationship between metadata and data.
- the metadata of image files f11' to f1n' can be processed based on the POSIX format, and the processed metadata is written to the second metadata temporary storage area AR2.
- the first metadata temporary storage area AR1 and the second metadata temporary storage area AR2 may also refer to the same metadata temporary storage area, or may be different metadata temporary storage areas, which is not limited in the present application.
- the snapshot program writes the metadata of the image files f11'-f1n' stored in the second metadata temporary storage area AR2 into the package file PF.
- the read and write code logic of the package file PF runs in the kernel space
- the snapshot program can write the metadata of the image files f11’ ⁇ f1n’ stored in the second metadata temporary area AR2 to the package file PF by copying the metadata of the image files f11’ ⁇ f1n’ from the second metadata temporary area AR2 of the user space to the page cache of the kernel space.
- the snapshot program performs a write-time copy on the data of the image files f11'-f1n' in the clone file set CF to save the data of the image files f11'-f1n' to the package file PF.
- the data of the image files f11'-f1n' in the clone file set CF are copied on write in the kernel space to save the data of the image files f11'-f1n' to the package file PF, that is, the package file PF and the clone file set CF share the data of the files f11-f1n, and the data of the image files f11'-f1n' are copied on write and saved to the package file PF, which does not involve reading/writing the file data on the disk, and the system overhead is small and the speed is fast.
- the snapshot program can copy the data of a mirror file on write each time to generate a COW copy corresponding to the data of each mirror file, until the COW copies of the data of all the image files f11'-f1n' are saved to the package file PF.
- the package file PF may be compressed to save storage space occupied by the package file PF and improve the migration efficiency of the package file PF.
- the snapshot program can also complete writing the metadata of files f11 ⁇ f1n to the packaged file PF in the kernel space, for example, by setting a metadata temporary storage area in the kernel space, so that the snapshot program can read the metadata of files f11 ⁇ f1n from the file system and temporarily store them in the metadata temporary storage area of the kernel space, and write the metadata of files f11 ⁇ f1n stored in the metadata temporary storage area of the kernel space to the clone file set CF.
- the snapshot program can also read the metadata of image files f11' ⁇ f1n' from the clone file set CF and temporarily store them in the metadata temporary storage area of the kernel space, and write the metadata of image files f11' ⁇ f1n' stored in the metadata temporary storage area of the kernel space to the packaged file PF.
- FIG. 7 is a schematic diagram of the architecture of the electronic device of the present application for implementing data snapshots.
- the operating system installed in the electronic device 10 is a system developed based on the Linux kernel.
- the electronic device 10 can be installed with multiple APPs.
- the APP installed in the electronic device 10 can be an APP installed when the electronic device 10 leaves the factory, or a third-party APP downloaded from the Internet or obtained from other electronic devices by the user during the use of the electronic device 10.
- taking a snapshot of the file of the first APP A1 as an example, taking a snapshot of the file of the first APP A1 includes taking a snapshot of the file metadata of the first APP A1 and taking a snapshot of the file data of the first APP A1.
- the first APP A1 can be an instant messaging application, a video application, an audio application, an image capture application, a cloud desktop application, etc. This application does not limit the type of the first APP A1.
- the electronic device 10 may run a snapshot program, and the snapshot program may respond to a snapshot request for the first APP A1, and take a snapshot of the data and metadata of each file of the first APP A1, so as to write the data and metadata of each file of the first APP A1 to the package file PF.
- the first APP A1 includes n files f11, f12, ..., f1n (n is a positive integer greater than 1), and the snapshot program adds the data and metadata of the files f11 to f1n of the first APP A1 to the package file PF, which may include the following implementation process.
- the snapshot program creates the mirror root directory of the first APP A1 and searches for the files to be mirrored in the user space.
- the electronic device 10 taking a snapshot of the files of the first APP A1 may refer to taking a snapshot of each file under the root directory d_1.
- the electronic device 10 may create a mirror root directory of the root directory d_1.
- the mirror root directory of the root directory d_1 is referred to as the root directory d_1' hereinafter.
- the root directory d_1' is used to store the mirror file of the first APP A1.
- the snapshot program may respond to the snapshot request for the first APP A1 and take a snapshot of the data and metadata of each file of the first APP A1, for example, searching for the files of the first APP A1 in the user space to achieve a snapshot of each file of the first APP A1.
- the files to be mirrored may refer to files in the first APP A1 for which mirror files have not yet been established.
- the snapshot program calls the kernel customized interface to copy the metadata of the searched file and perform write-time copy on the file data, so as to generate or update the image file in the image root directory and obtain the clone file set CF.
- the generation of the image root directory and the image files under the image root directory can be controlled in the user space.
- the image files or directories under the image root directory can be generated in the kernel space.
- the kernel customized interface can refer to an interface designed to copy the metadata of the files in the kernel space and copy the data of the files on write. Compared with FIG5 , setting the first metadata temporary storage area AR1 to temporarily store the metadata of the files f11 ⁇ f1n will involve two metadata copies between the kernel space and the user space, and it takes less time to copy the metadata of the files in the kernel space.
- the clone file set CF includes mirror files f11' ⁇ f1n' corresponding to files f11 ⁇ f1n.
- the mirror file f11' has the same data and metadata as the file f11, and the mirror file f1n' has the same data and metadata as the file f1n.
- the mirror file f11' shares the data of the file f11, and the mirror file f1n' shares the data of the file f1n.
- the mirror file f11' shares the data of the file f11, which means that the index structure of the mirror file f11' and the index structure of the file f11 point to the same physical block, and share the data stored in the physical block.
- the snapshot program reads metadata of the image files f11'-f1n' from the clone file set CF, pre-processes the metadata of the image files f11'-f1n', and saves them to the first metadata temporary storage area AR1 of the user space.
- the snapshot program writes the metadata of the image files f11'-f1n' stored in the first metadata temporary storage area AR1 into the package file PF.
- the snapshot program performs a write-time copy on the data of the image files f11'-f1n' in the clone file set CF to save the data of the image files f11'-f1n' to the package file PF.
- the clone file set CF includes the image file f11' corresponding to the file f11 and the image file f12' corresponding to the file f12
- the packaged file PF includes the image file f11" corresponding to the image file f11' and the image file f12" corresponding to the image file f12'.
- the data index structure I11 of the file f11, the data index structure I12 of the mirror file f11' and the mirror file The data index structure I13 of the mirror file f11" points to the same physical blocks P1 and P2, and shares the file data stored in the physical blocks P1 and P2.
- the data index structure I21 of the file f12, the data index structure I22 of the mirror file f12', and the data index structure I23 of the mirror file f12" point to the same physical blocks P3 and P4, and share the file data stored in the physical blocks P3 and P4.
- the process of obtaining the mirror file f11' from the file f11 may include: creating a first blank file, saving the metadata of the file f11 to the first blank file, performing copy-on-write on the data of the file f11, and saving the data of the file f11 to the first blank file storing the metadata of the file f11, thereby forming the mirror file f11'.
- the operation involved in saving the metadata of the file f11 to the first blank file may include reading the metadata of the file f11 from the kernel space and saving it to the metadata temporary storage area of the user space, and then copying the metadata of the file f11 stored in the metadata temporary storage area to the page cache of the kernel space, so as to save the metadata of the file f11 to the first blank file, and the metadata of the file f11 and the metadata of the mirror file f11' point to different physical pages.
- the operations involved in performing a copy-on-write operation on the data of file f11 and saving the data of file f11 to the first blank file storing the metadata of file f11 may include performing a copy-on-write operation on the data of file f11 and saving the data of file f11 to the first blank file storing the metadata of file f11, thereby forming a mirror file f11', and the data of file f11 and the data of mirror file f11' point to the same physical page.
- Saving the data of file f11 to the first blank file storing the metadata of file f11 based on the copy-on-write mechanism does not involve reading/writing the data of file f11 on the disk, and has low system overhead, that is, this process does not need to read the data of file f11 from the storage device or write the data of file f11 to the storage device, has little impact on system performance, and takes little time.
- the process of obtaining the mirror file f11” from the mirror file f11’ may also include: creating a second blank file, saving the metadata of the mirror file f11’ to the second blank file, the metadata of the mirror file f11’ and the metadata of the mirror file f11” point to different physical pages, performing write-time copy on the data of the mirror file f11’, and saving the data of the mirror file f11’ to the second blank file in which the metadata of the mirror file f11’ is stored, thereby forming the mirror file f11”.
- the data of the mirror file f11’ and the data of the mirror file f11” point to the same physical page.
- the process of obtaining the mirror file f12’ from the file f12 may include: creating a third blank file, saving the metadata of the file f12 to the third blank file, the metadata of the file f12 and the metadata of the mirror file f12’ point to different physical pages, performing write-time copy on the data of the file f12, and saving the data of the file f12 to the third blank file in which the metadata of the file f12 is stored, thereby forming the mirror file f12’.
- the data of the file f12 and the data of the mirror file f12’ point to the same physical page.
- the process of obtaining the mirror file f12” from the mirror file f12’ may also include: creating a fourth blank file, saving the metadata of the mirror file f12’ to the fourth blank file, the metadata of the mirror file f12’ and the metadata of the mirror file f12” point to different physical pages, performing write-time copy on the data of the mirror file f12’, and saving the data of the mirror file f12’ to the fourth blank file in which the metadata of the mirror file f12’ is saved, thereby forming the mirror file f12”.
- the data of the mirror file f12’ and the data of the mirror file f12” point to the same physical page.
- an embodiment of the present application provides a snapshot method, which is applied to an electronic device 10.
- the snapshot method may include:
- S91 In response to a snapshot request for a first file, generate a mirror file corresponding to the first file.
- the first file may include first file data (data of the first file) and first file metadata (metadata of the first file)
- the mirror file may include mirror file data (data of the mirror file) and mirror file metadata (metadata of the mirror file).
- a second preset storage area can be set in the user space.
- the method of writing the metadata of the first file to the mirror file can be to read the metadata of the first file from the kernel space and save it to the second preset storage area of the user space, and then write the metadata of the first file saved in the second preset storage area to the mirror file.
- the method of writing the mirror file can be to save the first file data to the mirror file by copying the first file data on write in the kernel space.
- the mirror file metadata and the first file metadata can point to different physical pages.
- the first file data is saved to the mirror file using the copy-on-write mechanism, and the mirror file data and the first file data can point to the same physical page. Since the first file data is saved to the mirror file using the copy-on-write method, no copying or writing operations of the first file data are involved. This process There is no need to read the first file data from the storage device or write the first file data to the storage device, the file snapshot is formed in a short time, and the impact on system performance is small.
- the two files share the same file data.
- the data will be copied to the new page and replace the original copy-on-write page.
- a first blank file can be created, and the first file metadata can be written to the first blank file.
- the first file data can be copied on write to save the first file data to the first blank file in which the first file metadata is written.
- the blank file in which the first file metadata is saved and the first file metadata are saved can serve as a mirror file corresponding to the first file.
- the mirror file and the first file have the same metadata and data.
- the index structure of the mirror file and the index structure of the first file point to the same physical block, and share the data stored in the physical block.
- a kernel interface can also be customized, and the kernel interface is used to implement the functions of copying the first file metadata and copying the first file data on write in the kernel space, and then the kernel interface can be called to respond to the snapshot request for the first file and generate a mirror file corresponding to the first file.
- the kernel interface By calling the kernel interface, the copying of the first file metadata and the copying of the first file data on write can be completed in the kernel space at one time.
- a metadata temporary storage area second preset storage area
- the sub-file to be mirrored can be searched in user space, and the kernel interface can be called in kernel space to copy the metadata of the sub-file to be mirrored and to perform write-time copy on the sub-file data to be mirrored, so as to obtain the image file corresponding to the first file.
- the kernel interface can be called in kernel space to copy the metadata of the sub-file to be mirrored and to perform write-time copy on the sub-file data to be mirrored, so as to obtain the image file corresponding to the first file.
- the first preset storage area may be located in the user space, and the image file metadata may be read from the kernel space and written to the first preset storage area located in the user space. If the first file includes multiple sub-files, and the image file corresponding to the first file includes multiple image sub-files, the physical structure of the metadata of the multiple image sub-files may be reorganized based on the preset packaging standard format, and the reorganized metadata of the multiple image sub-files may be written to the first preset storage area.
- the physical structure of the metadata and data of the multiple image sub-files is generally set by the file system, and is generally not sorted according to the association relationship between the metadata and the data.
- the metadata and data in the subsequent packaged files can be sorted according to the association relationship between the metadata and the data, for example, the packaged file has the following physical structure: [file 1 metadata] [file 1 data] [file 2 metadata] [file 2 data] ... [file N metadata] [file N data].
- the method for writing the metadata of a smaller image file into a package file may be to read the image file metadata from the first preset storage area and write it into the package file, and the method for writing the image file data of a larger image file into a package file may be to save the image file data into the package file by copying the image file data on write in the kernel space.
- the image file metadata stored in the first preset storage area can be written into the second blank file by creating a new second blank file, and the image file data can be copied on write.
- the image file metadata is saved in a second blank file written with the image file metadata, and the blank file with the image file metadata and the image file metadata are saved as a package file corresponding to the first file.
- the image file and the package file have the same metadata and data, and the index structure of the image file and the index structure of the package file point to the same physical block, and share the data stored in the physical block.
- taking the first file as all files of the first application as an example, after taking a snapshot of the first application to obtain an image file corresponding to the first application, a package file corresponding to the first application is generated based on the image file of the first application, so that the user can use the first application normally after the image file corresponding to the first application is generated.
- a prompt message can be output to remind the user that the first application can be used normally, and the problem existing in the existing package file generation scheme will not be caused: before the package file is generated, if the user uses the first application, the package file will cause the package file to contain files in both new and old states. That is, unlike the existing package file generation scheme, it is not necessary to prohibit the user from using the first application before the package file is generated, which can improve the user experience.
- the image file obtained in step S91 can be saved in the image root directory.
- the information of the root directory of the first application can be obtained, and the image root directory corresponding to the root directory of the first application can be created.
- the image root directory is used to save the image file of the first application, so that the package file can be generated based on the directories and files under the image root directory in the subsequent process.
- the image root directory can be the same as the root directory of the first application, that is, the root directory of the first application is the same as the directories and files under the image root directory of the first application, or the image root directory can be a subset of the root directory of the first application, that is, the image root directory of the first application has some directories and files of the root directory of the first application.
- an embodiment of the present application provides a snapshot device 100, including a state freezing module 101, a first writing module 102, and a second writing module 103.
- the module referred to in the embodiment of the present application may refer to a series of computer program instruction segments that can perform specific functions, or may be a functional module formed by the cooperation of computer program instruction segments and hardware.
- the division of modules is a logical function division, and there may be other division methods in actual implementation, which is not limited in the present application.
- the state freezing module 101 is configured to generate a mirror file corresponding to the first file in response to a snapshot request for the first file.
- the state of the first file is frozen by the state freezing module 101, so that the corresponding packaged file is generated based on the image file of the first file, and it is not necessary to prohibit the reading and writing of the first file before the packaged file is generated.
- the first file is all the files of the first application.
- the packaged file corresponding to the first application is generated based on the image file of the first application, so that the user can use the first application normally after the image file corresponding to the first file is generated, and the problem existing in the existing packaged file generation scheme will not occur: before the packaged file is generated, if the user uses the first application, the packaged file will contain files in both new and old states, that is, unlike the existing packaged file generation scheme, it is necessary to prohibit the user from using the first application before the packaged file is generated, which can improve the user experience.
- the first writing module 102 is used to write the image file metadata into the first preset storage area.
- the second writing module 103 is used to write the image file metadata stored in the first preset storage area into the package file, and save the image file data into the package file based on the copy-on-write mechanism.
- a method for writing metadata of a smaller file into a packaged file may be to read the image file metadata from the kernel space and save it to a first preset storage area in the user space, for example, the first preset storage area is a metadata temporary storage area of the user space, and then write the image file metadata saved in the first preset storage area into the packaged file.
- the image file metadata and the package file metadata point to different physical pages.
- a method for writing file data of a larger size into a packaged file may be to save the image file data to the packaged file by copying the image file data on write in the kernel space. In this file data writing method, the image file data and the package file data point to the same physical page.
- the image file data is saved to the packaged file using the copy-on-write method, no copying or writing operations of the image file data are involved. This process does not require reading the image file data from a storage device or writing the image file data to a storage device.
- the file snapshot is formed in a short time, has little impact on system performance, and has low development and maintenance costs.
- the electronic device 10 provided in the embodiment of the present application may include an internal memory 121 for storing instructions, and a processor 110 for storing instructions.
- the internal memory 121 is used to call the instructions in the internal memory 121, so that the electronic device 10 executes the above-mentioned related method steps to implement the snapshot method in the above-mentioned embodiment.
- the internal memory 121 can also store the state freezing module 101, the metadata writing module 102 and the data writing module 103, which are executed by the processor 110 to implement the function of the snapshot device 100.
- the embodiment of the present application also provides a computer storage medium, in which computer instructions are stored.
- the computer instructions When the computer instructions are executed on the electronic device 10, the electronic device 10 executes the above-mentioned related method steps to implement the snapshot method in the above-mentioned embodiment.
- the embodiment of the present application also provides a computer program product.
- the computer program product When the computer program product is run on an electronic device, the electronic device executes the above-mentioned related steps to implement the snapshot method in the above-mentioned embodiment.
- an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory so that the chip executes the snapshot method in the above-mentioned method embodiments.
- the computer storage medium, computer program product or chip provided in the embodiments of the present application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
- the disclosed devices and methods can be implemented in other ways.
- the device embodiments described above are schematic.
- the division of the modules or units is a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed.
- Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
- the units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
- each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
- the above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
- the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium.
- the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the software product is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the method described in each embodiment of the present application.
- the aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Software Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本申请提供了一种快照方法、电子设备、计算机程序产品及计算机可读存储介质,涉及终端领域。快照方法包括:响应于针对第一文件的快照请求,生成与第一文件对应的镜像文件;将镜像文件元数据写入至第一预设存储区;将第一预设存储区保存的镜像文件元数据写入至打包文件,及基于写时复制机制将镜像文件数据保存至打包文件,镜像文件元数据与打包文件元数据指向不同的物理页,镜像文件数据与打包文件数据指向相同的物理页。本申请将体积较小的文件元数据写入至打包文件,对于体积较大的文件数据则采用写时复制方式将文件数据保存至打包文件,不涉及从存储器件读取文件数据或者将文件数据写入至存储器件,缩短文件快照形成时间,对***性能影响小。
Description
本申请要求于2022年10月10日提交中国专利局,申请号为202211236869.7、申请名称为“快照方法、电子设备、计算机程序产品及可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及终端领域,尤其涉及一种快照方法、电子设备、计算机程序产品及计算机可读存储介质。
现有的操作***一般都支持通过备份***来实现备份用户数据,在数据备份过程中,较耗时的流程是产生应用快照,应用快照可以是指保存应用数据在某一瞬间的状态的快照文件。为了确保快照文件状态的一致性,在产生应用快照期间,通常会不建议用户使用应用,或者禁止用户使用应用,避免应用的快照文件中同时包含新、旧状态的文件数据。为了提高用户的使用体验,有必要尽可能地将应用快照时间缩短。
现有的一种应用快照方式如图1所示,通过遍历应用的原始应用文件,读取各个原始应用文件的元数据和数据,从内核空间写入至位于用户空间的暂存区,再将暂存区保存的元数据和数据写入至打包文件。即对原始应用文件的元数据/数据进行的快照涉及两次内核空间和用户空间之间的数据拷贝,使得应用快照的时间过长,且数据拷贝占用的***资源较大,对***性能影响大,影响用户的使用体验。
发明内容
有鉴于此,有必要提供一种快照方法,解决现有技术中应用快照形成时间过长,对***性能影响大的问题。
本申请实施例第一方面公开了一种快照方法,包括:响应于针对第一文件的快照请求,生成与第一文件对应的镜像文件;将镜像文件元数据写入至第一预设存储区;将第一预设存储区保存的镜像文件元数据写入至打包文件,及基于写时复制机制将镜像文件数据保存至打包文件,镜像文件元数据与打包文件元数据指向不同的物理页,镜像文件数据与打包文件数据指向相同的物理页。
采用上述技术方案,对文件进行快照时,通过生成与文件对应的镜像文件,实现快速对文件状态进行冻结,后续再基于镜像文件生成打包文件,使得用户在镜像文件生成之后可以正常对文件进行操作,不像现有打包文件生成方案需在生成打包文件之前一直禁止用户操作文件,可以提升用户使用体验,对于体积较小的文件元数据写入打包文件的方式可以为从内核空间读取镜像文件元数据保存至用户空间的第一预设存储区,例如第一预设存储区为用户空间的元数据暂存区,再将第一预设存储区保存的镜像文件元数据写入至打包文件,此种文件元数据写入方式,镜像文件元数据与打包文件元数据指向不同的物理页,对于体积较大的文件数据写入打包文件的方式可以为在内核空间通过对镜像文件数据进行写时复制,将镜像文件数据保存至打包文件,此种文件数据写入方式,镜像文件数据与打包文件数据指向相同的物理页,由于对镜像文件数据采用写时复制方式保存至打包文件,不涉及对镜像文件数据的拷贝、写入操作,此过程无需从存储器件读取镜像文件数据或者将镜像文件数据写入至存储器件,文件快照形成时间短,对***性能影响小,开发维护成本低。
在一些实施例中,镜像文件元数据与第一文件元数据指向不同的物理页,镜像文件数据与第一文件数据指向相同的物理页。
采用上述技术方案,镜像文件元数据与第一文件元数据亦指向不同的物理页,镜像文件数据、第一文件数据及答辩文件数据均指向相同的物理页。对第一文件数据采用写时复制方式保存至镜像文件,对镜像文件数据采用写时复制方式保存至打包文件,均不涉及对文件数据的拷贝、写入操作,此过程无需从存储器件读取文件数据或者将文件数据写入至存储器件,缩短文件快照形成时间,对***性能影响小。
在一些实施例中,生成与第一文件对应的镜像文件,包括:将第一文件元数据写入至镜像文件,及基于写时复制机制将第一文件数据保存至镜像文件。
采用上述技术方案,通过将体积较小的第一文件元数据写入至镜像文件,对于体积较大的第一文件数据,利用写时复制机制将第一文件数据保存至镜像文件,由于对第一文件数据采用写时复制方式保存至镜像文件,不涉及对第一文件数据的拷贝、写入操作,此过程无需从存储器件读取第一文件数据或者将第一文件数据写入至存储器件,文件快照形成时间短,对***性能影响小,开发维护成本低。
在一些实施例中,将第一文件元数据写入至镜像文件,及基于写时复制机制将第一文件数据保存至镜像文件,包括:新建第一空白文件,将第一文件元数据写入至第一空白文件;对第一文件数据进行写时复制,将第一文件数据保存至写入有第一文件元数据的第一空白文件,得到与第一文件对应的镜像文件。
采用上述技术方案,通过构建空白文件,将第一文件元数据写入至空白文件,对第一文件数据进行写时复制,以将第一文件数据保存至写入有第一文件元数据的空白文件,保存有第一文件元数据与第一文件元数据的空白文件作为与第一文件对应的镜像文件,镜像文件与第一文件具有相同的元数据与数据,镜像文件的索引结构与第一文件的索引结构指向相同的物理块,共享物理块中存储的数据。
在一些实施例中,将第一文件元数据写入至镜像文件,包括:将第一文件元数据写入至第二预设存储区;将第二预设存储区保存的第一文件元数据写入至镜像文件。
采用上述技术方案,对于体积较小的第一文件元数据写入镜像文件的方式可以为从内核空间读取第一文件元数据保存至用户空间的第二预设存储区,例如第二预设存储区为用户空间的元数据暂存区,再将第二预设存储区保存的第一文件元数据写入至镜像文件,第一文件元数据与镜像文件元数据指向不同的物理页。
在一些实施例中,第二预设存储区位于用户空间,基于写时复制机制将第一文件数据保存至镜像文件,包括:在内核空间对第一文件数据进行写时复制,将第一文件数据保存至镜像文件。
采用上述技术方案,对于体积较小的第一文件元数据写入镜像文件的方式可以为从内核空间读取第一文件元数据保存至用户空间的第二预设存储区,再将第二预设存储区保存的第一文件元数据写入至镜像文件,对于体积较大的第一文件数据写入镜像文件的方式可以为在内核空间通过对第一文件数据进行写时复制,将第一文件数据保存至镜像文件,由于对第一文件数据采用写时复制方式保存至镜像文件,不涉及对第一文件数据的拷贝、写入操作,此过程无需从存储器件读取第一文件数据或者将第一文件数据写入至存储器件,文件快照形成时间短,对***性能影响小,开发维护成本低。
在一些实施例中,第一文件包括多个子文件,与第一文件对应的镜像文件包括多个镜像子文件,将镜像文件元数据写入至第一预设存储区,包括:基于预设打包标准格式重新组织多个镜像子文件元数据的物理结构;将重新组织后的多个镜像子文件元数据写入至第一预设存储区。
采用上述技术方案,多个镜像子文件的元数据与数据的物理结构可以由文件***进行设定,一般不会依照元数据与数据的关联关系进行排序,通过对多个镜像子文件的元数据按照预设打包标准格式重新组织各个镜像子文件的元数据的物理结构,例如
预设打包标准格式为POSIX格式,并将重新组织后的元数据从内核空间写入到位于用户空间的第一预设存储区,使得后续打包文件中的元数据与数据可以依照元数据与数据的关联关系进行排序,例如使得打包文件具有如下的物理结构:[文件1元数据][文件1数据][文件2元数据][文件2数据]…[文件N元数据][文件N数据]。
在一些实施例中,生成与第一文件对应的镜像文件,包括:调用预设内核接口对第一文件元数据进行拷贝及对第一文件数据进行写时复制,得到与第一文件对应的镜像文件。
采用上述技术方案,可以定制化一个内核接口,用于实现拷贝第一文件元数据以及对第一文件数据进行写时复制的功能,得到与第一文件对应的镜像文件。
在一些实施例中,调用预设内核接口对第一文件元数据进行拷贝及对第一文件数据进行写时复制,包括:调用预设内核接口在内核空间对第一文件元数据进行拷贝及对第一文件数据进行写时复制。
采用上述技术方案,可以定制化一个内核接口,用于实现在内核空间完成拷贝第一文件元数据以及对第一文件数据进行写时复制的功能,调用内核接口可以实现在内核空间一次性完成对第一文件元数据进行拷贝及对第一文件数据进行写时复制,相比在用户空间设置元数据暂存区暂存文件元数据会涉及两次内核空间和用户空间之间的元数据拷贝,通过调用内核接口在内核空间拷贝文件的元数据花费时间更短。
在一些实施例中,第一文件包括多个子文件,调用预设内核接口对第一文件元数据进行拷贝及对第一文件数据进行写时复制,包括:在用户空间搜索待镜像的子文件;调用预设内核接口在内核空间对待镜像的子文件元数据进行拷贝及对待镜像的子文件数据进行写时复制。
采用上述技术方案,可以在用户空间实现搜索待镜像的子文件,在内核空间调用内核接口对待镜像的子文件元数据进行拷贝及对待镜像的子文件数据进行写时复制,得到第一文件对应的镜像文件,相比在内核空间实现待镜像的子文件的搜索与生成各个子文件的镜像文件的功能,降低开发难度与维护成本。
在一些实施例中,第一预设存储区位于用户空间,基于写时复制机制将镜像文件数据保存至打包文件,包括:在内核空间对镜像文件数据进行写时复制,将镜像文件数据保存至打包文件。
采用上述技术方案,通过将体积较小的镜像文件元数据写入至打包文件,对于体积较大的镜像文件数据,利用写时复制机制将镜像文件数据保存至打包文件,由于对镜像文件数据采用写时复制方式保存至打包文件,不涉及对镜像文件数据的拷贝、写入操作,此过程无需从存储器件读取镜像文件数据或者将镜像文件数据写入至存储器件,文件快照形成时间短,对***性能影响小,开发维护成本低。
在一些实施例中,将第一预设存储区保存的镜像文件元数据写入至打包文件,及基于写时复制机制将镜像文件数据保存至打包文件,包括:新建第二空白文件,将第一预设存储区保存的镜像文件元数据写入至第二空白文件;对所述镜像文件数据进行写时复制,将镜像文件数据保存至写入有镜像文件元数据的第二空白文件,得到打包文件。
采用上述技术方案,通过构建空白文件,将镜像文件元数据写入至空白文件,对镜像文件数据进行写时复制,以将镜像文件数据保存至写入有镜像文件元数据的空白文件,保存有镜像文件元数据与镜像文件元数据的空白文件作为与第一文件对应的打包文件,镜像文件与打包文件具有相同的元数据与数据,镜像文件的索引结构与打包文件的索引结构指向相同的物理块,共享物理块中存储的数据。
在一些实施例中,第一文件为第一应用的所有文件,生成与第一文件对应的镜像文件之后,还包括:输出与第一应用关联的提示信息,提示信息用于提示可对第一应用进行操作。
采用上述技术方案,当得到第一应用对应的镜像文件之后,基于第一应用的镜
像文件来生成与第一应用对应的打包文件,可以使得用户在第一文件对应的镜像文件生成之后可以正常使用第一应用,例如可以输出提示信息,以提醒用户可以正常使用第一应用,不会导致现有打包文件生成方案存在的问题:在打包文件生成之前,若用户使用第一应用将导致打包文件同时包含新、旧状态的文件,即不像现有打包文件生成方案需在生成打包文件之前一直禁止用户使用第一应用,可以提升用户使用体验。
在一些实施例中,第一文件为第一应用的所有文件,生成与第一文件对应的镜像文件之前,还包括:创建与第一应用的根目录对应的镜像根目录,镜像根目录用于保存镜像文件。
采用上述技术方案,对第一应用进行快照过程中,可以获取第一应用的根目录的信息,创建与第一应用的根目录对应的镜像根目录,镜像根目录可用于保存第一应用的镜像文件,便于后续可以基于镜像根目录下的目录与文件生成打包文件。
在一些实施例中,镜像根目录与第一应用的根目录相同,或者镜像根目录为第一应用的根目录的子集。
采用上述技术方案,第一应用的根目录与第一应用的镜像根目录可以是相同的,即第一应用的根目录与第一应用的镜像根目录下的目录与文件均相同,第一应用的镜像根目录也可以是第一应用的根目录的子集,即第一应用的镜像根目录具有第一应用的根目录的部分目录与文件。
第二方面,本申请实施例提供一种计算机可读存储介质,包括计算机指令,当计算机指令在电子设备上运行时,使得电子设备执行如第一方面所述的快照方法。
第三方面,本申请实施例提供一种电子设备,电子设备包括处理器和存储器,存储器用于存储指令,处理器用于调用存储器中的指令,使得电子设备执行如第一方面所述的快照方法。
第四方面,本申请实施例提供一种计算机程序产品,当计算机程序产品在电子设备(如计算机)上运行时,使得电子设备执行如第一方面所述的快照方法。
第五方面,提供一种装置,所述装置具有实现上述第一方面所提供的方法中电子设备行为的功能。功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。硬件或软件包括一个或多个与上述功能相对应的模块。
可以理解地,上述提供的第二方面所述的计算机可读存储介质,第三方面所述的电子设备,第四方面所述的计算机程序产品,第五方面所述的装置均与上述第一方面的方法对应,因此,其所能达到的有益效果可参考上文所提供的对应的方法中的有益效果,此处不再赘述。
图1为现有的电子设备实现应用快照的架构示意图;
图2为本申请一实施例提供的一种电子设备的结构示意图;
图3为本申请一实施例提供的一种电子设备的软件结构示意图;
图4为本申请一实施例提供的快照方法的应用场景示意图;
图5为本申请一实施例提供的电子设备实现应用快照的架构示意图;
图6a为本申请一实施例提供的第一APP的根目录结构示意图;
图6b为本申请一实施例提供的第一APP的镜像根目录结构示意图;
图7为本申请另一实施例提供的电子设备实现应用快照的架构示意图;
图8为本申请一实施例提供的第一APP的原始文件、镜像文件及打包文件共享物理块存储的文件数据的示意图;
图9为本申请一实施例提供的快照方法的流程示意图;
图10为本申请一实施例提供的快照装置的功能模块示意图。
需要说明的是,本申请中“至少一个”是指一个或者多个,“多个”是指两个或多于两个。“和/或”,描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B可以表示:单独存在A,同时存在A和B,单独存在B的情况,其中A,B可以是单数或者复数。本申请的说明书和权利要求书及附图中的术语“第一”、“第二”、“第三”、“第四”等(如果存在)是用于区别类似的对象,而不是用于描述特定的顺序或先后次序。
在本申请实施例中,“示例性的”或者“例如”等词用于表示作例子、例证或说明。本申请实施例中被描述为“示例性的”或者“例如”的任何实施例或设计方案不应被解释为比其它实施例或设计方案更优选或更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概念。
操作***(Operation System,OS):管理计算机硬件与软件资源的计算机程序。
内核:建立了计算机软件与硬件之间通讯的平台,内核提供***服务,比如文件管理、虚拟内存、设备输入/输出(Input/Output,I/O)等。
用户空间:也称用户态,上层应用程序的活动空间,应用程序的执行需依托于内核提供的资源,例如CPU资源、存储资源、I/O资源等。
内核空间:也称内核态,用于控制计算机的硬件资源,并提供上层应用程序运行的环境。
快照:是某个数据集在某一特定时刻的镜像,也称为即时拷贝,它是这个数据集的一个完整可用的副本。
写时复制(copy on write,COW):也可称写时拷贝,是计算机程序设计领域中的一种优化策略,其核心思想是:如果有多个调用者同时要求相同的资源,它们会共同获取相同的指针指向相同的资源,直到某个调用者视图修改资源内容时,***才会真正复制一份专用副本给该调用者,而其他调用者所见到的最初的资源仍然保持不变。这过程对其他的调用者都是透明的。此做法主要的优点是如果调用者没有修改资源,就不会有副本被创建,因此多个调用者只是读取操作时可以共享同一份资源。
文件***:是一种存储和组织计算机数据的方法,它使得对计算机数据的访问和查找变得容易,文件***使用文件和树形目录的抽象逻辑概念代替了硬盘和光盘等物理设备使用数据块的概念,用户使用文件***来保存数据,不必关心数据实际保存在硬盘(或者光盘)的地址为多少的数据块上,只需要记住这个文件的所属目录和文件名。在写入新数据之前,用户不必关心硬盘上的那个块地址没有被使用,硬盘上的存储空间管理(分配和释放等)功能由文件***自动完成,用户只需要记住数据被写入到了哪个文件中。
现有技术中,对文件进行快照包括文件的元数据进行快照及对文件的数据进行快照。文件的元数据为用于描述文件的数据,文件的元数据可以包括文件名、文件最近修改时间等信息。对文件的元数据进行快照时,可以遵循预设打包标准格式(例如可移植操作***接口(portable operating system interface of unix,POSIX)格式)重新组织元数据的物理结构,并将标准化后的元数据写入到打包文件。对文件的数据进行快照时,将文件的数据写入打包文件。打包文件可以是指将多个文件或目录保存在一个总的文件,该总的文件称为打包文件。当对文件的元数据或者数据进行快照时,从内核空间读取文件的元数据或者数据会涉及一次从内核空间到用户空间的拷贝,而从用户空间将文件的元数据或者数据写入打包文件又会涉及一次用户空间到内核空间的拷贝,即对文件的元数据或者数据进行快照均涉及两次内核空间和用户空间之间的数据拷贝,内核空间和用户空间之间的数据拷贝需要将磁盘上文件先拷贝到页缓存(page cache),再将页缓存中的文件拷贝到用户的缓存(buffer),用户空间和内
核空间之间的数据拷贝则相反,两次内核空间和用户空间之间的数据拷贝花费较长时间,导致文件的快照形成时间过长,且数据拷贝占用的***资源较大,对***性能影响大,影响用户的使用体验。若开发一种仅在内核空间实现对文件进行快照的方案,例如通过将原始文件页缓存中的数据拷贝到新文件的页缓存中,或者先将原始文件页缓存中的数据拷贝到临时开辟的缓存,再保存到新文件的页缓存中,上述方案虽然可以避免在对文件的元数据或者数据进行快照涉及内核空间和用户空间之间的数据拷贝的问题,但在纯内核空间实现的文件快照方案,内核开发需要较高的技术积累,开发难度大、调试困难,且内核开发无法使用较高级的编程语言,使用C语言或者汇编语言进行内核开发,开发维护成本又过高。
考虑到文件的元数据的体积在大多数情况下远远小于文件的数据的体积。例如,文件的元数据的体积可能为几K至十几K字节,文件的数据的体积可能为上百M至几个G字节。因此,文件的数据和元数据在内核空间和用户空间之间拷贝所产生的性能开销,主要是由文件的数据在内核空间和用户空间之间拷贝产生的。文件的元数据在内核空间和用户空间之间拷贝产生的性能开销通常很小。
基于此,本申请实施例提供一种快照方法,对于体积较小的文件元数据写入打包文件的方式为从内核空间读取文件的元数据保存至用户空间的元数据暂存区,再将元数据暂存区保存的文件的元数据写入至打包文件,对于体积较大的文件数据写入打包文件的方式为在内核空间通过对文件的数据进行写时复制,将写时复制副本保存至打包文件。由于对文件的数据采用写时复制方式保存至打包文件,不涉及对文件的数据的拷贝、写入操作,此过程无需从存储器件读取文件的数据或者将文件的数据写入至存储器件,文件快照形成时间短,对***性能影响小,且开发维护成本低。
本申请实施例提供的快照方法,可应用于电子设备中。本申请的电子设备可以包括但不限于手机、可折叠电子设备、平板电脑、个人电脑(personal computer,PC)、膝上型计算机、手持计算机、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本、蜂窝电话、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)设备、虚拟现实(virtual reality,VR)设备、人工智能(artificial intelligence,AI)设备、可穿戴式设备、智能家居设备、车机设备、及智慧城市设备中的至少一种,本申请实施例对电子设备的具体类型不作特殊限制。
在一些实施例中,电子设备还可以通过通信网络与其他电子设备或服务器进行通信。通信网络可以是有线网络,也可以是无线网络。例如,通信网络可以是局域网(local area networks,LAN),也可以是广域网(wide area networks,WAN),例如互联网。当该通信网络为局域网时,示例性的,该通信网络可以是无线保真(wireless fidelity,Wi-Fi)热点网络、Wi-Fi P2P网络、蓝牙网络、zigbee网络或近场通信(near field communication,NFC)网络等近距离通信网络。当该通信网络为广域网时,示例性的,该通信网络可以是第三代移动通信技术(3rd-generation wireless telephone technology,3G)网络、***移动通信技术(the 4th generation mobile communication technology,4G)网络、第五代移动通信技术(5th-generation mobile communication technology,5G)网络、未来演进的公共陆地移动网络(public land mobile network,PLMN)或因特网等。
在一些实施例中,电子设备可以安装一个或多个APP(Application)。APP可以简称应用,为能够实现某项或多项特定功能的软件程序。例如,即时通讯类应用、视频类应用、音频类应用、图像拍摄类应用、云桌面类应用等等。其中,即时通信类应用,例如可以包括图像拍摄类应用,例如可以包括相机应用(***相机或第三方相机应用)。视频类应用,例如可以包括华为视频、音频类应用,例如可以包括华为音乐、以下实施例中提到的应用,可以是电子设备出厂时已安装的***应用,也可以是用户在使用电子设备的过程中
从网络下载或从其他电子设备获取的第三方应用。
电子设备包括但不限于搭载Windows
或其他操作***。
图2示意了一种电子设备10的结构示意图。
电子设备10可以包括处理器110,外部存储器接口120,内部存储器121,天线1,天线2,移动通信模块130,无线通信模块140,音频模块150,传感器模块160,摄像模块170,显示屏180等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备10的具体限定。在本申请另一些实施例中,电子设备10可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
处理器110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器110中的存储器可以为高速缓冲存储器。所述存储器可以保存处理器110用过或使用频率较高的指令或数据。如果处理器110需要使用所述指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器110的等待时间,因而提高了***的效率。
在一些实施例中,处理器110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。处理器110可以通过以上至少一种接口连接音频模块、无线通信模块、显示器、摄像头等模块。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备10的结构限定。在本申请另一些实施例中,电子设备10也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
电子设备10的无线通信功能可以通过天线1,天线2,移动通信模块130,无线通信模块140,调制解调处理器以及基带处理器等实现。
移动通信模块130可以提供应用在电子设备10上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块130可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。在一些实施例中,移动通信模块130的至少部分功能模块可以被设置于处理器110中。在一些实施例中,移动通信模块130的至少部分功能模块可以与处理器110的至少部分模块被设置在同一个器件中。
无线通信模块140可以提供应用在电子设备10上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),蓝牙低功耗(bluetooth low energy,BLE),超宽带(ultra wide band,UWB),全球导航卫星***(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块140可以是集
成至少一个通信处理模块的一个或多个器件。
在一些实施例中,电子设备10可以通过无线通信技术与网络和其他电子设备通信。所述无线通信技术可以包括全球移动通讯***(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位***(global positioning system,GPS),全球导航卫星***(global navigation satellite system,GLONASS),北斗卫星导航***(beidou navigation satellite system,BDS),准天顶卫星***(quasi-zenith satellite system,QZSS)和/或星基增强***(satellite based augmentation systems,SBAS)。
电子设备10可以通过GPU,显示屏180,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏180和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
摄像模块170包括摄像头。显示屏180用于显示图像,视频等。显示屏180包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备10可以包括1个或多个显示屏180。
外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备10的存储能力。外部存储卡通过外部存储器接口120与处理器110通信,实现数据存储功能。
内部存储器121可以用于存储计算机可执行程序代码,所述可执行程序代码包括指令。内部存储器121可以包括存储程序区和存储数据区。其中,存储程序区可存储操作***,至少一个功能所需的应用程序(比如声音播放功能,图像播放功能等)等。存储数据区可存储电子设备10使用过程中所创建的数据等。此外,内部存储器121可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件,闪存器件,通用闪存存储器(universal flash storage,UFS)等。处理器110通过运行存储在内部存储器121的指令,和/或存储在设置于处理器中的存储器的指令,执行电子设备10的各种功能方法或数据处理。
音频模块150用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块150还可以用于对音频信号编码和解码。在一些实施例中,音频模块150可以设置于处理器110中,或将音频模块150的部分功能模块设置于处理器110中。
电子设备10的软件***可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。本申请实施例以分层架构的Android***为例,示例性说明电子设备10的软件结构。
图3是本申请一实施例的电子设备10的软件结构框图。
分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将Android***分为五层,从上至下分别为应用程序层,应用程序框架层,安卓运行时(Android runtime,ART)和原生C/C++库,硬件抽象层(Hardware Abstract Layer,HAL)以及内核层。
应用程序层可以包括一系列应用程序包。
如图3所示,应用程序包可以包括相机,图库,日历,通话,地图,导航,WLAN,蓝牙,音乐,视频,短信息等应用程序。
应用程序框架层为应用程序层的应用程序提供应用编程接口(application programming interface,API)和编程框架。应用程序框架层包括一些预先定义的函数。
如图3所示,应用程序框架层可以包括窗口管理器,内容提供器,视图***,资源管理器,通知管理器,活动管理器,输入管理器等。
窗口管理器提供窗口管理服务(Window Manager Service,WMS),WMS可以用于窗口管理、窗口动画管理、surface管理以及作为输入***的中转站。
内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。所述数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。
视图***包括可视控件,例如显示文字的控件,显示图片的控件等。视图***可用于构建应用程序。显示界面可以由一个或多个视图组成的。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。
资源管理器为应用程序提供各种资源,比如本地化字符串,图标,图片,布局文件,视频文件等等。
通知管理器使应用程序可以在状态栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后自动消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在***顶部状态栏的通知,例如后台运行的应用程序的通知,还可以是以对话窗口形式出现在屏幕上的通知。例如在状态栏提示文本信息,发出提示音,电子设备振动,指示灯闪烁等。
活动管理器可以提供活动管理服务(Activity Manager Service,AMS),AMS可以用于***组件(例如活动、服务、内容提供者、广播接收器)的启动、切换、调度以及应用进程的管理和调度工作。
输入管理器可以提供输入管理服务(Input Manager Service,IMS),IMS可以用于管理***的输入,例如触摸屏输入、按键输入、传感器输入等。IMS从输入设备节点取出事件,通过和WMS的交互,将事件分配至合适的窗口。
安卓运行时包括核心库和安卓运行时。安卓运行时负责将源代码转换为机器码。安卓运行时主要包括采用提前(ahead or time,AOT)编译技术和及时(just in time,JIT)编译技术。
核心库主要用于提供基本的Java类库的功能,例如基础数据结构、数学、IO、工具、数据库、网络等库。核心库为用户进行安卓应用开发提供了API。
原生C/C++库可以包括多个功能模块。例如:表面管理器(surface manager),媒体框架(Media Framework),libc,OpenGL ES、SQLite、Webkit等。
其中,表面管理器用于对显示子***进行管理,并且为多个应用程序提供了2D和3D图层的融合。媒体框架支持多种常用的音频,视频格式回放和录制,以及静态图像文件等。媒体库可以支持多种音视频编码格式,例如:MPEG4,H.264,MP3,AAC,AMR,JPG,PNG等。OpenGL ES提供应用程序中2D图形和3D图形的绘制和操作。SQLite为电子设备10的应用程序提供轻量级关系型数据库。
硬件抽象层运行于用户空间(user space),对内核层驱动进行封装,向上层提供调用接口。
内核层是硬件和软件之间的层。内核层至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动。
下面结合图4,示例性的介绍本申请实施例提供的快照方法的应用场景图。
为便于描述,如图4所示,电子设备10以手机为例进行说明。在该实施例中,电子设备10可以安装有一个或多个APP,用户点击某个APP后,电子设备10可以
创建相应的应用进程,应用进程可以实现对应APP的各项功能。
对于电子设备10安装的APP而言,电子设备10建立有用于保存APP文件的根目录。例如,电子设备10安装有华为视频APP,电子设备10建立有用于保存华为视频APP文件的根目录RT1。对华为视频APP文件进行快照可以是指对根目录RT1下的文件数据与文件元数据进行快照。通过对华为视频APP文件进行快照,可以便于后续对华为视频APP文件进行快速的数据恢复,或者将华为视频APP文件迁移到另一个电子设备上(如用户购买的新手机上)。例如,当电子设备10发生华为视频APP运行故障,或者发生华为视频APP文件损坏时,可以基于先前建立的快照快速进行APP文件恢复,实现将华为视频APP恢复到先前进行快照的时间点的状态。又例如,用户具有两个电子设备10(为了便于区分,以下称为第一电子设备与第二电子设备),第一电子设备安装有华为视频APP,第二电子设备未安装有华为视频APP,第一电子设备与第二电子设备建立通信连接,例如第一电子设备与第二电子设备可以通过蓝牙或者无线局域网建立通信连接,通信连接成功之后,可以在第一电子设备上选择需要迁移的数据,例如选中“华为视频APP”,再点击“开始迁移”图标,进而可以实现将华为视频APP文件迁移到第二电子设备上。
如图5所示,为本申请的电子设备实现数据快照的架构示意图。
该实施例中以电子设备10安装的操作***为基于Linux内核开发的***为例进行说明。电子设备10可以安装有多个APP,电子设备10安装的APP可以是指电子设备10出厂时已安装的APP,也可以是用户在使用电子设备10的过程中从网络下载或其他电子设备获取的第三方APP。以下以电子设备10安装有第一APP A1,并对第一APP A1的文件进行快照为例进行说明,对第一APP A1的文件进行快照包括对第一APP A1的文件元数据进行快照及对第一APP A1的文件数据进行快照。第一APP A1可以是即时通讯类应用、视频类应用、音频类应用、图像拍摄类应用、云桌面类应用等,本申请对第一APP A1的类型不作限定。
电子设备10建立有用于保存第一APP A1的文件的根目录d_0,电子设备10对第一APP A1的文件进行快照可以是指对根目录d_0下的每个文件进行快照。电子设备10在接收到针对第一APP A1的快照请求时,可以创建根目录d_0的镜像根目录,以下将根目录d_0的镜像根目录称为根目录d_0’,根目录d_0’用于保存第一APP A1的镜像文件。假设根目录d_0的目录结构如图6a所示,创建的根目录d_0’如图6b所示。对于根目录d_0与根目录d_0’而言,若根目录d_0中存在文件f11,文件f11的保存路径为“d_0/d1/d11/f11”,则根目录d_0’亦存在文件f11,根目录d_0’中的文件f11为根目录d_0中的文件f11的镜像文件,根目录d_0’中的文件f11的保存路径为“d_0’/d1/d11/f11”,根目录d_0’中的子目录d1为根目录d_0中的子目录d1的镜像目录,根目录d_0’中的子目录d11为根目录d_0中的子目录d11的镜像目录。
在一些实施例中,对某个根目录创建镜像根目录,镜像根目录用于保存镜像文件,根目录及其镜像根目录可以是相同的(即根目录及其镜像根目录下的目录与文件均相同),或者是镜像根目录是根目录的子集(即镜像根目录具有其根目录的部分目录与文件)。对某个文件创建镜像文件可以是指:新建一个空白文件,将文件的元数据保存至空白文件,文件的元数据可以包括文件名、文件修改时间等,再调用预设克隆接口将文件的数据写时复制至上述保存有文件的元数据的空白文件,从而形成镜像文件,本申请的镜像文件也可以称为克隆文件。
在一些实施例中,电子设备10可以运行有快照程序,快照程序可以响应针对第一APP A1的快照请求,对根目录d_0下的每个文件的数据与元数据进行快照,以将根目录d_0下的每个文件的数据与元数据写入至打包文件PF。例如,第一APP A1包括n个文件f11、f12、…、f1n(n为大于1的正整数),快照程序将第一APP A1的文件f11~f1n的数据与元数据添加至打包文件PF,可以包括如下实现过程。
51、快照程序从文件***中读取文件f11~f1n的元数据,及将文件f11~f1n的元
数据从内核空间保存到用户空间的第一元数据暂存区AR1。
在一些实施例中,文件f11的元数据可以是指用于描述文件f11的数据,文件f1n的元数据可以是指用于描述文件f1n的数据。例如,文件f11的元数据可以包括文件f11的文件名、文件最近修改时间、文件扩展属性等。用户空间的第一元数据暂存区AR1可以是指用户空间中被用作缓冲区(Buffer)的内存物理页。快照程序实现将文件f11~f1n的元数据从内核空间保存到用户空间的第一元数据暂存区AR1具体可以包括:a1、快照程序从磁盘上拷贝文件f11~f1n的元数据到内核空间的页缓存(Page Cache),例如快照程序依次从磁盘上拷贝文件f11~f1n的元数据到内核空间的页缓存,页缓存为内存物理页,或者快照程序通过并行方式从磁盘上拷贝文件f11~f1n的元数据到内核空间的页缓存;a2、快照程序将文件f11~f1n的元数据从页缓存拷贝到用户空间的第一元数据暂存区AR1,例如快照程序依次将文件f11~f1n的元数据从页缓存拷贝到用户空间的第一元数据暂存区AR1,或者快照程序通过并行方式将文件f11~f1n的元数据从页缓存拷贝到用户空间的第一元数据暂存区AR1。
52、快照程序在内核空间对文件f11~f1n的数据进行写时复制,以将文件f11~f1n的数据保存至克隆文件集CF。
在一些实施例中,通过在内核空间对文件f11~f1n的数据进行写时复制,可以实现将文件f11~f1n的数据保存至克隆文件集CF。当第一元数据暂存区AR1保存的文件f11~f1n的元数据被写入至克隆文件集CF之后,即克隆文件集CF具有文件f11~f1n相同的数据与元数据,克隆文件集CF包括与文件f11~f1n对应的镜像文件f11’~f1n’,镜像文件f11’具有与文件f11相同的数据与元数据,镜像文件f1n’具有与文件f1n相同的数据与元数据。镜像文件f11’共享文件f11的数据,镜像文件f1n’共享文件f1n的数据。镜像文件f11’共享文件f11的数据可以是指镜像文件f11’的索引结构与文件f11的索引结构指向相同的物理块,共享物理块中存储的数据。
在一些实施例中,快照程序每次可以对一个文件进行写时复制,实现将该文件的数据保存至克隆文件集CF,直至将所有文件f11~f1n的数据保存至克隆文件集CF。在本申请的实施例中,通过写时复制的方式将文件f11~f1n的数据保存至克隆文件集CF并不涉及在磁盘上对文件f11~f1n的数据进行读/写操作,***开销小,即此过程无需从存储器件读取文件的数据或者写入文件的数据至存储器件,CPU亦无需执行文件的数据的拷贝操作,对***性能影响小,耗时短,CPU与存储器件在写时复制时的功耗较低。
53、快照程序将第一元数据暂存区AR1保存的文件f11~f1n的元数据写入至克隆文件集CF。
在一些实施例中,通过将第一元数据暂存区AR1保存的文件f11~f1n的元数据写入至克隆文件集CF,使得克隆文件集CF既与文件f11~f1n具有相同的数据,又与文件f11~f1n具有相同的元数据,进而克隆文件集CF可以用作第一APP A1的文件副本。
在一些实施例中,当得到克隆文件集CF之后,基于克隆文件集CF来生成与第一APP A1对应的打包文件PF,可以使得用户在克隆文件集CF生成之后可以正常使用第一APP A1,不会导致现有打包文件生成方案存在的问题:在打包文件生成之前,若用户使用第一APP A1将导致打包文件同时包含新、旧状态的文件,即不像现有打包文件生成方案需在生成打包文件PF之前一直禁止用户使用第一APP A1,可以提升用户使用体验。
在一些实施例中,电子设备10可以在生成克隆文件集CF之后,输出一提示信息,以提醒用户可以正常使用第一APP A1。
在一些实施例中,快照程序可以通过将文件f11~f1n的元数据从用户空间的第一元数据暂存区AR1拷贝到内核空间的页缓存,来实现将第一元数据暂存区AR1保
存的文件f11~f1n的元数据写入至克隆文件集CF。
54、快照程序从克隆文件集CF中读取镜像文件f11’~f1n’的元数据,及对镜像文件f11’~f1n’的元数据进行预处理并保存到用户空间的第二元数据暂存区AR2。
在一些实施例中,文件f11~f1n的元数据与数据的物理结构,或者镜像文件f11’~f1n’的元数据与数据的物理结构由文件***进行设定,一般不会依照元数据与数据的关联关系进行排序。对镜像文件f11’~f1n’的元数据进行预处理可以是指遵循预设打包标准格式重新组织镜像文件f11’~f1n’的元数据的物理结构,并将处理后的元数据从内核空间写入到位于用户空间的第二元数据暂存区AR2,使得后续打包文件PF中的元数据与数据可以具有如下的物理结构:[文件1元数据][文件1数据][文件2元数据][文件2数据]…[文件N元数据][文件N数据],即依照元数据与数据的关联关系进行排序。例如,可以基于POSIX格式对镜像文件f11’~f1n’的元数据进行处理,处理后的元数据写入到第二元数据暂存区AR2。
在一些实施例中,第一元数据暂存区AR1与第二元数据暂存区AR2也可以是指同一个元数据暂存区,也可以是不同的元数据暂存区,本申请对此不作限定。
55、快照程序将第二元数据暂存区AR2保存的镜像文件f11’~f1n’的元数据写入至打包文件PF。
在一些实施例中,打包文件PF的读写代码逻辑运行在内核空间,快照程序可以通过将镜像文件f11’~f1n’的元数据从用户空间的第二元数据暂存区AR2拷贝到内核空间的页缓存,来实现将第二元数据暂存区AR2保存的镜像文件f11’~f1n’的元数据写入至打包文件PF。
56、快照程序对克隆文件集CF中的镜像文件f11’~f1n’的数据进行写时复制,以将镜像文件f11’~f1n’的数据保存至打包文件PF。
在一些实施例中,通过在内核空间对克隆文件集CF中的镜像文件f11’~f1n’的数据进行写时复制,实现将镜像文件f11’~f1n’的数据保存至打包文件PF,即打包文件PF与克隆文件集CF均共享文件f11~f1n的数据,对镜像文件f11’~f1n’的数据进行写时复制保存至打包文件PF,并不涉及在磁盘上对文件数据进行读/写操作,***开销小,速度快。例如,快照程序每次可以对一个镜像文件的数据进行写时复制,生成每个镜像文件的数据对应的COW副本,直至将所有镜像文件f11’~f1n’的数据的COW副本保存至打包文件PF。
通过将镜像文件f11’~f1n’的元数据写入至打包文件PF及将镜像文件f11’~f1n’的数据保存至打包文件PF,即可实现将根目录d_0’下的文件的元数据与数据写入至打包文件PF,使得打包文件PF具有与根目录d_0相同的文件元数据与文件数据,使得打包文件PF可以用作第一APP A1的快照文件。
在一些实施例中,生成打包文件PF之后,还可以对打包文件PF进行压缩,以节省打包文件PF所占用的存储空间,且可提升打包文件PF的迁移效率。
在一些实施例中,快照程序也可以在内核空间完成将文件f11~f1n的元数据写入至打包文件PF,例如通过在内核空间设置元数据暂存区,使得快照程序可以从文件***中读取文件f11~f1n的元数据暂存至内核空间的元数据暂存区,及将内核空间的元数据暂存区保存的文件f11~f1n的元数据写入至克隆文件集CF,快照程序还可以从克隆文件集CF中读取镜像文件f11’~f1n’的元数据暂存至内核空间的元数据暂存区,及将内核空间的元数据暂存区保存的镜像文件f11’~f1n’的元数据写入至打包文件PF。
图7为本申请的电子设备实现数据快照的架构示意图。
该实施例中以电子设备10安装的操作***为基于Linux内核开发的***为例进行说明。电子设备10可以安装有多个APP,电子设备10安装的APP可以是指电子设备10出厂时已安装的APP,也可以是用户在使用电子设备10的过程中从网络下载或其他电子设备获取的第三方APP。以下以电子设备10安装有第一APP A1,并
对第一APP A1的文件进行快照为例进行说明,对第一APP A1的文件进行快照包括对第一APP A1的文件元数据进行快照及对第一APP A1的文件数据进行快照。第一APP A1可以是即时通讯类应用、视频类应用、音频类应用、图像拍摄类应用、云桌面类应用等,本申请对第一APP A1的类型不作限定。
在一些实施例中,电子设备10可以运行有快照程序,快照程序可以响应针对第一APP A1的快照请求,对第一APP A1的每个文件的数据与元数据进行快照,以将第一APP A1的每个文件的数据与元数据写入至打包文件PF。例如,第一APP A1包括n个文件f11、f12、…、f1n(n为大于1的正整数),快照程序将第一APP A1的文件f11~f1n的数据与元数据添加至打包文件PF,可以包括如下实现过程。
71、快照程序创建第一APP A1的镜像根目录,在用户空间搜索待镜像的文件。
假设电子设备10建立有用于保存文件f11~f1n的根目录d_1,电子设备10对第一APP A1的文件进行快照可以是指对根目录d_1下的每个文件进行快照。电子设备10在接收到针对第一APP A1的快照请求时,可以创建根目录d_1的镜像根目录,以下将根目录d_1的镜像根目录称为根目录d_1’,根目录d_1’用于保存第一APP A1的镜像文件。快照程序可以响应针对第一APP A1的快照请求,对第一APP A1的每个文件的数据与元数据进行快照,例如在用户空间搜索第一APP A1的文件,以实现对第一APP A1的每个文件进行快照,待镜像的文件可以是指第一APP A1中还未建立镜像文件的文件。
72、快照程序调用内核定制化接口对搜索到的文件的元数据进行拷贝及对文件的数据进行写时复制,以在镜像根目录下生成或更新镜像文件,得到克隆文件集CF。
可以在用户空间控制镜像根目录及镜像根目录下的镜像文件的生成,镜像根目录下的镜像文件或目录可以在内核空间生成,通过搜索待镜像的文件或者目录,及调用内核定制化接口拷贝文件的元数据及写时复制文件的数据,实现在镜像根目录生成或更新镜像文件和目录。内核定制化接口可以是指为了实现在内核空间拷贝文件的元数据与对文件的数据进行写时复制而设计的接口。相比图5设置第一元数据暂存区AR1暂存文件f11~f1n的元数据,会涉及两次内核空间和用户空间之间的元数据拷贝,在内核空间拷贝文件的元数据花费时间更短。
通过在用户空间搜索第一APP A1的文件,调用内核定制化接口对搜索到的每个文件的元数据进行拷贝及对文件的数据进行写时复制,得到克隆文件集CF,速度快,***资源开销小,克隆文件集CF包括与文件f11~f1n对应的镜像文件f11’~f1n’,镜像文件f11’具有与文件f11相同的数据与元数据,镜像文件f1n’具有与文件f1n相同的数据与元数据。镜像文件f11’共享文件f11的数据,镜像文件f1n’共享文件f1n的数据。镜像文件f11’共享文件f11的数据可以是指镜像文件f11’的索引结构与文件f11的索引结构指向相同的物理块,共享物理块中存储的数据。
73、快照程序从克隆文件集CF中读取镜像文件f11’~f1n’的元数据,及对镜像文件f11’~f1n’的元数据进行预处理并保存到用户空间的第一元数据暂存区AR1。
74、快照程序将第一元数据暂存区AR1保存的镜像文件f11’~f1n’的元数据写入至打包文件PF。
75、快照程序对克隆文件集CF中的镜像文件f11’~f1n’的数据进行写时复制,以将镜像文件f11’~f1n’的数据保存至打包文件PF。
如图8所示,假设第一APP A1包括文件f11与文件f12,克隆文件集CF包括与文件f11对应的镜像文件f11’以及与文件f12对应的镜像文件f12’,打包文件PF包括与镜像文件f11’对应的镜像文件f11”以及与镜像文件f12’对应的镜像文件f12”。
文件f11的数据索引结构I11、镜像文件f11’的数据索引结构I12以及镜像文件
f11”的数据索引结构I13指向相同的物理块P1、P2,共享物理块P1、P2中存储的文件数据。文件f12的数据索引结构I21、镜像文件f12’的数据索引结构I22以及镜像文件f12”的数据索引结构I23指向相同的物理块P3、P4,共享物理块P3、P4中存储的文件数据。
由文件f11得到镜像文件f11’的过程可以包括:新建第一空白文件,将文件f11的元数据保存至第一空白文件,对文件f11的数据进行写时复制,将文件f11的数据保存至上述保存有文件f11的元数据的第一空白文件,从而形成镜像文件f11’。将文件f11的元数据保存至第一空白文件涉及的操作可以包括从内核空间读取文件f11的元数据并保存至用户空间的元数据暂存区,再将元数据暂存区保存的文件f11的元数据拷贝到内核空间的页缓存,实现将文件f11的元数据保存至第一空白文件,文件f11元数据与镜像文件f11’元数据指向不同的物理页。对文件f11的数据进行写时复制,将文件f11的数据保存至上述保存有文件f11的元数据的第一空白文件涉及的操作可以包括对文件f11的数据进行写时复制生成,将文件f11的数据保存至上述保存有文件f11的元数据的第一空白文件,从而形成镜像文件f11’,文件f11数据与镜像文件f11’数据指向相同的物理页。基于写时复制机制将文件f11的数据保存至上述保存有文件f11的元数据的第一空白文件,并不涉及在磁盘上对文件f11的数据进行读/写操作,***开销小,即此过程无需从存储器件读取文件f11的数据或者写入文件f11的数据至存储器件,对***性能影响小,耗时短。
由镜像文件f11’得到镜像文件f11”的过程同样可以包括:新建第二空白文件,将镜像文件f11’的元数据保存至第二空白文件,镜像文件f11’元数据与镜像文件f11”元数据指向不同的物理页,对镜像文件f11’的数据进行写时复制,将镜像文件f11’的数据保存至上述保存有镜像文件f11’的元数据的第二空白文件,从而形成镜像文件f11”。镜像文件f11’数据与镜像文件f11”数据指向相同的物理页。由文件f12得到镜像文件f12’的过程可以包括:新建第三空白文件,将文件f12的元数据保存至第三空白文件,文件f12元数据与镜像文件f12’元数据指向不同的物理页,对文件f12的数据进行写时复制,将文件f12的数据保存至上述保存有文件f12的元数据的第三空白文件,从而形成镜像文件f12’。文件f12数据与镜像文件f12’数据指向相同的物理页。由镜像文件f12’得到镜像文件f12”的过程同样可以包括:新建第四空白文件,将镜像文件f12’的元数据保存至第四空白文件,镜像文件f12’元数据与镜像文件f12”元数据指向不同的物理页,对镜像文件f12’的数据进行写时复制,将镜像文件f12’的数据保存至上述保存有镜像文件f12’的元数据的第四空白文件,从而形成镜像文件f12”。镜像文件f12’数据与镜像文件f12”数据指向相同的物理页。
参照图9所示,本申请一实施例提供一种快照方法,应用于电子设备10。快照方法可以包括:
S91,响应于针对第一文件的快照请求,生成与第一文件对应的镜像文件。
第一文件可以包括第一文件数据(第一文件的数据)与第一文件元数据(第一文件的元数据),镜像文件可以包括镜像文件数据(镜像文件的数据)与镜像文件元数据(镜像文件的元数据)。
在一些实施例中,可以在用户空间设置第二预设存储区,对于体积较小的第一文件元数据写入镜像文件的方式可以为从内核空间读取第一文件元数据保存至用户空间的第二预设存储区,再将第二预设存储区保存的第一文件元数据写入至镜像文件,对于体积较大的第一文件数据写入镜像文件的方式可以为在内核空间通过对第一文件数据进行写时复制,将第一文件数据保存至镜像文件。对于体积较小的第一文件元数据通过写入方式保存至镜像文件,镜像文件元数据与第一文件元数据可以指向不同的物理页,对于体积较大的第一文件数据,利用写时复制机制将第一文件数据保存至镜像文件,镜像文件数据与第一文件数据可以指向相同的物理页。由于对第一文件数据采用写时复制方式保存至镜像文件,不涉及对第一文件数据的拷贝、写入操作,此过程
无需从存储器件读取第一文件数据或者将第一文件数据写入至存储器件,文件快照形成时间短,对***性能影响小。
对于第一文件与于第一文件的镜像文件而言,两个文件共享写时复制的页之后,两个文件共享相同的文件数据,此时对两个文件中的任意一文件的写时复制页进行写操作时,数据将会拷贝到新页,并替换原本写时复制的页。
在一些实施例中,可以通过新建第一空白文件,将第一文件元数据写入至第一空白文件,通过对第一文件数据进行写时复制,以实现将第一文件数据保存至写入有第一文件元数据的第一空白文件,保存有第一文件元数据与第一文件元数据的空白文件可以作为与第一文件对应的镜像文件,镜像文件与第一文件具有相同的元数据与数据,镜像文件的索引结构与第一文件的索引结构指向相同的物理块,共享物理块中存储的数据。
在一些实施例中,还可以通过定制化一个内核接口,内核接口用于实现在内核空间完成拷贝第一文件元数据以及对第一文件数据进行写时复制的功能,进而可以通过调用内核接口实现响应于针对第一文件的快照请求,生成与第一文件对应的镜像文件。通过调用内核接口可以实现在内核空间一次性完成对第一文件元数据进行拷贝及对第一文件数据进行写时复制,相比在用户空间设置元数据暂存区(第二预设存储区)暂存文件元数据会涉及两次内核空间和用户空间之间的元数据拷贝,通过调用内核接口在内核空间拷贝文件的元数据花费时间更短。
若第一文件包括多个子文件,可以在用户空间实现搜索待镜像的子文件,在内核空间调用内核接口对待镜像的子文件元数据进行拷贝及对待镜像的子文件数据进行写时复制,得到第一文件对应的镜像文件,相比在内核空间实现待镜像的子文件的搜索与生成各个子文件的镜像文件的功能,降低开发难度与维护成本。
S92,将镜像文件元数据写入至第一预设存储区。
在一些实施例中,第一预设存储区可以位于用户空间,可以从内核空间读取镜像文件元数据写入至位于用户空间的第一预设存储区。若第一文件包括多个子文件,与第一文件对应的镜像文件包括多个镜像子文件,可以基于预设打包标准格式重新组织多个镜像子文件元数据的物理结构,将重新组织后的多个镜像子文件元数据写入至第一预设存储区。多个镜像子文件的元数据与数据的物理结构一般由文件***进行设定,一般不会依照元数据与数据的关联关系进行排序,通过对多个镜像子文件的元数据按照预设打包标准格式重新组织各个镜像子文件的元数据的物理结构,例如预设打包标准格式为POSIX格式,并将重新组织后的元数据从内核空间写入到位于用户空间的第一预设存储区,使得后续打包文件中的元数据与数据可以依照元数据与数据的关联关系进行排序,例如使得打包文件具有如下的物理结构:[文件1元数据][文件1数据][文件2元数据][文件2数据]…[文件N元数据][文件N数据]。
S93,将第一预设存储区保存的镜像文件元数据写入至打包文件,及基于写时复制机制将镜像文件数据保存至打包文件,镜像文件元数据与打包文件元数据指向不同的物理页,镜像文件数据与打包文件数据指向相同的物理页。
对于体积较小的镜像文件元数据写入打包文件的方式可以为从第一预设存储区读取镜像文件元数据写入至打包文件,对于体积较大的镜像文件数据写入打包文件的方式可以为在内核空间通过对镜像文件数据进行写时复制,将镜像文件数据保存至打包文件。通过将体积较小的镜像文件元数据以写入方式保存至打包文件,对于体积较大的镜像文件数据,基于写时复制机制将镜像文件数据保存至打包文件,由于对镜像文件数据采用写时复制方式保存至打包文件,不涉及对镜像文件数据的拷贝、写入操作,此过程无需从存储器件读取镜像文件数据或者将镜像文件数据写入至存储器件,文件快照形成时间短,对***性能影响小,开发维护成本低。
在一些实施例中,可以通过新建第二空白文件,将第一预设存储区保存的镜像文件元数据写入至第二空白文件,对所述镜像文件数据进行写时复制,将镜像文件数据
保存至写入有镜像文件元数据的第二空白文件,保存有镜像文件元数据与镜像文件元数据的空白文件作为与第一文件对应的打包文件,镜像文件与打包文件具有相同的元数据与数据,镜像文件的索引结构与打包文件的索引结构指向相同的物理块,共享物理块中存储的数据。
在一些实施例中,以第一文件为第一应用的所有文件为例,对第一应用进行快照得到第一应用对应的镜像文件之后,基于第一应用的镜像文件来生成与第一应用对应的打包文件,可以使得用户在第一应用对应的镜像文件生成之后可以正常使用第一应用,例如可以输出提示信息,以提醒用户可以正常使用第一应用,不会导致现有打包文件生成方案存在的问题:在打包文件生成之前,若用户使用第一应用将导致打包文件同时包含新、旧状态的文件,即不像现有打包文件生成方案需在生成打包文件之前一直禁止用户使用第一应用,可以提升用户使用体验。
在一些实施例中,步骤S91得到的镜像文件可以保存在镜像根目录中,以第一文件为第一应用的所有文件为例,对第一应用进行快照过程中,可以获取第一应用的根目录的信息,创建与第一应用的根目录对应的镜像根目录,镜像根目录用于保存第一应用的镜像文件,便于后续可以基于镜像根目录下的目录与文件生成打包文件。镜像根目录可以与第一应用的根目录相同,即第一应用的根目录与第一应用的镜像根目录下的目录与文件均相同,或者镜像根目录可以为第一应用的根目录的子集,即第一应用的镜像根目录具有第一应用的根目录的部分目录与文件。
参照图10所示,本申请一实施例提供一种快照装置100,包括状态冻结模块101、第一写入模块102及第二写入模块103。本申请实施例所称的模块可以是指能够完成特定功能的一系列计算机程序指令段,也可以是计算机程序指令段与硬件配合形成的功能模块,模块的划分为一种逻辑功能划分,实际实现时可以有另外的划分方式,本申请对此不作限定。
状态冻结模块101,用于响应于针对第一文件的快照请求,生成与第一文件对应的镜像文件。
通过状态冻结模块101实现对第一文件的状态进行冻结,便于后续基于第一文件的镜像文件生成对应的打包文件,无需在生成打包文件之前一直禁止对第一文件进行读写。例如,第一文件为第一应用的所有文件,当得到第一应用对应的镜像文件之后,基于第一应用的镜像文件来生成与第一应用对应的打包文件,可以使得用户在第一文件对应的镜像文件生成之后可以正常使用第一应用,不会导致现有打包文件生成方案存在的问题:在打包文件生成之前,若用户使用第一应用将导致打包文件同时包含新、旧状态的文件,即不像现有打包文件生成方案需在生成打包文件之前一直禁止用户使用第一应用,可以提升用户使用体验。
第一写入模块102,用于将镜像文件元数据写入至第一预设存储区。
第二写入模块103,用于将所述第一预设存储区保存的镜像文件元数据写入至打包文件,及基于写时复制机制将镜像文件数据保存至打包文件。
在一些实施例中,对于体积较小的文件元数据写入打包文件的方式可以为从内核空间读取镜像文件元数据保存至用户空间的第一预设存储区,例如第一预设存储区为用户空间的元数据暂存区,再将第一预设存储区保存的镜像文件元数据写入至打包文件,此种文件元数据写入方式,镜像文件元数据与打包文件元数据指向不同的物理页,对于体积较大的文件数据写入打包文件的方式可以为在内核空间通过对镜像文件数据进行写时复制,将镜像文件数据保存至打包文件,此种文件数据写入方式,镜像文件数据与打包文件数据指向相同的物理页,由于对镜像文件数据采用写时复制方式保存至打包文件,不涉及对镜像文件数据的拷贝、写入操作,此过程无需从存储器件读取镜像文件数据或者将镜像文件数据写入至存储器件,文件快照形成时间短,对***性能影响小,开发维护成本低。
本申请实施例提供的电子设备10,内部存储器121可用于存储指令,处理器110可
用于调用内部存储器121中的指令,使得电子设备10执行上述相关方法步骤实现上述实施例中的快照方法。内部存储器121也可以存储有状态冻结模块101、元数据写入模块102及数据写入模块103,由处理器110执行,实现快照装置100的功能。
本申请实施例还提供一种计算机存储介质,所述计算机存储介质中存储有计算机指令,当所述计算机指令在电子设备10上运行时,使得电子设备10执行上述相关方法步骤实现上述实施例中的快照方法。
本申请实施例还提供了一种计算机程序产品,当所述计算机程序产品在电子设备上运行时,使得电子设备执行上述相关步骤,以实现上述实施例中的快照方法。
另外,本申请实施例还提供一种装置,这个装置具体可以是芯片,组件或模块,所述装置可包括相连的处理器和存储器;其中,存储器用于存储计算机执行指令,当装置运行时,处理器可执行存储器存储的计算机执行指令,以使芯片执行上述各方法实施例中的快照方法。
其中,本申请实施例提供的计算机存储介质、计算机程序产品或芯片均用于执行上文所提供的对应的方法,因此,其所能达到的有益效果可参考上文所提供的对应的方法中的有益效果,此处不再赘述。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。
在本申请所提供的几个实施例中,应所述理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例是示意性的,例如,所述模块或单元的划分,为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是一个物理单元或多个物理单元,即可以位于一个地方,或者也可以分布到多个不同地方。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者所述技术方案的全部或部分可以以软件产品的形式体现出来,所述软件产品存储在一个存储介质中,包括若干指令用以使得一个设备(可以是单片机,芯片等)或处理器(processor)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何在本申请揭露的技术范围内的变化或替换,都应涵盖在本申请的保护范围之内。
Claims (18)
- 一种快照方法,其特征在于,包括:响应于针对第一文件的快照请求,生成与所述第一文件对应的镜像文件;将镜像文件元数据写入至第一预设存储区;将所述第一预设存储区保存的镜像文件元数据写入至打包文件,及基于写时复制机制将镜像文件数据保存至所述打包文件,所述镜像文件元数据与打包文件元数据指向不同的物理页,所述镜像文件数据与打包文件数据指向相同的物理页。
- 如权利要求1所述的快照方法,其特征在于,所述镜像文件元数据与第一文件元数据指向不同的物理页,所述镜像文件数据与第一文件数据指向相同的物理页。
- 如权利要求2所述的快照方法,其特征在于,所述生成与所述第一文件对应的镜像文件,包括:将所述第一文件元数据写入至所述镜像文件,及基于所述写时复制机制将所述第一文件数据保存至所述镜像文件。
- 如权利要求3所述的快照方法,其特征在于,所述将所述第一文件元数据写入至所述镜像文件,及基于所述写时复制机制将所述第一文件数据保存至所述镜像文件,包括:新建第一空白文件,将所述第一文件元数据写入至所述第一空白文件;对所述第一文件数据进行写时复制,将所述第一文件数据保存至写入有所述第一文件元数据的第一空白文件,得到与所述第一文件对应的镜像文件。
- 如权利要求3所述的快照方法,其特征在于,所述将所述第一文件元数据写入至所述镜像文件,包括:将所述第一文件元数据写入至第二预设存储区;将所述第二预设存储区保存的所述第一文件元数据写入至所述镜像文件。
- 如权利要求5所述的快照方法,其特征在于,所述第二预设存储区位于用户空间,所述基于所述写时复制机制将所述第一文件数据保存至所述镜像文件,包括:在内核空间对所述第一文件数据进行写时复制,将所述第一文件数据保存至所述镜像文件。
- 如权利要求1至6中任意一项所述的快照方法,其特征在于,所述第一文件包括多个子文件,与所述第一文件对应的镜像文件包括多个镜像子文件,所述将镜像文件元数据写入至第一预设存储区,包括:基于预设打包标准格式重新组织多个镜像子文件元数据的物理结构;将重新组织后的多个镜像子文件元数据写入至所述第一预设存储区。
- 如权利要求2所述的快照方法,其特征在于,所述生成与所述第一文件对应的镜像文件,包括:调用预设内核接口对所述第一文件元数据进行拷贝及对所述第一文件数据进行写时复制,得到与所述第一文件对应的镜像文件。
- 如权利要求8所述的快照方法,其特征在于,所述调用预设内核接口对所述第一文件元数据进行拷贝及对所述第一文件数据进行写时复制,包括:调用预设内核接口在内核空间对所述第一文件元数据进行拷贝及对所述第一文件数据进行写时复制。
- 如权利要求8所述的快照方法,其特征在于,所述第一文件包括多个子文件,所述调用预设内核接口对所述第一文件元数据进行拷贝及对所述第一文件数据进行写时复制,包括:在用户空间搜索待镜像的子文件;调用预设内核接口在内核空间对待镜像的子文件元数据进行拷贝及对待镜像的子文件数据进行写时复制。
- 如权利要求1所述的快照方法,其特征在于,所述第一预设存储区位于用户空间,所述基于写时复制机制将镜像文件数据保存至所述打包文件,包括:在内核空间对所述镜像文件数据进行写时复制,将所述镜像文件数据保存至所述打包文件。
- 如权利要求1所述的快照方法,其特征在于,所述将所述第一预设存储区保存的镜像文件元数据写入至打包文件,及基于写时复制机制将镜像文件数据保存至所述打包文件,包括:新建第二空白文件,将第一预设存储区保存的镜像文件元数据写入至所述第二空白文件;对所述镜像文件数据进行写时复制,将所述镜像文件数据保存至写入有所述镜像文件元数据的第二空白文件,得到所述打包文件。
- 如权利要求1至12中任意一项所述的快照方法,其特征在于,所述第一文件为第一应用的所有文件,所述生成与所述第一文件对应的镜像文件之后,还包括:输出与所述第一应用关联的提示信息,所述提示信息用于提示可对所述第一应用进行操作。
- 如权利要求1至12中任意一项所述的快照方法,其特征在于,所述第一文件为第一应用的所有文件,所述生成与所述第一文件对应的镜像文件之前,还包括:创建与所述第一应用的根目录对应的镜像根目录,所述镜像根目录用于保存所述镜像文件。
- 如权利要求14所述的快照方法,其特征在于,所述镜像根目录与所述第一应用的根目录相同,或者所述镜像根目录为所述第一应用的根目录的子集。
- 一种计算机可读存储介质,其特征在于,包括计算机指令,当所述计算机指令在处理器上运行时,使得电子设备执行如权利要求1至权利要求15任一项所述的快照方法。
- 一种电子设备,其特征在于,所述电子设备包括处理器和存储器,所述存储器用于存储指令,所述处理器用于调用所述存储器中的指令,使得所述电子设备执行权利要求1至权利要求15中任一项所述的快照方法。
- 一种计算机程序产品,其特征在于,包括计算机指令,当所述计算机指令在处理器上运行时,使得电子设备执行如权利要求1至权利要求15中任一项所述的快照方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211236869.7 | 2022-10-10 | ||
CN202211236869.7A CN117909287A (zh) | 2022-10-10 | 2022-10-10 | 快照方法、电子设备、计算机程序产品及可读存储介质 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2024078262A1 true WO2024078262A1 (zh) | 2024-04-18 |
Family
ID=90668758
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2023/119212 WO2024078262A1 (zh) | 2022-10-10 | 2023-09-15 | 快照方法、电子设备、计算机程序产品及可读存储介质 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN117909287A (zh) |
WO (1) | WO2024078262A1 (zh) |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050138312A1 (en) * | 2003-12-19 | 2005-06-23 | Kei Kubo | Method for acquiring snapshot |
CN104486392A (zh) * | 2014-12-05 | 2015-04-01 | 国云科技股份有限公司 | 一种低存储空间的虚拟机镜像打包方法 |
CN105511943A (zh) * | 2015-12-03 | 2016-04-20 | 华为技术有限公司 | 一种Docker容器运行方法和装置 |
CN107291883A (zh) * | 2017-06-20 | 2017-10-24 | 郑州云海信息技术有限公司 | 一种分布式存储***的快照方法及装置 |
CN110196755A (zh) * | 2019-05-07 | 2019-09-03 | 腾讯科技(深圳)有限公司 | 一种虚拟机快照管理方法、装置、服务器及存储介质 |
CN114003569A (zh) * | 2021-10-25 | 2022-02-01 | 武汉噢易云计算股份有限公司 | 一种qcow2镜像文件增量更新方法及装置 |
-
2022
- 2022-10-10 CN CN202211236869.7A patent/CN117909287A/zh active Pending
-
2023
- 2023-09-15 WO PCT/CN2023/119212 patent/WO2024078262A1/zh unknown
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050138312A1 (en) * | 2003-12-19 | 2005-06-23 | Kei Kubo | Method for acquiring snapshot |
CN104486392A (zh) * | 2014-12-05 | 2015-04-01 | 国云科技股份有限公司 | 一种低存储空间的虚拟机镜像打包方法 |
CN105511943A (zh) * | 2015-12-03 | 2016-04-20 | 华为技术有限公司 | 一种Docker容器运行方法和装置 |
CN107291883A (zh) * | 2017-06-20 | 2017-10-24 | 郑州云海信息技术有限公司 | 一种分布式存储***的快照方法及装置 |
CN110196755A (zh) * | 2019-05-07 | 2019-09-03 | 腾讯科技(深圳)有限公司 | 一种虚拟机快照管理方法、装置、服务器及存储介质 |
CN114003569A (zh) * | 2021-10-25 | 2022-02-01 | 武汉噢易云计算股份有限公司 | 一种qcow2镜像文件增量更新方法及装置 |
Also Published As
Publication number | Publication date |
---|---|
CN117909287A (zh) | 2024-04-19 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11868785B2 (en) | Application program page processing method and device | |
US11853820B2 (en) | Cross-process communication method, apparatus, and device | |
US9619304B2 (en) | Automatic connections between application components | |
CN104603750A (zh) | 使用bpram来布局和执行软件应用 | |
WO2020155417A1 (en) | Input/output processing in a distributed storage node with rdma | |
US20150365491A1 (en) | Managing content on an electronic device | |
US11347696B2 (en) | System for transition from a hierarchical file system to an object store | |
CN104704468A (zh) | Web应用程序的跨***安装 | |
CN104583948A (zh) | 使用bpram来布局和执行操作*** | |
EP4390690A1 (en) | Notification processing method, chip, electronic device, and computer readable storage medium | |
WO2021169379A1 (zh) | 权限复用方法、基于权限复用的资源访问方法及相关设备 | |
WO2024046084A1 (zh) | 一种用户界面显示方法及相关装置 | |
CN114238808A (zh) | 页面展示方法、装置、计算机设备和存储介质 | |
JP7082701B2 (ja) | 磁気ディスクの管理方法、磁気ディスクの管理装置、電子機器、コンピュータプログラムおよびコンピュータ可読記憶媒体 | |
US10599444B2 (en) | Extensible input stack for processing input device data | |
CN116339818B (zh) | 代码变更类型的筛选方法、电子设备及可读存储介质 | |
WO2024078262A1 (zh) | 快照方法、电子设备、计算机程序产品及可读存储介质 | |
US9047021B2 (en) | Managing metadata for logical volume managers | |
CN110196683B (zh) | 一种操作控制的方法、装置、终端设备和介质 | |
US10839037B2 (en) | Connected application experience | |
US20200394230A1 (en) | Dynamically rendering very large multi-format documents | |
US20190213015A1 (en) | Extensible input stack for processing input device data | |
CN114237814A (zh) | 跨虚拟化平台的虚拟机迁移方法、装置和计算机设备 | |
CN105183491A (zh) | 跨平台的桌面gis***及其启动方法 | |
CN113495869B (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: 23876467 Country of ref document: EP Kind code of ref document: A1 |