Skip to content

Commit 2237faa

Browse files
author
Android Build Coastguard Worker
committed
Snap for 7825665 from 98e7f42 to sc-qpr1-d-release
Change-Id: Idc1bad9acca53cbbae8c02d1da45e9cd2e9effc0
2 parents b590d92 + 98e7f42 commit 2237faa

5 files changed

Lines changed: 155 additions & 18 deletions

File tree

trusty/storage/interface/include/trusty/interface/storage.h

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,30 @@ enum storage_file_open_flag {
112112

113113
/**
114114
* enum storage_msg_flag - protocol-level flags in struct storage_msg
115-
* @STORAGE_MSG_FLAG_BATCH: if set, command belongs to a batch transaction.
116-
* No response will be sent by the server until
117-
* it receives a command with this flag unset, at
118-
* which point a cummulative result for all messages
119-
* sent with STORAGE_MSG_FLAG_BATCH will be sent.
120-
* This is only supported by the non-secure disk proxy
121-
* server.
122-
* @STORAGE_MSG_FLAG_PRE_COMMIT: if set, indicates that server need to commit
123-
* pending changes before processing this message.
124-
* @STORAGE_MSG_FLAG_POST_COMMIT: if set, indicates that server need to commit
125-
* pending changes after processing this message.
126-
* @STORAGE_MSG_FLAG_TRANSACT_COMPLETE: if set, indicates that server need to commit
127-
* current transaction after processing this message.
128-
* It is an alias for STORAGE_MSG_FLAG_POST_COMMIT.
115+
* @STORAGE_MSG_FLAG_BATCH: if set, command belongs to a batch transaction.
116+
* No response will be sent by the server until
117+
* it receives a command with this flag unset, at
118+
* which point a cumulative result for all messages
119+
* sent with STORAGE_MSG_FLAG_BATCH will be sent.
120+
* This is only supported by the non-secure disk proxy
121+
* server.
122+
* @STORAGE_MSG_FLAG_PRE_COMMIT: if set, indicates that server need to commit
123+
* pending changes before processing this message.
124+
* @STORAGE_MSG_FLAG_POST_COMMIT: if set, indicates that server need to commit
125+
* pending changes after processing this message.
126+
* @STORAGE_MSG_FLAG_TRANSACT_COMPLETE: if set, indicates that server need to commit
127+
* current transaction after processing this message.
128+
* It is an alias for STORAGE_MSG_FLAG_POST_COMMIT.
129+
* @STORAGE_MSG_FLAG_PRE_COMMIT_CHECKPOINT: if set, indicates that server needs to ensure
130+
* that there is not a pending checkpoint for
131+
* userdata before processing this message.
129132
*/
130133
enum storage_msg_flag {
131-
STORAGE_MSG_FLAG_BATCH = 0x1,
132-
STORAGE_MSG_FLAG_PRE_COMMIT = 0x2,
133-
STORAGE_MSG_FLAG_POST_COMMIT = 0x4,
134-
STORAGE_MSG_FLAG_TRANSACT_COMPLETE = STORAGE_MSG_FLAG_POST_COMMIT,
134+
STORAGE_MSG_FLAG_BATCH = 0x1,
135+
STORAGE_MSG_FLAG_PRE_COMMIT = 0x2,
136+
STORAGE_MSG_FLAG_POST_COMMIT = 0x4,
137+
STORAGE_MSG_FLAG_TRANSACT_COMPLETE = STORAGE_MSG_FLAG_POST_COMMIT,
138+
STORAGE_MSG_FLAG_PRE_COMMIT_CHECKPOINT = 0x8,
135139
};
136140

137141
/*

trusty/storage/proxy/Android.bp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@ cc_binary {
2323
vendor: true,
2424

2525
srcs: [
26+
"checkpoint_handling.cpp",
2627
"ipc.c",
2728
"rpmb.c",
2829
"storage.c",
2930
"proxy.c",
3031
],
3132

3233
shared_libs: [
34+
"libbase",
3335
"liblog",
3436
"libhardware_legacy",
3537
],
3638
header_libs: ["libcutils_headers"],
3739

3840
static_libs: [
41+
"libfstab",
3942
"libtrustystorageinterface",
4043
"libtrusty",
4144
],
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (C) 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "checkpoint_handling.h"
18+
#include "log.h"
19+
20+
#include <fstab/fstab.h>
21+
#include <cstring>
22+
#include <string>
23+
24+
namespace {
25+
26+
bool checkpointingDoneForever = false;
27+
28+
} // namespace
29+
30+
int is_data_checkpoint_active(bool* active) {
31+
if (!active) {
32+
ALOGE("active out parameter is null");
33+
return 0;
34+
}
35+
36+
*active = false;
37+
38+
if (checkpointingDoneForever) {
39+
return 0;
40+
}
41+
42+
android::fs_mgr::Fstab procMounts;
43+
bool success = android::fs_mgr::ReadFstabFromFile("/proc/mounts", &procMounts);
44+
if (!success) {
45+
ALOGE("Could not parse /proc/mounts\n");
46+
/* Really bad. Tell the caller to abort the write. */
47+
return -1;
48+
}
49+
50+
android::fs_mgr::FstabEntry* dataEntry =
51+
android::fs_mgr::GetEntryForMountPoint(&procMounts, "/data");
52+
if (dataEntry == NULL) {
53+
ALOGE("/data is not mounted yet\n");
54+
return 0;
55+
}
56+
57+
/* We can't handle e.g., ext4. Nothing we can do about it for now. */
58+
if (dataEntry->fs_type != "f2fs") {
59+
ALOGW("Checkpoint status not supported for filesystem %s\n", dataEntry->fs_type.c_str());
60+
checkpointingDoneForever = true;
61+
return 0;
62+
}
63+
64+
/*
65+
* The data entry looks like "... blah,checkpoint=disable:0,blah ...".
66+
* checkpoint=disable means checkpointing is on (yes, arguably reversed).
67+
*/
68+
size_t checkpointPos = dataEntry->fs_options.find("checkpoint=disable");
69+
if (checkpointPos == std::string::npos) {
70+
/* Assumption is that once checkpointing turns off, it stays off */
71+
checkpointingDoneForever = true;
72+
} else {
73+
*active = true;
74+
}
75+
76+
return 0;
77+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <stdbool.h>
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
/**
26+
* is_data_checkpoint_active() - Check for an active, uncommitted checkpoint of
27+
* /data. If a checkpoint is active, storage should not commit any
28+
* rollback-protected writes to /data.
29+
* @active: Out parameter that will be set to the result of the check.
30+
*
31+
* Return: 0 if active was set and is valid, non-zero otherwise.
32+
*/
33+
int is_data_checkpoint_active(bool* active);
34+
35+
#ifdef __cplusplus
36+
}
37+
#endif

