curl.c (9aedd5a5d607216e41bfa6a2c1f7f5d2b17041c3) | curl.c (e3542c67af4cb4fd90e3be912630be9acd97b9c0) |
---|---|
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 --- 47 unchanged lines hidden (view full) --- 56 57#define PROTOCOLS (CURLPROTO_HTTP | CURLPROTO_HTTPS | \ 58 CURLPROTO_FTP | CURLPROTO_FTPS | \ 59 CURLPROTO_TFTP) 60 61#define CURL_NUM_STATES 8 62#define CURL_NUM_ACB 8 63#define SECTOR_SIZE 512 | 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 --- 47 unchanged lines hidden (view full) --- 56 57#define PROTOCOLS (CURLPROTO_HTTP | CURLPROTO_HTTPS | \ 58 CURLPROTO_FTP | CURLPROTO_FTPS | \ 59 CURLPROTO_TFTP) 60 61#define CURL_NUM_STATES 8 62#define CURL_NUM_ACB 8 63#define SECTOR_SIZE 512 |
64#define READ_AHEAD_SIZE (256 * 1024) | 64#define READ_AHEAD_DEFAULT (256 * 1024) |
65 66#define FIND_RET_NONE 0 67#define FIND_RET_OK 1 68#define FIND_RET_WAIT 2 69 | 65 66#define FIND_RET_NONE 0 67#define FIND_RET_OK 1 68#define FIND_RET_WAIT 2 69 |
70#define CURL_BLOCK_OPT_URL "url" 71#define CURL_BLOCK_OPT_READAHEAD "readahead" 72 |
|
70struct BDRVCURLState; 71 72typedef struct CURLAIOCB { 73 BlockDriverAIOCB common; 74 QEMUBH *bh; 75 QEMUIOVector *qiov; 76 77 int64_t sector_num; --- 328 unchanged lines hidden (view full) --- 406 if (s->s->multi) 407 curl_multi_remove_handle(s->s->multi, s->curl); 408 s->in_use = 0; 409} 410 411static void curl_parse_filename(const char *filename, QDict *options, 412 Error **errp) 413{ | 73struct BDRVCURLState; 74 75typedef struct CURLAIOCB { 76 BlockDriverAIOCB common; 77 QEMUBH *bh; 78 QEMUIOVector *qiov; 79 80 int64_t sector_num; --- 328 unchanged lines hidden (view full) --- 409 if (s->s->multi) 410 curl_multi_remove_handle(s->s->multi, s->curl); 411 s->in_use = 0; 412} 413 414static void curl_parse_filename(const char *filename, QDict *options, 415 Error **errp) 416{ |
414 415 #define RA_OPTSTR ":readahead=" 416 char *file; 417 char *ra; 418 const char *ra_val; 419 int parse_state = 0; 420 421 file = g_strdup(filename); 422 423 /* Parse a trailing ":readahead=#:" param, if present. */ 424 ra = file + strlen(file) - 1; 425 while (ra >= file) { 426 if (parse_state == 0) { 427 if (*ra == ':') { 428 parse_state++; 429 } else { 430 break; 431 } 432 } else if (parse_state == 1) { 433 if (*ra > '9' || *ra < '0') { 434 char *opt_start = ra - strlen(RA_OPTSTR) + 1; 435 if (opt_start > file && 436 strncmp(opt_start, RA_OPTSTR, strlen(RA_OPTSTR)) == 0) { 437 ra_val = ra + 1; 438 ra -= strlen(RA_OPTSTR) - 1; 439 *ra = '\0'; 440 qdict_put(options, "readahead", qstring_from_str(ra_val)); 441 } 442 break; 443 } 444 } 445 ra--; 446 } 447 448 qdict_put(options, "url", qstring_from_str(file)); 449 450 g_free(file); | 417 qdict_put(options, CURL_BLOCK_OPT_URL, qstring_from_str(filename)); |
451} 452 453static QemuOptsList runtime_opts = { 454 .name = "curl", 455 .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), 456 .desc = { 457 { | 418} 419 420static QemuOptsList runtime_opts = { 421 .name = "curl", 422 .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), 423 .desc = { 424 { |
458 .name = "url", | 425 .name = CURL_BLOCK_OPT_URL, |
459 .type = QEMU_OPT_STRING, 460 .help = "URL to open", 461 }, 462 { | 426 .type = QEMU_OPT_STRING, 427 .help = "URL to open", 428 }, 429 { |
463 .name = "readahead", | 430 .name = CURL_BLOCK_OPT_READAHEAD, |
464 .type = QEMU_OPT_SIZE, 465 .help = "Readahead size", 466 }, 467 { /* end of list */ } 468 }, 469}; 470 471static int curl_open(BlockDriverState *bs, QDict *options, int flags, --- 15 unchanged lines hidden (view full) --- 487 488 opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); 489 qemu_opts_absorb_qdict(opts, options, &local_err); 490 if (local_err) { 491 error_propagate(errp, local_err); 492 goto out_noclean; 493 } 494 | 431 .type = QEMU_OPT_SIZE, 432 .help = "Readahead size", 433 }, 434 { /* end of list */ } 435 }, 436}; 437 438static int curl_open(BlockDriverState *bs, QDict *options, int flags, --- 15 unchanged lines hidden (view full) --- 454 455 opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); 456 qemu_opts_absorb_qdict(opts, options, &local_err); 457 if (local_err) { 458 error_propagate(errp, local_err); 459 goto out_noclean; 460 } 461 |
495 s->readahead_size = qemu_opt_get_size(opts, "readahead", READ_AHEAD_SIZE); | 462 s->readahead_size = qemu_opt_get_size(opts, CURL_BLOCK_OPT_READAHEAD, 463 READ_AHEAD_DEFAULT); |
496 if ((s->readahead_size & 0x1ff) != 0) { 497 error_setg(errp, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512", 498 s->readahead_size); 499 goto out_noclean; 500 } 501 | 464 if ((s->readahead_size & 0x1ff) != 0) { 465 error_setg(errp, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512", 466 s->readahead_size); 467 goto out_noclean; 468 } 469 |
502 file = qemu_opt_get(opts, "url"); | 470 file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL); |
503 if (file == NULL) { 504 error_setg(errp, "curl block driver requires an 'url' option"); 505 goto out_noclean; 506 } 507 508 if (!inited) { 509 curl_global_init(CURL_GLOBAL_ALL); 510 inited = 1; --- 254 unchanged lines hidden --- | 471 if (file == NULL) { 472 error_setg(errp, "curl block driver requires an 'url' option"); 473 goto out_noclean; 474 } 475 476 if (!inited) { 477 curl_global_init(CURL_GLOBAL_ALL); 478 inited = 1; --- 254 unchanged lines hidden --- |