ia64/xen-unstable
changeset 2200:f9df1e9a2193
bitkeeper revision 1.1159.1.41 (411b513abSOkSWbJ0fLA8-ej90H_yA)
Fixes in configuring a migrated domain.
Fixes in configuring a migrated domain.
author | mjw@wray-m-3.hpl.hp.com |
---|---|
date | Thu Aug 12 11:15:06 2004 +0000 (2004-08-12) |
parents | 95d17d8191a5 |
children | 86c685a1dda9 |
files | .rootkeys tools/python/xen/xend/XendDomain.py tools/xfrd/http.h tools/xfrd/xen_domain.c |
line diff
1.1 --- a/.rootkeys Thu Aug 12 09:18:19 2004 +0000 1.2 +++ b/.rootkeys Thu Aug 12 11:15:06 2004 +0000 1.3 @@ -476,6 +476,7 @@ 40e9808eyjiahG5uF6AMelNVujBzCg tools/xfr 1.4 40e9808eZpbdn9q2KSSMGCNvY_ZgpQ tools/xfrd/enum.h 1.5 40e9808easXCzzAZQodEfKAhgUXSPA tools/xfrd/hash_table.c 1.6 40e9808e94BNXIVVKBFHC3rnkvwtJg tools/xfrd/hash_table.h 1.7 +411b5139tfKZfWs1LQHmwDR_wjKoxQ tools/xfrd/http.h 1.8 40e9808epW9iHcLXuO3QfUfLzB7onw tools/xfrd/lexis.c 1.9 40e9808egccMhCizayQRGtpBA3L5MQ tools/xfrd/lexis.h 1.10 40e9808ePADCSKL1YgGCt2TbYPnYkw tools/xfrd/lzi_stream.c
2.1 --- a/tools/python/xen/xend/XendDomain.py Thu Aug 12 09:18:19 2004 +0000 2.2 +++ b/tools/python/xen/xend/XendDomain.py Thu Aug 12 11:15:06 2004 +0000 2.3 @@ -366,9 +366,11 @@ class XendDomain: 2.4 @param config: configuration 2.5 @return: deferred 2.6 """ 2.7 - dominfo = self.domain_get(id) 2.8 - if not dominfo: 2.9 - raise XendError("Invalid domain: " + str(id)) 2.10 + print 'domain_configure>', id, config 2.11 + dominfo = self.domain_lookup(id) 2.12 + print 'domain_configure>', 'dominfo=', dominfo 2.13 + for dinfo in self.domain_by_id.values(): 2.14 + print 'domain', dinfo.id, dinfo.name 2.15 log.debug('domain_configure> id=%s config=%s', id, str(config)) 2.16 if dominfo.config: 2.17 raise XendError("Domain already configured: " + dominfo.name)
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/tools/xfrd/http.h Thu Aug 12 11:15:06 2004 +0000 3.3 @@ -0,0 +1,50 @@ 3.4 +#ifndef _XFRD_HTTP_H_ 3.5 +#define _XFRD_HTTP_H_ 3.6 + 3.7 +enum { 3.8 + HTTP_OK = 200, 3.9 + HTTP_CREATED = 201, 3.10 + HTTP_ACCEPTED = 202, 3.11 + HTTP_NON_AUTHORITATIVE_INFORMATION = 203, 3.12 + HTTP_NO_CONTENT = 204, 3.13 + HTTP_RESET_CONTENT = 205, 3.14 + HTTP_PARTIAL_CONTENT = 206, 3.15 + HTTP_MULTI_STATUS = 207, 3.16 + 3.17 + HTTP_MULTIPLE_CHOICE = 300, 3.18 + HTTP_MOVED_PERMANENTLY = 301, 3.19 + HTTP_FOUND = 302, 3.20 + HTTP_SEE_OTHER = 303, 3.21 + HTTP_NOT_MODIFIED = 304, 3.22 + HTTP_USE_PROXY = 305, 3.23 + HTTP_TEMPORARY_REDIRECT = 307, 3.24 + 3.25 + HTTP_BAD_REQUEST = 400, 3.26 + HTTP_UNAUTHORIZED = 401, 3.27 + HTTP_PAYMENT_REQUIRED = 402, 3.28 + HTTP_FORBIDDEN = 403, 3.29 + HTTP_NOT_FOUND = 404, 3.30 + HTTP_NOT_ALLOWED = 405, 3.31 + HTTP_NOT_ACCEPTABLE = 406, 3.32 + HTTP_PROXY_AUTH_REQUIRED = 407, 3.33 + HTTP_REQUEST_TIMEOUT = 408, 3.34 + HTTP_CONFLICT = 409, 3.35 + HTTP_GONE = 410, 3.36 + HTTP_LENGTH_REQUIRED = 411, 3.37 + HTTP_PRECONDITION_FAILED = 412, 3.38 + HTTP_REQUEST_ENTITY_TOO_LARGE = 413, 3.39 + HTTP_REQUEST_URI_TOO_LONG = 414, 3.40 + HTTP_UNSUPPORTED_MEDIA_TYPE = 415, 3.41 + HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416, 3.42 + HTTP_EXPECTATION_FAILED = 417, 3.43 + 3.44 + HTTP_INTERNAL_SERVER_ERROR = 500, 3.45 + HTTP_NOT_IMPLEMENTED = 501, 3.46 + HTTP_BAD_GATEWAY = 502, 3.47 + HTTP_SERVICE_UNAVAILABLE = 503, 3.48 + HTTP_GATEWAY_TIMEOUT = 504, 3.49 + HTTP_VERSION_NOT_SUPPORTED = 505, 3.50 + HTTP_INSUFFICIENT_STORAGE_SPACE = 507, 3.51 + HTTP_NOT_EXTENDED = 510, 3.52 +}; 3.53 +#endif /* ! _XFRD_HTTP_H_ */
4.1 --- a/tools/xfrd/xen_domain.c Thu Aug 12 09:18:19 2004 +0000 4.2 +++ b/tools/xfrd/xen_domain.c Thu Aug 12 11:15:06 2004 +0000 4.3 @@ -136,9 +136,16 @@ int xen_domain_rcv(IOStream *io, uint32_ 4.4 } 4.5 4.6 #include <curl/curl.h> 4.7 +#include "http.h" 4.8 4.9 +/** Flag indicating whether we need to initialize libcurl. 4.10 + */ 4.11 static int do_curl_global_init = 1; 4.12 4.13 +/** Get a curl handle, initializing libcurl if needed. 4.14 + * 4.15 + * @return curl handle 4.16 + */ 4.17 static CURL *curlinit(void){ 4.18 if(do_curl_global_init){ 4.19 do_curl_global_init = 0; 4.20 @@ -150,37 +157,136 @@ static CURL *curlinit(void){ 4.21 return curl_easy_init(); 4.22 } 4.23 4.24 +/** Curl debug function. 4.25 + */ 4.26 int curldebug(CURL *curl, curl_infotype ty, char *buf, size_t buf_n, void *data){ 4.27 printf("%*s\n", buf_n, buf); 4.28 return 0; 4.29 } 4.30 4.31 -/** Configure a new domain. Talk to xend using libcurl. 4.32 +/** Setup a curl handle with a url. 4.33 + * Creates the url by formatting 'fmt' and the remaining arguments. 4.34 + * 4.35 + * @param pcurl return parameter for the curl handle 4.36 + * @param url url buffer 4.37 + * @param url_n size of url 4.38 + * @param fmt url format string, followed by parameters 4.39 + * @return 0 on success, error code otherwise 4.40 */ 4.41 -int xen_domain_configure(uint32_t dom, char *vmconfig, int vmconfig_n){ 4.42 +static int curlsetup(CURL **pcurl, char *url, int url_n, char *fmt, ...){ 4.43 int err = 0; 4.44 + va_list args; 4.45 CURL *curl = NULL; 4.46 - CURLcode curlcode = 0; 4.47 - char domainurl[128] = {}; 4.48 - int domainurl_n = sizeof(domainurl) - 1; 4.49 - int n; 4.50 - struct curl_httppost *form = NULL, *last = NULL; 4.51 - CURLFORMcode formcode = 0; 4.52 + int n = 0; 4.53 4.54 - dprintf("> dom=%u\n", dom); 4.55 curl = curlinit(); 4.56 if(!curl){ 4.57 eprintf("> Could not init libcurl\n"); 4.58 err = -ENOMEM; 4.59 goto exit; 4.60 } 4.61 - n = snprintf(domainurl, domainurl_n, 4.62 - "http://localhost:%d/xend/domain/%u", XEND_PORT, dom); 4.63 - if(n <= 0 || n >= domainurl_n){ 4.64 + url_n -= 1; 4.65 + va_start(args, fmt); 4.66 + n = vsnprintf(url, url_n, fmt, args); 4.67 + va_end(args); 4.68 + if(n <= 0 || n >= url_n){ 4.69 err = -ENOMEM; 4.70 - eprintf("Out of memory in url.\n"); 4.71 + eprintf("> Out of memory in url\n"); 4.72 + goto exit; 4.73 + } 4.74 + dprintf("> url=%s\n", url); 4.75 +#if DEBUG 4.76 + // Verbose. 4.77 + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); 4.78 + // Call the debug function on data received. 4.79 + curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, curldebug); 4.80 +#else 4.81 + // No progress meter. 4.82 + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); 4.83 + // Completely quiet. 4.84 + curl_easy_setopt(curl, CURLOPT_MUTE, 1); 4.85 +#endif 4.86 + // Set the URL. 4.87 + curl_easy_setopt(curl, CURLOPT_URL, url); 4.88 + exit: 4.89 + if(err && curl){ 4.90 + curl_easy_cleanup(curl); 4.91 + curl = NULL; 4.92 + } 4.93 + *pcurl = curl; 4.94 + return err; 4.95 +} 4.96 + 4.97 +/** Make the http request stored in the curl handle and get 4.98 + * the result code from the curl code and the http return code. 4.99 + * 4.100 + * @param curl curl handle 4.101 + * @return 0 for success, error code otherwise 4.102 + */ 4.103 +int curlresult(CURL *curl){ 4.104 + int err = 0; 4.105 + CURLcode curlcode = 0; 4.106 + long httpcode = 0; 4.107 + 4.108 + curlcode = curl_easy_perform(curl); 4.109 + if(curlcode){ 4.110 + eprintf("> curlcode=%d\n", curlcode); 4.111 + err = -EINVAL; 4.112 goto exit; 4.113 } 4.114 + curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &httpcode); 4.115 + if(httpcode != HTTP_OK){ 4.116 + eprintf("> httpcode=%d\n", (int)httpcode); 4.117 + err = -EINVAL; 4.118 + goto exit; 4.119 + } 4.120 + exit: 4.121 + return err; 4.122 +} 4.123 + 4.124 +/** Get xend to list domains. 4.125 + * We use this to force xend to refresh its domain list. 4.126 + * 4.127 + * @return 0 on success, error code otherwise 4.128 + */ 4.129 +int xen_domain_ls(void){ 4.130 + int err = 0; 4.131 + CURL *curl = NULL; 4.132 + char url[128] = {}; 4.133 + int url_n = sizeof(url); 4.134 + 4.135 + dprintf(">\n"); 4.136 + err = curlsetup(&curl, url, url_n, "http://localhost:%d/xend/domain", XEND_PORT); 4.137 + if(err) goto exit; 4.138 + err = curlresult(curl); 4.139 + exit: 4.140 + if(curl) curl_easy_cleanup(curl); 4.141 + dprintf("< err=%d\n", err); 4.142 + return err; 4.143 +} 4.144 + 4.145 +/** Get xend to configure a new domain. 4.146 + * 4.147 + * @param dom domain id 4.148 + * @param vmconfig configuration string 4.149 + * @param vmconfig_n length of vmconfig 4.150 + * @return 0 on success, error code otherwise 4.151 + */ 4.152 +int xen_domain_configure(uint32_t dom, char *vmconfig, int vmconfig_n){ 4.153 + int err = 0; 4.154 + CURL *curl = NULL; 4.155 + char url[128] = {}; 4.156 + int url_n = sizeof(url); 4.157 + struct curl_httppost *form = NULL, *last = NULL; 4.158 + CURLFORMcode formcode = 0; 4.159 + 4.160 + dprintf("> dom=%u\n", dom); 4.161 + // List domains so that xend will update its domain list and notice the new domain. 4.162 + xen_domain_ls(); 4.163 + 4.164 + err = curlsetup(&curl, url, url_n, "http://localhost:%d/xend/domain/%u", XEND_PORT, dom); 4.165 + if(err) goto exit; 4.166 + 4.167 // Config field - set from vmconfig. 4.168 formcode = curl_formadd(&form, &last, 4.169 CURLFORM_COPYNAME, "config", 4.170 @@ -201,36 +307,15 @@ int xen_domain_configure(uint32_t dom, c 4.171 4.172 if(formcode){ 4.173 eprintf("> Error adding op field.\n"); 4.174 + err = -EINVAL; 4.175 goto exit; 4.176 } 4.177 - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); 4.178 - curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, curldebug); 4.179 - // No progress meter. 4.180 - //curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); 4.181 - // Completely quiet. 4.182 - //curl_easy_setopt(curl, CURLOPT_MUTE, 1); 4.183 - // Set the URL. 4.184 - curl_easy_setopt(curl, CURLOPT_URL, domainurl); 4.185 // POST the form. 4.186 curl_easy_setopt(curl, CURLOPT_HTTPPOST, form); 4.187 - dprintf("> curl perform...\n"); 4.188 -#if 0 && defined(_XEN_XFR_STUB_) 4.189 - dprintf("> _XEN_XFR_STUB_ defined - not calling xend\n"); 4.190 - curlcode = 0; 4.191 -#else 4.192 - curlcode = curl_easy_perform(curl); 4.193 -#endif 4.194 + err = curlresult(curl); 4.195 exit: 4.196 if(curl) curl_easy_cleanup(curl); 4.197 if(form) curl_formfree(form); 4.198 - if(formcode){ 4.199 - dprintf("> formcode=%d\n", formcode); 4.200 - err = -EINVAL; 4.201 - } 4.202 - if(curlcode){ 4.203 - dprintf("> curlcode=%d\n", curlcode); 4.204 - err = -EINVAL; 4.205 - } 4.206 dprintf("< err=%d\n", err); 4.207 return err; 4.208 }