Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*


 582         struct fs *fspt;
 583         struct buf *tpt = 0;
 584         int error = 0;
 585         int flags = 0;
 586 
 587         if (args_len == sizeof (struct ufs_args) && raw_argsp)
 588                 flags = ((struct ufs_args *)raw_argsp)->flags;
 589 
 590         /* cannot remount to RDONLY */
 591         if (vfsp->vfs_flag & VFS_RDONLY)
 592                 return (ENOTSUP);
 593 
 594         /* whoops, wrong dev */
 595         if (vfsp->vfs_dev != dev)
 596                 return (EINVAL);
 597 
 598         /*
 599          * synchronize w/ufs ioctls
 600          */
 601         mutex_enter(&ulp->ul_lock);
 602         atomic_add_long(&ufs_quiesce_pend, 1);
 603 
 604         /*
 605          * reset options
 606          */
 607         ufsvfsp->vfs_nointr  = flags & UFSMNT_NOINTR;
 608         ufsvfsp->vfs_syncdir = flags & UFSMNT_SYNCDIR;
 609         ufsvfsp->vfs_nosetsec = flags & UFSMNT_NOSETSEC;
 610         ufsvfsp->vfs_noatime = flags & UFSMNT_NOATIME;
 611         if ((flags & UFSMNT_NODFRATIME) || ufsvfsp->vfs_noatime)
 612                 ufsvfsp->vfs_dfritime &= ~UFS_DFRATIME;
 613         else    /* dfratime, default behavior */
 614                 ufsvfsp->vfs_dfritime |= UFS_DFRATIME;
 615         if (flags & UFSMNT_FORCEDIRECTIO)
 616                 ufsvfsp->vfs_forcedirectio = 1;
 617         else    /* default is no direct I/O */
 618                 ufsvfsp->vfs_forcedirectio = 0;
 619         ufsvfsp->vfs_iotstamp = ddi_get_lbolt();
 620 
 621         /*
 622          * set largefiles flag in ufsvfs equal to the


 728         tpt = 0;
 729 
 730         if (fsp->fs_clean != FSSTABLE) {
 731                 error = ENOSPC;
 732                 goto remounterr;
 733         }
 734 
 735 
 736         if (TRANS_ISTRANS(ufsvfsp)) {
 737                 fsp->fs_clean = FSLOG;
 738                 ufsvfsp->vfs_dio = 0;
 739         } else
 740                 if (ufsvfsp->vfs_dio)
 741                         fsp->fs_clean = FSSUSPEND;
 742 
 743         TRANS_MATA_MOUNT(ufsvfsp);
 744 
 745         fsp->fs_fmod = 0;
 746         fsp->fs_ronly = 0;
 747 
 748         atomic_add_long(&ufs_quiesce_pend, -1);
 749         cv_broadcast(&ulp->ul_cv);
 750         mutex_exit(&ulp->ul_lock);
 751 
 752         if (TRANS_ISTRANS(ufsvfsp)) {
 753 
 754                 /*
 755                  * start the delete thread
 756                  */
 757                 ufs_thread_start(&ufsvfsp->vfs_delete, ufs_thread_delete, vfsp);
 758 
 759                 /*
 760                  * start the reclaim thread
 761                  */
 762                 if (fsp->fs_reclaim & (FS_RECLAIM|FS_RECLAIMING)) {
 763                         fsp->fs_reclaim &= ~FS_RECLAIM;
 764                         fsp->fs_reclaim |=  FS_RECLAIMING;
 765                         ufs_thread_start(&ufsvfsp->vfs_reclaim,
 766                             ufs_thread_reclaim, vfsp);
 767                 }
 768         }
 769 
 770         TRANS_SBWRITE(ufsvfsp, TOP_MOUNT);
 771 
 772         return (0);
 773 
 774 remounterr:
 775         if (tpt)
 776                 brelse(tpt);
 777         atomic_add_long(&ufs_quiesce_pend, -1);
 778         cv_broadcast(&ulp->ul_cv);
 779         mutex_exit(&ulp->ul_lock);
 780         return (error);
 781 }
 782 
 783 /*
 784  * If the device maxtransfer size is not available, we use ufs_maxmaxphys
 785  * along with the system value for maxphys to determine the value for
 786  * maxtransfer.
 787  */
 788 int ufs_maxmaxphys = (1024 * 1024);
 789 
 790 #include <sys/ddi.h>              /* for delay(9f) */
 791 
 792 int ufs_mount_error_delay = 20; /* default to 20ms */
 793 int ufs_mount_timeout = 60000;  /* default to 1 minute */
 794 
 795 static int
 796 mountfs(struct vfs *vfsp, enum whymountroot why, struct vnode *devvp,
 797         char *path, cred_t *cr, int isroot, void *raw_argsp, int args_len)


