Skip to content

Commit 692b9e4

Browse files
committed
lib: Remove LiveUpdate deprecated on_resume events
1 parent 3d474d3 commit 692b9e4

2 files changed

Lines changed: 19 additions & 60 deletions

File tree

lib/LiveUpdate/liveupdate.hpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,8 @@ struct LiveUpdate
7171
static bool is_resumable();
7272
static bool is_resumable(void* location);
7373

74-
// Register a user-defined handler for what to do with @id from storage
75-
static void on_resume(uint16_t id, resume_func custom_handler);
76-
77-
// Attempt to restore existing stored entries.
78-
// Returns false if there was nothing there. or if the process failed
79-
// to be sure that only failure can return false, use is_resumable first
80-
static void resume(std::string key, resume_func default_handler);
74+
// Restore existing state for a partition named @key.
75+
static void resume(std::string key, resume_func handler);
8176

8277
// When explicitly resuming from heap, heap overrun checks are disabled
8378
static void resume_from_heap(void* location, std::string key, resume_func);
@@ -199,20 +194,15 @@ struct Restore
199194
// if the end is reached, @id is not used
200195
void pop_marker(uint16_t id);
201196

202-
// cancel and exit state restoration process
203-
// NOTE: resume() will still return true
204-
void cancel(); // pseudo: "while (!is_end()) go_next()"
205-
206197
// NOTE:
207198
// it is safe to immediately use is_end() after any call to:
208-
// go_next(), pop_marker(), pop_marker(uint16_t), cancel()
199+
// go_next(), pop_marker(), pop_marker(uint16_t)
209200

210-
Restore(storage_entry*& ptr) : ent(ptr) {}
211-
Restore(const Restore&);
201+
Restore(storage_entry* ptr) : ent(ptr) {}
212202
private:
213203
const void* get_segment(size_t, size_t&) const;
214204
std::vector<std::string> rebuild_string_vector() const;
215-
storage_entry*& ent;
205+
storage_entry* ent;
216206
};
217207

218208
/// various inline functions

