def shutdown(self):
     """Backend Shutdown callback"""
     self.LOG(E_ALWAYS, self._prefix + '(%s): shutting down' % self.type)
     try:
         stat(self.image)
         self.umount()
     except:
         pass
     ## Shutdown PGSQL Backend
     BackendPGSQL.shutdown(self)
    def __init__(self, config, stage_type, ar_globals):
        """The constructor"""

        self._prefix = 'VFSImage Backend: '

        ### Init PGSQL Backend
        BackendPGSQL.__init__(self, config, 'archive', ar_globals, self._prefix)
        # Avoid any chance to call uneeded methods
        self.process_archive = None
        self.parse_recipients = None

        self.config = config
        self.type = stage_type

        if self.type != 'storage':
            raise StorageTypeNotSupported, self.type

        self.LOG = ar_globals['LOG']
        self.user = ar_globals['runas']

        if platform.find('linux') == -1:
            raise VFSError, 'This backend only works on Linux'

        error = None
        try:
            self.imagebase= config.get(self.type, 'imagebase')
            self.mountpoint = config.get(self.type, 'mountpoint')
            self.label = config.get(self.type, 'label')
            self.archiverdir = config.get(self.type, 'archiverdir')
            self.imagesize = config.getint(self.type, 'imagesize')
        except:
            t, val, tb = exc_info()
            del t, tb
            error = str(val)

        if error is not None:
            self.LOG(E_ERR, self._prefix + 'Bad config file: %s' % error)
            raise BadConfig

        self.image = self.imagebase + '.img'
        try:
            self.compression = config.get(self.type, 'compression')
        except:
            self.compression = None

        error = None
        if self.compression is not None:
            try:
                compressor, ratio = self.compression.split(':')
                ratio = int(ratio)
                if ratio < 0 or ratio > 9:
                    error = 'Invalid compression ratio'
                elif not compressors.has_key(compressor.lower()):
                    error = 'Compression type not supported'
                self.compression = (compressor, ratio)
            except:
                error = 'Unparsable compression entry in config file'

        if error is not None:
            self.LOG(E_ERR, self._prefix + 'Invalid compression option: %s' % error)
            raise BadConfig, 'Invalid compression option'

        if not access(self.mountpoint, F_OK | R_OK | W_OK):
            self.LOG(E_ERR, self._prefix + 'Mount point is not accessible: %s' % self.mountpoint)
            raise VFSError, 'Mount point is not accessible'

        if self.isMounted():
            self.LOG(E_ERR, self._prefix + 'Image already mounted')
            if not self.umount():
                raise VFSError, 'Cannot umount image'

        isPresent = True
        try:
            stat(self.image)
        except:
            isPresent = False

        if isPresent and not self.initImage():
            raise VFSError, 'Cannot init Image'
        else:
            self.LOG(E_ALWAYS, self._prefix + 'Image init postponed')


        self.LOG(E_ALWAYS, self._prefix + '(%s) at %s' % (self.type, self.image))