Bug 31632

Summary: Quota do not work on SAMBA Server.
Product: [Retired] Red Hat Linux Reporter: Keiichi Mori <kmori>
Component: sambaAssignee: Trond Eivind Glomsrxd <teg>
Status: CLOSED RAWHIDE QA Contact: David Lawrence <dkl>
Severity: high Docs Contact:
Priority: high    
Version: 7.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-03-30 04:13:32 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Keiichi Mori 2001-03-13 11:55:31 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [muriyari-ja] (X11; U; Linux 2.2.16-22 i686)


When Windows9x client access to SAMBA server, it cannot create files over
size limited by quota.
It is normal behavior.
But when Windows2000 client access to, it can create files over size
limited by quota.
(Windows2000 shows a Warning message.)



Reproducible: Always
Steps to Reproduce:
1.create quota file system. (/etc/fstab: /dev/hda5 /home usrquota,....)
2.Edit quota with edquota command. 
3.Edit smb.config so as to access the partition limited by quota.)
4.Windows 2000 client access to SAMBA server, and create( copy, ...) big
file (over limited size).


Actual Results:  Windows2000 shows Warning message. But it has created file
over limited size.


Expected Results:  SAMBA don not let Windows2000 client to create file over
limit size.

Comment 1 Keiichi Mori 2001-03-29 09:58:27 UTC
I make a patch for this problem.
I'm sure that the problem has been resolved by applying this patch.

Would you try to test this patch?
If you approve this patch, would you apply this patch to samba RPM package? 


---- samba-quotafix.patch -----

diff -uNr samba-2.0.7.org/source/lib/util_sock.c
samba-2.0.7/source/lib/util_sock.c
--- samba-2.0.7.org/source/lib/util_sock.c      Thu Mar 29 17:38:24 2001
+++ samba-2.0.7/source/lib/util_sock.c  Thu Mar 29 17:42:25 2001
@@ -506,6 +506,11 @@
 
     if (ret == -1) {
       DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno) ));
