def __handleStuckUmount(cls, masterDir): umountPids = utils.pgrep("umount") try: masterMount = mount.getMountFromTarget(masterDir) except OSError as ex: if ex.errno == errno.ENOENT: return raise for umountPid in umountPids: try: state = utils.pidStat(umountPid).state mountPoint = utils.getCmdArgs(umountPid)[-1] except: # Process probably exited continue if mountPoint != masterDir: continue if state != "D": # If the umount is not in d state there # is a possibility that the world might # be in flux and umount will get stuck # in an unkillable state that is not D # which I don't know about, perhaps a # bug in umount will cause umount to # wait for something unrelated that is # not the syscall. Waiting on a process # which is not your child is race prone # I will just call for another umount # and wait for it to finish. That way I # know that a umount ended. try: masterMount.umount() except mount.MountError: # timeout! we are stuck again. # if you are here spmprotect forgot to # reboot the machine but in any case # continue with the disconnection. pass try: vgName = masterDir.rsplit("/", 2)[1] masterDev = os.path.join( "/dev/mapper", vgName.replace("-", "--") + "-" + MASTERLV) except KeyError: # Umount succeeded after all return cls.log.warn( "master mount resource is `%s`, trying to disconnect " "underlying storage", masterDev) iscsi.disconnectFromUndelyingStorage(masterDev)
def __handleStuckUmount(cls, masterDir): umountPids = utils.pgrep("umount") try: masterMount = mount.getMountFromTarget(masterDir) except OSError as ex: if ex.errno == errno.ENOENT: return raise for umountPid in umountPids: try: state = utils.pidStat(umountPid).state mountPoint = utils.getCmdArgs(umountPid)[-1] except: # Process probably exited continue if mountPoint != masterDir: continue if state != "D": # If the umount is not in d state there # is a possibility that the world might # be in flux and umount will get stuck # in an unkillable state that is not D # which I don't know about, perhaps a # bug in umount will cause umount to # wait for something unrelated that is # not the syscall. Waiting on a process # which is not your child is race prone # I will just call for another umount # and wait for it to finish. That way I # know that a umount ended. try: masterMount.umount() except mount.MountError: # timeout! we are stuck again. # if you are here spmprotect forgot to # reboot the machine but in any case # continue with the disconnection. pass try: vgName = masterDir.rsplit("/", 2)[1] masterDev = os.path.join( "/dev/mapper", vgName.replace("-", "--") + "-" + MASTERLV) except KeyError: # Umount succeeded after all return cls.log.warn("master mount resource is `%s`, trying to disconnect " "underlying storage", masterDev) iscsi.disconnectFromUndelyingStorage(masterDev)
def test_without_affinity(self): args = ["sleep", "3"] sproc = commands.execCmd(args, sync=False) stats = utils.pidStat(sproc.pid) pid = int(stats.pid) # procName comes in the format of (procname) name = stats.comm self.assertEquals(pid, sproc.pid) self.assertEquals(name, args[0]) sproc.kill() sproc.wait()
def test(self): args = ["sleep", "3"] sproc = utils.execCmd(args, sync=False) stats = utils.pidStat(sproc.pid) pid = int(stats.pid) # procName comes in the format of (procname) name = stats.comm self.assertEquals(pid, sproc.pid) self.assertEquals(name, args[0]) sproc.kill() sproc.wait()
def getCmdArgs(pid): res = tuple() # Sometimes cmdline is empty even though the process is not a zombie. # Retrying seems to solve it. while len(res) == 0: # cmdline is empty for zombie processes if utils.pidStat(pid).state in ("Z", "z"): return tuple() res = _parseCmdLine(pid) return res
def pgrep(name): res = [] for pid in iteratePids(): try: pid = int(pid) except ValueError: continue try: procName = utils.pidStat(pid).comm if procName == name: res.append(pid) except (OSError, IOError): continue return res
def test(): nice = utils.pidStat(proc.pid).nice self.assertEqual(nice, 10)
def test(): nice = utils.pidStat(proc.pid).nice self.assertEquals(nice, 10)