ClRcT
clLogStreamOwnerCkptDsIdDelete(ClLogSOEoDataT  *pSoEoEntry,
                               ClUint32T       dsId) 
{
    ClRcT           rc      = CL_OK; 
    ClLogSvrCommonEoDataT  *pCommonEoData = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogStreamOwnerEoEntryGet(NULL, &pCommonEoData);
    if( CL_OK != rc )
    {
        return rc;
    }    

    rc = clBitmapBitClear(pSoEoEntry->hDsIdMap, dsId);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBitmapBitClear(): rc[0x %x]", rc));
        return rc;
    }    
    CL_LOG_CLEANUP(clCkptLibraryCkptDataSetDelete(pCommonEoData->hLibCkpt,
                                                  (SaNameT *) &gSOLocalCkptName, dsId),
                  CL_OK);
    CL_LOG_CLEANUP(clCkptLibraryCkptDataSetWrite(pCommonEoData->hLibCkpt, 
                                                 (SaNameT *) &gSOLocalCkptName,
                                                 CL_LOG_SO_DSID_START,
                                                 pSoEoEntry),
                 CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}    
ClRcT
clLogSvrCkptDataSetDelete(ClUint32T         dsId)
{
    ClRcT                  rc                 = CL_OK;
    ClLogSvrCommonEoDataT  *pSvrCommonEoEntry = NULL;
    ClLogSvrEoDataT        *pSvrEoEntry       = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogSvrEoEntryGet(&pSvrEoEntry, &pSvrCommonEoEntry);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogSvrEoEntryGet(): rc[0x %x]", rc));
        return rc;
    }

    if( CL_LOG_DSID_START >= dsId )
    {
        CL_LOG_DEBUG_ERROR(("Invalid DataSet ID\n "));
        return CL_LOG_RC(CL_ERR_INVALID_STATE);/*FIXME*/
    }
    rc = clBitmapBitClear(pSvrEoEntry->hDsIdMap, dsId);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clCkptLibraryCkptDataSetDelete(): rc[0x %x]", rc));
        return rc;
    }

    rc = clCkptLibraryCkptDataSetDelete(pSvrCommonEoEntry->hLibCkpt,
                                        (SaNameT *) &gSvrLocalCkptName,
                                        dsId);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clCkptLibraryCkptDataSetDelete(): rc[0x %x]", rc));
        return rc;
    }
    rc = clCkptLibraryCkptDataSetWrite(pSvrCommonEoEntry->hLibCkpt,
                                       (SaNameT *) &gSvrLocalCkptName,
                                       CL_LOG_DSID_START,
                                       pSvrEoEntry);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clCkptLibraryCkptDataSetWrite(): rc[0x %x]", rc));
    }


    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogStreamOwnerCkptDsIdGet(ClLogSOEoDataT  *pSoEoEntry, 
                            ClUint32T       *pDsId)
{
    ClRcT             rc         = CL_OK;
    ClLogSvrCommonEoDataT  *pCommonEoData = NULL;
    ClUint32T              dsId           = 0;

    CL_LOG_DEBUG_TRACE(("Enter"));
    
    rc = clLogStreamOwnerEoEntryGet(NULL, &pCommonEoData);
    if( CL_OK != rc )
    {
        return rc;
    }    

    dsId = pSoEoEntry->dsIdCnt;
    dsId++;
    rc = clBitmapBitSet(pSoEoEntry->hDsIdMap, dsId);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBitmapBitSet(): rc[0x %x]", rc));
        return rc;
    }    
    rc = clCkptLibraryCkptDataSetCreate(pCommonEoData->hLibCkpt, 
                                        (SaNameT *) &gSOLocalCkptName,
                                        dsId, 0, 0, 
                                        clLogStreamOwnerEntrySerialiser,
                                        clLogSOStreamEntryRecreate);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clCkptLibraryCkptDataSetCreate(): rc[0x %x]",
                    rc));
        CL_LOG_CLEANUP(clBitmapBitClear(pSoEoEntry->hDsIdMap, dsId), CL_OK);
        return rc;
    }    
    pSoEoEntry->dsIdCnt = dsId;
    *pDsId = dsId;

    CL_LOG_CLEANUP(clCkptLibraryCkptDataSetWrite(pCommonEoData->hLibCkpt, 
                                       (SaNameT *) &gSOLocalCkptName,
                                       CL_LOG_SO_DSID_START,
                                       pSoEoEntry), CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}    
