xref: /minix3/sys/fs/udf/udf_strat_direct.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* $NetBSD: udf_strat_direct.c,v 1.13 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_direct.c,v 1.13 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 
829f988b79SJean-Baptiste Boric struct strat_private {
839f988b79SJean-Baptiste Boric 	struct pool		desc_pool;	 /* node descriptors */
849f988b79SJean-Baptiste Boric };
859f988b79SJean-Baptiste Boric 
869f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
879f988b79SJean-Baptiste Boric 
889f988b79SJean-Baptiste Boric static void
udf_wr_nodedscr_callback(struct buf * buf)899f988b79SJean-Baptiste Boric udf_wr_nodedscr_callback(struct buf *buf)
909f988b79SJean-Baptiste Boric {
919f988b79SJean-Baptiste Boric 	struct udf_node *udf_node;
929f988b79SJean-Baptiste Boric 
939f988b79SJean-Baptiste Boric 	KASSERT(buf);
949f988b79SJean-Baptiste Boric 	KASSERT(buf->b_data);
959f988b79SJean-Baptiste Boric 
969f988b79SJean-Baptiste Boric 	/* called when write action is done */
979f988b79SJean-Baptiste Boric 	DPRINTF(WRITE, ("udf_wr_nodedscr_callback(): node written out\n"));
989f988b79SJean-Baptiste Boric 
999f988b79SJean-Baptiste Boric 	udf_node = VTOI(buf->b_vp);
1009f988b79SJean-Baptiste Boric 	if (udf_node == NULL) {
1019f988b79SJean-Baptiste Boric 		putiobuf(buf);
1029f988b79SJean-Baptiste Boric 		printf("udf_wr_node_callback: NULL node?\n");
1039f988b79SJean-Baptiste Boric 		return;
1049f988b79SJean-Baptiste Boric 	}
1059f988b79SJean-Baptiste Boric 
1069f988b79SJean-Baptiste Boric 	/* XXX right flags to mark dirty again on error? */
1079f988b79SJean-Baptiste Boric 	if (buf->b_error) {
1089f988b79SJean-Baptiste Boric 		/* write error on `defect free' media??? how to solve? */
1099f988b79SJean-Baptiste Boric 		/* XXX lookup UDF standard for unallocatable space */
1109f988b79SJean-Baptiste Boric 		udf_node->i_flags |= IN_MODIFIED | IN_ACCESSED;
1119f988b79SJean-Baptiste Boric 	}
1129f988b79SJean-Baptiste Boric 
1139f988b79SJean-Baptiste Boric 	/* decrement outstanding_nodedscr */
1149f988b79SJean-Baptiste Boric 	KASSERT(udf_node->outstanding_nodedscr >= 1);
1159f988b79SJean-Baptiste Boric 	udf_node->outstanding_nodedscr--;
1169f988b79SJean-Baptiste Boric 	if (udf_node->outstanding_nodedscr == 0) {
1179f988b79SJean-Baptiste Boric 		/* unlock the node */
1189f988b79SJean-Baptiste Boric 		UDF_UNLOCK_NODE(udf_node, 0);
1199f988b79SJean-Baptiste Boric 		wakeup(&udf_node->outstanding_nodedscr);
1209f988b79SJean-Baptiste Boric 	}
1219f988b79SJean-Baptiste Boric 
1229f988b79SJean-Baptiste Boric 	putiobuf(buf);
1239f988b79SJean-Baptiste Boric }
1249f988b79SJean-Baptiste Boric 
1259f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
1269f988b79SJean-Baptiste Boric 
1279f988b79SJean-Baptiste Boric static int
udf_getblank_nodedscr_direct(struct udf_strat_args * args)1289f988b79SJean-Baptiste Boric udf_getblank_nodedscr_direct(struct udf_strat_args *args)
1299f988b79SJean-Baptiste Boric {
1309f988b79SJean-Baptiste Boric 	union dscrptr   **dscrptr = &args->dscr;
1319f988b79SJean-Baptiste Boric 	struct udf_mount *ump = args->ump;
1329f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
1339f988b79SJean-Baptiste Boric 	uint32_t lb_size;
1349f988b79SJean-Baptiste Boric 
1359f988b79SJean-Baptiste Boric 	lb_size = udf_rw32(ump->logical_vol->lb_size);
1369f988b79SJean-Baptiste Boric 	*dscrptr = pool_get(&priv->desc_pool, PR_WAITOK);
1379f988b79SJean-Baptiste Boric 	memset(*dscrptr, 0, lb_size);
1389f988b79SJean-Baptiste Boric 
1399f988b79SJean-Baptiste Boric 	return 0;
1409f988b79SJean-Baptiste Boric }
1419f988b79SJean-Baptiste Boric 
1429f988b79SJean-Baptiste Boric 
1439f988b79SJean-Baptiste Boric static void
udf_free_nodedscr_direct(struct udf_strat_args * args)1449f988b79SJean-Baptiste Boric udf_free_nodedscr_direct(struct udf_strat_args *args)
1459f988b79SJean-Baptiste Boric {
1469f988b79SJean-Baptiste Boric 	union dscrptr    *dscr = args->dscr;
1479f988b79SJean-Baptiste Boric 	struct udf_mount *ump  = args->ump;
1489f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
1499f988b79SJean-Baptiste Boric 
1509f988b79SJean-Baptiste Boric 	pool_put(&priv->desc_pool, dscr);
1519f988b79SJean-Baptiste Boric }
1529f988b79SJean-Baptiste Boric 
1539f988b79SJean-Baptiste Boric 
1549f988b79SJean-Baptiste Boric static int
udf_read_nodedscr_direct(struct udf_strat_args * args)1559f988b79SJean-Baptiste Boric udf_read_nodedscr_direct(struct udf_strat_args *args)
1569f988b79SJean-Baptiste Boric {
1579f988b79SJean-Baptiste Boric 	union dscrptr   **dscrptr = &args->dscr;
1589f988b79SJean-Baptiste Boric 	union dscrptr    *tmpdscr;
1599f988b79SJean-Baptiste Boric 	struct udf_mount *ump = args->ump;
1609f988b79SJean-Baptiste Boric 	struct long_ad   *icb = args->icb;
1619f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
1629f988b79SJean-Baptiste Boric 	uint32_t lb_size;
1639f988b79SJean-Baptiste Boric 	uint32_t sector, dummy;
1649f988b79SJean-Baptiste Boric 	int error;
1659f988b79SJean-Baptiste Boric 
1669f988b79SJean-Baptiste Boric 	lb_size = udf_rw32(ump->logical_vol->lb_size);
1679f988b79SJean-Baptiste Boric 
1689f988b79SJean-Baptiste Boric 	error = udf_translate_vtop(ump, icb, &sector, &dummy);
1699f988b79SJean-Baptiste Boric 	if (error)
1709f988b79SJean-Baptiste Boric 		return error;
1719f988b79SJean-Baptiste Boric 
1729f988b79SJean-Baptiste Boric 	/* try to read in fe/efe */
1739f988b79SJean-Baptiste Boric 	error = udf_read_phys_dscr(ump, sector, M_UDFTEMP, &tmpdscr);
1749f988b79SJean-Baptiste Boric 	if (error)
1759f988b79SJean-Baptiste Boric 		return error;
1769f988b79SJean-Baptiste Boric 
1779f988b79SJean-Baptiste Boric 	*dscrptr = pool_get(&priv->desc_pool, PR_WAITOK);
1789f988b79SJean-Baptiste Boric 	memcpy(*dscrptr, tmpdscr, lb_size);
1799f988b79SJean-Baptiste Boric 	free(tmpdscr, M_UDFTEMP);
1809f988b79SJean-Baptiste Boric 
1819f988b79SJean-Baptiste Boric 	return 0;
1829f988b79SJean-Baptiste Boric }
1839f988b79SJean-Baptiste Boric 
1849f988b79SJean-Baptiste Boric 
1859f988b79SJean-Baptiste Boric static int
udf_write_nodedscr_direct(struct udf_strat_args * args)1869f988b79SJean-Baptiste Boric udf_write_nodedscr_direct(struct udf_strat_args *args)
1879f988b79SJean-Baptiste Boric {
1889f988b79SJean-Baptiste Boric 	struct udf_mount *ump      = args->ump;
1899f988b79SJean-Baptiste Boric 	struct udf_node  *udf_node = args->udf_node;
1909f988b79SJean-Baptiste Boric 	union dscrptr    *dscr     = args->dscr;
1919f988b79SJean-Baptiste Boric 	struct long_ad   *icb      = args->icb;
1929f988b79SJean-Baptiste Boric 	int               waitfor  = args->waitfor;
1939f988b79SJean-Baptiste Boric 	uint32_t logsector, sector, dummy;
1949f988b79SJean-Baptiste Boric 	int error, vpart __diagused;
1959f988b79SJean-Baptiste Boric 
1969f988b79SJean-Baptiste Boric 	/*
1979f988b79SJean-Baptiste Boric 	 * we have to decide if we write it out sequential or at its fixed
1989f988b79SJean-Baptiste Boric 	 * position by examining the partition its (to be) written on.
1999f988b79SJean-Baptiste Boric 	 */
2009f988b79SJean-Baptiste Boric 	vpart     = udf_rw16(udf_node->loc.loc.part_num);
2019f988b79SJean-Baptiste Boric 	logsector = udf_rw32(icb->loc.lb_num);
2029f988b79SJean-Baptiste Boric 	KASSERT(ump->vtop_tp[vpart] != UDF_VTOP_TYPE_VIRT);
2039f988b79SJean-Baptiste Boric 
2049f988b79SJean-Baptiste Boric 	sector = 0;
2059f988b79SJean-Baptiste Boric 	error  = udf_translate_vtop(ump, icb, &sector, &dummy);
2069f988b79SJean-Baptiste Boric 	if (error)
2079f988b79SJean-Baptiste Boric 		goto out;
2089f988b79SJean-Baptiste Boric 
2099f988b79SJean-Baptiste Boric 	if (waitfor) {
2109f988b79SJean-Baptiste Boric 		DPRINTF(WRITE, ("udf_write_nodedscr: sync write\n"));
2119f988b79SJean-Baptiste Boric 
2129f988b79SJean-Baptiste Boric 		error = udf_write_phys_dscr_sync(ump, udf_node, UDF_C_NODE,
2139f988b79SJean-Baptiste Boric 			dscr, sector, logsector);
2149f988b79SJean-Baptiste Boric 	} else {
2159f988b79SJean-Baptiste Boric 		DPRINTF(WRITE, ("udf_write_nodedscr: no wait, async write\n"));
2169f988b79SJean-Baptiste Boric 
2179f988b79SJean-Baptiste Boric 		error = udf_write_phys_dscr_async(ump, udf_node, UDF_C_NODE,
2189f988b79SJean-Baptiste Boric 			dscr, sector, logsector, udf_wr_nodedscr_callback);
2199f988b79SJean-Baptiste Boric 		/* will be UNLOCKED in call back */
2209f988b79SJean-Baptiste Boric 		return error;
2219f988b79SJean-Baptiste Boric 	}
2229f988b79SJean-Baptiste Boric out:
2239f988b79SJean-Baptiste Boric 	udf_node->outstanding_nodedscr--;
2249f988b79SJean-Baptiste Boric 	if (udf_node->outstanding_nodedscr == 0) {
2259f988b79SJean-Baptiste Boric 		UDF_UNLOCK_NODE(udf_node, 0);
2269f988b79SJean-Baptiste Boric 		wakeup(&udf_node->outstanding_nodedscr);
2279f988b79SJean-Baptiste Boric 	}
2289f988b79SJean-Baptiste Boric 
2299f988b79SJean-Baptiste Boric 	return error;
2309f988b79SJean-Baptiste Boric }
2319f988b79SJean-Baptiste Boric 
2329f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
2339f988b79SJean-Baptiste Boric 
2349f988b79SJean-Baptiste Boric static void
udf_queue_buf_direct(struct udf_strat_args * args)2359f988b79SJean-Baptiste Boric udf_queue_buf_direct(struct udf_strat_args *args)
2369f988b79SJean-Baptiste Boric {
2379f988b79SJean-Baptiste Boric 	struct udf_mount *ump = args->ump;
2389f988b79SJean-Baptiste Boric 	struct buf *buf = args->nestbuf;
2399f988b79SJean-Baptiste Boric 	struct buf *nestbuf;
2409f988b79SJean-Baptiste Boric 	struct desc_tag *tag;
2419f988b79SJean-Baptiste Boric 	struct long_ad *node_ad_cpy;
2429f988b79SJean-Baptiste Boric 	uint64_t *lmapping, *pmapping, *lmappos, run_start;
2439f988b79SJean-Baptiste Boric 	uint32_t sectornr;
2449f988b79SJean-Baptiste Boric 	uint32_t buf_offset, rbuflen, bpos;
2459f988b79SJean-Baptiste Boric 	uint16_t vpart_num;
2469f988b79SJean-Baptiste Boric 	uint8_t *fidblk;
2479f988b79SJean-Baptiste Boric 	off_t rblk;
2489f988b79SJean-Baptiste Boric 	int sector_size = ump->discinfo.sector_size;
2499f988b79SJean-Baptiste Boric 	int len, buf_len, sector, sectors, run_length;
2509f988b79SJean-Baptiste Boric 	int blks = sector_size / DEV_BSIZE;
2519f988b79SJean-Baptiste Boric 	int what, class __diagused, queue;
2529f988b79SJean-Baptiste Boric 
2539f988b79SJean-Baptiste Boric 	KASSERT(ump);
2549f988b79SJean-Baptiste Boric 	KASSERT(buf);
2559f988b79SJean-Baptiste Boric 	KASSERT(buf->b_iodone == nestiobuf_iodone);
2569f988b79SJean-Baptiste Boric 
2579f988b79SJean-Baptiste Boric 	what = buf->b_udf_c_type;
2589f988b79SJean-Baptiste Boric 	queue = UDF_SHED_READING;
2599f988b79SJean-Baptiste Boric 	if ((buf->b_flags & B_READ) == 0) {
2609f988b79SJean-Baptiste Boric 		/* writing */
2619f988b79SJean-Baptiste Boric 		queue = UDF_SHED_SEQWRITING;
2629f988b79SJean-Baptiste Boric 		if (what == UDF_C_ABSOLUTE)
2639f988b79SJean-Baptiste Boric 			queue = UDF_SHED_WRITING;
2649f988b79SJean-Baptiste Boric 		if (what == UDF_C_DSCR)
2659f988b79SJean-Baptiste Boric 			queue = UDF_SHED_WRITING;
2669f988b79SJean-Baptiste Boric 		if (what == UDF_C_NODE)
2679f988b79SJean-Baptiste Boric 			queue = UDF_SHED_WRITING;
2689f988b79SJean-Baptiste Boric 	}
2699f988b79SJean-Baptiste Boric 
2709f988b79SJean-Baptiste Boric 	/* use disc sheduler */
2719f988b79SJean-Baptiste Boric 	class = ump->discinfo.mmc_class;
2729f988b79SJean-Baptiste Boric 	KASSERT((class == MMC_CLASS_UNKN) || (class == MMC_CLASS_DISC) ||
2739f988b79SJean-Baptiste Boric 		(ump->discinfo.mmc_cur & MMC_CAP_HW_DEFECTFREE) ||
2749f988b79SJean-Baptiste Boric 		(ump->vfs_mountp->mnt_flag & MNT_RDONLY));
2759f988b79SJean-Baptiste Boric 
2769f988b79SJean-Baptiste Boric #ifndef UDF_DEBUG
2779f988b79SJean-Baptiste Boric 	__USE(blks);
2789f988b79SJean-Baptiste Boric #endif
2799f988b79SJean-Baptiste Boric 	if (queue == UDF_SHED_READING) {
2809f988b79SJean-Baptiste Boric 		DPRINTF(SHEDULE, ("\nudf_issue_buf READ %p : sector %d type %d,"
2819f988b79SJean-Baptiste Boric 			"b_resid %d, b_bcount %d, b_bufsize %d\n",
2829f988b79SJean-Baptiste Boric 			buf, (uint32_t) buf->b_blkno / blks, buf->b_udf_c_type,
2839f988b79SJean-Baptiste Boric 			buf->b_resid, buf->b_bcount, buf->b_bufsize));
2849f988b79SJean-Baptiste Boric 		VOP_STRATEGY(ump->devvp, buf);
2859f988b79SJean-Baptiste Boric 		return;
2869f988b79SJean-Baptiste Boric 	}
2879f988b79SJean-Baptiste Boric 
2889f988b79SJean-Baptiste Boric 
2899f988b79SJean-Baptiste Boric 	if (queue == UDF_SHED_WRITING) {
2909f988b79SJean-Baptiste Boric 		DPRINTF(SHEDULE, ("\nudf_issue_buf WRITE %p : sector %d "
2919f988b79SJean-Baptiste Boric 			"type %d, b_resid %d, b_bcount %d, b_bufsize %d\n",
2929f988b79SJean-Baptiste Boric 			buf, (uint32_t) buf->b_blkno / blks, buf->b_udf_c_type,
2939f988b79SJean-Baptiste Boric 			buf->b_resid, buf->b_bcount, buf->b_bufsize));
2949f988b79SJean-Baptiste Boric 		KASSERT(buf->b_udf_c_type == UDF_C_DSCR ||
2959f988b79SJean-Baptiste Boric 			buf->b_udf_c_type == UDF_C_ABSOLUTE ||
2969f988b79SJean-Baptiste Boric 			buf->b_udf_c_type == UDF_C_NODE);
2979f988b79SJean-Baptiste Boric 		 udf_fixup_node_internals(ump, buf->b_data, buf->b_udf_c_type);
2989f988b79SJean-Baptiste Boric 		VOP_STRATEGY(ump->devvp, buf);
2999f988b79SJean-Baptiste Boric 		return;
3009f988b79SJean-Baptiste Boric 	}
3019f988b79SJean-Baptiste Boric 
3029f988b79SJean-Baptiste Boric 	/* UDF_SHED_SEQWRITING */
3039f988b79SJean-Baptiste Boric 	KASSERT(queue == UDF_SHED_SEQWRITING);
3049f988b79SJean-Baptiste Boric 	DPRINTF(SHEDULE, ("\nudf_issue_buf SEQWRITE %p : sector XXXX "
3059f988b79SJean-Baptiste Boric 		"type %d, b_resid %d, b_bcount %d, b_bufsize %d\n",
3069f988b79SJean-Baptiste Boric 		buf, buf->b_udf_c_type, buf->b_resid, buf->b_bcount,
3079f988b79SJean-Baptiste Boric 		buf->b_bufsize));
3089f988b79SJean-Baptiste Boric 
3099f988b79SJean-Baptiste Boric 	/*
3109f988b79SJean-Baptiste Boric 	 * Buffers should not have been allocated to disc addresses yet on
3119f988b79SJean-Baptiste Boric 	 * this queue. Note that a buffer can get multiple extents allocated.
3129f988b79SJean-Baptiste Boric 	 *
3139f988b79SJean-Baptiste Boric 	 * lmapping contains lb_num relative to base partition.
3149f988b79SJean-Baptiste Boric 	 */
3159f988b79SJean-Baptiste Boric 	lmapping    = ump->la_lmapping;
3169f988b79SJean-Baptiste Boric 	node_ad_cpy = ump->la_node_ad_cpy;
3179f988b79SJean-Baptiste Boric 
3189f988b79SJean-Baptiste Boric 	/* logically allocate buf and map it in the file */
3199f988b79SJean-Baptiste Boric 	udf_late_allocate_buf(ump, buf, lmapping, node_ad_cpy, &vpart_num);
3209f988b79SJean-Baptiste Boric 
3219f988b79SJean-Baptiste Boric 	/* if we have FIDs, fixup using the new allocation table */
3229f988b79SJean-Baptiste Boric 	if (buf->b_udf_c_type == UDF_C_FIDS) {
3239f988b79SJean-Baptiste Boric 		buf_len = buf->b_bcount;
3249f988b79SJean-Baptiste Boric 		bpos = 0;
3259f988b79SJean-Baptiste Boric 		lmappos = lmapping;
3269f988b79SJean-Baptiste Boric 		while (buf_len) {
3279f988b79SJean-Baptiste Boric 			sectornr = *lmappos++;
3289f988b79SJean-Baptiste Boric 			len = MIN(buf_len, sector_size);
3299f988b79SJean-Baptiste Boric 			fidblk = (uint8_t *) buf->b_data + bpos;
3309f988b79SJean-Baptiste Boric 			udf_fixup_fid_block(fidblk, sector_size,
3319f988b79SJean-Baptiste Boric 				0, len, sectornr);
3329f988b79SJean-Baptiste Boric 			bpos += len;
3339f988b79SJean-Baptiste Boric 			buf_len -= len;
3349f988b79SJean-Baptiste Boric 		}
3359f988b79SJean-Baptiste Boric 	}
3369f988b79SJean-Baptiste Boric 	if (buf->b_udf_c_type == UDF_C_METADATA_SBM) {
3379f988b79SJean-Baptiste Boric 		if (buf->b_lblkno == 0) {
3389f988b79SJean-Baptiste Boric 			/* update the tag location inside */
3399f988b79SJean-Baptiste Boric 			tag = (struct desc_tag *) buf->b_data;
3409f988b79SJean-Baptiste Boric 			tag->tag_loc = udf_rw32(*lmapping);
3419f988b79SJean-Baptiste Boric 			udf_validate_tag_and_crc_sums(buf->b_data);
3429f988b79SJean-Baptiste Boric 		}
3439f988b79SJean-Baptiste Boric 	}
3449f988b79SJean-Baptiste Boric 	udf_fixup_node_internals(ump, buf->b_data, buf->b_udf_c_type);
3459f988b79SJean-Baptiste Boric 
3469f988b79SJean-Baptiste Boric 	/*
3479f988b79SJean-Baptiste Boric 	 * Translate new mappings in lmapping to pmappings and try to
3489f988b79SJean-Baptiste Boric 	 * conglomerate extents to reduce the number of writes.
3499f988b79SJean-Baptiste Boric 	 *
3509f988b79SJean-Baptiste Boric 	 * pmapping to contain lb_nums as used for disc adressing.
3519f988b79SJean-Baptiste Boric 	 */
3529f988b79SJean-Baptiste Boric 	pmapping = ump->la_pmapping;
3539f988b79SJean-Baptiste Boric 	sectors  = (buf->b_bcount + sector_size -1) / sector_size;
3549f988b79SJean-Baptiste Boric 	udf_translate_vtop_list(ump, sectors, vpart_num, lmapping, pmapping);
3559f988b79SJean-Baptiste Boric 
3569f988b79SJean-Baptiste Boric 	for (sector = 0; sector < sectors; sector++) {
3579f988b79SJean-Baptiste Boric 		buf_offset = sector * sector_size;
3589f988b79SJean-Baptiste Boric 		DPRINTF(WRITE, ("\tprocessing rel sector %d\n", sector));
3599f988b79SJean-Baptiste Boric 
3609f988b79SJean-Baptiste Boric 		DPRINTF(WRITE, ("\tissue write sector %"PRIu64"\n",
3619f988b79SJean-Baptiste Boric 			pmapping[sector]));
3629f988b79SJean-Baptiste Boric 
3639f988b79SJean-Baptiste Boric 		run_start  = pmapping[sector];
3649f988b79SJean-Baptiste Boric 		run_length = 1;
3659f988b79SJean-Baptiste Boric 		while (sector < sectors-1) {
3669f988b79SJean-Baptiste Boric 			if (pmapping[sector+1] != pmapping[sector]+1)
3679f988b79SJean-Baptiste Boric 				break;
3689f988b79SJean-Baptiste Boric 			run_length++;
3699f988b79SJean-Baptiste Boric 			sector++;
3709f988b79SJean-Baptiste Boric 		}
3719f988b79SJean-Baptiste Boric 
3729f988b79SJean-Baptiste Boric 		/* nest an iobuf for the extent */
3739f988b79SJean-Baptiste Boric 		rbuflen = run_length *  sector_size;
3749f988b79SJean-Baptiste Boric 		rblk    = run_start  * (sector_size/DEV_BSIZE);
3759f988b79SJean-Baptiste Boric 
3769f988b79SJean-Baptiste Boric 		nestbuf = getiobuf(NULL, true);
3779f988b79SJean-Baptiste Boric 		nestiobuf_setup(buf, nestbuf, buf_offset, rbuflen);
3789f988b79SJean-Baptiste Boric 		/* nestbuf is B_ASYNC */
3799f988b79SJean-Baptiste Boric 
3809f988b79SJean-Baptiste Boric 		/* identify this nestbuf */
3819f988b79SJean-Baptiste Boric 		nestbuf->b_lblkno   = sector;
3829f988b79SJean-Baptiste Boric 		assert(nestbuf->b_vp == buf->b_vp);
3839f988b79SJean-Baptiste Boric 
3849f988b79SJean-Baptiste Boric 		/* CD shedules on raw blkno */
3859f988b79SJean-Baptiste Boric 		nestbuf->b_blkno      = rblk;
3869f988b79SJean-Baptiste Boric 		nestbuf->b_proc       = NULL;
3879f988b79SJean-Baptiste Boric 		nestbuf->b_rawblkno   = rblk;
3889f988b79SJean-Baptiste Boric 		nestbuf->b_udf_c_type = UDF_C_PROCESSED;
3899f988b79SJean-Baptiste Boric 
3909f988b79SJean-Baptiste Boric 		VOP_STRATEGY(ump->devvp, nestbuf);
3919f988b79SJean-Baptiste Boric 	}
3929f988b79SJean-Baptiste Boric }
3939f988b79SJean-Baptiste Boric 
3949f988b79SJean-Baptiste Boric 
3959f988b79SJean-Baptiste Boric static void
udf_discstrat_init_direct(struct udf_strat_args * args)3969f988b79SJean-Baptiste Boric udf_discstrat_init_direct(struct udf_strat_args *args)
3979f988b79SJean-Baptiste Boric {
3989f988b79SJean-Baptiste Boric 	struct udf_mount  *ump = args->ump;
3999f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
4009f988b79SJean-Baptiste Boric 	uint32_t lb_size;
4019f988b79SJean-Baptiste Boric 
4029f988b79SJean-Baptiste Boric 	KASSERT(priv == NULL);
4039f988b79SJean-Baptiste Boric 	ump->strategy_private = malloc(sizeof(struct strat_private),
4049f988b79SJean-Baptiste Boric 		M_UDFTEMP, M_WAITOK);
4059f988b79SJean-Baptiste Boric 	priv = ump->strategy_private;
4069f988b79SJean-Baptiste Boric 	memset(priv, 0 , sizeof(struct strat_private));
4079f988b79SJean-Baptiste Boric 
4089f988b79SJean-Baptiste Boric 	/*
4099f988b79SJean-Baptiste Boric 	 * Initialise pool for descriptors associated with nodes. This is done
4109f988b79SJean-Baptiste Boric 	 * in lb_size units though currently lb_size is dictated to be
4119f988b79SJean-Baptiste Boric 	 * sector_size.
4129f988b79SJean-Baptiste Boric 	 */
4139f988b79SJean-Baptiste Boric 	memset(&priv->desc_pool, 0, sizeof(struct pool));
4149f988b79SJean-Baptiste Boric 
4159f988b79SJean-Baptiste Boric 	lb_size = udf_rw32(ump->logical_vol->lb_size);
4169f988b79SJean-Baptiste Boric 	pool_init(&priv->desc_pool, lb_size, 0, 0, 0, "udf_desc_pool", NULL,
4179f988b79SJean-Baptiste Boric 	    IPL_NONE);
4189f988b79SJean-Baptiste Boric }
4199f988b79SJean-Baptiste Boric 
4209f988b79SJean-Baptiste Boric 
4219f988b79SJean-Baptiste Boric static void
udf_discstrat_finish_direct(struct udf_strat_args * args)4229f988b79SJean-Baptiste Boric udf_discstrat_finish_direct(struct udf_strat_args *args)
4239f988b79SJean-Baptiste Boric {
4249f988b79SJean-Baptiste Boric 	struct udf_mount *ump = args->ump;
4259f988b79SJean-Baptiste Boric 	struct strat_private *priv = PRIV(ump);
4269f988b79SJean-Baptiste Boric 
4279f988b79SJean-Baptiste Boric 	/* destroy our pool */
4289f988b79SJean-Baptiste Boric 	pool_destroy(&priv->desc_pool);
4299f988b79SJean-Baptiste Boric 
4309f988b79SJean-Baptiste Boric 	/* free our private space */
4319f988b79SJean-Baptiste Boric 	free(ump->strategy_private, M_UDFTEMP);
4329f988b79SJean-Baptiste Boric 	ump->strategy_private = NULL;
4339f988b79SJean-Baptiste Boric }
4349f988b79SJean-Baptiste Boric 
4359f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
4369f988b79SJean-Baptiste Boric 
4379f988b79SJean-Baptiste Boric struct udf_strategy udf_strat_direct =
4389f988b79SJean-Baptiste Boric {
4399f988b79SJean-Baptiste Boric 	udf_getblank_nodedscr_direct,
4409f988b79SJean-Baptiste Boric 	udf_free_nodedscr_direct,
4419f988b79SJean-Baptiste Boric 	udf_read_nodedscr_direct,
4429f988b79SJean-Baptiste Boric 	udf_write_nodedscr_direct,
4439f988b79SJean-Baptiste Boric 	udf_queue_buf_direct,
4449f988b79SJean-Baptiste Boric 	udf_discstrat_init_direct,
4459f988b79SJean-Baptiste Boric 	udf_discstrat_finish_direct
4469f988b79SJean-Baptiste Boric };
4479f988b79SJean-Baptiste Boric 
448