1 /*
2 * Copyright (C) 2011
3 * Author Roger Pau Monne <roger.pau@entel.upc.edu>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; version 2.1 only. with the special
8 * exception on linking described in file LICENSE.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 */
15
16 #include "libxl_osdeps.h" /* must come before any other headers */
17
18 #include "libxl_internal.h"
19
libxl__try_phy_backend(mode_t st_mode)20 int libxl__try_phy_backend(mode_t st_mode)
21 {
22 if (S_ISREG(st_mode) || S_ISBLK(st_mode))
23 return 1;
24
25 return 0;
26 }
27
libxl__devid_to_localdev(libxl__gc * gc,int devid)28 char *libxl__devid_to_localdev(libxl__gc *gc, int devid)
29 {
30 /* TODO */
31 return NULL;
32 }
33
34 /* Hotplug scripts caller functions */
libxl__hotplug(libxl__gc * gc,libxl__device * dev,char *** args,libxl__device_action action)35 static int libxl__hotplug(libxl__gc *gc, libxl__device *dev, char ***args,
36 libxl__device_action action)
37 {
38 char *be_path = libxl__device_backend_path(gc, dev);
39 char *script;
40 int nr = 0, rc = 0, arraysize = 4;
41
42 script = libxl__xs_read(gc, XBT_NULL,
43 GCSPRINTF("%s/%s", be_path, "script"));
44 if (!script) {
45 LOGEVD(ERROR, errno, dev->domid,
46 "unable to read script from %s", be_path);
47 rc = ERROR_FAIL;
48 goto out;
49 }
50
51 GCNEW_ARRAY(*args, arraysize);
52 (*args)[nr++] = script;
53 (*args)[nr++] = be_path;
54 (*args)[nr++] = GCSPRINTF("%d", action == LIBXL__DEVICE_ACTION_ADD ?
55 XenbusStateInitWait : XenbusStateClosed);
56 (*args)[nr++] = NULL;
57 assert(nr == arraysize);
58
59 out:
60 return rc;
61 }
62
libxl__get_hotplug_script_info(libxl__gc * gc,libxl__device * dev,char *** args,char *** env,libxl__device_action action,int num_exec)63 int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
64 char ***args, char ***env,
65 libxl__device_action action,
66 int num_exec)
67 {
68 int rc;
69
70 switch (dev->backend_kind) {
71 case LIBXL__DEVICE_KIND_VBD:
72 if (num_exec != 0) {
73 LOGD(DEBUG, dev->domid,
74 "num_exec %d, not running hotplug scripts", num_exec);
75 rc = 0;
76 goto out;
77 }
78 rc = libxl__hotplug(gc, dev, args, action);
79 if (!rc) rc = 1;
80 break;
81 case LIBXL__DEVICE_KIND_VIF:
82 /*
83 * If domain has a stubdom we don't have to execute hotplug scripts
84 * for emulated interfaces
85 *
86 * NetBSD let QEMU call a script to plug emulated nic, so
87 * only test if num_exec == 0 in that case.
88 */
89 if ((num_exec != 0) ||
90 (libxl_get_stubdom_id(CTX, dev->domid) && num_exec)) {
91 LOGD(DEBUG, dev->domid,
92 "num_exec %d, not running hotplug scripts", num_exec);
93 rc = 0;
94 goto out;
95 }
96 rc = libxl__hotplug(gc, dev, args, action);
97 if (!rc) rc = 1;
98 break;
99 default:
100 /* If no need to execute any hotplug scripts,
101 * call the callback manually
102 */
103 rc = 0;
104 break;
105 }
106
107 out:
108 return rc;
109 }
110
libxl__default_device_model(libxl__gc * gc)111 libxl_device_model_version libxl__default_device_model(libxl__gc *gc)
112 {
113 return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
114 }
115
libxl__pci_numdevs(libxl__gc * gc)116 int libxl__pci_numdevs(libxl__gc *gc)
117 {
118 return ERROR_NI;
119 }
120
libxl__pci_topology_init(libxl__gc * gc,physdev_pci_device_t * devs,int num_devs)121 int libxl__pci_topology_init(libxl__gc *gc,
122 physdev_pci_device_t *devs,
123 int num_devs)
124 {
125 return ERROR_NI;
126 }
127
libxl__local_dm_preexec_restrict(libxl__gc * gc)128 int libxl__local_dm_preexec_restrict(libxl__gc *gc)
129 {
130 return 0;
131 }
132