]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/bug_1166_cancel_read.patch
c25e1d017b686566d7781ba4ce6998094841f850
[bacula/bacula] / bacula / patches / testing / bug_1166_cancel_read.patch
1 Index: src/dird/backup.c
2 ===================================================================
3 --- src/dird/backup.c   (revision 7725)
4 +++ src/dird/backup.c   (working copy)
5 @@ -193,6 +193,7 @@
6     Jmsg(jcr, M_INFO, 0, _("Start Backup JobId %s, Job=%s\n"),
7          edit_uint64(jcr->JobId, ed1), jcr->Job);
8  
9 +   jcr->set_owner();            /* we are responsible for this job */
10     set_jcr_job_status(jcr, JS_Running);
11     Dmsg2(100, "JobId=%d JobLevel=%c\n", jcr->jr.JobId, jcr->jr.JobLevel);
12     if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
13 @@ -361,8 +362,10 @@
14        if (timeout) {
15           tid = start_bsock_timer(fd, timeout); /* TODO: New timeout directive??? */
16        }
17 +      Dmsg0(1, "======== Wait for a message\n");
18        /* Wait for Client to terminate */
19        while ((n = bget_dirmsg(fd)) >= 0) {
20 +         Dmsg1(1, "======= Get client message=%s\n", fd->msg);
21           if (!fd_ok && 
22               (sscanf(fd->msg, EndJob, &jcr->FDJobStatus, &JobFiles,
23                       &ReadBytes, &JobBytes, &Errors, &VSS, &Encrypt) == 7 ||
24 Index: src/dird/job.c
25 ===================================================================
26 --- src/dird/job.c      (revision 7731)
27 +++ src/dird/job.c      (working copy)
28 @@ -390,6 +390,14 @@
29        jobq_remove(&job_queue, jcr); /* attempt to remove it from queue */
30        return true;
31  
32 +   case JS_Running:
33 +      if (jcr->get_JobType() == JT_BACKUP && jcr->file_bsock) {
34 +         /* When in JS_Running state, the main thread can wait for
35 +          * EndJob message from the Client. We send a signal to the job
36 +          * thread to cancel the read() 
37 +          */
38 +         jcr->send_signal_to_owner(TIMEOUT_SIGNAL);
39 +      }
40     default:
41        /* Cancel File daemon */
42        if (jcr->file_bsock) {
43 Index: src/jcr.h
44 ===================================================================
45 --- src/jcr.h   (revision 7725)
46 +++ src/jcr.h   (working copy)
47 @@ -180,6 +180,8 @@
48     bool is_job_canceled() {return job_canceled(this); };
49     int32_t get_JobType() { return m_JobType; };
50     int32_t get_JobLevel() { return m_JobLevel; };
51 +   void set_owner();
52 +   int send_signal_to_owner(int signal);
53  
54     const char *get_OperationName();    /* in lib/jcr.c */
55     const char *get_ActionName(bool past); /* in lib/jcr.c */
56 Index: src/lib/jcr.c
57 ===================================================================
58 --- src/lib/jcr.c       (revision 7725)
59 +++ src/lib/jcr.c       (working copy)
60 @@ -303,6 +303,31 @@
61  }
62  
63  /*
64 + * Update the my_thread_id variable with the current thread id
65 + */
66 +void JCR::set_owner()
67 +{
68 +   Dmsg1(0, "JCR::set_owner(%p)\n", pthread_self());
69 +   this->my_thread_id = pthread_self();
70 +}
71 +
72 +/*
73 + * Send a signal to the JCR thread owner. (to break a system call)
74 + * (Must have use set_owner() before)
75 + */
76 +int JCR::send_signal_to_owner(int sig)
77 +{
78 +   int ret=0;
79 +   Dmsg2(0, "Sending TIMEOUT ?? to %p by %p\n", this->my_thread_id, pthread_self());
80 +
81 +   if (!pthread_equal(this->my_thread_id, pthread_self())) {
82 +      Dmsg2(0, "Sending TIMEOUT to %p by %p\n", this->my_thread_id, pthread_self());
83 +      ret = pthread_kill(this->my_thread_id, sig);
84 +   }
85 +   return ret;
86 +}
87 +
88 +/*
89   * Push a subroutine address into the job end callback stack
90   */
91  void job_end_push(JCR *jcr, void job_end_cb(JCR *jcr,void *), void *ctx)
92 @@ -719,7 +744,7 @@
93      bool set_waittime = false;
94      int oldJobStatus = jcr->JobStatus;
95  
96 -    Dmsg2(800, "set_jcr_job_status(%s, %c)\n", jcr->Job, JobStatus);
97 +    Dmsg2(2, "set_jcr_job_status(%s, %c)\n", jcr->Job, JobStatus);
98      /* if wait state is new, we keep current time for watchdog MaxWaitTime */
99      switch (JobStatus) {
100         case JS_WaitFD:
101 @@ -740,7 +765,7 @@
102      * For a set of errors, ... keep the current status
103      *   so it isn't lost. For all others, set it.
104      */
105 -   Dmsg3(300, "jid=%u OnEntry JobStatus=%c set=%c\n", (uint32_t)jcr->JobId,
106 +   Dmsg3(2, "jid=%u OnEntry JobStatus=%c set=%c\n", (uint32_t)jcr->JobId,
107           jcr->JobStatus, JobStatus);
108     switch (jcr->JobStatus) {
109     case JS_ErrorTerminated:
110 @@ -781,7 +806,7 @@
111        }
112     }
113     if (oldJobStatus != jcr->JobStatus) {
114 -      Dmsg3(200, "jid=%u leave set_old_job_status=%c new_set=%c\n", (uint32_t)jcr->JobId,
115 +      Dmsg3(2, "jid=%u leave set_old_job_status=%c new_set=%c\n", (uint32_t)jcr->JobId,
116           oldJobStatus, JobStatus);
117  //    generate_plugin_event(jcr, bEventStatusChange, NULL);
118     }