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 "qemu-common.h"
26 #include "qemu/error-report.h"
27 #include "block/block_int.h"
28 #include "qapi/qmp/qbool.h"
29 #include "qapi/qmp/qstring.h"
30 #include "crypto/secret.h"
31 #include <curl/curl.h>
34 // #define DEBUG_VERBOSE
37 #define DPRINTF(fmt, ...) do { printf(fmt, ## __VA_ARGS__); } while (0)
39 #define DPRINTF(fmt, ...) do { } while (0)
42 #if LIBCURL_VERSION_NUM >= 0x071000
43 /* The multi interface timer callback was introduced in 7.16.0 */
44 #define NEED_CURL_TIMER_CALLBACK
45 #define HAVE_SOCKET_ACTION
48 #ifndef HAVE_SOCKET_ACTION
49 /* If curl_multi_socket_action isn't available, define it statically here in
50 * terms of curl_multi_socket. Note that ev_bitmask will be ignored, which is
51 * less efficient but still safe. */
52 static CURLMcode
__curl_multi_socket_action(CURLM
*multi_handle
,
57 return curl_multi_socket(multi_handle
, sockfd
, running_handles
);
59 #define curl_multi_socket_action __curl_multi_socket_action
62 #define PROTOCOLS (CURLPROTO_HTTP | CURLPROTO_HTTPS | \
63 CURLPROTO_FTP | CURLPROTO_FTPS | \
66 #define CURL_NUM_STATES 8
67 #define CURL_NUM_ACB 8
68 #define SECTOR_SIZE 512
69 #define READ_AHEAD_DEFAULT (256 * 1024)
70 #define CURL_TIMEOUT_DEFAULT 5
71 #define CURL_TIMEOUT_MAX 10000
73 #define FIND_RET_NONE 0
75 #define FIND_RET_WAIT 2
77 #define CURL_BLOCK_OPT_URL "url"
78 #define CURL_BLOCK_OPT_READAHEAD "readahead"
79 #define CURL_BLOCK_OPT_SSLVERIFY "sslverify"
80 #define CURL_BLOCK_OPT_TIMEOUT "timeout"
81 #define CURL_BLOCK_OPT_COOKIE "cookie"
82 #define CURL_BLOCK_OPT_USERNAME "username"
83 #define CURL_BLOCK_OPT_PASSWORD_SECRET "password-secret"
84 #define CURL_BLOCK_OPT_PROXY_USERNAME "proxy-username"
85 #define CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET "proxy-password-secret"
89 typedef struct CURLAIOCB
{
101 typedef struct CURLState
103 struct BDRVCURLState
*s
;
104 CURLAIOCB
*acb
[CURL_NUM_ACB
];
106 curl_socket_t sock_fd
;
112 char errmsg
[CURL_ERROR_SIZE
];
116 typedef struct BDRVCURLState
{
120 CURLState states
[CURL_NUM_STATES
];
122 size_t readahead_size
;
127 AioContext
*aio_context
;
134 static void curl_clean_state(CURLState
*s
);
135 static void curl_multi_do(void *arg
);
136 static void curl_multi_read(void *arg
);
138 #ifdef NEED_CURL_TIMER_CALLBACK
139 static int curl_timer_cb(CURLM
*multi
, long timeout_ms
, void *opaque
)
141 BDRVCURLState
*s
= opaque
;
143 DPRINTF("CURL: timer callback timeout_ms %ld\n", timeout_ms
);
144 if (timeout_ms
== -1) {
145 timer_del(&s
->timer
);
147 int64_t timeout_ns
= (int64_t)timeout_ms
* 1000 * 1000;
149 qemu_clock_get_ns(QEMU_CLOCK_REALTIME
) + timeout_ns
);
155 static int curl_sock_cb(CURL
*curl
, curl_socket_t fd
, int action
,
156 void *userp
, void *sp
)
159 CURLState
*state
= NULL
;
160 curl_easy_getinfo(curl
, CURLINFO_PRIVATE
, (char **)&state
);
164 DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action
, fd
);
167 aio_set_fd_handler(s
->aio_context
, fd
, false,
168 curl_multi_read
, NULL
, state
);
171 aio_set_fd_handler(s
->aio_context
, fd
, false,
172 NULL
, curl_multi_do
, state
);
174 case CURL_POLL_INOUT
:
175 aio_set_fd_handler(s
->aio_context
, fd
, false,
176 curl_multi_read
, curl_multi_do
, state
);
178 case CURL_POLL_REMOVE
:
179 aio_set_fd_handler(s
->aio_context
, fd
, false,
187 static size_t curl_header_cb(void *ptr
, size_t size
, size_t nmemb
, void *opaque
)
189 BDRVCURLState
*s
= opaque
;
190 size_t realsize
= size
* nmemb
;
191 const char *accept_line
= "Accept-Ranges: bytes";
193 if (realsize
>= strlen(accept_line
)
194 && strncmp((char *)ptr
, accept_line
, strlen(accept_line
)) == 0) {
195 s
->accept_range
= true;
201 static size_t curl_read_cb(void *ptr
, size_t size
, size_t nmemb
, void *opaque
)
203 CURLState
*s
= ((CURLState
*)opaque
);
204 size_t realsize
= size
* nmemb
;
207 DPRINTF("CURL: Just reading %zd bytes\n", realsize
);
209 if (!s
|| !s
->orig_buf
)
212 if (s
->buf_off
>= s
->buf_len
) {
213 /* buffer full, read nothing */
216 realsize
= MIN(realsize
, s
->buf_len
- s
->buf_off
);
217 memcpy(s
->orig_buf
+ s
->buf_off
, ptr
, realsize
);
218 s
->buf_off
+= realsize
;
220 for(i
=0; i
<CURL_NUM_ACB
; i
++) {
221 CURLAIOCB
*acb
= s
->acb
[i
];
226 if ((s
->buf_off
>= acb
->end
)) {
227 qemu_iovec_from_buf(acb
->qiov
, 0, s
->orig_buf
+ acb
->start
,
228 acb
->end
- acb
->start
);
229 acb
->common
.cb(acb
->common
.opaque
, 0);
238 static int curl_find_buf(BDRVCURLState
*s
, size_t start
, size_t len
,
242 size_t end
= start
+ len
;
244 for (i
=0; i
<CURL_NUM_STATES
; i
++) {
245 CURLState
*state
= &s
->states
[i
];
246 size_t buf_end
= (state
->buf_start
+ state
->buf_off
);
247 size_t buf_fend
= (state
->buf_start
+ state
->buf_len
);
249 if (!state
->orig_buf
)
254 // Does the existing buffer cover our section?
255 if ((start
>= state
->buf_start
) &&
256 (start
<= buf_end
) &&
257 (end
>= state
->buf_start
) &&
260 char *buf
= state
->orig_buf
+ (start
- state
->buf_start
);
262 qemu_iovec_from_buf(acb
->qiov
, 0, buf
, len
);
263 acb
->common
.cb(acb
->common
.opaque
, 0);
268 // Wait for unfinished chunks
270 (start
>= state
->buf_start
) &&
271 (start
<= buf_fend
) &&
272 (end
>= state
->buf_start
) &&
277 acb
->start
= start
- state
->buf_start
;
278 acb
->end
= acb
->start
+ len
;
280 for (j
=0; j
<CURL_NUM_ACB
; j
++) {
281 if (!state
->acb
[j
]) {
283 return FIND_RET_WAIT
;
289 return FIND_RET_NONE
;
292 static void curl_multi_check_completion(BDRVCURLState
*s
)
296 /* Try to find done transfers, so we can free the easy
300 msg
= curl_multi_info_read(s
->multi
, &msgs_in_queue
);
302 /* Quit when there are no more completions */
306 if (msg
->msg
== CURLMSG_DONE
) {
307 CURLState
*state
= NULL
;
308 curl_easy_getinfo(msg
->easy_handle
, CURLINFO_PRIVATE
,
311 /* ACBs for successful messages get completed in curl_read_cb */
312 if (msg
->data
.result
!= CURLE_OK
) {
314 static int errcount
= 100;
316 /* Don't lose the original error message from curl, since
317 * it contains extra data.
320 error_report("curl: %s", state
->errmsg
);
321 if (--errcount
== 0) {
322 error_report("curl: further errors suppressed");
326 for (i
= 0; i
< CURL_NUM_ACB
; i
++) {
327 CURLAIOCB
*acb
= state
->acb
[i
];
333 acb
->common
.cb(acb
->common
.opaque
, -EPROTO
);
335 state
->acb
[i
] = NULL
;
339 curl_clean_state(state
);
345 static void curl_multi_do(void *arg
)
347 CURLState
*s
= (CURLState
*)arg
;
356 r
= curl_multi_socket_action(s
->s
->multi
, s
->sock_fd
, 0, &running
);
357 } while(r
== CURLM_CALL_MULTI_PERFORM
);
361 static void curl_multi_read(void *arg
)
363 CURLState
*s
= (CURLState
*)arg
;
366 curl_multi_check_completion(s
->s
);
369 static void curl_multi_timeout_do(void *arg
)
371 #ifdef NEED_CURL_TIMER_CALLBACK
372 BDRVCURLState
*s
= (BDRVCURLState
*)arg
;
379 curl_multi_socket_action(s
->multi
, CURL_SOCKET_TIMEOUT
, 0, &running
);
381 curl_multi_check_completion(s
);
387 static CURLState
*curl_init_state(BlockDriverState
*bs
, BDRVCURLState
*s
)
389 CURLState
*state
= NULL
;
393 for (i
=0; i
<CURL_NUM_STATES
; i
++) {
394 for (j
=0; j
<CURL_NUM_ACB
; j
++)
395 if (s
->states
[i
].acb
[j
])
397 if (s
->states
[i
].in_use
)
400 state
= &s
->states
[i
];
405 aio_poll(bdrv_get_aio_context(bs
), true);
410 state
->curl
= curl_easy_init();
414 curl_easy_setopt(state
->curl
, CURLOPT_URL
, s
->url
);
415 curl_easy_setopt(state
->curl
, CURLOPT_SSL_VERIFYPEER
,
416 (long) s
->sslverify
);
418 curl_easy_setopt(state
->curl
, CURLOPT_COOKIE
, s
->cookie
);
420 curl_easy_setopt(state
->curl
, CURLOPT_TIMEOUT
, (long)s
->timeout
);
421 curl_easy_setopt(state
->curl
, CURLOPT_WRITEFUNCTION
,
422 (void *)curl_read_cb
);
423 curl_easy_setopt(state
->curl
, CURLOPT_WRITEDATA
, (void *)state
);
424 curl_easy_setopt(state
->curl
, CURLOPT_PRIVATE
, (void *)state
);
425 curl_easy_setopt(state
->curl
, CURLOPT_AUTOREFERER
, 1);
426 curl_easy_setopt(state
->curl
, CURLOPT_FOLLOWLOCATION
, 1);
427 curl_easy_setopt(state
->curl
, CURLOPT_NOSIGNAL
, 1);
428 curl_easy_setopt(state
->curl
, CURLOPT_ERRORBUFFER
, state
->errmsg
);
429 curl_easy_setopt(state
->curl
, CURLOPT_FAILONERROR
, 1);
432 curl_easy_setopt(state
->curl
, CURLOPT_USERNAME
, s
->username
);
435 curl_easy_setopt(state
->curl
, CURLOPT_PASSWORD
, s
->password
);
437 if (s
->proxyusername
) {
438 curl_easy_setopt(state
->curl
,
439 CURLOPT_PROXYUSERNAME
, s
->proxyusername
);
441 if (s
->proxypassword
) {
442 curl_easy_setopt(state
->curl
,
443 CURLOPT_PROXYPASSWORD
, s
->proxypassword
);
446 /* Restrict supported protocols to avoid security issues in the more
447 * obscure protocols. For example, do not allow POP3/SMTP/IMAP see
450 * Restricting protocols is only supported from 7.19.4 upwards.
452 #if LIBCURL_VERSION_NUM >= 0x071304
453 curl_easy_setopt(state
->curl
, CURLOPT_PROTOCOLS
, PROTOCOLS
);
454 curl_easy_setopt(state
->curl
, CURLOPT_REDIR_PROTOCOLS
, PROTOCOLS
);
458 curl_easy_setopt(state
->curl
, CURLOPT_VERBOSE
, 1);
467 static void curl_clean_state(CURLState
*s
)
470 curl_multi_remove_handle(s
->s
->multi
, s
->curl
);
474 static void curl_parse_filename(const char *filename
, QDict
*options
,
477 qdict_put(options
, CURL_BLOCK_OPT_URL
, qstring_from_str(filename
));
480 static void curl_detach_aio_context(BlockDriverState
*bs
)
482 BDRVCURLState
*s
= bs
->opaque
;
485 for (i
= 0; i
< CURL_NUM_STATES
; i
++) {
486 if (s
->states
[i
].in_use
) {
487 curl_clean_state(&s
->states
[i
]);
489 if (s
->states
[i
].curl
) {
490 curl_easy_cleanup(s
->states
[i
].curl
);
491 s
->states
[i
].curl
= NULL
;
493 g_free(s
->states
[i
].orig_buf
);
494 s
->states
[i
].orig_buf
= NULL
;
497 curl_multi_cleanup(s
->multi
);
501 timer_del(&s
->timer
);
504 static void curl_attach_aio_context(BlockDriverState
*bs
,
505 AioContext
*new_context
)
507 BDRVCURLState
*s
= bs
->opaque
;
509 aio_timer_init(new_context
, &s
->timer
,
510 QEMU_CLOCK_REALTIME
, SCALE_NS
,
511 curl_multi_timeout_do
, s
);
514 s
->multi
= curl_multi_init();
515 s
->aio_context
= new_context
;
516 curl_multi_setopt(s
->multi
, CURLMOPT_SOCKETFUNCTION
, curl_sock_cb
);
517 #ifdef NEED_CURL_TIMER_CALLBACK
518 curl_multi_setopt(s
->multi
, CURLMOPT_TIMERDATA
, s
);
519 curl_multi_setopt(s
->multi
, CURLMOPT_TIMERFUNCTION
, curl_timer_cb
);
523 static QemuOptsList runtime_opts
= {
525 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
528 .name
= CURL_BLOCK_OPT_URL
,
529 .type
= QEMU_OPT_STRING
,
530 .help
= "URL to open",
533 .name
= CURL_BLOCK_OPT_READAHEAD
,
534 .type
= QEMU_OPT_SIZE
,
535 .help
= "Readahead size",
538 .name
= CURL_BLOCK_OPT_SSLVERIFY
,
539 .type
= QEMU_OPT_BOOL
,
540 .help
= "Verify SSL certificate"
543 .name
= CURL_BLOCK_OPT_TIMEOUT
,
544 .type
= QEMU_OPT_NUMBER
,
545 .help
= "Curl timeout"
548 .name
= CURL_BLOCK_OPT_COOKIE
,
549 .type
= QEMU_OPT_STRING
,
550 .help
= "Pass the cookie or list of cookies with each request"
553 .name
= CURL_BLOCK_OPT_USERNAME
,
554 .type
= QEMU_OPT_STRING
,
555 .help
= "Username for HTTP auth"
558 .name
= CURL_BLOCK_OPT_PASSWORD_SECRET
,
559 .type
= QEMU_OPT_STRING
,
560 .help
= "ID of secret used as password for HTTP auth",
563 .name
= CURL_BLOCK_OPT_PROXY_USERNAME
,
564 .type
= QEMU_OPT_STRING
,
565 .help
= "Username for HTTP proxy auth"
568 .name
= CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET
,
569 .type
= QEMU_OPT_STRING
,
570 .help
= "ID of secret used as password for HTTP proxy auth",
572 { /* end of list */ }
577 static int curl_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
580 BDRVCURLState
*s
= bs
->opaque
;
581 CURLState
*state
= NULL
;
583 Error
*local_err
= NULL
;
587 const char *secretid
;
589 static int inited
= 0;
591 if (flags
& BDRV_O_RDWR
) {
592 error_setg(errp
, "curl block device does not support writes");
596 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
597 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
599 error_propagate(errp
, local_err
);
603 s
->readahead_size
= qemu_opt_get_size(opts
, CURL_BLOCK_OPT_READAHEAD
,
605 if ((s
->readahead_size
& 0x1ff) != 0) {
606 error_setg(errp
, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512",
611 s
->timeout
= qemu_opt_get_number(opts
, CURL_BLOCK_OPT_TIMEOUT
,
612 CURL_TIMEOUT_DEFAULT
);
613 if (s
->timeout
> CURL_TIMEOUT_MAX
) {
614 error_setg(errp
, "timeout parameter is too large or negative");
618 s
->sslverify
= qemu_opt_get_bool(opts
, CURL_BLOCK_OPT_SSLVERIFY
, true);
620 cookie
= qemu_opt_get(opts
, CURL_BLOCK_OPT_COOKIE
);
621 s
->cookie
= g_strdup(cookie
);
623 file
= qemu_opt_get(opts
, CURL_BLOCK_OPT_URL
);
625 error_setg(errp
, "curl block driver requires an 'url' option");
629 s
->username
= g_strdup(qemu_opt_get(opts
, CURL_BLOCK_OPT_USERNAME
));
630 secretid
= qemu_opt_get(opts
, CURL_BLOCK_OPT_PASSWORD_SECRET
);
633 s
->password
= qcrypto_secret_lookup_as_utf8(secretid
, errp
);
639 s
->proxyusername
= g_strdup(
640 qemu_opt_get(opts
, CURL_BLOCK_OPT_PROXY_USERNAME
));
641 secretid
= qemu_opt_get(opts
, CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET
);
643 s
->proxypassword
= qcrypto_secret_lookup_as_utf8(secretid
, errp
);
644 if (!s
->proxypassword
) {
650 curl_global_init(CURL_GLOBAL_ALL
);
654 DPRINTF("CURL: Opening %s\n", file
);
655 s
->aio_context
= bdrv_get_aio_context(bs
);
656 s
->url
= g_strdup(file
);
657 state
= curl_init_state(bs
, s
);
663 s
->accept_range
= false;
664 curl_easy_setopt(state
->curl
, CURLOPT_NOBODY
, 1);
665 curl_easy_setopt(state
->curl
, CURLOPT_HEADERFUNCTION
,
667 curl_easy_setopt(state
->curl
, CURLOPT_HEADERDATA
, s
);
668 if (curl_easy_perform(state
->curl
))
670 curl_easy_getinfo(state
->curl
, CURLINFO_CONTENT_LENGTH_DOWNLOAD
, &d
);
675 if ((!strncasecmp(s
->url
, "http://", strlen("http://"))
676 || !strncasecmp(s
->url
, "https://", strlen("https://")))
677 && !s
->accept_range
) {
678 pstrcpy(state
->errmsg
, CURL_ERROR_SIZE
,
679 "Server does not support 'range' (byte ranges).");
682 DPRINTF("CURL: Size = %zd\n", s
->len
);
684 curl_clean_state(state
);
685 curl_easy_cleanup(state
->curl
);
688 curl_attach_aio_context(bs
, bdrv_get_aio_context(bs
));
694 error_setg(errp
, "CURL: Error opening file: %s", state
->errmsg
);
695 curl_easy_cleanup(state
->curl
);
704 static const AIOCBInfo curl_aiocb_info
= {
705 .aiocb_size
= sizeof(CURLAIOCB
),
709 static void curl_readv_bh_cb(void *p
)
715 BDRVCURLState
*s
= acb
->common
.bs
->opaque
;
717 qemu_bh_delete(acb
->bh
);
720 size_t start
= acb
->sector_num
* SECTOR_SIZE
;
723 // In case we have the requested data already (e.g. read-ahead),
724 // we can just call the callback and be done.
725 switch (curl_find_buf(s
, start
, acb
->nb_sectors
* SECTOR_SIZE
, acb
)) {
735 // No cache found, so let's start a new request
736 state
= curl_init_state(acb
->common
.bs
, s
);
738 acb
->common
.cb(acb
->common
.opaque
, -EIO
);
744 acb
->end
= (acb
->nb_sectors
* SECTOR_SIZE
);
747 g_free(state
->orig_buf
);
748 state
->buf_start
= start
;
749 state
->buf_len
= acb
->end
+ s
->readahead_size
;
750 end
= MIN(start
+ state
->buf_len
, s
->len
) - 1;
751 state
->orig_buf
= g_try_malloc(state
->buf_len
);
752 if (state
->buf_len
&& state
->orig_buf
== NULL
) {
753 curl_clean_state(state
);
754 acb
->common
.cb(acb
->common
.opaque
, -ENOMEM
);
760 snprintf(state
->range
, 127, "%zd-%zd", start
, end
);
761 DPRINTF("CURL (AIO): Reading %d at %zd (%s)\n",
762 (acb
->nb_sectors
* SECTOR_SIZE
), start
, state
->range
);
763 curl_easy_setopt(state
->curl
, CURLOPT_RANGE
, state
->range
);
765 curl_multi_add_handle(s
->multi
, state
->curl
);
767 /* Tell curl it needs to kick things off */
768 curl_multi_socket_action(s
->multi
, CURL_SOCKET_TIMEOUT
, 0, &running
);
771 static BlockAIOCB
*curl_aio_readv(BlockDriverState
*bs
,
772 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
773 BlockCompletionFunc
*cb
, void *opaque
)
777 acb
= qemu_aio_get(&curl_aiocb_info
, bs
, cb
, opaque
);
780 acb
->sector_num
= sector_num
;
781 acb
->nb_sectors
= nb_sectors
;
783 acb
->bh
= aio_bh_new(bdrv_get_aio_context(bs
), curl_readv_bh_cb
, acb
);
784 qemu_bh_schedule(acb
->bh
);
788 static void curl_close(BlockDriverState
*bs
)
790 BDRVCURLState
*s
= bs
->opaque
;
792 DPRINTF("CURL: Close\n");
793 curl_detach_aio_context(bs
);
799 static int64_t curl_getlength(BlockDriverState
*bs
)
801 BDRVCURLState
*s
= bs
->opaque
;
805 static BlockDriver bdrv_http
= {
806 .format_name
= "http",
807 .protocol_name
= "http",
809 .instance_size
= sizeof(BDRVCURLState
),
810 .bdrv_parse_filename
= curl_parse_filename
,
811 .bdrv_file_open
= curl_open
,
812 .bdrv_close
= curl_close
,
813 .bdrv_getlength
= curl_getlength
,
815 .bdrv_aio_readv
= curl_aio_readv
,
817 .bdrv_detach_aio_context
= curl_detach_aio_context
,
818 .bdrv_attach_aio_context
= curl_attach_aio_context
,
821 static BlockDriver bdrv_https
= {
822 .format_name
= "https",
823 .protocol_name
= "https",
825 .instance_size
= sizeof(BDRVCURLState
),
826 .bdrv_parse_filename
= curl_parse_filename
,
827 .bdrv_file_open
= curl_open
,
828 .bdrv_close
= curl_close
,
829 .bdrv_getlength
= curl_getlength
,
831 .bdrv_aio_readv
= curl_aio_readv
,
833 .bdrv_detach_aio_context
= curl_detach_aio_context
,
834 .bdrv_attach_aio_context
= curl_attach_aio_context
,
837 static BlockDriver bdrv_ftp
= {
838 .format_name
= "ftp",
839 .protocol_name
= "ftp",
841 .instance_size
= sizeof(BDRVCURLState
),
842 .bdrv_parse_filename
= curl_parse_filename
,
843 .bdrv_file_open
= curl_open
,
844 .bdrv_close
= curl_close
,
845 .bdrv_getlength
= curl_getlength
,
847 .bdrv_aio_readv
= curl_aio_readv
,
849 .bdrv_detach_aio_context
= curl_detach_aio_context
,
850 .bdrv_attach_aio_context
= curl_attach_aio_context
,
853 static BlockDriver bdrv_ftps
= {
854 .format_name
= "ftps",
855 .protocol_name
= "ftps",
857 .instance_size
= sizeof(BDRVCURLState
),
858 .bdrv_parse_filename
= curl_parse_filename
,
859 .bdrv_file_open
= curl_open
,
860 .bdrv_close
= curl_close
,
861 .bdrv_getlength
= curl_getlength
,
863 .bdrv_aio_readv
= curl_aio_readv
,
865 .bdrv_detach_aio_context
= curl_detach_aio_context
,
866 .bdrv_attach_aio_context
= curl_attach_aio_context
,
869 static BlockDriver bdrv_tftp
= {
870 .format_name
= "tftp",
871 .protocol_name
= "tftp",
873 .instance_size
= sizeof(BDRVCURLState
),
874 .bdrv_parse_filename
= curl_parse_filename
,
875 .bdrv_file_open
= curl_open
,
876 .bdrv_close
= curl_close
,
877 .bdrv_getlength
= curl_getlength
,
879 .bdrv_aio_readv
= curl_aio_readv
,
881 .bdrv_detach_aio_context
= curl_detach_aio_context
,
882 .bdrv_attach_aio_context
= curl_attach_aio_context
,
885 static void curl_block_init(void)
887 bdrv_register(&bdrv_http
);
888 bdrv_register(&bdrv_https
);
889 bdrv_register(&bdrv_ftp
);
890 bdrv_register(&bdrv_ftps
);
891 bdrv_register(&bdrv_tftp
);
894 block_init(curl_block_init
);