3 * THE REGENTS OF THE UNIVERSITY OF MICHIGAN
6 * Permission is granted to use, copy, create derivative works
7 * and redistribute this software and such derivative works
8 * for any purpose, so long as the name of The University of
9 * Michigan is not used in any advertising or publicity
10 * pertaining to the use of distribution of this software
11 * without specific, written prior authorization. If the
12 * above copyright notice or any other identification of the
13 * University of Michigan is included in any copy of any
14 * portion of this software, then the disclaimer below must
17 * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
18 * FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
19 * PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY OF
20 * MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
21 * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
23 * REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
24 * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
25 * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
26 * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
27 * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
38 /* Debugging tool: prints out @servers info to syslog */
39 static void replicas_print(struct servers *sp)
43 syslog(LOG_INFO, "NULL replicas pointer");
46 syslog(LOG_INFO, "replicas listsize=%i", sp->h_num);
47 for (i=0; i<sp->h_num; i++) {
48 syslog(LOG_INFO, "%s:%s",
49 sp->h_mp[i]->h_host, sp->h_mp[i]->h_path);
53 /* Called by setting 'Method = stub' in config file. Just returns
54 * some syntactically correct gibberish for testing purposes.
56 static struct servers *method_stub(char *key)
59 struct mount_point *mp;
61 syslog(LOG_INFO, "called method_stub");
62 sp = malloc(sizeof(struct servers));
65 mp = calloc(1, sizeof(struct mount_point));
72 mp->h_host = strdup("stub_server");
73 mp->h_path = strdup("/my/test/path");
78 /* Scan @list, which is a NULL-terminated array of strings of the
79 * form path@host[+host], and return corresponding servers structure.
81 static struct servers *parse_list(char **list)
85 struct mount_point *mp;
88 res = malloc(sizeof(struct servers));
93 /* parse each of the answers in sucession. */
94 for (i=0; list[i] && i<FSLOC_MAX_LIST; i++) {
95 mp = calloc(1, sizeof(struct mount_point));
97 release_replicas(res);
100 cp = strchr(list[i], '@');
101 if ((!cp) || list[i][0] != '/') {
102 syslog(LOG_WARNING, "invalid entry '%s'", list[i]);
103 continue; /* XXX Need better error handling */
107 mp->h_path = strndup(list[i], cp - list[i]);
109 mp->h_host = strdup(cp);
110 /* hosts are '+' separated, kernel expects ':' separated */
111 while ( (cp = strchr(mp->h_host, '+')) )
117 /* @data is a string of form path@host[+host][:path@host[+host]]
119 static struct servers *method_list(char *data)
121 char *copy, *ptr=data;
124 struct servers *rv=NULL;
126 syslog(LOG_INFO, "method_list(%s)\n", data);
127 for (ptr--, listsize=1; ptr; ptr=index(ptr, ':'), listsize++)
129 list = malloc(listsize * sizeof(char *));
132 syslog(LOG_INFO, "converted to %s\n", copy);
135 for (i=0; i<listsize; i++) {
136 list[i] = strsep(&ptr, ":");
138 rv = parse_list(list);
146 /* Returns appropriately filled struct servers, or NULL if had a problem */
147 struct servers *replicas_lookup(int method, char *data, char *key)
149 struct servers *sp=NULL;
154 sp = method_list(data);
159 sp = method_list(data);
164 sp = method_stub(data);
167 syslog(LOG_WARNING, "Unknown method = %i", method);
173 void release_replicas(struct servers *server)
178 for (i = 0; i < server->h_num; i++) {
179 free(server->h_mp[i]->h_host);
180 free(server->h_mp[i]->h_path);
181 free(server->h_mp[i]);