root / hw / device-hotplug.c @ 21eea4b3
History | View | Annotate | Download (2.3 kB)
1 | 6f338c34 | aliguori | /*
|
---|---|---|---|
2 | 6f338c34 | aliguori | * QEMU device hotplug helpers
|
3 | 6f338c34 | aliguori | *
|
4 | 6f338c34 | aliguori | * Copyright (c) 2004 Fabrice Bellard
|
5 | 6f338c34 | aliguori | *
|
6 | 6f338c34 | aliguori | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 6f338c34 | aliguori | * of this software and associated documentation files (the "Software"), to deal
|
8 | 6f338c34 | aliguori | * in the Software without restriction, including without limitation the rights
|
9 | 6f338c34 | aliguori | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 6f338c34 | aliguori | * copies of the Software, and to permit persons to whom the Software is
|
11 | 6f338c34 | aliguori | * furnished to do so, subject to the following conditions:
|
12 | 6f338c34 | aliguori | *
|
13 | 6f338c34 | aliguori | * The above copyright notice and this permission notice shall be included in
|
14 | 6f338c34 | aliguori | * all copies or substantial portions of the Software.
|
15 | 6f338c34 | aliguori | *
|
16 | 6f338c34 | aliguori | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 6f338c34 | aliguori | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 6f338c34 | aliguori | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 6f338c34 | aliguori | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 6f338c34 | aliguori | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 6f338c34 | aliguori | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 6f338c34 | aliguori | * THE SOFTWARE.
|
23 | 6f338c34 | aliguori | */
|
24 | 6f338c34 | aliguori | |
25 | 6f338c34 | aliguori | #include "hw.h" |
26 | 6f338c34 | aliguori | #include "boards.h" |
27 | 6f338c34 | aliguori | #include "net.h" |
28 | 6f338c34 | aliguori | #include "block_int.h" |
29 | 6f338c34 | aliguori | #include "sysemu.h" |
30 | 6f338c34 | aliguori | |
31 | 9dfd7c7a | Gerd Hoffmann | DriveInfo *add_init_drive(const char *optstr) |
32 | 6f338c34 | aliguori | { |
33 | 751c6a17 | Gerd Hoffmann | int fatal_error;
|
34 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
35 | 9dfd7c7a | Gerd Hoffmann | QemuOpts *opts; |
36 | 6f338c34 | aliguori | |
37 | 9dfd7c7a | Gerd Hoffmann | opts = drive_add(NULL, "%s", optstr); |
38 | 9dfd7c7a | Gerd Hoffmann | if (!opts)
|
39 | 751c6a17 | Gerd Hoffmann | return NULL; |
40 | 6f338c34 | aliguori | |
41 | 9dfd7c7a | Gerd Hoffmann | dinfo = drive_init(opts, current_machine, &fatal_error); |
42 | 751c6a17 | Gerd Hoffmann | if (!dinfo) {
|
43 | 9dfd7c7a | Gerd Hoffmann | qemu_opts_del(opts); |
44 | 751c6a17 | Gerd Hoffmann | return NULL; |
45 | 6f338c34 | aliguori | } |
46 | 6f338c34 | aliguori | |
47 | 751c6a17 | Gerd Hoffmann | return dinfo;
|
48 | 6f338c34 | aliguori | } |
49 | 6f338c34 | aliguori | |
50 | 6f338c34 | aliguori | void destroy_nic(dev_match_fn *match_fn, void *arg) |
51 | 6f338c34 | aliguori | { |
52 | 6f338c34 | aliguori | int i;
|
53 | 6f338c34 | aliguori | NICInfo *nic; |
54 | 6f338c34 | aliguori | |
55 | 9a40611c | aliguori | for (i = 0; i < MAX_NICS; i++) { |
56 | 6f338c34 | aliguori | nic = &nd_table[i]; |
57 | 6f338c34 | aliguori | if (nic->used) {
|
58 | 6f338c34 | aliguori | if (nic->private && match_fn(nic->private, arg)) {
|
59 | ae50b274 | Mark McLoughlin | qemu_del_vlan_client(nic->vc); |
60 | 6f338c34 | aliguori | net_client_uninit(nic); |
61 | 6f338c34 | aliguori | } |
62 | 6f338c34 | aliguori | } |
63 | 9a40611c | aliguori | } |
64 | 6f338c34 | aliguori | } |
65 | 6f338c34 | aliguori | |
66 | 6f338c34 | aliguori | void destroy_bdrvs(dev_match_fn *match_fn, void *arg) |
67 | 6f338c34 | aliguori | { |
68 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
69 | 6f338c34 | aliguori | struct BlockDriverState *bs;
|
70 | 6f338c34 | aliguori | |
71 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(dinfo, &drives, next) { |
72 | 751c6a17 | Gerd Hoffmann | bs = dinfo->bdrv; |
73 | 6f338c34 | aliguori | if (bs) {
|
74 | 6f338c34 | aliguori | if (bs->private && match_fn(bs->private, arg)) {
|
75 | 6f338c34 | aliguori | drive_uninit(bs); |
76 | 6f338c34 | aliguori | bdrv_delete(bs); |
77 | 6f338c34 | aliguori | } |
78 | 6f338c34 | aliguori | } |
79 | 6f338c34 | aliguori | } |
80 | 6f338c34 | aliguori | } |
81 | 6f338c34 | aliguori |