lib/LiveUpdate/resume.cpp

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ extern char* heap_end;
3535
namespace liu
3636
{
3737
static void resume_begin(storage_header&, std::string, LiveUpdate::resume_func);
38-
static std::map<uint16_t, LiveUpdate::resume_func> resume_funcs;
3938

4039
bool LiveUpdate::is_resumable()
4140
{
@@ -82,40 +81,19 @@ void resume_begin(storage_header& storage, std::string key, LiveUpdate::resume_f
8281
LPRINT("* Resuming from partition %d at %p from %p\n",
8382
p, storage.begin(p), &storage);
8483

85-
/// restore each entry one by one, calling registered handlers
86-
for (auto* ptr = storage.begin(p); ptr->type != TYPE_END;)
87-
{
88-
auto* oldptr = ptr;
89-
// resume wrapper
90-
Restore wrapper {ptr};
91-
// use registered functions when we can, otherwise, use normal
92-
auto it = resume_funcs.find(ptr->id);
93-
if (it != resume_funcs.end())
94-
{
95-
it->second(wrapper);
96-
} else {
97-
func(wrapper);
98-
}
99-
// if we are already at the end due calls to go_next, break early
100-
if (ptr->type == TYPE_END) break;
101-
// call next manually only when no one called go_next
102-
if (oldptr == ptr) ptr = storage.next(ptr);
103-
}
84+
// resume wrapper
85+
Restore wrapper(storage.begin(p));
86+
// use registered functions when we can, otherwise, use normal
87+
func(wrapper);
88+
10489
// wake all the slumbering IP stacks
10590
serialized_tcp::wakeup_ip_networks();
106-
// clear registered resume callbacks
107-
resume_funcs.clear();
10891
// zero out the partition for security reasons
10992
storage.zero_partition(p);
11093
// if there are no more partitions, clear everything
11194
storage.try_zero();
11295
}
11396

114-
void LiveUpdate::on_resume(uint16_t id, resume_func func)
115-
{
116-
resume_funcs[id] = func;
117-
}
118-
11997
/// struct Restore
12098

12199
bool Restore::is_end() const noexcept
@@ -136,13 +114,13 @@ int Restore::as_int() const
136114
// this type uses the length field directly as value to save space
137115
if (ent->type == TYPE_INTEGER)
138116
return ent->len;
139-
throw std::runtime_error("Incorrect type: " + std::to_string(ent->type));
117+
throw std::runtime_error("LiveUpdate: Incorrect type " + std::to_string(ent->type));
140118
}
141119
std::string Restore::as_string() const
142120
{
143121
if (ent->type == TYPE_STRING)
144122
return std::string(ent->data(), ent->len);
145-
throw std::runtime_error("Incorrect type: " + std::to_string(ent->type));
123+
throw std::runtime_error("LiveUpdate: Incorrect type " + std::to_string(ent->type));
146124
}
147125
buffer_t Restore::as_buffer() const
148126
{
@@ -151,7 +129,7 @@ buffer_t Restore::as_buffer() const
151129
buffer.assign(ent->data(), ent->data() + ent->len);
152130
return buffer;
153131
}
154-
throw std::runtime_error("Incorrect type: " + std::to_string(ent->type));
132+
throw std::runtime_error("LiveUpdate: Incorrect type " + std::to_string(ent->type));
155133
}
156134
Restore::Connection_ptr Restore::as_tcp_connection(net::TCP& tcp) const
157135
{
@@ -177,19 +155,19 @@ const void* Restore::data() const noexcept
177155
const void* Restore::get_segment(size_t size, size_t& count) const
178156
{
179157
if (ent->type != TYPE_VECTOR)
180-
throw std::runtime_error("Incorrect type: " + std::to_string(ent->type));
158+
throw std::runtime_error("LiveUpdate: Incorrect type " + std::to_string(ent->type));
181159

182160
auto& segs = ent->get_segs();
183161
if (size != segs.esize)
184-
throw std::runtime_error("Incorrect type size: " + std::to_string(size) + " vs " + std::to_string(segs.esize));
162+
throw std::runtime_error("LiveUpdate: Incorrect type size " + std::to_string(size) + " vs " + std::to_string(segs.esize));
185163

186164
count = segs.count;
187165
return (const void*) segs.vla;
188166
}
189167
std::vector<std::string> Restore::rebuild_string_vector() const
190168
{
191169
if (ent->type != TYPE_STR_VECTOR)
192-
throw std::runtime_error("Incorrect type: " + std::to_string(ent->type));
170+
throw std::runtime_error("LiveUpdate: Incorrect type " + std::to_string(ent->type));
193171
std::vector<std::string> retv;
194172
// reserve just enough room
195173
auto* begin = (varseg_begin*) ent->vla;
@@ -210,7 +188,7 @@ std::vector<std::string> Restore::rebuild_string_vector() const
210188
void Restore::go_next()
211189
{
212190
if (is_end())
213-
throw std::runtime_error("Already reached end of storage");
191+
throw std::out_of_range("Already reached end of partition");
214192
// increase the counter, so the resume loop skips entries properly
215193
ent = ent->next();
216194
}
@@ -236,18 +214,9 @@ void Restore::pop_marker(uint16_t id)
236214
&& is_end() == false) go_next();
237215
if (is_marker()) {
238216
if (get_id() != id)
239-
throw std::runtime_error("Ran past marker with another id: " + std::to_string(get_id()));
217+
throw std::out_of_range("Ran past marker with another id: " + std::to_string(get_id()));
240218
go_next();
241219
}
242220
}
243221

244-
void Restore::cancel()
245-
{
246-
while (is_end() == false) go_next();
247-
}
248-
249-
// copy operator
250-
Restore::Restore(const Restore& other)
251-
: ent(other.ent) {}
252-
253-
}
222+
} // liu

0 commit comments

Comments
 (0)