1/*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
--- 18 unchanged lines hidden (view full) ---
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * $FreeBSD: head/sys/geom/geom_disk.c 110052 2003-01-29 19:47:25Z phk $
36 */
37
38#include "opt_geom.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/sysctl.h>
44#include <sys/bio.h>
45#include <sys/conf.h>
46#include <sys/disk.h>
--- 14 unchanged lines hidden (view full) ---
61 "DISK",
62 NULL,
63 NULL,
64 G_CLASS_INITIALIZER
65};
66
67DECLARE_GEOM_CLASS(g_disk_class, g_disk);
68
69static void __inline
70g_disk_lock_giant(struct disk *dp)
71{
72 if (!(dp->d_devsw->d_flags & D_NOGIANT))
73 mtx_lock(&Giant);
74}
75
76static void __inline
77g_disk_unlock_giant(struct disk *dp)
78{
79 if (!(dp->d_devsw->d_flags & D_NOGIANT))
80 mtx_unlock(&Giant);
81}
82
83static int
84g_disk_access(struct g_provider *pp, int r, int w, int e)
85{
86 struct disk *dp;
87 dev_t dev;
88 int error;
89
90 g_trace(G_T_ACCESS, "g_disk_access(%s, %d, %d, %d)",
91 pp->name, r, w, e);
92 g_topology_assert();
93 r += pp->acr;
94 w += pp->acw;
95 e += pp->ace;
96 dp = pp->geom->softc;
97 dev = dp->d_dev;
98 if ((pp->acr + pp->acw + pp->ace) == 0 && (r + w + e) > 0) {
99 g_disk_lock_giant(dp);
100 error = devsw(dev)->d_open(dev, 3, 0, NULL);
101 if (error != 0)
102 printf("Opened disk %s -> %d\n", pp->name, error);
103 g_disk_unlock_giant(dp);
104 pp->mediasize = dp->d_mediasize;
105 pp->sectorsize = dp->d_sectorsize;
106 } else if ((pp->acr + pp->acw + pp->ace) > 0 && (r + w + e) == 0) {
107 g_disk_lock_giant(dp);
108 error = devsw(dev)->d_close(dev, 3, 0, NULL);
109 if (error != 0)
110 printf("Closed disk %s -> %d\n", pp->name, error);
111 g_disk_unlock_giant(dp);
112 } else {
113 error = 0;
114 }
115 return (error);
116}
117
118static void
119g_disk_kerneldump(struct bio *bp, struct disk *dp)
--- 14 unchanged lines hidden (view full) ---
134 di.mediasize = gkd->length;
135 error = set_dumper(&di);
136 g_io_deliver(bp, error);
137}
138
139static void
140g_disk_done(struct bio *bp)
141{
142 struct disk *dp;
143
144 dp = bp->bio_caller1;
145 bp->bio_completed = bp->bio_length - bp->bio_resid;
146 if (!(dp->d_devsw->d_flags & D_NOGIANT)) {
147 DROP_GIANT();
148 g_std_done(bp);
149 PICKUP_GIANT();
150 } else {
151 g_std_done(bp);
152 }
153}
154
155static void
156g_disk_start(struct bio *bp)
157{
158 struct bio *bp2;
159 dev_t dev;
160 struct disk *dp;
--- 13 unchanged lines hidden (view full) ---
174 case BIO_READ:
175 case BIO_WRITE:
176 bp2 = g_clone_bio(bp);
177 bp2->bio_done = g_disk_done;
178 bp2->bio_blkno = bp2->bio_offset >> DEV_BSHIFT;
179 bp2->bio_pblkno = bp2->bio_offset / dp->d_sectorsize;
180 bp2->bio_bcount = bp2->bio_length;
181 bp2->bio_dev = dev;
182 bp2->bio_caller1 = dp;
183 g_disk_lock_giant(dp);
184 devsw(dev)->d_strategy(bp2);
185 g_disk_unlock_giant(dp);
186 break;
187 case BIO_GETATTR:
188 if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors))
189 break;
190 else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads))
191 break;
192 else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0))
193 break;
--- 138 unchanged lines hidden (view full) ---
332 error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1);
333 sbuf_delete(sb);
334 return error;
335}
336
337SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NOLOCK, 0, 0,
338 sysctl_disks, "A", "names of available disks");
339
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
--- 18 unchanged lines hidden (view full) ---
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * $FreeBSD: head/sys/geom/geom_disk.c 110052 2003-01-29 19:47:25Z phk $
36 */
37
38#include "opt_geom.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/sysctl.h>
44#include <sys/bio.h>
45#include <sys/conf.h>
46#include <sys/disk.h>
--- 14 unchanged lines hidden (view full) ---
61 "DISK",
62 NULL,
63 NULL,
64 G_CLASS_INITIALIZER
65};
66
67DECLARE_GEOM_CLASS(g_disk_class, g_disk);
68
69static void __inline
70g_disk_lock_giant(struct disk *dp)
71{
72 if (!(dp->d_devsw->d_flags & D_NOGIANT))
73 mtx_lock(&Giant);
74}
75
76static void __inline
77g_disk_unlock_giant(struct disk *dp)
78{
79 if (!(dp->d_devsw->d_flags & D_NOGIANT))
80 mtx_unlock(&Giant);
81}
82
83static int
84g_disk_access(struct g_provider *pp, int r, int w, int e)
85{
86 struct disk *dp;
87 dev_t dev;
88 int error;
89
90 g_trace(G_T_ACCESS, "g_disk_access(%s, %d, %d, %d)",
91 pp->name, r, w, e);
92 g_topology_assert();
93 r += pp->acr;
94 w += pp->acw;
95 e += pp->ace;
96 dp = pp->geom->softc;
97 dev = dp->d_dev;
98 if ((pp->acr + pp->acw + pp->ace) == 0 && (r + w + e) > 0) {
99 g_disk_lock_giant(dp);
100 error = devsw(dev)->d_open(dev, 3, 0, NULL);
101 if (error != 0)
102 printf("Opened disk %s -> %d\n", pp->name, error);
103 g_disk_unlock_giant(dp);
104 pp->mediasize = dp->d_mediasize;
105 pp->sectorsize = dp->d_sectorsize;
106 } else if ((pp->acr + pp->acw + pp->ace) > 0 && (r + w + e) == 0) {
107 g_disk_lock_giant(dp);
108 error = devsw(dev)->d_close(dev, 3, 0, NULL);
109 if (error != 0)
110 printf("Closed disk %s -> %d\n", pp->name, error);
111 g_disk_unlock_giant(dp);
112 } else {
113 error = 0;
114 }
115 return (error);
116}
117
118static void
119g_disk_kerneldump(struct bio *bp, struct disk *dp)
--- 14 unchanged lines hidden (view full) ---
134 di.mediasize = gkd->length;
135 error = set_dumper(&di);
136 g_io_deliver(bp, error);
137}
138
139static void
140g_disk_done(struct bio *bp)
141{
142 struct disk *dp;
143
144 dp = bp->bio_caller1;
145 bp->bio_completed = bp->bio_length - bp->bio_resid;
146 if (!(dp->d_devsw->d_flags & D_NOGIANT)) {
147 DROP_GIANT();
148 g_std_done(bp);
149 PICKUP_GIANT();
150 } else {
151 g_std_done(bp);
152 }
153}
154
155static void
156g_disk_start(struct bio *bp)
157{
158 struct bio *bp2;
159 dev_t dev;
160 struct disk *dp;
--- 13 unchanged lines hidden (view full) ---
174 case BIO_READ:
175 case BIO_WRITE:
176 bp2 = g_clone_bio(bp);
177 bp2->bio_done = g_disk_done;
178 bp2->bio_blkno = bp2->bio_offset >> DEV_BSHIFT;
179 bp2->bio_pblkno = bp2->bio_offset / dp->d_sectorsize;
180 bp2->bio_bcount = bp2->bio_length;
181 bp2->bio_dev = dev;
182 bp2->bio_caller1 = dp;
183 g_disk_lock_giant(dp);
184 devsw(dev)->d_strategy(bp2);
185 g_disk_unlock_giant(dp);
186 break;
187 case BIO_GETATTR:
188 if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors))
189 break;
190 else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads))
191 break;
192 else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0))
193 break;
--- 138 unchanged lines hidden (view full) ---
332 error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1);
333 sbuf_delete(sb);
334 return error;
335}
336
337SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NOLOCK, 0, 0,
338 sysctl_disks, "A", "names of available disks");
339