]> git.sur5r.net Git - bacula/bacula/commitdiff
Reduce casting in smartall + turn off reload debug output
authorKern Sibbald <kern@sibbald.com>
Tue, 22 Jun 2004 15:54:25 +0000 (15:54 +0000)
committerKern Sibbald <kern@sibbald.com>
Tue, 22 Jun 2004 15:54:25 +0000 (15:54 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1440 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/dird.c
bacula/src/lib/parse_conf.c
bacula/src/lib/parse_conf.h
bacula/src/lib/smartall.c

index 6d2ef2d6ea9d56fd065f21d996afad0dd5c8e9e7..38a6678a6efa18fec3bbe52c38460a197e6bbd9a 100644 (file)
@@ -298,10 +298,10 @@ static void free_saved_resources(int table)
    int num = r_last - r_first + 1;
    RES **res_tab = reload_table[table].res_table;
    if (!res_tab) {
-      Dmsg1(000, "res_tab for table %d already released.\n", table);
+      Dmsg1(100, "res_tab for table %d already released.\n", table);
       return;
    }
-   Dmsg1(000, "Freeing resources for table %d\n", table);
+   Dmsg1(100, "Freeing resources for table %d\n", table);
    for (int j=0; j<num; j++) {
       free_resource(res_tab[j], r_first + j);
    }
@@ -319,7 +319,7 @@ static void free_saved_resources(int table)
 static void reload_job_end_cb(JCR *jcr, void *ctx)
 {
    int reload_id = (int)ctx;
-   Dmsg3(000, "reload job_end JobId=%d table=%d cnt=%d\n", jcr->JobId,
+   Dmsg3(100, "reload job_end JobId=%d table=%d cnt=%d\n", jcr->JobId,
       reload_id, reload_table[reload_id].job_count);
    lock_jcr_chain();
    LockRes();
@@ -389,14 +389,13 @@ void reload_config(int sig)
       goto bail_out;
    }
 
-   Dmsg1(000, "Reload_config njobs=%d\n", njobs);
+   Dmsg1(100, "Reload_config njobs=%d\n", njobs);
    reload_table[table].res_table = save_config_resources();
-   Dmsg1(000, "Saved old config in table %d\n", table);
+   Dmsg1(100, "Saved old config in table %d\n", table);
 
-   Dmsg0(000, "Calling parse config\n");
    parse_config(configfile);
 
-   Dmsg0(000, "Reloaded config file\n");
+   Dmsg0(100, "Reloaded config file\n");
    if (!check_resources()) {
       rtable = find_free_reload_table_entry();   /* save new, bad table */
       if (rtable < 0) {
@@ -517,7 +516,7 @@ Without that I don't know who I am :-(\n"), configfile);
                       job->hdr.name, job_items[i].name, *def_svalue, i, offset);
                  svalue = (char **)((char *)job + offset);
                  if (*svalue) {
-                     Dmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
+                     Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
                  }
                  *svalue = bstrdup(*def_svalue);
                  set_bit(i, job->hdr.item_present);
@@ -527,7 +526,7 @@ Without that I don't know who I am :-(\n"), configfile);
                       job->hdr.name, job_items[i].name, i, offset);
                  svalue = (char **)((char *)job + offset);
                  if (*svalue) {
-                     Dmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
+                     Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
                  }
                  *svalue = *def_svalue;
                  set_bit(i, job->hdr.item_present);
index d29697d4b4584857e606df9629bb3a5e21194fef..662842eb73e735020fa37c4efe68ae180e5555ad 100755 (executable)
@@ -837,3 +837,11 @@ RES **save_config_resources()
    }
    return res;
 }
+
+RES **new_res_head()
+{
+   int size = (r_last - r_first + 1) * sizeof(RES *);
+   RES **res = (RES **)malloc(size);
+   memset(res, 0, size);
+   return res;
+}
index 236369e956a65c81aa23b4f526507fd74774e5f8..92bb70f37d42a2a012030894095c28b631aaa4a8 100644 (file)
@@ -21,7 +21,7 @@
 
  */
 
