]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/direct_drive_support.patch
Cleanup patches a bit
[bacula/bacula] / bacula / patches / testing / direct_drive_support.patch
1
2  This patch add a new protocol between storage and director
3  to be able to guess device organisation.
4
5
6 Index: src/dird/ua_cmds.c
7 ===================================================================
8 --- src/dird/ua_cmds.c  (rĂ©vision 8483)
9 +++ src/dird/ua_cmds.c  (copie de travail)
10 @@ -98,6 +98,7 @@
11  static int var_cmd(UAContext *ua, const char *cmd);
12  static int version_cmd(UAContext *ua, const char *cmd);
13  static int wait_cmd(UAContext *ua, const char *cmd);
14 +static int devicegroup_cmd(UAContext *ua, const char *command);
15  
16  static void do_job_delete(UAContext *ua, JobId_t JobId);
17  static void delete_job_id_range(UAContext *ua, char *tok);
18 @@ -154,6 +155,7 @@
19   { NT_("var"),        var_cmd,       _("does variable expansion"),                    false},
20   { NT_("version"),    version_cmd,   _("print Director version"),                     true},
21   { NT_("wait"),       wait_cmd,      _("wait [<jobname=name> | <jobid=nnn> | <ujobid=complete_name>] -- wait until no jobs are running"), false},
22 + { NT_("dg"),         devicegroup_cmd, _(""),                                         false}
23               };
24  #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
25  
26 @@ -1557,6 +1559,65 @@
27     jcr->store_bsock = NULL;
28  }
29  
30 +
31 +static int devicegroup_cmd(UAContext *ua, const char *command)
32 +{
33 +   USTORE store;
34 +   BSOCK *sd;
35 +   JCR *jcr = ua->jcr;
36 +   char dev_name[MAX_NAME_LENGTH];
37 +   POOL_MEM devname;
38 +   STORE *storage; 
39 +   DEVICE *dev;
40 +
41 +   if (!open_client_db(ua)) {
42 +      return 1;
43 +   }
44 +   Dmsg2(120, "%s: %s\n", command, ua->UA_sock->msg);
45 +
46 +   store.store = get_storage_resource(ua, true/*arg is storage*/);
47 +   if (!store.store) {
48 +      return 1;
49 +   }
50 +   pm_strcpy(store.store_source, _("unknown source"));
51 +   set_wstorage(jcr, &store);
52 +
53 +   if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
54 +      ua->error_msg(_("Failed to connect to Storage daemon.\n"));
55 +      return 1;
56 +   }
57 +   sd = jcr->store_bsock;
58 +   bstrncpy(dev_name, store.store->dev_name(), sizeof(dev_name));
59 +   bash_spaces(dev_name);
60 +   bnet_fsend(sd, "devicegroup storage=%s", dev_name);
61 +
62 +   /* can construct a list of device name */
63 +   while (bnet_recv(sd) >= 0) {
64 +      if (sscanf(sd->msg, "dev=%127s", devname.c_str()) == 1) {
65 +         unbash_spaces(devname);
66 +
67 +         /* get the device name from the storage resource */
68 +         foreach_res(storage, R_STORAGE) {
69 +            /* check that this resource is on the same storage */
70 +            if (bstrcmp(store.store->address, storage->address) &&
71 +                store.store->SDport == storage->SDport) 
72 +            {
73 +
74 +               foreach_alist(dev, storage->device) {
75 +                  if (bstrcmp(dev->name(), devname.c_str())) {
76 +                     ua->send_msg("%s\n", storage->name());
77 +                  } 
78 +               }
79 +            }
80 +         }
81 +      }
82 +   }
83 +   bnet_sig(sd, BNET_TERMINATE);
84 +   bnet_close(sd);
85 +   jcr->store_bsock = NULL;
86 +   return 1;
87 +}
88 +
89  /*
90   * mount [storage=<name>] [drive=nn] [slot=mm]
91   */
92 Index: src/stored/dircmd.c
93 ===================================================================
94 --- src/stored/dircmd.c (rĂ©vision 8483)
95 +++ src/stored/dircmd.c (copie de travail)
96 @@ -91,6 +91,7 @@
97                                 int Slot, int relabel);
98  static bool try_autoload_device(JCR *jcr, DCR *dcr, int slot, const char *VolName);
99  static void send_dir_busy_message(BSOCK *dir, DEVICE *dev);
100 +static bool devicegroup_cmd(JCR *jcr);
101  
102  struct s_cmds {
103     const char *cmd;
104 @@ -118,6 +119,7 @@
105     {"unmount",     unmount_cmd,     0},
106     {"use storage=", use_cmd,        0},
107     {"run",         run_cmd,         0},
108 +   {"devicegroup", devicegroup_cmd, 0},
109  // {"query",       query_cmd,       0},
110     {NULL,        NULL}                      /* list terminator */
111  };
112 @@ -629,6 +631,45 @@
113  
114  
115  /*
116 + * devicegroup storage=<name>
117 + */
118 +static bool devicegroup_cmd(JCR *jcr)
119 +{
120 +   POOL_MEM devname, result;
121 +   BSOCK *dir = jcr->dir_bsock;
122 +   AUTOCHANGER *ach;
123 +   DEVRES *dev; 
124 +   DCR *dcr;
125 +
126 +   bool ok = sscanf(dir->msg, "devicegroup storage=%127s", devname.c_str()) == 1;
127 +   if (ok) {
128 +      dcr = find_device(jcr, devname, -1);
129 +      if (dcr) {
130 +         ach = dcr->device->changer_res;
131 +         if (ach) {
132 +            /* Send the autochanger name as device*/
133 +            pm_strcpy(devname, ach->hdr.name);
134 +            bash_spaces(devname);
135 +            dir->fsend("dev=%s\n", devname.c_str());
136 +
137 +            /* Send all autochanger devices */
138 +            foreach_alist(dev, ach->device) {
139 +               pm_strcpy(devname, dev->hdr.name);
140 +               bash_spaces(devname);
141 +               dir->fsend("dev=%s\n", devname.c_str());
142 +            }
143 +         } else { /* if it's not an autochanger, just return it */
144 +            pm_strcpy(devname, dcr->device->hdr.name);
145 +            bash_spaces(devname);
146 +            dir->fsend("dev=%s\n", devname.c_str());            
147 +         } 
148 +      }
149 +   }
150 +   dir->signal(BNET_EOD);
151 +   return true;
152 +}
153 +
154 +/*
155   * Mount command from Director
156   */
157  static bool mount_cmd(JCR *jcr)