1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/*
* lxc_hostdev.c: VIRLXC hostdev management
*
* Copyright (C) 2006-2007, 2009-2012 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include "lxc_hostdev.h"
#include "virlog.h"
#include "virerror.h"
#include "virhostdev.h"
#define VIR_FROM_THIS VIR_FROM_LXC
VIR_LOG_INIT("lxc.lxc_hostdev");
int
virLXCUpdateActiveUSBHostdevs(virLXCDriver *driver,
virDomainDef *def)
{
virHostdevManager *hostdev_mgr = driver->hostdevMgr;
if (!def->nhostdevs)
return 0;
return virHostdevUpdateActiveUSBDevices(hostdev_mgr,
def->hostdevs, def->nhostdevs,
LXC_DRIVER_NAME, def->name);
}
static int
virLXCPrepareHostUSBDevices(virLXCDriver *driver,
virDomainDef *def)
{
virDomainHostdevDef **hostdevs = def->hostdevs;
int nhostdevs = def->nhostdevs;
const char *dom_name = def->name;
unsigned int flags = 0;
virHostdevManager *hostdev_mgr = driver->hostdevMgr;
return virHostdevPrepareUSBDevices(hostdev_mgr, LXC_DRIVER_NAME, dom_name,
hostdevs, nhostdevs, flags);
}
int virLXCPrepareHostDevices(virLXCDriver *driver,
virDomainDef *def)
{
size_t i;
if (!def->nhostdevs)
return 0;
/* Sanity check for supported configurations only */
for (i = 0; i < def->nhostdevs; i++) {
virDomainHostdevDef *dev = def->hostdevs[i];
switch (dev->mode) {
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
break;
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported hostdev type %1$s"),
virDomainHostdevSubsysTypeToString(dev->source.subsys.type));
return -1;
}
break;
case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
switch (dev->source.caps.type) {
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
break;
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported hostdev type %1$s"),
virDomainHostdevSubsysTypeToString(dev->source.caps.type));
return -1;
}
break;
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported hostdev mode %1$s"),
virDomainHostdevModeTypeToString(dev->mode));
return -1;
}
}
if (virLXCPrepareHostUSBDevices(driver, def) < 0)
return -1;
return 0;
}
static void
virLXCDomainReAttachHostUSBDevices(virLXCDriver *driver,
const char *name,
virDomainHostdevDef **hostdevs,
int nhostdevs)
{
virHostdevManager *hostdev_mgr = driver->hostdevMgr;
virHostdevReAttachUSBDevices(hostdev_mgr, LXC_DRIVER_NAME,
name, hostdevs, nhostdevs);
}
void virLXCDomainReAttachHostDevices(virLXCDriver *driver,
virDomainDef *def)
{
if (!def->nhostdevs)
return;
virLXCDomainReAttachHostUSBDevices(driver, def->name, def->hostdevs,
def->nhostdevs);
}
|