Esempio n. 1
0
 def create_lock(self, cur_dir, ami_path, exclusive):
     if ami_path == "":
         if cur_dir == None:
             ami_path = "SYS:"
         else:
             ami_path = cur_dir.ami_path
     else:
         ami_path = self.path_mgr.ami_abs_path(cur_dir, ami_path)
     sys_path = self.path_mgr.ami_to_sys_path(cur_dir,
                                              ami_path,
                                              searchMulti=True)
     name = self.path_mgr.ami_name_of_path(cur_dir, ami_path)
     if sys_path == None:
         log_lock.info("lock '%s' invalid: no sys path found: '%s'", name,
                       ami_path)
         return None
     exists = os.path.exists(sys_path)
     if not exists:
         log_lock.info(
             "lock '%s' invalid: sys path does not exist: '%s' -> '%s'",
             name,
             ami_path,
             sys_path,
         )
         return None
     lock = Lock(name, ami_path, sys_path, exclusive)
     self._register_lock(lock)
     return lock
Esempio n. 2
0
 def _register_lock(self, lock):
   # look up volume
   volume_name = self.path_mgr.ami_volume_of_path(lock.ami_path)
   log_lock.debug("fl_Volume: looking up volume '%s' of %s",volume_name,lock)
   volume = self.dos_list.get_entry_by_name(volume_name)
   if volume is None:
     vol_baddr = 0
     log_lock.warn("lock volume? volume=%s lock=%s",volume,lock)
   else:
     vol_baddr = volume.mem.addr
   # allocate lock struct
   b_addr = lock.alloc(self.alloc, vol_baddr, self.generate_key)
   self.locks_by_baddr[b_addr] = lock
   log_lock.info("registered: %s" % lock)
Esempio n. 3
0
    def _unregister_lock(self, lock):
        log_lock.info("unregistered: %s" % lock)
        # fetch key and lock_key
        slot_id = lock.key
        lock_key = self.keys[slot_id]
        # remove lock in key
        lock_key.del_lock(lock)
        # last lock in key?
        if lock_key.no_locks():
            del self.sys_path_to_key_map[lock.sys_path]
            self.locks.free(slot_id)

        # free lock itself
        lock.free(self.alloc)
        del lock
Esempio n. 4
0
 def create_lock(self, cur_dir, ami_path, exclusive):
   if ami_path == '':
     if cur_dir == None:
       ami_path = "SYS:"
     else:
       ami_path = cur_dir.ami_path
   else:
     ami_path = self.path_mgr.ami_abs_path(cur_dir,ami_path)
   sys_path = self.path_mgr.ami_to_sys_path(cur_dir,ami_path,searchMulti=True)
   name     = self.path_mgr.ami_name_of_path(cur_dir,ami_path)
   if sys_path == None:
     log_lock.info("lock '%s' invalid: no sys path found: '%s'", name, ami_path)
     return None
   exists = os.path.exists(sys_path)
   if not exists:
     log_lock.info("lock '%s' invalid: sys path does not exist: '%s' -> '%s'", name, ami_path, sys_path)
     return None
   lock = Lock(name, ami_path, sys_path, exclusive)
   self._register_lock(lock)
   return lock
Esempio n. 5
0
    def _register_lock(self, lock):
        # look up volume
        volume_name = self.path_mgr.ami_volume_of_path(lock.ami_path)
        log_lock.debug("fl_Volume: looking up volume '%s' of %s", volume_name, lock)
        volume = self.dos_list.get_entry_by_name(volume_name)
        if volume is None:
            vol_baddr = 0
            log_lock.warning("lock volume? volume=%s lock=%s", volume, lock)
        else:
            vol_baddr = volume.mem.addr

        # is key already assigned to sys_path?
        lock_key = self.sys_path_to_key_map.get(lock.sys_path)
        if not lock_key:
            # allocate new slot id
            lock_key = LockKey(lock.sys_path)
            slot_id = self.keys.alloc(lock_key)
            log_lock.debug(
                "allocate log key slot %s for sys_path '%s'", slot_id, lock.sys_path
            )
            if slot_id is None:
                log_lock.error("no more lock slots! max=%d", len(self.keys))
                return None
            lock_key.slot_id = slot_id
        else:
            slot_id = lock_key.slot_id
            log_lock.debug(
                "found log key slot %s for sys_path '%s'", slot_id, lock.sys_path
            )

        # allocate lock struct and use slot_id for key
        lock.alloc(self.alloc, vol_baddr, slot_id)

        # register lock in key (with baddr allocated above)
        lock_key.add_lock(lock)

        log_lock.info("registered: %s" % lock)
        return lock
Esempio n. 6
0
 def _unregister_lock(self, lock):
   log_lock.info("unregistered: %s" % lock)
   del self.locks_by_baddr[lock.b_addr]
   lock.free(self.alloc)
   del lock