13#include <zypp-media/ng/MediaVerifier>
14#include <zypp-media/MediaException>
19#undef ZYPP_BASE_LOGGER_LOGGROUP
20#define ZYPP_BASE_LOGGER_LOGGROUP "zyppng::worker::DeviceDriver"
37 const auto &val = i->second;
38 MIL <<
"Got attachpoint from controller: " << val << std::endl;
72 if ( i->use_count() == 1 && !(*i)->_mountPoint.empty() ) {
73 MIL <<
"Unmounting device " << (*i)->_name <<
" since its not used anymore" << std::endl;
75 if ( (*i)->_ephemeral ) {
109 if ( (*i)->_ephemeral ) {
132 ERR <<
"Failed to unmount device: " << dev.
_name << std::endl;
151 MIL <<
"Attach root is empty" << std::endl;
172 auto devVerifier = verifier->clone();
173 if ( !devVerifier ) {
180 bool relaxed = verifier->totalMedia() == 1 && !
isVolatile();
182 const auto &relMediaPath = devVerifier->mediaFilePath( mediaNr );
189 excpt.addHistory( verifier->expectedAsUserString( mediaNr ) );
196 excpt.addHistory( verifier->expectedAsUserString( mediaNr ) );
200 if ( !devVerifier->load( mediaFile ) ) {
203 if ( !verifier->matches( devVerifier ) ) {
214 ERR <<
"Create attach point: invalid attach root: '"
215 << attach_root <<
"'" << std::endl;
221 DBG <<
"Create attach point: attach root is not a writable directory: '"
222 << attach_root <<
"'" << std::endl;
226 static bool cleanup_once(
true );
229 cleanup_once =
false;
230 DBG <<
"Look for orphaned attach points in " << adir << std::endl;
231 std::list<std::string> entries;
233 for (
const std::string & entry : entries )
239 && sdir.
dev() == adir.
dev()
242 DBG <<
"Remove orphaned attach point " << sdir << std::endl;
252 if ( ! apoint.
empty() )
258 ERR <<
"Unable to resolve real path for attach point " << tmpdir << std::endl;
263 ERR <<
"Unable to create attach point below " << attach_root << std::endl;
275 MIL <<
"Deleted default attach point " <<
attachRoot << std::endl;
277 ERR <<
"Failed to Delete default attach point " <<
attachRoot
278 <<
" errno(" << res <<
")" << std::endl;
285 bool isAttached =
false;
293 DBG <<
"Mount table changed - rereading it" << std::endl;
295 DBG <<
"Forced check of the mount table" << std::endl;
301 if ( predicate(entry) ) {
318 if( entry.isBlockDevice() ) {
321 DBG <<
"Found device "
322 << majNr <<
":" << minNr
323 <<
" in the mount table as " << entry.src << std::endl;
334 if( !entry.isBlockDevice() ) {
335 if ( std::find( fst.begin(), fst.end(), entry.type ) != fst.end() ) {
336 if ( srcdev == entry.src ) {
337 DBG <<
"Found media mount"
338 <<
" in the mount table as " << entry.src << std::endl;
350 if( !entry.isBlockDevice() ) {
351 if ( srcdev == entry.src ) {
352 DBG <<
"Found bound media "
353 <<
" in the mount table as " << entry.src << std::endl;
376 _extra = { { std::string(zyppng::ErrMsgFields::History), { zyppng::HeaderValueMap::Value(e.historyAsString()) }} };
static const ValueType month
static Date now()
Return the current time.
Base class for Exception.
bool historyEmpty() const
Whether the history list is empty.
Wrapper class for stat/lstat.
const Pathname & path() const
Return current Pathname.
unsigned int devMinor() const
bool isExist() const
Return whether valid stat info exists.
unsigned int devMajor() const
bool absolute() const
Test for an absolute path.
const std::string & asString() const
String representation.
bool empty() const
Test for an empty path.
Pathname realpath() const
Returns this path as the absolute canonical pathname.
Provide a new empty temporary directory and recursively delete it when no longer needed.
bool autoCleanup() const
Whether path is valid and deleted when the last reference drops.
void set_worker_type(WorkerType t)
void set_cfg_flags(Flags f)
static expected success(ConsParams &&...params)
zypp::Pathname attachRoot() const
zypp::Pathname createAttachPoint(const zypp::Pathname &attach_root) const
virtual zyppng::expected< WorkerCaps > initialize(const zyppng::worker::Configuration &conf)
static const std::function< bool(const zypp::media::MountEntry &)> fstypePredicate(const std::string &src, const std::vector< std::string > &fstypes)
bool checkAttached(const zypp::Pathname &mountPoint, const std::function< bool(const zypp::media::MountEntry &)> predicate)
ProvideWorkerWeakRef _parentWorker
bool detachMedia(const std::string &attachId)
DeviceDriver(WorkerCaps::WorkerType wType)
zypp::Pathname _attachRoot
virtual bool isVolatile() const
void setProvider(ProvideWorkerWeakRef workerRef)
zyppng::expected< void > isDesiredMedium(const zypp::Url &deviceUrl, const zypp::Pathname &mountPoint, const zyppng::MediaDataVerifierRef &verifier, uint mediaNr=1)
WorkerCaps::WorkerType _wType
static const std::function< bool(const zypp::media::MountEntry &)> bindMountPredicate(const std::string &src)
virtual void detectDevices()
std::unordered_map< std::string, AttachedMedia > & attachedMedia()
std::vector< std::shared_ptr< Device > > & knownDevices()
const zyppng::worker::Configuration & config() const
virtual void immediateShutdown()
void removeAttachPoint(const zypp::Pathname &attach_pt) const
std::vector< std::shared_ptr< Device > > _sysDevs
ProviderConfiguration _config
std::unordered_map< std::string, AttachedMedia > _attachedMedia
ProvideWorkerRef parentWorker() const
void releaseIdleDevices()
static const std::function< bool(const zypp::media::MountEntry &)> devicePredicate(unsigned int majNr, unsigned int minNr)
void setAttachRoot(const zypp::Pathname &root)
virtual void unmountDevice(Device &dev)
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
std::string asUserString(VendorSupportOption opt)
converts the support option to a name intended to be printed to the user.
zyppng::ProviderConfiguration Configuration
zyppng::WorkerCaps WorkerCaps
constexpr std::string_view ATTACH_POINT("zconfig://media/AttachPoint")
A "struct mntent" like mount entry structure, but using std::strings.
AttachError(const MessageCodes code, const std::string &reason, const bool transient, const HeaderValueMap &extra={})
std::string _name
Path of the device node or URL for e.g. nfs devices.
zypp::Pathname _mountPoint
Mountpoint of the device, if empty dev is not mounted.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.