libzypp: zypp-media/ng/worker/devicedriver.h Source File

libzypp 17.36.6

devicedriver.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#ifndef ZYPP_MEDIA_NG_WORKER_DEVICEDRIVER_H_INCLUDED
11#define ZYPP_MEDIA_NG_WORKER_DEVICEDRIVER_H_INCLUDED
12
13#include <zypp-media/ng/ProvideFwd>
14#include <zypp-media/ng/worker/ProvideWorker>
15#include <zypp-media/ng/HeaderValueMap>
16#include <zypp-media/Mount>
17#include <zypp-core/zyppng/base/Signals>
18#include <zypp-core/zyppng/base/Base>
19#include <zypp-core/zyppng/base/zyppglobal.h>
20#include <zypp-core/zyppng/pipelines/Expected>
21#include <any>
22#include <unordered_map>
23
24namespace zyppng::worker
25{
26
27 ZYPP_FWD_DECL_TYPE_WITH_REFS (DeviceDriver);
28
29 struct Device
30 {
31 std::string _name;
32 unsigned int _maj_nr = 0;
33 unsigned int _min_nr = 0;
34 zypp::Pathname _mountPoint = {};
35 bool _ephemeral = false;
36 std::unordered_map<std::string, std::any> _properties = {};
37 };
38
39 struct AttachedMedia
40 {
41 std::shared_ptr<Device> _dev;
42 zypp::Pathname _attachRoot;
43 };
44
45 struct AttachError
46 {
47 AttachError ( const MessageCodes code, const std::string &reason, const bool transient, const HeaderValueMap &extra = {} );
48 AttachError ( const MessageCodes code, const bool transient, const zypp::Exception &e );
49
50 MessageCodes _code;
51 std::string _reason;
52 bool _transient;
53 HeaderValueMap _extra;
54 };
55
56 // either the mountpoint or an error
57 using AttachResult = expected<zypp::Pathname, AttachError>;
58
65 class DeviceDriver : public zyppng::Base
66 {
67 public:
68
69 DeviceDriver ( WorkerCaps::WorkerType wType );
70
74 void setProvider ( ProvideWorkerWeakRef workerRef );
75
79 virtual AttachResult mountDevice ( const uint32_t id, const zypp::Url &mediaUrl, const std::string &attachId, const std::string &label, const HeaderValueMap &extras ) = 0;
80
81
82
83 virtual zyppng::expected<WorkerCaps> initialize(const zyppng::worker::Configuration &conf);
84
85
94 bool detachMedia ( const std::string &attachId );
95
99 void releaseIdleDevices ();
100
106 virtual void detectDevices();
107
112 std::vector<std::shared_ptr<Device>> &knownDevices();
113
118 const std::vector<std::shared_ptr<Device>> &knownDevices() const;
119
123 std::unordered_map<std::string, AttachedMedia> &attachedMedia();
124
129 virtual bool isVolatile () const;
130
134 void setAttachRoot ( const zypp::Pathname &root );
135
139 zypp::Pathname attachRoot () const;
140
144 virtual void immediateShutdown();
145
149 ProvideWorkerRef parentWorker () const;
150
154 const zyppng::worker::Configuration &config() const;
155
156 protected:
160 virtual void unmountDevice ( Device &dev );
161
165 zyppng::expected<void> isDesiredMedium ( const zypp::Url &deviceUrl, const zypp::Pathname &mountPoint, const zyppng::MediaDataVerifierRef &verifier, uint mediaNr = 1 );
166
167
168 zypp::Pathname createAttachPoint(const zypp::Pathname &attach_root) const;
169 void removeAttachPoint ( const zypp::Pathname &attach_pt ) const;
170 bool checkAttached ( const zypp::Pathname &mountPoint, const std::function<bool( const zypp::media::MountEntry &)> predicate );
171
175 static const std::function<bool( const zypp::media::MountEntry &)> devicePredicate ( unsigned int majNr, unsigned int minNr );
176
180 static const std::function<bool( const zypp::media::MountEntry &)> fstypePredicate ( const std::string &src, const std::vector<std::string> &fstypes );
181
185 static const std::function<bool( const zypp::media::MountEntry &)> bindMountPredicate ( const std::string &src );
186
187 private:
188 WorkerCaps::WorkerType _wType;
189 ProviderConfiguration _config;
190 time_t _attach_mtime = 0; //< Timestamp of the mtab we did read
191 zypp::Pathname _attachRoot;
192 std::vector<std::shared_ptr<Device>> _sysDevs;
193 std::unordered_map<std::string, AttachedMedia> _attachedMedia;
194 ProvideWorkerWeakRef _parentWorker;
195 };
196
197
198
199
200}
201
202#endif
bool
zypp::Exception
Base class for Exception.
Definition Exception.h:147
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zyppng::Base
Definition base.h:60
zyppng::HeaderValueMap
Definition headervaluemap.h:67
zyppng::ProviderConfiguration
Definition providemessage_p.h:366
zyppng::WorkerCaps::WorkerType
WorkerType
Definition providemessage_p.h:379
zyppng::expected
Definition expected.h:27
zyppng::worker::DeviceDriver
Definition devicedriver.h:66
zyppng::worker::DeviceDriver::attachRoot
zypp::Pathname attachRoot() const
Definition devicedriver.cc:148
zyppng::worker::DeviceDriver::createAttachPoint
zypp::Pathname createAttachPoint(const zypp::Pathname &attach_root) const
Definition devicedriver.cc:209
zyppng::worker::DeviceDriver::initialize
virtual zyppng::expected< WorkerCaps > initialize(const zyppng::worker::Configuration &conf)
Definition devicedriver.cc:34
zyppng::worker::DeviceDriver::fstypePredicate
static const std::function< bool(const zypp::media::MountEntry &)> fstypePredicate(const std::string &src, const std::vector< std::string > &fstypes)
Definition devicedriver.cc:331
zyppng::worker::DeviceDriver::checkAttached
bool checkAttached(const zypp::Pathname &mountPoint, const std::function< bool(const zypp::media::MountEntry &)> predicate)
Definition devicedriver.cc:283
zyppng::worker::DeviceDriver::_parentWorker
ProvideWorkerWeakRef _parentWorker
Definition devicedriver.h:194
zyppng::worker::DeviceDriver::detachMedia
bool detachMedia(const std::string &attachId)
Definition devicedriver.cc:59
zyppng::worker::DeviceDriver::DeviceDriver
DeviceDriver(WorkerCaps::WorkerType wType)
Definition devicedriver.cc:25
zyppng::worker::DeviceDriver::_attachRoot
zypp::Pathname _attachRoot
Definition devicedriver.h:191
zyppng::worker::DeviceDriver::isVolatile
virtual bool isVolatile() const
Definition devicedriver.cc:138
zyppng::worker::DeviceDriver::setProvider
void setProvider(ProvideWorkerWeakRef workerRef)
Definition devicedriver.cc:29
zyppng::worker::DeviceDriver::isDesiredMedium
zyppng::expected< void > isDesiredMedium(const zypp::Url &deviceUrl, const zypp::Pathname &mountPoint, const zyppng::MediaDataVerifierRef &verifier, uint mediaNr=1)
Definition devicedriver.cc:162
zyppng::worker::DeviceDriver::_wType
WorkerCaps::WorkerType _wType
Definition devicedriver.h:188
zyppng::worker::DeviceDriver::bindMountPredicate
static const std::function< bool(const zypp::media::MountEntry &)> bindMountPredicate(const std::string &src)
Definition devicedriver.cc:347
zyppng::worker::DeviceDriver::detectDevices
virtual void detectDevices()
Definition devicedriver.cc:84
zyppng::worker::DeviceDriver::attachedMedia
std::unordered_map< std::string, AttachedMedia > & attachedMedia()
Definition devicedriver.cc:99
zyppng::worker::DeviceDriver::knownDevices
std::vector< std::shared_ptr< Device > > & knownDevices()
Definition devicedriver.cc:89
zyppng::worker::DeviceDriver::mountDevice
virtual AttachResult mountDevice(const uint32_t id, const zypp::Url &mediaUrl, const std::string &attachId, const std::string &label, const HeaderValueMap &extras)=0
zyppng::worker::DeviceDriver::config
const zyppng::worker::Configuration & config() const
Definition devicedriver.cc:157
zyppng::worker::DeviceDriver::immediateShutdown
virtual void immediateShutdown()
Definition devicedriver.cc:104
zyppng::worker::DeviceDriver::removeAttachPoint
void removeAttachPoint(const zypp::Pathname &attach_pt) const
Definition devicedriver.cc:268
zyppng::worker::DeviceDriver::_sysDevs
std::vector< std::shared_ptr< Device > > _sysDevs
Definition devicedriver.h:192
zyppng::worker::DeviceDriver::_config
ProviderConfiguration _config
Definition devicedriver.h:189
zyppng::worker::DeviceDriver::_attachedMedia
std::unordered_map< std::string, AttachedMedia > _attachedMedia
Definition devicedriver.h:193
zyppng::worker::DeviceDriver::parentWorker
ProvideWorkerRef parentWorker() const
Definition devicedriver.cc:118
zyppng::worker::DeviceDriver::releaseIdleDevices
void releaseIdleDevices()
Definition devicedriver.cc:69
zyppng::worker::DeviceDriver::devicePredicate
static const std::function< bool(const zypp::media::MountEntry &)> devicePredicate(unsigned int majNr, unsigned int minNr)
Definition devicedriver.cc:315
zyppng::worker::DeviceDriver::setAttachRoot
void setAttachRoot(const zypp::Pathname &root)
Definition devicedriver.cc:143
zyppng::worker::DeviceDriver::unmountDevice
virtual void unmountDevice(Device &dev)
Definition devicedriver.cc:123
zyppng::worker::DeviceDriver::_attach_mtime
time_t _attach_mtime
Definition devicedriver.h:190
zyppng::worker
Definition devicedriver.cc:23
zyppng::worker::AttachResult
expected< zypp::Pathname, AttachError > AttachResult
Definition devicedriver.h:57
zyppng::worker::Configuration
zyppng::ProviderConfiguration Configuration
Definition provideworker.h:31
zyppng::MessageCodes
MessageCodes
Definition providemessage_p.h:308
zypp::media::MountEntry
A "struct mntent" like mount entry structure, but using std::strings.
Definition mount.h:36
zyppng::worker::AttachError::_extra
HeaderValueMap _extra
Definition devicedriver.h:53
zyppng::worker::AttachError::_reason
std::string _reason
Definition devicedriver.h:51
zyppng::worker::AttachError::_transient
bool _transient
Definition devicedriver.h:52
zyppng::worker::AttachError::AttachError
AttachError(const MessageCodes code, const std::string &reason, const bool transient, const HeaderValueMap &extra={})
Definition devicedriver.cc:361
zyppng::worker::AttachError::_code
MessageCodes _code
Definition devicedriver.h:50
zyppng::worker::AttachedMedia
Definition devicedriver.h:40
zyppng::worker::AttachedMedia::_dev
std::shared_ptr< Device > _dev
Definition devicedriver.h:41
zyppng::worker::AttachedMedia::_attachRoot
zypp::Pathname _attachRoot
Definition devicedriver.h:42
zyppng::worker::Device
Definition devicedriver.h:30
zyppng::worker::Device::_properties
std::unordered_map< std::string, std::any > _properties
Definition devicedriver.h:36
zyppng::worker::Device::_name
std::string _name
Path of the device node or URL for e.g. nfs devices.
Definition devicedriver.h:31
zyppng::worker::Device::_min_nr
unsigned int _min_nr
Minor number of the device.
Definition devicedriver.h:33
zyppng::worker::Device::_maj_nr
unsigned int _maj_nr
Major number of the device.
Definition devicedriver.h:32
zyppng::worker::Device::_ephemeral
bool _ephemeral
If set to true the device is removed from the internal list after the last attachpoint was released.
Definition devicedriver.h:35
zyppng::worker::Device::_mountPoint
zypp::Pathname _mountPoint
Mountpoint of the device, if empty dev is not mounted.
Definition devicedriver.h:34
zyppglobal.h
ZYPP_FWD_DECL_TYPE_WITH_REFS
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126