Example #1
0
def explore_path(path, pattern):
    state = LockState()
    for e in path.effects:
        if state.is_locked():
            state.add(e)

        if isinstance(e, PathCall):
            if is_lock(e.func):
                dbg.trace("%s", e)
                state.lock(e)
            elif is_unlock(e.func):
                dbg.trace("%s", e)

                # NOTE. ignore 'reclaimed' for now, which do not
                # consider nested locks, so regrep such elements by
                # ourselves
                (lock, _, unlock) = state.unlock(e)
                if lock and unlock:
                    reclaimed = _grep(lock, path.effects, unlock)
                    pattern.collect(lock, reclaimed, unlock)

    if len(state.locks) > 1:
        for l in state.locks:
            if not "try" in l.func:
                state.err("not resolved", str(l), l.loc)

    return state
Example #2
0
def _load_fops(pn):

    def _load_struct(fd):
        pair = {}
        for l in fd:
            l = l.strip()
            if "};" in l or l.startswith("&") or l == "":
                break
            dbg.trace("%s", l)
            (lhs, rhs) = l.split("=")
            lhs = lhs.lstrip(".").strip()
            rhs = rhs.rstrip(" ,").strip()
            pair[lhs] = rhs
        return pair

    conf = []
    fd = open(pn)
    for l in fd:
        l = l.strip()
        if l == "" or l.startswith("#"):
            continue
        if l.endswith("{"):
            val = _load_struct(fd)
            key = l.rstrip(" {").split("/")
            dbg.trace("%s", key)
            if len(key) == 0:
                continue
            conf.append((key, val))
    return conf
Example #3
0
def _load_fops(pn):

    def _load_struct(fd):
        pair = {}
        for l in fd:
            l = l.strip()
            if "};" in l or l.startswith("&") or l == "":
                break
            dbg.trace("%s", l)
            (lhs, rhs) = l.split("=")
            lhs = lhs.lstrip(".").strip()
            rhs = rhs.rstrip(" ,").strip()
            pair[lhs] = rhs
        return pair

    conf = []
    fd = open(pn)
    for l in fd:
        l = l.strip()
        if l == "" or l.startswith("#"):
            continue
        if l.endswith("{"):
            val = _load_struct(fd)
            key = l.rstrip(" {").split("/")
            dbg.trace("%s", key)
            if len(key) == 0:
                continue
            conf.append((key, val))
    return conf
Example #4
0
 def _load_struct(fd):
     pair = {}
     for l in fd:
         l = l.strip()
         if "};" in l or l.startswith("&") or l == "":
             break
         dbg.trace("%s", l)
         (lhs, rhs) = l.split("=")
         lhs = lhs.lstrip(".").strip()
         rhs = rhs.rstrip(" ,").strip()
         pair[lhs] = rhs
     return pair
Example #5
0
 def _load_struct(fd):
     pair = {}
     for l in fd:
         l = l.strip()
         if "};" in l or l.startswith("&") or l == "":
             break
         dbg.trace("%s", l)
         (lhs, rhs) = l.split("=")
         lhs = lhs.lstrip(".").strip()
         rhs = rhs.rstrip(" ,").strip()
         pair[lhs] = rhs
     return pair
Example #6
0
def check_args(r, a):
    for k in r.args:
        # ignore mmap/munmap: addr (ASLR, change every execution)
        if r.nr in [syscall.NR_mmap, syscall.NR_munmap] and k == "addr":
            continue

        # ignore ioctl buf (user address) argment, (XXX need to check its value)
        if r.nr in [syscall.NR_ioctl] and k == "buf":
            continue

        # compare inode instead of `fd' number
        if isinstance(a.args[k], sysarg.file):
            # like, fd != -1 & pts and socket
            if (a.args[k].inode
                    and a.args[k].inode.prefix in ["pts", "socket"]):
                continue
            if a.args[k].inode != r.args[k].inode:
                dbg.trace("1)", a.args[k])
                dbg.trace("2)", r.args[k])
                return False
            continue

        # check identical
        if a.args[k] != r.args[k]:
            if r.nr == syscall.NR_open:
                # TODO(ipopov). Check this. It seems that the argument to open() should
                # not include the inode opened. Surely that belongs in the return value
                # of the syscall. Handling this here is a hack, and it needs to be
                # moved into a more general place.
                if (a.args[k].path == r.args[k].path
                        and a.args[k].root_in == r.args[k].root_in
                        and a.args[k].root_pn == r.args[k].root_pn
                        and a.args[k].pathid == a.args[k].pathid):
                    dbg.rerun(
                        'short circuiting. returning True. would have returned %s.'
                        % (str(a.args[k]) == str(r.args[k])))
                    continue
            # slow path: because some obj could be deep-copied, str -> repr
            if str(a.args[k]) == str(r.args[k]):
                continue
            # but sometimes, this str representation gets messed up for whatever
            # reason, so handle this special case here:
            # (needless to say, TODO: get some more sane argument checking here)
            if isinstance(a.args[k], list):
                if str(set(a.args[k])) == str(set(r.args[k])):
                    dbg.trace('hi ivo!')
                    continue
            dbg.trace("1)", a.args[k])
            dbg.trace("2)", r.args[k])
            return False
    return True
Example #7
0
def cmd_ready(fd, args):
    """index osloader: ready for what, info"""

    dbg.trace("loading: %s" % str(args))
    if args[0] == "socket":
        # XXX
        # for now, load everything
        osloader.load(None,None)
        dbg.trace("#%d objs loaded" % len(mgrapi.RegisteredObject.all()))

        # now ready for undoing/redoing
        The(CtrlFSM).set_state("ready")

    rtn_cmd(fd, "done")
Example #8
0
    def dataReceived(self, data):
        global gcmds

        toks = pickle.loads(data)
        cmds = The(CtrlFSM).get_trans()

        dbg.trace("[%s] got: %s" % (The(CtrlFSM).curstate, toks))

        if len(toks) == 0:
            cmd_invalid(self.transport, toks)
            return

        f = cmds.get(toks[0], None)
        if f is None:
            f = gcmds.get(toks[0], None)

        if f:
            f(self.transport, toks[1:])
        else:
            cmd_invalid(self.transport, toks)
Example #9
0
def cmd_rollback(fd, args):
    """rollback request from other dctrls"""

    if args[0] == "socket":
        sip   = args[1]
        sport = args[2]
        dport = args[3]

        # network node
        for p in sport:
            o = networkmgr.NetworkNode.lookup(sip, p)
            assert o
            dbg.trace("found %s:%s for %s" % (sip, p, o))
            dbg.trace("r:%s" % str(o.readers))
            dbg.trace("w:%s" % str(o.writers))

            # make sock behave like slave
            o.master = False
            chk = min(o.checkpoints)
            The(CtrlFSM).rollback(o, chk)

        The(CtrlFSM).set_state("repairing")

        # intentionally sleep to yield python thread
        time.sleep(1)

        rtn_cmd(fd, "done")
Example #10
0
    def collect(self, lock, protected, unlock):
        if len(lock.args) != 1:
            return
        arg = lock.args[0]

        # handle struct type & global lock
        matches = [
            (r"^&(\w+)->(\w+)$", self.handle_member_protected),
            (r"^&([\w_>\-]+)$", self.handle_global_lock),
        ]

        for (regexp, fn) in matches:
            m = re.match(regexp, str(arg))
            if m:
                fn(protected, lock, *m.groups())

        dbg.trace("paired: #%d protected" % len(protected))
        dbg.trace(" > %s" % lock)
        for e in protected:
            dbg.trace("     %s", e)
        dbg.trace(" < %s", unlock)