1404                  * the duration of the forcible umount so they won't
1405                  * use stale or even freed data later on when we're done.
1406                  * It may happen that the VFS has had a additional hold
1407                  * placed on it by someone other than UFS and thus will
1408                  * not get freed immediately once we're done with the
1409                  * umount by dounmount() - use VFS_UNMOUNTED to inform
1410                  * users of this still-alive VFS that its corresponding
1411                  * filesystem being gone so they can detect that and error
1412                  * out.
1413                  */
1414                 vfsp->vfs_flag |= VFS_UNMOUNTED;
1415 
1416                 ufs_thread_suspend(&ufsvfsp->vfs_delete);
1417                 mutex_enter(&ulp->ul_lock);
1418                 /*
1419                  * If file system is already hard locked,
1420                  * unmount the file system, otherwise
1421                  * hard lock it before unmounting.
1422                  */
1423                 if (!ULOCKFS_IS_HLOCK(ulp)) {
1424                         atomic_add_long(&ufs_quiesce_pend, 1);
1425                         lockfs.lf_lock = LOCKFS_HLOCK;
1426                         lockfs.lf_flags = 0;
1427                         lockfs.lf_key = ulp->ul_lockfs.lf_key + 1;
1428                         lockfs.lf_comlen = 0;
1429                         lockfs.lf_comment = NULL;
1430                         ufs_freeze(ulp, &lockfs);
1431                         ULOCKFS_SET_BUSY(ulp);
1432                         LOCKFS_SET_BUSY(&ulp->ul_lockfs);
1433                         (void) ufs_quiesce(ulp);
1434                         (void) ufs_flush(vfsp);
1435                         (void) ufs_thaw(vfsp, ufsvfsp, ulp);
1436                         atomic_add_long(&ufs_quiesce_pend, -1);
1437                         ULOCKFS_CLR_BUSY(ulp);
1438                         LOCKFS_CLR_BUSY(&ulp->ul_lockfs);
1439                         poll_events |= POLLERR;
1440                         pollwakeup(&ufs_pollhd, poll_events);
1441                 }
1442                 ufs_thread_continue(&ufsvfsp->vfs_delete);
1443                 mutex_exit(&ulp->ul_lock);
1444         }
1445 
1446         /* let all types of writes go through */
1447         ufsvfsp->vfs_iotstamp = ddi_get_lbolt();
1448 
1449         /* coordinate with global hlock thread */
1450         if (TRANS_ISTRANS(ufsvfsp) && (ufsvfsp->vfs_validfs == UT_HLOCKING)) {
1451                 /*
1452                  * last possibility for a forced umount to fail hence clear
1453                  * VFS_UNMOUNTED if appropriate.
1454                  */
1455                 if (fflag & MS_FORCE)
1456                         vfsp->vfs_flag &= ~VFS_UNMOUNTED;


2136         }
2137 
2138         new_rootvp = makespecvp(new_rootdev, VBLK);
2139 
2140         error = VOP_OPEN(&new_rootvp,
2141             (vfsp->vfs_flag & VFS_RDONLY) ? FREAD : FREAD|FWRITE, CRED(), NULL);
2142         if (error) {
2143                 cmn_err(CE_CONT,
2144                     "Cannot open mirrored root device, error %d\n", error);
2145                 return (error);
2146         }
2147 
2148         if (vfs_lock(vfsp) != 0) {
2149                 return (EBUSY);
2150         }
2151 
2152         ufsvfsp = (struct ufsvfs *)vfsp->vfs_data;
2153         ulp = &ufsvfsp->vfs_ulockfs;
2154 
2155         mutex_enter(&ulp->ul_lock);
2156         atomic_add_long(&ufs_quiesce_pend, 1);
2157 
2158         (void) ufs_quiesce(ulp);
2159         (void) ufs_flush(vfsp);
2160 
2161         /*
2162          * Convert root vfs to new dev_t, including vfs hash
2163          * table and fs id.
2164          */
2165         vfs_root_redev(vfsp, new_rootdev, ufsfstype);
2166 
2167         ufsvfsp->vfs_devvp = new_rootvp;
2168         ufsvfsp->vfs_dev = new_rootdev;
2169 
2170         bp = ufsvfsp->vfs_bufp;
2171         bp->b_edev = new_rootdev;
2172         bp->b_dev = cmpdev(new_rootdev);
2173 
2174         /*
2175          * The buffer for the root inode does not contain a valid b_vp
2176          */


2261                         fsp->fs_reclaim |= FS_RECLAIMING;
2262                         ufs_thread_start(&ufsvfsp->vfs_reclaim,
2263                             ufs_thread_reclaim, vfsp);
2264                         TRANS_SBWRITE(ufsvfsp, TOP_SBUPDATE_UPDATE);
2265                         if (sberror = geterror(ufsvfsp->vfs_bufp)) {
2266                                 refstr_t        *mntpt;
2267                                 mntpt = vfs_getmntpoint(vfsp);
2268                                 cmn_err(CE_WARN,
2269                                     "Remountroot failed to update Reclaim"
2270                                     "state for filesystem %s "
2271                                     "Error writing SuperBlock %d",
2272                                     refstr_value(mntpt), error);
2273                                 refstr_rele(mntpt);
2274                         }
2275                 }
2276         }
2277 
2278         rootdev = new_rootdev;
2279         rootvp = new_rootvp;
2280 
2281         atomic_add_long(&ufs_quiesce_pend, -1);
2282         cv_broadcast(&ulp->ul_cv);
2283         mutex_exit(&ulp->ul_lock);
2284 
2285         vfs_unlock(vfsp);
2286 
2287         error = VOP_CLOSE(old_rootvp, FREAD, 1, (offset_t)0, CRED(), NULL);
2288         if (error) {
2289                 cmn_err(CE_CONT,
2290                     "close of root device component failed, error %d\n",
2291                     error);
2292         }
2293         VN_RELE(old_rootvp);
2294 
2295         return (sberror ? sberror : error);
2296 }
2297 
2298 #endif  /* __sparc */


 582         struct fs *fspt;
 583         struct buf *tpt = 0;
 584         int error = 0;
 585         int flags = 0;
 586 
 587         if (args_len == sizeof (struct ufs_args) && raw_argsp)
 588                 flags = ((struct ufs_args *)raw_argsp)->flags;
 589 
 590         /* cannot remount to RDONLY */
 591         if (vfsp->vfs_flag & VFS_RDONLY)
 592                 return (ENOTSUP);
 593 
 594         /* whoops, wrong dev */
 595         if (vfsp->vfs_dev != dev)
 596                 return (EINVAL);
 597 
 598         /*
 599          * synchronize w/ufs ioctls
 600          */
 601         mutex_enter(&ulp->ul_lock);
 602         atomic_inc_ulong(&ufs_quiesce_pend);
 603 
 604         /*
 605          * reset options
 606          */
 607         ufsvfsp->vfs_nointr  = flags & UFSMNT_NOINTR;
 608         ufsvfsp->vfs_syncdir = flags & UFSMNT_SYNCDIR;
 609         ufsvfsp->vfs_nosetsec = flags & UFSMNT_NOSETSEC;
 610         ufsvfsp->vfs_noatime = flags & UFSMNT_NOATIME;
 611         if ((flags & UFSMNT_NODFRATIME) || ufsvfsp->vfs_noatime)
 612                 ufsvfsp->vfs_dfritime &= ~UFS_DFRATIME;
 613         else    /* dfratime, default behavior */
 614                 ufsvfsp->vfs_dfritime |= UFS_DFRATIME;
 615         if (flags & UFSMNT_FORCEDIRECTIO)
 616                 ufsvfsp->vfs_forcedirectio = 1;
 617         else    /* default is no direct I/O */
 618                 ufsvfsp->vfs_forcedirectio = 0;
 619         ufsvfsp->vfs_iotstamp = ddi_get_lbolt();
 620 
 621         /*
 622          * set largefiles flag in ufsvfs equal to the


 728         tpt = 0;
 729 
 730         if (fsp->fs_clean != FSSTABLE) {
 731                 error = ENOSPC;
 732                 goto remounterr;
 733         }
 734 
 735 
 736         if (TRANS_ISTRANS(ufsvfsp)) {
 737                 fsp->fs_clean = FSLOG;
 738                 ufsvfsp->vfs_dio = 0;
 739         } else
 740                 if (ufsvfsp->vfs_dio)
 741                         fsp->fs_clean = FSSUSPEND;
 742 
 743         TRANS_MATA_MOUNT(ufsvfsp);
 744 
 745         fsp->fs_fmod = 0;
 746         fsp->fs_ronly = 0;
 747 
 748         atomic_dec_ulong(&ufs_quiesce_pend);
 749         cv_broadcast(&ulp->ul_cv);
 750         mutex_exit(&ulp->ul_lock);
 751 
 752         if (TRANS_ISTRANS(ufsvfsp)) {
 753 
 754                 /*
 755                  * start the delete thread
 756                  */
 757                 ufs_thread_start(&ufsvfsp->vfs_delete, ufs_thread_delete, vfsp);
 758 
 759                 /*
 760                  * start the reclaim thread
 761                  */
 762                 if (fsp->fs_reclaim & (FS_RECLAIM|FS_RECLAIMING)) {
 763                         fsp->fs_reclaim &= ~FS_RECLAIM;
 764                         fsp->fs_reclaim |=  FS_RECLAIMING;
 765                         ufs_thread_start(&ufsvfsp->vfs_reclaim,
 766                             ufs_thread_reclaim, vfsp);
 767                 }
 768         }
 769 
 770         TRANS_SBWRITE(ufsvfsp, TOP_MOUNT);
 771 
 772         return (0);
 773 
 774 remounterr:
 775         if (tpt)
 776                 brelse(tpt);
 777         atomic_dec_ulong(&ufs_quiesce_pend);
 778         cv_broadcast(&ulp->ul_cv);
 779         mutex_exit(&ulp->ul_lock);
 780         return (error);
 781 }
 782 
 783 /*
 784  * If the device maxtransfer size is not available, we use ufs_maxmaxphys
 785  * along with the system value for maxphys to determine the value for
 786  * maxtransfer.
 787  */
 788 int ufs_maxmaxphys = (1024 * 1024);
 789 
 790 #include <sys/ddi.h>              /* for delay(9f) */
 791 
 792 int ufs_mount_error_delay = 20; /* default to 20ms */
 793 int ufs_mount_timeout = 60000;  /* default to 1 minute */
 794 
 795 static int
 796 mountfs(struct vfs *vfsp, enum whymountroot why, struct vnode *devvp,
 797         char *path, cred_t *cr, int isroot, void *raw_argsp, int args_len)


1404                  * the duration of the forcible umount so they won't
1405                  * use stale or even freed data later on when we're done.
1406                  * It may happen that the VFS has had a additional hold
1407                  * placed on it by someone other than UFS and thus will
1408                  * not get freed immediately once we're done with the
1409                  * umount by dounmount() - use VFS_UNMOUNTED to inform
1410                  * users of this still-alive VFS that its corresponding
1411                  * filesystem being gone so they can detect that and error
1412                  * out.
1413                  */
1414                 vfsp->vfs_flag |= VFS_UNMOUNTED;
1415 
1416                 ufs_thread_suspend(&ufsvfsp->vfs_delete);
1417                 mutex_enter(&ulp->ul_lock);
1418                 /*
1419                  * If file system is already hard locked,
1420                  * unmount the file system, otherwise
1421                  * hard lock it before unmounting.
1422                  */
1423                 if (!ULOCKFS_IS_HLOCK(ulp)) {
1424                         atomic_inc_ulong(&ufs_quiesce_pend);
1425                         lockfs.lf_lock = LOCKFS_HLOCK;
1426                         lockfs.lf_flags = 0;
1427                         lockfs.lf_key = ulp->ul_lockfs.lf_key + 1;
1428                         lockfs.lf_comlen = 0;
1429                         lockfs.lf_comment = NULL;
1430                         ufs_freeze(ulp, &lockfs);
1431                         ULOCKFS_SET_BUSY(ulp);
1432                         LOCKFS_SET_BUSY(&ulp->ul_lockfs);
1433                         (void) ufs_quiesce(ulp);
1434                         (void) ufs_flush(vfsp);
1435                         (void) ufs_thaw(vfsp, ufsvfsp, ulp);
1436                         atomic_dec_ulong(&ufs_quiesce_pend);
1437                         ULOCKFS_CLR_BUSY(ulp);
1438                         LOCKFS_CLR_BUSY(&ulp->ul_lockfs);
1439                         poll_events |= POLLERR;
1440                         pollwakeup(&ufs_pollhd, poll_events);
1441                 }
1442                 ufs_thread_continue(&ufsvfsp->vfs_delete);
1443                 mutex_exit(&ulp->ul_lock);
1444         }
1445 
1446         /* let all types of writes go through */
1447         ufsvfsp->vfs_iotstamp = ddi_get_lbolt();
1448 
1449         /* coordinate with global hlock thread */
1450         if (TRANS_ISTRANS(ufsvfsp) && (ufsvfsp->vfs_validfs == UT_HLOCKING)) {
1451                 /*
1452                  * last possibility for a forced umount to fail hence clear
1453                  * VFS_UNMOUNTED if appropriate.
1454                  */
1455                 if (fflag & MS_FORCE)
1456                         vfsp->vfs_flag &= ~VFS_UNMOUNTED;


2136         }
2137 
2138         new_rootvp = makespecvp(new_rootdev, VBLK);
2139 
2140         error = VOP_OPEN(&new_rootvp,
2141             (vfsp->vfs_flag & VFS_RDONLY) ? FREAD : FREAD|FWRITE, CRED(), NULL);
2142         if (error) {
2143                 cmn_err(CE_CONT,
2144                     "Cannot open mirrored root device, error %d\n", error);
2145                 return (error);
2146         }
2147 
2148         if (vfs_lock(vfsp) != 0) {
2149                 return (EBUSY);
2150         }
2151 
2152         ufsvfsp = (struct ufsvfs *)vfsp->vfs_data;
2153         ulp = &ufsvfsp->vfs_ulockfs;
2154 
2155         mutex_enter(&ulp->ul_lock);
2156         atomic_inc_ulong(&ufs_quiesce_pend);
2157 
2158         (void) ufs_quiesce(ulp);
2159         (void) ufs_flush(vfsp);
2160 
2161         /*
2162          * Convert root vfs to new dev_t, including vfs hash
2163          * table and fs id.
2164          */
2165         vfs_root_redev(vfsp, new_rootdev, ufsfstype);
2166 
2167         ufsvfsp->vfs_devvp = new_rootvp;
2168         ufsvfsp->vfs_dev = new_rootdev;
2169 
2170         bp = ufsvfsp->vfs_bufp;
2171         bp->b_edev = new_rootdev;
2172         bp->b_dev = cmpdev(new_rootdev);
2173 
2174         /*
2175          * The buffer for the root inode does not contain a valid b_vp
2176          */


