logger.debug('NFS unmount complete.') logger.debug('Saving synclog to disk.') try: tsumufs.syncLog.flushToDisk() except Exception, e: logger.debug('Unable to save synclog -- caught an exception.') tsumufs.syslogCurrentException() else: logger.debug('Synclog saved.') logger.debug('SyncThread shutdown complete.') except Exception, e: tsumufs.syslogCurrentException() @extendedattribute('root', 'tsumufs.pause-sync') def xattr_pauseSync(type_, path, value=None): try: if value != None: if value == '0': tsumufs.syncPause.clear() elif value == '1': tsumufs.syncPause.set() else: return -errno.EOPNOTSUPP return if tsumufs.syncPause.isSet():
def run(self): try: while not tsumufs.unmounted.isSet(): logger.debug('TsumuFS not unmounted yet.') while (not tsumufs.nfsAvailable.isSet() and not tsumufs.unmounted.isSet()): logger.debug('NFS unavailable') if not tsumufs.forceDisconnect.isSet(): self._attemptMount() tsumufs.unmounted.wait(5) else: logger.debug(('...because user forced disconnect. ' 'Not attempting mount.')) time.sleep(5) while tsumufs.syncPause.isSet(): logger.debug('User requested sync pause. Sleeping.') time.sleep(5) while (tsumufs.nfsAvailable.isSet() and not tsumufs.unmounted.isSet() and not tsumufs.syncPause.isSet()): try: logger.debug('Checking for items to sync.') (item, change) = tsumufs.syncLog.popChange() except IndexError: logger.debug('Nothing to sync. Sleeping.') time.sleep(5) continue logger.debug('Got one: %s' % repr(item)) try: # Handle the change logger.debug('Handling change.') self._handleChange(item, change) # Mark the change as complete. logger.debug('Marking change %s as complete.' % repr(item)) try: tsumufs.syncLog.finishedWithChange(item) except Exception, e: exc_info = sys.exc_info() logger.debug('*** Unhandled exception occurred') logger.debug('*** Type: %s' % str(exc_info[0])) logger.debug('*** Value: %s' % str(exc_info[1])) logger.debug('*** Traceback:') for line in traceback.extract_tb(exc_info[2]): logger.debug('*** %s(%d) in %s: %s' % line) except IOError, e: logger.debug('Caught an IOError in the middle of handling a change: ' '%s' % str(e)) logger.debug('Disconnecting from NFS.') tsumufs.nfsAvailable.clear() tsumufs.nfsMount.unmount() logger.debug('Not removing change from the synclog, but finishing.') tsumufs.syncLog.finishedWithChange(item, remove_item=False) logger.debug('Shutdown requested.') logger.debug('Unmounting NFS.') try: tsumufs.nfsMount.unmount() except: logger.debug('Unable to unmount NFS -- caught an exception.') tsumufs.syslogCurrentException() else: logger.debug('NFS unmount complete.') logger.debug('Saving synclog to disk.') try: tsumufs.syncLog.flushToDisk() except Exception, e: logger.debug('Unable to save synclog -- caught an exception.') tsumufs.syslogCurrentException()
def run(self): try: while not tsumufs.unmounted.isSet(): self._debug('TsumuFS not unmounted yet.') while (not self.replicationCheckOk() and not tsumufs.unmounted.isSet()): self._debug('Replication from server unavailable') time.sleep(5) while (not tsumufs.fsMount.fsMountCheckOK() and not tsumufs.unmounted.isSet()): self._debug('FS unavailable') if not tsumufs.forceDisconnect.isSet(): self._debug('Trying to mount fs') self._attemptMount() time.sleep(5) else: self._debug(('...because user forced disconnect. ' 'Not attempting mount.')) time.sleep(5) while (tsumufs.syncPause.isSet() and not tsumufs.unmounted.isSet()): self._debug('User requested sync pause. Sleeping.') time.sleep(5) while (tsumufs.fsMount.fsMountCheckOK() and not tsumufs.unmounted.isSet() and not tsumufs.syncPause.isSet()): self._debug('Checking for items to sync.') for (item, change) in tsumufs.syncLog.popChanges(): self._debug('Got one: %s' % repr(item)) if tsumufs.syncPause.isSet(): self._debug('... but user requested sync pause.') tsumufs.syncLog.finishedWithChange(item, remove_item=False) break try: tsumufs.syncWork.set() try: # Handle the change self._debug('Handling change.') self._handleChange(item, change) # Mark the change as complete. self._debug('Marking change %s as complete.' % repr(item)) tsumufs.syncLog.finishedWithChange(item) tsumufs.syncWork.clear() except Exception, e: exc_info = sys.exc_info() self._debug('*** Unhandled exception occurred') self._debug('*** Type: %s' % str(exc_info[0])) self._debug('*** Value: %s' % str(exc_info[1])) self._debug('*** Traceback:') for line in traceback.extract_tb(exc_info[2]): self._debug('*** %s(%d) in %s: %s' % line) raise e except Exception, e: self._debug('Caught an IOError in the middle of handling a change: ' '%s' % str(e)) self._debug('Disconnecting from fs.') tsumufs.fsAvailable.clear() tsumufs.fsMount.unmount() self._debug('Not removing change from the synclog, but finishing.') tsumufs.syncLog.finishedWithChange(item, remove_item=False) tsumufs.syncWork.clear() break self._debug('Shutdown requested.') self._debug('Unmounting fs.') try: tsumufs.fsMount.unmount() except: self._debug('Unable to unmount fs -- caught an exception.') tsumufs.syslogCurrentException() else: self._debug('fs unmount complete.') self._debug('Syncing changes to disk.') try: tsumufs.syncLog.checkpoint() except Exception, e: self._debug('Unable to commit changes -- caught an exception.') tsumufs.syslogCurrentException()