[zypp-commit] r11262 - in /trunk/libzypp/zypp/media: MediaException.cc MediaException.h MediaHandler.cc MediaISO.cc MediaISO.h
Author: jkupec Date: Wed Oct 8 16:24:19 2008 New Revision: 11262 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11262&view=rev Log: - detect and use unused loop device for mounting ISO images (bnc #428009) Modified: trunk/libzypp/zypp/media/MediaException.cc trunk/libzypp/zypp/media/MediaException.h trunk/libzypp/zypp/media/MediaHandler.cc trunk/libzypp/zypp/media/MediaISO.cc trunk/libzypp/zypp/media/MediaISO.h Modified: trunk/libzypp/zypp/media/MediaException.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaException.cc?rev=11262&r1=11261&r2=11262&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaException.cc (original) +++ trunk/libzypp/zypp/media/MediaException.cc Wed Oct 8 16:24:19 2008 @@ -266,6 +266,14 @@ return str << form(_(" SSL certificate problem, verify that the CA cert is OK for '%s'."), _url.c_str()) << endl; return str << _msg << endl; } + + std::ostream & MediaNoLoopDeviceException::dumpOn( std::ostream & str ) const + { + if (msg().empty()) + return str << form(_("Cannot find available loop device to mount the image file from '%s'"), _url.c_str()) << endl; + return str << msg() << endl; + } + ///////////////////////////////////////////////////////////////// } // namespace media } // namespace zypp Modified: trunk/libzypp/zypp/media/MediaException.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaException.h?rev=11262&r1=11261&r2=11262&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaException.h (original) +++ trunk/libzypp/zypp/media/MediaException.h Wed Oct 8 16:24:19 2008 @@ -594,6 +594,28 @@ std::string _url; std::string _msg; }; + + /** + * Thrown if /sbin/losetup fails to find an unused loop device for mounting + * an .iso image. + * + * UI hint: tell user to check permissions to read /dev/loop# or enablement + * of support for loop devices. + * + * \see MediaISO + */ + class MediaNoLoopDeviceException : public MediaException + { + public: + MediaNoLoopDeviceException(const Url & url_r, const std::string & msg = "") + : MediaException(msg) + , _url(url_r.asString()) + {} + virtual ~MediaNoLoopDeviceException() throw() {}; + protected: + virtual std::ostream & dumpOn( std::ostream & str ) const; + std::string _url; + }; ///////////////////////////////////////////////////////////////// } // namespace media } // namespace zypp Modified: trunk/libzypp/zypp/media/MediaHandler.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaHandler.cc?rev=11262&r1=11261&r2=11262&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaHandler.cc (original) +++ trunk/libzypp/zypp/media/MediaHandler.cc Wed Oct 8 16:24:19 2008 @@ -581,21 +581,6 @@ } // differs } - else // mixed cases: - { - // Type ISO: Since 11.1 mtab might contain the name of - // the loop device instead of the iso file: - if ( ref.mediaSource->type == "iso" - && str::hasPrefix( Pathname(e->src).asString(), "/dev/loop" ) - && ref.attachPoint->path == Pathname(e->dir) ) - { - DBG << "Found bound media " - << ref.mediaSource->asString() - << " in the mount table as " << e->src << std::endl; - _isAttached = true; - break; - } - } } if( !_isAttached) Modified: trunk/libzypp/zypp/media/MediaISO.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaISO.cc?rev=11262&r1=11261&r2=11262&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaISO.cc (original) +++ trunk/libzypp/zypp/media/MediaISO.cc Wed Oct 8 16:24:19 2008 @@ -9,11 +9,18 @@ /** \file zypp/media/MediaISO.cc * */ -#include "zypp/media/MediaISO.h" +#include <iostream> + #include "zypp/base/Logger.h" #include "zypp/media/Mount.h" -#include <iostream> +#include "zypp/media/MediaISO.h" + + +#define LOSETUP_TOOL_PATH "/sbin/losetup" + +using std::string; +using std::endl; ////////////////////////////////////////////////////////////////////// namespace zypp @@ -141,6 +148,32 @@ } // --------------------------------------------------------------- + string MediaISO::findUnusedLoopDevice() + { + const char* argv[] = + { + LOSETUP_TOOL_PATH, + "-f", + NULL + }; + ExternalProgram losetup(argv, ExternalProgram::Stderr_To_Stdout); + + string out = losetup.receiveLine(); + string device = out.substr(0, out.size() - 1); // remove the trailing endl + for(; out.length(); out = losetup.receiveLine()) + DBG << "losetup: " << out; + + if (losetup.close() != 0) + { + ERR << LOSETUP_TOOL_PATH " failed to find an unused loop device." << std::endl; + ZYPP_THROW(MediaNoLoopDeviceException(_url)); + } + + DBG << "found " << device << endl; + return device; + } + + // --------------------------------------------------------------- void MediaISO::attachTo(bool next) { if(next) @@ -181,9 +214,18 @@ ZYPP_THROW(MediaNotSupportedException(_url)); } - MediaSourceRef media( new MediaSource( - "iso", isofile.asString() - )); + //! \todo make this thread-safe - another thread might pick up the same device + string loopdev = findUnusedLoopDevice(); // (bnc #428009) + + MediaSourceRef media( new MediaSource("iso", loopdev)); + PathInfo dinfo(loopdev); + if( dinfo.isBlk()) + { + media->maj_nr = dinfo.major(); + media->min_nr = dinfo.minor(); + } + else + ERR << loopdev << " is not a block device" << endl; AttachedMedia ret( findAttachedMedia( media)); if( ret.mediaSource && @@ -210,7 +252,7 @@ setAttachPoint( mountpoint, true); } - std::string mountopts("ro,loop"); + std::string mountopts("ro,loop=" + loopdev); Mount mount; mount.mount(isofile.asString(), mountpoint, Modified: trunk/libzypp/zypp/media/MediaISO.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaISO.h?rev=11262&r1=11261&r2=11262&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaISO.h (original) +++ trunk/libzypp/zypp/media/MediaISO.h Wed Oct 8 16:24:19 2008 @@ -39,6 +39,9 @@ MediaAccessId _isosource; std::string _filesystem; + private: + std::string findUnusedLoopDevice(); + protected: virtual void attachTo (bool next = false); -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org
participants (1)
-
jkupec@svn.opensuse.org