+      if (errno = EDQUOT) {
+        SMB_OFF_T off = sys_lseek(fd, 0, SEEK_CUR);
+        int result = sys_ftruncate(fd, off);
+        DEBUG(3,("write_data: truncate file at the size = %d, result = %d errno
= %d\n", off, result, errno));
+      }
       return -1;
     }
     if (ret == 0) return total;
diff -uNr samba-2.0.7.org/source/smbd/quotas.c samba-2.0.7/source/smbd/quotas.c
--- samba-2.0.7.org/source/smbd/quotas.c        Thu Mar 29 17:38:24 2001
+++ samba-2.0.7/source/smbd/quotas.c    Thu Mar 29 17:40:44 2001
@@ -47,7 +47,7 @@
 
 #include <sys/types.h>
 #include <asm/types.h>
-#include <sys/quota.h>
+#include <linux/quota.h>
 
 #include <mntent.h>
 #include <linux/unistd.h>
@@ -61,7 +61,7 @@
 BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree,
SMB_BIG_UINT *dsize)
 {
   int r;
-  struct dqblk D;
+  struct mem_dqblk D;
   SMB_STRUCT_STAT S;
   FILE *fp;
   struct mntent *mnt;
@@ -99,6 +99,9 @@
   save_re_uid();
   set_effective_uid(0);  
   r=quotactl(QCMD(Q_GETQUOTA,USRQUOTA), mnt->mnt_fsname, euser_id,
(caddr_t)&D);
+  /* change unit from byte to Kbyte, but I'm not sure this change is correct.
*/
+  D.dqb_curspace /= 1024;
+
   restore_re_uid();
 
   /* Use softlimit to determine disk space, except when it has been exceeded */
@@ -108,21 +111,21 @@
       if (errno == EDQUOT) 
        {
          *dfree =0;
-         *dsize =D.dqb_curblocks;
+         *dsize =D.dqb_curspace;
          return (True);
     }
       else return(False);
   }
   /* Use softlimit to determine disk space, except when it has been exceeded */
   if (
-      (D.dqb_bsoftlimit && D.dqb_curblocks>=D.dqb_bsoftlimit) ||
-      (D.dqb_bhardlimit && D.dqb_curblocks>=D.dqb_bhardlimit) ||
+      (D.dqb_bsoftlimit && D.dqb_curspace>=D.dqb_bsoftlimit) ||
+      (D.dqb_bhardlimit && D.dqb_curspace>=D.dqb_bhardlimit) ||
       (D.dqb_isoftlimit && D.dqb_curinodes>=D.dqb_isoftlimit) ||
       (D.dqb_ihardlimit && D.dqb_curinodes>=D.dqb_ihardlimit)
      )
     {
       *dfree = 0;
-      *dsize = D.dqb_curblocks;
+      *dsize = D.dqb_curspace;
     }
   else if (D.dqb_bsoftlimit==0 && D.dqb_bhardlimit==0)
     {
@@ -131,7 +134,7 @@
   else {
     if (D.dqb_bsoftlimit == 0)
       D.dqb_bsoftlimit = D.dqb_bhardlimit;
-    *dfree = D.dqb_bsoftlimit - D.dqb_curblocks;
+    *dfree = D.dqb_bsoftlimit - D.dqb_curspace;
     *dsize = D.dqb_bsoftlimit;
   }
   return (True);
diff -uNr samba-2.0.7.org/source/smbd/reply.c samba-2.0.7/source/smbd/reply.c
--- samba-2.0.7.org/source/smbd/reply.c Thu Mar 29 17:38:24 2001
+++ samba-2.0.7/source/smbd/reply.c     Thu Mar 29 17:40:44 2001
@@ -2371,7 +2371,7 @@
   DEBUG(3,("writebraw1 fnum=%d start=%.0f num=%d wrote=%d sync=%d\n",
           fsp->fnum, (double)startpos, (int)numtowrite, (int)nwritten,
(int)write_through));
 
-  if (nwritten < numtowrite) 
+  if (nwritten < (ssize_t)numtowrite) 
     return(UNIXERROR(ERRHRD,ERRdiskfull));
 
   total_written = nwritten;

------------

Comment 2 Bill Nottingham 2001-03-29 22:16:45 UTC
*** Bug 33915 has been marked as a duplicate of this bug. ***

Comment 3 Bill Nottingham 2001-03-29 22:17:43 UTC
This patch is completely broken; it does not build in a 7.0 environment.

Does this problem only occur when running on a 2.4.recent kernel?

Comment 4 Keiichi Mori 2001-03-30 04:13:28 UTC
This problem occur when running on both 2.2 kernel and a 2.4.recent kernel

But I'm sorry. I have mixed the patch for this problem and the patch only for
kernel2.4.
So I break up the patch what I sent to you into two patches.

"samba-quotafix.patch" is a patch for resolving this problems.
I build this on RH7.0 environment and on RH7.1 QA0327 environment.

"samba-quota4kernel24.patch" is a patch for samba running on kernel 2.4.
I build this only on RH7.1 QA0327 environment.

--- samba-quotafix.patch ----

diff -uNr samba-2.0.7.org/source/lib/util_sock.c
samba-2.0.7/source/lib/util_sock.c
--- samba-2.0.7.org/source/lib/util_sock.c      Fri Mar 30 11:48:30 2001
+++ samba-2.0.7/source/lib/util_sock.c  Fri Mar 30 12:16:16 2001
@@ -506,6 +506,11 @@
 
     if (ret == -1) {
       DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno) ));
