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