]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/fix_maxwaittime.patch
ebl cleanup
[bacula/bacula] / bacula / patches / testing / fix_maxwaittime.patch
1 Index: src/dird/job.c
2 ===================================================================
3 --- src/dird/job.c      (révision 8005)
4 +++ src/dird/job.c      (copie de travail)
5 @@ -545,13 +545,20 @@
6  {
7     bool cancel = false;
8     JOB *job = jcr->job;
9 +   utime_t current=0;
10  
11     if (!job_waiting(jcr)) {
12        return false;
13     }
14 -   Dmsg3(200, "check maxwaittime %u - %u >= %u\n", watchdog_time, jcr->wait_time, job->MaxWaitTime);
15 +
16 +   if (jcr->wait_time) {
17 +      current = watchdog_time - jcr->wait_time;
18 +   }
19 +
20 +   Dmsg3(200, "check maxwaittime %u >= %u\n", 
21 +         current + jcr->wait_time_sum, job->MaxWaitTime);
22     if (job->MaxWaitTime != 0 &&
23 -       (watchdog_time - jcr->wait_time) >= job->MaxWaitTime) {
24 +       (current + jcr->wait_time_sum) >= job->MaxWaitTime) {
25        cancel = true;
26     }
27  
28 Index: src/jcr.h
29 ===================================================================
30 --- src/jcr.h   (révision 8005)
31 +++ src/jcr.h   (copie de travail)
32 @@ -216,7 +216,8 @@
33     time_t start_time;                 /* when job actually started */
34     time_t run_time;                   /* used for computing speed */
35     time_t end_time;                   /* job end time */
36 -   time_t wait_time;                  /* when job have started to wait */
37 +   time_t wait_time_sum;              /* cumulative wait time since job start */
38 +   time_t wait_time;                  /* timestamp when job have started to wait */
39     POOLMEM *client_name;              /* client name */
40     POOLMEM *RestoreBootstrap;         /* Bootstrap file to restore */
41     POOLMEM *stime;                    /* start time for incremental/differential */
42 Index: src/lib/jcr.c
43 ===================================================================
44 --- src/lib/jcr.c       (révision 8005)
45 +++ src/lib/jcr.c       (copie de travail)
46 @@ -738,41 +738,29 @@
47     return priority;
48  }
49  
50 -void set_jcr_job_status(JCR *jcr, int JobStatus)
51 +
52 +static void update_wait_time(JCR *jcr, int newJobStatus)
53  {
54 -    bool set_waittime = false;
55 -    int oldJobStatus = jcr->JobStatus;
56 -    int priority, old_priority;
57 +   bool enter_in_waittime;
58 +   int oldJobStatus = jcr->JobStatus;
59  
60 -    priority = get_status_priority(JobStatus);
61 -    old_priority = get_status_priority(oldJobStatus);
62 -
63 -    Dmsg2(800, "set_jcr_job_status(%s, %c)\n", jcr->Job, JobStatus);
64 -    /* if wait state is new, we keep current time for watchdog MaxWaitTime */
65 -    switch (JobStatus) {
66 -       case JS_WaitFD:
67 -       case JS_WaitSD:
68 -       case JS_WaitMedia:
69 -       case JS_WaitMount:
70 -       case JS_WaitStoreRes:
71 -       case JS_WaitJobRes:
72 -       case JS_WaitClientRes:
73 -       case JS_WaitMaxJobs:
74 -       case JS_WaitPriority:
75 -         set_waittime = true;
76 -       default:
77 -         break;
78 -    }
79
80 -   /*
81 -    * For a set of errors, ... keep the current status
82 -    *   so it isn't lost. For all others, set it.
83 -    */
84 -   Dmsg3(300, "jid=%u OnEntry JobStatus=%c set=%c\n", (uint32_t)jcr->JobId,
85 -         jcr->JobStatus, JobStatus);
86 -   if (priority >= old_priority) {
87 -      jcr->JobStatus = JobStatus;     /* replace with new priority */
88 +   switch (newJobStatus) {
89 +   case JS_WaitFD:
90 +   case JS_WaitSD:
91 +   case JS_WaitMedia:
92 +   case JS_WaitMount:
93 +   case JS_WaitStoreRes:
94 +   case JS_WaitJobRes:
95 +   case JS_WaitClientRes:
96 +   case JS_WaitMaxJobs:
97 +   case JS_WaitPriority:
98 +      enter_in_waittime = true;
99 +      break;
100 +   default:
101 +      enter_in_waittime = false; /* not a Wait situation */
102 +      break;
103     }
104 +   
105     /*
106      * If we were previously waiting and are not any more
107      *   we want to update the wait_time variable, which is
108 @@ -788,13 +776,43 @@
109     case JS_WaitClientRes:
110     case JS_WaitMaxJobs:
111     case JS_WaitPriority:
112 -       set_waittime = false;    /* keep old time */
113 +      if (!enter_in_waittime) { /* we get out the wait time */
114 +         jcr->wait_time_sum += (time(NULL) - jcr->wait_time);
115 +         jcr->wait_time = 0;
116 +      }
117 +      break;
118 +
119 +   /* if wait state is new, we keep current time for watchdog MaxWaitTime */
120     default:
121 -      if (set_waittime) {
122 -         Dmsg0(800, "Setting wait_time\n");
123 +      if (enter_in_waittime) {
124           jcr->wait_time = time(NULL);
125        }
126 +      break;
127     }
128 +}
129 +
130 +void set_jcr_job_status(JCR *jcr, int JobStatus)
131 +{
132 +   int priority, old_priority;
133 +   int oldJobStatus = jcr->JobStatus;
134 +   priority = get_status_priority(JobStatus);
135 +   old_priority = get_status_priority(oldJobStatus);
136 +   
137 +   Dmsg2(800, "set_jcr_job_status(%s, %c)\n", jcr->Job, JobStatus);
138 +
139 +   /* Update wait_time depending on newJobStatus and oldJobStatus */
140 +   update_wait_time(jcr, JobStatus);
141 +
142 +   /*
143 +    * For a set of errors, ... keep the current status
144 +    *   so it isn't lost. For all others, set it.
145 +    */
146 +   Dmsg3(300, "jid=%u OnEntry JobStatus=%c set=%c\n", (uint32_t)jcr->JobId,
147 +         jcr->JobStatus, JobStatus);
148 +   if (priority >= old_priority) {
149 +      jcr->JobStatus = JobStatus;     /* replace with new priority */
150 +   }
151 +
152     if (oldJobStatus != jcr->JobStatus) {
153        Dmsg3(200, "jid=%u leave set_old_job_status=%c new_set=%c\n", (uint32_t)jcr->JobId,
154           oldJobStatus, JobStatus);