16
16
17
17
#include "qemu-io.h"
18
18
#include "qemu/main-loop.h"
19
+ #include "qemu/option.h"
20
+ #include "qemu/config-file.h"
19
21
#include "block/block_int.h"
20
22
#include "trace/control.h"
21
23
@@ -44,7 +46,7 @@ static const cmdinfo_t close_cmd = {
44
46
.oneline = "close the current open file" ,
45
47
};
46
48
47
- static int openfile (char * name , int flags , int growable )
49
+ static int openfile (char * name , int flags , int growable , QDict * opts )
48
50
{
49
51
Error * local_err = NULL ;
50
52
@@ -54,7 +56,7 @@ static int openfile(char *name, int flags, int growable)
54
56
}
55
57
56
58
if (growable ) {
57
- if (bdrv_file_open (& qemuio_bs , name , NULL , flags , & local_err )) {
59
+ if (bdrv_file_open (& qemuio_bs , name , opts , flags , & local_err )) {
58
60
fprintf (stderr , "%s: can't open device %s: %s\n" , progname , name ,
59
61
error_get_pretty (local_err ));
60
62
error_free (local_err );
@@ -63,7 +65,7 @@ static int openfile(char *name, int flags, int growable)
63
65
} else {
64
66
qemuio_bs = bdrv_new ("hda" );
65
67
66
- if (bdrv_open (qemuio_bs , name , NULL , flags , NULL , & local_err ) < 0 ) {
68
+ if (bdrv_open (qemuio_bs , name , opts , flags , NULL , & local_err ) < 0 ) {
67
69
fprintf (stderr , "%s: can't open device %s: %s\n" , progname , name ,
68
70
error_get_pretty (local_err ));
69
71
error_free (local_err );
@@ -89,7 +91,8 @@ static void open_help(void)
89
91
" -r, -- open file read-only\n"
90
92
" -s, -- use snapshot file\n"
91
93
" -n, -- disable host cache\n"
92
- " -g, -- allow file to grow (only applies to protocols)"
94
+ " -g, -- allow file to grow (only applies to protocols)\n"
95
+ " -o, -- options to be given to the block driver"
93
96
"\n" );
94
97
}
95
98
@@ -102,19 +105,30 @@ static const cmdinfo_t open_cmd = {
102
105
.argmin = 1 ,
103
106
.argmax = -1 ,
104
107
.flags = CMD_NOFILE_OK ,
105
- .args = "[-Crsn] [path]" ,
108
+ .args = "[-Crsn] [-o options] [ path]" ,
106
109
.oneline = "open the file specified by path" ,
107
110
.help = open_help ,
108
111
};
109
112
113
+ static QemuOptsList empty_opts = {
114
+ .name = "drive" ,
115
+ .head = QTAILQ_HEAD_INITIALIZER (empty_opts .head ),
116
+ .desc = {
117
+ /* no elements => accept any params */
118
+ { /* end of list */ }
119
+ },
120
+ };
121
+
110
122
static int open_f (BlockDriverState * bs , int argc , char * * argv )
111
123
{
112
124
int flags = 0 ;
113
125
int readonly = 0 ;
114
126
int growable = 0 ;
115
127
int c ;
128
+ QemuOpts * qopts ;
129
+ QDict * opts = NULL ;
116
130
117
- while ((c = getopt (argc , argv , "snrg " )) != EOF ) {
131
+ while ((c = getopt (argc , argv , "snrgo: " )) != EOF ) {
118
132
switch (c ) {
119
133
case 's' :
120
134
flags |= BDRV_O_SNAPSHOT ;
@@ -128,6 +142,15 @@ static int open_f(BlockDriverState *bs, int argc, char **argv)
128
142
case 'g' :
129
143
growable = 1 ;
130
144
break ;
145
+ case 'o' :
146
+ qopts = qemu_opts_parse (& empty_opts , optarg , 0 );
147
+ if (qopts == NULL ) {
148
+ printf ("could not parse option list -- %s\n" , optarg );
149
+ return 0 ;
150
+ }
151
+ opts = qemu_opts_to_qdict (qopts , opts );
152
+ qemu_opts_del (qopts );
153
+ break ;
131
154
default :
132
155
return qemuio_command_usage (& open_cmd );
133
156
}
@@ -141,7 +164,7 @@ static int open_f(BlockDriverState *bs, int argc, char **argv)
141
164
return qemuio_command_usage (& open_cmd );
142
165
}
143
166
144
- return openfile (argv [optind ], flags , growable );
167
+ return openfile (argv [optind ], flags , growable , opts );
145
168
}
146
169
147
170
static int quit_f (BlockDriverState * bs , int argc , char * * argv )
@@ -418,7 +441,7 @@ int main(int argc, char **argv)
418
441
}
419
442
420
443
if ((argc - optind ) == 1 ) {
421
- openfile (argv [optind ], flags , growable );
444
+ openfile (argv [optind ], flags , growable , NULL );
422
445
}
423
446
command_loop ();
424
447
0 commit comments