]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/bug_897.patch
ebl First version of this patch, we need to handle VSS failure
[bacula/bacula] / bacula / patches / testing / bug_897.patch
1 Index: src/dird/backup.c
2 ===================================================================
3 --- src/dird/backup.c   (révision 5882)
4 +++ src/dird/backup.c   (copie de travail)
5 @@ -245,8 +245,7 @@
6     set_jcr_job_status(jcr, JS_ErrorTerminated);
7     Dmsg1(400, "wait for sd. use=%d\n", jcr->use_count());
8     /* Cancel SD */
9 -   cancel_storage_daemon_job(jcr);
10 -   wait_for_storage_daemon_termination(jcr);
11 +   wait_for_job_termination(jcr, 300);
12     Dmsg1(400, "after wait for sd. use=%d\n", jcr->use_count());
13     return false;
14  }
15 @@ -258,7 +257,7 @@
16   *   are done, we return the job status.
17   * Also used by restore.c
18   */
19 -int wait_for_job_termination(JCR *jcr)
20 +int wait_for_job_termination(JCR *jcr, int timeout)
21  {
22     int32_t n = 0;
23     BSOCK *fd = jcr->file_bsock;
24 @@ -268,32 +267,42 @@
25     uint64_t JobBytes = 0;
26     int VSS = 0;
27     int Encrypt = 0;
28 +   btimer_t *tid=NULL;
29  
30     set_jcr_job_status(jcr, JS_Running);
31 -   /* Wait for Client to terminate */
32 -   while ((n = bget_dirmsg(fd)) >= 0) {
33 -      if (!fd_ok && 
34 -          (sscanf(fd->msg, EndJob, &jcr->FDJobStatus, &JobFiles,
35 -              &ReadBytes, &JobBytes, &Errors, &VSS, &Encrypt) == 7 ||
36 -           sscanf(fd->msg, OldEndJob, &jcr->FDJobStatus, &JobFiles,
37 -                 &ReadBytes, &JobBytes, &Errors) == 5)) {
38 -         fd_ok = true;
39 -         set_jcr_job_status(jcr, jcr->FDJobStatus);
40 -         Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus);
41 -      } else {
42 -         Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
43 -            fd->msg);
44 +
45 +   if (fd) {
46 +      if (timeout) {
47 +         tid = start_bsock_timer(fd, timeout); /* TODO: use user timeout */
48        }
49 -      if (job_canceled(jcr)) {
50 -         break;
51 +      /* Wait for Client to terminate */
52 +      while ((n = bget_dirmsg(fd)) >= 0) {
53 +         if (!fd_ok && 
54 +             (sscanf(fd->msg, EndJob, &jcr->FDJobStatus, &JobFiles,
55 +                     &ReadBytes, &JobBytes, &Errors, &VSS, &Encrypt) == 7 ||
56 +              sscanf(fd->msg, OldEndJob, &jcr->FDJobStatus, &JobFiles,
57 +                     &ReadBytes, &JobBytes, &Errors) == 5)) {
58 +            fd_ok = true;
59 +            set_jcr_job_status(jcr, jcr->FDJobStatus);
60 +            Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus);
61 +         } else {
62 +            Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
63 +                 fd->msg);
64 +         }
65 +         if (job_canceled(jcr)) {
66 +            break;
67 +         }
68        }
69 -   }
70 +      if (tid) {
71 +         stop_bsock_timer(tid);
72 +      }
73  
74 -   if (is_bnet_error(fd)) {
75 -      Jmsg(jcr, M_FATAL, 0, _("Network error with FD during %s: ERR=%s\n"),
76 -          job_type_to_str(jcr->JobType), fd->bstrerror());
77 +      if (is_bnet_error(fd)) {
78 +         Jmsg(jcr, M_FATAL, 0, _("Network error with FD during %s: ERR=%s\n"),
79 +              job_type_to_str(jcr->JobType), fd->bstrerror());
80 +      }
81 +      fd->signal(BNET_TERMINATE);   /* tell Client we are terminating */
82     }
83 -   fd->signal(BNET_TERMINATE);   /* tell Client we are terminating */
84  
85     /* Force cancel in SD if failing */
86     if (job_canceled(jcr) || !fd_ok) {
87 @@ -303,7 +312,6 @@
88     /* Note, the SD stores in jcr->JobFiles/ReadBytes/JobBytes/Errors */
89     wait_for_storage_daemon_termination(jcr);
90  
91 -
92     /* Return values from FD */
93     if (fd_ok) {
94        jcr->JobFiles = JobFiles;
95 @@ -320,7 +328,7 @@
96  //   jcr->JobStatus, jcr->SDJobStatus);
97  
98     /* Return the first error status we find Dir, FD, or SD */
99 -   if (!fd_ok || is_bnet_error(fd)) {
100 +   if (!fd_ok || is_bnet_error(fd)) { /* if fd not set, that use !fd_ok */
101        jcr->FDJobStatus = JS_ErrorTerminated;
102     }
103     if (jcr->JobStatus != JS_Terminated) {
104 Index: src/dird/protos.h
105 ===================================================================
106 --- src/dird/protos.h   (révision 5882)
107 +++ src/dird/protos.h   (copie de travail)
108 @@ -52,7 +52,7 @@
109  extern bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr);
110  
111  /* backup.c */
112 -extern int wait_for_job_termination(JCR *jcr);
113 +extern int wait_for_job_termination(JCR *jcr, int timeout=0);
114  extern bool do_backup_init(JCR *jcr);
115  extern bool do_backup(JCR *jcr);
116  extern void backup_cleanup(JCR *jcr, int TermCode);
117 Index: src/filed/job.c
118 ===================================================================
119 --- src/filed/job.c     (révision 5882)
120 +++ src/filed/job.c     (copie de travail)
121 @@ -261,6 +261,16 @@
122        }
123     }
124  
125 +   if (jcr->JobId) {           /* send EndJob if running a job */
126 +      char ed1[50], ed2[50];
127 +      /* Send termination status back to Dir */
128 +      bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
129 +                edit_uint64(jcr->ReadBytes, ed1),
130 +                edit_uint64(jcr->JobBytes, ed2), jcr->Errors, jcr->VSS,
131 +                jcr->pki_encrypt);
132 +      Dmsg1(110, "End FD msg: %s\n", dir->msg);
133 +   }
134 +
135     /* Inform Storage daemon that we are done */
136     if (jcr->store_bsock) {
137        bnet_sig(jcr->store_bsock, BNET_TERMINATE);
138 @@ -1331,15 +1341,13 @@
139     BSOCK *sd = jcr->store_bsock;
140     int ok = 0;
141     int SDJobStatus;
142 -   char ed1[50], ed2[50];
143 -   bool bDoVSS = false;
144  
145  #if defined(WIN32_VSS)
146     // capture state here, if client is backed up by multiple directors
147     // and one enables vss and the other does not then enable_vss can change
148     // between here and where its evaluated after the job completes.
149 -   bDoVSS = g_pVSSClient && enable_vss;
150 -   if (bDoVSS) {
151 +   jcr->VSS = g_pVSSClient && enable_vss;
152 +   if (jcr->VSS) {
153        /* Run only one at a time */
154        P(vss_mutex);
155     }
156 @@ -1395,7 +1403,7 @@
157  
158  #if defined(WIN32_VSS)
159     /* START VSS ON WIN 32 */
160 -   if (bDoVSS) {      
161 +   if (jcr->VSS) {      
162        if (g_pVSSClient->InitializeForBackup()) {   
163          /* tell vss which drives to snapshot */   
164          char szWinDriveLetters[27];   
165 @@ -1488,7 +1496,7 @@
166  #if defined(WIN32_VSS)
167     /* STOP VSS ON WIN 32 */
168     /* tell vss to close the backup session */
169 -   if (bDoVSS) {
170 +   if (jcr->VSS) {
171        if (g_pVSSClient->CloseBackup()) {             
172           /* inform user about writer states */
173           for (int i=0; i<(int)g_pVSSClient->GetWriterCount(); i++) {
174 @@ -1504,12 +1512,6 @@
175     }
176  #endif
177  
178 -   bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
179 -      edit_uint64(jcr->ReadBytes, ed1),
180 -      edit_uint64(jcr->JobBytes, ed2), jcr->Errors, (int)bDoVSS, 
181 -      jcr->pki_encrypt);
182 -   Dmsg1(110, "End FD msg: %s\n", dir->msg);
183 -   
184     return 0;                          /* return and stop command loop */
185  }
186  
187 @@ -1521,7 +1523,7 @@
188  {
189     BSOCK *dir = jcr->dir_bsock;
190     BSOCK *sd  = jcr->store_bsock;
191 -   char level[100], ed1[50], ed2[50];
192 +   char level[100];
193  
194     jcr->JobType = JT_VERIFY;
195     if (sscanf(dir->msg, verifycmd, level) != 1) {
196 @@ -1585,15 +1587,6 @@
197  
198     bnet_sig(dir, BNET_EOD);
199  
200 -   /* Send termination status back to Dir */
201 -   bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
202 -      edit_uint64(jcr->ReadBytes, ed1),
203 -      edit_uint64(jcr->JobBytes, ed2), jcr->Errors, 0,
204 -      jcr->pki_encrypt);
205 -   Dmsg1(110, "End FD msg: %s\n", dir->msg);
206 -
207 -   /* Inform Director that we are done */
208 -   bnet_sig(dir, BNET_TERMINATE);
209     return 0;                          /* return and terminate command loop */
210  }
211  
212 @@ -1609,7 +1602,6 @@
213     bool use_regexwhere=false;
214     int prefix_links;
215     char replace;
216 -   char ed1[50], ed2[50];
217  
218     /*
219      * Scan WHERE (base directory for restore) from command
220 @@ -1696,16 +1688,7 @@
221     if (jcr->Errors) {
222        set_jcr_job_status(jcr, JS_ErrorTerminated);
223     }
224 -   /* Send termination status back to Dir */
225 -   bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
226 -      edit_uint64(jcr->ReadBytes, ed1),
227 -      edit_uint64(jcr->JobBytes, ed2), jcr->Errors, 0,
228 -      jcr->pki_encrypt);
229 -   Dmsg1(110, "End FD msg: %s\n", dir->msg);
230  
231 -   /* Inform Director that we are done */
232 -   bnet_sig(dir, BNET_TERMINATE);
233 -
234     Dmsg0(130, "Done in job.c\n");
235     return 0;                          /* return and terminate command loop */
236  }
237 Index: src/jcr.h
238 ===================================================================
239 --- src/jcr.h   (révision 5882)
240 +++ src/jcr.h   (copie de travail)
241 @@ -301,6 +301,7 @@
242     int32_t pki_session_encoded_size;  /* Size of DER-encoded pki_session */
243     POOLMEM *crypto_buf;               /* Encryption/Decryption buffer */
244     DIRRES* director;                  /* Director resource */
245 +   bool VSS;                          /* VSS used by FD */
246  #endif /* FILE_DAEMON */
247  
248