From nobody@FreeBSD.org  Sat May 31 20:17:30 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 899A7106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 31 May 2008 20:17:30 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 666588FC16
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 31 May 2008 20:17:30 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m4VKFegb011913
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 31 May 2008 20:15:40 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m4VKFe2K011909;
	Sat, 31 May 2008 20:15:40 GMT
	(envelope-from nobody)
Message-Id: <200805312015.m4VKFe2K011909@www.freebsd.org>
Date: Sat, 31 May 2008 20:15:40 GMT
From: Adam McDougall <mcdouga9@egr.msu.edu>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Samba disk quota support uses hardcoded and wrong blocksize for calculation
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         124172
>Category:       ports
>Synopsis:       net/Samba3 disk quota support uses hardcoded and wrong blocksize for calculation
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    timur
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 31 20:20:03 UTC 2008
>Closed-Date:    Tue Jul 15 04:10:35 UTC 2008
>Last-Modified:  Tue Jul 15 04:10:35 UTC 2008
>Originator:     Adam McDougall
>Release:        6.3-STABLE
>Organization:
>Environment:
FreeBSD ghost 6.3-STABLE FreeBSD 6.3-STABLE #4: Thu Feb 14 12:53:43 EST 2008     Rmcdouga@ghost:/usr/obj/usr/src/sys/X4100  amd64

>Description:
For a year or two at least, Samba has native support for NFS quotas on FreeBSD, but appears to make assumptions about the NFS server blocksize leading it to false reporting of quota usage and capacity.  I traced it down to this section of code, which I patch locally with another hack because it is simple enough to work for our site.  Basically, DEV_BSIZE is defined in a local system header as 512, which doesn't match a Netapp's blocksize of 4096, so all quotas are reported as 1/8th the real size.  Maybe FreeBSD NFS servers use a 512 blocksize, but the only servers I have quota enabled on use 4096 so I hardcoded it.  I would believe the proper thing to do would be to issue an RPC call to the server of the current mountpoint requesting the blocksize from the server. Additionally, the validity of the if check just before it looks questionable, it appears to be doing the equivalent of if (A == A == 1).  It looked like the block of code for quotas on FreeBSD was cut and pasted fro
 m another platform in the same file and modified to suit FreeBSD.  

--- smbd/quotas.c       Thu Jan 11 12:13:31 2007
+++ smbd/quotas.c       Thu Jan 11 12:26:42 2007
@@ -1091,7 +1091,15 @@
        *dsize = D.dqb_bsoftlimit;

        if (D.dqb_curblocks == D.dqb_curblocks == 1)
-               *bsize = DEV_BSIZE;
+       /*      *bsize = DEV_BSIZE; /*
+               *bsize = 4096;

>How-To-Repeat:
Compile samba with QUOTAS support on FreeBSD.  Create a samba share in smb.conf pointing to an NFS mount with a user quota applied and a non-512 blocksize such as a NetApp which uses 4096.  Use standard methods of checking the samba share's usage and free space totals (such as right clicking the drive letter in windows and clicking Properties) and note the disparity between reported values and real values. 

>Fix:
*bsize should be set to the NFS server's reported blocksize, not a static number.  

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->timur 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Sun Jun 1 06:56:14 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=124172 
State-Changed-From-To: open->feedback 
State-Changed-By: timur 
State-Changed-When: Tue Jul 1 23:11:55 UTC 2008 
State-Changed-Why:  


Can you, please try this piece of code on your NFS mounted 
system(also, look into man statfs for other interesting 
fields): 

#include <sys/types.h> 
#include <sys/param.h> 
#include <sys/mount.h> 
#include <stdio.h> 

int main(int argc, char *argv[]) { 
int rc; 
struct statfs buf; 

if((rc=statfs(argv[1], &buf)) != -1) { 
printf("Bsize: %ldn", buf.f_bsize); 
printf("FS type: %ldn", buf.f_type); 
} 
return rc; 
} 

That should give the correct BS. Send me results :) 

Regards, 
Timur. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=124172 

From: "Timur I. Bakeyev" <timur@gnu.org>
To: bug-followup@freebsd.org
Cc:  
Subject: ports/124172: net/Samba3 disk quota support uses hardcoded and wrong blocksize for calculation
Date: Tue, 8 Jul 2008 05:12:17 +0200

 On Wed, Jul 02, 2008 at 12:49:03AM -0400, Adam McDougall wrote:
 > On Tue, Jul 01, 2008 at 11:16:22PM +0000, timur@FreeBSD.org wrote:
 >
 >   Synopsis: net/Samba3 disk quota support uses hardcoded and wrong blocksize for calculation
 >
 > I expected 4096.  I'm not actually sure how to query it, I thought it might
 > be part of the quota rpc calls but I don't see a field in
 > http://search.cpan.org/~tomzo/Quota-1.6.2/Quota.pm.
 
 Ok, seems you got the answer right, just overlooked it :)
 
 The bug(tm) is actually here, I believe:
 
 if (D.dqb_curblocks == D.dqb_curblocks == 1)
 -               *bsize = DEV_BSIZE;
 +       /*      *bsize = DEV_BSIZE; /*
 +               *bsize = 4096;
 
 As you spotted, check is meaningless. It's supposed to be a safeguard, but
 due broken condition overrides correct results.
 
 Try to run Samba with debug level of 10 and quota enabled and you'd see:
 
 DEBUG(10,("nfs_quotas: Let`s look at D a bit closer... status \"%i\"
 bsize \"%i\"
 
 etc.
 
 bsize should be 4096 for you.
 
 The fix to the code is also trivial:
 
 - if (D.dqb_curblocks == D.dqb_curblocks == 1)
 + if (D.dqb_curblocks == 1)
        *bsize = DEV_BSIZE;
 
 Please, try this and confirm or deny my wild guess :) I hope, that it's ok and
 we nailed yet another Samba bug :)
 
 With best regards,
 Timur.
State-Changed-From-To: feedback->closed 
State-Changed-By: timur 
State-Changed-When: Tue Jul 15 04:09:24 UTC 2008 
State-Changed-Why:  
A patch was created for the port version, that addresses the problem, 
according to the confirmation of the requestor. Have to pull it into 
upstream as well. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=124172 
>Unformatted:
