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
{
108 typedef struct CURLState
110 struct BDRVCURLState
*s
;
111 CURLAIOCB
*acb
[CURL_NUM_ACB
];
113 curl_socket_t sock_fd
;
119 char errmsg
[CURL_ERROR_SIZE
];
123 typedef struct BDRVCURLState
{
127 CURLState states
[CURL_NUM_STATES
];
129 size_t readahead_size
;
134 AioContext
*aio_context
;
141 static void curl_clean_state(CURLState
*s
);
142 static void curl_multi_do(void *arg
);
143 static void curl_multi_read(void *arg
);
145 #ifdef NEED_CURL_TIMER_CALLBACK
146 static int curl_timer_cb(CURLM
*multi
, long timeout_ms
, void *opaque
)
148 BDRVCURLState
*s
= opaque
;
150 DPRINTF("CURL: timer callback timeout_ms %ld\n", timeout_ms
);
151 if (timeout_ms
== -1) {
152 timer_del(&s
->timer
);
154 int64_t timeout_ns
= (int64_t)timeout_ms
* 1000 * 1000;
156 qemu_clock_get_ns(QEMU_CLOCK_REALTIME
) + timeout_ns
);
162 static int curl_sock_cb(CURL
*curl
, curl_socket_t fd
, int action
,
163 void *userp
, void *sp
)
166 CURLState
*state
= NULL
;
167 curl_easy_getinfo(curl
, CURLINFO_PRIVATE
, (char **)&state
);
171 DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action
, (int)fd
);
174 aio_set_fd_handler(s
->aio_context
, fd
, false,
175 curl_multi_read
, NULL
, state
);
178 aio_set_fd_handler(s
->aio_context
, fd
, false,
179 NULL
, curl_multi_do
, state
);
181 case CURL_POLL_INOUT
:
182 aio_set_fd_handler(s
->aio_context
, fd
, false,
183 curl_multi_read
, curl_multi_do
, state
);
185 case CURL_POLL_REMOVE
:
186 aio_set_fd_handler(s
->aio_context
, fd
, false,
194 static size_t curl_header_cb(void *ptr
, size_t size
, size_t nmemb
, void *opaque
)
196 BDRVCURLState
*s
= opaque
;
197 size_t realsize
= size
* nmemb
;
198 const char *accept_line
= "Accept-Ranges: bytes";
200 if (realsize
>= strlen(accept_line
)
201 && strncmp((char *)ptr
, accept_line
, strlen(accept_line
)) == 0) {
202 s
->accept_range
= true;
208 static size_t curl_read_cb(void *ptr
, size_t size
, size_t nmemb
, void *opaque
)
210 CURLState
*s
= ((CURLState
*)opaque
);
211 size_t realsize
= size
* nmemb
;
214 DPRINTF("CURL: Just reading %zd bytes\n", realsize
);
216 if (!s
|| !s
->orig_buf
)
219 if (s
->buf_off
>= s
->buf_len
) {
220 /* buffer full, read nothing */
223 realsize
= MIN(realsize
, s
->buf_len
- s
->buf_off
);
224 memcpy(s
->orig_buf
+ s
->buf_off
, ptr
, realsize
);
225 s
->buf_off
+= realsize
;
227 for(i
=0; i
<CURL_NUM_ACB
; i
++) {
228 CURLAIOCB
*acb
= s
->acb
[i
];
233 if ((s
->buf_off
>= acb
->end
)) {
234 qemu_iovec_from_buf(acb
->qiov
, 0, s
->orig_buf
+ acb
->start
,
235 acb
->end
- acb
->start
);
236 acb
->common
.cb(acb
->common
.opaque
, 0);
245 static int curl_find_buf(BDRVCURLState
*s
, size_t start
, size_t len
,
249 size_t end
= start
+ len
;
251 for (i
=0; i
<CURL_NUM_STATES
; i
++) {
252 CURLState
*state
= &s
->states
[i
];
253 size_t buf_end
= (state
->buf_start
+ state
->buf_off
);
254 size_t buf_fend
= (state
->buf_start
+ state
->buf_len
);
256 if (!state
->orig_buf
)
261 // Does the existing buffer cover our section?
262 if ((start
>= state
->buf_start
) &&
263 (start
<= buf_end
) &&
264 (end
>= state
->buf_start
) &&
267 char *buf
= state
->orig_buf
+ (start
- state
->buf_start
);
269 qemu_iovec_from_buf(acb
->qiov
, 0, buf
, len
);
270 acb
->common
.cb(acb
->common
.opaque
, 0);
275 // Wait for unfinished chunks
277 (start
>= state
->buf_start
) &&
278 (start
<= buf_fend
) &&
279 (end
>= state
->buf_start
) &&
284 acb
->start
= start
- state
->buf_start
;
285 acb
->end
= acb
->start
+ len
;
287 for (j
=0; j
<CURL_NUM_ACB
; j
++) {
288 if (!state
->acb
[j
]) {
290 return FIND_RET_WAIT
;
296 return FIND_RET_NONE
;
299 static void curl_multi_check_completion(BDRVCURLState
*s
)
303 /* Try to find done transfers, so we can free the easy
307 msg
= curl_multi_info_read(s
->multi
, &msgs_in_queue
);
309 /* Quit when there are no more completions */
313 if (msg
->msg
== CURLMSG_DONE
) {
314 CURLState
*state
= NULL
;
315 curl_easy_getinfo(msg
->easy_handle
, CURLINFO_PRIVATE
,
318 /* ACBs for successful messages get completed in curl_read_cb */
319 if (msg
->data
.result
!= CURLE_OK
) {
321 static int errcount
= 100;
323 /* Don't lose the original error message from curl, since
324 * it contains extra data.
327 error_report("curl: %s", state
->errmsg
);
328 if (--errcount
== 0) {
329 error_report("curl: further errors suppressed");
333 for (i
= 0; i
< CURL_NUM_ACB
; i
++) {
334 CURLAIOCB
*acb
= state
->acb
[i
];
340 acb
->common
.cb(acb
->common
.opaque
, -EPROTO
);
342 state
->acb
[i
] = NULL
;
346 curl_clean_state(state
);
352 static void curl_multi_do(void *arg
)
354 CURLState
*s
= (CURLState
*)arg
;
363 r
= curl_multi_socket_action(s
->s
->multi
, s
->sock_fd
, 0, &running
);
364 } while(r
== CURLM_CALL_MULTI_PERFORM
);
368 static void curl_multi_read(void *arg
)
370 CURLState
*s
= (CURLState
*)arg
;
373 curl_multi_check_completion(s
->s
);
376 static void curl_multi_timeout_do(void *arg
)
378 #ifdef NEED_CURL_TIMER_CALLBACK
379 BDRVCURLState
*s
= (BDRVCURLState
*)arg
;
386 curl_multi_socket_action(s
->multi
, CURL_SOCKET_TIMEOUT
, 0, &running
);
388 curl_multi_check_completion(s
);
394 static CURLState
*curl_init_state(BlockDriverState
*bs
, BDRVCURLState
*s
)
396 CURLState
*state
= NULL
;
400 for (i
=0; i
<CURL_NUM_STATES
; i
++) {
401 for (j
=0; j
<CURL_NUM_ACB
; j
++)
402 if (s
->states
[i
].acb
[j
])
404 if (s
->states
[i
].in_use
)
407 state
= &s
->states
[i
];
412 aio_poll(bdrv_get_aio_context(bs
), true);
417 state
->curl
= curl_easy_init();
421 curl_easy_setopt(state
->curl
, CURLOPT_URL
, s
->url
);
422 curl_easy_setopt(state
->curl
, CURLOPT_SSL_VERIFYPEER
,
423 (long) s
->sslverify
);
425 curl_easy_setopt(state
->curl
, CURLOPT_COOKIE
, s
->cookie
);
427 curl_easy_setopt(state
->curl
, CURLOPT_TIMEOUT
, (long)s
->timeout
);
428 curl_easy_setopt(state
->curl
, CURLOPT_WRITEFUNCTION
,
429 (void *)curl_read_cb
);
430 curl_easy_setopt(state
->curl
, CURLOPT_WRITEDATA
, (void *)state
);
431 curl_easy_setopt(state
->curl
, CURLOPT_PRIVATE
, (void *)state
);
432 curl_easy_setopt(state
->curl
, CURLOPT_AUTOREFERER
, 1);
433 curl_easy_setopt(state
->curl
, CURLOPT_FOLLOWLOCATION
, 1);
434 curl_easy_setopt(state
->curl
, CURLOPT_NOSIGNAL
, 1);
435 curl_easy_setopt(state
->curl
, CURLOPT_ERRORBUFFER
, state
->errmsg
);
436 curl_easy_setopt(state
->curl
, CURLOPT_FAILONERROR
, 1);
439 curl_easy_setopt(state
->curl
, CURLOPT_USERNAME
, s
->username
);
442 curl_easy_setopt(state
->curl
, CURLOPT_PASSWORD
, s
->password
);
444 if (s
->proxyusername
) {
445 curl_easy_setopt(state
->curl
,
446 CURLOPT_PROXYUSERNAME
, s
->proxyusername
);
448 if (s
->proxypassword
) {
449 curl_easy_setopt(state
->curl
,
450 CURLOPT_PROXYPASSWORD
, s
->proxypassword
);
453 /* Restrict supported protocols to avoid security issues in the more
454 * obscure protocols. For example, do not allow POP3/SMTP/IMAP see
457 * Restricting protocols is only supported from 7.19.4 upwards.
459 #if LIBCURL_VERSION_NUM >= 0x071304
460 curl_easy_setopt(state
->curl
, CURLOPT_PROTOCOLS
, PROTOCOLS
);
461 curl_easy_setopt(state
->curl
, CURLOPT_REDIR_PROTOCOLS
, PROTOCOLS
);
465 curl_easy_setopt(state
->curl
, CURLOPT_VERBOSE
, 1);
474 static void curl_clean_state(CURLState
*s
)
477 curl_multi_remove_handle(s
->s
->multi
, s
->curl
);
481 static void curl_parse_filename(const char *filename
, QDict
*options
,
484 qdict_put(options
, CURL_BLOCK_OPT_URL
, qstring_from_str(filename
));
487 static void curl_detach_aio_context(BlockDriverState
*bs
)
489 BDRVCURLState
*s
= bs
->opaque
;
492 for (i
= 0; i
< CURL_NUM_STATES
; i
++) {
493 if (s
->states
[i
].in_use
) {
494 curl_clean_state(&s
->states
[i
]);
496 if (s
->states
[i
].curl
) {
497 curl_easy_cleanup(s
->states
[i
].curl
);
498 s
->states
[i
].curl
= NULL
;
500 g_free(s
->states
[i
].orig_buf
);
501 s
->states
[i
].orig_buf
= NULL
;
504 curl_multi_cleanup(s
->multi
);
508 timer_del(&s
->timer
);
511 static void curl_attach_aio_context(BlockDriverState
*bs
,
512 AioContext
*new_context
)
514 BDRVCURLState
*s
= bs
->opaque
;
516 aio_timer_init(new_context
, &s
->timer
,
517 QEMU_CLOCK_REALTIME
, SCALE_NS
,
518 curl_multi_timeout_do
, s
);
521 s
->multi
= curl_multi_init();
522 s
->aio_context
= new_context
;
523 curl_multi_setopt(s
->multi
, CURLMOPT_SOCKETFUNCTION
, curl_sock_cb
);
524 #ifdef NEED_CURL_TIMER_CALLBACK
525 curl_multi_setopt(s
->multi
, CURLMOPT_TIMERDATA
, s
);
526 curl_multi_setopt(s
->multi
, CURLMOPT_TIMERFUNCTION
, curl_timer_cb
);
530 static QemuOptsList runtime_opts
= {
532 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
535 .name
= CURL_BLOCK_OPT_URL
,
536 .type
= QEMU_OPT_STRING
,
537 .help
= "URL to open",
540 .name
= CURL_BLOCK_OPT_READAHEAD
,
541 .type
= QEMU_OPT_SIZE
,
542 .help
= "Readahead size",
545 .name
= CURL_BLOCK_OPT_SSLVERIFY
,
546 .type
= QEMU_OPT_BOOL
,
547 .help
= "Verify SSL certificate"
550 .name
= CURL_BLOCK_OPT_TIMEOUT
,
551 .type
= QEMU_OPT_NUMBER
,
552 .help
= "Curl timeout"
555 .name
= CURL_BLOCK_OPT_COOKIE
,
556 .type
= QEMU_OPT_STRING
,
557 .help
= "Pass the cookie or list of cookies with each request"
560 .name
= CURL_BLOCK_OPT_USERNAME
,
561 .type
= QEMU_OPT_STRING
,
562 .help
= "Username for HTTP auth"
565 .name
= CURL_BLOCK_OPT_PASSWORD_SECRET
,
566 .type
= QEMU_OPT_STRING
,
567 .help
= "ID of secret used as password for HTTP auth",
570 .name
= CURL_BLOCK_OPT_PROXY_USERNAME
,
571 .type
= QEMU_OPT_STRING
,
572 .help
= "Username for HTTP proxy auth"
575 .name
= CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET
,
576 .type
= QEMU_OPT_STRING
,
577 .help
= "ID of secret used as password for HTTP proxy auth",
579 { /* end of list */ }
584 static int curl_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
587 BDRVCURLState
*s
= bs
->opaque
;
588 CURLState
*state
= NULL
;
590 Error
*local_err
= NULL
;
594 const char *secretid
;
596 static int inited
= 0;
598 if (flags
& BDRV_O_RDWR
) {
599 error_setg(errp
, "curl block device does not support writes");
603 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
604 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
606 error_propagate(errp
, local_err
);
610 s
->readahead_size
= qemu_opt_get_size(opts
, CURL_BLOCK_OPT_READAHEAD
,
612 if ((s
->readahead_size
& 0x1ff) != 0) {
613 error_setg(errp
, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512",
618 s
->timeout
= qemu_opt_get_number(opts
, CURL_BLOCK_OPT_TIMEOUT
,
619 CURL_TIMEOUT_DEFAULT
);
620 if (s
->timeout
> CURL_TIMEOUT_MAX
) {
621 error_setg(errp
, "timeout parameter is too large or negative");
625 s
->sslverify
= qemu_opt_get_bool(opts
, CURL_BLOCK_OPT_SSLVERIFY
, true);
627 cookie
= qemu_opt_get(opts
, CURL_BLOCK_OPT_COOKIE
);
628 s
->cookie
= g_strdup(cookie
);
630 file
= qemu_opt_get(opts
, CURL_BLOCK_OPT_URL
);
632 error_setg(errp
, "curl block driver requires an 'url' option");
636 s
->username
= g_strdup(qemu_opt_get(opts
, CURL_BLOCK_OPT_USERNAME
));
637 secretid
= qemu_opt_get(opts
, CURL_BLOCK_OPT_PASSWORD_SECRET
);
640 s
->password
= qcrypto_secret_lookup_as_utf8(secretid
, errp
);
646 s
->proxyusername
= g_strdup(
647 qemu_opt_get(opts
, CURL_BLOCK_OPT_PROXY_USERNAME
));
648 secretid
= qemu_opt_get(opts
, CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET
);
650 s
->proxypassword
= qcrypto_secret_lookup_as_utf8(secretid
, errp
);
651 if (!s
->proxypassword
) {
657 curl_global_init(CURL_GLOBAL_ALL
);
661 DPRINTF("CURL: Opening %s\n", file
);
662 s
->aio_context
= bdrv_get_aio_context(bs
);
663 s
->url
= g_strdup(file
);
664 state
= curl_init_state(bs
, s
);
670 s
->accept_range
= false;
671 curl_easy_setopt(state
->curl
, CURLOPT_NOBODY
, 1);
672 curl_easy_setopt(state
->curl
, CURLOPT_HEADERFUNCTION
,
674 curl_easy_setopt(state
->curl
, CURLOPT_HEADERDATA
, s
);
675 if (curl_easy_perform(state
->curl
))
677 if (curl_easy_getinfo(state
->curl
, CURLINFO_CONTENT_LENGTH_DOWNLOAD
, &d
)) {
680 /* Prior CURL 7.19.4 return value of 0 could mean that the file size is not
681 * know or the size is zero. From 7.19.4 CURL returns -1 if size is not
682 * known and zero if it is realy zero-length file. */
683 #if LIBCURL_VERSION_NUM >= 0x071304
685 pstrcpy(state
->errmsg
, CURL_ERROR_SIZE
,
686 "Server didn't report file size.");
691 pstrcpy(state
->errmsg
, CURL_ERROR_SIZE
,
692 "Unknown file size or zero-length file.");
699 if ((!strncasecmp(s
->url
, "http://", strlen("http://"))
700 || !strncasecmp(s
->url
, "https://", strlen("https://")))
701 && !s
->accept_range
) {
702 pstrcpy(state
->errmsg
, CURL_ERROR_SIZE
,
703 "Server does not support 'range' (byte ranges).");
706 DPRINTF("CURL: Size = %zd\n", s
->len
);
708 curl_clean_state(state
);
709 curl_easy_cleanup(state
->curl
);
712 curl_attach_aio_context(bs
, bdrv_get_aio_context(bs
));
718 error_setg(errp
, "CURL: Error opening file: %s", state
->errmsg
);
719 curl_easy_cleanup(state
->curl
);
728 static const AIOCBInfo curl_aiocb_info
= {
729 .aiocb_size
= sizeof(CURLAIOCB
),
733 static void curl_readv_bh_cb(void *p
)
739 BDRVCURLState
*s
= acb
->common
.bs
->opaque
;
741 size_t start
= acb
->sector_num
* SECTOR_SIZE
;
744 // In case we have the requested data already (e.g. read-ahead),
745 // we can just call the callback and be done.
746 switch (curl_find_buf(s
, start
, acb
->nb_sectors
* SECTOR_SIZE
, acb
)) {
756 // No cache found, so let's start a new request
757 state
= curl_init_state(acb
->common
.bs
, s
);
759 acb
->common
.cb(acb
->common
.opaque
, -EIO
);
765 acb
->end
= (acb
->nb_sectors
* SECTOR_SIZE
);
768 g_free(state
->orig_buf
);
769 state
->buf_start
= start
;
770 state
->buf_len
= acb
->end
+ s
->readahead_size
;
771 end
= MIN(start
+ state
->buf_len
, s
->len
) - 1;
772 state
->orig_buf
= g_try_malloc(state
->buf_len
);
773 if (state
->buf_len
&& state
->orig_buf
== NULL
) {
774 curl_clean_state(state
);
775 acb
->common
.cb(acb
->common
.opaque
, -ENOMEM
);
781 snprintf(state
->range
, 127, "%zd-%zd", start
, end
);
782 DPRINTF("CURL (AIO): Reading %d at %zd (%s)\n",
783 (acb
->nb_sectors
* SECTOR_SIZE
), start
, state
->range
);
784 curl_easy_setopt(state
->curl
, CURLOPT_RANGE
, state
->range
);
786 curl_multi_add_handle(s
->multi
, state
->curl
);
788 /* Tell curl it needs to kick things off */
789 curl_multi_socket_action(s
->multi
, CURL_SOCKET_TIMEOUT
, 0, &running
);
792 static BlockAIOCB
*curl_aio_readv(BlockDriverState
*bs
,
793 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
794 BlockCompletionFunc
*cb
, void *opaque
)
798 acb
= qemu_aio_get(&curl_aiocb_info
, bs
, cb
, opaque
);
801 acb
->sector_num
= sector_num
;
802 acb
->nb_sectors
= nb_sectors
;
804 aio_bh_schedule_oneshot(bdrv_get_aio_context(bs
), curl_readv_bh_cb
, acb
);
808 static void curl_close(BlockDriverState
*bs
)
810 BDRVCURLState
*s
= bs
->opaque
;
812 DPRINTF("CURL: Close\n");
813 curl_detach_aio_context(bs
);
819 static int64_t curl_getlength(BlockDriverState
*bs
)
821 BDRVCURLState
*s
= bs
->opaque
;
825 static BlockDriver bdrv_http
= {
826 .format_name
= "http",
827 .protocol_name
= "http",
829 .instance_size
= sizeof(BDRVCURLState
),
830 .bdrv_parse_filename
= curl_parse_filename
,
831 .bdrv_file_open
= curl_open
,
832 .bdrv_close
= curl_close
,
833 .bdrv_getlength
= curl_getlength
,
835 .bdrv_aio_readv
= curl_aio_readv
,
837 .bdrv_detach_aio_context
= curl_detach_aio_context
,
838 .bdrv_attach_aio_context
= curl_attach_aio_context
,
841 static BlockDriver bdrv_https
= {
842 .format_name
= "https",
843 .protocol_name
= "https",
845 .instance_size
= sizeof(BDRVCURLState
),
846 .bdrv_parse_filename
= curl_parse_filename
,
847 .bdrv_file_open
= curl_open
,
848 .bdrv_close
= curl_close
,
849 .bdrv_getlength
= curl_getlength
,
851 .bdrv_aio_readv
= curl_aio_readv
,
853 .bdrv_detach_aio_context
= curl_detach_aio_context
,
854 .bdrv_attach_aio_context
= curl_attach_aio_context
,
857 static BlockDriver bdrv_ftp
= {
858 .format_name
= "ftp",
859 .protocol_name
= "ftp",
861 .instance_size
= sizeof(BDRVCURLState
),
862 .bdrv_parse_filename
= curl_parse_filename
,
863 .bdrv_file_open
= curl_open
,
864 .bdrv_close
= curl_close
,
865 .bdrv_getlength
= curl_getlength
,
867 .bdrv_aio_readv
= curl_aio_readv
,
869 .bdrv_detach_aio_context
= curl_detach_aio_context
,
870 .bdrv_attach_aio_context
= curl_attach_aio_context
,
873 static BlockDriver bdrv_ftps
= {
874 .format_name
= "ftps",
875 .protocol_name
= "ftps",
877 .instance_size
= sizeof(BDRVCURLState
),
878 .bdrv_parse_filename
= curl_parse_filename
,
879 .bdrv_file_open
= curl_open
,
880 .bdrv_close
= curl_close
,
881 .bdrv_getlength
= curl_getlength
,
883 .bdrv_aio_readv
= curl_aio_readv
,
885 .bdrv_detach_aio_context
= curl_detach_aio_context
,
886 .bdrv_attach_aio_context
= curl_attach_aio_context
,
889 static BlockDriver bdrv_tftp
= {
890 .format_name
= "tftp",
891 .protocol_name
= "tftp",
893 .instance_size
= sizeof(BDRVCURLState
),
894 .bdrv_parse_filename
= curl_parse_filename
,
895 .bdrv_file_open
= curl_open
,
896 .bdrv_close
= curl_close
,
897 .bdrv_getlength
= curl_getlength
,
899 .bdrv_aio_readv
= curl_aio_readv
,
901 .bdrv_detach_aio_context
= curl_detach_aio_context
,
902 .bdrv_attach_aio_context
= curl_attach_aio_context
,
905 static void curl_block_init(void)
907 bdrv_register(&bdrv_http
);
908 bdrv_register(&bdrv_https
);
909 bdrv_register(&bdrv_ftp
);
910 bdrv_register(&bdrv_ftps
);
911 bdrv_register(&bdrv_tftp
);
914 block_init(curl_block_init
);