Print this page


Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/tmpfs/tmp_vnops.c
          +++ new/usr/src/uts/common/fs/tmpfs/tmp_vnops.c
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
  27   27  /*
  28      - * Copyright 2016 Joyent, Inc.
       28 + * Copyright 2016, Joyent, Inc.
  29   29   * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  30   30   * Copyright 2016 RackTop Systems.
  31   31   */
  32   32  
  33   33  #include <sys/types.h>
  34   34  #include <sys/param.h>
  35   35  #include <sys/t_lock.h>
  36   36  #include <sys/systm.h>
  37   37  #include <sys/sysmacros.h>
  38   38  #include <sys/user.h>
↓ open down ↓ 539 lines elided ↑ open up ↑
 578  578  
 579  579  /* ARGSUSED2 */
 580  580  static int
 581  581  tmp_read(struct vnode *vp, struct uio *uiop, int ioflag, cred_t *cred,
 582  582      struct caller_context *ct)
 583  583  {
 584  584          struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
 585  585          struct tmount *tm = (struct tmount *)VTOTM(vp);
 586  586          int error;
 587  587  
 588      -        /* If the filesystem was umounted by force, return immediately. */
 589      -        if (vp->v_vfsp->vfs_flag & VFS_UNMOUNTED)
 590      -                return (EIO);
 591      -
 592  588          /*
 593  589           * We don't currently support reading non-regular files
 594  590           */
 595  591          if (vp->v_type == VDIR)
 596  592                  return (EISDIR);
 597  593          if (vp->v_type != VREG)
 598  594                  return (EINVAL);
 599  595          /*
 600  596           * tmp_rwlock should have already been called from layers above
 601  597           */
↓ open down ↓ 9 lines elided ↑ open up ↑
 611  607  }
 612  608  
 613  609  static int
 614  610  tmp_write(struct vnode *vp, struct uio *uiop, int ioflag, struct cred *cred,
 615  611      struct caller_context *ct)
 616  612  {
 617  613          struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
 618  614          struct tmount *tm = (struct tmount *)VTOTM(vp);
 619  615          int error;
 620  616  
 621      -        /* If the filesystem was umounted by force, return immediately. */
 622      -        if (vp->v_vfsp->vfs_flag & VFS_UNMOUNTED)
 623      -                return (EIO);
 624      -
 625  617          /*
 626  618           * We don't currently support writing to non-regular files
 627  619           */
 628  620          if (vp->v_type != VREG)
 629  621                  return (EINVAL);        /* XXX EISDIR? */
 630  622  
 631  623          /*
 632  624           * tmp_rwlock should have already been called from layers above
 633  625           */
 634  626          ASSERT(RW_WRITE_HELD(&tp->tn_rwlock));
↓ open down ↓ 205 lines elided ↑ open up ↑
 840  832          struct vnode *rdir,
 841  833          struct cred *cred,
 842  834          caller_context_t *ct,
 843  835          int *direntflags,
 844  836          pathname_t *realpnp)
 845  837  {
 846  838          struct tmpnode *tp = (struct tmpnode *)VTOTN(dvp);
 847  839          struct tmpnode *ntp = NULL;
 848  840          int error;
 849  841  
 850      -        /* If the filesystem was umounted by force, return immediately. */
 851      -        if (dvp->v_vfsp->vfs_flag & VFS_UNMOUNTED)
 852      -                return (EIO);
 853  842  
 854  843          /* allow cd into @ dir */
 855  844          if (flags & LOOKUP_XATTR) {
 856  845                  struct tmpnode *xdp;
 857  846                  struct tmount *tm;
 858  847  
 859  848                  /*
 860  849                   * don't allow attributes if not mounted XATTR support
 861  850                   */
 862  851                  if (!(dvp->v_vfsp->vfs_flag & VFS_XATTR))
 863  852                          return (EINVAL);
 864  853  
 865  854                  if (tp->tn_flags & ISXATTR)
 866  855                          /* No attributes on attributes */
 867  856                          return (EINVAL);
 868  857  
 869  858                  rw_enter(&tp->tn_rwlock, RW_WRITER);
 870  859                  if (tp->tn_xattrdp == NULL) {
 871      -                        int err;
 872      -
 873  860                          if (!(flags & CREATE_XATTR_DIR)) {
 874  861                                  rw_exit(&tp->tn_rwlock);
 875  862                                  return (ENOENT);
 876  863                          }
 877  864  
 878  865                          /*
 879  866                           * No attribute directory exists for this
 880  867                           * node - create the attr dir as a side effect
 881  868                           * of this lookup.
 882  869                           */
 883  870  
 884  871                          /*
 885  872                           * Make sure we have adequate permission...
 886  873                           */
 887  874  
 888  875                          if ((error = tmp_taccess(tp, VWRITE, cred)) != 0) {
 889  876                                  rw_exit(&tp->tn_rwlock);
 890  877                                  return (error);
 891  878                          }
 892  879  
      880 +                        xdp = tmp_memalloc(sizeof (struct tmpnode),
      881 +                            TMP_MUSTHAVE);
 893  882                          tm = VTOTM(dvp);
 894      -                        xdp = tmp_kmem_zalloc(tm, sizeof (struct tmpnode),
 895      -                            KM_SLEEP);
 896      -                        if (xdp == NULL) {
 897      -                                rw_exit(&tp->tn_rwlock);
 898      -                                return (ENOSPC);
 899      -                        }
 900  883                          tmpnode_init(tm, xdp, &tp->tn_attr, NULL);
 901  884                          /*
 902  885                           * Fix-up fields unique to attribute directories.
 903  886                           */
 904  887                          xdp->tn_flags = ISXATTR;
 905  888                          xdp->tn_type = VDIR;
 906  889                          if (tp->tn_type == VDIR) {
 907  890                                  xdp->tn_mode = tp->tn_attr.va_mode;
 908  891                          } else {
 909  892                                  xdp->tn_mode = 0700;
 910  893                                  if (tp->tn_attr.va_mode & 0040)
 911  894                                          xdp->tn_mode |= 0750;
 912  895                                  if (tp->tn_attr.va_mode & 0004)
 913  896                                          xdp->tn_mode |= 0705;
 914  897                          }
 915  898                          xdp->tn_vnode->v_type = VDIR;
 916  899                          xdp->tn_vnode->v_flag |= V_XATTRDIR;
 917      -                        if ((err = tdirinit(tp, xdp)) != 0) {
 918      -                                rw_exit(&tp->tn_rwlock);
 919      -                                /*
 920      -                                 * This never got properly initialized so we can
 921      -                                 * just clean it up.
 922      -                                 */
 923      -                                xdp->tn_vnode->v_flag &= V_XATTRDIR;
 924      -                                tmpnode_cleanup(tp);
 925      -                                return (err);
 926      -                        }
      900 +                        tdirinit(tp, xdp);
 927  901                          tp->tn_xattrdp = xdp;
 928  902                  } else {
 929  903                          VN_HOLD(tp->tn_xattrdp->tn_vnode);
 930  904                  }
 931  905                  *vpp = TNTOV(tp->tn_xattrdp);
 932  906                  rw_exit(&tp->tn_rwlock);
 933  907                  return (0);
 934  908          }
 935  909  
 936  910          /*
↓ open down ↓ 561 lines elided ↑ open up ↑
1498 1472          int error = 0;
1499 1473          size_t namelen;
1500 1474          struct dirent64 *dp;
1501 1475          ulong_t offset;
1502 1476          ulong_t total_bytes_wanted;
1503 1477          long outcount = 0;
1504 1478          long bufsize;
1505 1479          int reclen;
1506 1480          caddr_t outbuf;
1507 1481  
1508      -        /* If the filesystem was umounted by force, return immediately. */
1509      -        if (vp->v_vfsp->vfs_flag & VFS_UNMOUNTED)
1510      -                return (EIO);
1511      -
1512 1482          if (uiop->uio_loffset >= MAXOFF_T) {
1513 1483                  if (eofp)
1514 1484                          *eofp = 1;
1515 1485                  return (0);
1516 1486          }
1517 1487          /*
1518 1488           * assuming system call has already called tmp_rwlock
1519 1489           */
1520 1490          ASSERT(RW_READ_HELD(&tp->tn_rwlock));
1521 1491  
↓ open down ↓ 113 lines elided ↑ open up ↑
1635 1605                          tmpnode_rele(self);
1636 1606                  return (error);
1637 1607          }
1638 1608  
1639 1609          rw_enter(&parent->tn_rwlock, RW_WRITER);
1640 1610          error = tdirenter(tm, parent, lnm, DE_CREATE, (struct tmpnode *)NULL,
1641 1611              (struct tmpnode *)NULL, tva, &self, cred, ct);
1642 1612          rw_exit(&parent->tn_rwlock);
1643 1613  
1644 1614          if (error) {
1645      -                if (self != NULL)
     1615 +                if (self)
1646 1616                          tmpnode_rele(self);
1647 1617                  return (error);
1648 1618          }
1649 1619          len = strlen(tnm) + 1;
1650      -        cp = tmp_kmem_zalloc(tm, len, KM_NOSLEEP | KM_NORMALPRI);
     1620 +        cp = tmp_memalloc(len, 0);
