| 2907 | } |
| 2908 | |
| 2909 | static int |
| 2910 | swapongeom_locked(struct cdev *dev, struct vnode *vp) |
| 2911 | { |
| 2912 | struct g_provider *pp; |
| 2913 | struct g_consumer *cp; |
| 2914 | static struct g_geom *gp; |
| 2915 | struct swdevt *sp; |
| 2916 | u_long nblks; |
| 2917 | int error; |
| 2918 | |
| 2919 | pp = g_dev_getprovider(dev); |
| 2920 | if (pp == NULL) |
| 2921 | return (ENODEV); |
| 2922 | mtx_lock(&sw_dev_mtx); |
| 2923 | TAILQ_FOREACH(sp, &swtailq, sw_list) { |
| 2924 | cp = sp->sw_id; |
| 2925 | if (cp != NULL && cp->provider == pp) { |
| 2926 | mtx_unlock(&sw_dev_mtx); |
| 2927 | return (EBUSY); |
| 2928 | } |
| 2929 | } |
| 2930 | mtx_unlock(&sw_dev_mtx); |
| 2931 | if (gp == NULL) |
| 2932 | gp = g_new_geomf(&g_swap_class, "swap"); |
| 2933 | cp = g_new_consumer(gp); |
| 2934 | cp->index = 1; /* Number of active I/Os, plus one for being active. */ |
| 2935 | cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE; |
| 2936 | g_attach(cp, pp); |
| 2937 | /* |
| 2938 | * XXX: Every time you think you can improve the margin for |
| 2939 | * footshooting, somebody depends on the ability to do so: |
| 2940 | * savecore(8) wants to write to our swapdev so we cannot |
| 2941 | * set an exclusive count :-( |
| 2942 | */ |
| 2943 | error = g_access(cp, 1, 1, 0); |
| 2944 | if (error != 0) { |
| 2945 | g_detach(cp); |
| 2946 | g_destroy_consumer(cp); |
| 2947 | return (error); |
| 2948 | } |
| 2949 | nblks = pp->mediasize / DEV_BSIZE; |
| 2950 | swaponsomething(vp, cp, nblks, swapgeom_strategy, |
| 2951 | swapgeom_close, dev2udev(dev), |
| 2952 | (pp->flags & G_PF_ACCEPT_UNMAPPED) != 0 ? SW_UNMAPPED : 0); |
| 2953 | return (0); |
| 2954 | } |
| 2955 | |
| 2956 | static int |
| 2957 | swapongeom(struct vnode *vp) |
no test coverage detected