LCOV - code coverage report
Current view: top level - src/server - dpth.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 37 37 100.0 %
Date: 2015-11-30 Functions: 6 6 100.0 %

          Line data    Source code
       1             : #include "../burp.h"
       2             : #include "../alloc.h"
       3             : #include "../fsops.h"
       4             : #include "../fzp.h"
       5             : #include "../lock.h"
       6             : #include "../log.h"
       7             : #include "dpth.h"
       8             : 
       9          62 : struct dpth *dpth_alloc(void)
      10             : {
      11          62 :         return (struct dpth *)calloc_w(1, sizeof(struct dpth), __func__);
      12             : }
      13             : 
      14          61 : void dpth_free(struct dpth **dpth)
      15             : {
      16         122 :         if(!dpth || !*dpth) return;
      17          61 :         dpth_release_all(*dpth);
      18          61 :         free_w(&((*dpth)->base_path));
      19          61 :         free_v((void **)dpth);
      20             : }
      21             : 
      22           3 : int dpth_release_and_move_to_next_in_list(struct dpth *dpth)
      23             : {
      24           3 :         int ret=0;
      25           3 :         struct dpth_lock *next=NULL;
      26             : 
      27             :         // Try to release (and unlink) the lock even if fzp_close failed, just
      28             :         // to be tidy.
      29           3 :         if(fzp_close(&dpth->fzp)) ret=-1;
      30           3 :         if(lock_release(dpth->head->lock)) ret=-1;
      31           3 :         lock_free(&dpth->head->lock);
      32             : 
      33           3 :         next=dpth->head->next;
      34           3 :         if(dpth->head==dpth->tail) dpth->tail=next;
      35           3 :         free_v((void **)&dpth->head);
      36           3 :         dpth->head=next;
      37           3 :         return ret;
      38             : }
      39             : 
      40          61 : int dpth_release_all(struct dpth *dpth)
      41             : {
      42          61 :         int ret=0;
      43          61 :         if(!dpth) return 0;
      44          61 :         if(dpth->fzp && fzp_close(&dpth->fzp)) ret=-1;
      45         125 :         while(dpth->head)
      46           3 :                 if(dpth_release_and_move_to_next_in_list(dpth)) ret=-1;
      47          61 :         return ret;
      48             : }
      49             : 
      50             : #define MAX_FILES_PER_DIR       0xFFFF
      51             : 
      52          69 : static int incr(uint16_t *component, uint16_t max)
      53             : {
      54          69 :         if((*component)++<max) return 1;
      55          36 :         *component=0;
      56          36 :         return 0;
      57             : }
      58             : 
      59             : // Three levels with 65535 entries each gives
      60             : // 65535^3 = 281,462,092,005,375 data entries
      61             : // recommend a filesystem with lots of inodes?
      62             : // Hmm, but ext3 only allows 32000 subdirs, although that many files are OK.
      63          37 : int dpth_incr(struct dpth *dpth)
      64             : {
      65          74 :         if(incr(&dpth->comp[2], MAX_FILES_PER_DIR)
      66          20 :           || incr(&dpth->comp[1], dpth->max_storage_subdirs)
      67          49 :           || incr(&dpth->comp[0], dpth->max_storage_subdirs))
      68          33 :                 return 0;
      69             :         logp("No free data file entries out of the %d*%d*%d available!\n",
      70             :                 MAX_FILES_PER_DIR,
      71           4 :                 dpth->max_storage_subdirs, dpth->max_storage_subdirs);
      72           4 :         logp("Maybe move the storage directory aside and start again.\n");
      73           4 :         return -1;
      74             : }

Generated by: LCOV version 1.10