Revision d15e5465 block.c
b/block.c | ||
---|---|---|
26 | 26 |
#include "monitor.h" |
27 | 27 |
#include "block_int.h" |
28 | 28 |
#include "module.h" |
29 |
#include "qemu-objects.h" |
|
29 | 30 |
|
30 | 31 |
#ifdef CONFIG_BSD |
31 | 32 |
#include <sys/types.h> |
... | ... | |
1139 | 1140 |
return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum); |
1140 | 1141 |
} |
1141 | 1142 |
|
1142 |
void bdrv_info(Monitor *mon)
|
|
1143 |
static void bdrv_print_dict(QObject *obj, void *opaque)
|
|
1143 | 1144 |
{ |
1145 |
QDict *bs_dict; |
|
1146 |
Monitor *mon = opaque; |
|
1147 |
|
|
1148 |
bs_dict = qobject_to_qdict(obj); |
|
1149 |
|
|
1150 |
monitor_printf(mon, "%s: type=%s removable=%d", |
|
1151 |
qdict_get_str(bs_dict, "device"), |
|
1152 |
qdict_get_str(bs_dict, "type"), |
|
1153 |
qdict_get_bool(bs_dict, "removable")); |
|
1154 |
|
|
1155 |
if (qdict_get_bool(bs_dict, "removable")) { |
|
1156 |
monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, "locked")); |
|
1157 |
} |
|
1158 |
|
|
1159 |
if (qdict_haskey(bs_dict, "inserted")) { |
|
1160 |
QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted")); |
|
1161 |
|
|
1162 |
monitor_printf(mon, " file="); |
|
1163 |
monitor_print_filename(mon, qdict_get_str(qdict, "file")); |
|
1164 |
if (qdict_haskey(qdict, "backing_file")) { |
|
1165 |
monitor_printf(mon, " backing_file="); |
|
1166 |
monitor_print_filename(mon, qdict_get_str(qdict, "backing_file")); |
|
1167 |
} |
|
1168 |
monitor_printf(mon, " ro=%d drv=%s encrypted=%d", |
|
1169 |
qdict_get_bool(qdict, "ro"), |
|
1170 |
qdict_get_str(qdict, "drv"), |
|
1171 |
qdict_get_bool(qdict, "encrypted")); |
|
1172 |
} else { |
|
1173 |
monitor_printf(mon, " [not inserted]"); |
|
1174 |
} |
|
1175 |
|
|
1176 |
monitor_printf(mon, "\n"); |
|
1177 |
} |
|
1178 |
|
|
1179 |
void bdrv_info_print(Monitor *mon, const QObject *data) |
|
1180 |
{ |
|
1181 |
qlist_iter(qobject_to_qlist(data), bdrv_print_dict, mon); |
|
1182 |
} |
|
1183 |
|
|
1184 |
/** |
|
1185 |
* bdrv_info(): Block devices information |
|
1186 |
* |
|
1187 |
* Each block device information is stored in a QDict and the |
|
1188 |
* returned QObject is a QList of all devices. |
|
1189 |
* |
|
1190 |
* The QDict contains the following: |
|
1191 |
* |
|
1192 |
* - "device": device name |
|
1193 |
* - "type": device type |
|
1194 |
* - "removable": true if the device is removable, false otherwise |
|
1195 |
* - "locked": true if the device is locked, false otherwise |
|
1196 |
* - "inserted": only present if the device is inserted, it is a QDict |
|
1197 |
* containing the following: |
|
1198 |
* - "file": device file name |
|
1199 |
* - "ro": true if read-only, false otherwise |
|
1200 |
* - "drv": driver format name |
|
1201 |
* - "backing_file": backing file name if one is used |
|
1202 |
* - "encrypted": true if encrypted, false otherwise |
|
1203 |
* |
|
1204 |
* Example: |
|
1205 |
* |
|
1206 |
* [ { "device": "ide0-hd0", "type": "hd", "removable": false, "locked": false, |
|
1207 |
* "inserted": { "file": "/tmp/foobar", "ro": false, "drv": "qcow2" } }, |
|
1208 |
* { "device": "floppy0", "type": "floppy", "removable": true, |
|
1209 |
* "locked": false } ] |
|
1210 |
*/ |
|
1211 |
void bdrv_info(Monitor *mon, QObject **ret_data) |
|
1212 |
{ |
|
1213 |
QList *bs_list; |
|
1144 | 1214 |
BlockDriverState *bs; |
1145 | 1215 |
|
1216 |
bs_list = qlist_new(); |
|
1217 |
|
|
1146 | 1218 |
for (bs = bdrv_first; bs != NULL; bs = bs->next) { |
1147 |
monitor_printf(mon, "%s:", bs->device_name); |
|
1148 |
monitor_printf(mon, " type="); |
|
1219 |
QObject *bs_obj; |
|
1220 |
const char *type = "unknown"; |
|
1221 |
|
|
1149 | 1222 |
switch(bs->type) { |
1150 | 1223 |
case BDRV_TYPE_HD: |
1151 |
monitor_printf(mon, "hd");
|
|
1224 |
type = "hd";
|
|
1152 | 1225 |
break; |
1153 | 1226 |
case BDRV_TYPE_CDROM: |
1154 |
monitor_printf(mon, "cdrom");
|
|
1227 |
type = "cdrom";
|
|
1155 | 1228 |
break; |
1156 | 1229 |
case BDRV_TYPE_FLOPPY: |
1157 |
monitor_printf(mon, "floppy");
|
|
1230 |
type = "floppy";
|
|
1158 | 1231 |
break; |
1159 | 1232 |
} |
1160 |
monitor_printf(mon, " removable=%d", bs->removable); |
|
1161 |
if (bs->removable) { |
|
1162 |
monitor_printf(mon, " locked=%d", bs->locked); |
|
1163 |
} |
|
1233 |
|
|
1234 |
bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': %s, " |
|
1235 |
"'removable': %i, 'locked': %i }", |
|
1236 |
bs->device_name, type, bs->removable, |
|
1237 |
bs->locked); |
|
1238 |
assert(bs_obj != NULL); |
|
1239 |
|
|
1164 | 1240 |
if (bs->drv) { |
1165 |
monitor_printf(mon, " file="); |
|
1166 |
monitor_print_filename(mon, bs->filename); |
|
1241 |
QObject *obj; |
|
1242 |
QDict *bs_dict = qobject_to_qdict(bs_obj); |
|
1243 |
|
|
1244 |
obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, " |
|
1245 |
"'encrypted': %i }", |
|
1246 |
bs->filename, bs->read_only, |
|
1247 |
bs->drv->format_name, |
|
1248 |
bdrv_is_encrypted(bs)); |
|
1249 |
assert(obj != NULL); |
|
1167 | 1250 |
if (bs->backing_file[0] != '\0') { |
1168 |
monitor_printf(mon, " backing_file="); |
|
1169 |
monitor_print_filename(mon, bs->backing_file); |
|
1251 |
QDict *qdict = qobject_to_qdict(obj); |
|
1252 |
qdict_put(qdict, "backing_file", |
|
1253 |
qstring_from_str(bs->backing_file)); |
|
1170 | 1254 |
} |
1171 |
monitor_printf(mon, " ro=%d", bs->read_only); |
|
1172 |
monitor_printf(mon, " drv=%s", bs->drv->format_name); |
|
1173 |
monitor_printf(mon, " encrypted=%d", bdrv_is_encrypted(bs)); |
|
1174 |
} else { |
|
1175 |
monitor_printf(mon, " [not inserted]"); |
|
1255 |
|
|
1256 |
qdict_put_obj(bs_dict, "inserted", obj); |
|
1176 | 1257 |
} |
1177 |
monitor_printf(mon, "\n");
|
|
1258 |
qlist_append_obj(bs_list, bs_obj);
|
|
1178 | 1259 |
} |
1260 |
|
|
1261 |
*ret_data = QOBJECT(bs_list); |
|
1179 | 1262 |
} |
1180 | 1263 |
|
1181 | 1264 |
/* The "info blockstats" command. */ |
Also available in: Unified diff