提交 787e4a85 编写于 作者: K Kevin Wolf

block: Add options QDict to bdrv_file_open() prototypes

The new parameter is unused yet.
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
上级 92b7a08d
...@@ -708,7 +708,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, ...@@ -708,7 +708,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
bdrv_swap(file, bs); bdrv_swap(file, bs);
ret = 0; ret = 0;
} else { } else {
ret = drv->bdrv_file_open(bs, filename, open_flags); ret = drv->bdrv_file_open(bs, filename, options, open_flags);
} }
} else { } else {
assert(file != NULL); assert(file != NULL);
...@@ -742,13 +742,21 @@ free_and_fail: ...@@ -742,13 +742,21 @@ free_and_fail:
/* /*
* Opens a file using a protocol (file, host_device, nbd, ...) * Opens a file using a protocol (file, host_device, nbd, ...)
*
* options is a QDict of options to pass to the block drivers, or NULL for an
* empty set of options. The reference to the QDict belongs to the block layer
* after the call (even on failure), so if the caller intends to reuse the
* dictionary, it needs to use QINCREF() before calling bdrv_file_open.
*/ */
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags) int bdrv_file_open(BlockDriverState **pbs, const char *filename,
QDict *options, int flags)
{ {
BlockDriverState *bs; BlockDriverState *bs;
BlockDriver *drv; BlockDriver *drv;
int ret; int ret;
QDECREF(options);
drv = bdrv_find_protocol(filename); drv = bdrv_find_protocol(filename);
if (!drv) { if (!drv) {
return -ENOENT; return -ENOENT;
...@@ -888,7 +896,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, ...@@ -888,7 +896,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
flags |= BDRV_O_ALLOW_RDWR; flags |= BDRV_O_ALLOW_RDWR;
} }
ret = bdrv_file_open(&file, filename, bdrv_open_flags(bs, flags)); ret = bdrv_file_open(&file, filename, NULL, bdrv_open_flags(bs, flags));
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
......
...@@ -304,7 +304,8 @@ fail: ...@@ -304,7 +304,8 @@ fail:
} }
/* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */ /* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */
static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags) static int blkdebug_open(BlockDriverState *bs, const char *filename,
QDict *options, int flags)
{ {
BDRVBlkdebugState *s = bs->opaque; BDRVBlkdebugState *s = bs->opaque;
int ret; int ret;
...@@ -335,7 +336,7 @@ static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags) ...@@ -335,7 +336,7 @@ static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags)
s->state = 1; s->state = 1;
/* Open the backing file */ /* Open the backing file */
ret = bdrv_file_open(&bs->file, filename, flags); ret = bdrv_file_open(&bs->file, filename, NULL, flags);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
......
...@@ -69,7 +69,8 @@ static void GCC_FMT_ATTR(2, 3) blkverify_err(BlkverifyAIOCB *acb, ...@@ -69,7 +69,8 @@ static void GCC_FMT_ATTR(2, 3) blkverify_err(BlkverifyAIOCB *acb,
} }
/* Valid blkverify filenames look like blkverify:path/to/raw_image:path/to/image */ /* Valid blkverify filenames look like blkverify:path/to/raw_image:path/to/image */
static int blkverify_open(BlockDriverState *bs, const char *filename, int flags) static int blkverify_open(BlockDriverState *bs, const char *filename,
QDict *options, int flags)
{ {
BDRVBlkverifyState *s = bs->opaque; BDRVBlkverifyState *s = bs->opaque;
int ret; int ret;
...@@ -89,7 +90,7 @@ static int blkverify_open(BlockDriverState *bs, const char *filename, int flags) ...@@ -89,7 +90,7 @@ static int blkverify_open(BlockDriverState *bs, const char *filename, int flags)
raw = g_strdup(filename); raw = g_strdup(filename);
raw[c - filename] = '\0'; raw[c - filename] = '\0';
ret = bdrv_file_open(&bs->file, raw, flags); ret = bdrv_file_open(&bs->file, raw, NULL, flags);
g_free(raw); g_free(raw);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
......
...@@ -279,7 +279,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options) ...@@ -279,7 +279,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options)
return ret; return ret;
} }
ret = bdrv_file_open(&cow_bs, filename, BDRV_O_RDWR); ret = bdrv_file_open(&cow_bs, filename, NULL, BDRV_O_RDWR);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
......
...@@ -335,7 +335,8 @@ static void curl_clean_state(CURLState *s) ...@@ -335,7 +335,8 @@ static void curl_clean_state(CURLState *s)
s->in_use = 0; s->in_use = 0;
} }
static int curl_open(BlockDriverState *bs, const char *filename, int flags) static int curl_open(BlockDriverState *bs, const char *filename,
QDict *options, int flags)
{ {
BDRVCURLState *s = bs->opaque; BDRVCURLState *s = bs->opaque;
CURLState *state = NULL; CURLState *state = NULL;
......
...@@ -283,7 +283,7 @@ static int qemu_gluster_aio_flush_cb(void *opaque) ...@@ -283,7 +283,7 @@ static int qemu_gluster_aio_flush_cb(void *opaque)
} }
static int qemu_gluster_open(BlockDriverState *bs, const char *filename, static int qemu_gluster_open(BlockDriverState *bs, const char *filename,
int bdrv_flags) QDict *options, int bdrv_flags)
{ {
BDRVGlusterState *s = bs->opaque; BDRVGlusterState *s = bs->opaque;
int open_flags = O_BINARY; int open_flags = O_BINARY;
......
...@@ -1007,7 +1007,8 @@ out: ...@@ -1007,7 +1007,8 @@ out:
* We support iscsi url's on the form * We support iscsi url's on the form
* iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun> * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
*/ */
static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) static int iscsi_open(BlockDriverState *bs, const char *filename,
QDict *options, int flags)
{ {
IscsiLun *iscsilun = bs->opaque; IscsiLun *iscsilun = bs->opaque;
struct iscsi_context *iscsi = NULL; struct iscsi_context *iscsi = NULL;
...@@ -1203,7 +1204,7 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options) ...@@ -1203,7 +1204,7 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options)
bs.opaque = g_malloc0(sizeof(struct IscsiLun)); bs.opaque = g_malloc0(sizeof(struct IscsiLun));
iscsilun = bs.opaque; iscsilun = bs.opaque;
ret = iscsi_open(&bs, filename, 0); ret = iscsi_open(&bs, filename, NULL, 0);
if (ret != 0) { if (ret != 0) {
goto out; goto out;
} }
......
...@@ -376,7 +376,8 @@ static void nbd_teardown_connection(BlockDriverState *bs) ...@@ -376,7 +376,8 @@ static void nbd_teardown_connection(BlockDriverState *bs)
closesocket(s->sock); closesocket(s->sock);
} }
static int nbd_open(BlockDriverState *bs, const char* filename, int flags) static int nbd_open(BlockDriverState *bs, const char* filename,
QDict *options, int flags)
{ {
BDRVNBDState *s = bs->opaque; BDRVNBDState *s = bs->opaque;
int result; int result;
......
...@@ -679,7 +679,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options) ...@@ -679,7 +679,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options)
return ret; return ret;
} }
ret = bdrv_file_open(&qcow_bs, filename, BDRV_O_RDWR); ret = bdrv_file_open(&qcow_bs, filename, NULL, BDRV_O_RDWR);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
......
...@@ -1254,7 +1254,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, ...@@ -1254,7 +1254,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
return ret; return ret;
} }
ret = bdrv_file_open(&bs, filename, BDRV_O_RDWR); ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
......
...@@ -558,7 +558,7 @@ static int qed_create(const char *filename, uint32_t cluster_size, ...@@ -558,7 +558,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
return ret; return ret;
} }
ret = bdrv_file_open(&bs, filename, BDRV_O_RDWR | BDRV_O_CACHE_WB); ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
......
...@@ -303,7 +303,8 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, ...@@ -303,7 +303,8 @@ static int raw_open_common(BlockDriverState *bs, const char *filename,
return 0; return 0;
} }
static int raw_open(BlockDriverState *bs, const char *filename, int flags) static int raw_open(BlockDriverState *bs, const char *filename,
QDict *options, int flags)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
...@@ -1292,7 +1293,8 @@ static int check_hdev_writable(BDRVRawState *s) ...@@ -1292,7 +1293,8 @@ static int check_hdev_writable(BDRVRawState *s)
return 0; return 0;
} }
static int hdev_open(BlockDriverState *bs, const char *filename, int flags) static int hdev_open(BlockDriverState *bs, const char *filename,
QDict *options, int flags)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
int ret; int ret;
...@@ -1530,7 +1532,8 @@ static BlockDriver bdrv_host_device = { ...@@ -1530,7 +1532,8 @@ static BlockDriver bdrv_host_device = {
}; };
#ifdef __linux__ #ifdef __linux__
static int floppy_open(BlockDriverState *bs, const char *filename, int flags) static int floppy_open(BlockDriverState *bs, const char *filename,
QDict *options, int flags)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
int ret; int ret;
...@@ -1652,7 +1655,8 @@ static BlockDriver bdrv_host_floppy = { ...@@ -1652,7 +1655,8 @@ static BlockDriver bdrv_host_floppy = {
.bdrv_eject = floppy_eject, .bdrv_eject = floppy_eject,
}; };
static int cdrom_open(BlockDriverState *bs, const char *filename, int flags) static int cdrom_open(BlockDriverState *bs, const char *filename,
QDict *options, int flags)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
...@@ -1760,7 +1764,8 @@ static BlockDriver bdrv_host_cdrom = { ...@@ -1760,7 +1764,8 @@ static BlockDriver bdrv_host_cdrom = {
#endif /* __linux__ */ #endif /* __linux__ */
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
static int cdrom_open(BlockDriverState *bs, const char *filename, int flags) static int cdrom_open(BlockDriverState *bs, const char *filename,
QDict *options, int flags)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
int ret; int ret;
......
...@@ -1126,7 +1126,8 @@ static int write_object(int fd, char *buf, uint64_t oid, int copies, ...@@ -1126,7 +1126,8 @@ static int write_object(int fd, char *buf, uint64_t oid, int copies,
create, cache_flags); create, cache_flags);
} }
static int sd_open(BlockDriverState *bs, const char *filename, int flags) static int sd_open(BlockDriverState *bs, const char *filename,
QDict *options, int flags)
{ {
int ret, fd; int ret, fd;
uint32_t vid = 0; uint32_t vid = 0;
...@@ -1269,7 +1270,7 @@ static int sd_prealloc(const char *filename) ...@@ -1269,7 +1270,7 @@ static int sd_prealloc(const char *filename)
void *buf = g_malloc0(SD_DATA_OBJ_SIZE); void *buf = g_malloc0(SD_DATA_OBJ_SIZE);
int ret; int ret;
ret = bdrv_file_open(&bs, filename, BDRV_O_RDWR); ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }
...@@ -1367,7 +1368,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options) ...@@ -1367,7 +1368,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options)
goto out; goto out;
} }
ret = bdrv_file_open(&bs, backing_file, 0); ret = bdrv_file_open(&bs, backing_file, NULL, 0);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }
......
...@@ -661,7 +661,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, ...@@ -661,7 +661,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
path_combine(extent_path, sizeof(extent_path), path_combine(extent_path, sizeof(extent_path),
desc_file_path, fname); desc_file_path, fname);
ret = bdrv_file_open(&extent_file, extent_path, bs->open_flags); ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags);
if (ret) { if (ret) {
return ret; return ret;
} }
......
...@@ -988,7 +988,8 @@ static void vvfat_rebind(BlockDriverState *bs) ...@@ -988,7 +988,8 @@ static void vvfat_rebind(BlockDriverState *bs)
s->bs = bs; s->bs = bs;
} }
static int vvfat_open(BlockDriverState *bs, const char* dirname, int flags) static int vvfat_open(BlockDriverState *bs, const char* dirname,
QDict *options, int flags)
{ {
BDRVVVFATState *s = bs->opaque; BDRVVVFATState *s = bs->opaque;
int i, cyls, heads, secs; int i, cyls, heads, secs;
......
...@@ -135,7 +135,8 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top); ...@@ -135,7 +135,8 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
void bdrv_delete(BlockDriverState *bs); void bdrv_delete(BlockDriverState *bs);
int bdrv_parse_cache_flags(const char *mode, int *flags); int bdrv_parse_cache_flags(const char *mode, int *flags);
int bdrv_parse_discard_flags(const char *mode, int *flags); int bdrv_parse_discard_flags(const char *mode, int *flags);
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags); int bdrv_file_open(BlockDriverState **pbs, const char *filename,
QDict *options, int flags);
int bdrv_open_backing_file(BlockDriverState *bs); int bdrv_open_backing_file(BlockDriverState *bs);
int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
int flags, BlockDriver *drv); int flags, BlockDriver *drv);
......
...@@ -83,7 +83,8 @@ struct BlockDriver { ...@@ -83,7 +83,8 @@ struct BlockDriver {
void (*bdrv_reopen_abort)(BDRVReopenState *reopen_state); void (*bdrv_reopen_abort)(BDRVReopenState *reopen_state);
int (*bdrv_open)(BlockDriverState *bs, QDict *options, int flags); int (*bdrv_open)(BlockDriverState *bs, QDict *options, int flags);
int (*bdrv_file_open)(BlockDriverState *bs, const char *filename, int flags); int (*bdrv_file_open)(BlockDriverState *bs, const char *filename,
QDict *options, int flags);
int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num, int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors); uint8_t *buf, int nb_sectors);
int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num, int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
......
...@@ -1766,7 +1766,7 @@ static int openfile(char *name, int flags, int growable) ...@@ -1766,7 +1766,7 @@ static int openfile(char *name, int flags, int growable)
} }
if (growable) { if (growable) {
if (bdrv_file_open(&bs, name, flags)) { if (bdrv_file_open(&bs, name, NULL, flags)) {
fprintf(stderr, "%s: can't open device %s\n", progname, name); fprintf(stderr, "%s: can't open device %s\n", progname, name);
return 1; return 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册