]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/maxschedruntime.patch
ebl Check if maxschedruntime is over at the job begining
[bacula/bacula] / bacula / patches / testing / maxschedruntime.patch
1 Index: src/dird/getmsg.c
2 ===================================================================
3 --- src/dird/getmsg.c   (révision 4696)
4 +++ src/dird/getmsg.c   (copie de travail)
5 @@ -70,6 +70,33 @@
6  
7  static char OK_msg[] = "1000 OK\n";
8  
9 +
10 +void set_jcr_sd_job_status(JCR *jcr, int SDJobStatus)
11 +{
12 +   bool set_waittime=false;
13 +   Dmsg2(800, "set_jcr_sd_job_status(%s, %c)\n", jcr->Job, SDJobStatus);
14 +   /* if wait state is new, we keep current time for watchdog MaxWaitTime */
15 +   switch (SDJobStatus) {
16 +      case JS_WaitMedia:
17 +      case JS_WaitMount:
18 +      case JS_WaitMaxJobs:
19 +        set_waittime = true;
20 +      default:
21 +        break;
22 +   }
23 +
24 +   if (job_waiting(jcr)) {
25 +      set_waittime = false;
26 +   }
27 +
28 +   if (set_waittime) {
29 +      /* set it before JobStatus */
30 +      Dmsg0(800, "Setting wait_time\n");
31 +      jcr->wait_time = time(NULL);
32 +   }
33 +   jcr->SDJobStatus = SDJobStatus;
34 +}
35 +
36  /*
37   * Get a message
38   *  Call appropriate processing routine
39 @@ -230,7 +257,7 @@
40           int JobStatus;
41           char Job[MAX_NAME_LENGTH];
42           if (sscanf(bs->msg, Job_status, &Job, &JobStatus) == 2) {
43 -            jcr->SDJobStatus = JobStatus; /* current status */
44 +            set_jcr_sd_job_status(jcr,JobStatus); /* current status */
45           } else {
46              Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
47           }
48 Index: src/dird/job.c
49 ===================================================================
50 --- src/dird/job.c      (révision 4696)
51 +++ src/dird/job.c      (copie de travail)
52 @@ -41,8 +41,9 @@
53  static void *job_thread(void *arg);
54  static void job_monitor_watchdog(watchdog_t *self);
55  static void job_monitor_destructor(watchdog_t *self);
56 -static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr);
57 -static bool job_check_maxruntime(JCR *control_jcr, JCR *jcr);
58 +static bool job_check_maxwaittime(JCR *jcr);
59 +static bool job_check_maxruntime(JCR *jcr);
60 +static bool job_check_maxschedruntime(JCR *jcr);
61  
62  /* Imported subroutines */
63  extern void term_scheduler();
64 @@ -250,6 +251,11 @@
65        Jmsg(jcr, M_FATAL, 0, _("Job canceled because max start delay time exceeded.\n"));
66     }
67  
68 +   if (job_check_maxschedruntime(jcr)) {
69 +      set_jcr_job_status(jcr, JS_Canceled);
70 +      Jmsg(jcr, M_FATAL, 0, _("Job canceled because max sched run time exceeded.\n"));
71 +   }
72 +
73     /* TODO : check if it is used somewhere */
74     if (jcr->job->RunScripts == NULL) {
75        Dmsg0(200, "Warning, job->RunScripts is empty\n");
76 @@ -450,15 +456,20 @@
77        }
78  
79        /* check MaxWaitTime */
80 -      if (job_check_maxwaittime(control_jcr, jcr)) {
81 +      if (job_check_maxwaittime(jcr)) {
82           set_jcr_job_status(jcr, JS_Canceled);
83           Jmsg(jcr, M_FATAL, 0, _("Max wait time exceeded. Job canceled.\n"));
84           cancel = true;
85        /* check MaxRunTime */
86 -      } else if (job_check_maxruntime(control_jcr, jcr)) {
87 +      } else if (job_check_maxruntime(jcr)) {
88           set_jcr_job_status(jcr, JS_Canceled);
89           Jmsg(jcr, M_FATAL, 0, _("Max run time exceeded. Job canceled.\n"));
90           cancel = true;
91 +      /* check MaxSchedRunTime */ 
92 +      } else if (job_check_maxschedruntime(jcr)) {
93 +         set_jcr_job_status(jcr, JS_Canceled);
94 +         Jmsg(jcr, M_FATAL, 0, _("Max sched run time exceeded. Job canceled.\n"));
95 +         cancel = true;
96        }
97  
98        if (cancel) {
99 @@ -479,29 +490,30 @@
100   * Check if the maxwaittime has expired and it is possible
101   *  to cancel the job.
102   */
103 -static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr)
104 +static bool job_check_maxwaittime(JCR *jcr)
105  {
106     bool cancel = false;
107     JOB *job = jcr->job;
108  
109 -   if (job_canceled(jcr)) {
110 -      return false;                /* already canceled */
111 +   if (!job_waiting(jcr)) {
112 +      return false;
113     }
114     if (job->MaxWaitTime == 0 && job->FullMaxWaitTime == 0 &&
115         job->IncMaxWaitTime == 0 && job->DiffMaxWaitTime == 0) {
116        return false;
117     } 
118 +   Dmsg3(20, "check maxwaittime %u - %u >= %u\n", watchdog_time, jcr->wait_time, job->MaxWaitTime);
119     if (jcr->JobLevel == L_FULL && job->FullMaxWaitTime != 0 &&
120 -         (watchdog_time - jcr->start_time) >= job->FullMaxWaitTime) {
121 +         (watchdog_time - jcr->wait_time) >= job->FullMaxWaitTime) {
122        cancel = true;
123     } else if (jcr->JobLevel == L_DIFFERENTIAL && job->DiffMaxWaitTime != 0 &&
124 -         (watchdog_time - jcr->start_time) >= job->DiffMaxWaitTime) {
125 +         (watchdog_time - jcr->wait_time) >= job->DiffMaxWaitTime) {
126        cancel = true;
127     } else if (jcr->JobLevel == L_INCREMENTAL && job->IncMaxWaitTime != 0 &&
128 -         (watchdog_time - jcr->start_time) >= job->IncMaxWaitTime) {
129 +         (watchdog_time - jcr->wait_time) >= job->IncMaxWaitTime) {
130        cancel = true;
131     } else if (job->MaxWaitTime != 0 &&
132 -         (watchdog_time - jcr->start_time) >= job->MaxWaitTime) {
133 +         (watchdog_time - jcr->wait_time) >= job->MaxWaitTime) {
134        cancel = true;
135     }
136  
137 @@ -512,7 +524,7 @@
138   * Check if maxruntime has expired and if the job can be
139   *   canceled.
140   */
141 -static bool job_check_maxruntime(JCR *control_jcr, JCR *jcr)
142 +static bool job_check_maxruntime(JCR *jcr)
143  {
144     if (jcr->job->MaxRunTime == 0 || job_canceled(jcr)) {
145        return false;
146 @@ -527,6 +539,24 @@
147  }
148  
149  /*
150 + * Check if MaxSchedRunTime has expired and if the job can be
151 + *   canceled.
152 + */
153 +static bool job_check_maxschedruntime(JCR *jcr)
154 +{
155 +   if (jcr->job->MaxSchedRunTime == 0 || job_canceled(jcr)) {
156 +      return false;
157 +   }
158 +   if ((watchdog_time - jcr->sched_time) < jcr->job->MaxSchedRunTime) {
159 +      Dmsg3(200, "Job %p (%s) with MaxSchedRunTime %d not expired\n",
160 +            jcr, jcr->Job, jcr->job->MaxSchedRunTime);
161 +      return false;
162 +   }
163 +
164 +   return true;
165 +}
166 +
167 +/*
168   * Get or create a Pool record with the given name.
169   * Returns: 0 on error
170   *          poolid if OK
171 Index: src/dird/dird_conf.c
172 ===================================================================
173 --- src/dird/dird_conf.c        (révision 4696)
174 +++ src/dird/dird_conf.c        (copie de travail)
175 @@ -281,6 +281,7 @@
176     {"writebootstrap",store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0},
177     {"writeverifylist",store_dir, ITEM(res_job.WriteVerifyList), 0, 0, 0},
178     {"replace",  store_replace,  ITEM(res_job.replace), 0, ITEM_DEFAULT, REPLACE_ALWAYS},
179 +   {"maxschedruntime", store_time, ITEM(res_job.MaxSchedRunTime), 0, 0, 0},
180     {"maxruntime",   store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
181     {"fullmaxwaittime",  store_time, ITEM(res_job.FullMaxWaitTime), 0, 0, 0},
182     {"incrementalmaxwaittime",  store_time, ITEM(res_job.IncMaxWaitTime), 0, 0, 0},
183 @@ -627,6 +628,15 @@
184        if (res->res_job.WriteBootstrap) {
185           sendit(sock, _("  --> WriteBootstrap=%s\n"), NPRT(res->res_job.WriteBootstrap));
186        }
187 +      if (res->res_job.MaxRunTime) {
188 +         sendit(sock, _("  --> MaxRunTime=%u\n"), res->res_job.MaxRunTime);
189 +      }
190 +      if (res->res_job.MaxWaitTime) {
191 +         sendit(sock, _("  --> MaxWaitTime=%u\n"), res->res_job.MaxWaitTime);
192 +      }
193 +      if (res->res_job.MaxStartDelay) {
194 +         sendit(sock, _("  --> MaxStartDelay=%u\n"), res->res_job.MaxStartDelay);
195 +      }
196        if (res->res_job.storage) {
197           STORE *store;
198           foreach_alist(store, res->res_job.storage) {
199 Index: src/dird/dird_conf.h
200 ===================================================================
201 --- src/dird/dird_conf.h        (révision 4696)
202 +++ src/dird/dird_conf.h        (copie de travail)
203 @@ -371,6 +371,7 @@
204        char *WriteVerifyList;          /* List of changed files */
205     };
206     int   replace;                     /* How (overwrite, ..) */
207 +   utime_t MaxSchedRunTime;           /* max run time in seconds from Scheduled time*/
208     utime_t MaxRunTime;                /* max run time in seconds */
209     utime_t MaxWaitTime;               /* max blocking time in seconds */
210     utime_t FullMaxWaitTime;           /* Max Full job wait time */
211 Index: src/jcr.h
212 ===================================================================
213 --- src/jcr.h   (révision 4696)
214 +++ src/jcr.h   (copie de travail)
215 @@ -105,6 +105,22 @@
216     jcr->JobStatus == JS_ErrorTerminated || \
217     jcr->JobStatus == JS_FatalError)
218  
219 +#define job_waiting(jcr) \
220 +  (jcr->JobStatus == JS_WaitFD       || \
221 +   jcr->JobStatus == JS_WaitSD      || \
222 +   jcr->JobStatus == JS_WaitMedia    || \
223 +   jcr->JobStatus == JS_WaitMount    || \
224 +   jcr->JobStatus == JS_WaitStoreRes || \
225 +   jcr->JobStatus == JS_WaitJobRes   || \
226 +   jcr->JobStatus == JS_WaitClientRes|| \
227 +   jcr->JobStatus == JS_WaitMaxJobs  || \
228 +   jcr->JobStatus == JS_WaitPriority || \
229 +   jcr->SDJobStatus == JS_WaitMedia  || \
230 +   jcr->SDJobStatus == JS_WaitMount  || \
231 +   jcr->SDJobStatus == JS_WaitMaxJobs)
232 +
233 +
234 +
235  #define foreach_jcr(jcr) \
236     for (jcr=jcr_walk_start(); jcr; (jcr=jcr_walk_next(jcr)) )
237  
238 @@ -166,6 +182,7 @@
239     time_t start_time;                 /* when job actually started */
240     time_t run_time;                   /* used for computing speed */
241     time_t end_time;                   /* job end time */
242 +   time_t wait_time;                  /* when job have started to wait */
243     POOLMEM *client_name;              /* client name */
244     POOLMEM *RestoreBootstrap;         /* Bootstrap file to restore */
245     POOLMEM *stime;                    /* start time for incremental/differential */
246 Index: src/lib/jcr.c
247 ===================================================================
248 --- src/lib/jcr.c       (révision 4696)
249 +++ src/lib/jcr.c       (copie de travail)
250 @@ -546,18 +546,54 @@
251  
252  void set_jcr_job_status(JCR *jcr, int JobStatus)
253  {
254 +   bool set_waittime=false;
255 +   Dmsg2(800, "set_jcr_job_status(%s, %c)\n", jcr->Job, JobStatus);
256 +   /* if wait state is new, we keep current time for watchdog MaxWaitTime */
257 +   switch (JobStatus) {
258 +      case JS_WaitFD:
259 +      case JS_WaitSD:
260 +      case JS_WaitMedia:
261 +      case JS_WaitMount:
262 +      case JS_WaitStoreRes:
263 +      case JS_WaitJobRes:
264 +      case JS_WaitClientRes:
265 +      case JS_WaitMaxJobs:
266 +      case JS_WaitPriority:
267 +        set_waittime = true;
268 +      default:
269 +        break;
270 +   }
271 +
272 +   switch (jcr->JobStatus) {
273     /*
274      * For a set of errors, ... keep the current status
275      *   so it isn't lost. For all others, set it.
276      */
277 -   switch (jcr->JobStatus) {
278     case JS_ErrorTerminated:
279     case JS_Error:
280     case JS_FatalError:
281     case JS_Differences:
282     case JS_Canceled:
283        break;
284 +   /*
285 +    * For a set of Wait situation, keep old time.
286 +    */
287 +   case JS_WaitFD:
288 +   case JS_WaitSD:
289 +   case JS_WaitMedia:
290 +   case JS_WaitMount:
291 +   case JS_WaitStoreRes:
292 +   case JS_WaitJobRes:
293 +   case JS_WaitClientRes:
294 +   case JS_WaitMaxJobs:
295 +   case JS_WaitPriority:  
296 +      set_waittime = false;    /* keep old time */
297     default:
298 +      if (set_waittime) {
299 +        /* set it before JobStatus */
300 +        Dmsg0(800, "Setting wait_time\n");
301 +        jcr->wait_time = time(NULL);
302 +      }
303        jcr->JobStatus = JobStatus;
304     }
305  }