]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/bug_897_1005.patch
ebl First version of this patch, we need to handle VSS failure
[bacula/bacula] / bacula / patches / testing / bug_897_1005.patch
1 Index: src/dird/backup.c
2 ===================================================================
3 --- src/dird/backup.c   (révision 5819)
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,8 +267,13 @@
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 +
32 +   if (timeout) {
33 +      tid = start_bsock_timer(fd, timeout); /* TODO: use user timeout */
34 +   }
35     /* Wait for Client to terminate */
36     while ((n = bget_dirmsg(fd)) >= 0) {
37        if (!fd_ok && 
38 @@ -288,6 +292,9 @@
39           break;
40        }
41     }
42 +   if (tid) {
43 +      stop_bsock_timer(tid);
44 +   }
45  
46     if (is_bnet_error(fd)) {
47        Jmsg(jcr, M_FATAL, 0, _("Network error with FD during %s: ERR=%s\n"),
48 Index: src/dird/protos.h
49 ===================================================================
50 --- src/dird/protos.h   (révision 5819)
51 +++ src/dird/protos.h   (copie de travail)
52 @@ -52,7 +52,7 @@
53  extern bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr);
54  
55  /* backup.c */
56 -extern int wait_for_job_termination(JCR *jcr);
57 +extern int wait_for_job_termination(JCR *jcr, int timeout=0);
58  extern bool do_backup_init(JCR *jcr);
59  extern bool do_backup(JCR *jcr);
60  extern void backup_cleanup(JCR *jcr, int TermCode);
61 Index: src/filed/job.c
62 ===================================================================
63 --- src/filed/job.c     (révision 5856)
64 +++ src/filed/job.c     (copie de travail)
65 @@ -269,6 +269,16 @@
66     /* Run the after job */
67     run_scripts(jcr, jcr->RunScripts, "ClientAfterJob");
68  
69 +   if (jcr->JobId) {
70 +      char ed1[50], ed2[50];
71 +      /* Send termination status back to Dir */
72 +      bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
73 +                edit_uint64(jcr->ReadBytes, ed1),
74 +                edit_uint64(jcr->JobBytes, ed2), jcr->Errors, jcr->VSS,
75 +                jcr->pki_encrypt);
76 +      Dmsg1(110, "End FD msg: %s\n", dir->msg);
77 +   }
78 +
79     generate_daemon_event(jcr, "JobEnd");
80  
81     dequeue_messages(jcr);             /* send any queued messages */
82 @@ -1331,15 +1341,13 @@
83     BSOCK *sd = jcr->store_bsock;
84     int ok = 0;
85     int SDJobStatus;
86 -   char ed1[50], ed2[50];
87 -   bool bDoVSS = false;
88  
89  #if defined(WIN32_VSS)
90     // capture state here, if client is backed up by multiple directors
91     // and one enables vss and the other does not then enable_vss can change
92     // between here and where its evaluated after the job completes.
93 -   bDoVSS = g_pVSSClient && enable_vss;
94 -   if (bDoVSS) {
95 +   jcr->VSS = g_pVSSClient && enable_vss;
96 +   if (jcr->VSS) {
97        /* Run only one at a time */
98        P(vss_mutex);
99     }
100 @@ -1395,7 +1403,7 @@
101  
102  #if defined(WIN32_VSS)
103     /* START VSS ON WIN 32 */
104 -   if (bDoVSS) {      
105 +   if (jcr->VSS) {      
106        if (g_pVSSClient->InitializeForBackup()) {   
107          /* tell vss which drives to snapshot */   
108          char szWinDriveLetters[27];   
109 @@ -1488,7 +1496,7 @@
110  #if defined(WIN32_VSS)
111     /* STOP VSS ON WIN 32 */
112     /* tell vss to close the backup session */
113 -   if (bDoVSS) {
114 +   if (jcr->VSS) {
115        if (g_pVSSClient->CloseBackup()) {             
116           /* inform user about writer states */
117           for (int i=0; i<(int)g_pVSSClient->GetWriterCount(); i++) {
118 @@ -1504,12 +1512,6 @@
119     }
120  #endif
121  
122 -   bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
123 -      edit_uint64(jcr->ReadBytes, ed1),
124 -      edit_uint64(jcr->JobBytes, ed2), jcr->Errors, (int)bDoVSS, 
125 -      jcr->pki_encrypt);
126 -   Dmsg1(110, "End FD msg: %s\n", dir->msg);
127 -   
128     return 0;                          /* return and stop command loop */
129  }
130  
131 @@ -1521,7 +1523,7 @@
132  {
133     BSOCK *dir = jcr->dir_bsock;
134     BSOCK *sd  = jcr->store_bsock;
135 -   char level[100], ed1[50], ed2[50];
136 +   char level[100];
137  
138     jcr->JobType = JT_VERIFY;
139     if (sscanf(dir->msg, verifycmd, level) != 1) {
140 @@ -1585,15 +1587,6 @@
141  
142     bnet_sig(dir, BNET_EOD);
143  
144 -   /* Send termination status back to Dir */
145 -   bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
146 -      edit_uint64(jcr->ReadBytes, ed1),
147 -      edit_uint64(jcr->JobBytes, ed2), jcr->Errors, 0,
148 -      jcr->pki_encrypt);
149 -   Dmsg1(110, "End FD msg: %s\n", dir->msg);
150 -
151 -   /* Inform Director that we are done */
152 -   bnet_sig(dir, BNET_TERMINATE);
153     return 0;                          /* return and terminate command loop */
154  }
155  
156 @@ -1609,7 +1602,6 @@
157     bool use_regexwhere=false;
158     int prefix_links;
159     char replace;
160 -   char ed1[50], ed2[50];
161  
162     /*
163      * Scan WHERE (base directory for restore) from command
164 @@ -1696,16 +1688,7 @@
165     if (jcr->Errors) {
166        set_jcr_job_status(jcr, JS_ErrorTerminated);
167     }
168 -   /* Send termination status back to Dir */
169 -   bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
170 -      edit_uint64(jcr->ReadBytes, ed1),
171 -      edit_uint64(jcr->JobBytes, ed2), jcr->Errors, 0,
172 -      jcr->pki_encrypt);
173 -   Dmsg1(110, "End FD msg: %s\n", dir->msg);
174  
175 -   /* Inform Director that we are done */
176 -   bnet_sig(dir, BNET_TERMINATE);
177 -
178     Dmsg0(130, "Done in job.c\n");
179     return 0;                          /* return and terminate command loop */
180  }
181 Index: src/jcr.h
182 ===================================================================
183 --- src/jcr.h   (révision 5856)
184 +++ src/jcr.h   (copie de travail)
185 @@ -301,6 +301,7 @@
186     int32_t pki_session_encoded_size;  /* Size of DER-encoded pki_session */
187     POOLMEM *crypto_buf;               /* Encryption/Decryption buffer */
188     DIRRES* director;                  /* Director resource */
189 +   bool VSS;                          /* VSS used by FD */
190  #endif /* FILE_DAEMON */
191  
192