Revision 1b7bdbc1 block.c
b/block.c | ||
---|---|---|
55 | 55 |
static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num, |
56 | 56 |
const uint8_t *buf, int nb_sectors); |
57 | 57 |
|
58 |
static BlockDriverState *bdrv_first; |
|
58 |
static QTAILQ_HEAD(, BlockDriverState) bdrv_states = |
|
59 |
QTAILQ_HEAD_INITIALIZER(bdrv_states); |
|
59 | 60 |
|
60 | 61 |
static BlockDriver *first_drv; |
61 | 62 |
|
... | ... | |
148 | 149 |
/* create a new block device (by default it is empty) */ |
149 | 150 |
BlockDriverState *bdrv_new(const char *device_name) |
150 | 151 |
{ |
151 |
BlockDriverState **pbs, *bs;
|
|
152 |
BlockDriverState *bs; |
|
152 | 153 |
|
153 | 154 |
bs = qemu_mallocz(sizeof(BlockDriverState)); |
154 | 155 |
pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); |
155 | 156 |
if (device_name[0] != '\0') { |
156 |
/* insert at the end */ |
|
157 |
pbs = &bdrv_first; |
|
158 |
while (*pbs != NULL) |
|
159 |
pbs = &(*pbs)->next; |
|
160 |
*pbs = bs; |
|
157 |
QTAILQ_INSERT_TAIL(&bdrv_states, bs, list); |
|
161 | 158 |
} |
162 | 159 |
return bs; |
163 | 160 |
} |
... | ... | |
545 | 542 |
|
546 | 543 |
void bdrv_delete(BlockDriverState *bs) |
547 | 544 |
{ |
548 |
BlockDriverState **pbs; |
|
549 |
|
|
550 |
pbs = &bdrv_first; |
|
551 |
while (*pbs != bs && *pbs != NULL) |
|
552 |
pbs = &(*pbs)->next; |
|
553 |
if (*pbs == bs) |
|
554 |
*pbs = bs->next; |
|
545 |
/* remove from list, if necessary */ |
|
546 |
if (bs->device_name[0] != '\0') { |
|
547 |
QTAILQ_REMOVE(&bdrv_states, bs, list); |
|
548 |
} |
|
555 | 549 |
|
556 | 550 |
bdrv_close(bs); |
557 | 551 |
qemu_free(bs); |
... | ... | |
1172 | 1166 |
{ |
1173 | 1167 |
BlockDriverState *bs; |
1174 | 1168 |
|
1175 |
for (bs = bdrv_first; bs != NULL; bs = bs->next) {
|
|
1176 |
if (!strcmp(name, bs->device_name)) |
|
1169 |
QTAILQ_FOREACH(bs, &bdrv_states, list) {
|
|
1170 |
if (!strcmp(name, bs->device_name)) {
|
|
1177 | 1171 |
return bs; |
1172 |
} |
|
1178 | 1173 |
} |
1179 | 1174 |
return NULL; |
1180 | 1175 |
} |
... | ... | |
1183 | 1178 |
{ |
1184 | 1179 |
BlockDriverState *bs; |
1185 | 1180 |
|
1186 |
for (bs = bdrv_first; bs != NULL; bs = bs->next) {
|
|
1181 |
QTAILQ_FOREACH(bs, &bdrv_states, list) {
|
|
1187 | 1182 |
it(opaque, bs); |
1188 | 1183 |
} |
1189 | 1184 |
} |
... | ... | |
1203 | 1198 |
{ |
1204 | 1199 |
BlockDriverState *bs; |
1205 | 1200 |
|
1206 |
for (bs = bdrv_first; bs != NULL; bs = bs->next)
|
|
1207 |
if (bs->drv && !bdrv_is_read_only(bs) &&
|
|
1208 |
(!bdrv_is_removable(bs) || bdrv_is_inserted(bs))) |
|
1201 |
QTAILQ_FOREACH(bs, &bdrv_states, list) {
|
|
1202 |
if (bs->drv && !bdrv_is_read_only(bs) && |
|
1203 |
(!bdrv_is_removable(bs) || bdrv_is_inserted(bs))) {
|
|
1209 | 1204 |
bdrv_flush(bs); |
1205 |
} |
|
1206 |
} |
|
1210 | 1207 |
} |
1211 | 1208 |
|
1212 | 1209 |
/* |
... | ... | |
1340 | 1337 |
|
1341 | 1338 |
bs_list = qlist_new(); |
1342 | 1339 |
|
1343 |
for (bs = bdrv_first; bs != NULL; bs = bs->next) {
|
|
1340 |
QTAILQ_FOREACH(bs, &bdrv_states, list) {
|
|
1344 | 1341 |
QObject *bs_obj; |
1345 | 1342 |
const char *type = "unknown"; |
1346 | 1343 |
|
... | ... | |
1445 | 1442 |
|
1446 | 1443 |
devices = qlist_new(); |
1447 | 1444 |
|
1448 |
for (bs = bdrv_first; bs != NULL; bs = bs->next) {
|
|
1445 |
QTAILQ_FOREACH(bs, &bdrv_states, list) {
|
|
1449 | 1446 |
obj = qobject_from_jsonf("{ 'device': %s, 'stats': {" |
1450 | 1447 |
"'rd_bytes': %" PRId64 "," |
1451 | 1448 |
"'wr_bytes': %" PRId64 "," |
Also available in: Unified diff