]> git.proxmox.com Git - mirror_qemu.git/blob - block/curl.c
curl: Remove unnecessary explicit calls to internal event handler
[mirror_qemu.git] / block / curl.c
1 /*
2 * QEMU Block driver for CURL images
3 *
4 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 #include "qemu-common.h"
25 #include "block/block_int.h"
26 #include <curl/curl.h>
27
28 // #define DEBUG
29 // #define DEBUG_VERBOSE
30
31 #ifdef DEBUG_CURL
32 #define DPRINTF(fmt, ...) do { printf(fmt, ## __VA_ARGS__); } while (0)
33 #else
34 #define DPRINTF(fmt, ...) do { } while (0)
35 #endif
36
37 #if LIBCURL_VERSION_NUM >= 0x071000
38 /* The multi interface timer callback was introduced in 7.16.0 */
39 #define NEED_CURL_TIMER_CALLBACK
40 #endif
41
42 #define PROTOCOLS (CURLPROTO_HTTP | CURLPROTO_HTTPS | \
43 CURLPROTO_FTP | CURLPROTO_FTPS | \
44 CURLPROTO_TFTP)
45
46 #define CURL_NUM_STATES 8
47 #define CURL_NUM_ACB 8
48 #define SECTOR_SIZE 512
49 #define READ_AHEAD_SIZE (256 * 1024)
50
51 #define FIND_RET_NONE 0
52 #define FIND_RET_OK 1
53 #define FIND_RET_WAIT 2
54
55 struct BDRVCURLState;
56
57 typedef struct CURLAIOCB {
58 BlockDriverAIOCB common;
59 QEMUBH *bh;
60 QEMUIOVector *qiov;
61
62 int64_t sector_num;
63 int nb_sectors;
64
65 size_t start;
66 size_t end;
67 } CURLAIOCB;
68
69 typedef struct CURLState
70 {
71 struct BDRVCURLState *s;
72 CURLAIOCB *acb[CURL_NUM_ACB];
73 CURL *curl;
74 char *orig_buf;
75 size_t buf_start;
76 size_t buf_off;
77 size_t buf_len;
78 char range[128];
79 char errmsg[CURL_ERROR_SIZE];
80 char in_use;
81 } CURLState;
82
83 typedef struct BDRVCURLState {
84 CURLM *multi;
85 QEMUTimer timer;
86 size_t len;
87 CURLState states[CURL_NUM_STATES];
88 char *url;
89 size_t readahead_size;
90 bool accept_range;
91 } BDRVCURLState;
92
93 static void curl_clean_state(CURLState *s);
94 static void curl_multi_do(void *arg);
95
96 #ifdef NEED_CURL_TIMER_CALLBACK
97 static int curl_timer_cb(CURLM *multi, long timeout_ms, void *opaque)
98 {
99 BDRVCURLState *s = opaque;
100
101 DPRINTF("CURL: timer callback timeout_ms %ld\n", timeout_ms);
102 if (timeout_ms == -1) {
103 timer_del(&s->timer);
104 } else {
105 int64_t timeout_ns = (int64_t)timeout_ms * 1000 * 1000;
106 timer_mod(&s->timer,
107 qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timeout_ns);
108 }
109 return 0;
110 }
111 #endif
112
113 static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
114 void *s, void *sp)
115 {
116 DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
117 switch (action) {
118 case CURL_POLL_IN:
119 qemu_aio_set_fd_handler(fd, curl_multi_do, NULL, s);
120 break;
121 case CURL_POLL_OUT:
122 qemu_aio_set_fd_handler(fd, NULL, curl_multi_do, s);
123 break;
124 case CURL_POLL_INOUT:
125 qemu_aio_set_fd_handler(fd, curl_multi_do, curl_multi_do, s);
126 break;
127 case CURL_POLL_REMOVE:
128 qemu_aio_set_fd_handler(fd, NULL, NULL, NULL);
129 break;
130 }
131
132 return 0;
133 }
134
135 static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
136 {
137 BDRVCURLState *s = opaque;
138 size_t realsize = size * nmemb;
139 const char *accept_line = "Accept-Ranges: bytes";
140
141 if (realsize >= strlen(accept_line)
142 && strncmp((char *)ptr, accept_line, strlen(accept_line)) == 0) {
143 s->accept_range = true;
144 }
145
146 return realsize;
147 }
148
149 static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
150 {
151 CURLState *s = ((CURLState*)opaque);
152 size_t realsize = size * nmemb;
153 int i;
154
155 DPRINTF("CURL: Just reading %zd bytes\n", realsize);
156
157 if (!s || !s->orig_buf)
158 return 0;
159
160 if (s->buf_off >= s->buf_len) {
161 /* buffer full, read nothing */
162 return 0;
163 }
164 realsize = MIN(realsize, s->buf_len - s->buf_off);
165 memcpy(s->orig_buf + s->buf_off, ptr, realsize);
166 s->buf_off += realsize;
167
168 for(i=0; i<CURL_NUM_ACB; i++) {
169 CURLAIOCB *acb = s->acb[i];
170
171 if (!acb)
172 continue;
173
174 if ((s->buf_off >= acb->end)) {
175 qemu_iovec_from_buf(acb->qiov, 0, s->orig_buf + acb->start,
176 acb->end - acb->start);
177 acb->common.cb(acb->common.opaque, 0);
178 qemu_aio_release(acb);
179 s->acb[i] = NULL;
180 }
181 }
182
183 return realsize;
184 }
185
186 static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
187 CURLAIOCB *acb)
188 {
189 int i;
190 size_t end = start + len;
191
192 for (i=0; i<CURL_NUM_STATES; i++) {
193 CURLState *state = &s->states[i];
194 size_t buf_end = (state->buf_start + state->buf_off);
195 size_t buf_fend = (state->buf_start + state->buf_len);
196
197 if (!state->orig_buf)
198 continue;
199 if (!state->buf_off)
200 continue;
201
202 // Does the existing buffer cover our section?
203 if ((start >= state->buf_start) &&
204 (start <= buf_end) &&
205 (end >= state->buf_start) &&
206 (end <= buf_end))
207 {
208 char *buf = state->orig_buf + (start - state->buf_start);
209
210 qemu_iovec_from_buf(acb->qiov, 0, buf, len);
211 acb->common.cb(acb->common.opaque, 0);
212
213 return FIND_RET_OK;
214 }
215
216 // Wait for unfinished chunks
217 if ((start >= state->buf_start) &&
218 (start <= buf_fend) &&
219 (end >= state->buf_start) &&
220 (end <= buf_fend))
221 {
222 int j;
223
224 acb->start = start - state->buf_start;
225 acb->end = acb->start + len;
226
227 for (j=0; j<CURL_NUM_ACB; j++) {
228 if (!state->acb[j]) {
229 state->acb[j] = acb;
230 return FIND_RET_WAIT;
231 }
232 }
233 }
234 }
235
236 return FIND_RET_NONE;
237 }
238
239 static void curl_multi_read(BDRVCURLState *s)
240 {
241 int msgs_in_queue;
242
243 /* Try to find done transfers, so we can free the easy
244 * handle again. */
245 do {
246 CURLMsg *msg;
247 msg = curl_multi_info_read(s->multi, &msgs_in_queue);
248
249 if (!msg)
250 break;
251 if (msg->msg == CURLMSG_NONE)
252 break;
253
254 switch (msg->msg) {
255 case CURLMSG_DONE:
256 {
257 CURLState *state = NULL;
258 curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE,
259 (char **)&state);
260
261 /* ACBs for successful messages get completed in curl_read_cb */
262 if (msg->data.result != CURLE_OK) {
263 int i;
264 for (i = 0; i < CURL_NUM_ACB; i++) {
265 CURLAIOCB *acb = state->acb[i];
266
267 if (acb == NULL) {
268 continue;
269 }
270
271 acb->common.cb(acb->common.opaque, -EIO);
272 qemu_aio_release(acb);
273 state->acb[i] = NULL;
274 }
275 }
276
277 curl_clean_state(state);
278 break;
279 }
280 default:
281 msgs_in_queue = 0;
282 break;
283 }
284 } while(msgs_in_queue);
285 }
286
287 static void curl_multi_do(void *arg)
288 {
289 BDRVCURLState *s = (BDRVCURLState *)arg;
290 int running;
291 int r;
292
293 if (!s->multi) {
294 return;
295 }
296
297 do {
298 r = curl_multi_socket_all(s->multi, &running);
299 } while(r == CURLM_CALL_MULTI_PERFORM);
300
301 curl_multi_read(s);
302 }
303
304 static void curl_multi_timeout_do(void *arg)
305 {
306 #ifdef NEED_CURL_TIMER_CALLBACK
307 BDRVCURLState *s = (BDRVCURLState *)arg;
308 int running;
309
310 if (!s->multi) {
311 return;
312 }
313
314 curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);
315
316 curl_multi_read(s);
317 #else
318 abort();
319 #endif
320 }
321
322 static CURLState *curl_init_state(BDRVCURLState *s)
323 {
324 CURLState *state = NULL;
325 int i, j;
326
327 do {
328 for (i=0; i<CURL_NUM_STATES; i++) {
329 for (j=0; j<CURL_NUM_ACB; j++)
330 if (s->states[i].acb[j])
331 continue;
332 if (s->states[i].in_use)
333 continue;
334
335 state = &s->states[i];
336 state->in_use = 1;
337 break;
338 }
339 if (!state) {
340 qemu_aio_wait();
341 }
342 } while(!state);
343
344 if (!state->curl) {
345 state->curl = curl_easy_init();
346 if (!state->curl) {
347 return NULL;
348 }
349 curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
350 curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, 5);
351 curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION,
352 (void *)curl_read_cb);
353 curl_easy_setopt(state->curl, CURLOPT_WRITEDATA, (void *)state);
354 curl_easy_setopt(state->curl, CURLOPT_PRIVATE, (void *)state);
355 curl_easy_setopt(state->curl, CURLOPT_AUTOREFERER, 1);
356 curl_easy_setopt(state->curl, CURLOPT_FOLLOWLOCATION, 1);
357 curl_easy_setopt(state->curl, CURLOPT_NOSIGNAL, 1);
358 curl_easy_setopt(state->curl, CURLOPT_ERRORBUFFER, state->errmsg);
359 curl_easy_setopt(state->curl, CURLOPT_FAILONERROR, 1);
360
361 /* Restrict supported protocols to avoid security issues in the more
362 * obscure protocols. For example, do not allow POP3/SMTP/IMAP see
363 * CVE-2013-0249.
364 *
365 * Restricting protocols is only supported from 7.19.4 upwards.
366 */
367 #if LIBCURL_VERSION_NUM >= 0x071304
368 curl_easy_setopt(state->curl, CURLOPT_PROTOCOLS, PROTOCOLS);
369 curl_easy_setopt(state->curl, CURLOPT_REDIR_PROTOCOLS, PROTOCOLS);
370 #endif
371
372 #ifdef DEBUG_VERBOSE
373 curl_easy_setopt(state->curl, CURLOPT_VERBOSE, 1);
374 #endif
375 }
376
377 state->s = s;
378
379 return state;
380 }
381
382 static void curl_clean_state(CURLState *s)
383 {
384 if (s->s->multi)
385 curl_multi_remove_handle(s->s->multi, s->curl);
386 s->in_use = 0;
387 }
388
389 static void curl_parse_filename(const char *filename, QDict *options,
390 Error **errp)
391 {
392
393 #define RA_OPTSTR ":readahead="
394 char *file;
395 char *ra;
396 const char *ra_val;
397 int parse_state = 0;
398
399 file = g_strdup(filename);
400
401 /* Parse a trailing ":readahead=#:" param, if present. */
402 ra = file + strlen(file) - 1;
403 while (ra >= file) {
404 if (parse_state == 0) {
405 if (*ra == ':') {
406 parse_state++;
407 } else {
408 break;
409 }
410 } else if (parse_state == 1) {
411 if (*ra > '9' || *ra < '0') {
412 char *opt_start = ra - strlen(RA_OPTSTR) + 1;
413 if (opt_start > file &&
414 strncmp(opt_start, RA_OPTSTR, strlen(RA_OPTSTR)) == 0) {
415 ra_val = ra + 1;
416 ra -= strlen(RA_OPTSTR) - 1;
417 *ra = '\0';
418 qdict_put(options, "readahead", qstring_from_str(ra_val));
419 }
420 break;
421 }
422 }
423 ra--;
424 }
425
426 qdict_put(options, "url", qstring_from_str(file));
427
428 g_free(file);
429 }
430
431 static QemuOptsList runtime_opts = {
432 .name = "curl",
433 .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
434 .desc = {
435 {
436 .name = "url",
437 .type = QEMU_OPT_STRING,
438 .help = "URL to open",
439 },
440 {
441 .name = "readahead",
442 .type = QEMU_OPT_SIZE,
443 .help = "Readahead size",
444 },
445 { /* end of list */ }
446 },
447 };
448
449 static int curl_open(BlockDriverState *bs, QDict *options, int flags,
450 Error **errp)
451 {
452 BDRVCURLState *s = bs->opaque;
453 CURLState *state = NULL;
454 QemuOpts *opts;
455 Error *local_err = NULL;
456 const char *file;
457 double d;
458
459 static int inited = 0;
460
461 if (flags & BDRV_O_RDWR) {
462 error_setg(errp, "curl block device does not support writes");
463 return -EROFS;
464 }
465
466 opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
467 qemu_opts_absorb_qdict(opts, options, &local_err);
468 if (local_err) {
469 error_propagate(errp, local_err);
470 goto out_noclean;
471 }
472
473 s->readahead_size = qemu_opt_get_size(opts, "readahead", READ_AHEAD_SIZE);
474 if ((s->readahead_size & 0x1ff) != 0) {
475 error_setg(errp, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512",
476 s->readahead_size);
477 goto out_noclean;
478 }
479
480 file = qemu_opt_get(opts, "url");
481 if (file == NULL) {
482 error_setg(errp, "curl block driver requires an 'url' option");
483 goto out_noclean;
484 }
485
486 if (!inited) {
487 curl_global_init(CURL_GLOBAL_ALL);
488 inited = 1;
489 }
490
491 DPRINTF("CURL: Opening %s\n", file);
492 s->url = g_strdup(file);
493 state = curl_init_state(s);
494 if (!state)
495 goto out_noclean;
496
497 // Get file size
498
499 s->accept_range = false;
500 curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
501 curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
502 curl_header_cb);
503 curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
504 if (curl_easy_perform(state->curl))
505 goto out;
506 curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
507 if (d)
508 s->len = (size_t)d;
509 else if(!s->len)
510 goto out;
511 if ((!strncasecmp(s->url, "http://", strlen("http://"))
512 || !strncasecmp(s->url, "https://", strlen("https://")))
513 && !s->accept_range) {
514 pstrcpy(state->errmsg, CURL_ERROR_SIZE,
515 "Server does not support 'range' (byte ranges).");
516 goto out;
517 }
518 DPRINTF("CURL: Size = %zd\n", s->len);
519
520 curl_clean_state(state);
521 curl_easy_cleanup(state->curl);
522 state->curl = NULL;
523
524 aio_timer_init(bdrv_get_aio_context(bs), &s->timer,
525 QEMU_CLOCK_REALTIME, SCALE_NS,
526 curl_multi_timeout_do, s);
527
528 // Now we know the file exists and its size, so let's
529 // initialize the multi interface!
530
531 s->multi = curl_multi_init();
532 curl_multi_setopt(s->multi, CURLMOPT_SOCKETDATA, s);
533 curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);
534 #ifdef NEED_CURL_TIMER_CALLBACK
535 curl_multi_setopt(s->multi, CURLMOPT_TIMERDATA, s);
536 curl_multi_setopt(s->multi, CURLMOPT_TIMERFUNCTION, curl_timer_cb);
537 #endif
538
539 qemu_opts_del(opts);
540 return 0;
541
542 out:
543 error_setg(errp, "CURL: Error opening file: %s", state->errmsg);
544 curl_easy_cleanup(state->curl);
545 state->curl = NULL;
546 out_noclean:
547 g_free(s->url);
548 qemu_opts_del(opts);
549 return -EINVAL;
550 }
551
552 static void curl_aio_cancel(BlockDriverAIOCB *blockacb)
553 {
554 // Do we have to implement canceling? Seems to work without...
555 }
556
557 static const AIOCBInfo curl_aiocb_info = {
558 .aiocb_size = sizeof(CURLAIOCB),
559 .cancel = curl_aio_cancel,
560 };
561
562
563 static void curl_readv_bh_cb(void *p)
564 {
565 CURLState *state;
566 int running;
567
568 CURLAIOCB *acb = p;
569 BDRVCURLState *s = acb->common.bs->opaque;
570
571 qemu_bh_delete(acb->bh);
572 acb->bh = NULL;
573
574 size_t start = acb->sector_num * SECTOR_SIZE;
575 size_t end;
576
577 // In case we have the requested data already (e.g. read-ahead),
578 // we can just call the callback and be done.
579 switch (curl_find_buf(s, start, acb->nb_sectors * SECTOR_SIZE, acb)) {
580 case FIND_RET_OK:
581 qemu_aio_release(acb);
582 // fall through
583 case FIND_RET_WAIT:
584 return;
585 default:
586 break;
587 }
588
589 // No cache found, so let's start a new request
590 state = curl_init_state(s);
591 if (!state) {
592 acb->common.cb(acb->common.opaque, -EIO);
593 qemu_aio_release(acb);
594 return;
595 }
596
597 acb->start = 0;
598 acb->end = (acb->nb_sectors * SECTOR_SIZE);
599
600 state->buf_off = 0;
601 if (state->orig_buf)
602 g_free(state->orig_buf);
603 state->buf_start = start;
604 state->buf_len = acb->end + s->readahead_size;
605 end = MIN(start + state->buf_len, s->len) - 1;
606 state->orig_buf = g_malloc(state->buf_len);
607 state->acb[0] = acb;
608
609 snprintf(state->range, 127, "%zd-%zd", start, end);
610 DPRINTF("CURL (AIO): Reading %d at %zd (%s)\n",
611 (acb->nb_sectors * SECTOR_SIZE), start, state->range);
612 curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range);
613
614 curl_multi_add_handle(s->multi, state->curl);
615
616 /* Tell curl it needs to kick things off */
617 curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);
618 }
619
620 static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs,
621 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
622 BlockDriverCompletionFunc *cb, void *opaque)
623 {
624 CURLAIOCB *acb;
625
626 acb = qemu_aio_get(&curl_aiocb_info, bs, cb, opaque);
627
628 acb->qiov = qiov;
629 acb->sector_num = sector_num;
630 acb->nb_sectors = nb_sectors;
631
632 acb->bh = qemu_bh_new(curl_readv_bh_cb, acb);
633 qemu_bh_schedule(acb->bh);
634 return &acb->common;
635 }
636
637 static void curl_close(BlockDriverState *bs)
638 {
639 BDRVCURLState *s = bs->opaque;
640 int i;
641
642 DPRINTF("CURL: Close\n");
643 for (i=0; i<CURL_NUM_STATES; i++) {
644 if (s->states[i].in_use)
645 curl_clean_state(&s->states[i]);
646 if (s->states[i].curl) {
647 curl_easy_cleanup(s->states[i].curl);
648 s->states[i].curl = NULL;
649 }
650 if (s->states[i].orig_buf) {
651 g_free(s->states[i].orig_buf);
652 s->states[i].orig_buf = NULL;
653 }
654 }
655 if (s->multi)
656 curl_multi_cleanup(s->multi);
657
658 timer_del(&s->timer);
659
660 g_free(s->url);
661 }
662
663 static int64_t curl_getlength(BlockDriverState *bs)
664 {
665 BDRVCURLState *s = bs->opaque;
666 return s->len;
667 }
668
669 static BlockDriver bdrv_http = {
670 .format_name = "http",
671 .protocol_name = "http",
672
673 .instance_size = sizeof(BDRVCURLState),
674 .bdrv_parse_filename = curl_parse_filename,
675 .bdrv_file_open = curl_open,
676 .bdrv_close = curl_close,
677 .bdrv_getlength = curl_getlength,
678
679 .bdrv_aio_readv = curl_aio_readv,
680 };
681
682 static BlockDriver bdrv_https = {
683 .format_name = "https",
684 .protocol_name = "https",
685
686 .instance_size = sizeof(BDRVCURLState),
687 .bdrv_parse_filename = curl_parse_filename,
688 .bdrv_file_open = curl_open,
689 .bdrv_close = curl_close,
690 .bdrv_getlength = curl_getlength,
691
692 .bdrv_aio_readv = curl_aio_readv,
693 };
694
695 static BlockDriver bdrv_ftp = {
696 .format_name = "ftp",
697 .protocol_name = "ftp",
698
699 .instance_size = sizeof(BDRVCURLState),
700 .bdrv_parse_filename = curl_parse_filename,
701 .bdrv_file_open = curl_open,
702 .bdrv_close = curl_close,
703 .bdrv_getlength = curl_getlength,
704
705 .bdrv_aio_readv = curl_aio_readv,
706 };
707
708 static BlockDriver bdrv_ftps = {
709 .format_name = "ftps",
710 .protocol_name = "ftps",
711
712 .instance_size = sizeof(BDRVCURLState),
713 .bdrv_parse_filename = curl_parse_filename,
714 .bdrv_file_open = curl_open,
715 .bdrv_close = curl_close,
716 .bdrv_getlength = curl_getlength,
717
718 .bdrv_aio_readv = curl_aio_readv,
719 };
720
721 static BlockDriver bdrv_tftp = {
722 .format_name = "tftp",
723 .protocol_name = "tftp",
724
725 .instance_size = sizeof(BDRVCURLState),
726 .bdrv_parse_filename = curl_parse_filename,
727 .bdrv_file_open = curl_open,
728 .bdrv_close = curl_close,
729 .bdrv_getlength = curl_getlength,
730
731 .bdrv_aio_readv = curl_aio_readv,
732 };
733
734 static void curl_block_init(void)
735 {
736 bdrv_register(&bdrv_http);
737 bdrv_register(&bdrv_https);
738 bdrv_register(&bdrv_ftp);
739 bdrv_register(&bdrv_ftps);
740 bdrv_register(&bdrv_tftp);
741 }
742
743 block_init(curl_block_init);