sometimes mic can't know if the device can be released,
and it will bump up to maxinum used number, now record
an pid file for each used device so that they can be
released when needed
Change-Id: I24308eebd8b2c10a46f2bf20cfdb70bf7f1b04a2
Signed-off-by: Gui Chen <gui.chen@intel.com>
elif self.loopid:
os.unlink(self.device)
+DEVICE_PIDFILE_DIR = "/var/tmp/mic/device"
+
def get_loop_device(losetupcmd, lofile):
import fcntl
fp = open("/var/lock/__mic_loopdev.lock", 'w')
devinst.reg_atexit()
+ # try to save device and pid
+ makedirs(DEVICE_PIDFILE_DIR)
+ pidfile = os.path.join(DEVICE_PIDFILE_DIR, os.path.basename(loopdev))
+ if os.path.exists(pidfile):
+ os.unlink(pidfile)
+ with open(pidfile, 'w') as wf:
+ wf.write(str(os.getpid()))
+
except MountError, err:
raise CreatorError("%s" % str(err))
except: