Print this page
OS-5591 Double flock(3C) causes undue block
OS-5585 fcntl(F_OFD_GETLK) should return EINVAL on bad parameters
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/flock.c
          +++ new/usr/src/uts/common/os/flock.c
↓ open down ↓ 515 lines elided ↑ open up ↑
 516  516   * Routine called from fs_frlock in fs/fs_subr.c
 517  517   *
 518  518   * This implements traditional POSIX style record locking. The two primary
 519  519   * drawbacks to this style of locking are:
 520  520   * 1) It is per-process, so any close of a file descriptor that refers to the
 521  521   *    file will drop the lock (e.g. lock /etc/passwd, call a library function
 522  522   *    which opens /etc/passwd to read the file, when the library closes it's
 523  523   *    file descriptor the application loses its lock and does not know).
 524  524   * 2) Locks are not preserved across fork(2).
 525  525   *
 526      - * Because these locks are only assoiciated with a pid they are per-process.
 527      - * This is why any close will drop the lock and is also why once the process
 528      - * forks then the lock is no longer related to the new process. These locks can
 529      - * be considered as pid-ful.
      526 + * Because these locks are only associated with a PID, they are per-process.
      527 + * This is why any close will drop the lock and is also why, once the process
      528 + * forks, the lock is no longer related to the new process. These locks can
      529 + * be considered as PID-ful.
 530  530   *
 531  531   * See ofdlock() for the implementation of a similar but improved locking
 532  532   * scheme.
 533  533   */
 534  534  int
 535  535  reclock(vnode_t         *vp,
 536  536          flock64_t       *lckdat,
 537  537          int             cmd,
 538  538          int             flag,
 539  539          u_offset_t      offset,
↓ open down ↓ 456 lines elided ↑ open up ↑
 996  996   * when some thread has a reference to it as in reclock().
 997  997   */
 998  998  
 999  999  void
1000 1000  flk_free_lock(lock_descriptor_t *lock)
1001 1001  {
1002 1002          file_t *fp;
1003 1003  
1004 1004          ASSERT(IS_DEAD(lock));
1005 1005  
1006      -        if ((fp = lock->l_ofd) != NULL)
     1006 +        if ((fp = lock->l_ofd) != NULL && fp->f_filock == (struct filock *)lock)
1007 1007                  fp->f_filock = NULL;
1008 1008  
1009 1009          if (IS_REFERENCED(lock)) {
1010 1010                  lock->l_state |= DELETED_LOCK;
1011 1011                  return;
1012 1012          }
1013 1013          flk_lock_frees++;
1014 1014          kmem_free((void *)lock, sizeof (lock_descriptor_t));
1015 1015  }
1016 1016  
↓ open down ↓ 3591 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX