Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   CentOS (http://www.linux-archive.org/centos/)
-   -   pylorax.imgutils: add retry loop and "lazy" to umount() (http://www.linux-archive.org/centos/674735-pylorax-imgutils-add-retry-loop-lazy-umount.html)

Will Woods 06-20-2012 12:11 AM

pylorax.imgutils: add retry loop and "lazy" to umount()
 
There's something strange going on where unmounting a hfsplus volume
immediately after mounting it will fail with EBUSY.

This makes the umount fail, which makes the rmdir fail, which causes a
traceback, which breaks mkefiboot --apple.

It works fine if you wait a second and retry.. so do that.

Also, add the "lazy" argument so you can do lazy unmounts if you like.
---
src/pylorax/imgutils.py | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/pylorax/imgutils.py b/src/pylorax/imgutils.py
index 164c554..5ec6e8a 100644
--- a/src/pylorax/imgutils.py
+++ b/src/pylorax/imgutils.py
@@ -26,6 +26,7 @@ from pylorax.sysutils import cpfile
from subprocess import *
import sys
import traceback
+from time import sleep

######## Functions for making container images (cpio, squashfs) ##########

@@ -119,13 +120,31 @@ def mount(dev, opts="", mnt=None):
check_call(mount)
return mnt

-def umount(mnt):
- 'Unmount the given mountpoint. If the mount was a temporary dir created
- by mount, it will be deleted. Returns false if the unmount fails.'
+def umount(mnt, lazy=False, maxretry=3, retrysleep=1.0):
+ 'Unmount the given mountpoint. If lazy is True, do a lazy umount (-l).
+ If the mount was a temporary dir created by mount, it will be deleted.
+ raises CalledProcessError if umount fails.'
umount = ["umount"]
+ if lazy: umount += ["-l"]
umount += [mnt]
logger.debug(" ".join(umount))
- rv = call(umount)
+ count = 0
+ while maxretry > 0:
+ try:
+ rv = check_call(umount)
+ except CalledProcessError:
+ count += 1
+ if count == maxretry:
+ raise
+ logger.warn("failed to unmount %s. retrying (%d/%d)...",
+ mnt, count, maxretry)
+ if logger.getEffectiveLevel() <= logging.DEBUG:
+ fuser = check_output(["fuser", "-vm", mnt],
+ stderr=STDOUT)
+ logger.debug("fuser -vm:
%s
", fuser)
+ sleep(retrysleep)
+ else:
+ break
if 'lorax.imgutils' in mnt:
os.rmdir(mnt)
logger.debug("remove tmp mountdir %s", mnt)
--
1.7.10.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


All times are GMT. The time now is 09:47 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.