Example #1
0
    def _putMetadata(cls, metaId, meta):
        vgname, offs = metaId

        data = cls.formatMetadata(meta)
        data += "\0" * (volume.METADATA_SIZE - len(data))

        metavol = lvm.lvPath(vgname, sd.METADATA)
        with fileUtils.DirectFile(metavol, "r+d") as f:
            f.seek(offs * volume.METADATA_SIZE)
            f.write(data)
Example #2
0
    def __putMetadata(cls, metaId, meta):
        vgname, offs = metaId

        lines = [
            "%s=%s\n" % (key.strip(), str(value).strip())
            for key, value in meta.iteritems()
        ]
        lines.append("EOF\n")

        metavol = lvm.lvPath(vgname, sd.METADATA)
        with fileUtils.DirectFile(metavol, "r+d") as f:
            data = "".join(lines)
            if len(data) > VOLUME_METASIZE:
                raise se.MetadataOverflowError(data)

            data += "\0" * (VOLUME_METASIZE - len(data))

            f.seek(offs * VOLUME_METASIZE)
            f.write(data)
Example #3
0
    def __putMetadata(cls, meta, metaid):
        vgname = metaid[0]
        offs = metaid[1]
        lines = [
            "%s=%s\n" % (key.strip(), str(value).strip())
            for key, value in meta.iteritems()
        ]
        lines.append("EOF\n")
        metavol = lvm.lvPath(vgname, sd.METADATA)
        with fileUtils.DirectFile(metavol, "r+d") as f:
            data = "".join(lines)
            if len(data) > VOLUME_METASIZE:
                cls.log.warn("Truncating volume metadata (%s)", data)
                data = data[:VOLUME_METASIZE]
            else:
                data += "\0" * (VOLUME_METASIZE - len(data))

            f.seek(offs * VOLUME_METASIZE)
            f.write(data)
Example #4
0
    def writelines(self, lines):
        lvm.activateLVs(self._vgName, self._lvName)

        # Write `metadata' to metadata volume
        metaStr = StringIO()

        for line in lines:
            metaStr.write(line)
            metaStr.write("\n")

        if metaStr.pos > self._size:
            raise se.MetadataOverflowError()

        # Clear out previous data - it is a volume, not a file
        metaStr.write('\0' * (self._size - metaStr.pos))

        data = metaStr.getvalue()
        with fileUtils.DirectFile(self.metavol, "r+d") as f:
            f.seek(self._offset)
            f.write(data)