+      if (errno == EDQUOT) {
+        SMB_OFF_T off = sys_lseek(fd, 0, SEEK_CUR);
+        int result = sys_ftruncate(fd, off);
+        DEBUG(3, ("write_data: truncate file at the size = %d, result = %d,
errno = %d\n", off, result, errno));
+      }
       return -1;
     }
     if (ret == 0) return total;
diff -uNr samba-2.0.7.org/source/smbd/reply.c samba-2.0.7/source/smbd/reply.c
--- samba-2.0.7.org/source/smbd/reply.c Fri Mar 30 11:48:30 2001
+++ samba-2.0.7/source/smbd/reply.c     Fri Mar 30 11:52:22 2001
@@ -2371,7 +2371,7 @@
   DEBUG(3,("writebraw1 fnum=%d start=%.0f num=%d wrote=%d sync=%d\n",
           fsp->fnum, (double)startpos, (int)numtowrite, (int)nwritten,
(int)write_through));
 
-  if (nwritten < numtowrite) 
+  if (nwritten < (ssize_t)numtowrite) 
     return(UNIXERROR(ERRHRD,ERRdiskfull));
 
   total_written = nwritten;

------------------


--- samba-quota4kernel24.patch ----

--- samba-2.0.7.org/source/smbd/quotas.c        Thu Mar 29 17:38:24 2001
+++ samba-2.0.7/source/smbd/quotas.c    Thu Mar 29 17:40:44 2001
@@ -47,7 +47,7 @@
 
 #include <sys/types.h>
 #include <asm/types.h>
-#include <sys/quota.h>
+#include <linux/quota.h>
 
 #include <mntent.h>
 #include <linux/unistd.h>
@@ -61,7 +61,7 @@
 BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree,
SMB_BIG_UINT *dsize)
 {
   int r;
-  struct dqblk D;
+  struct mem_dqblk D;
   SMB_STRUCT_STAT S;
   FILE *fp;
   struct mntent *mnt;
@@ -99,6 +99,9 @@
   save_re_uid();
   set_effective_uid(0);  
   r=quotactl(QCMD(Q_GETQUOTA,USRQUOTA), mnt->mnt_fsname, euser_id,
(caddr_t)&D);
+  /* change unit from byte to Kbyte, but I'm not sure this change is correct.
*/
+  D.dqb_curspace /= 1024;
+
   restore_re_uid();
 
   /* Use softlimit to determine disk space, except when it has been exceeded */
@@ -108,21 +111,21 @@
       if (errno == EDQUOT) 
        {
          *dfree =0;
-         *dsize =D.dqb_curblocks;
+         *dsize =D.dqb_curspace;
          return (True);
     }
       else return(False);
   }
   /* Use softlimit to determine disk space, except when it has been exceeded */
   if (
-      (D.dqb_bsoftlimit && D.dqb_curblocks>=D.dqb_bsoftlimit) ||
-      (D.dqb_bhardlimit && D.dqb_curblocks>=D.dqb_bhardlimit) ||
+      (D.dqb_bsoftlimit && D.dqb_curspace>=D.dqb_bsoftlimit) ||
+      (D.dqb_bhardlimit && D.dqb_curspace>=D.dqb_bhardlimit) ||
       (D.dqb_isoftlimit && D.dqb_curinodes>=D.dqb_isoftlimit) ||
       (D.dqb_ihardlimit && D.dqb_curinodes>=D.dqb_ihardlimit)
      )
     {
       *dfree = 0;
-      *dsize = D.dqb_curblocks;
+      *dsize = D.dqb_curspace;
     }
   else if (D.dqb_bsoftlimit==0 && D.dqb_bhardlimit==0)
     {
@@ -131,7 +134,7 @@
   else {
     if (D.dqb_bsoftlimit == 0)
       D.dqb_bsoftlimit = D.dqb_bhardlimit;
-    *dfree = D.dqb_bsoftlimit - D.dqb_curblocks;
+    *dfree = D.dqb_bsoftlimit - D.dqb_curspace;
   }
   return (True);

------------------------



Comment 5 Bill Nottingham 2001-03-30 05:17:10 UTC
OK, both parts are applied in 2.0.7-35; the first patch may make its
way into a 7.0 samba package.

Comment 6 Keiichi Mori 2001-04-02 00:39:52 UTC
Thank you very much.
If you release sampa-2.0.7-35 package, I'd like to test this and report.