ClRcT
clLogCkptDsIdGetCleanup(ClLogSvrEoDataT  *pSvrEoEntry,
                        ClUint32T        dsId)
{
    ClRcT   rc = CL_OK;

    CL_LOG_DEBUG_TRACE(("Enter"));

    pSvrEoEntry->nextDsId--;
    rc = clBitmapBitClear(pSvrEoEntry->hDsIdMap, dsId);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBitmapBitClear(): rc[0x %x]", rc));
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogInitHandleBitmapFileRemove(ClLogHandleT      hLog, 
                                ClLogFileHandleT  hFileHdlr)
{
    ClRcT                  rc            = CL_OK;
    ClLogInitHandleDataT  *pData         = NULL;
    ClLogClntEoDataT      *pClntEoEntry  = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));
        
    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogClntEoEntryGet(): rc[0x %x]", rc));
        return rc;
    }

    rc = clHandleCheckout(pClntEoEntry->hClntHandleDB, hLog,
                          (void **) (&pData)); 
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]\n", rc));
        return rc;
    }

    rc = clBitmapBitClear(pData->hStreamBitmap, hFileHdlr);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBitmapBitSet(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clHandleCheckin(pClntEoEntry->hClntHandleDB, hLog),
                       CL_OK);
        return rc;
    }

    rc = clHandleCheckin(pClntEoEntry->hClntHandleDB, hLog); 
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(): rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
} 
ClRcT
clLogClntStreamOpen(ClLogHandleT        hLog,
                    SaNameT             *pStreamName,
                    SaNameT             *pNodeName,
                    ClStringT           *pShmName,
                    ClUint32T           shmSize,
                    ClLogStreamHandleT  *phStream,
                    ClUint32T           recSize)
{
    ClRcT                 rc              = CL_OK;
    ClLogClntEoDataT      *pClntEoEntry   = NULL;
    ClBoolT               addedTable      = CL_FALSE;
    ClBoolT               addedEntry      = CL_FALSE;
    ClCntNodeHandleT      hClntStreamNode = CL_HANDLE_INVALID_VALUE;
    ClLogClntStreamDataT  *pUserData      = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    CL_LOG_PARAM_CHK((NULL == pStreamName), CL_LOG_RC(CL_ERR_NULL_POINTER));
    CL_LOG_PARAM_CHK((NULL == pNodeName), CL_LOG_RC(CL_ERR_NULL_POINTER));
    CL_LOG_PARAM_CHK((NULL == pShmName), CL_LOG_RC(CL_ERR_NULL_POINTER));
    CL_LOG_PARAM_CHK((sizeof(ClLogStreamHeaderT) > shmSize),
                      CL_LOG_RC(CL_ERR_INVALID_PARAMETER));
    CL_LOG_PARAM_CHK((NULL == phStream), CL_LOG_RC(CL_ERR_NULL_POINTER));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogClntEoEntryGet(): rc[0x %x]", rc));
        return rc;
    }

    rc = clOsalMutexLock_L(&(pClntEoEntry->clntStreamTblLock));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clOsalMutexLock(): rc[0x %x]", rc));
        return rc;
    }

    if( CL_HANDLE_INVALID_VALUE == pClntEoEntry->hClntStreamTable )
    {
        rc = clCntHashtblCreate(pClntEoEntry->maxStreams,
                                clLogStreamKeyCompare,
                                clLogStreamHashFn,
                                clLogClntStreamDeleteCb,
                                clLogClntStreamDeleteCb,
                                CL_CNT_UNIQUE_KEY,
                                &(pClntEoEntry->hClntStreamTable));
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clCntHashtblCreate(): rc[0x %x]", rc));
            CL_LOG_CLEANUP(
                clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),CL_OK);
            return rc;
        }
        addedTable = CL_TRUE;
        CL_LOG_DEBUG_VERBOSE(("Created the HashTable"));
    }

    rc = clLogClntStreamEntryGet(pClntEoEntry, pStreamName, pNodeName,
                                 pShmName, shmSize, &hClntStreamNode,
                                 &addedEntry);
    if( CL_OK != rc)
    {
        if( CL_TRUE == addedTable )
        {
            CL_LOG_CLEANUP(clCntDelete(pClntEoEntry->hClntStreamTable), CL_OK);
        }
        CL_LOG_CLEANUP(clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),
                       CL_OK);
        return rc;
    }
    CL_LOG_DEBUG_VERBOSE(("Got the stream entry"));

    rc = clLogHandleStreamHandleCreate(hLog, hClntStreamNode, phStream);
    if( CL_OK != rc)
    {
        if( CL_TRUE == addedEntry )
        {
            CL_LOG_CLEANUP(clCntNodeDelete(pClntEoEntry->hClntStreamTable,
                                           hClntStreamNode), CL_OK);
        }
        if( CL_TRUE == addedTable )
        {
            CL_LOG_CLEANUP(clCntDelete(pClntEoEntry->hClntStreamTable), CL_OK);
        }
        CL_LOG_CLEANUP(clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),
                       CL_OK);
        return rc;
    }
    CL_LOG_DEBUG_VERBOSE(("Created the streamhandle"));

    rc = clCntNodeUserDataGet(pClntEoEntry->hClntStreamTable, hClntStreamNode,
                              (ClCntDataHandleT *) &pUserData);
    if( CL_OK != rc )
    {
        CL_LOG_CLEANUP(clHandleDestroy(pClntEoEntry->hClntHandleDB,
                                             *phStream), CL_OK);
        *phStream = CL_HANDLE_INVALID_VALUE;
        if( CL_TRUE == addedEntry )
        {
            CL_LOG_CLEANUP(clCntNodeDelete(pClntEoEntry->hClntStreamTable,
                                           hClntStreamNode), CL_OK);
        }

        if( CL_TRUE == addedTable )
        {
            CL_LOG_CLEANUP(clCntDelete(pClntEoEntry->hClntStreamTable), CL_OK);
        }
        CL_LOG_CLEANUP(clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),
                       CL_OK);
        return rc;
    }