trusty/storage/proxy/proxy.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <cutils/android_filesystem_config.h>
2828

29+
#include "checkpoint_handling.h"
2930
#include "ipc.h"
3031
#include "log.h"
3132
#include "rpmb.h"
@@ -130,6 +131,21 @@ static int handle_req(struct storage_msg* msg, const void* req, size_t req_len)
130131
}
131132
}
132133

134+
if (msg->flags & STORAGE_MSG_FLAG_PRE_COMMIT_CHECKPOINT) {
135+
bool is_checkpoint_active = false;
136+
137+
rc = is_data_checkpoint_active(&is_checkpoint_active);
138+
if (rc != 0) {
139+
ALOGE("is_data_checkpoint_active failed in an unexpected way. Aborting.\n");
140+
msg->result = STORAGE_ERR_GENERIC;
141+
return ipc_respond(msg, NULL, 0);
142+
} else if (is_checkpoint_active) {
143+
ALOGE("Checkpoint in progress, dropping write ...\n");
144+
msg->result = STORAGE_ERR_GENERIC;
145+
return ipc_respond(msg, NULL, 0);
146+
}
147+
}
148+
133149
switch (msg->cmd) {
134150
case STORAGE_FILE_DELETE:
135151
rc = storage_file_delete(msg, req, req_len);

0 commit comments

Comments
 (0)