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 xlog(L_NOTICE, "NULL replicas pointer");
46 xlog(L_NOTICE, "replicas listsize=%i", sp->h_num);
47 for (i=0; i<sp->h_num; i++) {
48 xlog(L_NOTICE, " %s:%s",
49 sp->h_mp[i]->h_host, sp->h_mp[i]->h_path);
54 /* Called by setting 'Method = stub' in config file. Just returns
55 * some syntactically correct gibberish for testing purposes.
57 static struct servers *method_stub(char *key)
60 struct mount_point *mp;
62 xlog(L_NOTICE, "called method_stub\n");
63 sp = malloc(sizeof(struct servers));
66 mp = calloc(1, sizeof(struct mount_point));
73 mp->h_host = strdup("stub_server");
74 mp->h_path = strdup("/my/test/path");
80 /* Scan @list, which is a NULL-terminated array of strings of the
81 * form path@host[+host], and return corresponding servers structure.
83 static struct servers *parse_list(char **list)
87 struct mount_point *mp;
90 res = malloc(sizeof(struct servers));
95 /* parse each of the answers in sucession. */
96 for (i=0; list[i] && i<FSLOC_MAX_LIST; i++) {
97 mp = calloc(1, sizeof(struct mount_point));
99 release_replicas(res);
102 cp = strchr(list[i], '@');
103 if ((!cp) || list[i][0] != '/') {
104 xlog(L_WARNING, "invalid entry '%s'", list[i]);
105 continue; /* XXX Need better error handling */
109 mp->h_path = strndup(list[i], cp - list[i]);
111 mp->h_host = strdup(cp);
112 /* hosts are '+' separated, kernel expects ':' separated */
113 while ( (cp = strchr(mp->h_host, '+')) )
119 /* @data is a string of form path@host[+host][:path@host[+host]]
121 static struct servers *method_list(char *data)
123 char *copy, *ptr=data, *p;
126 struct servers *rv=NULL;
129 xlog(L_NOTICE, "method_list(%s)", data);
130 for (ptr--, listsize=1; ptr; ptr=index(ptr, ':'), listsize++)
132 list = malloc(listsize * sizeof(char *));
135 xlog(L_NOTICE, "converted to %s", copy);
138 for (p = ptr, i = 0; *p && i < listsize; p++) {
144 if (!v6esc && *p == ':') {
154 rv = parse_list(list);
162 /* Returns appropriately filled struct servers, or NULL if had a problem */
163 struct servers *replicas_lookup(int method, char *data)
165 struct servers *sp=NULL;
170 sp = method_list(data);
175 sp = method_list(data);
181 sp = method_stub(data);
185 xlog(L_WARNING, "Unknown method = %i", method);
191 void release_replicas(struct servers *server)
196 for (i = 0; i < server->h_num; i++) {
197 free(server->h_mp[i]->h_host);
198 free(server->h_mp[i]->h_path);
199 free(server->h_mp[i]);