Skip to content

Commit 069c143

Browse files
authored
Merge pull request #1461 from fwsGonzo/dev
lib: Make LiveUpdate::resume boolean
2 parents aeb92fb + dbb78e8 commit 069c143

8 files changed

Lines changed: 25 additions & 25 deletions

File tree

lib/LiveUpdate/liveupdate.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct LiveUpdate
5353
// Register a function to be called when serialization phase begins
5454
// Internally it will be stored as its own partition and can be restored using
5555
// the same @key value during the resume process
56-
static void register_serialization_callback(std::string key, storage_func);
56+
static void register_partition(std::string key, storage_func);
5757

5858
// Start a live update process, storing all user-defined data
5959
// If no storage functions are registered no state will be saved
@@ -76,7 +76,9 @@ struct LiveUpdate
7676
static bool is_resumable(void* location);
7777

7878
// Restore existing state for a partition named @key.
79-
static void resume(std::string key, resume_func handler);
79+
// Returns false if there was no such partition
80+
// Can throw lots of standard exceptions
81+
static bool resume(std::string key, resume_func handler);
8082

8183
// When explicitly resuming from heap, heap overrun checks are disabled
8284
static void resume_from_heap(void* location, std::string key, resume_func);

lib/LiveUpdate/partition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int storage_header::find_partition(const char* key)
5959
throw std::runtime_error("Invalid CRC in partition '" + std::string(key) + "'");
6060
}
6161
}
62-
throw std::out_of_range("Could not find partition named " + std::string(key));
62+
return -1;
6363
}
6464
void storage_header::finish_partition(int p)
6565
{

lib/LiveUpdate/resume.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern char* heap_end;
3434

3535
namespace liu
3636
{
37-
static void resume_begin(storage_header&, std::string, LiveUpdate::resume_func);
37+
static bool resume_begin(storage_header&, std::string, LiveUpdate::resume_func);
3838

3939
bool LiveUpdate::is_resumable()
4040
{
@@ -45,17 +45,17 @@ bool LiveUpdate::is_resumable(void* location)
4545
return ((storage_header*) location)->validate();
4646
}
4747

48-
static void resume_helper(void* location, std::string key, LiveUpdate::resume_func func)
48+
static bool resume_helper(void* location, std::string key, LiveUpdate::resume_func func)
4949
{
5050
// check if an update has occurred
5151
if (!LiveUpdate::is_resumable(location))
52-
throw std::runtime_error("Trying to resume from invalid storage area");
52+
return false;
5353

5454
LPRINT("* Restoring data...\n");
5555
// restore connections etc.
56-
resume_begin(*(storage_header*) location, key.c_str(), func);
56+
return resume_begin(*(storage_header*) location, key.c_str(), func);
5757
}
58-
void LiveUpdate::resume(std::string key, resume_func func)
58+
bool LiveUpdate::resume(std::string key, resume_func func)
5959
{
6060
void* location = OS::liveupdate_storage_area();
6161
/// memory sanity check
@@ -65,19 +65,20 @@ void LiveUpdate::resume(std::string key, resume_func func)
6565
(long int) (heap_end - (char*) location));
6666
throw std::runtime_error("LiveUpdate storage area inside heap");
6767
}
68-
resume_helper(location, std::move(key), func);
68+
return resume_helper(location, std::move(key), func);
6969
}
7070
void LiveUpdate::resume_from_heap(void* location, std::string key, LiveUpdate::resume_func func)
7171
{
7272
resume_helper(location, std::move(key), func);
7373
}
7474