-struct RES_ITEM;                    /* Declare forward referenced structure */ 
+struct RES_ITEM;                   /* Declare forward referenced structure */ 
 typedef void (MSG_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
 
 /* This is the structure that defines
@@ -30,29 +30,29 @@ typedef void (MSG_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
  * tables.
  */
 struct RES_ITEM {
-   const char *name;                  /* Resource name i.e. Director, ... */
-   MSG_RES_HANDLER *handler;          /* Routine storing the resource item */
-   void **value;                      /* Where to store the item */
-   int  code;                         /* item code/additional info */
-   int  flags;                        /* flags: default, required, ... */
-   int  default_value;                /* default value */
+   const char *name;                 /* Resource name i.e. Director, ... */
+   MSG_RES_HANDLER *handler;         /* Routine storing the resource item */
+   void **value;                     /* Where to store the item */
+   int code;                         /* item code/additional info */
+   int flags;                        /* flags: default, required, ... */
+   int default_value;                /* default value */
 };
 
 /* For storing name_addr items in res_items table */
 #define ITEM(x) ((void **)&res_all.x)
 
-#define MAX_RES_ITEMS 50              /* maximum resource items per RES */
+#define MAX_RES_ITEMS 50             /* maximum resource items per RES */
 
 /* This is the universal header that is
  * at the beginning of every resource
  * record.
  */
 struct RES {
-   RES *next;                         /* pointer to next resource of this type */
-   char *name;                        /* resource name */
-   char *desc;                        /* resource description */
-   int   rcode;                       /* resource id or type */
-   int   refcnt;                      /* reference count for releasing */
+   RES *next;                        /* pointer to next resource of this type */
+   char *name;                       /* resource name */
+   char *desc;                       /* resource description */
+   int  rcode;                       /* resource id or type */
+   int  refcnt;                      /* reference count for releasing */
    char  item_present[MAX_RES_ITEMS]; /* set if item is present in conf file */
 };
 
@@ -62,26 +62,26 @@ struct RES {
  * This is the structure that defines the
  * resources that are available to this daemon.
  */
-struct RES_TABLE {       
-   const char *name;                  /* resource name */
-   RES_ITEM *items;                   /* list of resource keywords */
-   int rcode;                         /* code if needed */
+struct RES_TABLE {      
+   const char *name;                 /* resource name */
+   RES_ITEM *items;                  /* list of resource keywords */
+   int rcode;                        /* code if needed */
 };
 
 /* Common Resource definitions */
 
-#define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1       /* maximum resource name length */
+#define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1      /* maximum resource name length */
 
-#define ITEM_REQUIRED    0x1          /* item required */
-#define ITEM_DEFAULT     0x2          /* default supplied */
+#define ITEM_REQUIRED   0x1          /* item required */
+#define ITEM_DEFAULT    0x2          /* default supplied */
 #define ITEM_NO_EQUALS   0x4          /* Don't scan = after name */
 
 /* Message Resource */
 struct MSGS {
-   RES   hdr;
-   char *mail_cmd;                    /* mail command */
-   char *operator_cmd;                /* Operator command */
-   DEST *dest_chain;                  /* chain of destinations */
+   RES  hdr;
+   char *mail_cmd;                   /* mail command */
+   char *operator_cmd;               /* Operator command */
+   DEST *dest_chain;                 /* chain of destinations */
    char send_msg[nbytes_for_bits(M_MAX+1)];  /* bit array of types */
 };
 
@@ -96,9 +96,11 @@ union CURES {
 
 
 /* Configuration routines */
-int   parse_config(const char *cf, int exit_on_error = 1);
-void  free_config_resources(void);
+int    parse_config(const char *cf, int exit_on_error = 1);
+void   free_config_resources(void);
 RES   **save_config_resources(void);
+RES   **new_res_head();
+
 
 /* Resource routines */
 RES *GetResWithName(int rcode, char *name);
@@ -117,7 +119,7 @@ const char *res_to_str(int rcode);
 
 #ifdef the_old_way
 #define foreach_res(var, type) \
-        for((var)=NULL; (((void *)(var))=GetNextRes((type), (RES *)var));) 
+       for((var)=NULL; (((void *)(var))=GetNextRes((type), (RES *)var));) 
 #endif
 
 
index c9a333e34bcb4da180381996d782f370a01fbbcb..6e46ca7b6b91775a6191e10085ae90630c34abc5 100644 (file)
@@ -86,6 +86,11 @@ static struct b_queue abqueue = {    /* Allocated buffer queue */
    &abqueue, &abqueue
 };
 
+uint64_t sm_max_bytes = 0;
+uint64_t sm_bytes = 0;
+uint32_t sm_max_buffers = 0;
+uint32_t sm_buffers = 0;
+
 static bool bufimode = false;  /* Buffers not tracked when True */
 
 #define HEAD_SIZE BALIGN(sizeof(struct abufhead))
@@ -110,15 +115,23 @@ static void *smalloc(const char *fname, int lineno, unsigned int nbytes)
 
    nbytes += HEAD_SIZE + 1;
    if ((buf = (char *)malloc(nbytes)) != NULL) {
+      struct abufhead *head = (struct abufhead *)buf;
       P(mutex);
       /* Enqueue buffer on allocated list */
       qinsert(&abqueue, (struct b_queue *) buf);
-      ((struct abufhead *) buf)->ablen = nbytes;
-      ((struct abufhead *) buf)->abfname = bufimode ? NULL : fname;
-      ((struct abufhead *) buf)->ablineno = (sm_ushort) lineno;
+      head->ablen = nbytes;
+      head->abfname = bufimode ? NULL : fname;
+      head->ablineno = (sm_ushort) lineno;
       /* Emplace end-clobber detector at end of buffer */
       buf[nbytes - 1] = (((long) buf) & 0xFF) ^ 0xC5;
       buf += HEAD_SIZE;  /* Increment to user data start */
+      if (++sm_buffers > sm_max_buffers) {
+        sm_max_buffers = sm_buffers;
+      }
+      sm_bytes += nbytes;
+      if (sm_bytes > sm_max_bytes) {
+        sm_max_bytes = sm_bytes;
+      }
       V(mutex);
    } else {
       Emsg0(M_ABORT, 0, _("Out of memory\n"));
@@ -154,11 +167,12 @@ void sm_free(const char *file, int line, void *fp)
 
    cp -= HEAD_SIZE;
    qp = (struct b_queue *) cp;
+   struct abufhead *head = (struct abufhead *)cp;
 
    P(mutex);
    Dmsg4(1150, "sm_free %d at %x from %s:%d\n", 
-        ((struct abufhead *)cp)->ablen, fp, 
-        ((struct abufhead *)cp)->abfname, ((struct abufhead *)cp)->ablineno);
+        head->ablen, fp, 
+        head->abfname, head->ablineno);
 
    /* The following assertions will catch virtually every release
       of an address which isn't an allocated buffer. */
@@ -175,12 +189,12 @@ void sm_free(const char *file, int line, void *fp)
       allocated  space in the buffer by comparing the end of buffer
       checksum with the address of the buffer. */
 
-   if (((unsigned char *) cp)[((struct abufhead *) cp)->ablen - 1] !=
-           ((((long) cp) & 0xFF) ^ 0xC5)) {
+   if (((unsigned char *)cp)[head->ablen - 1] != ((((long) cp) & 0xFF) ^ 0xC5)) {
       V(mutex);
       Emsg2(M_ABORT, 0, "Buffer overrun called from %s:%d\n", file, line);
    }
-
+   sm_buffers--;
+   sm_bytes -= head->ablen;
 
    qdchain(qp);
    V(mutex);
@@ -191,7 +205,7 @@ void sm_free(const char *file, int line, void *fp)
       attempts to access data through a pointer into storage that's
       been previously released. */
 
-   memset(cp, 0xAA, (int) ((struct abufhead *) cp)->ablen);
+   memset(cp, 0xAA, (int) head->ablen);
 
    free(cp);
 }
@@ -263,7 +277,8 @@ void *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size)
       return the buffer passed in.  */
 
    cp -= HEAD_SIZE;
-   osize = ((struct abufhead *) cp)->ablen - (HEAD_SIZE + 1);
+   struct abufhead *head = (struct abufhead *)cp;
+   osize = head->ablen - (HEAD_SIZE + 1);
    if (size == osize) {
       return ptr;
    }
@@ -273,6 +288,9 @@ void *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size)
       return NULL from realloc()  and  leave  the  buffer  in  PTR
       intact.  */
 
+   sm_buffers--;
+   sm_bytes -= osize;
+
    if ((buf = smalloc(fname, lineno, size)) != NULL) {
       memcpy(buf, ptr, (int) sm_min(size, osize));
       /* If the new buffer is larger than the old, fill the balance