Statistics
| Branch: | Revision:

root / hw / device-hotplug.c @ 2ba2d706

History | View | Annotate | Download (2.5 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 6f338c34 aliguori
int add_init_drive(const char *opts)
32 6f338c34 aliguori
{
33 6f338c34 aliguori
    int drive_opt_idx, drive_idx;
34 6f338c34 aliguori
    int ret = -1;
35 6f338c34 aliguori
36 6f338c34 aliguori
    drive_opt_idx = drive_add(NULL, "%s", opts);
37 6f338c34 aliguori
    if (!drive_opt_idx)
38 6f338c34 aliguori
        return ret;
39 6f338c34 aliguori
40 6f338c34 aliguori
    drive_idx = drive_init(&drives_opt[drive_opt_idx], 0, current_machine);
41 6f338c34 aliguori
    if (drive_idx == -1) {
42 6f338c34 aliguori
        drive_remove(drive_opt_idx);
43 6f338c34 aliguori
        return ret;
44 6f338c34 aliguori
    }
45 6f338c34 aliguori
46 6f338c34 aliguori
    return drive_idx;
47 6f338c34 aliguori
}
48 6f338c34 aliguori
49 6f338c34 aliguori
void destroy_nic(dev_match_fn *match_fn, void *arg)
50 6f338c34 aliguori
{
51 6f338c34 aliguori
    int i;
52 6f338c34 aliguori
    NICInfo *nic;
53 6f338c34 aliguori
54 9a40611c aliguori
    for (i = 0; i < MAX_NICS; i++) {
55 6f338c34 aliguori
        nic = &nd_table[i];
56 6f338c34 aliguori
        if (nic->used) {
57 6f338c34 aliguori
            if (nic->private && match_fn(nic->private, arg)) {
58 6f338c34 aliguori
                if (nic->vlan) {
59 6f338c34 aliguori
                    VLANClientState *vc;
60 6f338c34 aliguori
                    vc = qemu_find_vlan_client(nic->vlan, nic->private);
61 6f338c34 aliguori
                    if (vc)
62 6f338c34 aliguori
                        qemu_del_vlan_client(vc);
63 6f338c34 aliguori
                }
64 6f338c34 aliguori
                net_client_uninit(nic);
65 6f338c34 aliguori
            }
66 6f338c34 aliguori
        }
67 9a40611c aliguori
    }
68 6f338c34 aliguori
}
69 6f338c34 aliguori
70 6f338c34 aliguori
void destroy_bdrvs(dev_match_fn *match_fn, void *arg)
71 6f338c34 aliguori
{
72 6f338c34 aliguori
    int i;
73 6f338c34 aliguori
    struct BlockDriverState *bs;
74 6f338c34 aliguori
75 6f338c34 aliguori
    for (i = 0; i <= MAX_DRIVES; i++) {
76 6f338c34 aliguori
        bs = drives_table[i].bdrv;
77 6f338c34 aliguori
        if (bs) {
78 6f338c34 aliguori
            if (bs->private && match_fn(bs->private, arg)) {
79 6f338c34 aliguori
                drive_uninit(bs);
80 6f338c34 aliguori
                bdrv_delete(bs);
81 6f338c34 aliguori
            }
82 6f338c34 aliguori
        }
83 6f338c34 aliguori
    }
84 6f338c34 aliguori
}
85 6f338c34 aliguori