75-
void resume_begin(storage_header& storage, std::string key, LiveUpdate::resume_func func)
75+
bool resume_begin(storage_header& storage, std::string key, LiveUpdate::resume_func func)
7676
{
7777
if (key.empty())
7878
throw std::length_error("LiveUpdate partition key cannot be an empty string");
7979

8080
int p = storage.find_partition(key.c_str());
81+
if (p == -1) return false;
8182
LPRINT("* Resuming from partition %d at %p from %p\n",
8283
p, storage.begin(p), &storage);
8384

@@ -92,6 +93,7 @@ void resume_begin(storage_header& storage, std::string key, LiveUpdate::resume_f
9293
storage.zero_partition(p);
9394
// if there are no more partitions, clear everything
9495
storage.try_zero();
96+
return true;
9597
}
9698

9799
/// struct Restore

lib/LiveUpdate/update.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636

3737
static const int SECT_SIZE = 512;
3838
static const int ELF_MINIMUM = 164;
39-
40-
extern "C"
41-
void solo5_exec(const char*, size_t);
39+
// hotswapping functions
40+
extern "C" void solo5_exec(const char*, size_t);
4241
static void* HOTSWAP_AREA = (void*) 0x8000;
4342
extern "C" void hotswap(const char*, int, char*, uintptr_t, void*);
4443
extern "C" char __hotswap_length;
@@ -61,7 +60,7 @@ static size_t update_store_data(void* location, const buffer_t*);
6160
// serialization callbacks
6261
static std::unordered_map<std::string, LiveUpdate::storage_func> storage_callbacks;
6362

64-
void LiveUpdate::register_serialization_callback(std::string key, storage_func callback)
63+
void LiveUpdate::register_partition(std::string key, storage_func callback)
6564
{
6665
auto it = storage_callbacks.find(key);
6766
if (it == storage_callbacks.end())
@@ -86,7 +85,7 @@ inline bool validate_header(const Class* hdr)
8685

8786
void LiveUpdate::exec(const buffer_t& blob, std::string key, storage_func func)
8887
{
89-
if (func != nullptr) register_serialization_callback(key, func);
88+
if (func != nullptr) LiveUpdate::register_partition(key, func);
9089
LiveUpdate::exec(blob);
9190
}
9291

lib/uplink/ws_uplink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace uplink {
4747
{
4848
OS::add_stdout({this, &WS_uplink::send_log});
4949

50-
liu::LiveUpdate::register_serialization_callback("uplink", {this, &WS_uplink::store});
50+
liu::LiveUpdate::register_partition("uplink", {this, &WS_uplink::store});
5151

5252
read_config();
5353
CHECK(config_.reboot, "Reboot on panic");

test/kernel/integration/LiveUpdate/service.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ void Service::start()
3131
{
3232
auto& inet = net::Super_stack::get<net::IP4>(0);
3333
setup_liveupdate_server(inet, 666, func);
34+
// signal test.py that the server is up
35+
printf("Ready to receive binary blob\n");
3436
}
3537
}

test/kernel/integration/LiveUpdate/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import socket
55

66
includeos_src = os.environ.get('INCLUDEOS_SRC',
7-
os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))).split('/test')[0])
7+
os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))).split('/test')[0])
88
sys.path.insert(0,includeos_src)
99

1010
from vmrunner import vmrunner

test/kernel/integration/LiveUpdate/test_boot.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ static void boot_resume_all(Restore& thing)
2828

2929
LiveUpdate::storage_func begin_test_boot()
3030
{
31-
try {
32-
LiveUpdate::resume("test", boot_resume_all);
33-
// if we are here,
34-
// resume() must have succeeded
31+
if (LiveUpdate::resume("test", boot_resume_all))
32+
{
3533
if (timestamps.size() >= 30)
3634
{
3735
// calculate median by sorting
3836
std::sort(timestamps.begin(), timestamps.end());
3937
auto median = timestamps[timestamps.size()/2];
4038
// show information
41-
printf("Median boot time over %lu samples: %llu micros\n",
39+
printf("Median boot time over %lu samples: %ld micros\n",
4240
timestamps.size(), median);
4341
/*
4442
for (auto& stamp : timestamps) {
@@ -53,9 +51,6 @@ LiveUpdate::storage_func begin_test_boot()
5351
LiveUpdate::exec(bloberino, "test", boot_save);
5452
}
5553
}
56-
catch (std::exception& e) {
57-
printf("Ready to receive binary blob\n");
58-
}
5954
// wait for update
6055
return boot_save;
6156
}

0 commit comments

Comments
 (0)