xref: /aosp_15_r20/system/core/fs_mgr/libsnapshot/snapuserd/user-space-merge/worker.h (revision 00c7fec1bb09f3284aad6a6f96d2f63dfc3650ad)
1 // Copyright (C) 2023 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <stddef.h>
18 
19 #include <memory>
20 #include <string>
21 
22 #include <android-base/unique_fd.h>
23 #include <libsnapshot/cow_reader.h>
24 #include <snapuserd/snapuserd_buffer.h>
25 #include <snapuserd/snapuserd_kernel.h>
26 
27 namespace android {
28 namespace snapshot {
29 
30 using android::base::unique_fd;
31 
32 class SnapshotHandler;
33 
34 class Worker {
35   public:
36     Worker(const std::string& cow_device, const std::string& misc_name,
37            const std::string& base_path_merge, std::shared_ptr<SnapshotHandler> snapuserd);
38     virtual ~Worker() = default;
39 
40     virtual bool Init();
41 
42   protected:
43     bool InitializeFds();
44     bool InitReader();
CloseFds()45     virtual void CloseFds() { base_path_merge_fd_ = {}; }
46 
47     std::unique_ptr<CowReader> reader_;
48 
49     std::string misc_name_;  // Needed for SNAP_LOG.
50 
51     unique_fd base_path_merge_fd_;
52 
53     std::shared_ptr<SnapshotHandler> snapuserd_;
54 
55   private:
56     std::string cow_device_;
57     std::string base_path_merge_;
58     unique_fd cow_fd_;
59 };
60 
61 }  // namespace snapshot
62 }  // namespace android
63