2261                         fsp->fs_reclaim |= FS_RECLAIMING;
2262                         ufs_thread_start(&ufsvfsp->vfs_reclaim,
2263                             ufs_thread_reclaim, vfsp);
2264                         TRANS_SBWRITE(ufsvfsp, TOP_SBUPDATE_UPDATE);
2265                         if (sberror = geterror(ufsvfsp->vfs_bufp)) {
2266                                 refstr_t        *mntpt;
2267                                 mntpt = vfs_getmntpoint(vfsp);
2268                                 cmn_err(CE_WARN,
2269                                     "Remountroot failed to update Reclaim"
2270                                     "state for filesystem %s "
2271                                     "Error writing SuperBlock %d",
2272                                     refstr_value(mntpt), error);
2273                                 refstr_rele(mntpt);
2274                         }
2275                 }
2276         }
2277 
2278         rootdev = new_rootdev;
2279         rootvp = new_rootvp;
2280 
2281         atomic_dec_ulong(&ufs_quiesce_pend);
2282         cv_broadcast(&ulp->ul_cv);
2283         mutex_exit(&ulp->ul_lock);
2284 
2285         vfs_unlock(vfsp);
2286 
2287         error = VOP_CLOSE(old_rootvp, FREAD, 1, (offset_t)0, CRED(), NULL);
2288         if (error) {
2289                 cmn_err(CE_CONT,
2290                     "close of root device component failed, error %d\n",
2291                     error);
2292         }
2293         VN_RELE(old_rootvp);
2294 
2295         return (sberror ? sberror : error);
2296 }
2297 
2298 #endif  /* __sparc */