@@ -267,8 +267,6 @@ static void DumpUmountDebuggingInfo(bool dump_all) {
267
267
268
268
static UmountStat UmountPartitions (std::chrono::milliseconds timeout) {
269
269
Timer t;
270
- UmountStat stat = UMOUNT_STAT_TIMEOUT;
271
- int retry = 0 ;
272
270
/* data partition needs all pending writes to be completed and all emulated partitions
273
271
* umounted.If the current waiting is not good enough, give
274
272
* up and leave it to e2fsck after reboot to fix it.
@@ -280,25 +278,27 @@ static UmountStat UmountPartitions(std::chrono::milliseconds timeout) {
280
278
return UMOUNT_STAT_ERROR;
281
279
}
282
280
if (block_devices.size () == 0 ) {
283
- stat = UMOUNT_STAT_SUCCESS;
284
- break ;
281
+ return UMOUNT_STAT_SUCCESS;
285
282
}
286
- if ((timeout < t.duration ()) && retry > 0 ) { // try umount at least once
287
- stat = UMOUNT_STAT_TIMEOUT;
288
- break ;
283
+ bool unmount_done = true ;
284
+ if (emulated_devices.size () > 0 ) {
285
+ unmount_done = std::all_of (emulated_devices.begin (), emulated_devices.end (),
286
+ [](auto & entry) { return entry.Umount (); });
287
+ if (unmount_done) {
288
+ sync ();
289
+ }
289
290
}
290
- if (emulated_devices.size () > 0 &&
291
- std::all_of (emulated_devices.begin (), emulated_devices.end (),
292
- [](auto & entry) { return entry.Umount (); })) {
293
- sync ();
291
+ unmount_done = std::all_of (block_devices.begin (), block_devices.end (),
292
+ [](auto & entry) { return entry.Umount (); }) &&
293
+ unmount_done;
294
+ if (unmount_done) {
295
+ return UMOUNT_STAT_SUCCESS;
294
296
}
295
- for ( auto & entry : block_devices) {
296
- entry. Umount () ;
297
+ if ((timeout < t. duration ())) { // try umount at least once
298
+ return UMOUNT_STAT_TIMEOUT ;
297
299
}
298
- retry++;
299
300
std::this_thread::sleep_for (100ms);
300
301
}
301
- return stat;
302
302
}
303
303
304
304
static void KillAllProcesses () { android::base::WriteStringToFile (" i" , " /proc/sysrq-trigger" ); }
0 commit comments