Ignore:
Timestamp:
Aug 16, 2016, 5:41:49 PM (9 years ago)
Author:
Silvan Scherrer
Message:

samba client: add the possibility to have logfiles per share

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/src/dircache.c

    r958 r960  
    109109       
    110110
    111 static int dceCreate (DirectoryCacheEntry **ppdce, DirectoryCache *pdc, const char *path, int cFiles)
     111static int dceCreate (DirectoryCacheEntry **ppdce, Resource *pRes, const char *path, int cFiles)
    112112{
    113113    DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)malloc(sizeof(DirectoryCacheEntry));
     
    128128    pdce->ulHash = computehash (path);
    129129    pdce->ulLastUpdateTime = 0;
    130     pdce->pdc = pdc;
     130    pdce->pdc = pRes->pdc;
    131131    pdce->fInvalid = 0;
    132132
     
    155155}
    156156
    157 static void dceWriteEntry (DirectoryCacheEntry *pdce, const smbwrp_fileinfo *finfo)
     157static void dceWriteEntry (Resource *pRes, DirectoryCacheEntry *pdce, const smbwrp_fileinfo *finfo)
    158158{
    159159    if (pdce->cInfos >= pdce->cInfosAllocated)
     
    165165                                                                cNewAllocated * sizeof (smbwrp_fileinfo));
    166166
    167         debuglocal(9, "dceWriteEntry: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated);
     167        debuglocal(pRes, 9, "dceWriteEntry: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated);
    168168        if (pNewInfos)
    169169        {
     
    183183}
    184184
    185 static void dceAdjust (DirectoryCacheEntry *pdce)
     185static void dceAdjust (Resource *pRes, DirectoryCacheEntry *pdce)
    186186{
    187187    /* If the entry has too many preallocated info structures, adjust the memory allocation */
     
    196196                                                                cNewAllocated * sizeof (smbwrp_fileinfo));
    197197
    198         debuglocal(9, "dceAdjust: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated);
     198        debuglocal(pRes, 9, "dceAdjust: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated);
    199199        if (pNewInfos)
    200200        {
     
    209209}
    210210
    211 static int dcePathEqualsTo (DirectoryCacheEntry *pdce, const char *path)
    212 {
    213     debuglocal(9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath);
     211static int dcePathEqualsTo (Resource *pRes, DirectoryCacheEntry *pdce, const char *path)
     212{
     213    debuglocal(pRes, 9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath);
    214214    return ph->fsphStrICmp (path, pdce->pszPath) == 0;
    215215}
     
    225225}
    226226               
    227 static struct DirectoryCacheEntry *dcFindDirCache (struct DirectoryCache *pdc, const char *path, int fPrefix)
     227static struct DirectoryCacheEntry *dcFindDirCache (Resource *pRes, const char *path, int fPrefix)
    228228{
    229229    unsigned long hash = computehash (path);
    230230
    231     DirectoryCacheEntry *iter = pdc->pEntriesHead;
    232 
    233     debuglocal(9, "findDirCache: [%s]\n", path);
     231    DirectoryCacheEntry *iter = pRes->pdc->pEntriesHead;
     232
     233    debuglocal(pRes, 9, "findDirCache: [%s]\n", path);
    234234
    235235    while (iter != NULL)
    236236    {
    237         debuglocal(9, "findDirCache: entry [%s]\n", iter->pszPath);
     237        debuglocal(pRes, 9, "findDirCache: entry [%s]\n", iter->pszPath);
    238238        if (fPrefix)
    239239        {
     
    246246        {
    247247            if (    iter->ulHash == hash
    248                  && dcePathEqualsTo (iter, path)
     248                 && dcePathEqualsTo (pRes, iter, path)
    249249               )
    250250            {
     
    255255    }
    256256
    257     debuglocal(9, "findDirCache: %p\n", iter);
     257    debuglocal(pRes, 9, "findDirCache: %p\n", iter);
    258258
    259259    return iter;
     
    363363};
    364364
    365 static int dcExistsInCache (DirectoryCache *pdc, const char *path)
     365static int dcExistsInCache (Resource *pRes, const char *path)
    366366{
    367367    int rc = CacheFault;
    368368       
    369     if (pdc->fEnabled)
    370     {
    371         if (dcFindDirCache (pdc, path, 0) != NULL)
     369    if (pRes->pdc->fEnabled)
     370    {
     371        if (dcFindDirCache (pRes, path, 0) != NULL)
    372372        {
    373373            rc = CacheOk;
    374374        }
    375375       
    376         debuglocal(9, "ExistsInCache: [%s], %d\n", path, rc);
     376        debuglocal(pRes, 9, "ExistsInCache: [%s], %d\n", path, rc);
    377377    }
    378378   
     
    380380}
    381381       
    382 static int dcRead (DirectoryCache *pdc, const char *path,
     382static int dcRead (Resource *pRes, const char *path,
    383383                   PFNADDDIRENTRY fn,
    384384                   filelist_state *state,
     
    387387    int i;
    388388   
     389    DirectoryCache *pdc = pRes->pdc;
    389390    int rc = CacheFault;
    390391       
     
    393394        DirectoryCacheEntry *pdce;
    394395
    395         pdce = dcFindDirCache (pdc, path, 0);
     396        pdce = dcFindDirCache (pRes, path, 0);
    396397       
    397398        if (pdce)
    398399        {
    399             debuglocal(9, "CacheRead: entry %p found for [%s]\n", pdce, path);
     400            debuglocal(pRes, 9, "CacheRead: entry %p found for [%s]\n", pdce, path);
    400401           
    401402            if (fForceCache)
     
    412413                if (dceExpired (pdce, pdc->ulExpirationTime))
    413414                {
    414                     debuglocal(9, "CacheRead: expired\n");
     415                    debuglocal(pRes, 9, "CacheRead: expired\n");
    415416                    dcRemoveEntry (pdce);
    416417                    dceDelete (pdce);
     
    433434        }
    434435       
    435         debuglocal(9, "CacheRead: [%s], %d\n", path, rc);
     436        debuglocal(pRes, 9, "CacheRead: [%s], %d\n", path, rc);
    436437    }
    437438   
     
    439440}
    440441
    441 static DirectoryCacheEntry *dcWriteBegin (DirectoryCache *pdc, const char *path, int cFiles)
     442static DirectoryCacheEntry *dcWriteBegin (Resource *pRes, const char *path, int cFiles)
    442443{
    443444    DirectoryCacheEntry *pdce = NULL;
    444445
    445     if (pdc->fEnabled)
    446     {
    447         pdce = dcFindDirCache (pdc, path, 0);
     446    if (pRes->pdc->fEnabled)
     447    {
     448        pdce = dcFindDirCache (pRes, path, 0);
    448449       
    449450        if (!pdce)
    450451        {
    451452            /* Does not exist in the cache yet. */
    452             dceCreate (&pdce, pdc, path, cFiles);
     453            dceCreate (&pdce, pRes, path, cFiles);
    453454        }
    454455        else
     
    465466        }
    466467       
    467         debuglocal(9, "CacheWriteBegin: %s\n", path);
     468        debuglocal(pRes, 9, "CacheWriteBegin: %s\n", path);
    468469    }
    469470   
     
    472473
    473474
    474 static void dcInvalidate (DirectoryCache *pdc, const char *path, int fPrefix)
     475static void dcInvalidate (Resource *pRes, const char *path, int fPrefix)
    475476{
    476477    DirectoryCacheEntry *pdce;
    477478   
    478     debuglocal(9, "CacheInvalidate: [%s]\n", path);
    479 
    480     pdce = dcFindDirCache (pdc, path, fPrefix);
     479    debuglocal(pRes, 9, "CacheInvalidate: [%s]\n", path);
     480
     481    pdce = dcFindDirCache (pRes, path, fPrefix);
    481482
    482483    while (pdce)
     
    485486        dceDelete (pdce);
    486487       
    487         pdce = dcFindDirCache (pdc, path, fPrefix);
    488     }
    489 }
    490 
    491 static int dcFindPath (DirectoryCache *pdc,
     488        pdce = dcFindDirCache (pRes, path, fPrefix);
     489    }
     490}
     491
     492static int dcFindPath (Resource *pRes, DirectoryCache *pdc,
    492493                       const char *path,
    493494                       const char *parent,
     
    500501    unsigned long hash = computehash (parent);
    501502
    502     debuglocal(9, "dcFindPath: [%s][%s]\n", parent, name);
     503    debuglocal(pRes, 9, "dcFindPath: [%s][%s]\n", parent, name);
    503504
    504505    while (pdce != NULL)
    505506    {
    506         debuglocal(9, "dcFindPath: entry [%s]\n", pdce->pszPath);
     507        debuglocal(pRes, 9, "dcFindPath: entry [%s]\n", pdce->pszPath);
    507508
    508509        if (   pdce->ulHash == hash
    509             && dcePathEqualsTo (pdce, parent))
     510            && dcePathEqualsTo (pRes, pdce, parent))
    510511        {
    511512            /* This entry should contain the path. */
     
    517518                    *finfo = pdce->aInfos[i];
    518519                    *pulAge = timesec () - pdce->ulLastUpdateTime;
    519                     debuglocal(9, "dircache: FindPath %s found, age %d\n", path, *pulAge);
     520                    debuglocal(pRes, 9, "dircache: FindPath %s found, age %d\n", path, *pulAge);
    520521                    return 1;
    521522                }
     
    526527    }
    527528
    528     debuglocal(9, "dircache: FindPath %s not found\n", path);
     529    debuglocal(pRes, 9, "dircache: FindPath %s not found\n", path);
    529530    return 0;
    530531}
     
    561562 */
    562563
    563 int dircache_create(DirectoryCache **ppdc, unsigned long ulExpirationTime, int cMaxEntries)
    564 {
     564int dircache_create(Resource *pRes)
     565{
     566    struct DirectoryCache **ppdc = &pRes->pdc;
     567    unsigned long ulExpirationTime = pRes->cachetimeout;
     568    int cMaxEntries = pRes->cachedepth;
    565569    int rc;
    566570
    567     debuglocal(9, "dircache_create: %u seconds, %d entries\n", ulExpirationTime, cMaxEntries);
     571    debuglocal(pRes, 9, "dircache_create: %u seconds, %d entries\n", ulExpirationTime, cMaxEntries);
    568572
    569573    rc = dcCreate(ppdc);
     
    574578    }
    575579
    576     debuglocal(9, "dircache_create: %p, rc = %d\n", *ppdc, rc);
     580    debuglocal(pRes, 9, "dircache_create: %p, rc = %d\n", *ppdc, rc);
    577581    return rc;
    578582}
    579583
    580 void dircache_delete(DirectoryCache *pdc)
    581 {
    582     debuglocal(9, "dircache_delete: %p\n", pdc);
     584void dircache_delete(Resource *pRes)
     585{
     586    DirectoryCache *pdc = pRes->pdc;
     587    debuglocal(pRes, 9, "dircache_delete: %p\n", pdc);
    583588
    584589    if (pdc)
     
    603608    }
    604609
    605     debuglocal(9, "dircache_list_files [%s]\n", path);
     610    debuglocal(state->pConn->pRes, 9, "dircache_list_files [%s]\n", path);
    606611
    607612    if (!pdc)
     
    612617    lockRequest (pdc->mutex);
    613618
    614     rc = dcRead (pdc, path, fn, state, ptotal_received, 0);
     619    rc = dcRead (state->pConn->pRes, path, fn, state, ptotal_received, 0);
    615620
    616621    lockRelease (pdc->mutex);
     
    632637    }
    633638
    634     debuglocal(9, "dircache_write_begin pdc %p path [%s]\n", pdc, path);
     639    debuglocal(state->pConn->pRes, 9, "dircache_write_begin pdc %p path [%s]\n", pdc, path);
    635640
    636641    if (!pdc)
     
    650655    }
    651656   
    652     pdce = dcWriteBegin (pdc, path, cFiles);
     657    pdce = dcWriteBegin (state->pConn->pRes, path, cFiles);
    653658   
    654659    lockRelease (pdc->mutex);
    655660
    656     debuglocal(9, "dircache_write_begin returning ctx %p\n", pdce);
     661    debuglocal(state->pConn->pRes, 9, "dircache_write_begin returning ctx %p\n", pdce);
    657662    return (void *)pdce;
    658663}
    659664
    660 void dircache_write_entry(void *dircachectx, const smbwrp_fileinfo *finfo)
     665void dircache_write_entry(Resource *pRes, void *dircachectx, const smbwrp_fileinfo *finfo)
    661666{
    662667    DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx;
    663668
    664     debuglocal(9, "dircache_write_entry %p\n", pdce);
     669    debuglocal(pRes, 9, "dircache_write_entry %p\n", pdce);
    665670   
    666671    if (!pdce)
     
    671676    lockRequest (pdce->pdc->mutex);
    672677   
    673     dceWriteEntry (pdce, finfo);
     678    dceWriteEntry (pRes, pdce, finfo);
    674679   
    675680    lockRelease (pdce->pdc->mutex);
    676681}
    677682
    678 void dircache_write_end(void *dircachectx)
     683void dircache_write_end(Resource *pRes, void *dircachectx)
    679684{
    680685    DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx;
    681686    DirectoryCache *pdc;
    682687
    683     debuglocal(9, "dircache_write_end: pdce %p\n", pdce);
     688    debuglocal(pRes, 9, "dircache_write_end: pdce %p\n", pdce);
    684689
    685690    if (!pdce)
     
    699704    else
    700705    {
    701         dceAdjust (pdce);
     706        dceAdjust (pRes, pdce);
    702707        dcInsertEntry (pdce);
    703708    }
     
    707712
    708713void dircache_invalidate(const char *path,
    709                          struct DirectoryCache *pdc,
     714                         Resource *pRes,
    710715                         int fParent)
    711716{
    712     debuglocal(9, "dircache_invalidate [%s], parent %d\n", path, fParent);
     717    struct DirectoryCache *pdc = pRes->pdc;
     718    debuglocal(pRes, 9, "dircache_invalidate [%s], parent %d\n", path, fParent);
    713719
    714720    if (!pdc)
     
    728734        {
    729735            *lastSlash = 0;
    730             dcInvalidate (pdc, p, 0);
     736            dcInvalidate (pRes, p, 0);
    731737        }
    732738        else
    733739        {
    734             dcInvalidate (pdc, "", 0);
     740            dcInvalidate (pRes, "", 0);
    735741        }
    736742    }
    737743    else
    738744    {
    739         dcInvalidate (pdc, path, 0);
     745        dcInvalidate (pRes, path, 0);
    740746    }
    741747   
     
    745751}
    746752
    747 int dircache_find_path(struct DirectoryCache *pdc,
     753int dircache_find_path(Resource *pRes,
    748754                       const char *path,
    749755                       smbwrp_fileinfo *finfo,
    750756                       unsigned long *pulAge)
    751757{
     758    struct DirectoryCache *pdc = pRes->pdc;
    752759    int cb;
    753760    char *p;
     
    755762    int fFound = 0;
    756763
    757     debuglocal(9, "dircache_find_path [%s]\n", path);
     764    debuglocal(pRes, 9, "dircache_find_path [%s]\n", path);
    758765
    759766    if (!pdc)
     
    778785    {
    779786        *lastSlash = 0;
    780         fFound = dcFindPath (pdc, path, p, lastSlash + 1, finfo, pulAge);
     787        fFound = dcFindPath (pRes, pdc, path, p, lastSlash + 1, finfo, pulAge);
    781788    }
    782789    else
    783790    {
    784791        /* Find in the root directory. p is the name. */
    785         fFound = dcFindPath (pdc, path, "", p, finfo, pulAge);
     792        fFound = dcFindPath (pRes, pdc, path, "", p, finfo, pulAge);
    786793    }
    787794   
Note: See TracChangeset for help on using the changeset viewer.