[PATCH] Add error checks to liveimg mount code (#1178703)

Vratislav Podzimek vpodzime at redhat.com
Fri Jan 9 07:14:02 UTC 2015


On Thu, 2015-01-08 at 11:34 -0800, Brian C. Lane wrote:
> Instead of logging the mount error and falling into the rsync and
> failing later catch problems with mounting the images and moving the
> mountpoint.
> 
> Related: rhbz#1178703
> ---
>  pyanaconda/packaging/livepayload.py | 67 ++++++++++++++++++++++++-------------
>  1 file changed, 44 insertions(+), 23 deletions(-)
> 
> diff --git a/pyanaconda/packaging/livepayload.py b/pyanaconda/packaging/livepayload.py
> index 0a67774..17c1bac 100644
> --- a/pyanaconda/packaging/livepayload.py
> +++ b/pyanaconda/packaging/livepayload.py
> @@ -373,29 +373,50 @@ class LiveImageKSPayload(LiveImagePayload):
>                      raise exn
>  
>          # If this looks like a tarfile, skip trying to mount it
> -        if not self.is_tarfile:
> -            # Mount the image and check to see if it is a LiveOS/*.img
> -            # style squashfs image. If so, move it to IMAGE_DIR and mount the real
> -            # root image on INSTALL_TREE
> -            blivet.util.mount(self.image_path, INSTALL_TREE, fstype="auto", options="ro")
> -            if os.path.exists(INSTALL_TREE+"/LiveOS"):
> -                # Find the first .img in the directory and mount that on INSTALL_TREE
> -                img_files = glob.glob(INSTALL_TREE+"/LiveOS/*.img")
> -                if img_files:
> -                    img_file = os.path.basename(sorted(img_files)[0])
> -
> -                    # move the mount to IMAGE_DIR
> -                    os.makedirs(IMAGE_DIR, 0o755)
> -                    # work around inability to move shared filesystems
> -                    iutil.execWithRedirect("mount",
> -                                           ["--make-rprivate", "/"])
> -                    iutil.execWithRedirect("mount",
> -                                           ["--move", INSTALL_TREE, IMAGE_DIR])
> -                    blivet.util.mount(IMAGE_DIR+"/LiveOS/"+img_file, INSTALL_TREE,
> -                                      fstype="auto", options="ro")
> -
> -                    source = iutil.eintr_retry_call(os.statvfs, INSTALL_TREE)
> -                    self.source_size = source.f_frsize * (source.f_blocks - source.f_bfree)
> +        if self.is_tarfile:
> +            return
> +
> +        # Mount the image and check to see if it is a LiveOS/*.img
> +        # style squashfs image. If so, move it to IMAGE_DIR and mount the real
> +        # root image on INSTALL_TREE
> +        rc = blivet.util.mount(self.image_path, INSTALL_TREE, fstype="auto", options="ro")
> +        if rc != 0:
> +            log.error("mount error (%s) with %s", rc, self.image_path)
> +            exn = PayloadInstallError("mount error %s" % rc)
> +            if errorHandler.cb(exn) == ERROR_RAISE:
> +                raise exn
> +
> +        # Nothing more to mount
> +        if not os.path.exists(INSTALL_TREE+"/LiveOS"):
> +            return
> +
> +        # Mount the first .img in the directory on INSTALL_TREE
> +        img_files = glob.glob(INSTALL_TREE+"/LiveOS/*.img")
> +        if img_files:
> +            # move the mount to IMAGE_DIR
> +            os.makedirs(IMAGE_DIR, 0o755)
> +            # work around inability to move shared filesystems
> +            rc = iutil.execWithRedirect("mount",
> +                                        ["--make-rprivate", "/"])
> +            if rc == 0:
> +                rc = iutil.execWithRedirect("mount",
> +                                            ["--move", INSTALL_TREE, IMAGE_DIR])
> +            if rc != 0:
> +                log.error("error %s moving mount", rc)
> +                exn = PayloadInstallError("mount error %s" % rc)
> +                if errorHandler.cb(exn) == ERROR_RAISE:
> +                    raise exn
> +
> +            img_file = IMAGE_DIR+"/LiveOS/"+os.path.basename(sorted(img_files)[0])
> +            rc = blivet.util.mount(img_file, INSTALL_TREE, fstype="auto", options="ro")
> +            if rc != 0:
> +                log.error("mount error (%s) with %s", rc, img_file)
> +                exn = PayloadInstallError("mount error %s with %s" % (rc, img_file))
> +                if errorHandler.cb(exn) == ERROR_RAISE:
> +                    raise exn
> +
> +            source = iutil.eintr_retry_call(os.statvfs, INSTALL_TREE)
> +            self.source_size = source.f_frsize * (source.f_blocks - source.f_bfree)
>  
>      def install(self):
>          """ Install the payload if it is a tar.
Looks good to me.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list