]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/real_maxwaittime.patch
ebl Update to use a separate db connexion to compute and
[bacula/bacula] / bacula / patches / testing / real_maxwaittime.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 @@ -484,24 +484,25 @@
53     bool cancel = false;
54     JOB *job = jcr->job;
55  
56 -   if (job_canceled(jcr)) {
57 -      return false;                /* already canceled */
58 +   if (!job_waiting(jcr)) {
59 +      return false;
60     }
61     if (job->MaxWaitTime == 0 && job->FullMaxWaitTime == 0 &&
62         job->IncMaxWaitTime == 0 && job->DiffMaxWaitTime == 0) {
63        return false;
64     } 
65 +   Dmsg3(20, "check maxwaittime %u - %u >= %u\n", watchdog_time, jcr->wait_time, job->MaxWaitTime);
66     if (jcr->JobLevel == L_FULL && job->FullMaxWaitTime != 0 &&
67 -         (watchdog_time - jcr->start_time) >= job->FullMaxWaitTime) {
68 +         (watchdog_time - jcr->wait_time) >= job->FullMaxWaitTime) {
69        cancel = true;
70     } else if (jcr->JobLevel == L_DIFFERENTIAL && job->DiffMaxWaitTime != 0 &&
71 -         (watchdog_time - jcr->start_time) >= job->DiffMaxWaitTime) {
72 +         (watchdog_time - jcr->wait_time) >= job->DiffMaxWaitTime) {
73        cancel = true;
74     } else if (jcr->JobLevel == L_INCREMENTAL && job->IncMaxWaitTime != 0 &&
75 -         (watchdog_time - jcr->start_time) >= job->IncMaxWaitTime) {
76 +         (watchdog_time - jcr->wait_time) >= job->IncMaxWaitTime) {
77        cancel = true;
78     } else if (job->MaxWaitTime != 0 &&
79 -         (watchdog_time - jcr->start_time) >= job->MaxWaitTime) {
80 +         (watchdog_time - jcr->wait_time) >= job->MaxWaitTime) {
81        cancel = true;
82     }
83  
84 Index: src/dird/dird_conf.c
85 ===================================================================
86 --- src/dird/dird_conf.c        (révision 4696)
87 +++ src/dird/dird_conf.c        (copie de travail)
88 @@ -627,6 +627,15 @@
89        if (res->res_job.WriteBootstrap) {
90           sendit(sock, _("  --> WriteBootstrap=%s\n"), NPRT(res->res_job.WriteBootstrap));
91        }
92 +      if (res->res_job.MaxRunTime) {
93 +         sendit(sock, _("  --> MaxRunTime=%u\n"), res->res_job.MaxRunTime);
94 +      }
95 +      if (res->res_job.MaxWaitTime) {
96 +         sendit(sock, _("  --> MaxWaitTime=%u\n"), res->res_job.MaxWaitTime);
97 +      }
98 +      if (res->res_job.MaxStartDelay) {
99 +         sendit(sock, _("  --> MaxStartDelay=%u\n"), res->res_job.MaxStartDelay);
100 +      }
101        if (res->res_job.storage) {
102           STORE *store;
103           foreach_alist(store, res->res_job.storage) {
104 Index: src/jcr.h
105 ===================================================================
106 --- src/jcr.h   (révision 4696)
107 +++ src/jcr.h   (copie de travail)
108 @@ -105,6 +105,22 @@
109     jcr->JobStatus == JS_ErrorTerminated || \
110     jcr->JobStatus == JS_FatalError)
111  
112 +#define job_waiting(jcr) \
113 +  (jcr->JobStatus == JS_WaitFD       || \
114 +   jcr->JobStatus == JS_WaitSD      || \
115 +   jcr->JobStatus == JS_WaitMedia    || \
116 +   jcr->JobStatus == JS_WaitMount    || \
117 +   jcr->JobStatus == JS_WaitStoreRes || \
118 +   jcr->JobStatus == JS_WaitJobRes   || \
119 +   jcr->JobStatus == JS_WaitClientRes|| \
120 +   jcr->JobStatus == JS_WaitMaxJobs  || \
121 +   jcr->JobStatus == JS_WaitPriority || \
122 +   jcr->SDJobStatus == JS_WaitMedia  || \
123 +   jcr->SDJobStatus == JS_WaitMount  || \
124 +   jcr->SDJobStatus == JS_WaitMaxJobs)
125 +
126 +
127 +
128  #define foreach_jcr(jcr) \
129     for (jcr=jcr_walk_start(); jcr; (jcr=jcr_walk_next(jcr)) )
130  
131 @@ -166,6 +182,7 @@
132     time_t start_time;                 /* when job actually started */
133     time_t run_time;                   /* used for computing speed */
134     time_t end_time;                   /* job end time */
135 +   time_t wait_time;                  /* when job have started to wait */
136     POOLMEM *client_name;              /* client name */
137     POOLMEM *RestoreBootstrap;         /* Bootstrap file to restore */
138     POOLMEM *stime;                    /* start time for incremental/differential */
139 Index: src/lib/jcr.c
140 ===================================================================
141 --- src/lib/jcr.c       (révision 4696)
142 +++ src/lib/jcr.c       (copie de travail)
143 @@ -546,18 +546,54 @@
144  
145  void set_jcr_job_status(JCR *jcr, int JobStatus)
146  {
147 +   bool set_waittime=false;
148 +   Dmsg2(800, "set_jcr_job_status(%s, %c)\n", jcr->Job, JobStatus);
149 +   /* if wait state is new, we keep current time for watchdog MaxWaitTime */
150 +   switch (JobStatus) {
151 +      case JS_WaitFD:
152 +      case JS_WaitSD:
153 +      case JS_WaitMedia:
154 +      case JS_WaitMount:
155 +      case JS_WaitStoreRes:
156 +      case JS_WaitJobRes:
157 +      case JS_WaitClientRes:
158 +      case JS_WaitMaxJobs:
159 +      case JS_WaitPriority:
160 +        set_waittime = true;
161 +      default:
162 +        break;
163 +   }
164 +
165 +   switch (jcr->JobStatus) {
166     /*
167      * For a set of errors, ... keep the current status
168      *   so it isn't lost. For all others, set it.
169      */
170 -   switch (jcr->JobStatus) {
171     case JS_ErrorTerminated:
172     case JS_Error:
173     case JS_FatalError:
174     case JS_Differences:
175     case JS_Canceled:
176        break;
177 +   /*
178 +    * For a set of Wait situation, keep old time.
179 +    */
180 +   case JS_WaitFD:
181 +   case JS_WaitSD:
182 +   case JS_WaitMedia:
183 +   case JS_WaitMount:
184 +   case JS_WaitStoreRes:
185 +   case JS_WaitJobRes:
186 +   case JS_WaitClientRes:
187 +   case JS_WaitMaxJobs:
188 +   case JS_WaitPriority:  
189 +      set_waittime = false;    /* keep old time */
190     default:
191 +      if (set_waittime) {
192 +        /* set it before JobStatus */
193 +        Dmsg0(800, "Setting wait_time\n");
194 +        jcr->wait_time = time(NULL);
195 +      }
196        jcr->JobStatus = JobStatus;
197     }
198  }