block.c (6f7a3b535f0d48d138e43cadf13323f083bfb547) | block.c (bd86fb990cfedc50d9705b8ed31d183f01942035) |
---|---|
1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 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 --- 62 unchanged lines hidden (view full) --- 71 72static QLIST_HEAD(, BlockDriver) bdrv_drivers = 73 QLIST_HEAD_INITIALIZER(bdrv_drivers); 74 75static BlockDriverState *bdrv_open_inherit(const char *filename, 76 const char *reference, 77 QDict *options, int flags, 78 BlockDriverState *parent, | 1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 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 --- 62 unchanged lines hidden (view full) --- 71 72static QLIST_HEAD(, BlockDriver) bdrv_drivers = 73 QLIST_HEAD_INITIALIZER(bdrv_drivers); 74 75static BlockDriverState *bdrv_open_inherit(const char *filename, 76 const char *reference, 77 QDict *options, int flags, 78 BlockDriverState *parent, |
79 const BdrvChildRole *child_role, | 79 const BdrvChildClass *child_class, |
80 Error **errp); 81 82/* If non-zero, use only whitelisted block drivers */ 83static int use_bdrv_whitelist; 84 85#ifdef _WIN32 86static int is_windows_drive_prefix(const char *filename) 87{ --- 1090 unchanged lines hidden (view full) --- 1178 1179 /* Clear flags that only apply to the top layer */ 1180 flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ | 1181 BDRV_O_NO_IO); 1182 1183 *child_flags = flags; 1184} 1185 | 80 Error **errp); 81 82/* If non-zero, use only whitelisted block drivers */ 83static int use_bdrv_whitelist; 84 85#ifdef _WIN32 86static int is_windows_drive_prefix(const char *filename) 87{ --- 1090 unchanged lines hidden (view full) --- 1178 1179 /* Clear flags that only apply to the top layer */ 1180 flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ | 1181 BDRV_O_NO_IO); 1182 1183 *child_flags = flags; 1184} 1185 |
1186const BdrvChildRole child_file = { | 1186const BdrvChildClass child_file = { |
1187 .parent_is_bds = true, 1188 .get_parent_desc = bdrv_child_get_parent_desc, 1189 .inherit_options = bdrv_inherited_options, 1190 .drained_begin = bdrv_child_cb_drained_begin, 1191 .drained_poll = bdrv_child_cb_drained_poll, 1192 .drained_end = bdrv_child_cb_drained_end, 1193 .attach = bdrv_child_cb_attach, 1194 .detach = bdrv_child_cb_detach, --- 11 unchanged lines hidden (view full) --- 1206 int parent_flags, QDict *parent_options) 1207{ 1208 child_file.inherit_options(child_flags, child_options, 1209 parent_flags, parent_options); 1210 1211 *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO); 1212} 1213 | 1187 .parent_is_bds = true, 1188 .get_parent_desc = bdrv_child_get_parent_desc, 1189 .inherit_options = bdrv_inherited_options, 1190 .drained_begin = bdrv_child_cb_drained_begin, 1191 .drained_poll = bdrv_child_cb_drained_poll, 1192 .drained_end = bdrv_child_cb_drained_end, 1193 .attach = bdrv_child_cb_attach, 1194 .detach = bdrv_child_cb_detach, --- 11 unchanged lines hidden (view full) --- 1206 int parent_flags, QDict *parent_options) 1207{ 1208 child_file.inherit_options(child_flags, child_options, 1209 parent_flags, parent_options); 1210 1211 *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO); 1212} 1213 |
1214const BdrvChildRole child_format = { | 1214const BdrvChildClass child_format = { |
1215 .parent_is_bds = true, 1216 .get_parent_desc = bdrv_child_get_parent_desc, 1217 .inherit_options = bdrv_inherited_fmt_options, 1218 .drained_begin = bdrv_child_cb_drained_begin, 1219 .drained_poll = bdrv_child_cb_drained_poll, 1220 .drained_end = bdrv_child_cb_drained_end, 1221 .attach = bdrv_child_cb_attach, 1222 .detach = bdrv_child_cb_detach, --- 107 unchanged lines hidden (view full) --- 1330 1331 if (read_only) { 1332 bdrv_reopen_set_read_only(parent, true, NULL); 1333 } 1334 1335 return ret; 1336} 1337 | 1215 .parent_is_bds = true, 1216 .get_parent_desc = bdrv_child_get_parent_desc, 1217 .inherit_options = bdrv_inherited_fmt_options, 1218 .drained_begin = bdrv_child_cb_drained_begin, 1219 .drained_poll = bdrv_child_cb_drained_poll, 1220 .drained_end = bdrv_child_cb_drained_end, 1221 .attach = bdrv_child_cb_attach, 1222 .detach = bdrv_child_cb_detach, --- 107 unchanged lines hidden (view full) --- 1330 1331 if (read_only) { 1332 bdrv_reopen_set_read_only(parent, true, NULL); 1333 } 1334 1335 return ret; 1336} 1337 |
1338const BdrvChildRole child_backing = { | 1338const BdrvChildClass child_backing = { |
1339 .parent_is_bds = true, 1340 .get_parent_desc = bdrv_child_get_parent_desc, 1341 .attach = bdrv_backing_attach, 1342 .detach = bdrv_backing_detach, 1343 .inherit_options = bdrv_backing_options, 1344 .drained_begin = bdrv_child_cb_drained_begin, 1345 .drained_poll = bdrv_child_cb_drained_poll, 1346 .drained_end = bdrv_child_cb_drained_end, --- 601 unchanged lines hidden (view full) --- 1948 * be written to but do not count as read-only images. 1949 */ 1950bool bdrv_is_writable(BlockDriverState *bs) 1951{ 1952 return bdrv_is_writable_after_reopen(bs, NULL); 1953} 1954 1955static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, | 1339 .parent_is_bds = true, 1340 .get_parent_desc = bdrv_child_get_parent_desc, 1341 .attach = bdrv_backing_attach, 1342 .detach = bdrv_backing_detach, 1343 .inherit_options = bdrv_backing_options, 1344 .drained_begin = bdrv_child_cb_drained_begin, 1345 .drained_poll = bdrv_child_cb_drained_poll, 1346 .drained_end = bdrv_child_cb_drained_end, --- 601 unchanged lines hidden (view full) --- 1948 * be written to but do not count as read-only images. 1949 */ 1950bool bdrv_is_writable(BlockDriverState *bs) 1951{ 1952 return bdrv_is_writable_after_reopen(bs, NULL); 1953} 1954 1955static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, |
1956 BdrvChild *c, const BdrvChildRole *role, | 1956 BdrvChild *c, const BdrvChildClass *child_class, |
1957 BlockReopenQueue *reopen_queue, 1958 uint64_t parent_perm, uint64_t parent_shared, 1959 uint64_t *nperm, uint64_t *nshared) 1960{ 1961 assert(bs->drv && bs->drv->bdrv_child_perm); | 1957 BlockReopenQueue *reopen_queue, 1958 uint64_t parent_perm, uint64_t parent_shared, 1959 uint64_t *nperm, uint64_t *nshared) 1960{ 1961 assert(bs->drv && bs->drv->bdrv_child_perm); |
1962 bs->drv->bdrv_child_perm(bs, c, role, reopen_queue, | 1962 bs->drv->bdrv_child_perm(bs, c, child_class, reopen_queue, |
1963 parent_perm, parent_shared, 1964 nperm, nshared); 1965 /* TODO Take force_share from reopen_queue */ 1966 if (child_bs && child_bs->force_share) { 1967 *nshared = BLK_PERM_ALL; 1968 } 1969} 1970 --- 77 unchanged lines hidden (view full) --- 2048 return 0; 2049 } 2050 2051 /* Check all children */ 2052 QLIST_FOREACH(c, &bs->children, next) { 2053 uint64_t cur_perm, cur_shared; 2054 bool child_tighten_restr; 2055 | 1963 parent_perm, parent_shared, 1964 nperm, nshared); 1965 /* TODO Take force_share from reopen_queue */ 1966 if (child_bs && child_bs->force_share) { 1967 *nshared = BLK_PERM_ALL; 1968 } 1969} 1970 --- 77 unchanged lines hidden (view full) --- 2048 return 0; 2049 } 2050 2051 /* Check all children */ 2052 QLIST_FOREACH(c, &bs->children, next) { 2053 uint64_t cur_perm, cur_shared; 2054 bool child_tighten_restr; 2055 |
2056 bdrv_child_perm(bs, c->bs, c, c->role, q, | 2056 bdrv_child_perm(bs, c->bs, c, c->klass, q, |
2057 cumulative_perms, cumulative_shared_perms, 2058 &cur_perm, &cur_shared); 2059 ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, 2060 tighten_restrictions ? &child_tighten_restr 2061 : NULL, 2062 errp); 2063 if (tighten_restrictions) { 2064 *tighten_restrictions |= child_tighten_restr; --- 50 unchanged lines hidden (view full) --- 2115 if (!drv->bdrv_child_perm) { 2116 assert(QLIST_EMPTY(&bs->children)); 2117 return; 2118 } 2119 2120 /* Update all children */ 2121 QLIST_FOREACH(c, &bs->children, next) { 2122 uint64_t cur_perm, cur_shared; | 2057 cumulative_perms, cumulative_shared_perms, 2058 &cur_perm, &cur_shared); 2059 ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, 2060 tighten_restrictions ? &child_tighten_restr 2061 : NULL, 2062 errp); 2063 if (tighten_restrictions) { 2064 *tighten_restrictions |= child_tighten_restr; --- 50 unchanged lines hidden (view full) --- 2115 if (!drv->bdrv_child_perm) { 2116 assert(QLIST_EMPTY(&bs->children)); 2117 return; 2118 } 2119 2120 /* Update all children */ 2121 QLIST_FOREACH(c, &bs->children, next) { 2122 uint64_t cur_perm, cur_shared; |
2123 bdrv_child_perm(bs, c->bs, c, c->role, NULL, | 2123 bdrv_child_perm(bs, c->bs, c, c->klass, NULL, |
2124 cumulative_perms, cumulative_shared_perms, 2125 &cur_perm, &cur_shared); 2126 bdrv_child_set_perm(c, cur_perm, cur_shared); 2127 } 2128} 2129 2130void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, 2131 uint64_t *shared_perm) --- 8 unchanged lines hidden (view full) --- 2140 } 2141 2142 *perm = cumulative_perms; 2143 *shared_perm = cumulative_shared_perms; 2144} 2145 2146static char *bdrv_child_user_desc(BdrvChild *c) 2147{ | 2124 cumulative_perms, cumulative_shared_perms, 2125 &cur_perm, &cur_shared); 2126 bdrv_child_set_perm(c, cur_perm, cur_shared); 2127 } 2128} 2129 2130void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, 2131 uint64_t *shared_perm) --- 8 unchanged lines hidden (view full) --- 2140 } 2141 2142 *perm = cumulative_perms; 2143 *shared_perm = cumulative_shared_perms; 2144} 2145 2146static char *bdrv_child_user_desc(BdrvChild *c) 2147{ |
2148 if (c->role->get_parent_desc) { 2149 return c->role->get_parent_desc(c); | 2148 if (c->klass->get_parent_desc) { 2149 return c->klass->get_parent_desc(c); |
2150 } 2151 2152 return g_strdup("another user"); 2153} 2154 2155char *bdrv_perm_names(uint64_t perm) 2156{ 2157 struct perm_name { --- 185 unchanged lines hidden (view full) --- 2343} 2344 2345int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) 2346{ 2347 uint64_t parent_perms, parent_shared; 2348 uint64_t perms, shared; 2349 2350 bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); | 2150 } 2151 2152 return g_strdup("another user"); 2153} 2154 2155char *bdrv_perm_names(uint64_t perm) 2156{ 2157 struct perm_name { --- 185 unchanged lines hidden (view full) --- 2343} 2344 2345int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) 2346{ 2347 uint64_t parent_perms, parent_shared; 2348 uint64_t perms, shared; 2349 2350 bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); |
2351 bdrv_child_perm(bs, c->bs, c, c->role, NULL, parent_perms, parent_shared, | 2351 bdrv_child_perm(bs, c->bs, c, c->klass, NULL, parent_perms, parent_shared, |
2352 &perms, &shared); 2353 2354 return bdrv_child_try_set_perm(c, perms, shared, errp); 2355} 2356 2357void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | 2352 &perms, &shared); 2353 2354 return bdrv_child_try_set_perm(c, perms, shared, errp); 2355} 2356 2357void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, |
2358 const BdrvChildRole *role, | 2358 const BdrvChildClass *child_class, |
2359 BlockReopenQueue *reopen_queue, 2360 uint64_t perm, uint64_t shared, 2361 uint64_t *nperm, uint64_t *nshared) 2362{ 2363 *nperm = perm & DEFAULT_PERM_PASSTHROUGH; 2364 *nshared = (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHANGED; 2365} 2366 2367void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | 2359 BlockReopenQueue *reopen_queue, 2360 uint64_t perm, uint64_t shared, 2361 uint64_t *nperm, uint64_t *nshared) 2362{ 2363 *nperm = perm & DEFAULT_PERM_PASSTHROUGH; 2364 *nshared = (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHANGED; 2365} 2366 2367void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, |
2368 const BdrvChildRole *role, | 2368 const BdrvChildClass *child_class, |
2369 BlockReopenQueue *reopen_queue, 2370 uint64_t perm, uint64_t shared, 2371 uint64_t *nperm, uint64_t *nshared) 2372{ | 2369 BlockReopenQueue *reopen_queue, 2370 uint64_t perm, uint64_t shared, 2371 uint64_t *nperm, uint64_t *nshared) 2372{ |
2373 bool backing = (role == &child_backing); 2374 assert(role == &child_backing || role == &child_file); | 2373 bool backing = (child_class == &child_backing); 2374 assert(child_class == &child_backing || child_class == &child_file); |
2375 2376 if (!backing) { 2377 int flags = bdrv_reopen_get_flags(reopen_queue, bs); 2378 2379 /* Apart from the modifications below, the same permissions are 2380 * forwarded and left alone as for filters */ | 2375 2376 if (!backing) { 2377 int flags = bdrv_reopen_get_flags(reopen_queue, bs); 2378 2379 /* Apart from the modifications below, the same permissions are 2380 * forwarded and left alone as for filters */ |
2381 bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, 2382 &perm, &shared); | 2381 bdrv_filter_default_perms(bs, c, child_class, reopen_queue, 2382 perm, shared, &perm, &shared); |
2383 2384 /* Format drivers may touch metadata even if the guest doesn't write */ 2385 if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { 2386 perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE; 2387 } 2388 2389 /* bs->file always needs to be consistent because of the metadata. We 2390 * can never allow other users to resize or write to it. */ --- 60 unchanged lines hidden (view full) --- 2451 2452 new_bs_quiesce_counter = (new_bs ? new_bs->quiesce_counter : 0); 2453 drain_saldo = new_bs_quiesce_counter - child->parent_quiesce_counter; 2454 2455 /* 2456 * If the new child node is drained but the old one was not, flush 2457 * all outstanding requests to the old child node. 2458 */ | 2383 2384 /* Format drivers may touch metadata even if the guest doesn't write */ 2385 if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { 2386 perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE; 2387 } 2388 2389 /* bs->file always needs to be consistent because of the metadata. We 2390 * can never allow other users to resize or write to it. */ --- 60 unchanged lines hidden (view full) --- 2451 2452 new_bs_quiesce_counter = (new_bs ? new_bs->quiesce_counter : 0); 2453 drain_saldo = new_bs_quiesce_counter - child->parent_quiesce_counter; 2454 2455 /* 2456 * If the new child node is drained but the old one was not, flush 2457 * all outstanding requests to the old child node. 2458 */ |
2459 while (drain_saldo > 0 && child->role->drained_begin) { | 2459 while (drain_saldo > 0 && child->klass->drained_begin) { |
2460 bdrv_parent_drained_begin_single(child, true); 2461 drain_saldo--; 2462 } 2463 2464 if (old_bs) { 2465 /* Detach first so that the recursive drain sections coming from @child 2466 * are already gone and we only end the drain sections that came from 2467 * elsewhere. */ | 2460 bdrv_parent_drained_begin_single(child, true); 2461 drain_saldo--; 2462 } 2463 2464 if (old_bs) { 2465 /* Detach first so that the recursive drain sections coming from @child 2466 * are already gone and we only end the drain sections that came from 2467 * elsewhere. */ |
2468 if (child->role->detach) { 2469 child->role->detach(child); | 2468 if (child->klass->detach) { 2469 child->klass->detach(child); |
2470 } 2471 QLIST_REMOVE(child, next_parent); 2472 } 2473 2474 child->bs = new_bs; 2475 2476 if (new_bs) { 2477 QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); --- 5 unchanged lines hidden (view full) --- 2483 * drained_end appropriately more often. 2484 */ 2485 assert(new_bs->quiesce_counter <= new_bs_quiesce_counter); 2486 drain_saldo += new_bs->quiesce_counter - new_bs_quiesce_counter; 2487 2488 /* Attach only after starting new drained sections, so that recursive 2489 * drain sections coming from @child don't get an extra .drained_begin 2490 * callback. */ | 2470 } 2471 QLIST_REMOVE(child, next_parent); 2472 } 2473 2474 child->bs = new_bs; 2475 2476 if (new_bs) { 2477 QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); --- 5 unchanged lines hidden (view full) --- 2483 * drained_end appropriately more often. 2484 */ 2485 assert(new_bs->quiesce_counter <= new_bs_quiesce_counter); 2486 drain_saldo += new_bs->quiesce_counter - new_bs_quiesce_counter; 2487 2488 /* Attach only after starting new drained sections, so that recursive 2489 * drain sections coming from @child don't get an extra .drained_begin 2490 * callback. */ |
2491 if (child->role->attach) { 2492 child->role->attach(child); | 2491 if (child->klass->attach) { 2492 child->klass->attach(child); |
2493 } 2494 } 2495 2496 /* 2497 * If the old child node was drained but the new one is not, allow 2498 * requests to come in only after the new node has been attached. 2499 */ | 2493 } 2494 } 2495 2496 /* 2497 * If the old child node was drained but the new one is not, allow 2498 * requests to come in only after the new node has been attached. 2499 */ |
2500 while (drain_saldo < 0 && child->role->drained_end) { | 2500 while (drain_saldo < 0 && child->klass->drained_end) { |
2501 bdrv_parent_drained_end_single(child); 2502 drain_saldo++; 2503 } 2504} 2505 2506/* 2507 * Updates @child to change its reference to point to @new_bs, including 2508 * checking and applying the necessary permisson updates both to the old node --- 56 unchanged lines hidden (view full) --- 2565 * On failure NULL is returned, errp is set and the reference to 2566 * child_bs is also dropped. 2567 * 2568 * The caller must hold the AioContext lock @child_bs, but not that of @ctx 2569 * (unless @child_bs is already in @ctx). 2570 */ 2571BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, 2572 const char *child_name, | 2501 bdrv_parent_drained_end_single(child); 2502 drain_saldo++; 2503 } 2504} 2505 2506/* 2507 * Updates @child to change its reference to point to @new_bs, including 2508 * checking and applying the necessary permisson updates both to the old node --- 56 unchanged lines hidden (view full) --- 2565 * On failure NULL is returned, errp is set and the reference to 2566 * child_bs is also dropped. 2567 * 2568 * The caller must hold the AioContext lock @child_bs, but not that of @ctx 2569 * (unless @child_bs is already in @ctx). 2570 */ 2571BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, 2572 const char *child_name, |
2573 const BdrvChildRole *child_role, | 2573 const BdrvChildClass *child_class, |
2574 AioContext *ctx, 2575 uint64_t perm, uint64_t shared_perm, 2576 void *opaque, Error **errp) 2577{ 2578 BdrvChild *child; 2579 Error *local_err = NULL; 2580 int ret; 2581 --- 4 unchanged lines hidden (view full) --- 2586 bdrv_unref(child_bs); 2587 return NULL; 2588 } 2589 2590 child = g_new(BdrvChild, 1); 2591 *child = (BdrvChild) { 2592 .bs = NULL, 2593 .name = g_strdup(child_name), | 2574 AioContext *ctx, 2575 uint64_t perm, uint64_t shared_perm, 2576 void *opaque, Error **errp) 2577{ 2578 BdrvChild *child; 2579 Error *local_err = NULL; 2580 int ret; 2581 --- 4 unchanged lines hidden (view full) --- 2586 bdrv_unref(child_bs); 2587 return NULL; 2588 } 2589 2590 child = g_new(BdrvChild, 1); 2591 *child = (BdrvChild) { 2592 .bs = NULL, 2593 .name = g_strdup(child_name), |
2594 .role = child_role, | 2594 .klass = child_class, |
2595 .perm = perm, 2596 .shared_perm = shared_perm, 2597 .opaque = opaque, 2598 }; 2599 2600 /* If the AioContexts don't match, first try to move the subtree of 2601 * child_bs into the AioContext of the new parent. If this doesn't work, 2602 * try moving the parent into the AioContext of child_bs instead. */ 2603 if (bdrv_get_aio_context(child_bs) != ctx) { 2604 ret = bdrv_try_set_aio_context(child_bs, ctx, &local_err); | 2595 .perm = perm, 2596 .shared_perm = shared_perm, 2597 .opaque = opaque, 2598 }; 2599 2600 /* If the AioContexts don't match, first try to move the subtree of 2601 * child_bs into the AioContext of the new parent. If this doesn't work, 2602 * try moving the parent into the AioContext of child_bs instead. */ 2603 if (bdrv_get_aio_context(child_bs) != ctx) { 2604 ret = bdrv_try_set_aio_context(child_bs, ctx, &local_err); |
2605 if (ret < 0 && child_role->can_set_aio_ctx) { | 2605 if (ret < 0 && child_class->can_set_aio_ctx) { |
2606 GSList *ignore = g_slist_prepend(NULL, child); 2607 ctx = bdrv_get_aio_context(child_bs); | 2606 GSList *ignore = g_slist_prepend(NULL, child); 2607 ctx = bdrv_get_aio_context(child_bs); |
2608 if (child_role->can_set_aio_ctx(child, ctx, &ignore, NULL)) { | 2608 if (child_class->can_set_aio_ctx(child, ctx, &ignore, NULL)) { |
2609 error_free(local_err); 2610 ret = 0; 2611 g_slist_free(ignore); 2612 ignore = g_slist_prepend(NULL, child); | 2609 error_free(local_err); 2610 ret = 0; 2611 g_slist_free(ignore); 2612 ignore = g_slist_prepend(NULL, child); |
2613 child_role->set_aio_ctx(child, ctx, &ignore); | 2613 child_class->set_aio_ctx(child, ctx, &ignore); |
2614 } 2615 g_slist_free(ignore); 2616 } 2617 if (ret < 0) { 2618 error_propagate(errp, local_err); 2619 g_free(child); 2620 bdrv_abort_perm_update(child_bs); 2621 bdrv_unref(child_bs); --- 16 unchanged lines hidden (view full) --- 2638 * child_bs is also dropped. 2639 * 2640 * If @parent_bs and @child_bs are in different AioContexts, the caller must 2641 * hold the AioContext lock for @child_bs, but not for @parent_bs. 2642 */ 2643BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, 2644 BlockDriverState *child_bs, 2645 const char *child_name, | 2614 } 2615 g_slist_free(ignore); 2616 } 2617 if (ret < 0) { 2618 error_propagate(errp, local_err); 2619 g_free(child); 2620 bdrv_abort_perm_update(child_bs); 2621 bdrv_unref(child_bs); --- 16 unchanged lines hidden (view full) --- 2638 * child_bs is also dropped. 2639 * 2640 * If @parent_bs and @child_bs are in different AioContexts, the caller must 2641 * hold the AioContext lock for @child_bs, but not for @parent_bs. 2642 */ 2643BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, 2644 BlockDriverState *child_bs, 2645 const char *child_name, |
2646 const BdrvChildRole *child_role, | 2646 const BdrvChildClass *child_class, |
2647 Error **errp) 2648{ 2649 BdrvChild *child; 2650 uint64_t perm, shared_perm; 2651 2652 bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); 2653 2654 assert(parent_bs->drv); | 2647 Error **errp) 2648{ 2649 BdrvChild *child; 2650 uint64_t perm, shared_perm; 2651 2652 bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); 2653 2654 assert(parent_bs->drv); |
2655 bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL, | 2655 bdrv_child_perm(parent_bs, child_bs, NULL, child_class, NULL, |
2656 perm, shared_perm, &perm, &shared_perm); 2657 | 2656 perm, shared_perm, &perm, &shared_perm); 2657 |
2658 child = bdrv_root_attach_child(child_bs, child_name, child_role, | 2658 child = bdrv_root_attach_child(child_bs, child_name, child_class, |
2659 bdrv_get_aio_context(parent_bs), 2660 perm, shared_perm, parent_bs, errp); 2661 if (child == NULL) { 2662 return NULL; 2663 } 2664 2665 QLIST_INSERT_HEAD(&parent_bs->children, child, next); 2666 return child; --- 56 unchanged lines hidden (view full) --- 2723 bdrv_root_unref_child(child); 2724} 2725 2726 2727static void bdrv_parent_cb_change_media(BlockDriverState *bs, bool load) 2728{ 2729 BdrvChild *c; 2730 QLIST_FOREACH(c, &bs->parents, next_parent) { | 2659 bdrv_get_aio_context(parent_bs), 2660 perm, shared_perm, parent_bs, errp); 2661 if (child == NULL) { 2662 return NULL; 2663 } 2664 2665 QLIST_INSERT_HEAD(&parent_bs->children, child, next); 2666 return child; --- 56 unchanged lines hidden (view full) --- 2723 bdrv_root_unref_child(child); 2724} 2725 2726 2727static void bdrv_parent_cb_change_media(BlockDriverState *bs, bool load) 2728{ 2729 BdrvChild *c; 2730 QLIST_FOREACH(c, &bs->parents, next_parent) { |
2731 if (c->role->change_media) { 2732 c->role->change_media(c, load); | 2731 if (c->klass->change_media) { 2732 c->klass->change_media(c, load); |
2733 } 2734 } 2735} 2736 2737/* Return true if you can reach parent going through child->inherits_from 2738 * recursively. If parent or child are NULL, return false */ 2739static bool bdrv_inherits_from_recursive(BlockDriverState *child, 2740 BlockDriverState *parent) --- 159 unchanged lines hidden (view full) --- 2900free_exit: 2901 g_free(backing_filename); 2902 qobject_unref(tmp_parent_options); 2903 return ret; 2904} 2905 2906static BlockDriverState * 2907bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, | 2733 } 2734 } 2735} 2736 2737/* Return true if you can reach parent going through child->inherits_from 2738 * recursively. If parent or child are NULL, return false */ 2739static bool bdrv_inherits_from_recursive(BlockDriverState *child, 2740 BlockDriverState *parent) --- 159 unchanged lines hidden (view full) --- 2900free_exit: 2901 g_free(backing_filename); 2902 qobject_unref(tmp_parent_options); 2903 return ret; 2904} 2905 2906static BlockDriverState * 2907bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, |
2908 BlockDriverState *parent, const BdrvChildRole *child_role, | 2908 BlockDriverState *parent, const BdrvChildClass *child_class, |
2909 bool allow_none, Error **errp) 2910{ 2911 BlockDriverState *bs = NULL; 2912 QDict *image_options; 2913 char *bdref_key_dot; 2914 const char *reference; 2915 | 2909 bool allow_none, Error **errp) 2910{ 2911 BlockDriverState *bs = NULL; 2912 QDict *image_options; 2913 char *bdref_key_dot; 2914 const char *reference; 2915 |
2916 assert(child_role != NULL); | 2916 assert(child_class != NULL); |
2917 2918 bdref_key_dot = g_strdup_printf("%s.", bdref_key); 2919 qdict_extract_subqdict(options, &image_options, bdref_key_dot); 2920 g_free(bdref_key_dot); 2921 2922 /* 2923 * Caution: while qdict_get_try_str() is fine, getting non-string 2924 * types would require more care. When @options come from --- 7 unchanged lines hidden (view full) --- 2932 error_setg(errp, "A block device must be specified for \"%s\"", 2933 bdref_key); 2934 } 2935 qobject_unref(image_options); 2936 goto done; 2937 } 2938 2939 bs = bdrv_open_inherit(filename, reference, image_options, 0, | 2917 2918 bdref_key_dot = g_strdup_printf("%s.", bdref_key); 2919 qdict_extract_subqdict(options, &image_options, bdref_key_dot); 2920 g_free(bdref_key_dot); 2921 2922 /* 2923 * Caution: while qdict_get_try_str() is fine, getting non-string 2924 * types would require more care. When @options come from --- 7 unchanged lines hidden (view full) --- 2932 error_setg(errp, "A block device must be specified for \"%s\"", 2933 bdref_key); 2934 } 2935 qobject_unref(image_options); 2936 goto done; 2937 } 2938 2939 bs = bdrv_open_inherit(filename, reference, image_options, 0, |
2940 parent, child_role, errp); | 2940 parent, child_class, errp); |
2941 if (!bs) { 2942 goto done; 2943 } 2944 2945done: 2946 qdict_del(options, bdref_key); 2947 return bs; 2948} --- 10 unchanged lines hidden (view full) --- 2959 * itself, all options starting with "${bdref_key}." are considered part of the 2960 * BlockdevRef. 2961 * 2962 * The BlockdevRef will be removed from the options QDict. 2963 */ 2964BdrvChild *bdrv_open_child(const char *filename, 2965 QDict *options, const char *bdref_key, 2966 BlockDriverState *parent, | 2941 if (!bs) { 2942 goto done; 2943 } 2944 2945done: 2946 qdict_del(options, bdref_key); 2947 return bs; 2948} --- 10 unchanged lines hidden (view full) --- 2959 * itself, all options starting with "${bdref_key}." are considered part of the 2960 * BlockdevRef. 2961 * 2962 * The BlockdevRef will be removed from the options QDict. 2963 */ 2964BdrvChild *bdrv_open_child(const char *filename, 2965 QDict *options, const char *bdref_key, 2966 BlockDriverState *parent, |
2967 const BdrvChildRole *child_role, | 2967 const BdrvChildClass *child_class, |
2968 bool allow_none, Error **errp) 2969{ 2970 BlockDriverState *bs; 2971 | 2968 bool allow_none, Error **errp) 2969{ 2970 BlockDriverState *bs; 2971 |
2972 bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_role, | 2972 bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_class, |
2973 allow_none, errp); 2974 if (bs == NULL) { 2975 return NULL; 2976 } 2977 | 2973 allow_none, errp); 2974 if (bs == NULL) { 2975 return NULL; 2976 } 2977 |
2978 return bdrv_attach_child(parent, bs, bdref_key, child_role, errp); | 2978 return bdrv_attach_child(parent, bs, bdref_key, child_class, errp); |
2979} 2980 | 2979} 2980 |
2981/* TODO Future callers may need to specify parent/child_role in order for 2982 * option inheritance to work. Existing callers use it for the root node. */ | 2981/* 2982 * TODO Future callers may need to specify parent/child_class in order for 2983 * option inheritance to work. Existing callers use it for the root node. 2984 */ |
2983BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp) 2984{ 2985 BlockDriverState *bs = NULL; 2986 QObject *obj = NULL; 2987 QDict *qdict = NULL; 2988 const char *reference = NULL; 2989 Visitor *v = NULL; 2990 --- 111 unchanged lines hidden (view full) --- 3102 * The reference parameter may be used to specify an existing block device which 3103 * should be opened. If specified, neither options nor a filename may be given, 3104 * nor can an existing BDS be reused (that is, *pbs has to be NULL). 3105 */ 3106static BlockDriverState *bdrv_open_inherit(const char *filename, 3107 const char *reference, 3108 QDict *options, int flags, 3109 BlockDriverState *parent, | 2985BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp) 2986{ 2987 BlockDriverState *bs = NULL; 2988 QObject *obj = NULL; 2989 QDict *qdict = NULL; 2990 const char *reference = NULL; 2991 Visitor *v = NULL; 2992 --- 111 unchanged lines hidden (view full) --- 3104 * The reference parameter may be used to specify an existing block device which 3105 * should be opened. If specified, neither options nor a filename may be given, 3106 * nor can an existing BDS be reused (that is, *pbs has to be NULL). 3107 */ 3108static BlockDriverState *bdrv_open_inherit(const char *filename, 3109 const char *reference, 3110 QDict *options, int flags, 3111 BlockDriverState *parent, |
3110 const BdrvChildRole *child_role, | 3112 const BdrvChildClass *child_class, |
3111 Error **errp) 3112{ 3113 int ret; 3114 BlockBackend *file = NULL; 3115 BlockDriverState *bs; 3116 BlockDriver *drv = NULL; 3117 BdrvChild *child; 3118 const char *drvname; 3119 const char *backing; 3120 Error *local_err = NULL; 3121 QDict *snapshot_options = NULL; 3122 int snapshot_flags = 0; 3123 | 3113 Error **errp) 3114{ 3115 int ret; 3116 BlockBackend *file = NULL; 3117 BlockDriverState *bs; 3118 BlockDriver *drv = NULL; 3119 BdrvChild *child; 3120 const char *drvname; 3121 const char *backing; 3122 Error *local_err = NULL; 3123 QDict *snapshot_options = NULL; 3124 int snapshot_flags = 0; 3125 |
3124 assert(!child_role || !flags); 3125 assert(!child_role == !parent); | 3126 assert(!child_class || !flags); 3127 assert(!child_class == !parent); |
3126 3127 if (reference) { 3128 bool options_non_empty = options ? qdict_size(options) : false; 3129 qobject_unref(options); 3130 3131 if (filename || options_non_empty) { 3132 error_setg(errp, "Cannot reference an existing block device with " 3133 "additional options or a new filename"); --- 19 unchanged lines hidden (view full) --- 3153 /* json: syntax counts as explicit options, as if in the QDict */ 3154 parse_json_protocol(options, &filename, &local_err); 3155 if (local_err) { 3156 goto fail; 3157 } 3158 3159 bs->explicit_options = qdict_clone_shallow(options); 3160 | 3128 3129 if (reference) { 3130 bool options_non_empty = options ? qdict_size(options) : false; 3131 qobject_unref(options); 3132 3133 if (filename || options_non_empty) { 3134 error_setg(errp, "Cannot reference an existing block device with " 3135 "additional options or a new filename"); --- 19 unchanged lines hidden (view full) --- 3155 /* json: syntax counts as explicit options, as if in the QDict */ 3156 parse_json_protocol(options, &filename, &local_err); 3157 if (local_err) { 3158 goto fail; 3159 } 3160 3161 bs->explicit_options = qdict_clone_shallow(options); 3162 |
3161 if (child_role) { | 3163 if (child_class) { |
3162 bs->inherits_from = parent; | 3164 bs->inherits_from = parent; |
3163 child_role->inherit_options(&flags, options, 3164 parent->open_flags, parent->options); | 3165 child_class->inherit_options(&flags, options, 3166 parent->open_flags, parent->options); |
3165 } 3166 3167 ret = bdrv_fill_options(&options, filename, &flags, &local_err); 3168 if (ret < 0) { 3169 goto fail; 3170 } 3171 3172 /* --- 294 unchanged lines hidden (view full) --- 3467 * returns a pointer to bs_queue, which is either the newly allocated 3468 * bs_queue, or the existing bs_queue being used. 3469 * 3470 * bs must be drained between bdrv_reopen_queue() and bdrv_reopen_multiple(). 3471 */ 3472static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, 3473 BlockDriverState *bs, 3474 QDict *options, | 3167 } 3168 3169 ret = bdrv_fill_options(&options, filename, &flags, &local_err); 3170 if (ret < 0) { 3171 goto fail; 3172 } 3173 3174 /* --- 294 unchanged lines hidden (view full) --- 3469 * returns a pointer to bs_queue, which is either the newly allocated 3470 * bs_queue, or the existing bs_queue being used. 3471 * 3472 * bs must be drained between bdrv_reopen_queue() and bdrv_reopen_multiple(). 3473 */ 3474static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, 3475 BlockDriverState *bs, 3476 QDict *options, |
3475 const BdrvChildRole *role, | 3477 const BdrvChildClass *klass, |
3476 QDict *parent_options, 3477 int parent_flags, 3478 bool keep_old_opts) 3479{ 3480 assert(bs != NULL); 3481 3482 BlockReopenQueueEntry *bs_entry; 3483 BdrvChild *child; --- 39 unchanged lines hidden (view full) --- 3523 qobject_unref(old_options); 3524 } 3525 3526 explicit_options = qdict_clone_shallow(options); 3527 3528 /* Inherit from parent node */ 3529 if (parent_options) { 3530 flags = 0; | 3478 QDict *parent_options, 3479 int parent_flags, 3480 bool keep_old_opts) 3481{ 3482 assert(bs != NULL); 3483 3484 BlockReopenQueueEntry *bs_entry; 3485 BdrvChild *child; --- 39 unchanged lines hidden (view full) --- 3525 qobject_unref(old_options); 3526 } 3527 3528 explicit_options = qdict_clone_shallow(options); 3529 3530 /* Inherit from parent node */ 3531 if (parent_options) { 3532 flags = 0; |
3531 role->inherit_options(&flags, options, parent_flags, parent_options); | 3533 klass->inherit_options(&flags, options, parent_flags, parent_options); |
3532 } else { 3533 flags = bdrv_get_flags(bs); 3534 } 3535 3536 if (keep_old_opts) { 3537 /* Old values are used for options that aren't set yet */ 3538 old_options = qdict_clone_shallow(bs->options); 3539 bdrv_join_options(bs, options, old_options); --- 74 unchanged lines hidden (view full) --- 3614 /* Extract child options ("child-name.*") */ 3615 char *child_key_dot = g_strdup_printf("%s.", child->name); 3616 qdict_extract_subqdict(explicit_options, NULL, child_key_dot); 3617 qdict_extract_subqdict(options, &new_child_options, child_key_dot); 3618 g_free(child_key_dot); 3619 } 3620 3621 bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, | 3534 } else { 3535 flags = bdrv_get_flags(bs); 3536 } 3537 3538 if (keep_old_opts) { 3539 /* Old values are used for options that aren't set yet */ 3540 old_options = qdict_clone_shallow(bs->options); 3541 bdrv_join_options(bs, options, old_options); --- 74 unchanged lines hidden (view full) --- 3616 /* Extract child options ("child-name.*") */ 3617 char *child_key_dot = g_strdup_printf("%s.", child->name); 3618 qdict_extract_subqdict(explicit_options, NULL, child_key_dot); 3619 qdict_extract_subqdict(options, &new_child_options, child_key_dot); 3620 g_free(child_key_dot); 3621 } 3622 3623 bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, |
3622 child->role, options, flags, child_keep_old); | 3624 child->klass, options, flags, child_keep_old); |
3623 } 3624 3625 return bs_queue; 3626} 3627 3628BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, 3629 BlockDriverState *bs, 3630 QDict *options, bool keep_old_opts) --- 163 unchanged lines hidden (view full) --- 3794 QLIST_FOREACH(c, &bs->parents, next_parent) { 3795 parent = find_parent_in_reopen_queue(q, c); 3796 if (!parent) { 3797 cumulative_perms |= c->perm; 3798 cumulative_shared_perms &= c->shared_perm; 3799 } else { 3800 uint64_t nperm, nshared; 3801 | 3625 } 3626 3627 return bs_queue; 3628} 3629 3630BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, 3631 BlockDriverState *bs, 3632 QDict *options, bool keep_old_opts) --- 163 unchanged lines hidden (view full) --- 3796 QLIST_FOREACH(c, &bs->parents, next_parent) { 3797 parent = find_parent_in_reopen_queue(q, c); 3798 if (!parent) { 3799 cumulative_perms |= c->perm; 3800 cumulative_shared_perms &= c->shared_perm; 3801 } else { 3802 uint64_t nperm, nshared; 3803 |
3802 bdrv_child_perm(parent->state.bs, bs, c, c->role, q, | 3804 bdrv_child_perm(parent->state.bs, bs, c, c->klass, q, |
3803 parent->state.perm, parent->state.shared_perm, 3804 &nperm, &nshared); 3805 3806 cumulative_perms |= nperm; 3807 cumulative_shared_perms &= nshared; 3808 } 3809 } 3810 *perm = cumulative_perms; --- 489 unchanged lines hidden (view full) --- 4300} 4301 4302static bool should_update_child(BdrvChild *c, BlockDriverState *to) 4303{ 4304 GQueue *queue; 4305 GHashTable *found; 4306 bool ret; 4307 | 3805 parent->state.perm, parent->state.shared_perm, 3806 &nperm, &nshared); 3807 3808 cumulative_perms |= nperm; 3809 cumulative_shared_perms &= nshared; 3810 } 3811 } 3812 *perm = cumulative_perms; --- 489 unchanged lines hidden (view full) --- 4302} 4303 4304static bool should_update_child(BdrvChild *c, BlockDriverState *to) 4305{ 4306 GQueue *queue; 4307 GHashTable *found; 4308 bool ret; 4309 |
4308 if (c->role->stay_at_node) { | 4310 if (c->klass->stay_at_node) { |
4309 return false; 4310 } 4311 4312 /* If the child @c belongs to the BDS @to, replacing the current 4313 * c->bs by @to would mean to create a loop. 4314 * 4315 * Such a case occurs when appending a BDS to a backing chain. 4316 * For instance, imagine the following chain: --- 454 unchanged lines hidden (view full) --- 4771 ignore_children, NULL, &local_err); 4772 g_slist_free(ignore_children); 4773 if (ret < 0) { 4774 error_report_err(local_err); 4775 goto exit; 4776 } 4777 4778 /* If so, update the backing file path in the image file */ | 4311 return false; 4312 } 4313 4314 /* If the child @c belongs to the BDS @to, replacing the current 4315 * c->bs by @to would mean to create a loop. 4316 * 4317 * Such a case occurs when appending a BDS to a backing chain. 4318 * For instance, imagine the following chain: --- 454 unchanged lines hidden (view full) --- 4773 ignore_children, NULL, &local_err); 4774 g_slist_free(ignore_children); 4775 if (ret < 0) { 4776 error_report_err(local_err); 4777 goto exit; 4778 } 4779 4780 /* If so, update the backing file path in the image file */ |
4779 if (c->role->update_filename) { 4780 ret = c->role->update_filename(c, base, backing_file_str, 4781 &local_err); | 4781 if (c->klass->update_filename) { 4782 ret = c->klass->update_filename(c, base, backing_file_str, 4783 &local_err); |
4782 if (ret < 0) { 4783 bdrv_abort_perm_update(base); 4784 error_report_err(local_err); 4785 goto exit; 4786 } 4787 } 4788 4789 /* Do the actual switch in the in-memory graph. --- 431 unchanged lines hidden (view full) --- 5221 5222const char *bdrv_get_parent_name(const BlockDriverState *bs) 5223{ 5224 BdrvChild *c; 5225 const char *name; 5226 5227 /* If multiple parents have a name, just pick the first one. */ 5228 QLIST_FOREACH(c, &bs->parents, next_parent) { | 4784 if (ret < 0) { 4785 bdrv_abort_perm_update(base); 4786 error_report_err(local_err); 4787 goto exit; 4788 } 4789 } 4790 4791 /* Do the actual switch in the in-memory graph. --- 431 unchanged lines hidden (view full) --- 5223 5224const char *bdrv_get_parent_name(const BlockDriverState *bs) 5225{ 5226 BdrvChild *c; 5227 const char *name; 5228 5229 /* If multiple parents have a name, just pick the first one. */ 5230 QLIST_FOREACH(c, &bs->parents, next_parent) { |
5229 if (c->role->get_name) { 5230 name = c->role->get_name(c); | 5231 if (c->klass->get_name) { 5232 name = c->klass->get_name(c); |
5231 if (name && *name) { 5232 return name; 5233 } 5234 } 5235 } 5236 5237 return NULL; 5238} --- 342 unchanged lines hidden (view full) --- 5581 if (ret < 0) { 5582 bs->open_flags |= BDRV_O_INACTIVE; 5583 error_setg_errno(errp, -ret, "Could not refresh total sector count"); 5584 return; 5585 } 5586 } 5587 5588 QLIST_FOREACH(parent, &bs->parents, next_parent) { | 5233 if (name && *name) { 5234 return name; 5235 } 5236 } 5237 } 5238 5239 return NULL; 5240} --- 342 unchanged lines hidden (view full) --- 5583 if (ret < 0) { 5584 bs->open_flags |= BDRV_O_INACTIVE; 5585 error_setg_errno(errp, -ret, "Could not refresh total sector count"); 5586 return; 5587 } 5588 } 5589 5590 QLIST_FOREACH(parent, &bs->parents, next_parent) { |
5589 if (parent->role->activate) { 5590 parent->role->activate(parent, &local_err); | 5591 if (parent->klass->activate) { 5592 parent->klass->activate(parent, &local_err); |
5591 if (local_err) { 5592 bs->open_flags |= BDRV_O_INACTIVE; 5593 error_propagate(errp, local_err); 5594 return; 5595 } 5596 } 5597 } 5598} --- 51 unchanged lines hidden (view full) --- 5650 } 5651} 5652 5653static bool bdrv_has_bds_parent(BlockDriverState *bs, bool only_active) 5654{ 5655 BdrvChild *parent; 5656 5657 QLIST_FOREACH(parent, &bs->parents, next_parent) { | 5593 if (local_err) { 5594 bs->open_flags |= BDRV_O_INACTIVE; 5595 error_propagate(errp, local_err); 5596 return; 5597 } 5598 } 5599 } 5600} --- 51 unchanged lines hidden (view full) --- 5652 } 5653} 5654 5655static bool bdrv_has_bds_parent(BlockDriverState *bs, bool only_active) 5656{ 5657 BdrvChild *parent; 5658 5659 QLIST_FOREACH(parent, &bs->parents, next_parent) { |
5658 if (parent->role->parent_is_bds) { | 5660 if (parent->klass->parent_is_bds) { |
5659 BlockDriverState *parent_bs = parent->opaque; 5660 if (!only_active || !(parent_bs->open_flags & BDRV_O_INACTIVE)) { 5661 return true; 5662 } 5663 } 5664 } 5665 5666 return false; --- 22 unchanged lines hidden (view full) --- 5689 if (bs->drv->bdrv_inactivate) { 5690 ret = bs->drv->bdrv_inactivate(bs); 5691 if (ret < 0) { 5692 return ret; 5693 } 5694 } 5695 5696 QLIST_FOREACH(parent, &bs->parents, next_parent) { | 5661 BlockDriverState *parent_bs = parent->opaque; 5662 if (!only_active || !(parent_bs->open_flags & BDRV_O_INACTIVE)) { 5663 return true; 5664 } 5665 } 5666 } 5667 5668 return false; --- 22 unchanged lines hidden (view full) --- 5691 if (bs->drv->bdrv_inactivate) { 5692 ret = bs->drv->bdrv_inactivate(bs); 5693 if (ret < 0) { 5694 return ret; 5695 } 5696 } 5697 5698 QLIST_FOREACH(parent, &bs->parents, next_parent) { |
5697 if (parent->role->inactivate) { 5698 ret = parent->role->inactivate(parent); | 5699 if (parent->klass->inactivate) { 5700 ret = parent->klass->inactivate(parent); |
5699 if (ret < 0) { 5700 return ret; 5701 } 5702 } 5703 } 5704 5705 bs->open_flags |= BDRV_O_INACTIVE; 5706 --- 483 unchanged lines hidden (view full) --- 6190 } 6191 *ignore = g_slist_prepend(*ignore, child); 6192 bdrv_set_aio_context_ignore(child->bs, new_context, ignore); 6193 } 6194 QLIST_FOREACH(child, &bs->parents, next_parent) { 6195 if (g_slist_find(*ignore, child)) { 6196 continue; 6197 } | 5701 if (ret < 0) { 5702 return ret; 5703 } 5704 } 5705 } 5706 5707 bs->open_flags |= BDRV_O_INACTIVE; 5708 --- 483 unchanged lines hidden (view full) --- 6192 } 6193 *ignore = g_slist_prepend(*ignore, child); 6194 bdrv_set_aio_context_ignore(child->bs, new_context, ignore); 6195 } 6196 QLIST_FOREACH(child, &bs->parents, next_parent) { 6197 if (g_slist_find(*ignore, child)) { 6198 continue; 6199 } |
6198 assert(child->role->set_aio_ctx); | 6200 assert(child->klass->set_aio_ctx); |
6199 *ignore = g_slist_prepend(*ignore, child); | 6201 *ignore = g_slist_prepend(*ignore, child); |
6200 child->role->set_aio_ctx(child, new_context, ignore); | 6202 child->klass->set_aio_ctx(child, new_context, ignore); |
6201 } 6202 6203 bdrv_detach_aio_context(bs); 6204 6205 /* Acquire the new context, if necessary */ 6206 if (qemu_get_aio_context() != new_context) { 6207 aio_context_acquire(new_context); 6208 } --- 23 unchanged lines hidden (view full) --- 6232static bool bdrv_parent_can_set_aio_context(BdrvChild *c, AioContext *ctx, 6233 GSList **ignore, Error **errp) 6234{ 6235 if (g_slist_find(*ignore, c)) { 6236 return true; 6237 } 6238 *ignore = g_slist_prepend(*ignore, c); 6239 | 6203 } 6204 6205 bdrv_detach_aio_context(bs); 6206 6207 /* Acquire the new context, if necessary */ 6208 if (qemu_get_aio_context() != new_context) { 6209 aio_context_acquire(new_context); 6210 } --- 23 unchanged lines hidden (view full) --- 6234static bool bdrv_parent_can_set_aio_context(BdrvChild *c, AioContext *ctx, 6235 GSList **ignore, Error **errp) 6236{ 6237 if (g_slist_find(*ignore, c)) { 6238 return true; 6239 } 6240 *ignore = g_slist_prepend(*ignore, c); 6241 |
6240 /* A BdrvChildRole that doesn't handle AioContext changes cannot 6241 * tolerate any AioContext changes */ 6242 if (!c->role->can_set_aio_ctx) { | 6242 /* 6243 * A BdrvChildClass that doesn't handle AioContext changes cannot 6244 * tolerate any AioContext changes 6245 */ 6246 if (!c->klass->can_set_aio_ctx) { |
6243 char *user = bdrv_child_user_desc(c); 6244 error_setg(errp, "Changing iothreads is not supported by %s", user); 6245 g_free(user); 6246 return false; 6247 } | 6247 char *user = bdrv_child_user_desc(c); 6248 error_setg(errp, "Changing iothreads is not supported by %s", user); 6249 g_free(user); 6250 return false; 6251 } |
6248 if (!c->role->can_set_aio_ctx(c, ctx, ignore, errp)) { | 6252 if (!c->klass->can_set_aio_ctx(c, ctx, ignore, errp)) { |
6249 assert(!errp || *errp); 6250 return false; 6251 } 6252 return true; 6253} 6254 6255bool bdrv_child_can_set_aio_context(BdrvChild *c, AioContext *ctx, 6256 GSList **ignore, Error **errp) --- 369 unchanged lines hidden (view full) --- 6626 generate_json_filename |= backing_overridden; 6627 6628 if (drv->bdrv_gather_child_options) { 6629 /* Some block drivers may not want to present all of their children's 6630 * options, or name them differently from BdrvChild.name */ 6631 drv->bdrv_gather_child_options(bs, opts, backing_overridden); 6632 } else { 6633 QLIST_FOREACH(child, &bs->children, next) { | 6253 assert(!errp || *errp); 6254 return false; 6255 } 6256 return true; 6257} 6258 6259bool bdrv_child_can_set_aio_context(BdrvChild *c, AioContext *ctx, 6260 GSList **ignore, Error **errp) --- 369 unchanged lines hidden (view full) --- 6630 generate_json_filename |= backing_overridden; 6631 6632 if (drv->bdrv_gather_child_options) { 6633 /* Some block drivers may not want to present all of their children's 6634 * options, or name them differently from BdrvChild.name */ 6635 drv->bdrv_gather_child_options(bs, opts, backing_overridden); 6636 } else { 6637 QLIST_FOREACH(child, &bs->children, next) { |
6634 if (child->role == &child_backing && !backing_overridden) { | 6638 if (child->klass == &child_backing && !backing_overridden) { |
6635 /* We can skip the backing BDS if it has not been overridden */ 6636 continue; 6637 } 6638 6639 qdict_put(opts, child->name, 6640 qobject_ref(child->bs->full_open_options)); 6641 } 6642 --- 147 unchanged lines hidden --- | 6639 /* We can skip the backing BDS if it has not been overridden */ 6640 continue; 6641 } 6642 6643 qdict_put(opts, child->name, 6644 qobject_ref(child->bs->full_open_options)); 6645 } 6646 --- 147 unchanged lines hidden --- |