Deleted Added
full compact
geom_io.c (93250) geom_io.c (93778)
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 *
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_io.c 93250 2002-03-26 22:07:38Z phk $
35 * $FreeBSD: head/sys/geom/geom_io.c 93778 2002-04-04 09:58:20Z phk $
36 */
37
38
39#include <sys/param.h>
40#ifndef _KERNEL
41#include <stdio.h>
42#include <string.h>
43#include <stdlib.h>

--- 174 unchanged lines hidden (view full) ---

218 if (error == EBUSY)
219 tsleep(&error, 0, "getattr_busy", hz);
220
221 } while(error == EBUSY);
222 return (error);
223}
224
225void
36 */
37
38
39#include <sys/param.h>
40#ifndef _KERNEL
41#include <stdio.h>
42#include <string.h>
43#include <stdlib.h>

--- 174 unchanged lines hidden (view full) ---

218 if (error == EBUSY)
219 tsleep(&error, 0, "getattr_busy", hz);
220
221 } while(error == EBUSY);
222 return (error);
223}
224
225void
226g_io_fail(struct bio *bp, int error)
227{
228
229 bp->bio_error = error;
230
231 g_trace(G_T_BIO,
232 "bio_fail(%p) from %p(%s) to %p(%s) cmd %d error %d\n",
233 bp, bp->bio_from, bp->bio_from->geom->name,
234 bp->bio_to, bp->bio_to->name, bp->bio_cmd, bp->bio_error);
235 g_io_deliver(bp);
236 return;
237}
238
239void
226g_io_request(struct bio *bp, struct g_consumer *cp)
227{
228 int error;
240g_io_request(struct bio *bp, struct g_consumer *cp)
241{
242 int error;
243 off_t excess;
229
230 KASSERT(cp != NULL, ("bio_request on thin air"));
231 error = 0;
232 bp->bio_from = cp;
233 bp->bio_to = cp->provider;
244
245 KASSERT(cp != NULL, ("bio_request on thin air"));
246 error = 0;
247 bp->bio_from = cp;
248 bp->bio_to = cp->provider;
249 bp->bio_error = 0;
250 bp->bio_completed = 0;
234
235 /* begin_stats(&bp->stats); */
236
237 atomic_add_int(&cp->biocount, 1);
251
252 /* begin_stats(&bp->stats); */
253
254 atomic_add_int(&cp->biocount, 1);
255 /* Fail on unattached consumers */
238 if (bp->bio_to == NULL)
256 if (bp->bio_to == NULL)
239 error = ENXIO;
240 if (!error) {
241 switch(bp->bio_cmd) {
242 case BIO_READ:
243 case BIO_GETATTR:
244 if (cp->acr == 0)
245 error = EPERM;
246 break;
247 case BIO_WRITE:
248 if (cp->acw == 0)
249 error = EPERM;
250 break;
251 case BIO_SETATTR:
252 case BIO_DELETE:
253 if ((cp->acw == 0) || (cp->ace == 0))
254 error = EPERM;
255 break;
256 default:
257 error = EPERM;
258 break;
257 return (g_io_fail(bp, ENXIO));
258 /* Fail if access doesn't allow operation */
259 switch(bp->bio_cmd) {
260 case BIO_READ:
261 case BIO_GETATTR:
262 if (cp->acr == 0)
263 return (g_io_fail(bp, EPERM));
264 break;
265 case BIO_WRITE:
266 case BIO_DELETE:
267 if (cp->acw == 0)
268 return (g_io_fail(bp, EPERM));
269 break;
270 case BIO_SETATTR:
271 if ((cp->acw == 0) || (cp->ace == 0))
272 return (g_io_fail(bp, EPERM));
273 break;
274 default:
275 return (g_io_fail(bp, EPERM));
276 }
277 /* if provider is marked for error, don't disturb. */
278 if (bp->bio_to->error)
279 return (g_io_fail(bp, bp->bio_to->error));
280 switch(bp->bio_cmd) {
281 case BIO_READ:
282 case BIO_WRITE:
283 case BIO_DELETE:
284 /* Reject requests past the end of media. */
285 if (bp->bio_offset > bp->bio_to->mediasize)
286 return (g_io_fail(bp, EIO));
287 /* Truncate requests to the end of providers media. */
288 excess = bp->bio_offset + bp->bio_length;
289 if (excess > bp->bio_to->mediasize) {
290 excess -= bp->bio_to->mediasize;
291 bp->bio_length -= excess;
259 }
292 }
293 /* Deliver zero length transfers right here. */
294 if (bp->bio_length == 0)
295 return (g_io_deliver(bp));
296 break;
297 default:
298 break;
260 }
299 }
261 /* if provider is marked for error, don't disturb */
262 if (!error)
263 error = bp->bio_to->error;
264 if (error) {
265 bp->bio_error = error;
266 /* finish_stats(&bp->stats); */
267
268 g_trace(G_T_BIO,
269 "bio_request(%p) from %p(%s) to %p(%s) cmd %d error %d\n",
270 bp, bp->bio_from, bp->bio_from->geom->name,
271 bp->bio_to, bp->bio_to->name, bp->bio_cmd, bp->bio_error);
272 g_bioq_enqueue_tail(bp, &g_bio_run_up);
273 mtx_lock(&Giant);
274 wakeup(&g_wait_up);
275 mtx_unlock(&Giant);
276 } else {
277 g_trace(G_T_BIO, "bio_request(%p) from %p(%s) to %p(%s) cmd %d",
278 bp, bp->bio_from, bp->bio_from->geom->name,
279 bp->bio_to, bp->bio_to->name, bp->bio_cmd);
280 g_bioq_enqueue_tail(bp, &g_bio_run_down);
281 mtx_lock(&Giant);
282 wakeup(&g_wait_down);
283 mtx_unlock(&Giant);
284 }
300 /* Pass it on down. */
301 g_trace(G_T_BIO, "bio_request(%p) from %p(%s) to %p(%s) cmd %d",
302 bp, bp->bio_from, bp->bio_from->geom->name,
303 bp->bio_to, bp->bio_to->name, bp->bio_cmd);
304 g_bioq_enqueue_tail(bp, &g_bio_run_down);
305 mtx_lock(&Giant);
306 wakeup(&g_wait_down);
307 mtx_unlock(&Giant);
285}
286
287void
288g_io_deliver(struct bio *bp)
289{
290
291 g_trace(G_T_BIO,
292 "g_io_deliver(%p) from %p(%s) to %p(%s) cmd %d error %d",

--- 83 unchanged lines hidden ---
308}
309
310void
311g_io_deliver(struct bio *bp)
312{
313
314 g_trace(G_T_BIO,
315 "g_io_deliver(%p) from %p(%s) to %p(%s) cmd %d error %d",

--- 83 unchanged lines hidden ---