Beispiel #1
0
    def write(self, data):
        if not self._valid:
            raise exception.VolumeDriverException(name=self._vdiname)

        length = len(data)
        cmd = ('dog', 'vdi', 'write', '-a', self._addr, '-p', self._port,
               self._vdiname, self._offset, length)
        self._execute(cmd, data)
        self._offset += length
        return length
Beispiel #2
0
    def read(self, length=None):
        if not self._valid:
            raise exception.VolumeDriverException(name=self._vdiname)

        cmd = ['dog', 'vdi', 'read', '-a', self._addr, '-p', self._port]
        if self._snapshot_name:
            cmd.extend(('-s', self._snapshot_name))
        cmd.extend((self._vdiname, self._offset))
        if length:
            cmd.append(length)
        data = self._execute(cmd)
        self._offset += len(data)
        return data
Beispiel #3
0
 def _execute(self, cmd, data=None):
     try:
         # NOTE(yamada-h): processutils.execute causes busy waiting
         # under eventlet.
         # To avoid wasting CPU resources, it should not be used for
         # the command which takes long time to execute.
         # For workaround, we replace a subprocess module with
         # the original one while only executing a read/write command.
         _processutils_subprocess = processutils.subprocess
         processutils.subprocess = eventlet.patcher.original('subprocess')
         return processutils.execute(*cmd, process_input=data)[0]
     except (processutils.ProcessExecutionError, OSError):
         self._valid = False
         raise exception.VolumeDriverException(name=self._vdiname)
     finally:
         processutils.subprocess = _processutils_subprocess
Beispiel #4
0
    def seek(self, offset, whence=0):
        if not self._valid:
            raise exception.VolumeDriverException(name=self._vdiname)

        if whence == 0:
            # SEEK_SET or 0 - start of the stream (the default);
            # offset should be zero or positive
            new_offset = offset
        elif whence == 1:
            # SEEK_CUR or 1 - current stream position; offset may be negative
            new_offset = self._offset + offset
        else:
            # SEEK_END or 2 - end of the stream; offset is usually negative
            # TODO(yamada-h): Support SEEK_END
            raise IOError(
                _("Invalid argument - whence=%s not supported.") % whence)

        if new_offset < 0:
            raise IOError(_("Invalid argument - negative seek offset."))

        self._offset = new_offset