block.c (c8f6d58edb0defbe1e90d44419ec8ec6d711c341) | block.c (12fa4af61fb2a08b156134c3b6717534c637c995) |
---|---|
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 --- 1869 unchanged lines hidden (view full) --- 1878 } 1879 } 1880} 1881 1882/* 1883 * Sets the backing file link of a BDS. A new reference is created; callers 1884 * which don't need their own reference any more must call bdrv_unref(). 1885 */ | 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 --- 1869 unchanged lines hidden (view full) --- 1878 } 1879 } 1880} 1881 1882/* 1883 * Sets the backing file link of a BDS. A new reference is created; callers 1884 * which don't need their own reference any more must call bdrv_unref(). 1885 */ |
1886void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd) | 1886void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, 1887 Error **errp) |
1887{ 1888 if (backing_hd) { 1889 bdrv_ref(backing_hd); 1890 } 1891 1892 if (bs->backing) { 1893 bdrv_unref_child(bs, bs->backing); 1894 } 1895 1896 if (!backing_hd) { 1897 bs->backing = NULL; 1898 goto out; 1899 } | 1888{ 1889 if (backing_hd) { 1890 bdrv_ref(backing_hd); 1891 } 1892 1893 if (bs->backing) { 1894 bdrv_unref_child(bs, bs->backing); 1895 } 1896 1897 if (!backing_hd) { 1898 bs->backing = NULL; 1899 goto out; 1900 } |
1900 /* FIXME Error handling */ | 1901 |
1901 bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_backing, | 1902 bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_backing, |
1902 &error_abort); | 1903 errp); 1904 if (!bs->backing) { 1905 bdrv_unref(backing_hd); 1906 } |
1903 1904out: 1905 bdrv_refresh_limits(bs, NULL); 1906} 1907 1908/* 1909 * Opens the backing file for a BlockDriverState if not yet open 1910 * --- 67 unchanged lines hidden (view full) --- 1978 bs->open_flags |= BDRV_O_NO_BACKING; 1979 error_prepend(errp, "Could not open backing file: "); 1980 ret = -EINVAL; 1981 goto free_exit; 1982 } 1983 1984 /* Hook up the backing file link; drop our reference, bs owns the 1985 * backing_hd reference now */ | 1907 1908out: 1909 bdrv_refresh_limits(bs, NULL); 1910} 1911 1912/* 1913 * Opens the backing file for a BlockDriverState if not yet open 1914 * --- 67 unchanged lines hidden (view full) --- 1982 bs->open_flags |= BDRV_O_NO_BACKING; 1983 error_prepend(errp, "Could not open backing file: "); 1984 ret = -EINVAL; 1985 goto free_exit; 1986 } 1987 1988 /* Hook up the backing file link; drop our reference, bs owns the 1989 * backing_hd reference now */ |
1986 bdrv_set_backing_hd(bs, backing_hd); | 1990 bdrv_set_backing_hd(bs, backing_hd, &local_err); |
1987 bdrv_unref(backing_hd); | 1991 bdrv_unref(backing_hd); |
1992 if (local_err) { 1993 ret = -EINVAL; 1994 goto free_exit; 1995 } |
|
1988 1989 qdict_del(parent_options, bdref_key); 1990 1991free_exit: 1992 g_free(backing_filename); 1993 QDECREF(tmp_parent_options); 1994 return ret; 1995} --- 817 unchanged lines hidden (view full) --- 2813 assert(QLIST_EMPTY(&bs->dirty_bitmaps)); 2814 2815 if (bs->drv) { 2816 BdrvChild *child, *next; 2817 2818 bs->drv->bdrv_close(bs); 2819 bs->drv = NULL; 2820 | 1996 1997 qdict_del(parent_options, bdref_key); 1998 1999free_exit: 2000 g_free(backing_filename); 2001 QDECREF(tmp_parent_options); 2002 return ret; 2003} --- 817 unchanged lines hidden (view full) --- 2821 assert(QLIST_EMPTY(&bs->dirty_bitmaps)); 2822 2823 if (bs->drv) { 2824 BdrvChild *child, *next; 2825 2826 bs->drv->bdrv_close(bs); 2827 bs->drv = NULL; 2828 |
2821 bdrv_set_backing_hd(bs, NULL); | 2829 bdrv_set_backing_hd(bs, NULL, &error_abort); |
2822 2823 if (bs->file != NULL) { 2824 bdrv_unref_child(bs, bs->file); 2825 bs->file = NULL; 2826 } 2827 2828 QLIST_FOREACH_SAFE(child, &bs->children, next, next) { 2829 /* TODO Remove bdrv_unref() from drivers' close function and use --- 92 unchanged lines hidden (view full) --- 2922void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) 2923{ 2924 assert(!atomic_read(&bs_top->in_flight)); 2925 assert(!atomic_read(&bs_new->in_flight)); 2926 2927 bdrv_ref(bs_top); 2928 2929 change_parent_backing_link(bs_top, bs_new); | 2830 2831 if (bs->file != NULL) { 2832 bdrv_unref_child(bs, bs->file); 2833 bs->file = NULL; 2834 } 2835 2836 QLIST_FOREACH_SAFE(child, &bs->children, next, next) { 2837 /* TODO Remove bdrv_unref() from drivers' close function and use --- 92 unchanged lines hidden (view full) --- 2930void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) 2931{ 2932 assert(!atomic_read(&bs_top->in_flight)); 2933 assert(!atomic_read(&bs_new->in_flight)); 2934 2935 bdrv_ref(bs_top); 2936 2937 change_parent_backing_link(bs_top, bs_new); |
2930 bdrv_set_backing_hd(bs_new, bs_top); | 2938 /* FIXME Error handling */ 2939 bdrv_set_backing_hd(bs_new, bs_top, &error_abort); |
2931 bdrv_unref(bs_top); 2932 2933 /* bs_new is now referenced by its new parents, we don't need the 2934 * additional reference any more. */ 2935 bdrv_unref(bs_new); 2936} 2937 2938void bdrv_replace_in_backing_chain(BlockDriverState *old, BlockDriverState *new) --- 131 unchanged lines hidden (view full) --- 3070 * Error conditions: 3071 * if active == top, that is considered an error 3072 * 3073 */ 3074int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, 3075 BlockDriverState *base, const char *backing_file_str) 3076{ 3077 BlockDriverState *new_top_bs = NULL; | 2940 bdrv_unref(bs_top); 2941 2942 /* bs_new is now referenced by its new parents, we don't need the 2943 * additional reference any more. */ 2944 bdrv_unref(bs_new); 2945} 2946 2947void bdrv_replace_in_backing_chain(BlockDriverState *old, BlockDriverState *new) --- 131 unchanged lines hidden (view full) --- 3079 * Error conditions: 3080 * if active == top, that is considered an error 3081 * 3082 */ 3083int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, 3084 BlockDriverState *base, const char *backing_file_str) 3085{ 3086 BlockDriverState *new_top_bs = NULL; |
3087 Error *local_err = NULL; |
|
3078 int ret = -EIO; 3079 3080 if (!top->drv || !base->drv) { 3081 goto exit; 3082 } 3083 3084 new_top_bs = bdrv_find_overlay(active, top); 3085 --- 16 unchanged lines hidden (view full) --- 3102 3103 /* success - we can delete the intermediate states, and link top->base */ 3104 backing_file_str = backing_file_str ? backing_file_str : base->filename; 3105 ret = bdrv_change_backing_file(new_top_bs, backing_file_str, 3106 base->drv ? base->drv->format_name : ""); 3107 if (ret) { 3108 goto exit; 3109 } | 3088 int ret = -EIO; 3089 3090 if (!top->drv || !base->drv) { 3091 goto exit; 3092 } 3093 3094 new_top_bs = bdrv_find_overlay(active, top); 3095 --- 16 unchanged lines hidden (view full) --- 3112 3113 /* success - we can delete the intermediate states, and link top->base */ 3114 backing_file_str = backing_file_str ? backing_file_str : base->filename; 3115 ret = bdrv_change_backing_file(new_top_bs, backing_file_str, 3116 base->drv ? base->drv->format_name : ""); 3117 if (ret) { 3118 goto exit; 3119 } |
3110 bdrv_set_backing_hd(new_top_bs, base); | |
3111 | 3120 |
3121 bdrv_set_backing_hd(new_top_bs, base, &local_err); 3122 if (local_err) { 3123 ret = -EPERM; 3124 error_report_err(local_err); 3125 goto exit; 3126 } 3127 |
|
3112 ret = 0; 3113exit: 3114 return ret; 3115} 3116 3117/** 3118 * Truncate file to 'offset' bytes (needed only for file protocols) 3119 */ --- 1483 unchanged lines hidden --- | 3128 ret = 0; 3129exit: 3130 return ret; 3131} 3132 3133/** 3134 * Truncate file to 'offset' bytes (needed only for file protocols) 3135 */ --- 1483 unchanged lines hidden --- |