Print this page
NEX-5164 backport illumos 6514 AS_* lock macros simplification
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
6514 AS_* lock macros simplification
Reviewed by: Piotr Jasiukajtis <estibi@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Albert Lee <trisk@omniti.com>
Approved by: Dan McDonald <danmcd@omniti.com>
re #13613 rb4516 Tunables needs volatile keyword


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1984, 2010, Oracle and/or its affiliates. All rights reserved.

  24  * Copyright 2017 Joyent, Inc.
  25  * Copyright (c) 2016 by Delphix. All rights reserved.
  26  */
  27 
  28 /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
  29 /*        All Rights Reserved   */
  30 
  31 /*
  32  * Portions of this source code were derived from Berkeley 4.3 BSD
  33  * under license from the Regents of the University of California.
  34  */
  35 
  36 #include <sys/types.h>
  37 #include <sys/t_lock.h>
  38 #include <sys/ksynch.h>
  39 #include <sys/param.h>
  40 #include <sys/time.h>
  41 #include <sys/systm.h>
  42 #include <sys/sysmacros.h>
  43 #include <sys/resource.h>


 379                 }
 380 
 381                 rw_enter(&ip->i_contents, RW_READER);
 382                 error = rdip(ip, uiop, ioflag, cr);
 383                 rw_exit(&ip->i_contents);
 384 
 385                 if (intrans) {
 386                         TRANS_END_SYNC(ufsvfsp, error, TOP_READ_SYNC,
 387                             TOP_READ_SIZE);
 388                 }
 389         }
 390 
 391         if (ulp) {
 392                 ufs_lockfs_end(ulp);
 393         }
 394 out:
 395 
 396         return (error);
 397 }
 398 
 399 extern  int     ufs_HW;         /* high water mark */
 400 extern  int     ufs_LW;         /* low water mark */
 401 int     ufs_WRITES = 1;         /* XXX - enable/disable */
 402 int     ufs_throttles = 0;      /* throttling count */
 403 int     ufs_allow_shared_writes = 1;    /* directio shared writes */
 404 
 405 static int
 406 ufs_check_rewrite(struct inode *ip, struct uio *uiop, int ioflag)
 407 {
 408         int     shared_write;
 409 
 410         /*
 411          * If the FDSYNC flag is set then ignore the global
 412          * ufs_allow_shared_writes in this case.
 413          */
 414         shared_write = (ioflag & FDSYNC) | ufs_allow_shared_writes;
 415 
 416         /*
 417          * Filter to determine if this request is suitable as a
 418          * concurrent rewrite. This write must not allocate blocks
 419          * by extending the file or filling in holes. No use trying
 420          * through FSYNC descriptors as the inode will be synchronously
 421          * updated after the write. The uio structure has not yet been


 646                 goto retry_mandlock;
 647         }
 648 
 649         if (error == ENOSPC && (start_resid != uiop->uio_resid))
 650                 error = 0;
 651 
 652         return (error);
 653 }
 654 
 655 /*
 656  * Don't cache write blocks to files with the sticky bit set.
 657  * Used to keep swap files from blowing the page cache on a server.
 658  */
 659 int stickyhack = 1;
 660 
 661 /*
 662  * Free behind hacks.  The pager is busted.
 663  * XXX - need to pass the information down to writedone() in a flag like B_SEQ
 664  * or B_FREE_IF_TIGHT_ON_MEMORY.
 665  */
 666 int     freebehind = 1;
 667 int     smallfile = 0;
 668 u_offset_t smallfile64 = 32 * 1024;
 669 
 670 /*
 671  * While we should, in most cases, cache the pages for write, we
 672  * may also want to cache the pages for read as long as they are
 673  * frequently re-usable.
 674  *
 675  * If cache_read_ahead = 1, the pages for read will go to the tail
 676  * of the cache list when they are released, otherwise go to the head.
 677  */
 678 int     cache_read_ahead = 0;
 679 
 680 /*
 681  * Freebehind exists  so that as we read  large files  sequentially we
 682  * don't consume most of memory with pages  from a few files. It takes
 683  * longer to re-read from disk multiple small files as it does reading
 684  * one large one sequentially.  As system  memory grows customers need
 685  * to retain bigger chunks   of files in  memory.   The advent of  the
 686  * cachelist opens up of the possibility freeing pages  to the head or
 687  * tail of the list.


1545         return (error);
1546 }
1547 
1548 /* ARGSUSED */
1549 static int
1550 ufs_ioctl(
1551         struct vnode    *vp,
1552         int             cmd,
1553         intptr_t        arg,
1554         int             flag,
1555         struct cred     *cr,
1556         int             *rvalp,
1557         caller_context_t *ct)
1558 {
1559         struct lockfs   lockfs, lockfs_out;
1560         struct ufsvfs   *ufsvfsp = VTOI(vp)->i_ufsvfs;
1561         char            *comment, *original_comment;
1562         struct fs       *fs;
1563         struct ulockfs  *ulp;
1564         offset_t        off;
1565         extern int      maxphys;
1566         int             error;
1567         int             issync;
1568         int             trans_size;
1569 
1570 
1571         /*
1572          * forcibly unmounted
1573          */
1574         if (ufsvfsp == NULL || vp->v_vfsp == NULL ||
1575             vp->v_vfsp->vfs_flag & VFS_UNMOUNTED)
1576                 return (EIO);
1577         fs = ufsvfsp->vfs_fs;
1578 
1579         if (cmd == Q_QUOTACTL) {
1580                 error = ufs_lockfs_begin(ufsvfsp, &ulp, ULOCKFS_QUOTA_MASK);
1581                 if (error)
1582                         return (error);
1583 
1584                 if (ulp) {
1585                         TRANS_BEGIN_ASYNC(ufsvfsp, TOP_QUOTA,


1877                 }
1878 
1879                 case _FIOSNAPSHOTDELETE:
1880                 {
1881                         struct fiosnapdelete    fc;
1882 
1883                         if (copyin((void *)arg, &fc, sizeof (fc)))
1884                                 return (EFAULT);
1885                         error = ufs_snap_delete(vp, &fc, cr);
1886                         if (!error && copyout(&fc, (void *)arg, sizeof (fc)))
1887                                 error = EFAULT;
1888                         return (error);
1889                 }
1890 
1891                 case _FIOGETSUPERBLOCK:
1892                         if (copyout(fs, (void *)arg, SBSIZE))
1893                                 return (EFAULT);
1894                         return (0);
1895 
1896                 case _FIOGETMAXPHYS:
1897                         if (copyout(&maxphys, (void *)arg, sizeof (maxphys)))

1898                                 return (EFAULT);
1899                         return (0);
1900 
1901                 /*
1902                  * The following 3 ioctls are for TSufs support
1903                  * although could potentially be used elsewhere
1904                  */
1905                 case _FIO_SET_LUFS_DEBUG:
1906                         if (secpolicy_fs_config(cr, ufsvfsp->vfs_vfs) != 0)
1907                                 return (EPERM);
1908                         lufs_debug = (uint32_t)arg;
1909                         return (0);
1910 
1911                 case _FIO_SET_LUFS_ERROR:
1912                         if (secpolicy_fs_config(cr, ufsvfsp->vfs_vfs) != 0)
1913                                 return (EPERM);
1914                         TRANS_SETERROR(ufsvfsp);
1915                         return (0);
1916 
1917                 case _FIO_GET_TOP_STATS:




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1984, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright 2017 Joyent, Inc.
  26  * Copyright (c) 2016 by Delphix. All rights reserved.
  27  */
  28 
  29 /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
  30 /*        All Rights Reserved   */
  31 
  32 /*
  33  * Portions of this source code were derived from Berkeley 4.3 BSD
  34  * under license from the Regents of the University of California.
  35  */
  36 
  37 #include <sys/types.h>
  38 #include <sys/t_lock.h>
  39 #include <sys/ksynch.h>
  40 #include <sys/param.h>
  41 #include <sys/time.h>
  42 #include <sys/systm.h>
  43 #include <sys/sysmacros.h>
  44 #include <sys/resource.h>


 380                 }
 381 
 382                 rw_enter(&ip->i_contents, RW_READER);
 383                 error = rdip(ip, uiop, ioflag, cr);
 384                 rw_exit(&ip->i_contents);
 385 
 386                 if (intrans) {
 387                         TRANS_END_SYNC(ufsvfsp, error, TOP_READ_SYNC,
 388                             TOP_READ_SIZE);
 389                 }
 390         }
 391 
 392         if (ulp) {
 393                 ufs_lockfs_end(ulp);
 394         }
 395 out:
 396 
 397         return (error);
 398 }
 399 
 400 extern  volatile int    ufs_HW; /* high water mark */
 401 extern  volatile int    ufs_LW; /* low water mark */
 402 volatile int    ufs_WRITES = 1; /* XXX - enable/disable */
 403 int     ufs_throttles = 0;      /* throttling count */
 404 int     ufs_allow_shared_writes = 1;    /* directio shared writes */
 405 
 406 static int
 407 ufs_check_rewrite(struct inode *ip, struct uio *uiop, int ioflag)
 408 {
 409         int     shared_write;
 410 
 411         /*
 412          * If the FDSYNC flag is set then ignore the global
 413          * ufs_allow_shared_writes in this case.
 414          */
 415         shared_write = (ioflag & FDSYNC) | ufs_allow_shared_writes;
 416 
 417         /*
 418          * Filter to determine if this request is suitable as a
 419          * concurrent rewrite. This write must not allocate blocks
 420          * by extending the file or filling in holes. No use trying
 421          * through FSYNC descriptors as the inode will be synchronously
 422          * updated after the write. The uio structure has not yet been


 647                 goto retry_mandlock;
 648         }
 649 
 650         if (error == ENOSPC && (start_resid != uiop->uio_resid))
 651                 error = 0;
 652 
 653         return (error);
 654 }
 655 
 656 /*
 657  * Don't cache write blocks to files with the sticky bit set.
 658  * Used to keep swap files from blowing the page cache on a server.
 659  */
 660 int stickyhack = 1;
 661 
 662 /*
 663  * Free behind hacks.  The pager is busted.
 664  * XXX - need to pass the information down to writedone() in a flag like B_SEQ
 665  * or B_FREE_IF_TIGHT_ON_MEMORY.
 666  */
 667 volatile int    freebehind = 1;
 668 volatile int    smallfile = 0;
 669 u_offset_t smallfile64 = 32 * 1024;
 670 
 671 /*
 672  * While we should, in most cases, cache the pages for write, we
 673  * may also want to cache the pages for read as long as they are
 674  * frequently re-usable.
 675  *
 676  * If cache_read_ahead = 1, the pages for read will go to the tail
 677  * of the cache list when they are released, otherwise go to the head.
 678  */
 679 int     cache_read_ahead = 0;
 680 
 681 /*
 682  * Freebehind exists  so that as we read  large files  sequentially we
 683  * don't consume most of memory with pages  from a few files. It takes
 684  * longer to re-read from disk multiple small files as it does reading
 685  * one large one sequentially.  As system  memory grows customers need
 686  * to retain bigger chunks   of files in  memory.   The advent of  the
 687  * cachelist opens up of the possibility freeing pages  to the head or
 688  * tail of the list.


1546         return (error);
1547 }
1548 
1549 /* ARGSUSED */
1550 static int
1551 ufs_ioctl(
1552         struct vnode    *vp,
1553         int             cmd,
1554         intptr_t        arg,
1555         int             flag,
1556         struct cred     *cr,
1557         int             *rvalp,
1558         caller_context_t *ct)
1559 {
1560         struct lockfs   lockfs, lockfs_out;
1561         struct ufsvfs   *ufsvfsp = VTOI(vp)->i_ufsvfs;
1562         char            *comment, *original_comment;
1563         struct fs       *fs;
1564         struct ulockfs  *ulp;
1565         offset_t        off;

1566         int             error;
1567         int             issync;
1568         int             trans_size;
1569 
1570 
1571         /*
1572          * forcibly unmounted
1573          */
1574         if (ufsvfsp == NULL || vp->v_vfsp == NULL ||
1575             vp->v_vfsp->vfs_flag & VFS_UNMOUNTED)
1576                 return (EIO);
1577         fs = ufsvfsp->vfs_fs;
1578 
1579         if (cmd == Q_QUOTACTL) {
1580                 error = ufs_lockfs_begin(ufsvfsp, &ulp, ULOCKFS_QUOTA_MASK);
1581                 if (error)
1582                         return (error);
1583 
1584                 if (ulp) {
1585                         TRANS_BEGIN_ASYNC(ufsvfsp, TOP_QUOTA,


1877                 }
1878 
1879                 case _FIOSNAPSHOTDELETE:
1880                 {
1881                         struct fiosnapdelete    fc;
1882 
1883                         if (copyin((void *)arg, &fc, sizeof (fc)))
1884                                 return (EFAULT);
1885                         error = ufs_snap_delete(vp, &fc, cr);
1886                         if (!error && copyout(&fc, (void *)arg, sizeof (fc)))
1887                                 error = EFAULT;
1888                         return (error);
1889                 }
1890 
1891                 case _FIOGETSUPERBLOCK:
1892                         if (copyout(fs, (void *)arg, SBSIZE))
1893                                 return (EFAULT);
1894                         return (0);
1895 
1896                 case _FIOGETMAXPHYS:
1897                         if (copyout((void *)&maxphys, (void *)arg,
1898                             sizeof (maxphys)))
1899                                 return (EFAULT);
1900                         return (0);
1901 
1902                 /*
1903                  * The following 3 ioctls are for TSufs support
1904                  * although could potentially be used elsewhere
1905                  */
1906                 case _FIO_SET_LUFS_DEBUG:
1907                         if (secpolicy_fs_config(cr, ufsvfsp->vfs_vfs) != 0)
1908                                 return (EPERM);
1909                         lufs_debug = (uint32_t)arg;
1910                         return (0);
1911 
1912                 case _FIO_SET_LUFS_ERROR:
1913                         if (secpolicy_fs_config(cr, ufsvfsp->vfs_vfs) != 0)
1914                                 return (EPERM);
1915                         TRANS_SETERROR(ufsvfsp);
1916                         return (0);
1917 
1918                 case _FIO_GET_TOP_STATS: