Ejemplo n.º 1
0
Archivo: spa.py Proyecto: fhriley/zfspy
    def load_labels(self, dev):
        """
        Load vdev label informations, return the four labels

        Return
            [VDevLabel]
        """
        l = []
        l.append(VDevLabel(ZIO.read(dev, 0, VDEVLABEL_SIZE)))
        l.append(VDevLabel(ZIO.read(dev, VDEVLABEL_SIZE, VDEVLABEL_SIZE)))
        l.append(VDevLabel(ZIO.read(dev, -VDEVLABEL_SIZE * 2, VDEVLABEL_SIZE, 2)))
        l.append(VDevLabel(ZIO.read(dev, -VDEVLABEL_SIZE, VDEVLABEL_SIZE, 2)))
        return l
Ejemplo n.º 2
0
    def load_labels(self, dev):
        """
        Load vdev label informations, return the four labels

        Return
            [VDevLabel]
        """
        l = []
        l.append(VDevLabel(ZIO.read(dev, 0, VDEVLABEL_SIZE)))
        l.append(VDevLabel(ZIO.read(dev, VDEVLABEL_SIZE, VDEVLABEL_SIZE)))
        l.append(
            VDevLabel(ZIO.read(dev, -VDEVLABEL_SIZE * 2, VDEVLABEL_SIZE, 2)))
        l.append(VDevLabel(ZIO.read(dev, -VDEVLABEL_SIZE, VDEVLABEL_SIZE, 2)))
        return l
Ejemplo n.º 3
0
    def get_blk(self, id):
        """
        Get level0 block of this dnode by id
        
        indirect block onlys contain block pointers, its size is 1 << indblkshift. maxblkid is the max id
        of level 0 blocks
        """
        bp_per_indirectblk = (1 << self.indblkshift) / BlockPtr_SIZE
        if id > self.maxblkid:
            return None

        debug('bp_per_indirectblk=%d, nlevels %d' %
              (bp_per_indirectblk, self.nlevels))

        # compute offset of every level from bottom to top
        map = []
        blkid = id
        for level in range(0, self.nlevels - 1):
            blkid, offset = blkid / bp_per_indirectblk, blkid % bp_per_indirectblk
            map.append((blkid, offset))
        debug('levels offset for blkid %d: %s' % (id, map))
        toplevel_blkid = blkid
        # top level only can have 3 blocks at most, its blkid must be less than
        # the number of real blkptr we have. if it's greater than 3, it means that
        # we should have one more level then.
        if toplevel_blkid >= len(self.blkptr):
            return None
        bp = self.blkptr[toplevel_blkid]
        blk_data = ZIO.read_blk(self.vdev, bp)
        levels = range(self.nlevels - 1)
        levels.reverse()
        for level in levels:
            # offset in blk really matters, blkid in level doesn't
            offset = map[level][1]
            debug('offset %d in level %d' % (offset, level))
            bp = BlockPtr(get_record(blk_data, BlockPtr_SIZE, offset))
            blk_data = ZIO.read_blk(self.vdev, bp)
        return blk_data
Ejemplo n.º 4
0
Archivo: dmu.py Proyecto: fhriley/zfspy
    def get_blk(self, id):
        """
        Get level0 block of this dnode by id
        
        indirect block onlys contain block pointers, its size is 1 << indblkshift. maxblkid is the max id
        of level 0 blocks
        """
        bp_per_indirectblk = (1 << self.indblkshift) / BlockPtr_SIZE
        if id > self.maxblkid:
            return None
        
        debug('bp_per_indirectblk=%d, nlevels %d' %(bp_per_indirectblk, self.nlevels))

        # compute offset of every level from bottom to top
        map = []
        blkid = id
        for level in range(0, self.nlevels-1):
            blkid, offset = blkid / bp_per_indirectblk, blkid % bp_per_indirectblk
            map.append((blkid, offset))
        debug('levels offset for blkid %d: %s' % (id, map))
        toplevel_blkid = blkid
        # top level only can have 3 blocks at most, its blkid must be less than 
        # the number of real blkptr we have. if it's greater than 3, it means that
        # we should have one more level then.
        if toplevel_blkid >= len(self.blkptr):
            return None
        bp = self.blkptr[toplevel_blkid]
        blk_data = ZIO.read_blk(self.vdev, bp)
        levels = range(self.nlevels - 1)
        levels.reverse()
        for level in levels: 
            # offset in blk really matters, blkid in level doesn't
            offset = map[level][1]
            debug('offset %d in level %d' % (offset, level))
            bp = BlockPtr(get_record(blk_data, BlockPtr_SIZE, offset))
            blk_data = ZIO.read_blk(self.vdev, bp)
        return blk_data