block.c (4c265bf9f434d4b47f42e3c079adc205b7625ad6) block.c (7c8eece45b10fc9b716850345118ed6fa8d17887)
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

--- 2856 unchanged lines hidden (view full) ---

2865BlockDriverState *bdrv_next_node(BlockDriverState *bs)
2866{
2867 if (!bs) {
2868 return QTAILQ_FIRST(&graph_bdrv_states);
2869 }
2870 return QTAILQ_NEXT(bs, node_list);
2871}
2872
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

--- 2856 unchanged lines hidden (view full) ---

2865BlockDriverState *bdrv_next_node(BlockDriverState *bs)
2866{
2867 if (!bs) {
2868 return QTAILQ_FIRST(&graph_bdrv_states);
2869 }
2870 return QTAILQ_NEXT(bs, node_list);
2871}
2872
2873/* Iterates over all top-level BlockDriverStates, i.e. BDSs that are owned by
2874 * the monitor or attached to a BlockBackend */
2875BlockDriverState *bdrv_next(BlockDriverState *bs)
2876{
2877 if (!bs || bs->blk) {
2878 bs = blk_next_root_bs(bs);
2879 if (bs) {
2880 return bs;
2881 }
2882 }
2883
2884 /* Ignore all BDSs that are attached to a BlockBackend here; they have been
2885 * handled by the above block already */
2886 do {
2887 bs = bdrv_next_monitor_owned(bs);
2888 } while (bs && bs->blk);
2889 return bs;
2890}
2891
2892const char *bdrv_get_node_name(const BlockDriverState *bs)
2893{
2894 return bs->node_name;
2895}
2896
2897static const char *bdrv_get_parent_name(const BlockDriverState *bs)
2898{
2899 BdrvChild *c;

--- 315 unchanged lines hidden (view full) ---

3215 bs->open_flags |= BDRV_O_INACTIVE;
3216 error_setg_errno(errp, -ret, "Could not refresh total sector count");
3217 return;
3218 }
3219}
3220
3221void bdrv_invalidate_cache_all(Error **errp)
3222{
2873const char *bdrv_get_node_name(const BlockDriverState *bs)
2874{
2875 return bs->node_name;
2876}
2877
2878static const char *bdrv_get_parent_name(const BlockDriverState *bs)
2879{
2880 BdrvChild *c;

--- 315 unchanged lines hidden (view full) ---

3196 bs->open_flags |= BDRV_O_INACTIVE;
3197 error_setg_errno(errp, -ret, "Could not refresh total sector count");
3198 return;
3199 }
3200}
3201
3202void bdrv_invalidate_cache_all(Error **errp)
3203{
3223 BlockDriverState *bs = NULL;
3204 BlockDriverState *bs;
3224 Error *local_err = NULL;
3205 Error *local_err = NULL;
3206 BdrvNextIterator *it = NULL;
3225
3207
3226 while ((bs = bdrv_next(bs)) != NULL) {
3208 while ((it = bdrv_next(it, &bs)) != NULL) {
3227 AioContext *aio_context = bdrv_get_aio_context(bs);
3228
3229 aio_context_acquire(aio_context);
3230 bdrv_invalidate_cache(bs, &local_err);
3231 aio_context_release(aio_context);
3232 if (local_err) {
3233 error_propagate(errp, local_err);
3234 return;

--- 25 unchanged lines hidden (view full) ---

3260 bs->open_flags |= BDRV_O_INACTIVE;
3261 }
3262 return 0;
3263}
3264
3265int bdrv_inactivate_all(void)
3266{
3267 BlockDriverState *bs = NULL;
3209 AioContext *aio_context = bdrv_get_aio_context(bs);
3210
3211 aio_context_acquire(aio_context);
3212 bdrv_invalidate_cache(bs, &local_err);
3213 aio_context_release(aio_context);
3214 if (local_err) {
3215 error_propagate(errp, local_err);
3216 return;

--- 25 unchanged lines hidden (view full) ---

3242 bs->open_flags |= BDRV_O_INACTIVE;
3243 }
3244 return 0;
3245}
3246
3247int bdrv_inactivate_all(void)
3248{
3249 BlockDriverState *bs = NULL;
3250 BdrvNextIterator *it = NULL;
3268 int ret = 0;
3269 int pass;
3270
3251 int ret = 0;
3252 int pass;
3253
3271 while ((bs = bdrv_next(bs)) != NULL) {
3254 while ((it = bdrv_next(it, &bs)) != NULL) {
3272 aio_context_acquire(bdrv_get_aio_context(bs));
3273 }
3274
3275 /* We do two passes of inactivation. The first pass calls to drivers'
3276 * .bdrv_inactivate callbacks recursively so all cache is flushed to disk;
3277 * the second pass sets the BDRV_O_INACTIVE flag so that no further write
3278 * is allowed. */
3279 for (pass = 0; pass < 2; pass++) {
3255 aio_context_acquire(bdrv_get_aio_context(bs));
3256 }
3257
3258 /* We do two passes of inactivation. The first pass calls to drivers'
3259 * .bdrv_inactivate callbacks recursively so all cache is flushed to disk;
3260 * the second pass sets the BDRV_O_INACTIVE flag so that no further write
3261 * is allowed. */
3262 for (pass = 0; pass < 2; pass++) {
3280 bs = NULL;
3281 while ((bs = bdrv_next(bs)) != NULL) {
3263 it = NULL;
3264 while ((it = bdrv_next(it, &bs)) != NULL) {
3282 ret = bdrv_inactivate_recurse(bs, pass);
3283 if (ret < 0) {
3284 goto out;
3285 }
3286 }
3287 }
3288
3289out:
3265 ret = bdrv_inactivate_recurse(bs, pass);
3266 if (ret < 0) {
3267 goto out;
3268 }
3269 }
3270 }
3271
3272out:
3290 bs = NULL;
3291 while ((bs = bdrv_next(bs)) != NULL) {
3273 it = NULL;
3274 while ((it = bdrv_next(it, &bs)) != NULL) {
3292 aio_context_release(bdrv_get_aio_context(bs));
3293 }
3294
3295 return ret;
3296}
3297
3298/**************************************************************/
3299/* removable device support */

--- 476 unchanged lines hidden (view full) ---

3776}
3777
3778/* This function checks if the candidate is the first non filter bs down it's
3779 * bs chain. Since we don't have pointers to parents it explore all bs chains
3780 * from the top. Some filters can choose not to pass down the recursion.
3781 */
3782bool bdrv_is_first_non_filter(BlockDriverState *candidate)
3783{
3275 aio_context_release(bdrv_get_aio_context(bs));
3276 }
3277
3278 return ret;
3279}
3280
3281/**************************************************************/
3282/* removable device support */

--- 476 unchanged lines hidden (view full) ---

3759}
3760
3761/* This function checks if the candidate is the first non filter bs down it's
3762 * bs chain. Since we don't have pointers to parents it explore all bs chains
3763 * from the top. Some filters can choose not to pass down the recursion.
3764 */
3765bool bdrv_is_first_non_filter(BlockDriverState *candidate)
3766{
3784 BlockDriverState *bs = NULL;
3767 BlockDriverState *bs;
3768 BdrvNextIterator *it = NULL;
3785
3786 /* walk down the bs forest recursively */
3769
3770 /* walk down the bs forest recursively */
3787 while ((bs = bdrv_next(bs)) != NULL) {
3771 while ((it = bdrv_next(it, &bs)) != NULL) {
3788 bool perm;
3789
3790 /* try to recurse in this top level bs */
3791 perm = bdrv_recurse_is_first_non_filter(bs, candidate);
3792
3793 /* candidate is the first non filter */
3794 if (perm) {
3795 return true;

--- 242 unchanged lines hidden ---
3772 bool perm;
3773
3774 /* try to recurse in this top level bs */
3775 perm = bdrv_recurse_is_first_non_filter(bs, candidate);
3776
3777 /* candidate is the first non filter */
3778 if (perm) {
3779 return true;

--- 242 unchanged lines hidden ---