libsnapshot: Add support for first-to-second-stage transitions of snapuserd.
This patch introduces the fundamentals needed to support booting off dm-user. First, a method has been added to start snapuserd in first-stage init. It simply forks and execs, creates a specially named first-stage socket, then waits for requests. Next, a new method has been added to SnapshotManager to perform a second-stage handoff. This works by first launching a second copy of snapuserd using init's normal service management functionality. The new snapuserd runs alongside the original, but has correct privileges and a correct selinux context. Next, we inspect each COW device, and if its table uses dm-user, we replace the table with a renamed control device. The new control device is bound to the new snapuserd. device-mapper guarantees that such a table swap is safe. It flushes I/O to the old table and then replaces it with the new table. Once the new table is in place, the old dm-user control devices are automatically destroyed. Thus, once all dm-user devices has been transitioned, the first-stage daemon is idle and can gracefully exit. This patch does not modify init. A few changes will be needed on top of this patch: (1) CreateLogicalAndSnapshotPartitions will need further changes to start the first-stage daemon and track its pid. Additionally, it will need to ensure the named socket file is deleted, so there is no further IPC allowed after partitions are completed. (2) init will need to propagate the pid to second-stage init so the process can be killed (or signalled). (3) first-stage snapuserd will need to gracefully exit once it has no active handler threads. (4) second-stage init will need to invoke the transition helper on SnapshotMaanager, ideally as soon as feasible. Bug: 168259959 Test: manual test Change-Id: I54dec2edf85ed95f11ab4518eb3d7dbaf0bdcbfd
Loading
Please register or sign in to comment