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 DEBUG_CURL_PRINT 1
41 #define DEBUG_CURL_PRINT 0
43 #define DPRINTF(fmt, ...) \
45 if (DEBUG_CURL_PRINT) { \
46 fprintf(stderr, fmt, ## __VA_ARGS__); \
50 #if LIBCURL_VERSION_NUM >= 0x071000
51 /* The multi interface timer callback was introduced in 7.16.0 */
52 #define NEED_CURL_TIMER_CALLBACK
53 #define HAVE_SOCKET_ACTION
56 #ifndef HAVE_SOCKET_ACTION
57 /* If curl_multi_socket_action isn't available, define it statically here in
58 * terms of curl_multi_socket. Note that ev_bitmask will be ignored, which is
59 * less efficient but still safe. */
60 static CURLMcode
__curl_multi_socket_action(CURLM
*multi_handle
,
65 return curl_multi_socket(multi_handle
, sockfd
, running_handles
);
67 #define curl_multi_socket_action __curl_multi_socket_action
70 #define PROTOCOLS (CURLPROTO_HTTP | CURLPROTO_HTTPS | \
71 CURLPROTO_FTP | CURLPROTO_FTPS | \
74 #define CURL_NUM_STATES 8
75 #define CURL_NUM_ACB 8
76 #define SECTOR_SIZE 512
77 #define READ_AHEAD_DEFAULT (256 * 1024)
78 #define CURL_TIMEOUT_DEFAULT 5
79 #define CURL_TIMEOUT_MAX 10000
81 #define FIND_RET_NONE 0
83 #define FIND_RET_WAIT 2
85 #define CURL_BLOCK_OPT_URL "url"
86 #define CURL_BLOCK_OPT_READAHEAD "readahead"
87 #define CURL_BLOCK_OPT_SSLVERIFY "sslverify"
88 #define CURL_BLOCK_OPT_TIMEOUT "timeout"
89 #define CURL_BLOCK_OPT_COOKIE "cookie"
90 #define CURL_BLOCK_OPT_USERNAME "username"
91 #define CURL_BLOCK_OPT_PASSWORD_SECRET "password-secret"
92 #define CURL_BLOCK_OPT_PROXY_USERNAME "proxy-username"
93 #define CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET "proxy-password-secret"
97 typedef struct CURLAIOCB
{
109 typedef struct CURLState
111 struct BDRVCURLState
*s
;
112 CURLAIOCB
*acb
[CURL_NUM_ACB
];
114 curl_socket_t sock_fd
;
120 char errmsg
[CURL_ERROR_SIZE
];
124 typedef struct BDRVCURLState
{
128 CURLState states
[CURL_NUM_STATES
];
130 size_t readahead_size
;
135 AioContext
*aio_context
;
142 static void curl_clean_state(CURLState
*s
);
143 static void curl_multi_do(void *arg
);
144 static void curl_multi_read(void *arg
);
146 #ifdef NEED_CURL_TIMER_CALLBACK
147 static int curl_timer_cb(CURLM
*multi
, long timeout_ms
, void *opaque
)
149 BDRVCURLState
*s
= opaque
;
151 DPRINTF("CURL: timer callback timeout_ms %ld\n", timeout_ms
);
152 if (timeout_ms
== -1) {
153 timer_del(&s
->timer
);
155 int64_t timeout_ns
= (int64_t)timeout_ms
* 1000 * 1000;
157 qemu_clock_get_ns(QEMU_CLOCK_REALTIME
) + timeout_ns
);
163 static int curl_sock_cb(CURL
*curl
, curl_socket_t fd
, int action
,
164 void *userp
, void *sp
)
167 CURLState
*state
= NULL
;
168 curl_easy_getinfo(curl
, CURLINFO_PRIVATE
, (char **)&state
);
172 DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action
, (int)fd
);
175 aio_set_fd_handler(s
->aio_context
, fd
, false,
176 curl_multi_read
, NULL
, state
);
179 aio_set_fd_handler(s
->aio_context
, fd
, false,
180 NULL
, curl_multi_do
, state
);
182 case CURL_POLL_INOUT
:
183 aio_set_fd_handler(s
->aio_context
, fd
, false,
184 curl_multi_read
, curl_multi_do
, state
);
186 case CURL_POLL_REMOVE
:
187 aio_set_fd_handler(s
->aio_context
, fd
, false,
195 static size_t curl_header_cb(void *ptr
, size_t size
, size_t nmemb
, void *opaque
)
197 BDRVCURLState
*s
= opaque
;
198 size_t realsize
= size
* nmemb
;
199 const char *accept_line
= "Accept-Ranges: bytes";
201 if (realsize
>= strlen(accept_line
)
202 && strncmp((char *)ptr
, accept_line
, strlen(accept_line
)) == 0) {
203 s
->accept_range
= true;
209 static size_t curl_read_cb(void *ptr
, size_t size
, size_t nmemb
, void *opaque
)
211 CURLState
*s
= ((CURLState
*)opaque
);
212 size_t realsize
= size
* nmemb
;
215 DPRINTF("CURL: Just reading %zd bytes\n", realsize
);
217 if (!s
|| !s
->orig_buf
)
220 if (s
->buf_off
>= s
->buf_len
) {
221 /* buffer full, read nothing */
224 realsize
= MIN(realsize
, s
->buf_len
- s
->buf_off
);
225 memcpy(s
->orig_buf
+ s
->buf_off
, ptr
, realsize
);
226 s
->buf_off
+= realsize
;
228 for(i
=0; i
<CURL_NUM_ACB
; i
++) {
229 CURLAIOCB
*acb
= s
->acb
[i
];
234 if ((s
->buf_off
>= acb
->end
)) {
235 qemu_iovec_from_buf(acb
->qiov
, 0, s
->orig_buf
+ acb
->start
,
236 acb
->end
- acb
->start
);
237 acb
->common
.cb(acb
->common
.opaque
, 0);
246 static int curl_find_buf(BDRVCURLState
*s
, size_t start
, size_t len
,
250 size_t end
= start
+ len
;
252 for (i
=0; i
<CURL_NUM_STATES
; i
++) {
253 CURLState
*state
= &s
->states
[i
];
254 size_t buf_end
= (state
->buf_start
+ state
->buf_off
);
255 size_t buf_fend
= (state
->buf_start
+ state
->buf_len
);
257 if (!state
->orig_buf
)
262 // Does the existing buffer cover our section?
263 if ((start
>= state
->buf_start
) &&
264 (start
<= buf_end
) &&
265 (end
>= state
->buf_start
) &&
268 char *buf
= state
->orig_buf
+ (start
- state
->buf_start
);
270 qemu_iovec_from_buf(acb
->qiov
, 0, buf
, len
);
271 acb
->common
.cb(acb
->common
.opaque
, 0);
276 // Wait for unfinished chunks
278 (start
>= state
->buf_start
) &&
279 (start
<= buf_fend
) &&
280 (end
>= state
->buf_start
) &&
285 acb
->start
= start
- state
->buf_start
;
286 acb
->end
= acb
->start
+ len
;
288 for (j
=0; j
<CURL_NUM_ACB
; j
++) {
289 if (!state
->acb
[j
]) {
291 return FIND_RET_WAIT
;
297 return FIND_RET_NONE
;
300 static void curl_multi_check_completion(BDRVCURLState
*s
)
304 /* Try to find done transfers, so we can free the easy
308 msg
= curl_multi_info_read(s
->multi
, &msgs_in_queue
);
310 /* Quit when there are no more completions */
314 if (msg
->msg
== CURLMSG_DONE
) {
315 CURLState
*state
= NULL
;
316 curl_easy_getinfo(msg
->easy_handle
, CURLINFO_PRIVATE
,
319 /* ACBs for successful messages get completed in curl_read_cb */
320 if (msg
->data
.result
!= CURLE_OK
) {
322 static int errcount
= 100;
324 /* Don't lose the original error message from curl, since
325 * it contains extra data.
328 error_report("curl: %s", state
->errmsg
);
329 if (--errcount
== 0) {
330 error_report("curl: further errors suppressed");
334 for (i
= 0; i
< CURL_NUM_ACB
; i
++) {
335 CURLAIOCB
*acb
= state
->acb
[i
];
341 acb
->common
.cb(acb
->common
.opaque
, -EPROTO
);
343 state
->acb
[i
] = NULL
;
347 curl_clean_state(state
);
353 static void curl_multi_do(void *arg
)
355 CURLState
*s
= (CURLState
*)arg
;
364 r
= curl_multi_socket_action(s
->s
->multi
, s
->sock_fd
, 0, &running
);
365 } while(r
== CURLM_CALL_MULTI_PERFORM
);
369 static void curl_multi_read(void *arg
)
371 CURLState
*s
= (CURLState
*)arg
;
374 curl_multi_check_completion(s
->s
);
377 static void curl_multi_timeout_do(void *arg
)
379 #ifdef NEED_CURL_TIMER_CALLBACK
380 BDRVCURLState
*s
= (BDRVCURLState
*)arg
;
387 curl_multi_socket_action(s
->multi
, CURL_SOCKET_TIMEOUT
, 0, &running
);
389 curl_multi_check_completion(s
);
395 static CURLState
*curl_init_state(BlockDriverState
*bs
, BDRVCURLState
*s
)
397 CURLState
*state
= NULL
;
401 for (i
=0; i
<CURL_NUM_STATES
; i
++) {
402 for (j
=0; j
<CURL_NUM_ACB
; j
++)
403 if (s
->states
[i
].acb
[j
])
405 if (s
->states
[i
].in_use
)
408 state
= &s
->states
[i
];
413 aio_poll(bdrv_get_aio_context(bs
), true);
418 state
->curl
= curl_easy_init();
422 curl_easy_setopt(state
->curl
, CURLOPT_URL
, s
->url
);
423 curl_easy_setopt(state
->curl
, CURLOPT_SSL_VERIFYPEER
,
424 (long) s
->sslverify
);
426 curl_easy_setopt(state
->curl
, CURLOPT_COOKIE
, s
->cookie
);
428 curl_easy_setopt(state
->curl
, CURLOPT_TIMEOUT
, (long)s
->timeout
);
429 curl_easy_setopt(state
->curl
, CURLOPT_WRITEFUNCTION
,
430 (void *)curl_read_cb
);
431 curl_easy_setopt(state
->curl
, CURLOPT_WRITEDATA
, (void *)state
);
432 curl_easy_setopt(state
->curl
, CURLOPT_PRIVATE
, (void *)state
);
433 curl_easy_setopt(state
->curl
, CURLOPT_AUTOREFERER
, 1);
434 curl_easy_setopt(state
->curl
, CURLOPT_FOLLOWLOCATION
, 1);
435 curl_easy_setopt(state
->curl
, CURLOPT_NOSIGNAL
, 1);
436 curl_easy_setopt(state
->curl
, CURLOPT_ERRORBUFFER
, state
->errmsg
);
437 curl_easy_setopt(state
->curl
, CURLOPT_FAILONERROR
, 1);
440 curl_easy_setopt(state
->curl
, CURLOPT_USERNAME
, s
->username
);
443 curl_easy_setopt(state
->curl
, CURLOPT_PASSWORD
, s
->password
);
445 if (s
->proxyusername
) {
446 curl_easy_setopt(state
->curl
,
447 CURLOPT_PROXYUSERNAME
, s
->proxyusername
);
449 if (s
->proxypassword
) {
450 curl_easy_setopt(state
->curl
,
451 CURLOPT_PROXYPASSWORD
, s
->proxypassword
);
454 /* Restrict supported protocols to avoid security issues in the more
455 * obscure protocols. For example, do not allow POP3/SMTP/IMAP see
458 * Restricting protocols is only supported from 7.19.4 upwards.
460 #if LIBCURL_VERSION_NUM >= 0x071304
461 curl_easy_setopt(state
->curl
, CURLOPT_PROTOCOLS
, PROTOCOLS
);
462 curl_easy_setopt(state
->curl
, CURLOPT_REDIR_PROTOCOLS
, PROTOCOLS
);
466 curl_easy_setopt(state
->curl
, CURLOPT_VERBOSE
, 1);
475 static void curl_clean_state(CURLState
*s
)
478 curl_multi_remove_handle(s
->s
->multi
, s
->curl
);
482 static void curl_parse_filename(const char *filename
, QDict
*options
,
485 qdict_put(options
, CURL_BLOCK_OPT_URL
, qstring_from_str(filename
));
488 static void curl_detach_aio_context(BlockDriverState
*bs
)
490 BDRVCURLState
*s
= bs
->opaque
;
493 for (i
= 0; i
< CURL_NUM_STATES
; i
++) {
494 if (s
->states
[i
].in_use
) {
495 curl_clean_state(&s
->states
[i
]);
497 if (s
->states
[i
].curl
) {
498 curl_easy_cleanup(s
->states
[i
].curl
);
499 s
->states
[i
].curl
= NULL
;
501 g_free(s
->states
[i
].orig_buf
);
502 s
->states
[i
].orig_buf
= NULL
;
505 curl_multi_cleanup(s
->multi
);
509 timer_del(&s
->timer
);
512 static void curl_attach_aio_context(BlockDriverState
*bs
,
513 AioContext
*new_context
)
515 BDRVCURLState
*s
= bs
->opaque
;
517 aio_timer_init(new_context
, &s
->timer
,
518 QEMU_CLOCK_REALTIME
, SCALE_NS
,
519 curl_multi_timeout_do
, s
);
522 s
->multi
= curl_multi_init();
523 s
->aio_context
= new_context
;
524 curl_multi_setopt(s
->multi
, CURLMOPT_SOCKETFUNCTION
, curl_sock_cb
);
525 #ifdef NEED_CURL_TIMER_CALLBACK
526 curl_multi_setopt(s
->multi
, CURLMOPT_TIMERDATA
, s
);
527 curl_multi_setopt(s
->multi
, CURLMOPT_TIMERFUNCTION
, curl_timer_cb
);
531 static QemuOptsList runtime_opts
= {
533 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
536 .name
= CURL_BLOCK_OPT_URL
,
537 .type
= QEMU_OPT_STRING
,
538 .help
= "URL to open",
541 .name
= CURL_BLOCK_OPT_READAHEAD
,
542 .type
= QEMU_OPT_SIZE
,
543 .help
= "Readahead size",
546 .name
= CURL_BLOCK_OPT_SSLVERIFY
,
547 .type
= QEMU_OPT_BOOL
,
548 .help
= "Verify SSL certificate"
551 .name
= CURL_BLOCK_OPT_TIMEOUT
,
552 .type
= QEMU_OPT_NUMBER
,
553 .help
= "Curl timeout"
556 .name
= CURL_BLOCK_OPT_COOKIE
,
557 .type
= QEMU_OPT_STRING
,
558 .help
= "Pass the cookie or list of cookies with each request"
561 .name
= CURL_BLOCK_OPT_USERNAME
,
562 .type
= QEMU_OPT_STRING
,
563 .help
= "Username for HTTP auth"
566 .name
= CURL_BLOCK_OPT_PASSWORD_SECRET
,
567 .type
= QEMU_OPT_STRING
,
568 .help
= "ID of secret used as password for HTTP auth",
571 .name
= CURL_BLOCK_OPT_PROXY_USERNAME
,
572 .type
= QEMU_OPT_STRING
,
573 .help
= "Username for HTTP proxy auth"
576 .name
= CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET
,
577 .type
= QEMU_OPT_STRING
,
578 .help
= "ID of secret used as password for HTTP proxy auth",
580 { /* end of list */ }
585 static int curl_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
588 BDRVCURLState
*s
= bs
->opaque
;
589 CURLState
*state
= NULL
;
591 Error
*local_err
= NULL
;
595 const char *secretid
;
597 static int inited
= 0;
599 if (flags
& BDRV_O_RDWR
) {
600 error_setg(errp
, "curl block device does not support writes");
604 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
605 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
607 error_propagate(errp
, local_err
);
611 s
->readahead_size
= qemu_opt_get_size(opts
, CURL_BLOCK_OPT_READAHEAD
,
613 if ((s
->readahead_size
& 0x1ff) != 0) {
614 error_setg(errp
, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512",
619 s
->timeout
= qemu_opt_get_number(opts
, CURL_BLOCK_OPT_TIMEOUT
,
620 CURL_TIMEOUT_DEFAULT
);
621 if (s
->timeout
> CURL_TIMEOUT_MAX
) {
622 error_setg(errp
, "timeout parameter is too large or negative");
626 s
->sslverify
= qemu_opt_get_bool(opts
, CURL_BLOCK_OPT_SSLVERIFY
, true);
628 cookie
= qemu_opt_get(opts
, CURL_BLOCK_OPT_COOKIE
);
629 s
->cookie
= g_strdup(cookie
);
631 file
= qemu_opt_get(opts
, CURL_BLOCK_OPT_URL
);
633 error_setg(errp
, "curl block driver requires an 'url' option");
637 s
->username
= g_strdup(qemu_opt_get(opts
, CURL_BLOCK_OPT_USERNAME
));
638 secretid
= qemu_opt_get(opts
, CURL_BLOCK_OPT_PASSWORD_SECRET
);
641 s
->password
= qcrypto_secret_lookup_as_utf8(secretid
, errp
);
647 s
->proxyusername
= g_strdup(
648 qemu_opt_get(opts
, CURL_BLOCK_OPT_PROXY_USERNAME
));
649 secretid
= qemu_opt_get(opts
, CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET
);
651 s
->proxypassword
= qcrypto_secret_lookup_as_utf8(secretid
, errp
);
652 if (!s
->proxypassword
) {
658 curl_global_init(CURL_GLOBAL_ALL
);
662 DPRINTF("CURL: Opening %s\n", file
);
663 s
->aio_context
= bdrv_get_aio_context(bs
);
664 s
->url
= g_strdup(file
);
665 state
= curl_init_state(bs
, s
);
671 s
->accept_range
= false;
672 curl_easy_setopt(state
->curl
, CURLOPT_NOBODY
, 1);
673 curl_easy_setopt(state
->curl
, CURLOPT_HEADERFUNCTION
,
675 curl_easy_setopt(state
->curl
, CURLOPT_HEADERDATA
, s
);
676 if (curl_easy_perform(state
->curl
))
678 curl_easy_getinfo(state
->curl
, CURLINFO_CONTENT_LENGTH_DOWNLOAD
, &d
);
683 if ((!strncasecmp(s
->url
, "http://", strlen("http://"))
684 || !strncasecmp(s
->url
, "https://", strlen("https://")))
685 && !s
->accept_range
) {
686 pstrcpy(state
->errmsg
, CURL_ERROR_SIZE
,
687 "Server does not support 'range' (byte ranges).");
690 DPRINTF("CURL: Size = %zd\n", s
->len
);
692 curl_clean_state(state
);
693 curl_easy_cleanup(state
->curl
);
696 curl_attach_aio_context(bs
, bdrv_get_aio_context(bs
));
702 error_setg(errp
, "CURL: Error opening file: %s", state
->errmsg
);
703 curl_easy_cleanup(state
->curl
);
712 static const AIOCBInfo curl_aiocb_info
= {
713 .aiocb_size
= sizeof(CURLAIOCB
),
717 static void curl_readv_bh_cb(void *p
)
723 BDRVCURLState
*s
= acb
->common
.bs
->opaque
;
725 qemu_bh_delete(acb
->bh
);
728 size_t start
= acb
->sector_num
* SECTOR_SIZE
;
731 // In case we have the requested data already (e.g. read-ahead),
732 // we can just call the callback and be done.
733 switch (curl_find_buf(s
, start
, acb
->nb_sectors
* SECTOR_SIZE
, acb
)) {
743 // No cache found, so let's start a new request
744 state
= curl_init_state(acb
->common
.bs
, s
);
746 acb
->common
.cb(acb
->common
.opaque
, -EIO
);
752 acb
->end
= (acb
->nb_sectors
* SECTOR_SIZE
);
755 g_free(state
->orig_buf
);
756 state
->buf_start
= start
;
757 state
->buf_len
= acb
->end
+ s
->readahead_size
;
758 end
= MIN(start
+ state
->buf_len
, s
->len
) - 1;
759 state
->orig_buf
= g_try_malloc(state
->buf_len
);
760 if (state
->buf_len
&& state
->orig_buf
== NULL
) {
761 curl_clean_state(state
);
762 acb
->common
.cb(acb
->common
.opaque
, -ENOMEM
);
768 snprintf(state
->range
, 127, "%zd-%zd", start
, end
);
769 DPRINTF("CURL (AIO): Reading %d at %zd (%s)\n",
770 (acb
->nb_sectors
* SECTOR_SIZE
), start
, state
->range
);
771 curl_easy_setopt(state
->curl
, CURLOPT_RANGE
, state
->range
);
773 curl_multi_add_handle(s
->multi
, state
->curl
);
775 /* Tell curl it needs to kick things off */
776 curl_multi_socket_action(s
->multi
, CURL_SOCKET_TIMEOUT
, 0, &running
);
779 static BlockAIOCB
*curl_aio_readv(BlockDriverState
*bs
,
780 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
781 BlockCompletionFunc
*cb
, void *opaque
)
785 acb
= qemu_aio_get(&curl_aiocb_info
, bs
, cb
, opaque
);
788 acb
->sector_num
= sector_num
;
789 acb
->nb_sectors
= nb_sectors
;
791 acb
->bh
= aio_bh_new(bdrv_get_aio_context(bs
), curl_readv_bh_cb
, acb
);
792 qemu_bh_schedule(acb
->bh
);
796 static void curl_close(BlockDriverState
*bs
)
798 BDRVCURLState
*s
= bs
->opaque
;
800 DPRINTF("CURL: Close\n");
801 curl_detach_aio_context(bs
);
807 static int64_t curl_getlength(BlockDriverState
*bs
)
809 BDRVCURLState
*s
= bs
->opaque
;
813 static BlockDriver bdrv_http
= {
814 .format_name
= "http",
815 .protocol_name
= "http",
817 .instance_size
= sizeof(BDRVCURLState
),
818 .bdrv_parse_filename
= curl_parse_filename
,
819 .bdrv_file_open
= curl_open
,
820 .bdrv_close
= curl_close
,
821 .bdrv_getlength
= curl_getlength
,
823 .bdrv_aio_readv
= curl_aio_readv
,
825 .bdrv_detach_aio_context
= curl_detach_aio_context
,
826 .bdrv_attach_aio_context
= curl_attach_aio_context
,
829 static BlockDriver bdrv_https
= {
830 .format_name
= "https",
831 .protocol_name
= "https",
833 .instance_size
= sizeof(BDRVCURLState
),
834 .bdrv_parse_filename
= curl_parse_filename
,
835 .bdrv_file_open
= curl_open
,
836 .bdrv_close
= curl_close
,
837 .bdrv_getlength
= curl_getlength
,
839 .bdrv_aio_readv
= curl_aio_readv
,
841 .bdrv_detach_aio_context
= curl_detach_aio_context
,
842 .bdrv_attach_aio_context
= curl_attach_aio_context
,
845 static BlockDriver bdrv_ftp
= {
846 .format_name
= "ftp",
847 .protocol_name
= "ftp",
849 .instance_size
= sizeof(BDRVCURLState
),
850 .bdrv_parse_filename
= curl_parse_filename
,
851 .bdrv_file_open
= curl_open
,
852 .bdrv_close
= curl_close
,
853 .bdrv_getlength
= curl_getlength
,
855 .bdrv_aio_readv
= curl_aio_readv
,
857 .bdrv_detach_aio_context
= curl_detach_aio_context
,
858 .bdrv_attach_aio_context
= curl_attach_aio_context
,
861 static BlockDriver bdrv_ftps
= {
862 .format_name
= "ftps",
863 .protocol_name
= "ftps",
865 .instance_size
= sizeof(BDRVCURLState
),
866 .bdrv_parse_filename
= curl_parse_filename
,
867 .bdrv_file_open
= curl_open
,
868 .bdrv_close
= curl_close
,
869 .bdrv_getlength
= curl_getlength
,
871 .bdrv_aio_readv
= curl_aio_readv
,
873 .bdrv_detach_aio_context
= curl_detach_aio_context
,
874 .bdrv_attach_aio_context
= curl_attach_aio_context
,
877 static BlockDriver bdrv_tftp
= {
878 .format_name
= "tftp",
879 .protocol_name
= "tftp",
881 .instance_size
= sizeof(BDRVCURLState
),
882 .bdrv_parse_filename
= curl_parse_filename
,
883 .bdrv_file_open
= curl_open
,
884 .bdrv_close
= curl_close
,
885 .bdrv_getlength
= curl_getlength
,
887 .bdrv_aio_readv
= curl_aio_readv
,
889 .bdrv_detach_aio_context
= curl_detach_aio_context
,
890 .bdrv_attach_aio_context
= curl_attach_aio_context
,
893 static void curl_block_init(void)
895 bdrv_register(&bdrv_http
);
896 bdrv_register(&bdrv_https
);
897 bdrv_register(&bdrv_ftp
);
898 bdrv_register(&bdrv_ftps
);
899 bdrv_register(&bdrv_tftp
);
902 block_init(curl_block_init
);