17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
580d34432Sfrankho * Common Development and Distribution License (the "License").
680d34432Sfrankho * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
2244c4f64bSJohn Levon * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23*4763305eSRobert Mustacchi * Copyright 2024 Oxide Computer Company
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
287c478bd9Sstevel@tonic-gate #include <sys/param.h>
297c478bd9Sstevel@tonic-gate #include <sys/time.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
327c478bd9Sstevel@tonic-gate #include <sys/resource.h>
337c478bd9Sstevel@tonic-gate #include <sys/signal.h>
347c478bd9Sstevel@tonic-gate #include <sys/cred.h>
357c478bd9Sstevel@tonic-gate #include <sys/user.h>
367c478bd9Sstevel@tonic-gate #include <sys/buf.h>
377c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
387c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
397c478bd9Sstevel@tonic-gate #include <sys/proc.h>
407c478bd9Sstevel@tonic-gate #include <sys/disp.h>
417c478bd9Sstevel@tonic-gate #include <sys/file.h>
427c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
437c478bd9Sstevel@tonic-gate #include <sys/flock.h>
44bc69f433Saguzovsk #include <sys/atomic.h>
457c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
467c478bd9Sstevel@tonic-gate #include <sys/uio.h>
477c478bd9Sstevel@tonic-gate #include <sys/conf.h>
487c478bd9Sstevel@tonic-gate #include <sys/mman.h>
497c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
507c478bd9Sstevel@tonic-gate #include <sys/debug.h>
517c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h>
527c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
537c478bd9Sstevel@tonic-gate #include <sys/filio.h>
547c478bd9Sstevel@tonic-gate #include <sys/dnlc.h>
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_filio.h>
577c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_lockfs.h>
587c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
597c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
607c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fsdir.h>
617c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_quota.h>
627c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_trans.h>
637c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_log.h>
647c478bd9Sstevel@tonic-gate #include <sys/dirent.h> /* must be AFTER <sys/fs/fsdir.h>! */
657c478bd9Sstevel@tonic-gate #include <sys/errno.h>
667c478bd9Sstevel@tonic-gate #include <sys/sysinfo.h>
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate #include <vm/hat.h>
697c478bd9Sstevel@tonic-gate #include <vm/page.h>
707c478bd9Sstevel@tonic-gate #include <vm/pvn.h>
717c478bd9Sstevel@tonic-gate #include <vm/as.h>
727c478bd9Sstevel@tonic-gate #include <vm/seg.h>
737c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
747c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
757c478bd9Sstevel@tonic-gate #include <vm/rm.h>
767c478bd9Sstevel@tonic-gate #include <sys/swap.h>
777c478bd9Sstevel@tonic-gate #include <sys/model.h>
787c478bd9Sstevel@tonic-gate #include <sys/policy.h>
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate #include "fs/fs_subr.h"
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate * ufs_fioio is the ufs equivalent of NFS_CNVT and is tailored to
847c478bd9Sstevel@tonic-gate * metamucil's needs. It may change at any time.
857c478bd9Sstevel@tonic-gate */
867c478bd9Sstevel@tonic-gate /* ARGSUSED */
877c478bd9Sstevel@tonic-gate int
ufs_fioio(struct vnode * vp,struct fioio * fiou,int flag,struct cred * cr)887c478bd9Sstevel@tonic-gate ufs_fioio(
897c478bd9Sstevel@tonic-gate struct vnode *vp, /* any file on the fs */
907c478bd9Sstevel@tonic-gate struct fioio *fiou, /* fioio struct in userland */
917c478bd9Sstevel@tonic-gate int flag, /* flag from VOP_IOCTL() */
927c478bd9Sstevel@tonic-gate struct cred *cr) /* credentials from ufs_ioctl */
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate int error = 0;
957c478bd9Sstevel@tonic-gate struct vnode *vpio = NULL; /* vnode for inode open */
967c478bd9Sstevel@tonic-gate struct inode *ipio = NULL; /* inode for inode open */
977c478bd9Sstevel@tonic-gate struct file *fpio = NULL; /* file for inode open */
987c478bd9Sstevel@tonic-gate struct inode *ip; /* inode for file system */
997c478bd9Sstevel@tonic-gate struct fs *fs; /* fs for file system */
1007c478bd9Sstevel@tonic-gate STRUCT_DECL(fioio, fio); /* copy of user's fioio struct */
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate * must be privileged
1047c478bd9Sstevel@tonic-gate */
1057c478bd9Sstevel@tonic-gate if (secpolicy_fs_config(cr, vp->v_vfsp) != 0)
1067c478bd9Sstevel@tonic-gate return (EPERM);
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate STRUCT_INIT(fio, flag & DATAMODEL_MASK);
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate * get user's copy of fioio struct
1127c478bd9Sstevel@tonic-gate */
1137c478bd9Sstevel@tonic-gate if (copyin(fiou, STRUCT_BUF(fio), STRUCT_SIZE(fio)))
1147c478bd9Sstevel@tonic-gate return (EFAULT);
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate ip = VTOI(vp);
1177c478bd9Sstevel@tonic-gate fs = ip->i_fs;
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate * check the inode number against the fs's inode number bounds
1217c478bd9Sstevel@tonic-gate */
1227c478bd9Sstevel@tonic-gate if (STRUCT_FGET(fio, fio_ino) < UFSROOTINO)
1237c478bd9Sstevel@tonic-gate return (ESRCH);
1247c478bd9Sstevel@tonic-gate if (STRUCT_FGET(fio, fio_ino) >= fs->fs_ncg * fs->fs_ipg)
1257c478bd9Sstevel@tonic-gate return (ESRCH);
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate rw_enter(&ip->i_ufsvfs->vfs_dqrwlock, RW_READER);
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate * get the inode
1317c478bd9Sstevel@tonic-gate */
1327c478bd9Sstevel@tonic-gate error = ufs_iget(ip->i_vfs, STRUCT_FGET(fio, fio_ino), &ipio, cr);
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate rw_exit(&ip->i_ufsvfs->vfs_dqrwlock);
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate if (error)
1377c478bd9Sstevel@tonic-gate return (error);
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate * check the generation number
1417c478bd9Sstevel@tonic-gate */
1427c478bd9Sstevel@tonic-gate rw_enter(&ipio->i_contents, RW_READER);
1437c478bd9Sstevel@tonic-gate if (ipio->i_gen != STRUCT_FGET(fio, fio_gen)) {
1447c478bd9Sstevel@tonic-gate error = ESTALE;
1457c478bd9Sstevel@tonic-gate rw_exit(&ipio->i_contents);
1467c478bd9Sstevel@tonic-gate goto errout;
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate * check if the inode is free
1517c478bd9Sstevel@tonic-gate */
1527c478bd9Sstevel@tonic-gate if (ipio->i_mode == 0) {
1537c478bd9Sstevel@tonic-gate error = ENOENT;
1547c478bd9Sstevel@tonic-gate rw_exit(&ipio->i_contents);
1557c478bd9Sstevel@tonic-gate goto errout;
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate rw_exit(&ipio->i_contents);
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate * Adapted from copen: get a file struct
1617c478bd9Sstevel@tonic-gate * Large Files: We open this file descriptor with FOFFMAX flag
1627c478bd9Sstevel@tonic-gate * set so that it will be like a large file open.
1637c478bd9Sstevel@tonic-gate */
1647c478bd9Sstevel@tonic-gate if (falloc(NULL, (FREAD|FOFFMAX), &fpio, STRUCT_FADDR(fio, fio_fd)))
1657c478bd9Sstevel@tonic-gate goto errout;
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate * Adapted from vn_open: check access and then open the file
1697c478bd9Sstevel@tonic-gate */
1707c478bd9Sstevel@tonic-gate vpio = ITOV(ipio);
171da6c28aaSamw if (error = VOP_ACCESS(vpio, VREAD, 0, cr, NULL))
1727c478bd9Sstevel@tonic-gate goto errout;
1737c478bd9Sstevel@tonic-gate
174da6c28aaSamw if (error = VOP_OPEN(&vpio, FREAD, cr, NULL))
1757c478bd9Sstevel@tonic-gate goto errout;
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate * Adapted from copen: initialize the file struct
1797c478bd9Sstevel@tonic-gate */
1807c478bd9Sstevel@tonic-gate fpio->f_vnode = vpio;
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate * return the fd
1847c478bd9Sstevel@tonic-gate */
1857c478bd9Sstevel@tonic-gate if (copyout(STRUCT_BUF(fio), fiou, STRUCT_SIZE(fio))) {
1867c478bd9Sstevel@tonic-gate error = EFAULT;
1877c478bd9Sstevel@tonic-gate goto errout;
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate setf(STRUCT_FGET(fio, fio_fd), fpio);
1907c478bd9Sstevel@tonic-gate mutex_exit(&fpio->f_tlock);
1917c478bd9Sstevel@tonic-gate return (0);
1927c478bd9Sstevel@tonic-gate errout:
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate * free the file struct and fd
1957c478bd9Sstevel@tonic-gate */
1967c478bd9Sstevel@tonic-gate if (fpio) {
1977c478bd9Sstevel@tonic-gate setf(STRUCT_FGET(fio, fio_fd), NULL);
1987c478bd9Sstevel@tonic-gate unfalloc(fpio);
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate /*
2027c478bd9Sstevel@tonic-gate * release the hold on the inode
2037c478bd9Sstevel@tonic-gate */
2047c478bd9Sstevel@tonic-gate if (ipio)
2057c478bd9Sstevel@tonic-gate VN_RELE(ITOV(ipio));
2067c478bd9Sstevel@tonic-gate return (error);
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate /*
2107c478bd9Sstevel@tonic-gate * ufs_fiosatime
2117c478bd9Sstevel@tonic-gate * set access time w/o altering change time. This ioctl is tailored
2127c478bd9Sstevel@tonic-gate * to metamucil's needs and may change at any time.
2137c478bd9Sstevel@tonic-gate */
2147c478bd9Sstevel@tonic-gate int
ufs_fiosatime(struct vnode * vp,struct timeval * tvu,int flag,struct cred * cr)2157c478bd9Sstevel@tonic-gate ufs_fiosatime(
2167c478bd9Sstevel@tonic-gate struct vnode *vp, /* file's vnode */
2177c478bd9Sstevel@tonic-gate struct timeval *tvu, /* struct timeval in userland */
2187c478bd9Sstevel@tonic-gate int flag, /* flag from VOP_IOCTL() */
2197c478bd9Sstevel@tonic-gate struct cred *cr) /* credentials from ufs_ioctl */
2207c478bd9Sstevel@tonic-gate {
2217c478bd9Sstevel@tonic-gate struct inode *ip; /* inode for vp */
2227c478bd9Sstevel@tonic-gate struct timeval32 tv; /* copy of user's timeval */
2237c478bd9Sstevel@tonic-gate int now = 0;
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate * must have sufficient privileges
2277c478bd9Sstevel@tonic-gate */
2287c478bd9Sstevel@tonic-gate if (secpolicy_fs_config(cr, vp->v_vfsp) != 0)
2297c478bd9Sstevel@tonic-gate return (EPERM);
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate * get user's copy of timeval struct and check values
2337c478bd9Sstevel@tonic-gate * if input is NULL, will set time to now
2347c478bd9Sstevel@tonic-gate */
2357c478bd9Sstevel@tonic-gate if (tvu == NULL) {
2367c478bd9Sstevel@tonic-gate now = 1;
2377c478bd9Sstevel@tonic-gate } else {
2387c478bd9Sstevel@tonic-gate if ((flag & DATAMODEL_MASK) == DATAMODEL_ILP32) {
2397c478bd9Sstevel@tonic-gate if (copyin(tvu, &tv, sizeof (tv)))
2407c478bd9Sstevel@tonic-gate return (EFAULT);
2417c478bd9Sstevel@tonic-gate } else {
2427c478bd9Sstevel@tonic-gate struct timeval tv64;
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate if (copyin(tvu, &tv64, sizeof (tv64)))
2457c478bd9Sstevel@tonic-gate return (EFAULT);
2467c478bd9Sstevel@tonic-gate if (TIMEVAL_OVERFLOW(&tv64))
2477c478bd9Sstevel@tonic-gate return (EOVERFLOW);
2487c478bd9Sstevel@tonic-gate TIMEVAL_TO_TIMEVAL32(&tv, &tv64);
2497c478bd9Sstevel@tonic-gate }
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate if (tv.tv_usec < 0 || tv.tv_usec >= 1000000)
2527c478bd9Sstevel@tonic-gate return (EINVAL);
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate /*
2567c478bd9Sstevel@tonic-gate * update access time
2577c478bd9Sstevel@tonic-gate */
2587c478bd9Sstevel@tonic-gate ip = VTOI(vp);
2597c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
2607c478bd9Sstevel@tonic-gate ITIMES_NOLOCK(ip);
2617c478bd9Sstevel@tonic-gate if (now) {
2627c478bd9Sstevel@tonic-gate mutex_enter(&ufs_iuniqtime_lock);
2637c478bd9Sstevel@tonic-gate ip->i_atime = iuniqtime;
2647c478bd9Sstevel@tonic-gate mutex_exit(&ufs_iuniqtime_lock);
2657c478bd9Sstevel@tonic-gate } else {
2667c478bd9Sstevel@tonic-gate ip->i_atime = tv;
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate ip->i_flag |= IMODACC;
2697c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate return (0);
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate /*
2757c478bd9Sstevel@tonic-gate * ufs_fiogdio
2767c478bd9Sstevel@tonic-gate * Get delayed-io state. This ioctl is tailored
2777c478bd9Sstevel@tonic-gate * to metamucil's needs and may change at any time.
2787c478bd9Sstevel@tonic-gate */
2797c478bd9Sstevel@tonic-gate /* ARGSUSED */
2807c478bd9Sstevel@tonic-gate int
ufs_fiogdio(struct vnode * vp,uint_t * diop,int flag,struct cred * cr)2817c478bd9Sstevel@tonic-gate ufs_fiogdio(
2827c478bd9Sstevel@tonic-gate struct vnode *vp, /* file's vnode */
2837c478bd9Sstevel@tonic-gate uint_t *diop, /* dio state returned here */
2847c478bd9Sstevel@tonic-gate int flag, /* flag from ufs_ioctl */
2857c478bd9Sstevel@tonic-gate struct cred *cr) /* credentials from ufs_ioctl */
2867c478bd9Sstevel@tonic-gate {
2877c478bd9Sstevel@tonic-gate struct ufsvfs *ufsvfsp = VTOI(vp)->i_ufsvfs;
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate /*
2907c478bd9Sstevel@tonic-gate * forcibly unmounted
2917c478bd9Sstevel@tonic-gate */
2927c478bd9Sstevel@tonic-gate if (ufsvfsp == NULL)
2937c478bd9Sstevel@tonic-gate return (EIO);
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate if (suword32(diop, ufsvfsp->vfs_dio))
2967c478bd9Sstevel@tonic-gate return (EFAULT);
2977c478bd9Sstevel@tonic-gate return (0);
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate /*
3017c478bd9Sstevel@tonic-gate * ufs_fiosdio
3027c478bd9Sstevel@tonic-gate * Set delayed-io state. This ioctl is tailored
3037c478bd9Sstevel@tonic-gate * to metamucil's needs and may change at any time.
3047c478bd9Sstevel@tonic-gate */
3057c478bd9Sstevel@tonic-gate int
ufs_fiosdio(struct vnode * vp,uint_t * diop,int flag,struct cred * cr)3067c478bd9Sstevel@tonic-gate ufs_fiosdio(
3077c478bd9Sstevel@tonic-gate struct vnode *vp, /* file's vnode */
3087c478bd9Sstevel@tonic-gate uint_t *diop, /* dio flag */
3097c478bd9Sstevel@tonic-gate int flag, /* flag from ufs_ioctl */
3107c478bd9Sstevel@tonic-gate struct cred *cr) /* credentials from ufs_ioctl */
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate uint_t dio; /* copy of user's dio */
3137c478bd9Sstevel@tonic-gate struct inode *ip; /* inode for vp */
3147c478bd9Sstevel@tonic-gate struct ufsvfs *ufsvfsp;
3157c478bd9Sstevel@tonic-gate struct fs *fs;
3167c478bd9Sstevel@tonic-gate struct ulockfs *ulp;
3177c478bd9Sstevel@tonic-gate int error = 0;
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate #ifdef lint
3207c478bd9Sstevel@tonic-gate flag = flag;
3217c478bd9Sstevel@tonic-gate #endif
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate /* check input conditions */
3247c478bd9Sstevel@tonic-gate if (secpolicy_fs_config(cr, vp->v_vfsp) != 0)
3257c478bd9Sstevel@tonic-gate return (EPERM);
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate if (copyin(diop, &dio, sizeof (dio)))
3287c478bd9Sstevel@tonic-gate return (EFAULT);
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate if (dio > 1)
3317c478bd9Sstevel@tonic-gate return (EINVAL);
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate /* file system has been forcibly unmounted */
3347c478bd9Sstevel@tonic-gate if (VTOI(vp)->i_ufsvfs == NULL)
3357c478bd9Sstevel@tonic-gate return (EIO);
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate ip = VTOI(vp);
3387c478bd9Sstevel@tonic-gate ufsvfsp = ip->i_ufsvfs;
3397c478bd9Sstevel@tonic-gate ulp = &ufsvfsp->vfs_ulockfs;
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate /* logging file system; dio ignored */
3427c478bd9Sstevel@tonic-gate if (TRANS_ISTRANS(ufsvfsp))
3437c478bd9Sstevel@tonic-gate return (error);
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate /* hold the mutex to prevent race with a lockfs request */
3467c478bd9Sstevel@tonic-gate vfs_lock_wait(vp->v_vfsp);
3477c478bd9Sstevel@tonic-gate mutex_enter(&ulp->ul_lock);
3481a5e258fSJosef 'Jeff' Sipek atomic_inc_ulong(&ufs_quiesce_pend);
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate if (ULOCKFS_IS_HLOCK(ulp)) {
3517c478bd9Sstevel@tonic-gate error = EIO;
3527c478bd9Sstevel@tonic-gate goto out;
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate if (ULOCKFS_IS_ELOCK(ulp)) {
3567c478bd9Sstevel@tonic-gate error = EBUSY;
3577c478bd9Sstevel@tonic-gate goto out;
3587c478bd9Sstevel@tonic-gate }
3597c478bd9Sstevel@tonic-gate /* wait for outstanding accesses to finish */
3607c478bd9Sstevel@tonic-gate if (error = ufs_quiesce(ulp))
3617c478bd9Sstevel@tonic-gate goto out;
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate /* flush w/invalidate */
3647c478bd9Sstevel@tonic-gate if (error = ufs_flush(vp->v_vfsp))
3657c478bd9Sstevel@tonic-gate goto out;
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate /*
3687c478bd9Sstevel@tonic-gate * update dio
3697c478bd9Sstevel@tonic-gate */
3707c478bd9Sstevel@tonic-gate mutex_enter(&ufsvfsp->vfs_lock);
3717c478bd9Sstevel@tonic-gate ufsvfsp->vfs_dio = dio;
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate /*
3747c478bd9Sstevel@tonic-gate * enable/disable clean flag processing
3757c478bd9Sstevel@tonic-gate */
3767c478bd9Sstevel@tonic-gate fs = ip->i_fs;
3777c478bd9Sstevel@tonic-gate if (fs->fs_ronly == 0 &&
3787c478bd9Sstevel@tonic-gate fs->fs_clean != FSBAD &&
3797c478bd9Sstevel@tonic-gate fs->fs_clean != FSLOG) {
3807c478bd9Sstevel@tonic-gate if (dio)
3817c478bd9Sstevel@tonic-gate fs->fs_clean = FSSUSPEND;
3827c478bd9Sstevel@tonic-gate else
3837c478bd9Sstevel@tonic-gate fs->fs_clean = FSACTIVE;
3847c478bd9Sstevel@tonic-gate ufs_sbwrite(ufsvfsp);
3857c478bd9Sstevel@tonic-gate mutex_exit(&ufsvfsp->vfs_lock);
3867c478bd9Sstevel@tonic-gate } else
3877c478bd9Sstevel@tonic-gate mutex_exit(&ufsvfsp->vfs_lock);
3887c478bd9Sstevel@tonic-gate out:
3897c478bd9Sstevel@tonic-gate /*
3907c478bd9Sstevel@tonic-gate * we need this broadcast because of the ufs_quiesce call above
3917c478bd9Sstevel@tonic-gate */
3921a5e258fSJosef 'Jeff' Sipek atomic_dec_ulong(&ufs_quiesce_pend);
3937c478bd9Sstevel@tonic-gate cv_broadcast(&ulp->ul_cv);
3947c478bd9Sstevel@tonic-gate mutex_exit(&ulp->ul_lock);
3957c478bd9Sstevel@tonic-gate vfs_unlock(vp->v_vfsp);
3967c478bd9Sstevel@tonic-gate return (error);
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate /*
400*4763305eSRobert Mustacchi * ufs_fioffs - common function for VFS and ioctl entry points to flush a single
401*4763305eSRobert Mustacchi * file system.
4027c478bd9Sstevel@tonic-gate */
4037c478bd9Sstevel@tonic-gate int
ufs_fioffs(vfs_t * vfsp,cred_t * cr)404*4763305eSRobert Mustacchi ufs_fioffs(vfs_t *vfsp, cred_t *cr)
4057c478bd9Sstevel@tonic-gate {
4067c478bd9Sstevel@tonic-gate int error;
4077c478bd9Sstevel@tonic-gate struct ufsvfs *ufsvfsp;
4087c478bd9Sstevel@tonic-gate struct ulockfs *ulp;
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate /* file system has been forcibly unmounted */
411*4763305eSRobert Mustacchi if ((vfsp->vfs_flag & VFS_UNMOUNTED) != 0)
4127c478bd9Sstevel@tonic-gate return (EIO);
4137c478bd9Sstevel@tonic-gate
414*4763305eSRobert Mustacchi ufsvfsp = vfsp->vfs_data;
4157c478bd9Sstevel@tonic-gate ulp = &ufsvfsp->vfs_ulockfs;
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate * suspend the delete thread
4197c478bd9Sstevel@tonic-gate * this must be done outside the lockfs locking protocol
4207c478bd9Sstevel@tonic-gate */
421*4763305eSRobert Mustacchi vfs_lock_wait(vfsp);
4227c478bd9Sstevel@tonic-gate ufs_thread_suspend(&ufsvfsp->vfs_delete);
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate /* hold the mutex to prevent race with a lockfs request */
4257c478bd9Sstevel@tonic-gate mutex_enter(&ulp->ul_lock);
4261a5e258fSJosef 'Jeff' Sipek atomic_inc_ulong(&ufs_quiesce_pend);
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate if (ULOCKFS_IS_HLOCK(ulp)) {
4297c478bd9Sstevel@tonic-gate error = EIO;
4307c478bd9Sstevel@tonic-gate goto out;
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate if (ULOCKFS_IS_ELOCK(ulp)) {
4337c478bd9Sstevel@tonic-gate error = EBUSY;
4347c478bd9Sstevel@tonic-gate goto out;
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate /* wait for outstanding accesses to finish */
4377c478bd9Sstevel@tonic-gate if (error = ufs_quiesce(ulp))
4387c478bd9Sstevel@tonic-gate goto out;
4397c478bd9Sstevel@tonic-gate
4407c478bd9Sstevel@tonic-gate /*
4417c478bd9Sstevel@tonic-gate * If logging, and the logmap was marked as not rollable,
4427c478bd9Sstevel@tonic-gate * make it rollable now, and start the trans_roll thread and
4437c478bd9Sstevel@tonic-gate * the reclaim thread. The log at this point is safe to write to.
4447c478bd9Sstevel@tonic-gate */
4457c478bd9Sstevel@tonic-gate if (ufsvfsp->vfs_log) {
4467c478bd9Sstevel@tonic-gate ml_unit_t *ul = ufsvfsp->vfs_log;
4477c478bd9Sstevel@tonic-gate struct fs *fsp = ufsvfsp->vfs_fs;
4487c478bd9Sstevel@tonic-gate int err;
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate if (ul->un_flags & LDL_NOROLL) {
4517c478bd9Sstevel@tonic-gate ul->un_flags &= ~LDL_NOROLL;
4527c478bd9Sstevel@tonic-gate logmap_start_roll(ul);
4537c478bd9Sstevel@tonic-gate if (!fsp->fs_ronly && (fsp->fs_reclaim &
4547c478bd9Sstevel@tonic-gate (FS_RECLAIM|FS_RECLAIMING))) {
4557c478bd9Sstevel@tonic-gate fsp->fs_reclaim &= ~FS_RECLAIM;
4567c478bd9Sstevel@tonic-gate fsp->fs_reclaim |= FS_RECLAIMING;
4577c478bd9Sstevel@tonic-gate ufs_thread_start(&ufsvfsp->vfs_reclaim,
458*4763305eSRobert Mustacchi ufs_thread_reclaim, vfsp);
4597c478bd9Sstevel@tonic-gate if (!fsp->fs_ronly) {
4607c478bd9Sstevel@tonic-gate TRANS_SBWRITE(ufsvfsp,
4617c478bd9Sstevel@tonic-gate TOP_SBUPDATE_UPDATE);
4627c478bd9Sstevel@tonic-gate if (err =
4637c478bd9Sstevel@tonic-gate geterror(ufsvfsp->vfs_bufp)) {
4647c478bd9Sstevel@tonic-gate refstr_t *mntpt;
465*4763305eSRobert Mustacchi mntpt = vfs_getmntpoint(vfsp);
4667c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE,
4677c478bd9Sstevel@tonic-gate "Filesystem Flush "
4687c478bd9Sstevel@tonic-gate "Failed to update "
4697c478bd9Sstevel@tonic-gate "Reclaim Status for "
4707c478bd9Sstevel@tonic-gate " %s, Write failed to "
4717c478bd9Sstevel@tonic-gate "update superblock, "
4727c478bd9Sstevel@tonic-gate "error %d",
4737c478bd9Sstevel@tonic-gate refstr_value(mntpt),
4747c478bd9Sstevel@tonic-gate err);
4757c478bd9Sstevel@tonic-gate refstr_rele(mntpt);
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate }
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate }
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate
4827c478bd9Sstevel@tonic-gate /* synchronously flush dirty data and metadata */
483*4763305eSRobert Mustacchi error = ufs_flush(vfsp);
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gate out:
4861a5e258fSJosef 'Jeff' Sipek atomic_dec_ulong(&ufs_quiesce_pend);
4877c478bd9Sstevel@tonic-gate cv_broadcast(&ulp->ul_cv);
4887c478bd9Sstevel@tonic-gate mutex_exit(&ulp->ul_lock);
489*4763305eSRobert Mustacchi vfs_unlock(vfsp);
4907c478bd9Sstevel@tonic-gate
4917c478bd9Sstevel@tonic-gate /*
4927c478bd9Sstevel@tonic-gate * allow the delete thread to continue
4937c478bd9Sstevel@tonic-gate */
4947c478bd9Sstevel@tonic-gate ufs_thread_continue(&ufsvfsp->vfs_delete);
4957c478bd9Sstevel@tonic-gate return (error);
4967c478bd9Sstevel@tonic-gate }
4977c478bd9Sstevel@tonic-gate
4987c478bd9Sstevel@tonic-gate /*
4997c478bd9Sstevel@tonic-gate * ufs_fioisbusy
5007c478bd9Sstevel@tonic-gate * Get number of references on this vnode.
5017c478bd9Sstevel@tonic-gate * Contract-private interface for Legato's NetWorker product.
5027c478bd9Sstevel@tonic-gate */
5037c478bd9Sstevel@tonic-gate /* ARGSUSED */
5047c478bd9Sstevel@tonic-gate int
ufs_fioisbusy(struct vnode * vp,int * isbusy,struct cred * cr)5057c478bd9Sstevel@tonic-gate ufs_fioisbusy(struct vnode *vp, int *isbusy, struct cred *cr)
5067c478bd9Sstevel@tonic-gate {
5077c478bd9Sstevel@tonic-gate int is_it_busy;
5087c478bd9Sstevel@tonic-gate
5097c478bd9Sstevel@tonic-gate /*
5107c478bd9Sstevel@tonic-gate * The caller holds one reference, there may be one in the dnlc
5117c478bd9Sstevel@tonic-gate * so we need to flush it.
5127c478bd9Sstevel@tonic-gate */
5137c478bd9Sstevel@tonic-gate if (vp->v_count > 1)
5147c478bd9Sstevel@tonic-gate dnlc_purge_vp(vp);
5157c478bd9Sstevel@tonic-gate /*
5167c478bd9Sstevel@tonic-gate * Since we've just flushed the dnlc and we hold a reference
5177c478bd9Sstevel@tonic-gate * to this vnode, then anything but 1 means busy (this had
5187c478bd9Sstevel@tonic-gate * BETTER not be zero!). Also, it's possible for someone to
5197c478bd9Sstevel@tonic-gate * have this file mmap'ed with no additional reference count.
5207c478bd9Sstevel@tonic-gate */
5217c478bd9Sstevel@tonic-gate ASSERT(vp->v_count > 0);
5227c478bd9Sstevel@tonic-gate if ((vp->v_count == 1) && (VTOI(vp)->i_mapcnt == 0))
5237c478bd9Sstevel@tonic-gate is_it_busy = 0;
5247c478bd9Sstevel@tonic-gate else
5257c478bd9Sstevel@tonic-gate is_it_busy = 1;
5267c478bd9Sstevel@tonic-gate
5277c478bd9Sstevel@tonic-gate if (suword32(isbusy, is_it_busy))
5287c478bd9Sstevel@tonic-gate return (EFAULT);
5297c478bd9Sstevel@tonic-gate return (0);
5307c478bd9Sstevel@tonic-gate }
5317c478bd9Sstevel@tonic-gate
5327c478bd9Sstevel@tonic-gate /* ARGSUSED */
5337c478bd9Sstevel@tonic-gate int
ufs_fiodirectio(struct vnode * vp,int cmd,struct cred * cr)5347c478bd9Sstevel@tonic-gate ufs_fiodirectio(struct vnode *vp, int cmd, struct cred *cr)
5357c478bd9Sstevel@tonic-gate {
5367c478bd9Sstevel@tonic-gate int error = 0;
5377c478bd9Sstevel@tonic-gate struct inode *ip = VTOI(vp);
5387c478bd9Sstevel@tonic-gate
5397c478bd9Sstevel@tonic-gate /*
5407c478bd9Sstevel@tonic-gate * Acquire reader lock and set/reset direct mode
5417c478bd9Sstevel@tonic-gate */
5427c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_READER);
5437c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
5447c478bd9Sstevel@tonic-gate if (cmd == DIRECTIO_ON)
5457c478bd9Sstevel@tonic-gate ip->i_flag |= IDIRECTIO; /* enable direct mode */
5467c478bd9Sstevel@tonic-gate else if (cmd == DIRECTIO_OFF)
5477c478bd9Sstevel@tonic-gate ip->i_flag &= ~IDIRECTIO; /* disable direct mode */
5487c478bd9Sstevel@tonic-gate else
5497c478bd9Sstevel@tonic-gate error = EINVAL;
5507c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
5517c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
5527c478bd9Sstevel@tonic-gate return (error);
5537c478bd9Sstevel@tonic-gate }
5547c478bd9Sstevel@tonic-gate
5557c478bd9Sstevel@tonic-gate /*
5567c478bd9Sstevel@tonic-gate * ufs_fiotune
5577c478bd9Sstevel@tonic-gate * Allow some tunables to be set on a mounted fs
5587c478bd9Sstevel@tonic-gate */
5597c478bd9Sstevel@tonic-gate int
ufs_fiotune(struct vnode * vp,struct fiotune * uftp,struct cred * cr)5607c478bd9Sstevel@tonic-gate ufs_fiotune(struct vnode *vp, struct fiotune *uftp, struct cred *cr)
5617c478bd9Sstevel@tonic-gate {
5627c478bd9Sstevel@tonic-gate struct fiotune ftp;
5637c478bd9Sstevel@tonic-gate struct fs *fs;
5647c478bd9Sstevel@tonic-gate struct ufsvfs *ufsvfsp;
5657c478bd9Sstevel@tonic-gate
5667c478bd9Sstevel@tonic-gate /*
5677c478bd9Sstevel@tonic-gate * must have sufficient privileges
5687c478bd9Sstevel@tonic-gate */
5697c478bd9Sstevel@tonic-gate if (secpolicy_fs_config(cr, vp->v_vfsp) != 0)
5707c478bd9Sstevel@tonic-gate return (EPERM);
5717c478bd9Sstevel@tonic-gate
5727c478bd9Sstevel@tonic-gate /*
5737c478bd9Sstevel@tonic-gate * get user's copy
5747c478bd9Sstevel@tonic-gate */
5757c478bd9Sstevel@tonic-gate if (copyin(uftp, &ftp, sizeof (ftp)))
5767c478bd9Sstevel@tonic-gate return (EFAULT);
5777c478bd9Sstevel@tonic-gate
5787c478bd9Sstevel@tonic-gate /*
5797c478bd9Sstevel@tonic-gate * some minimal sanity checks
5807c478bd9Sstevel@tonic-gate */
5817c478bd9Sstevel@tonic-gate if ((ftp.maxcontig <= 0) ||
5827c478bd9Sstevel@tonic-gate (ftp.rotdelay != 0) ||
5837c478bd9Sstevel@tonic-gate (ftp.maxbpg <= 0) ||
5847c478bd9Sstevel@tonic-gate (ftp.minfree < 0) ||
5857c478bd9Sstevel@tonic-gate (ftp.minfree > 99) ||
5867c478bd9Sstevel@tonic-gate ((ftp.optim != FS_OPTTIME) && (ftp.optim != FS_OPTSPACE)))
5877c478bd9Sstevel@tonic-gate return (EINVAL);
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate /*
5907c478bd9Sstevel@tonic-gate * update superblock but don't write it! If it gets out, fine.
5917c478bd9Sstevel@tonic-gate */
5927c478bd9Sstevel@tonic-gate fs = VTOI(vp)->i_fs;
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate fs->fs_maxcontig = ftp.maxcontig;
5957c478bd9Sstevel@tonic-gate fs->fs_rotdelay = ftp.rotdelay;
5967c478bd9Sstevel@tonic-gate fs->fs_maxbpg = ftp.maxbpg;
5977c478bd9Sstevel@tonic-gate fs->fs_minfree = ftp.minfree;
5987c478bd9Sstevel@tonic-gate fs->fs_optim = ftp.optim;
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate /*
6017c478bd9Sstevel@tonic-gate * Adjust cluster based on the new maxcontig. The cluster size
6027c478bd9Sstevel@tonic-gate * can be any positive value. The check for this is done above.
6037c478bd9Sstevel@tonic-gate */
6047c478bd9Sstevel@tonic-gate ufsvfsp = VTOI(vp)->i_ufsvfs;
6057c478bd9Sstevel@tonic-gate ufsvfsp->vfs_ioclustsz = fs->fs_bsize * fs->fs_maxcontig;
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate /*
6087c478bd9Sstevel@tonic-gate * Adjust minfrags from minfree
6097c478bd9Sstevel@tonic-gate */
6107c478bd9Sstevel@tonic-gate ufsvfsp->vfs_minfrags = (int)((int64_t)fs->fs_dsize *
6117c478bd9Sstevel@tonic-gate fs->fs_minfree / 100);
6127c478bd9Sstevel@tonic-gate
6137c478bd9Sstevel@tonic-gate /*
6147c478bd9Sstevel@tonic-gate * Write the superblock
6157c478bd9Sstevel@tonic-gate */
6167c478bd9Sstevel@tonic-gate if (fs->fs_ronly == 0) {
6177c478bd9Sstevel@tonic-gate TRANS_BEGIN_ASYNC(ufsvfsp, TOP_SBUPDATE_UPDATE,
6187c478bd9Sstevel@tonic-gate TOP_SBWRITE_SIZE);
6197c478bd9Sstevel@tonic-gate TRANS_SBWRITE(ufsvfsp, TOP_SBUPDATE_UPDATE);
6207c478bd9Sstevel@tonic-gate TRANS_END_ASYNC(ufsvfsp, TOP_SBUPDATE_UPDATE, TOP_SBWRITE_SIZE);
6217c478bd9Sstevel@tonic-gate }
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate return (0);
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate
6267c478bd9Sstevel@tonic-gate /*
6277c478bd9Sstevel@tonic-gate * Lseek support for finding holes (cmd == _FIO_SEEK_HOLE) and
6287c478bd9Sstevel@tonic-gate * data (cmd == _FIO_SEEK_DATA). "off" is an in/out parameter.
6297c478bd9Sstevel@tonic-gate */
6307c478bd9Sstevel@tonic-gate int
ufs_fio_holey(vnode_t * vp,int cmd,offset_t * off)6317c478bd9Sstevel@tonic-gate ufs_fio_holey(vnode_t *vp, int cmd, offset_t *off)
6327c478bd9Sstevel@tonic-gate {
6337c478bd9Sstevel@tonic-gate inode_t *ip = VTOI(vp);
6347c478bd9Sstevel@tonic-gate u_offset_t noff = (u_offset_t)*off; /* new offset */
6357c478bd9Sstevel@tonic-gate u_offset_t isz;
6367c478bd9Sstevel@tonic-gate int error;
6377c478bd9Sstevel@tonic-gate boolean_t hole;
6387c478bd9Sstevel@tonic-gate
6397c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_READER);
64043dcf702Sperrin isz = ip->i_size;
64143dcf702Sperrin if (noff >= isz) {
6427c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
6437c478bd9Sstevel@tonic-gate return (ENXIO);
6447c478bd9Sstevel@tonic-gate }
6457c478bd9Sstevel@tonic-gate
6467c478bd9Sstevel@tonic-gate /*
6477c478bd9Sstevel@tonic-gate * Check for the usual case where a file has no holes.
6487c478bd9Sstevel@tonic-gate * If so we can optimise to set the end of the file as the first
6497c478bd9Sstevel@tonic-gate * (virtual) hole. This avoids bmap_find() searching through
6507c478bd9Sstevel@tonic-gate * every block in the file for a (non-existent) hole.
6517c478bd9Sstevel@tonic-gate */
6527c478bd9Sstevel@tonic-gate if (!bmap_has_holes(ip)) {
6537c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
6547c478bd9Sstevel@tonic-gate if (cmd == _FIO_SEEK_HOLE) {
6557c478bd9Sstevel@tonic-gate *off = isz;
6567c478bd9Sstevel@tonic-gate return (0);
6577c478bd9Sstevel@tonic-gate }
6587c478bd9Sstevel@tonic-gate /* *off must already point to valid data (non hole) */
6597c478bd9Sstevel@tonic-gate return (0);
6607c478bd9Sstevel@tonic-gate }
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate /*
6637c478bd9Sstevel@tonic-gate * Calling bmap_read() one block at a time on a 1TB file takes forever,
6647c478bd9Sstevel@tonic-gate * so we use a special function to search for holes or blocks.
6657c478bd9Sstevel@tonic-gate */
6667c478bd9Sstevel@tonic-gate if (cmd == _FIO_SEEK_HOLE)
6677c478bd9Sstevel@tonic-gate hole = B_TRUE;
6687c478bd9Sstevel@tonic-gate else
6697c478bd9Sstevel@tonic-gate hole = B_FALSE;
6707c478bd9Sstevel@tonic-gate error = bmap_find(ip, hole, &noff);
6717c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate /* end of file? */
6747c478bd9Sstevel@tonic-gate if (error == ENXIO) {
6757c478bd9Sstevel@tonic-gate /*
6767c478bd9Sstevel@tonic-gate * Handle the virtual hole at the end of file.
6777c478bd9Sstevel@tonic-gate */
6787c478bd9Sstevel@tonic-gate if (cmd == _FIO_SEEK_HOLE) {
6797c478bd9Sstevel@tonic-gate *off = isz;
6807c478bd9Sstevel@tonic-gate return (0);
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate return (ENXIO);
6837c478bd9Sstevel@tonic-gate }
6847c478bd9Sstevel@tonic-gate if (noff < *off)
6857c478bd9Sstevel@tonic-gate return (error);
6867c478bd9Sstevel@tonic-gate *off = noff;
6877c478bd9Sstevel@tonic-gate return (error);
6887c478bd9Sstevel@tonic-gate }
689986fd29aSsetje
690986fd29aSsetje int
ufs_mark_compressed(struct vnode * vp)691986fd29aSsetje ufs_mark_compressed(struct vnode *vp)
692986fd29aSsetje {
693986fd29aSsetje struct inode *ip = VTOI(vp);
694986fd29aSsetje struct ufsvfs *ufsvfsp = ip->i_ufsvfs;
695986fd29aSsetje
696986fd29aSsetje if (vp->v_type != VREG)
697986fd29aSsetje return (EINVAL);
698986fd29aSsetje
699986fd29aSsetje rw_enter(&ip->i_contents, RW_WRITER);
700986fd29aSsetje ip->i_cflags |= ICOMPRESS;
701986fd29aSsetje TRANS_INODE(ufsvfsp, ip);
702986fd29aSsetje ip->i_flag |= (ICHG|ISEQ);
703986fd29aSsetje ip->i_seq++;
704986fd29aSsetje if (!TRANS_ISTRANS(ufsvfsp))
705986fd29aSsetje ufs_iupdat(ip, I_ASYNC);
706986fd29aSsetje rw_exit(&ip->i_contents);
707986fd29aSsetje
708986fd29aSsetje return (0);
709986fd29aSsetje }
710