]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/status_storage_slots.patch
Attempt to fix bug #1128 InChanger flag cleared during Migration
[bacula/bacula] / bacula / patches / testing / status_storage_slots.patch
1 Index: src/dird/ua_label.c
2 ===================================================================
3 --- src/dird/ua_label.c (rĂ©vision 7144)
4 +++ src/dird/ua_label.c (copie de travail)
5 @@ -1015,3 +1015,142 @@
6     return strncmp(mr->VolumeName, ua->jcr->pool->cleaning_prefix,
7                    strlen(ua->jcr->pool->cleaning_prefix)) == 0;
8  }
9 +
10 +
11 +/*
12 + * Print slots from AutoChanger
13 + */
14 +void status_slots(UAContext *ua, STORE *store_r)
15 +{
16 +   USTORE store;
17 +   POOL_DBR pr;
18 +   vol_list_t *vl, *vol_list = NULL;
19 +   MEDIA_DBR mr;
20 +   char *slot_list;
21 +   int max_slots;
22 +   int drive;
23 +   int i=1;
24 +
25 +   if (!open_client_db(ua)) {
26 +      return;
27 +   }
28 +   store.store = store_r;
29 +
30 +   pm_strcpy(store.store_source, _("command line"));
31 +   set_wstorage(ua->jcr, &store);
32 +   drive = get_storage_drive(ua, store.store);
33 +
34 +   max_slots = get_num_slots_from_SD(ua);
35 +
36 +   if (max_slots <= 0) {
37 +      ua->warning_msg(_("No slots in changer to scan.\n"));
38 +      return;
39 +   }
40 +   slot_list = (char *)malloc(max_slots+1);
41 +   if (!get_user_slot_list(ua, slot_list, max_slots)) {
42 +      free(slot_list);
43 +      return;
44 +   }
45 +
46 +   vol_list = get_vol_list_from_SD(ua, true /* want to see all slots */);
47 +
48 +   if (!vol_list) {
49 +      ua->warning_msg(_("No Volumes found, or no barcodes.\n"));
50 +      goto bail_out;
51 +   }
52 +   if (!ua->api) {
53 +      ua->info_msg(_(" Slot |   Volume Name    |   Status  |    Type    |      Pool          |  Loaded |\n"));
54 +      ua->info_msg(_("------+------------------+-----------+------------+--------------------+---------|\n"));
55 +   }
56 +   /* Walk through the list getting the media records */
57 +   for (vl=vol_list; vl; vl=vl->next) {
58 +      if (vl->Slot > max_slots) {
59 +         ua->warning_msg(_("Slot %d greater than max %d ignored.\n"),
60 +            vl->Slot, max_slots);
61 +         continue;
62 +      }
63 +      /* Check if user wants us to look at this slot */
64 +      if (!slot_list[vl->Slot]) {
65 +         Dmsg1(100, "Skipping slot=%d\n", vl->Slot);
66 +         continue;
67 +      }
68 +
69 +      slot_list[vl->Slot] = 0;        /* clear Slot */
70 +
71 +      if (!vl->VolName) {
72 +         Dmsg1(100, "No VolName for Slot=%d.\n", vl->Slot);
73 +        if (!ua->api) {
74 +           ua->info_msg(_(" %4i%c| %16s | %9s | %10s | %18s |    %i    |\n"),
75 +                        vl->Slot, '*',
76 +                        "?", "?", "?", "?", 0);
77 +        } else {
78 +           ua->info_msg(_("%i||||||\n"), vl->Slot);
79 +        }
80 +         continue;
81 +      }
82 +
83 +      /* Hope that slots are ordered */
84 +      for (; i < vl->Slot; i++) {
85 +        if (slot_list[i]) {
86 +           if (!ua->api) {
87 +              ua->info_msg(_(" %4i | %16s | %9s | %10s | %18s |    %i    |\n"),
88 +                           i, "", "", "", "", 0);
89 +           } else {
90 +              ua->info_msg(_("%i||||||\n"), i);
91 +           }       
92 +           slot_list[i]=0;
93 +        }
94 +      }
95 +
96 +      memset(&mr, 0, sizeof(mr));
97 +      bstrncpy(mr.VolumeName, vl->VolName, sizeof(mr.VolumeName));
98 +      db_lock(ua->db);
99 +      if (mr.VolumeName[0] && db_get_media_record(ua->jcr, ua->db, &mr)) {
100 +        memset(&pr, 0, sizeof(POOL_DBR));
101 +        pr.PoolId = mr.PoolId;
102 +        if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
103 +           strcpy(pr.Name, "?");
104 +        }
105 +
106 +        if (!ua->api) {
107 +           /* Print information */
108 +           ua->info_msg(_(" %4i%c| %16s | %9s | %10s | %18s |    %i    |\n"),
109 +                        vl->Slot, ((vl->Slot==mr.Slot)?' ':'*'),
110 +                        mr.VolumeName, mr.VolStatus, mr.MediaType, pr.Name, 0);
111 +        } else {
112 +           ua->info_msg(_("%i|%i|%s|%s|%s|%s|%i|\n"),
113 +                        vl->Slot, mr.Slot, mr.VolumeName, mr.VolStatus, mr.MediaType, pr.Name, 0);
114 +        }
115 +
116 +         db_unlock(ua->db);
117 +         continue;
118 +      } else {                 /* TODO: get information from catalog  */
119 +        ua->info_msg(_(" %4i%c| %16s | %9s | %10s | %18s |    %i    |\n"),
120 +                     vl->Slot, '*',
121 +                     mr.VolumeName, "?", "?", "?", 0);
122 +      }
123 +      db_unlock(ua->db);
124 +   }
125 +
126 +   /* Display the rest of the autochanger
127 +    */
128 +   for (; i <= max_slots; i++) {
129 +      if (slot_list[i]) {
130 +        if (!ua->api) {
131 +           ua->info_msg(_(" %4i | %16s | %9s | %10s | %18s |    %i    |\n"),
132 +                        i, "", "", "", "", 0);
133 +        } else {
134 +           ua->info_msg(_("%i||||||\n"), i);
135 +        } 
136 +        slot_list[i]=0;
137 +      }
138 +   }
139 +
140 +bail_out:
141 +
142 +   free_vol_list(vol_list);
143 +   free(slot_list);
144 +   close_sd_bsock(ua);
145 +
146 +   return;
147 +}
148 Index: src/dird/ua_status.c
149 ===================================================================
150 --- src/dird/ua_status.c        (rĂ©vision 7144)
151 +++ src/dird/ua_status.c        (copie de travail)
152 @@ -47,6 +47,7 @@
153  static void do_client_status(UAContext *ua, CLIENT *client, char *cmd);
154  static void do_director_status(UAContext *ua);
155  static void do_all_status(UAContext *ua);
156 +void status_slots(UAContext *ua, STORE *store);
157  
158  static char OKqstatus[]   = "1000 OK .status\n";
159  static char DotStatusJob[] = "JobId=%s JobStatus=%c JobErrors=%d\n";
160 @@ -157,7 +158,11 @@
161        } else {
162           store = get_storage_resource(ua, false/*no default*/);
163           if (store) {
164 -            do_storage_status(ua, store, NULL);
165 +           if (find_arg(ua, NT_("slots")) > 0) {
166 +              status_slots(ua, store);
167 +           } else {
168 +              do_storage_status(ua, store, NULL);
169 +           }
170           }
171           return 1;
172        }