]> git.proxmox.com Git - qemu.git/blame - block/curl.c
block/curl: drop curl_aio_flush()
[qemu.git] / block / curl.c
CommitLineData
769ce76d
AG
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"
737e150e 25#include "block/block_int.h"
769ce76d
AG
26#include <curl/curl.h>
27
28// #define DEBUG
29// #define DEBUG_VERBOSE
30
31#ifdef DEBUG_CURL
d0f2c4c6 32#define DPRINTF(fmt, ...) do { printf(fmt, ## __VA_ARGS__); } while (0)
769ce76d 33#else
d0f2c4c6 34#define DPRINTF(fmt, ...) do { } while (0)
769ce76d
AG
35#endif
36
fb6d1bbd
SH
37#define PROTOCOLS (CURLPROTO_HTTP | CURLPROTO_HTTPS | \
38 CURLPROTO_FTP | CURLPROTO_FTPS | \
39 CURLPROTO_TFTP)
40
769ce76d
AG
41#define CURL_NUM_STATES 8
42#define CURL_NUM_ACB 8
43#define SECTOR_SIZE 512
44#define READ_AHEAD_SIZE (256 * 1024)
45
46#define FIND_RET_NONE 0
47#define FIND_RET_OK 1
48#define FIND_RET_WAIT 2
49
50struct BDRVCURLState;
51
52typedef struct CURLAIOCB {
53 BlockDriverAIOCB common;
363c3c85 54 QEMUBH *bh;
769ce76d 55 QEMUIOVector *qiov;
363c3c85
NT
56
57 int64_t sector_num;
58 int nb_sectors;
59
769ce76d
AG
60 size_t start;
61 size_t end;
62} CURLAIOCB;
63
64typedef struct CURLState
65{
66 struct BDRVCURLState *s;
67 CURLAIOCB *acb[CURL_NUM_ACB];
68 CURL *curl;
69 char *orig_buf;
70 size_t buf_start;
71 size_t buf_off;
72 size_t buf_len;
73 char range[128];
74 char errmsg[CURL_ERROR_SIZE];
75 char in_use;
76} CURLState;
77
78typedef struct BDRVCURLState {
79 CURLM *multi;
80 size_t len;
81 CURLState states[CURL_NUM_STATES];
82 char *url;
c76f4952 83 size_t readahead_size;
3494d650 84 bool accept_range;
769ce76d
AG
85} BDRVCURLState;
86
87static void curl_clean_state(CURLState *s);
88static void curl_multi_do(void *arg);
89
90static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
91 void *s, void *sp)
92{
d0f2c4c6 93 DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
769ce76d
AG
94 switch (action) {
95 case CURL_POLL_IN:
0d146022 96 qemu_aio_set_fd_handler(fd, curl_multi_do, NULL, NULL, s);
769ce76d
AG
97 break;
98 case CURL_POLL_OUT:
0d146022 99 qemu_aio_set_fd_handler(fd, NULL, curl_multi_do, NULL, s);
769ce76d
AG
100 break;
101 case CURL_POLL_INOUT:
c84dcdc1 102 qemu_aio_set_fd_handler(fd, curl_multi_do, curl_multi_do,
0d146022 103 NULL, s);
769ce76d
AG
104 break;
105 case CURL_POLL_REMOVE:
bafbd6a1 106 qemu_aio_set_fd_handler(fd, NULL, NULL, NULL, NULL);
769ce76d
AG
107 break;
108 }
109
110 return 0;
111}
112
3494d650 113static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
769ce76d 114{
3494d650 115 BDRVCURLState *s = opaque;
769ce76d 116 size_t realsize = size * nmemb;
3494d650 117 const char *accept_line = "Accept-Ranges: bytes";
769ce76d 118
3494d650
FZ
119 if (realsize >= strlen(accept_line)
120 && strncmp((char *)ptr, accept_line, strlen(accept_line)) == 0) {
121 s->accept_range = true;
0bfcd599 122 }
769ce76d
AG
123
124 return realsize;
125}
126
127static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
128{
129 CURLState *s = ((CURLState*)opaque);
130 size_t realsize = size * nmemb;
131 int i;
132
0bfcd599 133 DPRINTF("CURL: Just reading %zd bytes\n", realsize);
769ce76d
AG
134
135 if (!s || !s->orig_buf)
136 goto read_end;
137
138 memcpy(s->orig_buf + s->buf_off, ptr, realsize);
139 s->buf_off += realsize;
140
141 for(i=0; i<CURL_NUM_ACB; i++) {
142 CURLAIOCB *acb = s->acb[i];
143
144 if (!acb)
145 continue;
146
147 if ((s->buf_off >= acb->end)) {
03396148
MT
148 qemu_iovec_from_buf(acb->qiov, 0, s->orig_buf + acb->start,
149 acb->end - acb->start);
769ce76d
AG
150 acb->common.cb(acb->common.opaque, 0);
151 qemu_aio_release(acb);
152 s->acb[i] = NULL;
153 }
154 }
155
156read_end:
157 return realsize;
158}
159
160static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
161 CURLAIOCB *acb)
162{
163 int i;
164 size_t end = start + len;
165
166 for (i=0; i<CURL_NUM_STATES; i++) {
167 CURLState *state = &s->states[i];
168 size_t buf_end = (state->buf_start + state->buf_off);
169 size_t buf_fend = (state->buf_start + state->buf_len);
170
171 if (!state->orig_buf)
172 continue;
173 if (!state->buf_off)
174 continue;
175
176 // Does the existing buffer cover our section?
177 if ((start >= state->buf_start) &&
178 (start <= buf_end) &&
179 (end >= state->buf_start) &&
180 (end <= buf_end))
181 {
182 char *buf = state->orig_buf + (start - state->buf_start);
183
03396148 184 qemu_iovec_from_buf(acb->qiov, 0, buf, len);
769ce76d
AG
185 acb->common.cb(acb->common.opaque, 0);
186
187 return FIND_RET_OK;
188 }
189
190 // Wait for unfinished chunks
191 if ((start >= state->buf_start) &&
192 (start <= buf_fend) &&
193 (end >= state->buf_start) &&
194 (end <= buf_fend))
195 {
196 int j;
197
198 acb->start = start - state->buf_start;
199 acb->end = acb->start + len;
200
201 for (j=0; j<CURL_NUM_ACB; j++) {
202 if (!state->acb[j]) {
203 state->acb[j] = acb;
204 return FIND_RET_WAIT;
205 }
206 }
207 }
208 }
209
210 return FIND_RET_NONE;
211}
212
213static void curl_multi_do(void *arg)
214{
215 BDRVCURLState *s = (BDRVCURLState *)arg;
216 int running;
217 int r;
218 int msgs_in_queue;
219
220 if (!s->multi)
221 return;
222
223 do {
224 r = curl_multi_socket_all(s->multi, &running);
225 } while(r == CURLM_CALL_MULTI_PERFORM);
226
227 /* Try to find done transfers, so we can free the easy
228 * handle again. */
229 do {
230 CURLMsg *msg;
231 msg = curl_multi_info_read(s->multi, &msgs_in_queue);
232
233 if (!msg)
234 break;
235 if (msg->msg == CURLMSG_NONE)
236 break;
237
238 switch (msg->msg) {
239 case CURLMSG_DONE:
240 {
241 CURLState *state = NULL;
242 curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, (char**)&state);
f785a5ae
NT
243
244 /* ACBs for successful messages get completed in curl_read_cb */
245 if (msg->data.result != CURLE_OK) {
246 int i;
247 for (i = 0; i < CURL_NUM_ACB; i++) {
248 CURLAIOCB *acb = state->acb[i];
249
250 if (acb == NULL) {
251 continue;
252 }
253
254 acb->common.cb(acb->common.opaque, -EIO);
255 qemu_aio_release(acb);
256 state->acb[i] = NULL;
257 }
258 }
259
769ce76d
AG
260 curl_clean_state(state);
261 break;
262 }
263 default:
264 msgs_in_queue = 0;
265 break;
266 }
267 } while(msgs_in_queue);
268}
269
270static CURLState *curl_init_state(BDRVCURLState *s)
271{
272 CURLState *state = NULL;
273 int i, j;
274
275 do {
276 for (i=0; i<CURL_NUM_STATES; i++) {
277 for (j=0; j<CURL_NUM_ACB; j++)
278 if (s->states[i].acb[j])
279 continue;
280 if (s->states[i].in_use)
281 continue;
282
283 state = &s->states[i];
284 state->in_use = 1;
285 break;
286 }
287 if (!state) {
fb7c8e8a 288 g_usleep(100);
769ce76d
AG
289 curl_multi_do(s);
290 }
291 } while(!state);
292
293 if (state->curl)
294 goto has_curl;
295
296 state->curl = curl_easy_init();
297 if (!state->curl)
298 return NULL;
299 curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
300 curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, 5);
df3cee1a 301 curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION, (void *)curl_read_cb);
769ce76d
AG
302 curl_easy_setopt(state->curl, CURLOPT_WRITEDATA, (void *)state);
303 curl_easy_setopt(state->curl, CURLOPT_PRIVATE, (void *)state);
304 curl_easy_setopt(state->curl, CURLOPT_AUTOREFERER, 1);
305 curl_easy_setopt(state->curl, CURLOPT_FOLLOWLOCATION, 1);
306 curl_easy_setopt(state->curl, CURLOPT_NOSIGNAL, 1);
307 curl_easy_setopt(state->curl, CURLOPT_ERRORBUFFER, state->errmsg);
f785a5ae
NT
308 curl_easy_setopt(state->curl, CURLOPT_FAILONERROR, 1);
309
fb6d1bbd
SH
310 /* Restrict supported protocols to avoid security issues in the more
311 * obscure protocols. For example, do not allow POP3/SMTP/IMAP see
312 * CVE-2013-0249.
8a8f5840
SH
313 *
314 * Restricting protocols is only supported from 7.19.4 upwards.
fb6d1bbd 315 */
8a8f5840 316#if LIBCURL_VERSION_NUM >= 0x071304
fb6d1bbd
SH
317 curl_easy_setopt(state->curl, CURLOPT_PROTOCOLS, PROTOCOLS);
318 curl_easy_setopt(state->curl, CURLOPT_REDIR_PROTOCOLS, PROTOCOLS);
8a8f5840 319#endif
fb6d1bbd 320
769ce76d
AG
321#ifdef DEBUG_VERBOSE
322 curl_easy_setopt(state->curl, CURLOPT_VERBOSE, 1);
323#endif
324
325has_curl:
326
327 state->s = s;
328
329 return state;
330}
331
332static void curl_clean_state(CURLState *s)
333{
334 if (s->s->multi)
335 curl_multi_remove_handle(s->s->multi, s->curl);
336 s->in_use = 0;
337}
338
8e6d58cd
KW
339static void curl_parse_filename(const char *filename, QDict *options,
340 Error **errp)
769ce76d 341{
c76f4952
N
342
343 #define RA_OPTSTR ":readahead="
344 char *file;
345 char *ra;
346 const char *ra_val;
347 int parse_state = 0;
348
7267c094 349 file = g_strdup(filename);
c76f4952
N
350
351 /* Parse a trailing ":readahead=#:" param, if present. */
352 ra = file + strlen(file) - 1;
353 while (ra >= file) {
354 if (parse_state == 0) {
8e6d58cd 355 if (*ra == ':') {
c76f4952 356 parse_state++;
8e6d58cd 357 } else {
c76f4952 358 break;
8e6d58cd 359 }
c76f4952
N
360 } else if (parse_state == 1) {
361 if (*ra > '9' || *ra < '0') {
362 char *opt_start = ra - strlen(RA_OPTSTR) + 1;
363 if (opt_start > file &&
364 strncmp(opt_start, RA_OPTSTR, strlen(RA_OPTSTR)) == 0) {
365 ra_val = ra + 1;
366 ra -= strlen(RA_OPTSTR) - 1;
367 *ra = '\0';
8e6d58cd 368 qdict_put(options, "readahead", qstring_from_str(ra_val));
c76f4952 369 }
8e6d58cd 370 break;
c76f4952
N
371 }
372 }
373 ra--;
374 }
375
8e6d58cd
KW
376 qdict_put(options, "url", qstring_from_str(file));
377
378 g_free(file);
379}
380
381static QemuOptsList runtime_opts = {
382 .name = "curl",
383 .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
384 .desc = {
385 {
386 .name = "url",
387 .type = QEMU_OPT_STRING,
388 .help = "URL to open",
389 },
390 {
391 .name = "readahead",
392 .type = QEMU_OPT_SIZE,
393 .help = "Readahead size",
394 },
395 { /* end of list */ }
396 },
397};
398
56d1b4d2 399static int curl_open(BlockDriverState *bs, QDict *options, int flags)
8e6d58cd
KW
400{
401 BDRVCURLState *s = bs->opaque;
402 CURLState *state = NULL;
403 QemuOpts *opts;
404 Error *local_err = NULL;
405 const char *file;
406 double d;
407
408 static int inited = 0;
409
a7cea2ba
RJ
410 if (flags & BDRV_O_RDWR) {
411 qerror_report(ERROR_CLASS_GENERIC_ERROR,
412 "curl block device does not support writes");
413 return -EROFS;
414 }
415
8e6d58cd
KW
416 opts = qemu_opts_create_nofail(&runtime_opts);
417 qemu_opts_absorb_qdict(opts, options, &local_err);
418 if (error_is_set(&local_err)) {
419 qerror_report_err(local_err);
420 error_free(local_err);
421 goto out_noclean;
422 }
423
424 s->readahead_size = qemu_opt_get_size(opts, "readahead", READ_AHEAD_SIZE);
c76f4952 425 if ((s->readahead_size & 0x1ff) != 0) {
48a402e6 426 fprintf(stderr, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n",
c76f4952
N
427 s->readahead_size);
428 goto out_noclean;
429 }
430
8e6d58cd
KW
431 file = qemu_opt_get(opts, "url");
432 if (file == NULL) {
433 qerror_report(ERROR_CLASS_GENERIC_ERROR, "curl block driver requires "
434 "an 'url' option");
435 goto out_noclean;
436 }
437
769ce76d
AG
438 if (!inited) {
439 curl_global_init(CURL_GLOBAL_ALL);
440 inited = 1;
441 }
442
d0f2c4c6 443 DPRINTF("CURL: Opening %s\n", file);
8e6d58cd 444 s->url = g_strdup(file);
769ce76d
AG
445 state = curl_init_state(s);
446 if (!state)
447 goto out_noclean;
448
449 // Get file size
450
3494d650 451 s->accept_range = false;
769ce76d 452 curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
3494d650
FZ
453 curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
454 curl_header_cb);
455 curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
769ce76d
AG
456 if (curl_easy_perform(state->curl))
457 goto out;
458 curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
769ce76d
AG
459 if (d)
460 s->len = (size_t)d;
461 else if(!s->len)
462 goto out;
3494d650
FZ
463 if ((!strncasecmp(s->url, "http://", strlen("http://"))
464 || !strncasecmp(s->url, "https://", strlen("https://")))
465 && !s->accept_range) {
466 pstrcpy(state->errmsg, CURL_ERROR_SIZE,
467 "Server does not support 'range' (byte ranges).");
468 goto out;
469 }
0bfcd599 470 DPRINTF("CURL: Size = %zd\n", s->len);
769ce76d
AG
471
472 curl_clean_state(state);
473 curl_easy_cleanup(state->curl);
474 state->curl = NULL;
475
476 // Now we know the file exists and its size, so let's
477 // initialize the multi interface!
478
479 s->multi = curl_multi_init();
9e5e2b23
RJ
480 curl_multi_setopt(s->multi, CURLMOPT_SOCKETDATA, s);
481 curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);
769ce76d
AG
482 curl_multi_do(s);
483
8e6d58cd 484 qemu_opts_del(opts);
769ce76d
AG
485 return 0;
486
487out:
488 fprintf(stderr, "CURL: Error opening file: %s\n", state->errmsg);
489 curl_easy_cleanup(state->curl);
490 state->curl = NULL;
491out_noclean:
8e6d58cd
KW
492 g_free(s->url);
493 qemu_opts_del(opts);
769ce76d
AG
494 return -EINVAL;
495}
496
c16b5a2c
CH
497static void curl_aio_cancel(BlockDriverAIOCB *blockacb)
498{
499 // Do we have to implement canceling? Seems to work without...
500}
501
d7331bed 502static const AIOCBInfo curl_aiocb_info = {
c16b5a2c
CH
503 .aiocb_size = sizeof(CURLAIOCB),
504 .cancel = curl_aio_cancel,
505};
506
363c3c85
NT
507
508static void curl_readv_bh_cb(void *p)
769ce76d 509{
769ce76d
AG
510 CURLState *state;
511
363c3c85
NT
512 CURLAIOCB *acb = p;
513 BDRVCURLState *s = acb->common.bs->opaque;
769ce76d 514
363c3c85
NT
515 qemu_bh_delete(acb->bh);
516 acb->bh = NULL;
517
518 size_t start = acb->sector_num * SECTOR_SIZE;
519 size_t end;
769ce76d
AG
520
521 // In case we have the requested data already (e.g. read-ahead),
522 // we can just call the callback and be done.
363c3c85 523 switch (curl_find_buf(s, start, acb->nb_sectors * SECTOR_SIZE, acb)) {
769ce76d
AG
524 case FIND_RET_OK:
525 qemu_aio_release(acb);
526 // fall through
527 case FIND_RET_WAIT:
363c3c85 528 return;
769ce76d
AG
529 default:
530 break;
531 }
532
533 // No cache found, so let's start a new request
769ce76d 534 state = curl_init_state(s);
363c3c85
NT
535 if (!state) {
536 acb->common.cb(acb->common.opaque, -EIO);
537 qemu_aio_release(acb);
538 return;
539 }
769ce76d
AG
540
541 acb->start = 0;
363c3c85 542 acb->end = (acb->nb_sectors * SECTOR_SIZE);
769ce76d
AG
543
544 state->buf_off = 0;
545 if (state->orig_buf)
7267c094 546 g_free(state->orig_buf);
769ce76d 547 state->buf_start = start;
c76f4952 548 state->buf_len = acb->end + s->readahead_size;
769ce76d 549 end = MIN(start + state->buf_len, s->len) - 1;
7267c094 550 state->orig_buf = g_malloc(state->buf_len);
769ce76d
AG
551 state->acb[0] = acb;
552
0bfcd599
BS
553 snprintf(state->range, 127, "%zd-%zd", start, end);
554 DPRINTF("CURL (AIO): Reading %d at %zd (%s)\n",
363c3c85 555 (acb->nb_sectors * SECTOR_SIZE), start, state->range);
769ce76d
AG
556 curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range);
557
558 curl_multi_add_handle(s->multi, state->curl);
559 curl_multi_do(s);
560
363c3c85
NT
561}
562
563static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs,
564 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
565 BlockDriverCompletionFunc *cb, void *opaque)
566{
567 CURLAIOCB *acb;
568
d7331bed 569 acb = qemu_aio_get(&curl_aiocb_info, bs, cb, opaque);
363c3c85 570
363c3c85
NT
571 acb->qiov = qiov;
572 acb->sector_num = sector_num;
573 acb->nb_sectors = nb_sectors;
574
575 acb->bh = qemu_bh_new(curl_readv_bh_cb, acb);
576
577 if (!acb->bh) {
578 DPRINTF("CURL: qemu_bh_new failed\n");
579 return NULL;
580 }
581
582 qemu_bh_schedule(acb->bh);
769ce76d
AG
583 return &acb->common;
584}
585
769ce76d
AG
586static void curl_close(BlockDriverState *bs)
587{
588 BDRVCURLState *s = bs->opaque;
589 int i;
590
d0f2c4c6 591 DPRINTF("CURL: Close\n");
769ce76d
AG
592 for (i=0; i<CURL_NUM_STATES; i++) {
593 if (s->states[i].in_use)
594 curl_clean_state(&s->states[i]);
595 if (s->states[i].curl) {
596 curl_easy_cleanup(s->states[i].curl);
597 s->states[i].curl = NULL;
598 }
599 if (s->states[i].orig_buf) {
7267c094 600 g_free(s->states[i].orig_buf);
769ce76d
AG
601 s->states[i].orig_buf = NULL;
602 }
603 }
604 if (s->multi)
605 curl_multi_cleanup(s->multi);
45724d6d 606 g_free(s->url);
769ce76d
AG
607}
608
609static int64_t curl_getlength(BlockDriverState *bs)
610{
611 BDRVCURLState *s = bs->opaque;
612 return s->len;
613}
614
615static BlockDriver bdrv_http = {
8e6d58cd
KW
616 .format_name = "http",
617 .protocol_name = "http",
769ce76d 618
8e6d58cd
KW
619 .instance_size = sizeof(BDRVCURLState),
620 .bdrv_parse_filename = curl_parse_filename,
621 .bdrv_file_open = curl_open,
622 .bdrv_close = curl_close,
623 .bdrv_getlength = curl_getlength,
769ce76d 624
8e6d58cd 625 .bdrv_aio_readv = curl_aio_readv,
769ce76d
AG
626};
627
628static BlockDriver bdrv_https = {
8e6d58cd
KW
629 .format_name = "https",
630 .protocol_name = "https",
769ce76d 631
8e6d58cd
KW
632 .instance_size = sizeof(BDRVCURLState),
633 .bdrv_parse_filename = curl_parse_filename,
634 .bdrv_file_open = curl_open,
635 .bdrv_close = curl_close,
636 .bdrv_getlength = curl_getlength,
769ce76d 637
8e6d58cd 638 .bdrv_aio_readv = curl_aio_readv,
769ce76d
AG
639};
640
641static BlockDriver bdrv_ftp = {
8e6d58cd
KW
642 .format_name = "ftp",
643 .protocol_name = "ftp",
769ce76d 644
8e6d58cd
KW
645 .instance_size = sizeof(BDRVCURLState),
646 .bdrv_parse_filename = curl_parse_filename,
647 .bdrv_file_open = curl_open,
648 .bdrv_close = curl_close,
649 .bdrv_getlength = curl_getlength,
769ce76d 650
8e6d58cd 651 .bdrv_aio_readv = curl_aio_readv,
769ce76d
AG
652};
653
654static BlockDriver bdrv_ftps = {
8e6d58cd
KW
655 .format_name = "ftps",
656 .protocol_name = "ftps",
769ce76d 657
8e6d58cd
KW
658 .instance_size = sizeof(BDRVCURLState),
659 .bdrv_parse_filename = curl_parse_filename,
660 .bdrv_file_open = curl_open,
661 .bdrv_close = curl_close,
662 .bdrv_getlength = curl_getlength,
769ce76d 663
8e6d58cd 664 .bdrv_aio_readv = curl_aio_readv,
769ce76d
AG
665};
666
667static BlockDriver bdrv_tftp = {
8e6d58cd
KW
668 .format_name = "tftp",
669 .protocol_name = "tftp",
769ce76d 670
8e6d58cd
KW
671 .instance_size = sizeof(BDRVCURLState),
672 .bdrv_parse_filename = curl_parse_filename,
673 .bdrv_file_open = curl_open,
674 .bdrv_close = curl_close,
675 .bdrv_getlength = curl_getlength,
769ce76d 676
8e6d58cd 677 .bdrv_aio_readv = curl_aio_readv,
769ce76d
AG
678};
679
680static void curl_block_init(void)
681{
682 bdrv_register(&bdrv_http);
683 bdrv_register(&bdrv_https);
684 bdrv_register(&bdrv_ftp);
685 bdrv_register(&bdrv_ftps);
686 bdrv_register(&bdrv_tftp);
687}
688
689block_init(curl_block_init);