aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-prod (mdb) <android-build-team-robot@google.com>2019-03-04 19:35:25 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-03-04 19:35:25 +0000
commita81c30038872e28c0db9dae6c65a711db903878a (patch)
tree38906c8e3b9b56917367bae8f758904aa0cc797a
parent7a25683828b26962773d71adb037f9314adc98e2 (diff)
parent83a0d77daac612ec266a4f16ea08bd31bec520bb (diff)
downloadqemu-emu-3.0-release.tar.gz
Merge "Merge cherrypicks of [917955, 917956] into emu-3.0-release" into emu-3.0-releaseemu-3.0-release
-rw-r--r--android-qemu2-glue/drive-share.cpp58
-rw-r--r--android/android-emu/android/snapshot/SnapshotAPI.cpp5
2 files changed, 47 insertions, 16 deletions
diff --git a/android-qemu2-glue/drive-share.cpp b/android-qemu2-glue/drive-share.cpp
index 61df6675f3..f58c46971b 100644
--- a/android-qemu2-glue/drive-share.cpp
+++ b/android-qemu2-glue/drive-share.cpp
@@ -210,6 +210,10 @@ static bool parseQemuOptForQcow2(bool wipeData) {
// We are not using qcow2
continue;
}
+ if (!android::base::PathUtils::isAbsolute(qcow2_image_path)) {
+ qcow2_path_buffer = path_join(avd_data_dir, qcow2_image_path);
+ sDriveShare->srcImagePaths[images[p].drive] = qcow2_path_buffer;
+ }
}
Error* img_creation_error = NULL;
@@ -232,6 +236,7 @@ static bool parseQemuOptForQcow2(bool wipeData) {
free(qcow2_path_buffer);
if (img_creation_error) {
error_report("%s", error_get_pretty(img_creation_error));
+ error_free(img_creation_error);
return false;
}
}
@@ -282,19 +287,24 @@ static bool createEmptySnapshot(BlockDriverState* bs,
static std::string initDrivePath(const char* id,
android::base::FileShare shareMode,
- QemuOpts* opts) {
+ QemuOpts* opts,
+ bool skipInitQCow2) {
assert(sDriveShare->srcImagePaths.count(id));
if (needCreateTmp(id, shareMode, opts)) {
// Create a temp qcow2-on-qcow2
Error* img_creation_error = NULL;
TempFile* img = tempfile_create_with_ext(".qcow2");
const char* imgPath = tempfile_path(img);
+ if (skipInitQCow2) {
+ return imgPath;
+ }
bdrv_img_create(imgPath, QCOW2_SUFFIX,
sDriveShare->srcImagePaths[id].c_str(), "qcow2",
nullptr, -1, 0, true, &img_creation_error);
if (img_creation_error) {
tempfile_close(img);
error_report("%s", error_get_pretty(img_creation_error));
+ error_free(img_creation_error);
return "";
}
return imgPath;
@@ -309,20 +319,27 @@ static void mirrorTmpCache(const char* dst, const char* src) {
// Thus we directly copy the qcow2 file.
// TODO (yahan@): figure out why
path_copy_file(dst, src);
- QDict *options = qdict_new();
- qdict_put(options, "driver", qstring_from_str(QCOW2_SUFFIX));
Error *local_err = NULL;
- BlockBackend *blk = blk_new_open(dst,
- NULL, options, BDRV_O_RDWR | BDRV_O_NO_BACKING,
- &local_err);
- if (!blk) {
+
+ BlockDriverState* bs = bdrv_open(
+ dst, nullptr, nullptr, BDRV_O_RDWR | BDRV_O_NO_BACKING, &local_err);
+ if (!bs) {
error_report("Could not open '%s': ", dst);
- } else {
- BlockDriverState* bs = blk_bs(blk);
- bdrv_change_backing_file(bs,
- android_hw->disk_cachePartition_path, NULL);
- blk_unref(blk);
+ error_free(local_err);
+ return;
}
+ char* absPath = nullptr;
+ char* backingFile = android_hw->disk_cachePartition_path;
+ if (!android::base::PathUtils::isAbsolute(backingFile)) {
+ absPath =
+ path_join(avdInfo_getContentPath(android_avdInfo), backingFile);
+ backingFile = absPath;
+ }
+ D("backing cache.img path: %s\n", backingFile);
+ int res = bdrv_change_backing_file(bs, backingFile, NULL);
+ D("cache changing backing file result: %d\n", res);
+ bdrv_unref(bs);
+ free(absPath);
}
// This is for C-style function pointer
@@ -331,7 +348,7 @@ static int drive_init(void* opaque, QemuOpts* opts, Error** errp) {
DriveInitParam* param = (DriveInitParam*)opaque;
const char* id = opts->id;
if (id) {
- std::string path = initDrivePath(id, param->shareMode, opts);
+ std::string path = initDrivePath(id, param->shareMode, opts, false);
qemu_opt_set(opts, "file", path.c_str(), errp);
if (needCreateTmp(id, param->shareMode, opts) && param->snapshotName) {
if (strcmp(id, "cache")) {
@@ -396,7 +413,9 @@ static int drive_reinit(void* opaque, QemuOpts* opts, Error** errp) {
aio_context_release(aioCtx);
return 1;
}
+ res = bdrv_commit(oldbs);
}
+ blk_flush(blk);
blk_remove_bs(blk);
aio_context_release(aioCtx);
if (param->shareMode == android::base::FileShare::Write) {
@@ -406,7 +425,8 @@ static int drive_reinit(void* opaque, QemuOpts* opts, Error** errp) {
D("Closing old image %s\n", oldPath);
tempfile_unref_and_close(oldPath);
}
- std::string path = initDrivePath(id, param->shareMode, opts);
+ // Don't write file contents if it is for cache
+ std::string path = initDrivePath(id, param->shareMode, opts, isCache);
if (needCreateTmp(id, param->shareMode, opts) && isCache) {
mirrorTmpCache(path.c_str(),
sDriveShare->srcImagePaths[id].c_str());
@@ -438,10 +458,15 @@ static int drive_reinit(void* opaque, QemuOpts* opts, Error** errp) {
qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_NO_FLUSH, "off");
qdict_set_default_str(bs_opts, BDRV_OPT_READ_ONLY, "off");
qdict_del(bs_opts, "id");
+ Error* local_err = NULL;
- BlockDriverState* bs = bdrv_open(path.c_str(), nullptr, bs_opts, 0, errp);
+ BlockDriverState* bs =
+ bdrv_open(path.c_str(), nullptr, bs_opts, 0, &local_err);
if (!bs) {
- error_setg(errp, "drive %s open failure", path.c_str());
+ D("drive %s open failure: %s", path.c_str(),
+ error_get_pretty(local_err));
+ error_report("%s", error_get_pretty(local_err));
+ error_free(local_err);
return 1;
}
@@ -499,6 +524,7 @@ static bool updateDriveShareMode(const char* snapshotName,
&error);
if (res) {
error_report("%s", error_get_pretty(error));
+ error_free(error);
return false;
}
return true;
diff --git a/android/android-emu/android/snapshot/SnapshotAPI.cpp b/android/android-emu/android/snapshot/SnapshotAPI.cpp
index b675cc5997..c243604083 100644
--- a/android/android-emu/android/snapshot/SnapshotAPI.cpp
+++ b/android/android-emu/android/snapshot/SnapshotAPI.cpp
@@ -179,6 +179,11 @@ void forkReadOnlyInstances(android::AsyncMessagePipeHandle pipe,
sSnapshotCrossSession->sForkTotal = forkTotal;
sSnapshotCrossSession->sForkId = 0;
+ if (forkTotal <= 1) {
+ android::offworld::sendResponse(pipe, createForkIdResponse(0));
+ return;
+ }
+
sSnapshotCrossSession->mPipesAwaitingResponse[pipe] = RequestType::Fork;
sSnapshotCrossSession->mOverrideResponse[RequestType::Fork] =
createForkIdResponse(0);