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;
332 const std::function<bool (const zypp::media::MountEntry &)>
DeviceDriver::fstypePredicate(
const std::string &src,
const std::vector<std::string> &fstypes )
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 ),
374 _transient( transient )
DeviceDriver(WorkerCaps::WorkerType wType)
void releaseIdleDevices()
bool autoCleanup() const
Whether path is valid and deleted when the last reference drops.
const Pathname & path() const
Return current Pathname.
bool detachMedia(const std::string &attachId)
Pathname realpath() const
Returns this path as the absolute canonical pathname.
std::unordered_map< std::string, AttachedMedia > & attachedMedia()
zypp::proto::Capabilities WorkerCaps
ProvideWorkerWeakRef _parentWorker
zypp::Pathname attachRoot() const
constexpr std::string_view ATTACH_POINT("zconfig://media/AttachPoint")
std::vector< std::shared_ptr< Device > > _sysDevs
WorkerCaps::WorkerType _wType
unsigned int devMinor() const
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
virtual void immediateShutdown()
virtual zyppng::expected< WorkerCaps > initialize(const zyppng::worker::Configuration &conf)
std::unordered_map< std::string, AttachedMedia > _attachedMedia
ProvideWorkerRef parentWorker() const
static const ValueType month
static const std::function< bool(const zypp::media::MountEntry &)> bindMountPredicate(const std::string &src)
const zyppng::worker::Configuration & config() const
bool empty() const
Test for an empty path.
zypp::Pathname _attachRoot
Provide a new empty temporary directory and recursively delete it when no longer needed.
const std::string & asString() const
String representation.
bool isExist() const
Return whether valid stat info exists.
std::string _name
Path of the device node or URL for e.g. nfs devices.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
void removeAttachPoint(const zypp::Pathname &attach_pt) const
bool historyEmpty() const
Whether the history list is empty.
std::string historyAsString() const
The history as string.
bool absolute() const
Test for an absolute path.
std::vector< std::shared_ptr< Device > > & knownDevices()
zypp::Pathname createAttachPoint(const zypp::Pathname &attach_root) const
void setAttachRoot(const zypp::Pathname &root)
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
bool checkAttached(const zypp::Pathname &mountPoint, const std::function< bool(const zypp::media::MountEntry &)> predicate)
Base class for Exception.
static const std::function< bool(const zypp::media::MountEntry &)> devicePredicate(unsigned int majNr, unsigned int minNr)
static Date now()
Return the current time.
A "struct mntent" like mount entry structure, but using std::strings.
unsigned int devMajor() const
Wrapper class for ::stat/::lstat.
constexpr std::string_view History("history")
zypp::Pathname _mountPoint
Mountpoint of the device, if empty dev is not mounted.
std::string asUserString(VendorSupportOption opt)
converts the support option to a name intended to be printed to the user.
zypp::proto::Configuration Configuration
void setProvider(ProvideWorkerWeakRef workerRef)
zyppng::expected< void > isDesiredMedium(const zypp::Url &deviceUrl, const zypp::Pathname &mountPoint, const zyppng::MediaDataVerifierRef &verifier, uint mediaNr=1)
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
virtual bool isVolatile() const
static const std::function< bool(const zypp::media::MountEntry &)> fstypePredicate(const std::string &src, const std::vector< std::string > &fstypes)
zyppng::worker::Configuration _config
virtual void detectDevices()
virtual void unmountDevice(Device &dev)
AttachError(const uint code, const std::string &reason, const bool transient, const HeaderValueMap &extra={})