Federico Simoncelli has uploaded a new change for review.
Change subject: storage: kill ongoing operations on exit ......................................................................
storage: kill ongoing operations on exit
Some storage operations must be forcibly interrupted when the vdsm (parent) process exits.
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=713434 Change-Id: Ic6ff67cb687494099e332d2d7b1eb3a293d1b4e4 Signed-off-by: Federico Simoncelli fsimonce@redhat.com --- M lib/vdsm/utils.py M vdsm/storage/blockSD.py M vdsm/storage/curlImgWrap.py M vdsm/storage/misc.py M vdsm/storage/sp.py M vdsm/storage/storage_mailbox.py M vdsm/storage/volume.py 7 files changed, 35 insertions(+), 21 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/74/18074/1
diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py index 538498f..8890160 100644 --- a/lib/vdsm/utils.py +++ b/lib/vdsm/utils.py @@ -458,7 +458,8 @@
def execCmd(command, sudo=False, cwd=None, data=None, raw=False, logErr=True, printable=None, env=None, sync=True, nice=None, ioclass=None, - ioclassdata=None, setsid=False, execCmdLogger=logging.root): + ioclassdata=None, setsid=False, execCmdLogger=logging.root, + killOnExit=True): """ Executes an external command, optionally via sudo. """ @@ -485,7 +486,8 @@ cmdline = repr(subprocess.list2cmdline(printable)) execCmdLogger.debug("%s (cwd %s)", cmdline, cwd)
- p = BetterPopen(command, close_fds=True, cwd=cwd, env=env) + p = BetterPopen(command, close_fds=True, cwd=cwd, env=env, + deathSignal=(signal.SIGKILL if killOnExit else 0)) p = AsyncProc(p) if not sync: if data is not None: @@ -516,12 +518,14 @@
def watchCmd(command, stop, cwd=None, data=None, recoveryCallback=None, - nice=None, ioclass=None, execCmdLogger=logging.root): + nice=None, ioclass=None, execCmdLogger=logging.root, + killOnExit=False): """ Executes an external command, optionally via sudo with stop abilities. """ proc = execCmd(command, sudo=False, cwd=cwd, data=data, sync=False, - nice=nice, ioclass=ioclass, execCmdLogger=execCmdLogger) + nice=nice, ioclass=ioclass, execCmdLogger=execCmdLogger, + killOnExit=killOnExit) if recoveryCallback: recoveryCallback(proc)
diff --git a/vdsm/storage/blockSD.py b/vdsm/storage/blockSD.py index e8b2980..baca437 100644 --- a/vdsm/storage/blockSD.py +++ b/vdsm/storage/blockSD.py @@ -204,7 +204,8 @@ "of=%s" % lvm.lvPath(sdUUID, volUUID), "bs=%s" % BS, "count=%s" % count] p = misc.execCmd(cmd, sudo=False, sync=False, - nice=utils.NICENESS.HIGH, ioclass=utils.IOCLASS.IDLE) + nice=utils.NICENESS.HIGH, ioclass=utils.IOCLASS.IDLE, + killOnExit=True) return p
@@ -1084,7 +1085,7 @@ # If there is a journal already tune2fs will do nothing, indicating # this condition only with exit code. However, we do not really care. cmd = [constants.EXT_TUNE2FS, "-j", masterfsdev] - misc.execCmd(cmd, sudo=True) + misc.execCmd(cmd, sudo=True, killOnExit=True)
masterMount = mount.Mount(masterfsdev, masterDir)
@@ -1274,7 +1275,7 @@ Create a special file system to store VM data """ cmd = [constants.EXT_MKFS, "-q", "-j", "-E", "nodiscard", dev] - rc = misc.execCmd(cmd, sudo=True)[0] + rc = misc.execCmd(cmd, sudo=True, killOnExit=True)[0] if rc != 0: raise se.MkfsError(dev)
diff --git a/vdsm/storage/curlImgWrap.py b/vdsm/storage/curlImgWrap.py index 2f63311..e9b574e 100644 --- a/vdsm/storage/curlImgWrap.py +++ b/vdsm/storage/curlImgWrap.py @@ -63,7 +63,7 @@ cmd = [constants.EXT_CURL_IMG_WRAP, "--download"] cmd.extend(_headersToOptions(headers) + [path, url])
- rc, out, err = utils.execCmd(cmd) + rc, out, err = utils.execCmd(cmd, killOnExit=True)
if rc != 0: raise CurlError(rc, out, err) @@ -73,7 +73,7 @@ cmd = [constants.EXT_CURL_IMG_WRAP, "--upload"] cmd.extend(_headersToOptions(headers) + [path, url])
- rc, out, err = utils.execCmd(cmd) + rc, out, err = utils.execCmd(cmd, killOnExit=True)
if rc != 0: raise CurlError(rc, out, err) diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py index fe3a870..013eded 100644 --- a/vdsm/storage/misc.py +++ b/vdsm/storage/misc.py @@ -367,12 +367,14 @@
if not stop: (rc, out, err) = execCmd(cmd, sudo=False, nice=utils.NICENESS.HIGH, - ioclass=utils.IOCLASS.IDLE) + ioclass=utils.IOCLASS.IDLE, + killOnExit=True) else: (rc, out, err) = watchCmd(cmd, stop=stop, recoveryCallback=recoveryCallback, nice=utils.NICENESS.HIGH, - ioclass=utils.IOCLASS.IDLE) + ioclass=utils.IOCLASS.IDLE, + killOnExit=True)
if rc: raise se.MiscBlockWriteException(dst, offset, size) diff --git a/vdsm/storage/sp.py b/vdsm/storage/sp.py index 3f3c1bf..90c6313 100644 --- a/vdsm/storage/sp.py +++ b/vdsm/storage/sp.py @@ -2077,7 +2077,7 @@ try: if method.lower() == "wget": cmd = [constants.EXT_WGET, "-O", targetPath, srcPath] - (rc, out, err) = misc.execCmd(cmd, sudo=False) + (rc, out, err) = misc.execCmd(cmd, sudo=False, killOnExit=True)
if rc: self.log.error("uploadVolume - error while trying to " @@ -2086,7 +2086,7 @@ raise se.VolumeCopyError(vol, err) elif method.lower() == "rsync": cmd = [constants.EXT_RSYNC, "-aq", srcPath, targetPath] - (rc, out, err) = misc.execCmd(cmd, sudo=False) + (rc, out, err) = misc.execCmd(cmd, sudo=False, killOnExit=True)
if rc: self.log.error("uploadVolume - error while trying to copy:" diff --git a/vdsm/storage/storage_mailbox.py b/vdsm/storage/storage_mailbox.py index af3ccb8..38dff90 100644 --- a/vdsm/storage/storage_mailbox.py +++ b/vdsm/storage/storage_mailbox.py @@ -269,7 +269,8 @@
def _initMailbox(self): # Sync initial incoming mail state with storage view - (rc, out, err) = misc.execCmd(self._inCmd, sudo=False, raw=True) + (rc, out, err) = misc.execCmd(self._inCmd, sudo=False, raw=True, + killOnExit=True) if rc == 0: self._incomingMail = out self._init = True @@ -385,7 +386,8 @@ pChk = struct.pack('<l', chk) # Assumes CHECKSUM_BYTES equals 4!!! self._outgoingMail = \ self._outgoingMail[0:MAILBOX_SIZE - CHECKSUM_BYTES] + pChk - misc.execCmd(self._outCmd, data=self._outgoingMail, sudo=False) + misc.execCmd(self._outCmd, data=self._outgoingMail, sudo=False, + killOnExit=True)
def _handleMessage(self, message): # TODO: add support for multiple mailboxes @@ -569,7 +571,8 @@ self.log.debug("SPM_MailMonitor - clearing outgoing mail, command is: " "%s", self._outCmd) cmd = self._outCmd + ['bs=' + str(self._outMailLen)] - (rc, out, err) = misc.execCmd(cmd, sudo=False, data=self._outgoingMail) + (rc, out, err) = misc.execCmd(cmd, sudo=False, data=self._outgoingMail, + killOnExit=True) if rc: self.log.warning("SPM_MailMonitor couldn't clear outgoing mail, " "dd failed") @@ -742,7 +745,8 @@ try: cmd = self._outCmd + ['bs=' + str(self._outMailLen)] (rc, out, err) = misc.execCmd(cmd, sudo=False, - data=self._outgoingMail) + data=self._outgoingMail, + killOnExit=True) if rc: self.log.warning("SPM_MailMonitor couldn't write " "outgoing mail, dd failed") @@ -767,7 +771,8 @@ 'seek=' + str(mailboxOffset / MAILBOX_SIZE)] #self.log.debug("Running command: %s, for message id: %s", # str(cmd), str(msgID)) - (rc, out, err) = misc.execCmd(cmd, sudo=False, data=mailbox) + (rc, out, err) = misc.execCmd(cmd, sudo=False, data=mailbox, + killOnExit=True) if rc: self.log.error("SPM_MailMonitor: sendReply - couldn't send " "reply, dd failed") diff --git a/vdsm/storage/volume.py b/vdsm/storage/volume.py index 10b3363..3c3b378 100644 --- a/vdsm/storage/volume.py +++ b/vdsm/storage/volume.py @@ -1057,7 +1057,7 @@ # +1 is so that odd numbers will round upwards. cmd += [volume, "%uK" % ((size + 1) / 2)]
- (rc, out, err) = misc.execCmd(cmd, sudo=False, cwd=cwd) + (rc, out, err) = misc.execCmd(cmd, sudo=False, cwd=cwd, killOnExit=True) if rc: raise se.VolumeCreationError(out) return True @@ -1096,7 +1096,8 @@ (rc, out, err) = misc.watchCmd(cmd, stop=stop, cwd=cwd, recoveryCallback=recoveryCallback, ioclass=utils.IOCLASS.IDLE, - nice=utils.NICENESS.HIGH) + nice=utils.NICENESS.HIGH, + killOnExit=True)
log.debug('(qemuRebase): REBASE %s DONE' % (src)) return (rc, out, err) @@ -1124,7 +1125,8 @@ (rc, out, err) = misc.watchCmd(cmd, stop=stop, recoveryCallback=baseAsyncTasksRollback, ioclass=utils.IOCLASS.IDLE, - nice=utils.NICENESS.HIGH) + nice=utils.NICENESS.HIGH, + killOnExit=True)
log.debug('(qemuConvert): COPY %s to %s DONE' % (src, dst)) return (rc, out, err)