Print this page
NEX-1643 dtrace provider for smbsrv
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
NEX-6041 Should pass the smbtorture lock tests
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/smbsrv/smb_lock_byte_range.c
          +++ new/usr/src/uts/common/fs/smbsrv/smb_lock_byte_range.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
       24 + *
       25 + * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
  24   26   */
  25   27  /*
  26   28   * SMB: lock_byte_range
  27   29   *
  28   30   * The lock record message is sent to lock the given byte range.  More than
  29   31   * one non-overlapping byte range may be locked in a given file.  Locks
  30   32   * prevent attempts to lock, read or write the locked portion of the file
  31   33   * by other clients or Pids.  Overlapping locks are not allowed. Offsets
  32   34   * beyond the current end of file may be locked.  Such locks will not cause
  33   35   * allocation of file space.
↓ open down ↓ 21 lines elided ↑ open up ↑
  55   57   * This client request does not wait for the lock to be granted.  If the
  56   58   * lock can not be immediately granted (within 200-300 ms), the server
  57   59   * should return failure to the client
  58   60   */
  59   61  
  60   62  #include <smbsrv/smb_kproto.h>
  61   63  
  62   64  smb_sdrc_t
  63   65  smb_pre_lock_byte_range(smb_request_t *sr)
  64   66  {
  65      -        DTRACE_SMB_1(op__LockByteRange__start, smb_request_t *, sr);
       67 +        DTRACE_SMB_START(op__LockByteRange, smb_request_t *, sr);
  66   68          return (SDRC_SUCCESS);
  67   69  }
  68   70  
  69   71  void
  70   72  smb_post_lock_byte_range(smb_request_t *sr)
  71   73  {
  72      -        DTRACE_SMB_1(op__LockByteRange__done, smb_request_t *, sr);
       74 +        DTRACE_SMB_DONE(op__LockByteRange, smb_request_t *, sr);
  73   75  }
  74   76  
       77 +/*
       78 + * Legacy SMB command; takes an exclusive byte-range lock
       79 + */
  75   80  smb_sdrc_t
  76   81  smb_com_lock_byte_range(struct smb_request *sr)
  77   82  {
  78   83          uint32_t        count;
  79   84          uint32_t        off;
       85 +        uint32_t        lk_pid;
  80   86          DWORD           result;
  81   87          int             rc;
  82   88  
  83   89          if (smbsr_decode_vwv(sr, "wll", &sr->smb_fid, &count, &off) != 0)
  84   90                  return (SDRC_ERROR);
  85   91  
  86   92          smbsr_lookup_file(sr);
  87   93          if (sr->fid_ofile == NULL) {
  88   94                  smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
  89   95                      ERRDOS, ERRbadfid);
  90   96                  return (SDRC_ERROR);
  91   97          }
  92   98  
  93      -        /*
  94      -         * The last parameter is lock type. This is dependent on
  95      -         * lock flag (3rd parameter). Since the lock flag is
  96      -         * set to be exclusive, lock type is passed as
  97      -         * normal lock (write lock).
  98      -         */
  99      -        result = smb_lock_range(sr, (u_offset_t)off, (uint64_t)count,  0,
 100      -            SMB_LOCK_TYPE_READWRITE);
       99 +        /* Note: SMB1 locking uses 16-bit PIDs. */
      100 +        lk_pid = sr->smb_pid & 0xFFFF;
      101 +
      102 +        result = smb_lock_range(sr, (u_offset_t)off, (uint64_t)count,
      103 +            lk_pid, SMB_LOCK_TYPE_READWRITE, 0);
 101  104          if (result != NT_STATUS_SUCCESS) {
 102  105                  smb_lock_range_error(sr, result);
 103  106                  return (SDRC_ERROR);
 104  107          }
 105  108  
 106  109          rc = smbsr_encode_empty_result(sr);
 107  110          return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
 108  111  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX