Exemplo n.º 1
0
    def calcReadPossibleData(self, op, packState):
        """
        Calculate read possibilities for each block.
        
        """
        assert (isinstance(packState, PackState))
        pack = packState.pack()
        if pack.isWrite():
            return
        assert (isinstance(packState, ReadPackState))
        if op != ReadPackState.SUBMIT:  # not just after began.
            return

        def possibleDataWithCondition1(addr):
            """
            addr :: int
            return :: int
            
            """
            assert (isinstance(addr, int))
            firstOverlapPackS = None
            packId = self.totalNumPacks() - 1
            while packId >= 0:
                packS = self.packStateList()[packId]
                if (packS.isEnd() and packS.pack().isWrite()
                        and hasAddr(packS.pack(), addr)):
                    firstOverlapPackS = packS
                    break
                packId -= 1
            if firstOverlapPackS is None:
                return dataAt(self.fStorage(), addr)
            else:
                return dataAt(firstOverlapPackS.pack(), addr)

        def possiblePackStateListWithCondition2a(addr):
            """
            addr :: int
            return :: [PackStateList]
            
            """
            assert (isinstance(addr, int))

            def f1(packS):
                assert (isinstance(packS, PackState))
                return (not packS.isEnd() and packS.pack().isWrite()
                        and hasAddr(packS.pack(), addr))

            #return filter(f1, self.packStateList()[self.firstNotEndedPackId():])
            return filter(f1, self.packStateList())

        # calculate possibleData for each block in the pack.
        for addr in forAllAddrInPack(pack):
            writtenData = possibleDataWithCondition1(addr)
            possiblePackStateL = possiblePackStateListWithCondition2a(addr)
            if False:  #debug
                print packState.pack().pid(), addr, '___', [writtenData] + \
                    map(lambda packS: dataAt(packS.pack(), addr), possiblePackStateL)
            possibleData = (writtenData, possiblePackStateL)
            packState.setPossibleData(addr, possibleData)
        pass
Exemplo n.º 2
0
    def calcReadPossibleData(self, op, packState):
        """
        Calculate read possibilities for each block.
        
        """
        assert(isinstance(packState, PackState))
        pack = packState.pack()
        if pack.isWrite():
            return
        assert(isinstance(packState, ReadPackState))
        if op != ReadPackState.SUBMIT: # not just after began.
            return
        
        def possibleDataWithCondition1(addr):
            """
            addr :: int
            return :: int
            
            """
            assert(isinstance(addr, int))
            firstOverlapPackS = None
            packId = self.totalNumPacks() - 1
            while packId >= 0:
                packS = self.packStateList()[packId]
                if (packS.isEnd() and
                    packS.pack().isWrite() and
                    hasAddr(packS.pack(), addr)):
                    firstOverlapPackS = packS
                    break
                packId -= 1
            if firstOverlapPackS is None:
                return dataAt(self.fStorage(), addr)
            else:
                return dataAt(firstOverlapPackS.pack(), addr)
        def possiblePackStateListWithCondition2a(addr):
            """
            addr :: int
            return :: [PackStateList]
            
            """
            assert(isinstance(addr, int))
            def f1(packS):
                assert(isinstance(packS, PackState))
                return (not packS.isEnd() and 
                        packS.pack().isWrite() and
                        hasAddr(packS.pack(), addr))
            #return filter(f1, self.packStateList()[self.firstNotEndedPackId():])
            return filter(f1, self.packStateList())

        # calculate possibleData for each block in the pack.
        for addr in forAllAddrInPack(pack):
            writtenData = possibleDataWithCondition1(addr)
            possiblePackStateL = possiblePackStateListWithCondition2a(addr)
            if False: #debug
                print packState.pack().pid(), addr, '___', [writtenData] + \
                    map(lambda packS: dataAt(packS.pack(), addr), possiblePackStateL) 
            possibleData = (writtenData, possiblePackStateL)
            packState.setPossibleData(addr, possibleData)
        pass
Exemplo n.º 3
0
    def validateRead(self, op, packState):
        """
        Validate a read pack just after IO execution.

        op :: int
        packState :: PackState
        return :: None

        """
        assert (isinstance(packState, PackState))
        pack = packState.pack()
        if pack.isWrite():
            return
        assert (isinstance(packState, ReadPackState))
        if op != ReadPackState.END_REQ:  # not just after ended.
            return

        def possiblePackStateListWithCondition2b(addr, possiblePackStateList):
            """
            addr :: int
            possiblePackStateList :; [WritePackState]
            return :: [WritePackState]
            
            """
            assert (isinstance(addr, int))

            def f1(packS):
                assert (isinstance(packS, PackState))
                return (packS.isBegin() and packS.pack().isWrite()
                        and hasAddr(packS.pack(), addr))

            return filter(f1, possiblePackStateList)

        # validate data for each block in the pack.
        for addr in forAllAddrInPack(pack):
            readData = dataAt(pack, addr)
            writtenData, possibleStatePackL = packState.possibleData(addr)
            possibleDataL \
                = [writtenData] + \
                map(lambda packS: dataAt(packS.pack(), addr),
                    possiblePackStateListWithCondition2b(addr, possibleStatePackL))

            #print pack.pid(), addr, readData, possibleDataL #debug
            found = False
            for possibleData in possibleDataL:
                if readData == possibleData:
                    found = True
            if not found:  #debug
                for packS in self.packStateList():
                    print packS
            assert (found)
Exemplo n.º 4
0
    def validateRead(self, op, packState):
        """
        Validate a read pack just after IO execution.

        op :: int
        packState :: PackState
        return :: None

        """
        assert(isinstance(packState, PackState))
        pack = packState.pack()
        if pack.isWrite():
            return
        assert(isinstance(packState, ReadPackState))
        if op != ReadPackState.END_REQ: # not just after ended.
            return

        def possiblePackStateListWithCondition2b(addr, possiblePackStateList):
            """
            addr :: int
            possiblePackStateList :; [WritePackState]
            return :: [WritePackState]
            
            """
            assert(isinstance(addr, int))
            def f1(packS):
                assert(isinstance(packS, PackState))
                return (packS.isBegin() and 
                        packS.pack().isWrite() and
                        hasAddr(packS.pack(), addr))

            return filter(f1, possiblePackStateList)
        
        # validate data for each block in the pack.
        for addr in forAllAddrInPack(pack):
            readData = dataAt(pack, addr)
            writtenData, possibleStatePackL = packState.possibleData(addr)
            possibleDataL \
                = [writtenData] + \
                map(lambda packS: dataAt(packS.pack(), addr),
                    possiblePackStateListWithCondition2b(addr, possibleStatePackL))

            #print pack.pid(), addr, readData, possibleDataL #debug
            found = False
            for possibleData in possibleDataL:
                if readData == possibleData:
                    found = True
            if not found: #debug
                for packS in self.packStateList():
                    print packS
            assert(found)
Exemplo n.º 5
0
    def execute(self, op, vStorage, rStorage):

        assert(isinstance(op, int))
        assert(isinstance(vStorage, DiskImage))
        assert(isinstance(rStorage, DiskImage))

        assert(op >= 0)
        assert(op < WritePackState.N_OP)
        self.setSt(op)

        if op == WritePackState.WRITE_RSTORAGE:
            #print 'Write rStorage', self.pack()
            self.executeIO(rStorage)
            if False:
                for addr in forAllAddrInPack(self.pack()): #debug
                    print self.pack().pid(), addr, 'Write', dataAt(self.pack(), addr)
            
        if op == WritePackState.WRITE_VSTORAGE:
            #print 'Write vStorage', self.pack()
            self.executeIO(vStorage)
Exemplo n.º 6
0
    def execute(self, op, vStorage, rStorage):

        assert (isinstance(op, int))
        assert (isinstance(vStorage, DiskImage))
        assert (isinstance(rStorage, DiskImage))

        assert (op >= 0)
        assert (op < WritePackState.N_OP)
        self.setSt(op)

        if op == WritePackState.WRITE_RSTORAGE:
            #print 'Write rStorage', self.pack()
            self.executeIO(rStorage)
            if False:
                for addr in forAllAddrInPack(self.pack()):  #debug
                    print self.pack().pid(), addr, 'Write', dataAt(
                        self.pack(), addr)

        if op == WritePackState.WRITE_VSTORAGE:
            #print 'Write vStorage', self.pack()
            self.executeIO(vStorage)