| 167 | } |
| 168 | |
| 169 | static int |
| 170 | iflib_clone_create(struct if_clone *ifc, int unit, caddr_t params) |
| 171 | { |
| 172 | const char *name = ifc_name(ifc); |
| 173 | struct iflib_cloneattach_ctx clctx; |
| 174 | if_ctx_t ctx; |
| 175 | if_pseudo_t ip; |
| 176 | device_t dev; |
| 177 | int rc; |
| 178 | |
| 179 | clctx.cc_ifc = ifc; |
| 180 | clctx.cc_len = 0; |
| 181 | clctx.cc_params = params; |
| 182 | clctx.cc_name = name; |
| 183 | |
| 184 | if (__predict_false(iflib_pseudodev == NULL)) { |
| 185 | /* SYSINIT initialization would panic !?! */ |
| 186 | mtx_lock(&Giant); |
| 187 | iflib_pseudodev = device_add_child(root_bus, "ifpseudo", 0); |
| 188 | mtx_unlock(&Giant); |
| 189 | MPASS(iflib_pseudodev != NULL); |
| 190 | } |
| 191 | ip = iflib_ip_lookup(name); |
| 192 | if (ip == NULL) { |
| 193 | printf("no ip found for %s\n", name); |
| 194 | return (ENOENT); |
| 195 | } |
| 196 | if ((dev = devclass_get_device(ip->ip_dc, unit)) != NULL) { |
| 197 | printf("unit %d allocated\n", unit); |
| 198 | bus_generic_print_child(iflib_pseudodev, dev); |
| 199 | return (EBUSY); |
| 200 | } |
| 201 | PSEUDO_LOCK(); |
| 202 | dev = device_add_child(iflib_pseudodev, name, unit); |
| 203 | device_set_driver(dev, &iflib_pseudodriver); |
| 204 | PSEUDO_UNLOCK(); |
| 205 | device_quiet(dev); |
| 206 | rc = device_attach(dev); |
| 207 | MPASS(rc == 0); |
| 208 | MPASS(dev != NULL); |
| 209 | MPASS(devclass_get_device(ip->ip_dc, unit) == dev); |
| 210 | rc = iflib_pseudo_register(dev, ip->ip_sctx, &ctx, &clctx); |
| 211 | if (rc) { |
| 212 | mtx_lock(&Giant); |
| 213 | device_delete_child(iflib_pseudodev, dev); |
| 214 | mtx_unlock(&Giant); |
| 215 | } else |
| 216 | device_set_softc(dev, ctx); |
| 217 | |
| 218 | return (rc); |
| 219 | } |
| 220 | |
| 221 | static void |
| 222 | iflib_clone_destroy(if_t ifp) |
nothing calls this directly
no test coverage detected