13#include <zypp-media/ng/MediaVerifier>
14#include <zypp-media/MediaException>
15#include <zypp-core/fs/PathInfo.h>
16#include <zypp-core/fs/TmpPath.h>
17#include <zypp-core/Date.h>
19#undef ZYPP_BASE_LOGGER_LOGGROUP
20#define ZYPP_BASE_LOGGER_LOGGROUP "zyppng::worker::DeviceDriver"
36 const auto &values = conf.values();
38 const auto &val = i->second;
39 MIL <<
"Got attachpoint from controller: " << val << std::endl;
48 caps.set_worker_type (
_wType );
50 zyppng::worker::WorkerCaps::Flags (
51 zyppng::worker::WorkerCaps::Pipeline
52 | zyppng::worker::WorkerCaps::ZyppLogFormat
53 | zyppng::worker::WorkerCaps::SingleInstance
57 return zyppng::expected<zyppng::worker::WorkerCaps>::success(caps);
73 if ( i->use_count() == 1 && !(*i)->_mountPoint.empty() ) {
74 MIL <<
"Unmounting device " << (*i)->_name <<
" since its not used anymore" << std::endl;
76 if ( (*i)->_ephemeral ) {
110 if ( (*i)->_ephemeral ) {
133 ERR <<
"Failed to unmount device: " << dev.
_name << std::endl;
152 MIL <<
"Attach root is empty" << std::endl;
169 return zyppng::expected<void>::success();
173 auto devVerifier =
verifier->clone();
174 if ( !devVerifier ) {
183 const auto &relMediaPath = devVerifier->mediaFilePath( mediaNr );
188 return zyppng::expected<void>::success();
190 excpt.addHistory(
verifier->expectedAsUserString( mediaNr ) );
191 return zyppng::expected<void>::error(
ZYPP_EXCPT_PTR( std::move(excpt) ) );
195 return zyppng::expected<void>::success();
197 excpt.addHistory(
verifier->expectedAsUserString( mediaNr ) );
198 return zyppng::expected<void>::error(
ZYPP_EXCPT_PTR( std::move(excpt) ) );
201 if ( !devVerifier->load( mediaFile ) ) {
204 if ( !
verifier->matches( devVerifier ) ) {
207 return zyppng::expected<void>::success();
215 ERR <<
"Create attach point: invalid attach root: '"
216 << attach_root <<
"'" << std::endl;
222 DBG <<
"Create attach point: attach root is not a writable directory: '"
223 << attach_root <<
"'" << std::endl;
227 static bool cleanup_once(
true );
230 cleanup_once =
false;
231 DBG <<
"Look for orphaned attach points in " << adir << std::endl;
232 std::list<std::string> entries;
234 for (
const std::string & entry : entries )
240 && sdir.
dev() == adir.
dev()
243 DBG <<
"Remove orphaned attach point " << sdir << std::endl;
253 if ( ! apoint.
empty() )
259 ERR <<
"Unable to resolve real path for attach point " << tmpdir << std::endl;
264 ERR <<
"Unable to create attach point below " << attach_root << std::endl;
276 MIL <<
"Deleted default attach point " <<
attachRoot << std::endl;
278 ERR <<
"Failed to Delete default attach point " <<
attachRoot
279 <<
" errno(" << res <<
")" << std::endl;
286 bool isAttached =
false;
294 DBG <<
"Mount table changed - rereading it" << std::endl;
296 DBG <<
"Forced check of the mount table" << std::endl;
319 if( entry.isBlockDevice() ) {
322 DBG <<
"Found device "
323 << majNr <<
":" << minNr
324 <<
" in the mount table as " << entry.src << std::endl;
335 if( !entry.isBlockDevice() ) {
336 if ( std::find( fst.begin(), fst.end(), entry.type ) != fst.end() ) {
337 if ( srcdev == entry.src ) {
338 DBG <<
"Found media mount"
339 <<
" in the mount table as " << entry.src << std::endl;
351 if( !entry.isBlockDevice() ) {
352 if ( srcdev == entry.src ) {
353 DBG <<
"Found bound media "
354 <<
" in the mount table as " << entry.src << std::endl;
365 _transient( transient ),
373 _reason( e.asUserString() ),
374 _transient( transient )
static const ValueType month
static Date now()
Return the current time.
Base class for Exception.
std::string historyAsString() const
The history as string.
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.
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)
zyppng::worker::Configuration _config
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
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 readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
constexpr std::string_view History("history")
zypp::proto::Configuration Configuration
zypp::proto::Capabilities WorkerCaps
constexpr std::string_view ATTACH_POINT("zconfig://media/AttachPoint")
A "struct mntent" like mount entry structure, but using std::strings.
AttachError(const uint 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.