Changeset 165

Show
Ignore:
Timestamp:
12/30/08 00:32:25 (15 years ago)
Author:
broder
Message:

* Fix a bug that caused the old liblocker attach and add to not work.
* Keep the negative cache on a per-PID basis.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/source/pyhesiodfs/pyHesiodFS.py

    r163 r165  
    3838         
    3939        def __str__(self): 
    40             print 'defaultdict(%s, %s)' % (self.default_factory,  
    41                                            super(defaultdict, self).__str__()) 
     40            return 'defaultdict(%s, %s)' % (self.default_factory,  
     41                                            super(defaultdict, self).__str__()) 
    4242 
    4343class negcache(dict): 
     
    4949    """ 
    5050     
    51     def __init__(self, cache_time): 
     51    def __init__(self, cache_time=0.5): 
    5252        self.cache_time = cache_time 
    5353     
     
    5656     
    5757    def remove(self, obj): 
    58         del self[obj] 
     58        try: 
     59            del self[obj] 
     60        except KeyError: 
     61            pass 
    5962     
    6063    def __contains__(self, k): 
     
    119122        # Cache deletions for half a second - should give `ln -nsf` 
    120123        # enough time to make a new symlink 
    121         self.negcache = negcache(0.5
    122      
    123     def _user(self): 
     124        self.negcache = defaultdict(negcache
     125     
     126    def _uid(self): 
    124127        return fuse.FuseGetContext()['uid'] 
     128     
     129    def _gid(self): 
     130        return fuse.FuseGetContext()['gid'] 
     131     
     132    def _pid(self): 
     133        return fuse.FuseGetContext()['pid'] 
    125134     
    126135    def getattr(self, path): 
    127136        st = MyStat() 
    128137        if path == '/': 
    129             st.st_mode = stat.S_IFDIR | 0777 
     138            st.st_mode = stat.S_IFDIR | 0775 
     139            st.st_gid = self._gid() 
    130140            st.st_nlink = 2 
    131141        elif path == hello_path: 
     
    134144            st.st_size = len(hello_str) 
    135145        elif '/' not in path[1:]: 
    136             if path[1:] not in self.negcache and self.findLocker(path[1:]): 
     146            if path[1:] not in self.negcache[self._pid()] and self.findLocker(path[1:]): 
    137147                st.st_mode = stat.S_IFLNK | 0777 
    138                 st.st_uid = self._user() 
     148                st.st_uid = self._uid() 
    139149                st.st_nlink = 1 
    140150                st.st_size = len(self.findLocker(path[1:])) 
     
    149159 
    150160    def getCachedLockers(self): 
    151         return self.mounts[self._user()].keys() 
     161        return self.mounts[self._uid()].keys() 
    152162 
    153163    def findLocker(self, name): 
    154164        """Lookup a locker in hesiod and return its path""" 
    155         if name in self.mounts[self._user()]: 
    156             return self.mounts[self._user()][name] 
     165        if name in self.mounts[self._uid()]: 
     166            return self.mounts[self._uid()][name] 
    157167        else: 
    158168            try: 
     
    171181                    return None 
    172182                else: 
    173                     self.mounts[self._user()][name] = pointer['location'] 
     183                    self.mounts[self._uid()][name] = pointer['location'] 
    174184                    syslog(LOG_INFO, "Mounting "+name+" on "+pointer['location']) 
    175185                    return pointer['location'] 
     
    211221            return -errno.EPERM 
    212222        elif '/' not in path[1:]: 
    213             self.mounts[self._user()][path[1:]] = src 
    214             self.negcache.remove(path[1:]) 
    215             print self.mounts[self._user()] 
     223            self.mounts[self._uid()][path[1:]] = src 
     224            self.negcache[self._pid()].remove(path[1:]) 
    216225        else: 
    217226            return -errno.EPERM 
     
    221230            return -errno.EPERM 
    222231        elif '/' not in path[1:]: 
    223             del self.mounts[self._user()][path[1:]] 
    224             self.negcache.add(path[1:]) 
     232            del self.mounts[self._uid()][path[1:]] 
     233            self.negcache[self._pid()].add(path[1:]) 
    225234        else: 
    226235            return -errno.EPERM