1 /* $NetBSD: udf_strat_sequential.c,v 1.12 2013/10/18 19:56:55 christos Exp $ */ 2 3 /* 4 * Copyright (c) 2006, 2008 Reinoud Zandijk 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 */ 28 29 #include <sys/cdefs.h> 30 #ifndef lint 31 __KERNEL_RCSID(0, "$NetBSD: udf_strat_sequential.c,v 1.12 2013/10/18 19:56:55 christos Exp $"); 32 #endif /* not lint */ 33 34 35 #if defined(_KERNEL_OPT) 36 #include "opt_compat_netbsd.h" 37 #endif 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/sysctl.h> 42 #include <sys/namei.h> 43 #include <sys/proc.h> 44 #include <sys/kernel.h> 45 #include <sys/vnode.h> 46 #include <miscfs/genfs/genfs_node.h> 47 #include <sys/mount.h> 48 #include <sys/buf.h> 49 #include <sys/file.h> 50 #include <sys/device.h> 51 #include <sys/disklabel.h> 52 #include <sys/ioctl.h> 53 #include <sys/malloc.h> 54 #include <sys/dirent.h> 55 #include <sys/stat.h> 56 #include <sys/conf.h> 57 #include <sys/kauth.h> 58 #include <sys/kthread.h> 59 #include <dev/clock_subr.h> 60 61 #include <fs/udf/ecma167-udf.h> 62 #include <fs/udf/udf_mount.h> 63 64 #include "udf.h" 65 #include "udf_subr.h" 66 #include "udf_bswap.h" 67 68 69 #define VTOI(vnode) ((struct udf_node *) vnode->v_data) 70 #define PRIV(ump) ((struct strat_private *) ump->strategy_private) 71 72 /* --------------------------------------------------------------------- */ 73 74 /* BUFQ's */ 75 #define UDF_SHED_MAX 3 76 77 #define UDF_SHED_READING 0 78 #define UDF_SHED_WRITING 1 79 #define UDF_SHED_SEQWRITING 2 80 81 struct strat_private { 82 struct pool desc_pool; /* node descriptors */ 83 84 lwp_t *queue_lwp; 85 kcondvar_t discstrat_cv; /* to wait on */ 86 kmutex_t discstrat_mutex; /* disc strategy */ 87 88 int run_thread; /* thread control */ 89 int cur_queue; 90 91 struct disk_strategy old_strategy_setting; 92 struct bufq_state *queues[UDF_SHED_MAX]; 93 struct timespec last_queued[UDF_SHED_MAX]; 94 }; 95 96 97 /* --------------------------------------------------------------------- */ 98 99 static void 100 udf_wr_nodedscr_callback(struct buf *buf) 101 { 102 struct udf_node *udf_node; 103 104 KASSERT(buf); 105 KASSERT(buf->b_data); 106 107 /* called when write action is done */ 108 DPRINTF(WRITE, ("udf_wr_nodedscr_callback(): node written out\n")); 109 110 udf_node = VTOI(buf->b_vp); 111 if (udf_node == NULL) { 112 putiobuf(buf); 113 printf("udf_wr_node_callback: NULL node?\n"); 114 return; 115 } 116 117 /* XXX right flags to mark dirty again on error? */ 118 if (buf->b_error) { 119 udf_node->i_flags |= IN_MODIFIED | IN_ACCESSED; 120 /* XXX TODO reshedule on error */ 121 } 122 123 /* decrement outstanding_nodedscr */ 124 KASSERT(udf_node->outstanding_nodedscr >= 1); 125 udf_node->outstanding_nodedscr--; 126 if (udf_node->outstanding_nodedscr == 0) { 127 /* first unlock the node */ 128 UDF_UNLOCK_NODE(udf_node, 0); 129 wakeup(&udf_node->outstanding_nodedscr); 130 } 131 132 /* unreference the vnode so it can be recycled */ 133 holdrele(udf_node->vnode); 134 135 putiobuf(buf); 136 } 137 138 /* --------------------------------------------------------------------- */ 139 140 static int 141 udf_create_logvol_dscr_seq(struct udf_strat_args *args) 142 { 143 union dscrptr **dscrptr = &args->dscr; 144 struct udf_mount *ump = args->ump; 145 struct strat_private *priv = PRIV(ump); 146 uint32_t lb_size; 147 148 lb_size = udf_rw32(ump->logical_vol->lb_size); 149 *dscrptr = pool_get(&priv->desc_pool, PR_WAITOK); 150 memset(*dscrptr, 0, lb_size); 151 152 return 0; 153 } 154 155 156 static void 157 udf_free_logvol_dscr_seq(struct udf_strat_args *args) 158 { 159 union dscrptr *dscr = args->dscr; 160 struct udf_mount *ump = args->ump; 161 struct strat_private *priv = PRIV(ump); 162 163 pool_put(&priv->desc_pool, dscr); 164 } 165 166 167 static int 168 udf_read_logvol_dscr_seq(struct udf_strat_args *args) 169 { 170 union dscrptr **dscrptr = &args->dscr; 171 union dscrptr *tmpdscr; 172 struct udf_mount *ump = args->ump; 173 struct long_ad *icb = args->icb; 174 struct strat_private *priv = PRIV(ump); 175 uint32_t lb_size; 176 uint32_t sector, dummy; 177 int error; 178 179 lb_size = udf_rw32(ump->logical_vol->lb_size); 180 181 error = udf_translate_vtop(ump, icb, §or, &dummy); 182 if (error) 183 return error; 184 185 /* try to read in fe/efe */ 186 error = udf_read_phys_dscr(ump, sector, M_UDFTEMP, &tmpdscr); 187 if (error) 188 return error; 189 190 *dscrptr = pool_get(&priv->desc_pool, PR_WAITOK); 191 memcpy(*dscrptr, tmpdscr, lb_size); 192 free(tmpdscr, M_UDFTEMP); 193 194 return 0; 195 } 196 197 198 static int 199 udf_write_logvol_dscr_seq(struct udf_strat_args *args) 200 { 201 union dscrptr *dscr = args->dscr; 202 struct udf_mount *ump = args->ump; 203 struct udf_node *udf_node = args->udf_node; 204 struct long_ad *icb = args->icb; 205 int waitfor = args->waitfor; 206 uint32_t logsectornr, sectornr, dummy; 207 int error, vpart; 208 209 /* 210 * we have to decide if we write it out sequential or at its fixed 211 * position by examining the partition its (to be) written on. 212 */ 213 vpart = udf_rw16(udf_node->loc.loc.part_num); 214 logsectornr = udf_rw32(icb->loc.lb_num); 215 sectornr = 0; 216 if (ump->vtop_tp[vpart] != UDF_VTOP_TYPE_VIRT) { 217 error = udf_translate_vtop(ump, icb, §ornr, &dummy); 218 if (error) 219 goto out; 220 } 221 222 /* add reference to the vnode to prevent recycling */ 223 vhold(udf_node->vnode); 224 225 if (waitfor) { 226 DPRINTF(WRITE, ("udf_write_logvol_dscr: sync write\n")); 227 228 error = udf_write_phys_dscr_sync(ump, udf_node, UDF_C_NODE, 229 dscr, sectornr, logsectornr); 230 } else { 231 DPRINTF(WRITE, ("udf_write_logvol_dscr: no wait, async write\n")); 232 233 error = udf_write_phys_dscr_async(ump, udf_node, UDF_C_NODE, 234 dscr, sectornr, logsectornr, udf_wr_nodedscr_callback); 235 /* will be UNLOCKED in call back */ 236 return error; 237 } 238 239 holdrele(udf_node->vnode); 240 out: 241 udf_node->outstanding_nodedscr--; 242 if (udf_node->outstanding_nodedscr == 0) { 243 UDF_UNLOCK_NODE(udf_node, 0); 244 wakeup(&udf_node->outstanding_nodedscr); 245 } 246 247 return error; 248 } 249 250 /* --------------------------------------------------------------------- */ 251 252 /* 253 * Main file-system specific sheduler. Due to the nature of optical media 254 * sheduling can't be performed in the traditional way. Most OS 255 * implementations i've seen thus read or write a file atomically giving all 256 * kinds of side effects. 257 * 258 * This implementation uses a kernel thread to shedule the queued requests in 259 * such a way that is semi-optimal for optical media; this means aproximately 260 * (R*|(Wr*|Ws*))* since switching between reading and writing is expensive in 261 * time. 262 */ 263 264 static void 265 udf_queuebuf_seq(struct udf_strat_args *args) 266 { 267 struct udf_mount *ump = args->ump; 268 struct buf *nestbuf = args->nestbuf; 269 struct strat_private *priv = PRIV(ump); 270 int queue; 271 int what; 272 273 KASSERT(ump); 274 KASSERT(nestbuf); 275 KASSERT(nestbuf->b_iodone == nestiobuf_iodone); 276 277 what = nestbuf->b_udf_c_type; 278 queue = UDF_SHED_READING; 279 if ((nestbuf->b_flags & B_READ) == 0) { 280 /* writing */ 281 queue = UDF_SHED_SEQWRITING; 282 if (what == UDF_C_ABSOLUTE) 283 queue = UDF_SHED_WRITING; 284 } 285 286 /* use our own sheduler lists for more complex sheduling */ 287 mutex_enter(&priv->discstrat_mutex); 288 bufq_put(priv->queues[queue], nestbuf); 289 vfs_timestamp(&priv->last_queued[queue]); 290 mutex_exit(&priv->discstrat_mutex); 291 292 /* signal our thread that there might be something to do */ 293 cv_signal(&priv->discstrat_cv); 294 } 295 296 /* --------------------------------------------------------------------- */ 297 298 /* TODO convert to lb_size */ 299 static void 300 udf_VAT_mapping_update(struct udf_mount *ump, struct buf *buf, uint32_t lb_map) 301 { 302 union dscrptr *fdscr = (union dscrptr *) buf->b_data; 303 struct vnode *vp = buf->b_vp; 304 struct udf_node *udf_node = VTOI(vp); 305 uint32_t lb_num; 306 uint32_t udf_rw32_lbmap; 307 int c_type = buf->b_udf_c_type; 308 int error; 309 310 /* only interested when we're using a VAT */ 311 KASSERT(ump->vat_node); 312 KASSERT(ump->vtop_alloc[ump->node_part] == UDF_ALLOC_VAT); 313 314 /* only nodes are recorded in the VAT */ 315 /* NOTE: and the fileset descriptor (FIXME ?) */ 316 if (c_type != UDF_C_NODE) 317 return; 318 319 udf_rw32_lbmap = udf_rw32(lb_map); 320 321 /* if we're the VAT itself, only update our assigned sector number */ 322 if (udf_node == ump->vat_node) { 323 fdscr->tag.tag_loc = udf_rw32_lbmap; 324 udf_validate_tag_sum(fdscr); 325 DPRINTF(TRANSLATE, ("VAT assigned to sector %u\n", 326 udf_rw32(udf_rw32_lbmap))); 327 /* no use mapping the VAT node in the VAT */ 328 return; 329 } 330 331 /* record new position in VAT file */ 332 lb_num = udf_rw32(fdscr->tag.tag_loc); 333 334 /* lb_num = udf_rw32(udf_node->write_loc.loc.lb_num); */ 335 336 DPRINTF(TRANSLATE, ("VAT entry change (log %u -> phys %u)\n", 337 lb_num, lb_map)); 338 339 /* VAT should be the longer than this write, can't go wrong */ 340 KASSERT(lb_num <= ump->vat_entries); 341 342 mutex_enter(&ump->allocate_mutex); 343 error = udf_vat_write(ump->vat_node, 344 (uint8_t *) &udf_rw32_lbmap, 4, 345 ump->vat_offset + lb_num * 4); 346 mutex_exit(&ump->allocate_mutex); 347 348 if (error) 349 panic( "udf_VAT_mapping_update: HELP! i couldn't " 350 "write in the VAT file ?\n"); 351 } 352 353 354 static void 355 udf_issue_buf(struct udf_mount *ump, int queue, struct buf *buf) 356 { 357 union dscrptr *dscr; 358 struct long_ad *node_ad_cpy; 359 struct part_desc *pdesc; 360 uint64_t *lmapping, *lmappos; 361 uint32_t sectornr, bpos; 362 uint32_t ptov; 363 uint16_t vpart_num; 364 uint8_t *fidblk; 365 int sector_size = ump->discinfo.sector_size; 366 int blks = sector_size / DEV_BSIZE; 367 int len, buf_len; 368 369 /* if reading, just pass to the device's STRATEGY */ 370 if (queue == UDF_SHED_READING) { 371 DPRINTF(SHEDULE, ("\nudf_issue_buf READ %p : sector %d type %d," 372 "b_resid %d, b_bcount %d, b_bufsize %d\n", 373 buf, (uint32_t) buf->b_blkno / blks, buf->b_udf_c_type, 374 buf->b_resid, buf->b_bcount, buf->b_bufsize)); 375 VOP_STRATEGY(ump->devvp, buf); 376 return; 377 } 378 379 if (queue == UDF_SHED_WRITING) { 380 DPRINTF(SHEDULE, ("\nudf_issue_buf WRITE %p : sector %d " 381 "type %d, b_resid %d, b_bcount %d, b_bufsize %d\n", 382 buf, (uint32_t) buf->b_blkno / blks, buf->b_udf_c_type, 383 buf->b_resid, buf->b_bcount, buf->b_bufsize)); 384 KASSERT(buf->b_udf_c_type == UDF_C_ABSOLUTE); 385 386 // udf_fixup_node_internals(ump, buf->b_data, buf->b_udf_c_type); 387 VOP_STRATEGY(ump->devvp, buf); 388 return; 389 } 390 391 KASSERT(queue == UDF_SHED_SEQWRITING); 392 DPRINTF(SHEDULE, ("\nudf_issue_buf SEQWRITE %p : sector XXXX " 393 "type %d, b_resid %d, b_bcount %d, b_bufsize %d\n", 394 buf, buf->b_udf_c_type, buf->b_resid, buf->b_bcount, 395 buf->b_bufsize)); 396 397 /* 398 * Buffers should not have been allocated to disc addresses yet on 399 * this queue. Note that a buffer can get multiple extents allocated. 400 * 401 * lmapping contains lb_num relative to base partition. 402 */ 403 lmapping = ump->la_lmapping; 404 node_ad_cpy = ump->la_node_ad_cpy; 405 406 /* logically allocate buf and map it in the file */ 407 udf_late_allocate_buf(ump, buf, lmapping, node_ad_cpy, &vpart_num); 408 409 /* 410 * NOTE We are using the knowledge here that sequential media will 411 * always be mapped linearly. Thus no use to explicitly translate the 412 * lmapping list. 413 */ 414 415 /* calculate offset from physical base partition */ 416 pdesc = ump->partitions[ump->vtop[vpart_num]]; 417 ptov = udf_rw32(pdesc->start_loc); 418 419 /* set buffers blkno to the physical block number */ 420 buf->b_blkno = (*lmapping + ptov) * blks; 421 422 /* fixate floating descriptors */ 423 if (buf->b_udf_c_type == UDF_C_FLOAT_DSCR) { 424 /* set our tag location to the absolute position */ 425 dscr = (union dscrptr *) buf->b_data; 426 dscr->tag.tag_loc = udf_rw32(*lmapping + ptov); 427 udf_validate_tag_and_crc_sums(dscr); 428 } 429 430 /* update mapping in the VAT */ 431 if (buf->b_udf_c_type == UDF_C_NODE) { 432 udf_VAT_mapping_update(ump, buf, *lmapping); 433 udf_fixup_node_internals(ump, buf->b_data, buf->b_udf_c_type); 434 } 435 436 /* if we have FIDs, fixup using the new allocation table */ 437 if (buf->b_udf_c_type == UDF_C_FIDS) { 438 buf_len = buf->b_bcount; 439 bpos = 0; 440 lmappos = lmapping; 441 while (buf_len) { 442 sectornr = *lmappos++; 443 len = MIN(buf_len, sector_size); 444 fidblk = (uint8_t *) buf->b_data + bpos; 445 udf_fixup_fid_block(fidblk, sector_size, 446 0, len, sectornr); 447 bpos += len; 448 buf_len -= len; 449 } 450 } 451 452 VOP_STRATEGY(ump->devvp, buf); 453 } 454 455 456 static void 457 udf_doshedule(struct udf_mount *ump) 458 { 459 struct buf *buf; 460 struct timespec now, *last; 461 struct strat_private *priv = PRIV(ump); 462 void (*b_callback)(struct buf *); 463 int new_queue; 464 int error; 465 466 buf = bufq_get(priv->queues[priv->cur_queue]); 467 if (buf) { 468 /* transfer from the current queue to the device queue */ 469 mutex_exit(&priv->discstrat_mutex); 470 471 /* transform buffer to synchronous; XXX needed? */ 472 b_callback = buf->b_iodone; 473 buf->b_iodone = NULL; 474 CLR(buf->b_flags, B_ASYNC); 475 476 /* issue and wait on completion */ 477 udf_issue_buf(ump, priv->cur_queue, buf); 478 biowait(buf); 479 480 mutex_enter(&priv->discstrat_mutex); 481 482 /* if there is an error, repair this error, otherwise propagate */ 483 if (buf->b_error && ((buf->b_flags & B_READ) == 0)) { 484 /* check what we need to do */ 485 panic("UDF write error, can't handle yet!\n"); 486 } 487 488 /* propagate result to higher layers */ 489 if (b_callback) { 490 buf->b_iodone = b_callback; 491 (*buf->b_iodone)(buf); 492 } 493 494 return; 495 } 496 497 /* Check if we're idling in this state */ 498 vfs_timestamp(&now); 499 last = &priv->last_queued[priv->cur_queue]; 500 if (ump->discinfo.mmc_class == MMC_CLASS_CD) { 501 /* dont switch too fast for CD media; its expensive in time */ 502 if (now.tv_sec - last->tv_sec < 3) 503 return; 504 } 505 506 /* check if we can/should switch */ 507 new_queue = priv->cur_queue; 508 509 if (bufq_peek(priv->queues[UDF_SHED_READING])) 510 new_queue = UDF_SHED_READING; 511 if (bufq_peek(priv->queues[UDF_SHED_WRITING])) /* only for unmount */ 512 new_queue = UDF_SHED_WRITING; 513 if (bufq_peek(priv->queues[UDF_SHED_SEQWRITING])) 514 new_queue = UDF_SHED_SEQWRITING; 515 if (priv->cur_queue == UDF_SHED_READING) { 516 if (new_queue == UDF_SHED_SEQWRITING) { 517 /* TODO use flag to signal if this is needed */ 518 mutex_exit(&priv->discstrat_mutex); 519 520 /* update trackinfo for data and metadata */ 521 error = udf_update_trackinfo(ump, 522 &ump->data_track); 523 assert(error == 0); 524 error = udf_update_trackinfo(ump, 525 &ump->metadata_track); 526 assert(error == 0); 527 mutex_enter(&priv->discstrat_mutex); 528 } 529 } 530 531 if (new_queue != priv->cur_queue) { 532 DPRINTF(SHEDULE, ("switching from %d to %d\n", 533 priv->cur_queue, new_queue)); 534 } 535 536 priv->cur_queue = new_queue; 537 } 538 539 540 static void 541 udf_discstrat_thread(void *arg) 542 { 543 struct udf_mount *ump = (struct udf_mount *) arg; 544 struct strat_private *priv = PRIV(ump); 545 int empty; 546 547 empty = 1; 548 mutex_enter(&priv->discstrat_mutex); 549 while (priv->run_thread || !empty) { 550 /* process the current selected queue */ 551 udf_doshedule(ump); 552 empty = (bufq_peek(priv->queues[UDF_SHED_READING]) == NULL); 553 empty &= (bufq_peek(priv->queues[UDF_SHED_WRITING]) == NULL); 554 empty &= (bufq_peek(priv->queues[UDF_SHED_SEQWRITING]) == NULL); 555 556 /* wait for more if needed */ 557 if (empty) 558 cv_timedwait(&priv->discstrat_cv, 559 &priv->discstrat_mutex, hz/8); 560 } 561 mutex_exit(&priv->discstrat_mutex); 562 563 wakeup(&priv->run_thread); 564 kthread_exit(0); 565 /* not reached */ 566 } 567 568 /* --------------------------------------------------------------------- */ 569 570 static void 571 udf_discstrat_init_seq(struct udf_strat_args *args) 572 { 573 struct udf_mount *ump = args->ump; 574 struct strat_private *priv = PRIV(ump); 575 struct disk_strategy dkstrat; 576 uint32_t lb_size; 577 578 KASSERT(ump); 579 KASSERT(ump->logical_vol); 580 KASSERT(priv == NULL); 581 582 lb_size = udf_rw32(ump->logical_vol->lb_size); 583 KASSERT(lb_size > 0); 584 585 /* initialise our memory space */ 586 ump->strategy_private = malloc(sizeof(struct strat_private), 587 M_UDFTEMP, M_WAITOK); 588 priv = ump->strategy_private; 589 memset(priv, 0 , sizeof(struct strat_private)); 590 591 /* initialise locks */ 592 cv_init(&priv->discstrat_cv, "udfstrat"); 593 mutex_init(&priv->discstrat_mutex, MUTEX_DEFAULT, IPL_NONE); 594 595 /* 596 * Initialise pool for descriptors associated with nodes. This is done 597 * in lb_size units though currently lb_size is dictated to be 598 * sector_size. 599 */ 600 pool_init(&priv->desc_pool, lb_size, 0, 0, 0, "udf_desc_pool", NULL, 601 IPL_NONE); 602 603 /* 604 * remember old device strategy method and explicit set method 605 * `discsort' since we have our own more complex strategy that is not 606 * implementable on the CD device and other strategies will get in the 607 * way. 608 */ 609 memset(&priv->old_strategy_setting, 0, 610 sizeof(struct disk_strategy)); 611 VOP_IOCTL(ump->devvp, DIOCGSTRATEGY, &priv->old_strategy_setting, 612 FREAD | FKIOCTL, NOCRED); 613 memset(&dkstrat, 0, sizeof(struct disk_strategy)); 614 strcpy(dkstrat.dks_name, "discsort"); 615 VOP_IOCTL(ump->devvp, DIOCSSTRATEGY, &dkstrat, FWRITE | FKIOCTL, 616 NOCRED); 617 618 /* initialise our internal sheduler */ 619 priv->cur_queue = UDF_SHED_READING; 620 bufq_alloc(&priv->queues[UDF_SHED_READING], "disksort", 621 BUFQ_SORT_RAWBLOCK); 622 bufq_alloc(&priv->queues[UDF_SHED_WRITING], "disksort", 623 BUFQ_SORT_RAWBLOCK); 624 bufq_alloc(&priv->queues[UDF_SHED_SEQWRITING], "fcfs", 0); 625 vfs_timestamp(&priv->last_queued[UDF_SHED_READING]); 626 vfs_timestamp(&priv->last_queued[UDF_SHED_WRITING]); 627 vfs_timestamp(&priv->last_queued[UDF_SHED_SEQWRITING]); 628 629 /* create our disk strategy thread */ 630 priv->run_thread = 1; 631 if (kthread_create(PRI_NONE, 0 /* KTHREAD_MPSAFE*/, NULL /* cpu_info*/, 632 udf_discstrat_thread, ump, &priv->queue_lwp, 633 "%s", "udf_rw")) { 634 panic("fork udf_rw"); 635 } 636 } 637 638 639 static void 640 udf_discstrat_finish_seq(struct udf_strat_args *args) 641 { 642 struct udf_mount *ump = args->ump; 643 struct strat_private *priv = PRIV(ump); 644 int error; 645 646 if (ump == NULL) 647 return; 648 649 /* stop our sheduling thread */ 650 KASSERT(priv->run_thread == 1); 651 priv->run_thread = 0; 652 wakeup(priv->queue_lwp); 653 do { 654 error = tsleep(&priv->run_thread, PRIBIO+1, 655 "udfshedfin", hz); 656 } while (error); 657 /* kthread should be finished now */ 658 659 /* set back old device strategy method */ 660 VOP_IOCTL(ump->devvp, DIOCSSTRATEGY, &priv->old_strategy_setting, 661 FWRITE, NOCRED); 662 663 /* destroy our pool */ 664 pool_destroy(&priv->desc_pool); 665 666 mutex_destroy(&priv->discstrat_mutex); 667 cv_destroy(&priv->discstrat_cv); 668 669 /* free our private space */ 670 free(ump->strategy_private, M_UDFTEMP); 671 ump->strategy_private = NULL; 672 } 673 674 /* --------------------------------------------------------------------- */ 675 676 struct udf_strategy udf_strat_sequential = 677 { 678 udf_create_logvol_dscr_seq, 679 udf_free_logvol_dscr_seq, 680 udf_read_logvol_dscr_seq, 681 udf_write_logvol_dscr_seq, 682 udf_queuebuf_seq, 683 udf_discstrat_init_seq, 684 udf_discstrat_finish_seq 685 }; 686 687 688