How can I view disk quota usage on a CIFS share from a Linux client?

6

2

I have several Linux clients that mount a share on a remote machine running Windows Server 2012. The relevant line in /etc/fstab looks like this:

//server.address.com/share /media/share cifs rw,user,noauto,_netdev,soft,cred=/etc/samba/cred/share 0 0

If I use df to query the amount of free space, I get:

~$ df -kh /media/share
Filesystem                 Type  Size  Used Avail Use% Mounted on
//server.address.com/share cifs  1.8T  1.1T  803G  57% /media/share

I get basically the same usage statistics using stat -f:

~$ stat -f /media/share
  File: "/media/share"
    ID: 0        Namelen: 4096    Type: cifs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 483183820  Free: 210294051  Available: 210294051
Inodes: Total: 0          Free: 0

Here, 4096 * 210294051 / 2^30 = 802.2GB free. However I know for a fact that the share is almost completely filled - from a Windows client I see that 1.79/1.80T is used.

I suspect that the discrepancy may be related to this issue. According to that discussion thread (started in 2012), the CIFS kernel client does not support reporting quota usage. I haven't come across any newer information on the subject (my clients run Ubuntu 14.04, kernel v3.13.0-46-generic, mount.cifs v6.0).

I have tried mounting with the nounix flag, but I still get incorrect usage stats:

~$ df -kh /media/share
Filesystem                 Type  Size  Used Avail Use% Mounted on
//server.address.com/share cifs  1.8T  1.1T  803G  57% /media/share

~$ stat -f /media/share
  File: "/media/share"
    ID: 0        Namelen: 4096    Type: cifs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 483183820  Free: 210294040  Available: 210294040
Inodes: Total: 0          Free: 0

I have also tried using quota, but this presumably only works for NFS mounts, since it prints nothing for my CIFS share:

~$ quota -v
~$

ali_m

Posted 2015-03-17T12:06:33.197

Reputation: 486

Answers

2

If you don't specify a mount option for the version of the SMB protocol, it uses the default, which is 1.0. Reporting the quota is only supported by SMB protocol version 2.0 and higher. SMB Version in fstab is specified like:

man mount.cifs
...
OPTIONS 
...

     vers=
           SMB protocol version. Allowed values are:

           ·   1.0 - The classic CIFS/SMBv1 protocol. This is the default.

           ·   2.0 - The SMBv2.002 protocol. This was initially introduced in Windows Vista Service Pack 1, and Windows Server 2008.
               Note that the initial release version of Windows Vista spoke a slightly different dialect (2.000) that is not
               supported.

           ·   2.1 - The SMBv2.1 protocol that was introduced in Microsoft Windows 7 and Windows Server 2008R2.

           ·   3.0 - The SMBv3.0 protocol that was introduced in Microsoft Windows 8 and Windows Server 2012.

           Note too that while this option governs the protocol version used, not all features of each version are available.

So just add vers=2.0 or higher to your example and df should report the quota correctly:

//server.address.com/share /media/share cifs rw,user,noauto,_netdev,soft,cred=/etc/samba/cred/share,vers=2.0 0 0

zwobot

Posted 2015-03-17T12:06:33.197

Reputation: 21

0

You can use the below userspace tool to query quota information.

https://github.com/kenneth-dsouza/smb2quota

# smb2quota.py /test
 Amount Used | Quota Limit | Warning Level | Percent Used | Status       | SID 
 70.0 kiB    | 16.0 EiB    | 16.0 EiB      | N/A          | Ok           | S-1-5-32-544
 480.0 MiB   | 500.0 MiB   | 450.0 MiB     | 96.0         | Warning      | S-1-5-21-3363399803-746912020-2622272238-1001
 4.0 MiB     | 16.0 EiB    | 16.0 EiB      | N/A          | Ok           | S-1-5-18

Please Note:

Kernel support for smb2quota requires the CIFS_QUERY_INFO IOCTL which was initially introduced in the 4.20 kernel and is only implemented for mount points using SMB2 or above see mount.cifs(8) vers option

user1097713

Posted 2015-03-17T12:06:33.197

Reputation: 1