xref: /minix3/sys/fs/udf/udf_strat_sequential.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* $NetBSD: udf_strat_sequential.c,v 1.14 2015/10/06 08:57:34 hannken Exp $ */
29f988b79SJean-Baptiste Boric 
39f988b79SJean-Baptiste Boric /*
49f988b79SJean-Baptiste Boric  * Copyright (c) 2006, 2008 Reinoud Zandijk
59f988b79SJean-Baptiste Boric  * All rights reserved.
69f988b79SJean-Baptiste Boric  *
79f988b79SJean-Baptiste Boric  * Redistribution and use in source and binary forms, with or without
89f988b79SJean-Baptiste Boric  * modification, are permitted provided that the following conditions
99f988b79SJean-Baptiste Boric  * are met:
109f988b79SJean-Baptiste Boric  * 1. Redistributions of source code must retain the above copyright
119f988b79SJean-Baptiste Boric  *    notice, this list of conditions and the following disclaimer.
129f988b79SJean-Baptiste Boric  * 2. Redistributions in binary form must reproduce the above copyright
139f988b79SJean-Baptiste Boric  *    notice, this list of conditions and the following disclaimer in the
149f988b79SJean-Baptiste Boric  *    documentation and/or other materials provided with the distribution.
159f988b79SJean-Baptiste Boric  *
169f988b79SJean-Baptiste Boric  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
179f988b79SJean-Baptiste Boric  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
189f988b79SJean-Baptiste Boric  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
199f988b79SJean-Baptiste Boric  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
209f988b79SJean-Baptiste Boric  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
219f988b79SJean-Baptiste Boric  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
229f988b79SJean-Baptiste Boric  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
239f988b79SJean-Baptiste Boric  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
249f988b79SJean-Baptiste Boric  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
259f988b79SJean-Baptiste Boric  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
269f988b79SJean-Baptiste Boric  *
279f988b79SJean-Baptiste Boric  */
289f988b79SJean-Baptiste Boric 
299f988b79SJean-Baptiste Boric #include <sys/cdefs.h>
309f988b79SJean-Baptiste Boric #ifndef lint
31*0a6a1f1dSLionel Sambuc __KERNEL_RCSID(0, "$NetBSD: udf_strat_sequential.c,v 1.14 2015/10/06 08:57:34 hannken Exp $");
329f988b79SJean-Baptiste Boric #endif /* not lint */
339f988b79SJean-Baptiste Boric 
349f988b79SJean-Baptiste Boric 
359f988b79SJean-Baptiste Boric #if defined(_KERNEL_OPT)
369f988b79SJean-Baptiste Boric #include "opt_compat_netbsd.h"
379f988b79SJean-Baptiste Boric #endif
389f988b79SJean-Baptiste Boric 
399f988b79SJean-Baptiste Boric #include <sys/param.h>
409f988b79SJean-Baptiste Boric #include <sys/systm.h>
419f988b79SJean-Baptiste Boric #include <sys/sysctl.h>
429f988b79SJean-Baptiste Boric #include <sys/namei.h>
439f988b79SJean-Baptiste Boric #include <sys/proc.h>
449f988b79SJean-Baptiste Boric #include <sys/kernel.h>
459f988b79SJean-Baptiste Boric #include <sys/vnode.h>
469f988b79SJean-Baptiste Boric #include <miscfs/genfs/genfs_node.h>
479f988b79SJean-Baptiste Boric #include <sys/mount.h>
489f988b79SJean-Baptiste Boric #include <sys/buf.h>
499f988b79SJean-Baptiste Boric #include <sys/file.h>
509f988b79SJean-Baptiste Boric #include <sys/device.h>
519f988b79SJean-Baptiste Boric #include <sys/disklabel.h>
529f988b79SJean-Baptiste Boric #include <sys/ioctl.h>
539f988b79SJean-Baptiste Boric #include <sys/malloc.h>
549f988b79SJean-Baptiste Boric #include <sys/dirent.h>
559f988b79SJean-Baptiste Boric #include <sys/stat.h>
569f988b79SJean-Baptiste Boric #include <sys/conf.h>
579f988b79SJean-Baptiste Boric #include <sys/kauth.h>
589f988b79SJean-Baptiste Boric #include <sys/kthread.h>
599f988b79SJean-Baptiste Boric #include <dev/clock_subr.h>
609f988b79SJean-Baptiste Boric 
619f988b79SJean-Baptiste Boric #include <fs/udf/ecma167-udf.h>
629f988b79SJean-Baptiste Boric #include <fs/udf/udf_mount.h>
639f988b79SJean-Baptiste Boric 
649f988b79SJean-Baptiste Boric #include "udf.h"
659f988b79SJean-Baptiste Boric #include "udf_subr.h"
669f988b79SJean-Baptiste Boric #include "udf_bswap.h"
679f988b79SJean-Baptiste Boric 
689f988b79SJean-Baptiste Boric 
699f988b79SJean-Baptiste Boric #define VTOI(vnode) ((struct udf_node *) vnode->v_data)
709f988b79SJean-Baptiste Boric #define PRIV(ump) ((struct strat_private *) ump->strategy_private)
719f988b79SJean-Baptiste Boric 
729f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
739f988b79SJean-Baptiste Boric 
749f988b79SJean-Baptiste Boric /* BUFQ's */
759f988b79SJean-Baptiste Boric #define UDF_SHED_MAX 3
769f988b79SJean-Baptiste Boric 
779f988b79SJean-Baptiste Boric #define UDF_SHED_READING	0
789f988b79SJean-Baptiste Boric #define UDF_SHED_WRITING	1
799f988b79SJean-Baptiste Boric #define UDF_SHED_SEQWRITING	2
809f988b79SJean-Baptiste Boric 
819f988b79SJean-Baptiste Boric struct strat_private {
829f988b79SJean-Baptiste Boric 	struct pool		 desc_pool;	 	/* node descriptors */
839f988b79SJean-Baptiste Boric 
849f988b79SJean-Baptiste Boric 	lwp_t			*queue_lwp;
859f988b79SJean-Baptiste Boric 	kcondvar_t		 discstrat_cv;		/* to wait on       */
869f988b79SJean-Baptiste Boric 	kmutex_t		 discstrat_mutex;	/* disc strategy    */
879f988b79SJean-Baptiste Boric 
889f988b79SJean-Baptiste Boric 	int			 run_thread;		/* thread control */
899f988b79SJean-Baptiste Boric 	int			 cur_queue;
909f988b79SJean-Baptiste Boric 
919f988b79SJean-Baptiste Boric 	struct disk_strategy	 old_strategy_setting;
929f988b79SJean-Baptiste Boric 	struct bufq_state	*queues[UDF_SHED_MAX];
939f988b79SJean-Baptiste Boric 	struct timespec		 last_queued[UDF_SHED_MAX];
949f988b79SJean-Baptiste Boric };
959f988b79SJean-Baptiste Boric 
969f988b79SJean-Baptiste Boric 
979f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
989f988b79SJean-Baptiste Boric 
999f988b79SJean-Baptiste Boric static void
udf_wr_nodedscr_callback(struct buf * buf)1009f988b79SJean-Baptiste Boric udf_wr_nodedscr_callback(struct buf *buf)
1019f988b79SJean-Baptiste Boric {
1029f988b79SJean-Baptiste Boric 	struct udf_node *udf_node;
1039f988b79SJean-Baptiste Boric 
1049f988b79SJean-Baptiste Boric 	KASSERT(buf);
1059f988b79SJean-Baptiste Boric 	KASSERT(buf->b_data);
1069f988b79SJean-Baptiste Boric 
1079f988b79SJean-Baptiste Boric 	/* called when write action is done */
1089f988b79SJean-Baptiste Boric 	DPRINTF(WRITE, ("udf_wr_nodedscr_callback(): node written out\n"));
1099f988b79SJean-Baptiste Boric 
1109f988b79SJean-Baptiste Boric 	udf_node = VTOI(buf->b_vp);
1119f988b79SJean-Baptiste Boric 	if (udf_node == NULL) {
1129f988b79SJean-Baptiste Boric 		putiobuf(buf);
1139f988b79SJean-Baptiste Boric 		printf("udf_wr_node_callback: NULL node?\n");
1149f988b79SJean-Baptiste Boric 		return;
1159f988b79SJean-Baptiste Boric 	}
1169f988b79SJean-Baptiste Boric 
1179f988b79SJean-Baptiste Boric 	/* XXX right flags to mark dirty again on error? */
1189f988b79SJean-Baptiste Boric 	if (buf->b_error) {
1199f988b79SJean-Baptiste Boric 		udf_node->i_flags |= IN_MODIFIED | IN_ACCESSED;
1209f988b79SJean-Baptiste Boric 		/* XXX TODO reshedule on error */
1219f988b79SJean-Baptiste Boric 	}
1229f988b79SJean-Baptiste Boric 
1239f988b79SJean-Baptiste Boric 	/* decrement outstanding_nodedscr */
1249f988b79SJean-Baptiste Boric 	KASSERT(udf_node->outstanding_nodedscr >= 1);
1259f988b79SJean-Baptiste Boric 	udf_node->outstanding_nodedscr--;
1269f988b79SJean-Baptiste Boric 	if (udf_node->outstanding_nodedscr == 0) {
1279f988b79SJean-Baptiste Boric 		/* first unlock the node */
1289f988b79SJean-Baptiste Boric 		UDF_UNLOCK_NODE(udf_node, 0);
1299f988b79SJean-Baptiste Boric 		wakeup(&udf_node->outstanding_nodedscr);
1309f988b79SJean-Baptiste Boric 	}
1319f988b79SJean-Baptiste Boric 
1329f988b79SJean-Baptiste Boric 	putiobuf(buf);
1339f988b79SJean-Baptiste Boric }
1349f988b79SJean-Baptiste Boric 
1359f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
1369f988b79SJean-Baptiste Boric 
1379f988b79SJean-Baptiste Boric static int
udf_create_logvol_dscr_seq(struct udf_strat_args * args)1389f988b79SJean-Baptiste Boric udf_create_logvol_dscr_seq(struct udf_strat_args *args)
1399f988b79SJean-Baptiste Boric {
1409f988b79SJean-Baptiste Boric 	union dscrptr   **dscrptr = &args->dscr;
1419f988b79SJean-Baptiste Boric 	struct udf_mount *ump = args->ump;
1429f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
1439f988b79SJean-Baptiste Boric 	uint32_t lb_size;
1449f988b79SJean-Baptiste Boric 
1459f988b79SJean-Baptiste Boric 	lb_size = udf_rw32(ump->logical_vol->lb_size);
1469f988b79SJean-Baptiste Boric 	*dscrptr = pool_get(&priv->desc_pool, PR_WAITOK);
1479f988b79SJean-Baptiste Boric 	memset(*dscrptr, 0, lb_size);
1489f988b79SJean-Baptiste Boric 
1499f988b79SJean-Baptiste Boric 	return 0;
1509f988b79SJean-Baptiste Boric }
1519f988b79SJean-Baptiste Boric 
1529f988b79SJean-Baptiste Boric 
1539f988b79SJean-Baptiste Boric static void
udf_free_logvol_dscr_seq(struct udf_strat_args * args)1549f988b79SJean-Baptiste Boric udf_free_logvol_dscr_seq(struct udf_strat_args *args)
1559f988b79SJean-Baptiste Boric {
1569f988b79SJean-Baptiste Boric 	union dscrptr    *dscr = args->dscr;
1579f988b79SJean-Baptiste Boric 	struct udf_mount *ump  = args->ump;
1589f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
1599f988b79SJean-Baptiste Boric 
1609f988b79SJean-Baptiste Boric 	pool_put(&priv->desc_pool, dscr);
1619f988b79SJean-Baptiste Boric }
1629f988b79SJean-Baptiste Boric 
1639f988b79SJean-Baptiste Boric 
1649f988b79SJean-Baptiste Boric static int
udf_read_logvol_dscr_seq(struct udf_strat_args * args)1659f988b79SJean-Baptiste Boric udf_read_logvol_dscr_seq(struct udf_strat_args *args)
1669f988b79SJean-Baptiste Boric {
1679f988b79SJean-Baptiste Boric 	union dscrptr   **dscrptr = &args->dscr;
1689f988b79SJean-Baptiste Boric 	union dscrptr    *tmpdscr;
1699f988b79SJean-Baptiste Boric 	struct udf_mount *ump = args->ump;
1709f988b79SJean-Baptiste Boric 	struct long_ad   *icb = args->icb;
1719f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
1729f988b79SJean-Baptiste Boric 	uint32_t lb_size;
1739f988b79SJean-Baptiste Boric 	uint32_t sector, dummy;
1749f988b79SJean-Baptiste Boric 	int error;
1759f988b79SJean-Baptiste Boric 
1769f988b79SJean-Baptiste Boric 	lb_size = udf_rw32(ump->logical_vol->lb_size);
1779f988b79SJean-Baptiste Boric 
1789f988b79SJean-Baptiste Boric 	error = udf_translate_vtop(ump, icb, &sector, &dummy);
1799f988b79SJean-Baptiste Boric 	if (error)
1809f988b79SJean-Baptiste Boric 		return error;
1819f988b79SJean-Baptiste Boric 
1829f988b79SJean-Baptiste Boric 	/* try to read in fe/efe */
1839f988b79SJean-Baptiste Boric 	error = udf_read_phys_dscr(ump, sector, M_UDFTEMP, &tmpdscr);
1849f988b79SJean-Baptiste Boric 	if (error)
1859f988b79SJean-Baptiste Boric 		return error;
1869f988b79SJean-Baptiste Boric 
1879f988b79SJean-Baptiste Boric 	*dscrptr = pool_get(&priv->desc_pool, PR_WAITOK);
1889f988b79SJean-Baptiste Boric 	memcpy(*dscrptr, tmpdscr, lb_size);
1899f988b79SJean-Baptiste Boric 	free(tmpdscr, M_UDFTEMP);
1909f988b79SJean-Baptiste Boric 
1919f988b79SJean-Baptiste Boric 	return 0;
1929f988b79SJean-Baptiste Boric }
1939f988b79SJean-Baptiste Boric 
1949f988b79SJean-Baptiste Boric 
1959f988b79SJean-Baptiste Boric static int
udf_write_logvol_dscr_seq(struct udf_strat_args * args)1969f988b79SJean-Baptiste Boric udf_write_logvol_dscr_seq(struct udf_strat_args *args)
1979f988b79SJean-Baptiste Boric {
1989f988b79SJean-Baptiste Boric 	union dscrptr    *dscr     = args->dscr;
1999f988b79SJean-Baptiste Boric 	struct udf_mount *ump      = args->ump;
2009f988b79SJean-Baptiste Boric 	struct udf_node  *udf_node = args->udf_node;
2019f988b79SJean-Baptiste Boric 	struct long_ad   *icb      = args->icb;
2029f988b79SJean-Baptiste Boric 	int               waitfor  = args->waitfor;
2039f988b79SJean-Baptiste Boric 	uint32_t logsectornr, sectornr, dummy;
2049f988b79SJean-Baptiste Boric 	int error, vpart;
2059f988b79SJean-Baptiste Boric 
2069f988b79SJean-Baptiste Boric 	/*
2079f988b79SJean-Baptiste Boric 	 * we have to decide if we write it out sequential or at its fixed
2089f988b79SJean-Baptiste Boric 	 * position by examining the partition its (to be) written on.
2099f988b79SJean-Baptiste Boric 	 */
2109f988b79SJean-Baptiste Boric 	vpart       = udf_rw16(udf_node->loc.loc.part_num);
2119f988b79SJean-Baptiste Boric 	logsectornr = udf_rw32(icb->loc.lb_num);
2129f988b79SJean-Baptiste Boric 	sectornr    = 0;
2139f988b79SJean-Baptiste Boric 	if (ump->vtop_tp[vpart] != UDF_VTOP_TYPE_VIRT) {
2149f988b79SJean-Baptiste Boric 		error = udf_translate_vtop(ump, icb, &sectornr, &dummy);
2159f988b79SJean-Baptiste Boric 		if (error)
2169f988b79SJean-Baptiste Boric 			goto out;
2179f988b79SJean-Baptiste Boric 	}
2189f988b79SJean-Baptiste Boric 
2199f988b79SJean-Baptiste Boric 	if (waitfor) {
2209f988b79SJean-Baptiste Boric 		DPRINTF(WRITE, ("udf_write_logvol_dscr: sync write\n"));
2219f988b79SJean-Baptiste Boric 
2229f988b79SJean-Baptiste Boric 		error = udf_write_phys_dscr_sync(ump, udf_node, UDF_C_NODE,
2239f988b79SJean-Baptiste Boric 			dscr, sectornr, logsectornr);
2249f988b79SJean-Baptiste Boric 	} else {
2259f988b79SJean-Baptiste Boric 		DPRINTF(WRITE, ("udf_write_logvol_dscr: no wait, async write\n"));
2269f988b79SJean-Baptiste Boric 
2279f988b79SJean-Baptiste Boric 		error = udf_write_phys_dscr_async(ump, udf_node, UDF_C_NODE,
2289f988b79SJean-Baptiste Boric 			dscr, sectornr, logsectornr, udf_wr_nodedscr_callback);
2299f988b79SJean-Baptiste Boric 		/* will be UNLOCKED in call back */
2309f988b79SJean-Baptiste Boric 		return error;
2319f988b79SJean-Baptiste Boric 	}
2329f988b79SJean-Baptiste Boric out:
2339f988b79SJean-Baptiste Boric 	udf_node->outstanding_nodedscr--;
2349f988b79SJean-Baptiste Boric 	if (udf_node->outstanding_nodedscr == 0) {
2359f988b79SJean-Baptiste Boric 		UDF_UNLOCK_NODE(udf_node, 0);
2369f988b79SJean-Baptiste Boric 		wakeup(&udf_node->outstanding_nodedscr);
2379f988b79SJean-Baptiste Boric 	}
2389f988b79SJean-Baptiste Boric 
2399f988b79SJean-Baptiste Boric 	return error;
2409f988b79SJean-Baptiste Boric }
2419f988b79SJean-Baptiste Boric 
2429f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
2439f988b79SJean-Baptiste Boric 
2449f988b79SJean-Baptiste Boric /*
2459f988b79SJean-Baptiste Boric  * Main file-system specific sheduler. Due to the nature of optical media
2469f988b79SJean-Baptiste Boric  * sheduling can't be performed in the traditional way. Most OS
2479f988b79SJean-Baptiste Boric  * implementations i've seen thus read or write a file atomically giving all
2489f988b79SJean-Baptiste Boric  * kinds of side effects.
2499f988b79SJean-Baptiste Boric  *
2509f988b79SJean-Baptiste Boric  * This implementation uses a kernel thread to shedule the queued requests in
2519f988b79SJean-Baptiste Boric  * such a way that is semi-optimal for optical media; this means aproximately
2529f988b79SJean-Baptiste Boric  * (R*|(Wr*|Ws*))* since switching between reading and writing is expensive in
2539f988b79SJean-Baptiste Boric  * time.
2549f988b79SJean-Baptiste Boric  */
2559f988b79SJean-Baptiste Boric 
2569f988b79SJean-Baptiste Boric static void
udf_queuebuf_seq(struct udf_strat_args * args)2579f988b79SJean-Baptiste Boric udf_queuebuf_seq(struct udf_strat_args *args)
2589f988b79SJean-Baptiste Boric {
2599f988b79SJean-Baptiste Boric 	struct udf_mount *ump = args->ump;
2609f988b79SJean-Baptiste Boric 	struct buf *nestbuf = args->nestbuf;
2619f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
2629f988b79SJean-Baptiste Boric 	int queue;
2639f988b79SJean-Baptiste Boric 	int what;
2649f988b79SJean-Baptiste Boric 
2659f988b79SJean-Baptiste Boric 	KASSERT(ump);
2669f988b79SJean-Baptiste Boric 	KASSERT(nestbuf);
2679f988b79SJean-Baptiste Boric 	KASSERT(nestbuf->b_iodone == nestiobuf_iodone);
2689f988b79SJean-Baptiste Boric 
2699f988b79SJean-Baptiste Boric 	what = nestbuf->b_udf_c_type;
2709f988b79SJean-Baptiste Boric 	queue = UDF_SHED_READING;
2719f988b79SJean-Baptiste Boric 	if ((nestbuf->b_flags & B_READ) == 0) {
2729f988b79SJean-Baptiste Boric 		/* writing */
2739f988b79SJean-Baptiste Boric 		queue = UDF_SHED_SEQWRITING;
2749f988b79SJean-Baptiste Boric 		if (what == UDF_C_ABSOLUTE)
2759f988b79SJean-Baptiste Boric 			queue = UDF_SHED_WRITING;
2769f988b79SJean-Baptiste Boric 	}
2779f988b79SJean-Baptiste Boric 
2789f988b79SJean-Baptiste Boric 	/* use our own sheduler lists for more complex sheduling */
2799f988b79SJean-Baptiste Boric 	mutex_enter(&priv->discstrat_mutex);
2809f988b79SJean-Baptiste Boric 		bufq_put(priv->queues[queue], nestbuf);
2819f988b79SJean-Baptiste Boric 		vfs_timestamp(&priv->last_queued[queue]);
2829f988b79SJean-Baptiste Boric 	mutex_exit(&priv->discstrat_mutex);
2839f988b79SJean-Baptiste Boric 
2849f988b79SJean-Baptiste Boric 	/* signal our thread that there might be something to do */
2859f988b79SJean-Baptiste Boric 	cv_signal(&priv->discstrat_cv);
2869f988b79SJean-Baptiste Boric }
2879f988b79SJean-Baptiste Boric 
2889f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
2899f988b79SJean-Baptiste Boric 
2909f988b79SJean-Baptiste Boric /* TODO convert to lb_size */
2919f988b79SJean-Baptiste Boric static void
udf_VAT_mapping_update(struct udf_mount * ump,struct buf * buf,uint32_t lb_map)2929f988b79SJean-Baptiste Boric udf_VAT_mapping_update(struct udf_mount *ump, struct buf *buf, uint32_t lb_map)
2939f988b79SJean-Baptiste Boric {
2949f988b79SJean-Baptiste Boric 	union dscrptr    *fdscr = (union dscrptr *) buf->b_data;
2959f988b79SJean-Baptiste Boric 	struct vnode     *vp = buf->b_vp;
2969f988b79SJean-Baptiste Boric 	struct udf_node  *udf_node = VTOI(vp);
2979f988b79SJean-Baptiste Boric 	uint32_t lb_num;
2989f988b79SJean-Baptiste Boric 	uint32_t udf_rw32_lbmap;
2999f988b79SJean-Baptiste Boric 	int c_type = buf->b_udf_c_type;
3009f988b79SJean-Baptiste Boric 	int error;
3019f988b79SJean-Baptiste Boric 
3029f988b79SJean-Baptiste Boric 	/* only interested when we're using a VAT */
3039f988b79SJean-Baptiste Boric 	KASSERT(ump->vat_node);
3049f988b79SJean-Baptiste Boric 	KASSERT(ump->vtop_alloc[ump->node_part] == UDF_ALLOC_VAT);
3059f988b79SJean-Baptiste Boric 
3069f988b79SJean-Baptiste Boric 	/* only nodes are recorded in the VAT */
3079f988b79SJean-Baptiste Boric 	/* NOTE: and the fileset descriptor (FIXME ?) */
3089f988b79SJean-Baptiste Boric 	if (c_type != UDF_C_NODE)
3099f988b79SJean-Baptiste Boric 		return;
3109f988b79SJean-Baptiste Boric 
3119f988b79SJean-Baptiste Boric 	udf_rw32_lbmap = udf_rw32(lb_map);
3129f988b79SJean-Baptiste Boric 
3139f988b79SJean-Baptiste Boric 	/* if we're the VAT itself, only update our assigned sector number */
3149f988b79SJean-Baptiste Boric 	if (udf_node == ump->vat_node) {
3159f988b79SJean-Baptiste Boric 		fdscr->tag.tag_loc = udf_rw32_lbmap;
3169f988b79SJean-Baptiste Boric 		udf_validate_tag_sum(fdscr);
3179f988b79SJean-Baptiste Boric 		DPRINTF(TRANSLATE, ("VAT assigned to sector %u\n",
3189f988b79SJean-Baptiste Boric 			udf_rw32(udf_rw32_lbmap)));
3199f988b79SJean-Baptiste Boric 		/* no use mapping the VAT node in the VAT */
3209f988b79SJean-Baptiste Boric 		return;
3219f988b79SJean-Baptiste Boric 	}
3229f988b79SJean-Baptiste Boric 
3239f988b79SJean-Baptiste Boric 	/* record new position in VAT file */
3249f988b79SJean-Baptiste Boric 	lb_num = udf_rw32(fdscr->tag.tag_loc);
3259f988b79SJean-Baptiste Boric 
3269f988b79SJean-Baptiste Boric 	/* lb_num = udf_rw32(udf_node->write_loc.loc.lb_num); */
3279f988b79SJean-Baptiste Boric 
3289f988b79SJean-Baptiste Boric 	DPRINTF(TRANSLATE, ("VAT entry change (log %u -> phys %u)\n",
3299f988b79SJean-Baptiste Boric 			lb_num, lb_map));
3309f988b79SJean-Baptiste Boric 
3319f988b79SJean-Baptiste Boric 	/* VAT should be the longer than this write, can't go wrong */
3329f988b79SJean-Baptiste Boric 	KASSERT(lb_num <= ump->vat_entries);
3339f988b79SJean-Baptiste Boric 
3349f988b79SJean-Baptiste Boric 	mutex_enter(&ump->allocate_mutex);
3359f988b79SJean-Baptiste Boric 	error = udf_vat_write(ump->vat_node,
3369f988b79SJean-Baptiste Boric 			(uint8_t *) &udf_rw32_lbmap, 4,
3379f988b79SJean-Baptiste Boric 			ump->vat_offset + lb_num * 4);
3389f988b79SJean-Baptiste Boric 	mutex_exit(&ump->allocate_mutex);
3399f988b79SJean-Baptiste Boric 
3409f988b79SJean-Baptiste Boric 	if (error)
3419f988b79SJean-Baptiste Boric 		panic( "udf_VAT_mapping_update: HELP! i couldn't "
3429f988b79SJean-Baptiste Boric 			"write in the VAT file ?\n");
3439f988b79SJean-Baptiste Boric }
3449f988b79SJean-Baptiste Boric 
3459f988b79SJean-Baptiste Boric 
3469f988b79SJean-Baptiste Boric static void
udf_issue_buf(struct udf_mount * ump,int queue,struct buf * buf)3479f988b79SJean-Baptiste Boric udf_issue_buf(struct udf_mount *ump, int queue, struct buf *buf)
3489f988b79SJean-Baptiste Boric {
3499f988b79SJean-Baptiste Boric 	union dscrptr *dscr;
3509f988b79SJean-Baptiste Boric 	struct long_ad *node_ad_cpy;
3519f988b79SJean-Baptiste Boric 	struct part_desc *pdesc;
3529f988b79SJean-Baptiste Boric 	uint64_t *lmapping, *lmappos;
3539f988b79SJean-Baptiste Boric 	uint32_t sectornr, bpos;
3549f988b79SJean-Baptiste Boric 	uint32_t ptov;
3559f988b79SJean-Baptiste Boric 	uint16_t vpart_num;
3569f988b79SJean-Baptiste Boric 	uint8_t *fidblk;
3579f988b79SJean-Baptiste Boric 	int sector_size = ump->discinfo.sector_size;
3589f988b79SJean-Baptiste Boric 	int blks = sector_size / DEV_BSIZE;
3599f988b79SJean-Baptiste Boric 	int len, buf_len;
3609f988b79SJean-Baptiste Boric 
3619f988b79SJean-Baptiste Boric 	/* if reading, just pass to the device's STRATEGY */
3629f988b79SJean-Baptiste Boric 	if (queue == UDF_SHED_READING) {
3639f988b79SJean-Baptiste Boric 		DPRINTF(SHEDULE, ("\nudf_issue_buf READ %p : sector %d type %d,"
3649f988b79SJean-Baptiste Boric 			"b_resid %d, b_bcount %d, b_bufsize %d\n",
3659f988b79SJean-Baptiste Boric 			buf, (uint32_t) buf->b_blkno / blks, buf->b_udf_c_type,
3669f988b79SJean-Baptiste Boric 			buf->b_resid, buf->b_bcount, buf->b_bufsize));
3679f988b79SJean-Baptiste Boric 		VOP_STRATEGY(ump->devvp, buf);
3689f988b79SJean-Baptiste Boric 		return;
3699f988b79SJean-Baptiste Boric 	}
3709f988b79SJean-Baptiste Boric 
3719f988b79SJean-Baptiste Boric 	if (queue == UDF_SHED_WRITING) {
3729f988b79SJean-Baptiste Boric 		DPRINTF(SHEDULE, ("\nudf_issue_buf WRITE %p : sector %d "
3739f988b79SJean-Baptiste Boric 			"type %d, b_resid %d, b_bcount %d, b_bufsize %d\n",
3749f988b79SJean-Baptiste Boric 			buf, (uint32_t) buf->b_blkno / blks, buf->b_udf_c_type,
3759f988b79SJean-Baptiste Boric 			buf->b_resid, buf->b_bcount, buf->b_bufsize));
3769f988b79SJean-Baptiste Boric 		KASSERT(buf->b_udf_c_type == UDF_C_ABSOLUTE);
3779f988b79SJean-Baptiste Boric 
3789f988b79SJean-Baptiste Boric 		// udf_fixup_node_internals(ump, buf->b_data, buf->b_udf_c_type);
3799f988b79SJean-Baptiste Boric 		VOP_STRATEGY(ump->devvp, buf);
3809f988b79SJean-Baptiste Boric 		return;
3819f988b79SJean-Baptiste Boric 	}
3829f988b79SJean-Baptiste Boric 
3839f988b79SJean-Baptiste Boric 	KASSERT(queue == UDF_SHED_SEQWRITING);
3849f988b79SJean-Baptiste Boric 	DPRINTF(SHEDULE, ("\nudf_issue_buf SEQWRITE %p : sector XXXX "
3859f988b79SJean-Baptiste Boric 		"type %d, b_resid %d, b_bcount %d, b_bufsize %d\n",
3869f988b79SJean-Baptiste Boric 		buf, buf->b_udf_c_type, buf->b_resid, buf->b_bcount,
3879f988b79SJean-Baptiste Boric 		buf->b_bufsize));
3889f988b79SJean-Baptiste Boric 
3899f988b79SJean-Baptiste Boric 	/*
3909f988b79SJean-Baptiste Boric 	 * Buffers should not have been allocated to disc addresses yet on
3919f988b79SJean-Baptiste Boric 	 * this queue. Note that a buffer can get multiple extents allocated.
3929f988b79SJean-Baptiste Boric 	 *
3939f988b79SJean-Baptiste Boric 	 * lmapping contains lb_num relative to base partition.
3949f988b79SJean-Baptiste Boric 	 */
3959f988b79SJean-Baptiste Boric 	lmapping    = ump->la_lmapping;
3969f988b79SJean-Baptiste Boric 	node_ad_cpy = ump->la_node_ad_cpy;
3979f988b79SJean-Baptiste Boric 
3989f988b79SJean-Baptiste Boric 	/* logically allocate buf and map it in the file */
3999f988b79SJean-Baptiste Boric 	udf_late_allocate_buf(ump, buf, lmapping, node_ad_cpy, &vpart_num);
4009f988b79SJean-Baptiste Boric 
4019f988b79SJean-Baptiste Boric 	/*
4029f988b79SJean-Baptiste Boric 	 * NOTE We are using the knowledge here that sequential media will
4039f988b79SJean-Baptiste Boric 	 * always be mapped linearly. Thus no use to explicitly translate the
4049f988b79SJean-Baptiste Boric 	 * lmapping list.
4059f988b79SJean-Baptiste Boric 	 */
4069f988b79SJean-Baptiste Boric 
4079f988b79SJean-Baptiste Boric 	/* calculate offset from physical base partition */
4089f988b79SJean-Baptiste Boric 	pdesc = ump->partitions[ump->vtop[vpart_num]];
4099f988b79SJean-Baptiste Boric 	ptov  = udf_rw32(pdesc->start_loc);
4109f988b79SJean-Baptiste Boric 
4119f988b79SJean-Baptiste Boric 	/* set buffers blkno to the physical block number */
4129f988b79SJean-Baptiste Boric 	buf->b_blkno = (*lmapping + ptov) * blks;
4139f988b79SJean-Baptiste Boric 
4149f988b79SJean-Baptiste Boric 	/* fixate floating descriptors */
4159f988b79SJean-Baptiste Boric 	if (buf->b_udf_c_type == UDF_C_FLOAT_DSCR) {
4169f988b79SJean-Baptiste Boric 		/* set our tag location to the absolute position */
4179f988b79SJean-Baptiste Boric 		dscr = (union dscrptr *) buf->b_data;
4189f988b79SJean-Baptiste Boric 		dscr->tag.tag_loc = udf_rw32(*lmapping + ptov);
4199f988b79SJean-Baptiste Boric 		udf_validate_tag_and_crc_sums(dscr);
4209f988b79SJean-Baptiste Boric 	}
4219f988b79SJean-Baptiste Boric 
4229f988b79SJean-Baptiste Boric 	/* update mapping in the VAT */
4239f988b79SJean-Baptiste Boric 	if (buf->b_udf_c_type == UDF_C_NODE) {
4249f988b79SJean-Baptiste Boric 		udf_VAT_mapping_update(ump, buf, *lmapping);
4259f988b79SJean-Baptiste Boric 		udf_fixup_node_internals(ump, buf->b_data, buf->b_udf_c_type);
4269f988b79SJean-Baptiste Boric 	}
4279f988b79SJean-Baptiste Boric 
4289f988b79SJean-Baptiste Boric 	/* if we have FIDs, fixup using the new allocation table */
4299f988b79SJean-Baptiste Boric 	if (buf->b_udf_c_type == UDF_C_FIDS) {
4309f988b79SJean-Baptiste Boric 		buf_len = buf->b_bcount;
4319f988b79SJean-Baptiste Boric 		bpos = 0;
4329f988b79SJean-Baptiste Boric 		lmappos = lmapping;
4339f988b79SJean-Baptiste Boric 		while (buf_len) {
4349f988b79SJean-Baptiste Boric 			sectornr = *lmappos++;
4359f988b79SJean-Baptiste Boric 			len = MIN(buf_len, sector_size);
4369f988b79SJean-Baptiste Boric 			fidblk = (uint8_t *) buf->b_data + bpos;
4379f988b79SJean-Baptiste Boric 			udf_fixup_fid_block(fidblk, sector_size,
4389f988b79SJean-Baptiste Boric 				0, len, sectornr);
4399f988b79SJean-Baptiste Boric 			bpos += len;
4409f988b79SJean-Baptiste Boric 			buf_len -= len;
4419f988b79SJean-Baptiste Boric 		}
4429f988b79SJean-Baptiste Boric 	}
4439f988b79SJean-Baptiste Boric 
4449f988b79SJean-Baptiste Boric 	VOP_STRATEGY(ump->devvp, buf);
4459f988b79SJean-Baptiste Boric }
4469f988b79SJean-Baptiste Boric 
4479f988b79SJean-Baptiste Boric 
4489f988b79SJean-Baptiste Boric static void
udf_doshedule(struct udf_mount * ump)4499f988b79SJean-Baptiste Boric udf_doshedule(struct udf_mount *ump)
4509f988b79SJean-Baptiste Boric {
4519f988b79SJean-Baptiste Boric 	struct buf *buf;
4529f988b79SJean-Baptiste Boric 	struct timespec now, *last;
4539f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
4549f988b79SJean-Baptiste Boric 	void (*b_callback)(struct buf *);
4559f988b79SJean-Baptiste Boric 	int new_queue;
4569f988b79SJean-Baptiste Boric 	int error;
4579f988b79SJean-Baptiste Boric 
4589f988b79SJean-Baptiste Boric 	buf = bufq_get(priv->queues[priv->cur_queue]);
4599f988b79SJean-Baptiste Boric 	if (buf) {
4609f988b79SJean-Baptiste Boric 		/* transfer from the current queue to the device queue */
4619f988b79SJean-Baptiste Boric 		mutex_exit(&priv->discstrat_mutex);
4629f988b79SJean-Baptiste Boric 
4639f988b79SJean-Baptiste Boric 		/* transform buffer to synchronous; XXX needed? */
4649f988b79SJean-Baptiste Boric 		b_callback = buf->b_iodone;
4659f988b79SJean-Baptiste Boric 		buf->b_iodone = NULL;
4669f988b79SJean-Baptiste Boric 		CLR(buf->b_flags, B_ASYNC);
4679f988b79SJean-Baptiste Boric 
4689f988b79SJean-Baptiste Boric 		/* issue and wait on completion */
4699f988b79SJean-Baptiste Boric 		udf_issue_buf(ump, priv->cur_queue, buf);
4709f988b79SJean-Baptiste Boric 		biowait(buf);
4719f988b79SJean-Baptiste Boric 
4729f988b79SJean-Baptiste Boric 		mutex_enter(&priv->discstrat_mutex);
4739f988b79SJean-Baptiste Boric 
4749f988b79SJean-Baptiste Boric 		/* if there is an error, repair this error, otherwise propagate */
4759f988b79SJean-Baptiste Boric 		if (buf->b_error && ((buf->b_flags & B_READ) == 0)) {
4769f988b79SJean-Baptiste Boric 			/* check what we need to do */
4779f988b79SJean-Baptiste Boric 			panic("UDF write error, can't handle yet!\n");
4789f988b79SJean-Baptiste Boric 		}
4799f988b79SJean-Baptiste Boric 
4809f988b79SJean-Baptiste Boric 		/* propagate result to higher layers */
4819f988b79SJean-Baptiste Boric 		if (b_callback) {
4829f988b79SJean-Baptiste Boric 			buf->b_iodone = b_callback;
4839f988b79SJean-Baptiste Boric 			(*buf->b_iodone)(buf);
4849f988b79SJean-Baptiste Boric 		}
4859f988b79SJean-Baptiste Boric 
4869f988b79SJean-Baptiste Boric 		return;
4879f988b79SJean-Baptiste Boric 	}
4889f988b79SJean-Baptiste Boric 
4899f988b79SJean-Baptiste Boric 	/* Check if we're idling in this state */
4909f988b79SJean-Baptiste Boric 	vfs_timestamp(&now);
4919f988b79SJean-Baptiste Boric 	last = &priv->last_queued[priv->cur_queue];
4929f988b79SJean-Baptiste Boric 	if (ump->discinfo.mmc_class == MMC_CLASS_CD) {
4939f988b79SJean-Baptiste Boric 		/* dont switch too fast for CD media; its expensive in time */
4949f988b79SJean-Baptiste Boric 		if (now.tv_sec - last->tv_sec < 3)
4959f988b79SJean-Baptiste Boric 			return;
4969f988b79SJean-Baptiste Boric 	}
4979f988b79SJean-Baptiste Boric 
4989f988b79SJean-Baptiste Boric 	/* check if we can/should switch */
4999f988b79SJean-Baptiste Boric 	new_queue = priv->cur_queue;
5009f988b79SJean-Baptiste Boric 
5019f988b79SJean-Baptiste Boric 	if (bufq_peek(priv->queues[UDF_SHED_READING]))
5029f988b79SJean-Baptiste Boric 		new_queue = UDF_SHED_READING;
5039f988b79SJean-Baptiste Boric 	if (bufq_peek(priv->queues[UDF_SHED_WRITING]))		/* only for unmount */
5049f988b79SJean-Baptiste Boric 		new_queue = UDF_SHED_WRITING;
5059f988b79SJean-Baptiste Boric 	if (bufq_peek(priv->queues[UDF_SHED_SEQWRITING]))
5069f988b79SJean-Baptiste Boric 		new_queue = UDF_SHED_SEQWRITING;
5079f988b79SJean-Baptiste Boric 	if (priv->cur_queue == UDF_SHED_READING) {
5089f988b79SJean-Baptiste Boric 		if (new_queue == UDF_SHED_SEQWRITING) {
5099f988b79SJean-Baptiste Boric 			/* TODO use flag to signal if this is needed */
5109f988b79SJean-Baptiste Boric 			mutex_exit(&priv->discstrat_mutex);
5119f988b79SJean-Baptiste Boric 
5129f988b79SJean-Baptiste Boric 			/* update trackinfo for data and metadata */
5139f988b79SJean-Baptiste Boric 			error = udf_update_trackinfo(ump,
5149f988b79SJean-Baptiste Boric 					&ump->data_track);
5159f988b79SJean-Baptiste Boric 			assert(error == 0);
5169f988b79SJean-Baptiste Boric 			error = udf_update_trackinfo(ump,
5179f988b79SJean-Baptiste Boric 					&ump->metadata_track);
5189f988b79SJean-Baptiste Boric 			assert(error == 0);
5199f988b79SJean-Baptiste Boric 			mutex_enter(&priv->discstrat_mutex);
520*0a6a1f1dSLionel Sambuc 			__USE(error);
5219f988b79SJean-Baptiste Boric 		}
5229f988b79SJean-Baptiste Boric 	}
5239f988b79SJean-Baptiste Boric 
5249f988b79SJean-Baptiste Boric 	if (new_queue != priv->cur_queue) {
5259f988b79SJean-Baptiste Boric 		DPRINTF(SHEDULE, ("switching from %d to %d\n",
5269f988b79SJean-Baptiste Boric 			priv->cur_queue, new_queue));
5279f988b79SJean-Baptiste Boric 	}
5289f988b79SJean-Baptiste Boric 
5299f988b79SJean-Baptiste Boric 	priv->cur_queue = new_queue;
5309f988b79SJean-Baptiste Boric }
5319f988b79SJean-Baptiste Boric 
5329f988b79SJean-Baptiste Boric 
5339f988b79SJean-Baptiste Boric static void
udf_discstrat_thread(void * arg)5349f988b79SJean-Baptiste Boric udf_discstrat_thread(void *arg)
5359f988b79SJean-Baptiste Boric {
5369f988b79SJean-Baptiste Boric 	struct udf_mount *ump = (struct udf_mount *) arg;
5379f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
5389f988b79SJean-Baptiste Boric 	int empty;
5399f988b79SJean-Baptiste Boric 
5409f988b79SJean-Baptiste Boric 	empty = 1;
5419f988b79SJean-Baptiste Boric 	mutex_enter(&priv->discstrat_mutex);
5429f988b79SJean-Baptiste Boric 	while (priv->run_thread || !empty) {
5439f988b79SJean-Baptiste Boric 		/* process the current selected queue */
5449f988b79SJean-Baptiste Boric 		udf_doshedule(ump);
5459f988b79SJean-Baptiste Boric 		empty  = (bufq_peek(priv->queues[UDF_SHED_READING]) == NULL);
5469f988b79SJean-Baptiste Boric 		empty &= (bufq_peek(priv->queues[UDF_SHED_WRITING]) == NULL);
5479f988b79SJean-Baptiste Boric 		empty &= (bufq_peek(priv->queues[UDF_SHED_SEQWRITING]) == NULL);
5489f988b79SJean-Baptiste Boric 
5499f988b79SJean-Baptiste Boric 		/* wait for more if needed */
5509f988b79SJean-Baptiste Boric 		if (empty)
5519f988b79SJean-Baptiste Boric 			cv_timedwait(&priv->discstrat_cv,
5529f988b79SJean-Baptiste Boric 				&priv->discstrat_mutex, hz/8);
5539f988b79SJean-Baptiste Boric 	}
5549f988b79SJean-Baptiste Boric 	mutex_exit(&priv->discstrat_mutex);
5559f988b79SJean-Baptiste Boric 
5569f988b79SJean-Baptiste Boric 	wakeup(&priv->run_thread);
5579f988b79SJean-Baptiste Boric 	kthread_exit(0);
5589f988b79SJean-Baptiste Boric 	/* not reached */
5599f988b79SJean-Baptiste Boric }
5609f988b79SJean-Baptiste Boric 
5619f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
5629f988b79SJean-Baptiste Boric 
5639f988b79SJean-Baptiste Boric static void
udf_discstrat_init_seq(struct udf_strat_args * args)5649f988b79SJean-Baptiste Boric udf_discstrat_init_seq(struct udf_strat_args *args)
5659f988b79SJean-Baptiste Boric {
5669f988b79SJean-Baptiste Boric 	struct udf_mount *ump = args->ump;
5679f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
5689f988b79SJean-Baptiste Boric 	struct disk_strategy dkstrat;
5699f988b79SJean-Baptiste Boric 	uint32_t lb_size;
5709f988b79SJean-Baptiste Boric 
5719f988b79SJean-Baptiste Boric 	KASSERT(ump);
5729f988b79SJean-Baptiste Boric 	KASSERT(ump->logical_vol);
5739f988b79SJean-Baptiste Boric 	KASSERT(priv == NULL);
5749f988b79SJean-Baptiste Boric 
5759f988b79SJean-Baptiste Boric 	lb_size = udf_rw32(ump->logical_vol->lb_size);
5769f988b79SJean-Baptiste Boric 	KASSERT(lb_size > 0);
5779f988b79SJean-Baptiste Boric 
5789f988b79SJean-Baptiste Boric 	/* initialise our memory space */
5799f988b79SJean-Baptiste Boric 	ump->strategy_private = malloc(sizeof(struct strat_private),
5809f988b79SJean-Baptiste Boric 		M_UDFTEMP, M_WAITOK);
5819f988b79SJean-Baptiste Boric 	priv = ump->strategy_private;
5829f988b79SJean-Baptiste Boric 	memset(priv, 0 , sizeof(struct strat_private));
5839f988b79SJean-Baptiste Boric 
5849f988b79SJean-Baptiste Boric 	/* initialise locks */
5859f988b79SJean-Baptiste Boric 	cv_init(&priv->discstrat_cv, "udfstrat");
5869f988b79SJean-Baptiste Boric 	mutex_init(&priv->discstrat_mutex, MUTEX_DEFAULT, IPL_NONE);
5879f988b79SJean-Baptiste Boric 
5889f988b79SJean-Baptiste Boric 	/*
5899f988b79SJean-Baptiste Boric 	 * Initialise pool for descriptors associated with nodes. This is done
5909f988b79SJean-Baptiste Boric 	 * in lb_size units though currently lb_size is dictated to be
5919f988b79SJean-Baptiste Boric 	 * sector_size.
5929f988b79SJean-Baptiste Boric 	 */
5939f988b79SJean-Baptiste Boric 	pool_init(&priv->desc_pool, lb_size, 0, 0, 0, "udf_desc_pool", NULL,
5949f988b79SJean-Baptiste Boric 	    IPL_NONE);
5959f988b79SJean-Baptiste Boric 
5969f988b79SJean-Baptiste Boric 	/*
5979f988b79SJean-Baptiste Boric 	 * remember old device strategy method and explicit set method
5989f988b79SJean-Baptiste Boric 	 * `discsort' since we have our own more complex strategy that is not
5999f988b79SJean-Baptiste Boric 	 * implementable on the CD device and other strategies will get in the
6009f988b79SJean-Baptiste Boric 	 * way.
6019f988b79SJean-Baptiste Boric 	 */
6029f988b79SJean-Baptiste Boric 	memset(&priv->old_strategy_setting, 0,
6039f988b79SJean-Baptiste Boric 		sizeof(struct disk_strategy));
6049f988b79SJean-Baptiste Boric 	VOP_IOCTL(ump->devvp, DIOCGSTRATEGY, &priv->old_strategy_setting,
6059f988b79SJean-Baptiste Boric 		FREAD | FKIOCTL, NOCRED);
6069f988b79SJean-Baptiste Boric 	memset(&dkstrat, 0, sizeof(struct disk_strategy));
6079f988b79SJean-Baptiste Boric 	strcpy(dkstrat.dks_name, "discsort");
6089f988b79SJean-Baptiste Boric 	VOP_IOCTL(ump->devvp, DIOCSSTRATEGY, &dkstrat, FWRITE | FKIOCTL,
6099f988b79SJean-Baptiste Boric 		NOCRED);
6109f988b79SJean-Baptiste Boric 
6119f988b79SJean-Baptiste Boric 	/* initialise our internal sheduler */
6129f988b79SJean-Baptiste Boric 	priv->cur_queue = UDF_SHED_READING;
6139f988b79SJean-Baptiste Boric 	bufq_alloc(&priv->queues[UDF_SHED_READING], "disksort",
6149f988b79SJean-Baptiste Boric 		BUFQ_SORT_RAWBLOCK);
6159f988b79SJean-Baptiste Boric 	bufq_alloc(&priv->queues[UDF_SHED_WRITING], "disksort",
6169f988b79SJean-Baptiste Boric 		BUFQ_SORT_RAWBLOCK);
6179f988b79SJean-Baptiste Boric 	bufq_alloc(&priv->queues[UDF_SHED_SEQWRITING], "fcfs", 0);
6189f988b79SJean-Baptiste Boric 	vfs_timestamp(&priv->last_queued[UDF_SHED_READING]);
6199f988b79SJean-Baptiste Boric 	vfs_timestamp(&priv->last_queued[UDF_SHED_WRITING]);
6209f988b79SJean-Baptiste Boric 	vfs_timestamp(&priv->last_queued[UDF_SHED_SEQWRITING]);
6219f988b79SJean-Baptiste Boric 
6229f988b79SJean-Baptiste Boric 	/* create our disk strategy thread */
6239f988b79SJean-Baptiste Boric 	priv->run_thread = 1;
6249f988b79SJean-Baptiste Boric 	if (kthread_create(PRI_NONE, 0 /* KTHREAD_MPSAFE*/, NULL /* cpu_info*/,
6259f988b79SJean-Baptiste Boric 		udf_discstrat_thread, ump, &priv->queue_lwp,
6269f988b79SJean-Baptiste Boric 		"%s", "udf_rw")) {
6279f988b79SJean-Baptiste Boric 		panic("fork udf_rw");
6289f988b79SJean-Baptiste Boric 	}
6299f988b79SJean-Baptiste Boric }
6309f988b79SJean-Baptiste Boric 
6319f988b79SJean-Baptiste Boric 
6329f988b79SJean-Baptiste Boric static void
udf_discstrat_finish_seq(struct udf_strat_args * args)6339f988b79SJean-Baptiste Boric udf_discstrat_finish_seq(struct udf_strat_args *args)
6349f988b79SJean-Baptiste Boric {
6359f988b79SJean-Baptiste Boric 	struct udf_mount *ump = args->ump;
6369f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
6379f988b79SJean-Baptiste Boric 	int error;
6389f988b79SJean-Baptiste Boric 
6399f988b79SJean-Baptiste Boric 	if (ump == NULL)
6409f988b79SJean-Baptiste Boric 		return;
6419f988b79SJean-Baptiste Boric 
6429f988b79SJean-Baptiste Boric 	/* stop our sheduling thread */
6439f988b79SJean-Baptiste Boric 	KASSERT(priv->run_thread == 1);
6449f988b79SJean-Baptiste Boric 	priv->run_thread = 0;
6459f988b79SJean-Baptiste Boric 	wakeup(priv->queue_lwp);
6469f988b79SJean-Baptiste Boric 	do {
6479f988b79SJean-Baptiste Boric 		error = tsleep(&priv->run_thread, PRIBIO+1,
6489f988b79SJean-Baptiste Boric 			"udfshedfin", hz);
6499f988b79SJean-Baptiste Boric 	} while (error);
6509f988b79SJean-Baptiste Boric 	/* kthread should be finished now */
6519f988b79SJean-Baptiste Boric 
6529f988b79SJean-Baptiste Boric 	/* set back old device strategy method */
6539f988b79SJean-Baptiste Boric 	VOP_IOCTL(ump->devvp, DIOCSSTRATEGY, &priv->old_strategy_setting,
6549f988b79SJean-Baptiste Boric 			FWRITE, NOCRED);
6559f988b79SJean-Baptiste Boric 
6569f988b79SJean-Baptiste Boric 	/* destroy our pool */
6579f988b79SJean-Baptiste Boric 	pool_destroy(&priv->desc_pool);
6589f988b79SJean-Baptiste Boric 
6599f988b79SJean-Baptiste Boric 	mutex_destroy(&priv->discstrat_mutex);
6609f988b79SJean-Baptiste Boric 	cv_destroy(&priv->discstrat_cv);
6619f988b79SJean-Baptiste Boric 
6629f988b79SJean-Baptiste Boric 	/* free our private space */
6639f988b79SJean-Baptiste Boric 	free(ump->strategy_private, M_UDFTEMP);
6649f988b79SJean-Baptiste Boric 	ump->strategy_private = NULL;
6659f988b79SJean-Baptiste Boric }
6669f988b79SJean-Baptiste Boric 
6679f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
6689f988b79SJean-Baptiste Boric 
6699f988b79SJean-Baptiste Boric struct udf_strategy udf_strat_sequential =
6709f988b79SJean-Baptiste Boric {
6719f988b79SJean-Baptiste Boric 	udf_create_logvol_dscr_seq,
6729f988b79SJean-Baptiste Boric 	udf_free_logvol_dscr_seq,
6739f988b79SJean-Baptiste Boric 	udf_read_logvol_dscr_seq,
6749f988b79SJean-Baptiste Boric 	udf_write_logvol_dscr_seq,
6759f988b79SJean-Baptiste Boric 	udf_queuebuf_seq,
6769f988b79SJean-Baptiste Boric 	udf_discstrat_init_seq,
6779f988b79SJean-Baptiste Boric 	udf_discstrat_finish_seq
6789f988b79SJean-Baptiste Boric };
6799f988b79SJean-Baptiste Boric 
6809f988b79SJean-Baptiste Boric 
681