1651 1621          if (cp == NULL) {
1652 1622                  tmpnode_rele(self);
1653 1623                  return (ENOSPC);
1654 1624          }
1655 1625          (void) strcpy(cp, tnm);
1656 1626  
1657 1627          self->tn_symlink = cp;
1658 1628          self->tn_size = len - 1;
1659 1629          tmpnode_rele(self);
1660 1630          return (error);
↓ open down ↓ 44 lines elided ↑ open up ↑
1705 1675  top:
1706 1676          mutex_enter(&tp->tn_tlock);
1707 1677          mutex_enter(&vp->v_lock);
1708 1678          ASSERT(vp->v_count >= 1);
1709 1679  
1710 1680          /*
1711 1681           * If we don't have the last hold or the link count is non-zero,
1712 1682           * there's little to do -- just drop our hold.
1713 1683           */
1714 1684          if (vp->v_count > 1 || tp->tn_nlink != 0) {
1715      -                if (vp->v_vfsp->vfs_flag & VFS_UNMOUNTED) {
1716      -                        /*
1717      -                         * Since the file system was forcibly unmounted, we can
1718      -                         * have a case (v_count == 1, tn_nlink != 0) where this
1719      -                         * file was open so we didn't add an extra hold on the
1720      -                         * file in tmp_unmount. We are counting on the
1721      -                         * interaction of the hold made in tmp_unmount and
1722      -                         * rele-ed in tmp_vfsfree so we need to be sure we
1723      -                         * don't decrement in this case.
1724      -                         */
1725      -                        if (vp->v_count > 1)
1726      -                                vp->v_count--;
1727      -                } else {
1728      -                        vp->v_count--;
1729      -                }
     1685 +                vp->v_count--;
1730 1686                  mutex_exit(&vp->v_lock);
1731 1687                  mutex_exit(&tp->tn_tlock);
1732 1688                  rw_exit(&tp->tn_rwlock);
1733      -                /* If the filesystem was umounted by force, rele the vfs ref */
1734      -                if (tm->tm_vfsp->vfs_flag & VFS_UNMOUNTED)
1735      -                        VFS_RELE(tm->tm_vfsp);
1736 1689                  return;
1737 1690          }
1738 1691  
1739 1692          /*
1740 1693           * We have the last hold *and* the link count is zero, so this
1741 1694           * tmpnode is dead from the filesystem's viewpoint.  However,
1742 1695           * if the tmpnode has any pages associated with it (i.e. if it's
1743 1696           * a normal file with non-zero size), the tmpnode can still be
1744 1697           * discovered by pageout or fsflush via the page vnode pointers.
1745 1698           * In this case we must drop all our locks, truncate the tmpnode,
↓ open down ↓ 4 lines elided ↑ open up ↑
1750 1703                          mutex_exit(&vp->v_lock);
1751 1704                          mutex_exit(&tp->tn_tlock);
1752 1705                          rw_enter(&tp->tn_contents, RW_WRITER);
1753 1706                          (void) tmpnode_trunc(tm, tp, 0);
1754 1707                          rw_exit(&tp->tn_contents);
1755 1708                          ASSERT(tp->tn_size == 0);
1756 1709                          ASSERT(tp->tn_nblocks == 0);
1757 1710                          goto top;
1758 1711                  }
1759 1712                  if (tp->tn_type == VLNK)
1760      -                        tmp_kmem_free(tm, tp->tn_symlink, tp->tn_size + 1);
     1713 +                        tmp_memfree(tp->tn_symlink, tp->tn_size + 1);
1761 1714          }
1762 1715  
1763 1716          /*
1764 1717           * Remove normal file/dir's xattr dir and xattrs.
1765 1718           */
1766 1719          if (tp->tn_xattrdp) {
1767 1720                  struct tmpnode *xtp = tp->tn_xattrdp;
1768 1721  
1769 1722                  ASSERT(xtp->tn_flags & ISXATTR);
1770 1723                  tmpnode_hold(xtp);
↓ open down ↓ 13 lines elided ↑ open up ↑
1784 1737          if (tp->tn_forw == NULL)
1785 1738                  tm->tm_rootnode->tn_back = tp->tn_back;
1786 1739          else
1787 1740                  tp->tn_forw->tn_back = tp->tn_back;
1788 1741          tp->tn_back->tn_forw = tp->tn_forw;
1789 1742          mutex_exit(&tm->tm_contents);
1790 1743          rw_exit(&tp->tn_rwlock);
1791 1744          rw_destroy(&tp->tn_rwlock);
1792 1745          mutex_destroy(&tp->tn_tlock);
1793 1746          vn_free(TNTOV(tp));
1794      -        tmp_kmem_free(tm, tp, sizeof (struct tmpnode));
1795      -
1796      -        /* If the filesystem was umounted by force, rele the vfs ref */
1797      -        if (tm->tm_vfsp->vfs_flag & VFS_UNMOUNTED)
1798      -                VFS_RELE(tm->tm_vfsp);
     1747 +        tmp_memfree(tp, sizeof (struct tmpnode));
1799 1748  }
1800 1749  
1801 1750  /* ARGSUSED2 */
1802 1751  static int
1803 1752  tmp_fid(struct vnode *vp, struct fid *fidp, caller_context_t *ct)
1804 1753  {
1805 1754          struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
1806 1755          struct tfid *tfid;
1807 1756  
1808 1757          if (fidp->fid_len < (sizeof (struct tfid) - sizeof (ushort_t))) {
↓ open down ↓ 101 lines elided ↑ open up ↑
1910 1859          caddr_t addr,
1911 1860          enum seg_rw rw,
1912 1861          struct cred *cr)
1913 1862  {
1914 1863          struct page *pp;
1915 1864          int flags;
1916 1865          int err = 0;
1917 1866          struct vnode *pvp;
1918 1867          u_offset_t poff;
1919 1868  
1920      -        /* If the filesystem was umounted by force, return immediately. */
1921      -        if (vp->v_vfsp->vfs_flag & VFS_UNMOUNTED)
1922      -                return (EIO);
1923      -
1924 1869          if (protp != NULL)
1925 1870                  *protp = PROT_ALL;
1926 1871  again:
1927 1872          if (pp = page_lookup(vp, off, rw == S_CREATE ? SE_EXCL : SE_SHARED)) {
1928 1873                  if (pl) {
1929 1874                          pl[0] = pp;
1930 1875                          pl[1] = NULL;
1931 1876                  } else {
1932 1877                          page_unlock(pp);
1933 1878                  }
↓ open down ↓ 201 lines elided ↑ open up ↑
2135 2080          long tmp_klustsize;
2136 2081          struct tmpnode *tp;
2137 2082          size_t pp_off, pp_len;
2138 2083          u_offset_t io_off;
2139 2084          size_t io_len;
2140 2085          struct vnode *pvp;
2141 2086          u_offset_t pstart;
2142 2087          u_offset_t offset;
2143 2088          u_offset_t tmpoff;
2144 2089  
2145      -        /* If the filesystem was umounted by force, return immediately. */
2146      -        if (vp->v_vfsp->vfs_flag & VFS_UNMOUNTED)
2147      -                return (EIO);
2148      -
2149 2090          ASSERT(PAGE_LOCKED(pp));
2150 2091  
2151 2092          /* Kluster in tmp_klustsize chunks */
2152 2093          tp = VTOTN(vp);
2153 2094          tmp_klustsize = klustsize;
2154 2095          offset = pp->p_offset;
2155 2096          klstart = (offset / tmp_klustsize) * tmp_klustsize;
2156 2097          kllen = MIN(tmp_klustsize, tp->tn_size - klstart);
2157 2098  
2158 2099          /* Get a kluster of pages */
↓ open down ↓ 380 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX