Repository navigation
feat: 复制实例(modavd clone、管理器「复制实例」) - #199
Merged
Merged
Conversation
把一台已关机的实例整份复制成新实例,带着游戏、登录状态和设置:新编号和端口, 其余配置和 mas-avd.json 里的记录照源实例(去掉新建状态、诊断、老板键)。 数据盘整份拷,目录里相对的 qcow2 链原样带过去;源目录内写成绝对路径的 backing 改成相对的,目录外的拍平成独立的一张。复制前查剩余空间,失败或取消时删掉半成品、 不留登记和锁文件。 Refs ModAVD/ModAVD#239
与批量新建、删除(ModAVDManager#197)在 internal/cli/commands.go、format.go 的冲突:两边都保留,clone 命令、runClone、formatClone 放在批量的代码旁边。 Refs ModAVD/ModAVD#239
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs ModAVD/ModAVD#239
做了什么
modavd clone <i> [--title T],管理器卡片「更多操作」里加「复制实例」(关机后可用,任务挂在源实例上,有进度,可以取消)。HTTP 是POST /api/instances/{i}/clone {title?}。config.ini整份带过去(只改avd.id、avd.name、avd.ini.displayname),mas-avd.json的instances.<i>也照抄,去掉只属于源实例的creationState/creationError/creationLog、diagnostics/diagnosticsSince和bossKey(新实例用它编号的默认老板键),createdAt写新的。snapshots(每次都是冷启动)、hardware-qemu.ini和emu-launch-params.txt(每次开机按实例自己的路径重写)、锁文件、整理磁盘留下的临时文件。数据盘
userdata-qemu.img.qcow2→userdata-qemu.img),整目录拷过去链就在新目录里。qemu-img rebase -u改成相对的;backing 在实例目录以外的(system / vendor 覆盖层除外,它们本来就叠在根目录的只读系统镜像上,由执行桥那边维护),用qemu-img convert拍平成独立的一张。带内部快照的盘拒绝。precheck_failed,什么都不写。mas-avd.json记录、.ini和新编号的锁文件。新实例的mas_<i>.ini最后写,写之前它不会被列出来。busy);新编号拿着新建锁。设备标识
复制出来的两台 Android ID(SSAID,按应用存在
/data/system/users/0/settings_ssaid.xml)和 GSF ID 都一样。重置的办法是删掉 SSAID 文件或清 GSF 数据,但游戏的登录多半绑在这些标识上,重置等于把登录状态也丢了,和这个功能要的相反,所以没做;帮助、文档和管理器完成提示里写明「两台设备标识一样,别同时登同一个账号」。adb 密钥是宿主那一份,不分实例,所以没有要换的。测试
internal/emu/clone_test.go,临时根目录 + 假 qemu-img + 假剩余空间,碰不到真根目录):整份复制和跳过的文件、配置和元数据的改写、两个 backing 分支(rebase、拍平)、内部快照拒绝、源实例在跑 / 五种锁 / 新建失败 / 标题非法拒绝、空间正好够和差 1 字节、rebase 失败和取消时回滚。命令行和管理器接口各加了用例。go test ./...、go vet ./...、CI 里的 node 测试都过。MkdirAll换掉Mkdir(两个进程抢同一个编号的竞争,单测没造)。/sdcard、/data/local/tmp的标记文件和一条settings global,正常关机;modavd clone 1 --title clone-copy复制 1.6 GB 用时 2.5 秒,得到实例 2(端口 +10);开机三处标记都在,df /data正常,三个 qcow2 的 backing 都是新目录里的相对路径,android_id和源实例相同(符合上面的说明);关机后两台都删掉。管理器的按钮没在真窗口点过,靠单测和代码。没做的