2 * QEMU Block driver for CURL images
4 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 #include "qemu/osdep.h"
25 #include "qapi/error.h"
26 #include "qemu-common.h"
27 #include "qemu/error-report.h"
28 #include "block/block_int.h"
29 #include "qapi/qmp/qbool.h"
30 #include "qapi/qmp/qstring.h"
31 #include "crypto/secret.h"
32 #include <curl/curl.h>
33 #include "qemu/cutils.h"
36 // #define DEBUG_VERBOSE
39 #define DPRINTF(fmt, ...) do { printf(fmt, ## __VA_ARGS__); } while (0)
41 #define DPRINTF(fmt, ...) do { } while (0)
44 #if LIBCURL_VERSION_NUM >= 0x071000
45 /* The multi interface timer callback was introduced in 7.16.0 */
46 #define NEED_CURL_TIMER_CALLBACK
47 #define HAVE_SOCKET_ACTION
50 #ifndef HAVE_SOCKET_ACTION
51 /* If curl_multi_socket_action isn't available, define it statically here in
52 * terms of curl_multi_socket. Note that ev_bitmask will be ignored, which is
53 * less efficient but still safe. */
54 static CURLMcode
__curl_multi_socket_action(CURLM
*multi_handle
,
59 return curl_multi_socket(multi_handle
, sockfd
, running_handles
);
61 #define curl_multi_socket_action __curl_multi_socket_action
64 #define PROTOCOLS (CURLPROTO_HTTP | CURLPROTO_HTTPS | \
65 CURLPROTO_FTP | CURLPROTO_FTPS | \
68 #define CURL_NUM_STATES 8
69 #define CURL_NUM_ACB 8
70 #define SECTOR_SIZE 512
71 #define READ_AHEAD_DEFAULT (256 * 1024)
72 #define CURL_TIMEOUT_DEFAULT 5
73 #define CURL_TIMEOUT_MAX 10000
75 #define FIND_RET_NONE 0
77 #define FIND_RET_WAIT 2
79 #define CURL_BLOCK_OPT_URL "url"
80 #define CURL_BLOCK_OPT_READAHEAD "readahead"
81 #define CURL_BLOCK_OPT_SSLVERIFY "sslverify"
82 #define CURL_BLOCK_OPT_TIMEOUT "timeout"
83 #define CURL_BLOCK_OPT_COOKIE "cookie"
84 #define CURL_BLOCK_OPT_USERNAME "username"
85 #define CURL_BLOCK_OPT_PASSWORD_SECRET "password-secret"
86 #define CURL_BLOCK_OPT_PROXY_USERNAME "proxy-username"
87 #define CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET "proxy-password-secret"
91 typedef struct CURLAIOCB
{
103 typedef struct CURLState
105 struct BDRVCURLState
*s
;
106 CURLAIOCB
*acb
[CURL_NUM_ACB
];
108 curl_socket_t sock_fd
;
114 char errmsg
[CURL_ERROR_SIZE
];
118 typedef struct BDRVCURLState
{
122 CURLState states
[CURL_NUM_STATES
];
124 size_t readahead_size
;
129 AioContext
*aio_context
;
136 static void curl_clean_state(CURLState
*s
);
137 static void curl_multi_do(void *arg
);
138 static void curl_multi_read(void *arg
);
140 #ifdef NEED_CURL_TIMER_CALLBACK
141 static int curl_timer_cb(CURLM
*multi
, long timeout_ms
, void *opaque
)
143 BDRVCURLState
*s
= opaque
;
145 DPRINTF("CURL: timer callback timeout_ms %ld\n", timeout_ms
);
146 if (timeout_ms
== -1) {
147 timer_del(&s
->timer
);
149 int64_t timeout_ns
= (int64_t)timeout_ms
* 1000 * 1000;
151 qemu_clock_get_ns(QEMU_CLOCK_REALTIME
) + timeout_ns
);
157 static int curl_sock_cb(CURL
*curl
, curl_socket_t fd
, int action
,
158 void *userp
, void *sp
)
161 CURLState
*state
= NULL
;
162 curl_easy_getinfo(curl
, CURLINFO_PRIVATE
, (char **)&state
);
166 DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action
, fd
);
169 aio_set_fd_handler(s
->aio_context
, fd
, false,
170 curl_multi_read
, NULL
, state
);
173 aio_set_fd_handler(s
->aio_context
, fd
, false,
174 NULL
, curl_multi_do
, state
);
176 case CURL_POLL_INOUT
:
177 aio_set_fd_handler(s
->aio_context
, fd
, false,
178 curl_multi_read
, curl_multi_do
, state
);
180 case CURL_POLL_REMOVE
:
181 aio_set_fd_handler(s
->aio_context
, fd
, false,
189 static size_t curl_header_cb(void *ptr
, size_t size
, size_t nmemb
, void *opaque
)
191 BDRVCURLState
*s
= opaque
;
192 size_t realsize
= size
* nmemb
;
193 const char *accept_line
= "Accept-Ranges: bytes";
195 if (realsize
>= strlen(accept_line
)
196 && strncmp((char *)ptr
, accept_line
, strlen(accept_line
)) == 0) {
197 s
->accept_range
= true;
203 static size_t curl_read_cb(void *ptr
, size_t size
, size_t nmemb
, void *opaque
)
205 CURLState
*s
= ((CURLState
*)opaque
);
206 size_t realsize
= size
* nmemb
;
209 DPRINTF("CURL: Just reading %zd bytes\n", realsize
);
211 if (!s
|| !s
->orig_buf
)
214 if (s
->buf_off
>= s
->buf_len
) {
215 /* buffer full, read nothing */
218 realsize
= MIN(realsize
, s
->buf_len
- s
->buf_off
);
219 memcpy(s
->orig_buf
+ s
->buf_off
, ptr
, realsize
);
220 s
->buf_off
+= realsize
;
222 for(i
=0; i
<CURL_NUM_ACB
; i
++) {
223 CURLAIOCB
*acb
= s
->acb
[i
];
228 if ((s
->buf_off
>= acb
->end
)) {
229 qemu_iovec_from_buf(acb
->qiov
, 0, s
->orig_buf
+ acb
->start
,
230 acb
->end
- acb
->start
);
231 acb
->common
.cb(acb
->common
.opaque
, 0);
240 static int curl_find_buf(BDRVCURLState
*s
, size_t start
, size_t len
,
244 size_t end
= start
+ len
;
246 for (i
=0; i
<CURL_NUM_STATES
; i
++) {
247 CURLState
*state
= &s
->states
[i
];
248 size_t buf_end
= (state
->buf_start
+ state
->buf_off
);
249 size_t buf_fend
= (state
->buf_start
+ state
->buf_len
);
251 if (!state
->orig_buf
)
256 // Does the existing buffer cover our section?
257 if ((start
>= state
->buf_start
) &&
258 (start
<= buf_end
) &&
259 (end
>= state
->buf_start
) &&
262 char *buf
= state
->orig_buf
+ (start
- state
->buf_start
);
264 qemu_iovec_from_buf(acb
->qiov
, 0, buf
, len
);
265 acb
->common
.cb(acb
->common
.opaque
, 0);
270 // Wait for unfinished chunks
272 (start
>= state
->buf_start
) &&
273 (start
<= buf_fend
) &&
274 (end
>= state
->buf_start
) &&
279 acb
->start
= start
- state
->buf_start
;
280 acb
->end
= acb
->start
+ len
;
282 for (j
=0; j
<CURL_NUM_ACB
; j
++) {
283 if (!state
->acb
[j
]) {
285 return FIND_RET_WAIT
;
291 return FIND_RET_NONE
;
294 static void curl_multi_check_completion(BDRVCURLState
*s
)
298 /* Try to find done transfers, so we can free the easy
302 msg
= curl_multi_info_read(s
->multi
, &msgs_in_queue
);
304 /* Quit when there are no more completions */
308 if (msg
->msg
== CURLMSG_DONE
) {
309 CURLState
*state
= NULL
;
310 curl_easy_getinfo(msg
->easy_handle
, CURLINFO_PRIVATE
,
313 /* ACBs for successful messages get completed in curl_read_cb */
314 if (msg
->data
.result
!= CURLE_OK
) {
316 static int errcount
= 100;
318 /* Don't lose the original error message from curl, since
319 * it contains extra data.
322 error_report("curl: %s", state
->errmsg
);
323 if (--errcount
== 0) {
324 error_report("curl: further errors suppressed");
328 for (i
= 0; i
< CURL_NUM_ACB
; i
++) {
329 CURLAIOCB
*acb
= state
->acb
[i
];
335 acb
->common
.cb(acb
->common
.opaque
, -EPROTO
);
337 state
->acb
[i
] = NULL
;
341 curl_clean_state(state
);
347 static void curl_multi_do(void *arg
)
349 CURLState
*s
= (CURLState
*)arg
;
358 r
= curl_multi_socket_action(s
->s
->multi
, s
->sock_fd
, 0, &running
);
359 } while(r
== CURLM_CALL_MULTI_PERFORM
);
363 static void curl_multi_read(void *arg
)
365 CURLState
*s
= (CURLState
*)arg
;
368 curl_multi_check_completion(s
->s
);
371 static void curl_multi_timeout_do(void *arg
)
373 #ifdef NEED_CURL_TIMER_CALLBACK
374 BDRVCURLState
*s
= (BDRVCURLState
*)arg
;
381 curl_multi_socket_action(s
->multi
, CURL_SOCKET_TIMEOUT
, 0, &running
);
383 curl_multi_check_completion(s
);
389 static CURLState
*curl_init_state(BlockDriverState
*bs
, BDRVCURLState
*s
)
391 CURLState
*state
= NULL
;
395 for (i
=0; i
<CURL_NUM_STATES
; i
++) {
396 for (j
=0; j
<CURL_NUM_ACB
; j
++)
397 if (s
->states
[i
].acb
[j
])
399 if (s
->states
[i
].in_use
)
402 state
= &s
->states
[i
];
407 aio_poll(bdrv_get_aio_context(bs
), true);
412 state
->curl
= curl_easy_init();
416 curl_easy_setopt(state
->curl
, CURLOPT_URL
, s
->url
);
417 curl_easy_setopt(state
->curl
, CURLOPT_SSL_VERIFYPEER
,
418 (long) s
->sslverify
);
420 curl_easy_setopt(state
->curl
, CURLOPT_COOKIE
, s
->cookie
);
422 curl_easy_setopt(state
->curl
, CURLOPT_TIMEOUT
, (long)s
->timeout
);
423 curl_easy_setopt(state
->curl
, CURLOPT_WRITEFUNCTION
,
424 (void *)curl_read_cb
);
425 curl_easy_setopt(state
->curl
, CURLOPT_WRITEDATA
, (void *)state
);
426 curl_easy_setopt(state
->curl
, CURLOPT_PRIVATE
, (void *)state
);
427 curl_easy_setopt(state
->curl
, CURLOPT_AUTOREFERER
, 1);
428 curl_easy_setopt(state
->curl
, CURLOPT_FOLLOWLOCATION
, 1);
429 curl_easy_setopt(state
->curl
, CURLOPT_NOSIGNAL
, 1);
430 curl_easy_setopt(state
->curl
, CURLOPT_ERRORBUFFER
, state
->errmsg
);
431 curl_easy_setopt(state
->curl
, CURLOPT_FAILONERROR
, 1);
434 curl_easy_setopt(state
->curl
, CURLOPT_USERNAME
, s
->username
);
437 curl_easy_setopt(state
->curl
, CURLOPT_PASSWORD
, s
->password
);
439 if (s
->proxyusername
) {
440 curl_easy_setopt(state
->curl
,
441 CURLOPT_PROXYUSERNAME
, s
->proxyusername
);
443 if (s
->proxypassword
) {
444 curl_easy_setopt(state
->curl
,
445 CURLOPT_PROXYPASSWORD
, s
->proxypassword
);
448 /* Restrict supported protocols to avoid security issues in the more
449 * obscure protocols. For example, do not allow POP3/SMTP/IMAP see
452 * Restricting protocols is only supported from 7.19.4 upwards.
454 #if LIBCURL_VERSION_NUM >= 0x071304
455 curl_easy_setopt(state
->curl
, CURLOPT_PROTOCOLS
, PROTOCOLS
);
456 curl_easy_setopt(state
->curl
, CURLOPT_REDIR_PROTOCOLS
, PROTOCOLS
);
460 curl_easy_setopt(state
->curl
, CURLOPT_VERBOSE
, 1);
469 static void curl_clean_state(CURLState
*s
)
472 curl_multi_remove_handle(s
->s
->multi
, s
->curl
);
476 static void curl_parse_filename(const char *filename
, QDict
*options
,
479 qdict_put(options
, CURL_BLOCK_OPT_URL
, qstring_from_str(filename
));
482 static void curl_detach_aio_context(BlockDriverState
*bs
)
484 BDRVCURLState
*s
= bs
->opaque
;
487 for (i
= 0; i
< CURL_NUM_STATES
; i
++) {
488 if (s
->states
[i
].in_use
) {
489 curl_clean_state(&s
->states
[i
]);
491 if (s
->states
[i
].curl
) {
492 curl_easy_cleanup(s
->states
[i
].curl
);
493 s
->states
[i
].curl
= NULL
;
495 g_free(s
->states
[i
].orig_buf
);
496 s
->states
[i
].orig_buf
= NULL
;
499 curl_multi_cleanup(s
->multi
);
503 timer_del(&s
->timer
);
506 static void curl_attach_aio_context(BlockDriverState
*bs
,
507 AioContext
*new_context
)
509 BDRVCURLState
*s
= bs
->opaque
;
511 aio_timer_init(new_context
, &s
->timer
,
512 QEMU_CLOCK_REALTIME
, SCALE_NS
,
513 curl_multi_timeout_do
, s
);
516 s
->multi
= curl_multi_init();
517 s
->aio_context
= new_context
;
518 curl_multi_setopt(s
->multi
, CURLMOPT_SOCKETFUNCTION
, curl_sock_cb
);
519 #ifdef NEED_CURL_TIMER_CALLBACK
520 curl_multi_setopt(s
->multi
, CURLMOPT_TIMERDATA
, s
);
521 curl_multi_setopt(s
->multi
, CURLMOPT_TIMERFUNCTION
, curl_timer_cb
);
525 static QemuOptsList runtime_opts
= {
527 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
530 .name
= CURL_BLOCK_OPT_URL
,
531 .type
= QEMU_OPT_STRING
,
532 .help
= "URL to open",
535 .name
= CURL_BLOCK_OPT_READAHEAD
,
536 .type
= QEMU_OPT_SIZE
,
537 .help
= "Readahead size",
540 .name
= CURL_BLOCK_OPT_SSLVERIFY
,
541 .type
= QEMU_OPT_BOOL
,
542 .help
= "Verify SSL certificate"
545 .name
= CURL_BLOCK_OPT_TIMEOUT
,
546 .type
= QEMU_OPT_NUMBER
,
547 .help
= "Curl timeout"
550 .name
= CURL_BLOCK_OPT_COOKIE
,
551 .type
= QEMU_OPT_STRING
,
552 .help
= "Pass the cookie or list of cookies with each request"
555 .name
= CURL_BLOCK_OPT_USERNAME
,
556 .type
= QEMU_OPT_STRING
,
557 .help
= "Username for HTTP auth"
560 .name
= CURL_BLOCK_OPT_PASSWORD_SECRET
,
561 .type
= QEMU_OPT_STRING
,
562 .help
= "ID of secret used as password for HTTP auth",
565 .name
= CURL_BLOCK_OPT_PROXY_USERNAME
,
566 .type
= QEMU_OPT_STRING
,
567 .help
= "Username for HTTP proxy auth"
570 .name
= CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET
,
571 .type
= QEMU_OPT_STRING
,
572 .help
= "ID of secret used as password for HTTP proxy auth",
574 { /* end of list */ }
579 static int curl_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
582 BDRVCURLState
*s
= bs
->opaque
;
583 CURLState
*state
= NULL
;
585 Error
*local_err
= NULL
;
589 const char *secretid
;
591 static int inited
= 0;
593 if (flags
& BDRV_O_RDWR
) {
594 error_setg(errp
, "curl block device does not support writes");
598 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
599 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
601 error_propagate(errp
, local_err
);
605 s
->readahead_size
= qemu_opt_get_size(opts
, CURL_BLOCK_OPT_READAHEAD
,
607 if ((s
->readahead_size
& 0x1ff) != 0) {
608 error_setg(errp
, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512",
613 s
->timeout
= qemu_opt_get_number(opts
, CURL_BLOCK_OPT_TIMEOUT
,
614 CURL_TIMEOUT_DEFAULT
);
615 if (s
->timeout
> CURL_TIMEOUT_MAX
) {
616 error_setg(errp
, "timeout parameter is too large or negative");
620 s
->sslverify
= qemu_opt_get_bool(opts
, CURL_BLOCK_OPT_SSLVERIFY
, true);
622 cookie
= qemu_opt_get(opts
, CURL_BLOCK_OPT_COOKIE
);
623 s
->cookie
= g_strdup(cookie
);
625 file
= qemu_opt_get(opts
, CURL_BLOCK_OPT_URL
);
627 error_setg(errp
, "curl block driver requires an 'url' option");
631 s
->username
= g_strdup(qemu_opt_get(opts
, CURL_BLOCK_OPT_USERNAME
));
632 secretid
= qemu_opt_get(opts
, CURL_BLOCK_OPT_PASSWORD_SECRET
);
635 s
->password
= qcrypto_secret_lookup_as_utf8(secretid
, errp
);
641 s
->proxyusername
= g_strdup(
642 qemu_opt_get(opts
, CURL_BLOCK_OPT_PROXY_USERNAME
));
643 secretid
= qemu_opt_get(opts
, CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET
);
645 s
->proxypassword
= qcrypto_secret_lookup_as_utf8(secretid
, errp
);
646 if (!s
->proxypassword
) {
652 curl_global_init(CURL_GLOBAL_ALL
);
656 DPRINTF("CURL: Opening %s\n", file
);
657 s
->aio_context
= bdrv_get_aio_context(bs
);
658 s
->url
= g_strdup(file
);
659 state
= curl_init_state(bs
, s
);
665 s
->accept_range
= false;
666 curl_easy_setopt(state
->curl
, CURLOPT_NOBODY
, 1);
667 curl_easy_setopt(state
->curl
, CURLOPT_HEADERFUNCTION
,
669 curl_easy_setopt(state
->curl
, CURLOPT_HEADERDATA
, s
);
670 if (curl_easy_perform(state
->curl
))
672 curl_easy_getinfo(state
->curl
, CURLINFO_CONTENT_LENGTH_DOWNLOAD
, &d
);
677 if ((!strncasecmp(s
->url
, "http://", strlen("http://"))
678 || !strncasecmp(s
->url
, "https://", strlen("https://")))
679 && !s
->accept_range
) {
680 pstrcpy(state
->errmsg
, CURL_ERROR_SIZE
,
681 "Server does not support 'range' (byte ranges).");
684 DPRINTF("CURL: Size = %zd\n", s
->len
);
686 curl_clean_state(state
);
687 curl_easy_cleanup(state
->curl
);
690 curl_attach_aio_context(bs
, bdrv_get_aio_context(bs
));
696 error_setg(errp
, "CURL: Error opening file: %s", state
->errmsg
);
697 curl_easy_cleanup(state
->curl
);
706 static const AIOCBInfo curl_aiocb_info
= {
707 .aiocb_size
= sizeof(CURLAIOCB
),
711 static void curl_readv_bh_cb(void *p
)
717 BDRVCURLState
*s
= acb
->common
.bs
->opaque
;
719 qemu_bh_delete(acb
->bh
);
722 size_t start
= acb
->sector_num
* SECTOR_SIZE
;
725 // In case we have the requested data already (e.g. read-ahead),
726 // we can just call the callback and be done.
727 switch (curl_find_buf(s
, start
, acb
->nb_sectors
* SECTOR_SIZE
, acb
)) {
737 // No cache found, so let's start a new request
738 state
= curl_init_state(acb
->common
.bs
, s
);
740 acb
->common
.cb(acb
->common
.opaque
, -EIO
);
746 acb
->end
= (acb
->nb_sectors
* SECTOR_SIZE
);
749 g_free(state
->orig_buf
);
750 state
->buf_start
= start
;
751 state
->buf_len
= acb
->end
+ s
->readahead_size
;
752 end
= MIN(start
+ state
->buf_len
, s
->len
) - 1;
753 state
->orig_buf
= g_try_malloc(state
->buf_len
);
754 if (state
->buf_len
&& state
->orig_buf
== NULL
) {
755 curl_clean_state(state
);
756 acb
->common
.cb(acb
->common
.opaque
, -ENOMEM
);
762 snprintf(state
->range
, 127, "%zd-%zd", start
, end
);
763 DPRINTF("CURL (AIO): Reading %d at %zd (%s)\n",
764 (acb
->nb_sectors
* SECTOR_SIZE
), start
, state
->range
);
765 curl_easy_setopt(state
->curl
, CURLOPT_RANGE
, state
->range
);
767 curl_multi_add_handle(s
->multi
, state
->curl
);
769 /* Tell curl it needs to kick things off */
770 curl_multi_socket_action(s
->multi
, CURL_SOCKET_TIMEOUT
, 0, &running
);
773 static BlockAIOCB
*curl_aio_readv(BlockDriverState
*bs
,
774 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
775 BlockCompletionFunc
*cb
, void *opaque
)
779 acb
= qemu_aio_get(&curl_aiocb_info
, bs
, cb
, opaque
);
782 acb
->sector_num
= sector_num
;
783 acb
->nb_sectors
= nb_sectors
;
785 acb
->bh
= aio_bh_new(bdrv_get_aio_context(bs
), curl_readv_bh_cb
, acb
);
786 qemu_bh_schedule(acb
->bh
);
790 static void curl_close(BlockDriverState
*bs
)
792 BDRVCURLState
*s
= bs
->opaque
;
794 DPRINTF("CURL: Close\n");
795 curl_detach_aio_context(bs
);
801 static int64_t curl_getlength(BlockDriverState
*bs
)
803 BDRVCURLState
*s
= bs
->opaque
;
807 static BlockDriver bdrv_http
= {
808 .format_name
= "http",
809 .protocol_name
= "http",
811 .instance_size
= sizeof(BDRVCURLState
),
812 .bdrv_parse_filename
= curl_parse_filename
,
813 .bdrv_file_open
= curl_open
,
814 .bdrv_close
= curl_close
,
815 .bdrv_getlength
= curl_getlength
,
817 .bdrv_aio_readv
= curl_aio_readv
,
819 .bdrv_detach_aio_context
= curl_detach_aio_context
,
820 .bdrv_attach_aio_context
= curl_attach_aio_context
,
823 static BlockDriver bdrv_https
= {
824 .format_name
= "https",
825 .protocol_name
= "https",
827 .instance_size
= sizeof(BDRVCURLState
),
828 .bdrv_parse_filename
= curl_parse_filename
,
829 .bdrv_file_open
= curl_open
,
830 .bdrv_close
= curl_close
,
831 .bdrv_getlength
= curl_getlength
,
833 .bdrv_aio_readv
= curl_aio_readv
,
835 .bdrv_detach_aio_context
= curl_detach_aio_context
,
836 .bdrv_attach_aio_context
= curl_attach_aio_context
,
839 static BlockDriver bdrv_ftp
= {
840 .format_name
= "ftp",
841 .protocol_name
= "ftp",
843 .instance_size
= sizeof(BDRVCURLState
),
844 .bdrv_parse_filename
= curl_parse_filename
,
845 .bdrv_file_open
= curl_open
,
846 .bdrv_close
= curl_close
,
847 .bdrv_getlength
= curl_getlength
,
849 .bdrv_aio_readv
= curl_aio_readv
,
851 .bdrv_detach_aio_context
= curl_detach_aio_context
,
852 .bdrv_attach_aio_context
= curl_attach_aio_context
,
855 static BlockDriver bdrv_ftps
= {
856 .format_name
= "ftps",
857 .protocol_name
= "ftps",
859 .instance_size
= sizeof(BDRVCURLState
),
860 .bdrv_parse_filename
= curl_parse_filename
,
861 .bdrv_file_open
= curl_open
,
862 .bdrv_close
= curl_close
,
863 .bdrv_getlength
= curl_getlength
,
865 .bdrv_aio_readv
= curl_aio_readv
,
867 .bdrv_detach_aio_context
= curl_detach_aio_context
,
868 .bdrv_attach_aio_context
= curl_attach_aio_context
,
871 static BlockDriver bdrv_tftp
= {
872 .format_name
= "tftp",
873 .protocol_name
= "tftp",
875 .instance_size
= sizeof(BDRVCURLState
),
876 .bdrv_parse_filename
= curl_parse_filename
,
877 .bdrv_file_open
= curl_open
,
878 .bdrv_close
= curl_close
,
879 .bdrv_getlength
= curl_getlength
,
881 .bdrv_aio_readv
= curl_aio_readv
,
883 .bdrv_detach_aio_context
= curl_detach_aio_context
,
884 .bdrv_attach_aio_context
= curl_attach_aio_context
,
887 static void curl_block_init(void)
889 bdrv_register(&bdrv_http
);
890 bdrv_register(&bdrv_https
);
891 bdrv_register(&bdrv_ftp
);
892 bdrv_register(&bdrv_ftps
);
893 bdrv_register(&bdrv_tftp
);
896 block_init(curl_block_init
);