Print this page
NEX-15680 Implement SMB2 getinfo FS level FileFsSectorSizeInformation
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-15680 Implement SMB2 getinfo FS level FileFsSectorSizeInformation
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-5598 SMB needs a few more ioctls for Hyper-V
Reviewed by: Gordon Ross <gwr@nexenta.com>
SMB-11 SMB2 message parse & dispatch
SMB-12 SMB2 Negotiate Protocol
SMB-13 SMB2 Session Setup
SMB-14 SMB2 Logoff
SMB-15 SMB2 Tree Connect
SMB-16 SMB2 Tree Disconnect
SMB-17 SMB2 Create
SMB-18 SMB2 Close
SMB-19 SMB2 Flush
SMB-20 SMB2 Read
SMB-21 SMB2 Write
SMB-22 SMB2 Lock/Unlock
SMB-23 SMB2 Ioctl
SMB-24 SMB2 Cancel
SMB-25 SMB2 Echo
SMB-26 SMB2 Query Dir
SMB-27 SMB2 Change Notify
SMB-28 SMB2 Query Info
SMB-29 SMB2 Set Info
SMB-30 SMB2 Oplocks
SMB-53 SMB2 Create Context options
(SMB2 code review cleanup 1, 2, 3)

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/smbsrv/smb2_qinfo_fs.c
          +++ new/usr/src/uts/common/fs/smbsrv/smb2_qinfo_fs.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
       23 + * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
  24   24   */
  25   25  
  26   26  /*
  27   27   * Dispatch function for SMB2_QUERY_INFO
  28   28   *
  29   29   * [MS-FSCC 2.5] If a file system does not implement ...
  30   30   * an Information Classs, NT_STATUS_INVALID_PARAMETER...
  31   31   */
  32   32  
  33   33  #include <smbsrv/smb2_kproto.h>
  34   34  #include <smbsrv/smb_fsops.h>
  35   35  #include <smbsrv/ntifs.h>
  36   36  
  37   37  uint32_t smb2_qfs_volume(smb_request_t *);
  38   38  uint32_t smb2_qfs_size(smb_request_t *);
  39   39  uint32_t smb2_qfs_device(smb_request_t *);
  40   40  uint32_t smb2_qfs_attr(smb_request_t *);
  41   41  uint32_t smb2_qfs_control(smb_request_t *);
  42   42  uint32_t smb2_qfs_fullsize(smb_request_t *);
  43   43  uint32_t smb2_qfs_obj_id(smb_request_t *);
       44 +uint32_t smb2_qfs_sectorsize(smb_request_t *);
  44   45  
  45   46  uint32_t
  46   47  smb2_qinfo_fs(smb_request_t *sr, smb_queryinfo_t *qi)
  47   48  {
  48   49          uint32_t status;
  49   50  
  50   51          switch (qi->qi_InfoClass) {
  51   52  
  52   53          /* pg 153 */
  53   54          case FileFsVolumeInformation:   /* 1 */
↓ open down ↓ 10 lines elided ↑ open up ↑
  64   65                  break;
  65   66          case FileFsControlInformation:  /* 6 */
  66   67                  status = smb2_qfs_control(sr);
  67   68                  break;
  68   69          case FileFsFullSizeInformation: /* 7 */
  69   70                  status = smb2_qfs_fullsize(sr);
  70   71                  break;
  71   72          case FileFsObjectIdInformation: /* 8 */
  72   73                  status = smb2_qfs_obj_id(sr);
  73   74                  break;
  74      -
  75      -        default:
       75 +        case FileFsVolumeFlagsInformation:      /* A */
  76   76                  status = NT_STATUS_INVALID_INFO_CLASS;
  77   77                  break;
       78 +        case FileFsSectorSizeInformation:       /* B */
       79 +                status = smb2_qfs_sectorsize(sr);
       80 +                break;
       81 +        default: /* there are some infoclasses we don't yet handle */
       82 +                status = NT_STATUS_INVALID_INFO_CLASS;
       83 +#ifdef  DEBUG
       84 +                cmn_err(CE_NOTE, "unknown InfoClass 0x%x", qi->qi_InfoClass);
       85 +#endif
       86 +                break;
  78   87          }
  79   88  
  80   89          return (status);
  81   90  }
  82   91  
  83   92  /*
  84   93   * FileFsVolumeInformation
  85   94   */
  86   95  uint32_t
  87   96  smb2_qfs_volume(smb_request_t *sr)
↓ open down ↓ 191 lines elided ↑ open up ↑
 279  288  }
 280  289  
 281  290  /*
 282  291   * FileFsObjectIdInformation
 283  292   */
 284  293  /* ARGSUSED */
 285  294  uint32_t
 286  295  smb2_qfs_obj_id(smb_request_t *sr)
 287  296  {
 288  297          return (NT_STATUS_INVALID_PARAMETER);
      298 +}
      299 +
      300 +/*
      301 + * Not sure yet where these should go.
      302 + * Flags in FileFsSectorSizeInformation
      303 + */
      304 +
      305 +#define SSINFO_FLAGS_ALIGNED_DEVICE     0x00000001
      306 +// When set, this flag indicates that the first physical sector of the device
      307 +// is aligned with the first logical sector. When not set, the first physical
      308 +// sector of the device is misaligned with the first logical sector.
      309 +
      310 +#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE        0x00000002
      311 +// When set, this flag indicates that the partition is aligned to physical
      312 +// sector boundaries on the storage device.
      313 +
      314 +#define SSINFO_FLAGS_NO_SEEK_PENALTY    0x00000004
      315 +// When set, the device reports that it does not incur a seek penalty (this
      316 +// typically indicates that the device does not have rotating media, such as
      317 +// flash-based disks).
      318 +
      319 +#define SSINFO_FLAGS_TRIM_ENABLED       0x00000008
      320 +// When set, the device supports TRIM operations, either T13 (ATA) TRIM or
      321 +// T10 (SCSI/SAS) UNMAP.
      322 +
      323 +#define SSINFO_OFFSET_UNKNOWN           0xffffffff
      324 +// For "Alignment" fields below
      325 +
      326 +/* We have to lie to Windows Hyper-V about our logical record size. */
      327 +int smb2_max_logical_sector_size = 4096;
      328 +
      329 +/*
      330 + * FileFsSectorSizeInformation
      331 + *
      332 + * Returns a FILE_FS_SECTOR_SIZE_INFORMATION
      333 + * See: [MS-FSCC] 2.5.8 FileFsSizeInformation
      334 + *
      335 + * LogicalBytesPerSector (4 bytes): ... number of bytes in a logical sector
      336 + *   for the device backing the volume. This field is the unit of logical
      337 + *   addressing for the device and is not the unit of atomic write.
      338 + * PhysicalBytesPerSectorForAtomicity (4 bytes): ... number of bytes in a
      339 + *   physical sector for the device backing the volume.  This is the reported
      340 + *   physical sector size of the device and is the unit of atomic write.
      341 + * PhysicalBytesPerSectorForPerformance (4 bytes): ... number of bytes in a
      342 + *   physical sector for the device backing the volume. This is the reported
      343 + *   physical sector size of the device and is the unit of performance.
      344 + * FileSystemEffectivePhysicalBytesPerSectorForAtomicity (4 bytes): unit, in
      345 + *   bytes, that the file system on the volume will use for internal operations
      346 + *   that require alignment and atomicity.
      347 + * Flags (4 bytes): See ...
      348 + * ByteOffsetForSectorAlignment (4 bytes): ... logical sector offset within the
      349 + *   first physical sector where the first logical sector is placed, in bytes.
      350 + *   If this value is set to SSINFO_OFFSET_UNKNOWN (0xffffffff), there was
      351 + *   insufficient information to compute this field.
      352 + * ByteOffsetForPartitionAlignment (4 bytes): ... byte offset from the first
      353 + *   physical sector where the first partition is placed. If this value is
      354 + *   set to SSINFO_OFFSET_UNKNOWN (0xffffffff), there was either insufficient
      355 + *   information or an error was encountered in computing this field.
      356 + */
      357 +uint32_t
      358 +smb2_qfs_sectorsize(smb_request_t *sr)
      359 +{
      360 +        smb_fssize_t            fssize;
      361 +        smb_tree_t *tree = sr->tid_tree;
      362 +        uint32_t lbps, pbps;
      363 +        uint32_t flags;
      364 +        int rc;
      365 +
      366 +        if (!STYPE_ISDSK(tree->t_res_type))
      367 +                return (NT_STATUS_INVALID_PARAMETER);
      368 +
      369 +        rc = smb_fssize(sr, &fssize);
      370 +        if (rc)
      371 +                return (smb_errno2status(rc));
      372 +        pbps = fssize.fs_bytes_per_sector;
      373 +        lbps = fssize.fs_sectors_per_unit * pbps;
      374 +        if (lbps > smb2_max_logical_sector_size)
      375 +                lbps = smb2_max_logical_sector_size;
      376 +
      377 +        // LogicalBytesPerSector
      378 +        (void) smb_mbc_encodef(&sr->raw_data, "l", lbps);
      379 +
      380 +        // PhysicalBytesPerSectorForAtomicity
      381 +        (void) smb_mbc_encodef(&sr->raw_data, "l", pbps);
      382 +
      383 +        // PhysicalBytesPerSectorForPerformance
      384 +        // Using logical size here.
      385 +        (void) smb_mbc_encodef(&sr->raw_data, "l", lbps);
      386 +
      387 +        // FileSystemEffectivePhysicalBytesPerSectorForAtomicity
      388 +        (void) smb_mbc_encodef(&sr->raw_data, "l", pbps);
      389 +
      390 +        // Flags
      391 +        // We include "no seek penalty" because our files are
      392 +        // always ZFS-backed, which can reorder things on disk.
      393 +        // Leaving out SSINFO_FLAGS_TRIM_ENABLED for now.
      394 +        flags = SSINFO_FLAGS_ALIGNED_DEVICE |
      395 +                SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE |
      396 +                SSINFO_FLAGS_NO_SEEK_PENALTY;
      397 +        (void) smb_mbc_encodef(&sr->raw_data, "l", flags);
      398 +
      399 +        // ByteOffsetForSectorAlignment
      400 +        // ByteOffsetForPartitionAlignment
      401 +        // Just say "unknown" for these two.
      402 +        (void) smb_mbc_encodef(
      403 +            &sr->raw_data, "l",
      404 +            SSINFO_OFFSET_UNKNOWN,
      405 +            SSINFO_OFFSET_UNKNOWN);
      406 +
      407 +        return (0);
 289  408  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX