Exemplo n.º 1
0
 def __init__(self, filehandle):
     self._objid = ObCacheId(filehandle)
     if self._objid.bucketNameVersionIsV1():
         self.prefix = "%08X_%s." % (fnv1_hash(self._objid.bytes), str(self._objid).upper())
         self._name_version = 1
     else:
         self.prefix = "%016X_%s." % (hash64(self._objid), str(self._objid).upper())
         self._name_version = 2
     self.best_name = None
     self.best_version = None
Exemplo n.º 2
0
class ObjectListManager():
    '''
    Manage state for finding the newest object name
    for an inode.
    '''
    def __init__(self, filehandle):
        self._objid = ObCacheId(filehandle)
        if self._objid.bucketNameVersionIsV1():
            self.prefix = "%08X_%s." % (fnv1_hash(self._objid.bytes), str(self._objid).upper())
            self._name_version = 1
        else:
            self.prefix = "%016X_%s." % (hash64(self._objid), str(self._objid).upper())
            self._name_version = 2
        self.best_name = None
        self.best_version = None

    def see_name(self, wrock, name):
        '''
        An object with the given name is observed.
        '''
        if not name.startswith(self.prefix):
            wrock.logger.warning("%s see_name mismatch prefix '%s' does not match '%s'", wrock, self.prefix, name)
            return
        toks = name.split('.')
        try:
            name_version = int(toks[-1])
        except ValueError:
            wrock.logger.warning("%s cannot parse inode object name '%s'", wrock, name)
            return
        if name_version != self._name_version:
            wrock.logger.warning("%s objid='%s' unexpected name_version '%s' != '%s' name='%s'", wrock, self._objid, name_version, self._name_version, name)
            # we know how to parse this, so keep going
        if name_version == 1:
            if len(toks) != 4:
                wrock.logger.warning("%s objid='%s' unexpected token count for name='%s'", wrock, self._objid, name)
                return
            version_str = toks[1]
        elif name_version == 2:
            if len(toks) != 6:
                wrock.logger.warning("%s objid='%s' unexpected token count for name='%s'", wrock, self._objid, name)
                return
            version_str = toks[3]
        else:
            # OK, we do not know how to handle this
            wrock.logger.warning("%s objid='%s' unhandled name_version=%s", wrock, self._objid, name_version)
            return
        try:
            version = int(version_str)
        except ValueError:
            wrock.logger.warning("%s cannot parse version from object name '%s' version_str='%s'", wrock, name, version_str)
            return
        self._see_name_and_version(name, version)

    def _see_name_and_version(self, name, version):
        '''
        Observe a new name at the given version
        '''
        if (self.best_version is None) or (version > self.best_version):
            self.best_name = name
            self.best_version = version
Exemplo n.º 3
0
def generate_bucket_name(objId,
                         ownerObjId,
                         objType,
                         version=OBJ_VERSION_INITIAL,
                         nameprefix=None):
    '''
    Generate bucketnames given oid and owner obj id.
    Special objects that are outside the filesystem tree have V1 names.
    All other objects have V2 names
    '''
    if isinstance(objId, Filehandle):
        objId = ObCacheId(objId)

    if objId.bucketNameVersionIsV1():
        nameVersion = 1
    else:
        nameVersion = 2

    if objId.isRootId():
        ownerObjId = objId
        objType = Btype.BTYPE_DIR

    if nameVersion == 1:
        prefix = fnv1_hash(objId.bytes)
    else:
        prefix = hash64(objId)

    parentHash = hash64(ownerObjId)
    snapshotid = 0xFFFFFFFF
    if nameVersion == 1:
        name = "%08X_%s.%011u.%08X.%04u" % (prefix, str(objId).upper(),
                                            version, snapshotid, nameVersion)
    else:
        name = "%016X_%s.%04u.%016X.%011u.%08X.%04u" % (prefix, objId.__str__(
        ).upper(), objType, parentHash, version, snapshotid, nameVersion)
    if not nameprefix:
        return name
    return nameprefix + name
Exemplo n.º 4
0
def unparse_indirect(run_options, tObj, blockList, treeIndex, depth):
    ba = bytearray()
    btypeList = get_unparse_handle_list(tObj.ftype, Btype.BTYPE_INDIRECT)
    indirBlockId = ObCacheId()
    offset = 0xFFFFFFFF & ((treeIndex << 16) + depth)
    ba = unparse_obj_handles(run_options,
                             tObj,
                             ba,
                             indirBlockId,
                             objBtypeList=btypeList,
                             ownerFh=tObj.filehandle,
                             dataOffset=offset,
                             indirectBlockList=blockList)
    return indirBlockId, ba
Exemplo n.º 5
0
def unparse_segment(run_options, tobj, ftype, ownerfh, offset, data):
    'pass owning object offset and data at offset'
    segmentId = ObCacheId()
    return segmentId, unparse_segment_using_obid(run_options, segmentId, tobj,
                                                 ftype, ownerfh, offset, data)