#ifdef NO_SAF
    pUserData->recSize=recSize;
#endif
    CL_LOG_DEBUG_VERBOSE(("Got stream entry"));
    rc = clBitmapBitSet(pUserData->hStreamBitmap, CL_HDL_IDX(*phStream));
    if( CL_OK != rc )
    {
        CL_LOG_CLEANUP(clHandleDestroy(pClntEoEntry->hClntHandleDB, *phStream),
                       CL_OK);
        *phStream = CL_HANDLE_INVALID_VALUE;
        if( CL_TRUE == addedEntry )
        {
            CL_LOG_CLEANUP(clCntNodeDelete(pClntEoEntry->hClntStreamTable,
                                           hClntStreamNode), CL_OK);
        }

        if( CL_TRUE == addedTable )
        {
            CL_LOG_CLEANUP(clCntDelete(pClntEoEntry->hClntStreamTable), CL_OK);
        }
        CL_LOG_CLEANUP(clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),
                       CL_OK);
        return rc;
    }
    CL_LOG_DEBUG_VERBOSE(("Updated stream bitmap"));

    rc = clLogHandleInitHandleStreamAdd(hLog, *phStream);
    if( CL_OK != rc )
    {
        CL_LOG_CLEANUP(clBitmapBitClear(pUserData->hStreamBitmap, CL_HDL_IDX(*phStream)),
                       CL_OK);
        CL_LOG_CLEANUP(clHandleDestroy(pClntEoEntry->hClntHandleDB, *phStream),
                       CL_OK);
        *phStream = CL_HANDLE_INVALID_VALUE;
        if( CL_TRUE == addedEntry )
        {
            CL_LOG_CLEANUP(clCntNodeDelete(pClntEoEntry->hClntStreamTable,
                                           hClntStreamNode), CL_OK);
        }

        if( CL_TRUE == addedTable )
        {
            CL_LOG_CLEANUP(clCntDelete(pClntEoEntry->hClntStreamTable), CL_OK);
        }
        CL_LOG_CLEANUP(clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),
                       CL_OK);
        return rc;
    }
    CL_LOG_DEBUG_VERBOSE(("Updated init handle"));

    rc = clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clOsalMutexUnlock(): rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}