vserver 1.9.3
[linux-2.6.git] / fs / jfs / jfs_extent.c
index 2b411bc..1953acb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *   Copyright (C) International Business Machines Corp., 2000-2003
+ *   Copyright (C) International Business Machines Corp., 2000-2004
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -17,6 +17,7 @@
  */
 
 #include <linux/fs.h>
+#include <linux/quotaops.h>
 #include "jfs_incore.h"
 #include "jfs_superblock.h"
 #include "jfs_dmap.h"
@@ -144,6 +145,13 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, boolean_t abnr)
                return (rc);
        }
 
+       /* Allocate blocks to quota. */
+       if (DQUOT_ALLOC_BLOCK(ip, nxlen)) {
+               dbFree(ip, nxaddr, (s64) nxlen);
+               up(&JFS_IP(ip)->commit_sem);
+               return -EDQUOT;
+       }
+
        /* determine the value of the extent flag */
        xflag = (abnr == TRUE) ? XAD_NOTRECORDED : 0;
 
@@ -161,13 +169,11 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, boolean_t abnr)
         */
        if (rc) {
                dbFree(ip, nxaddr, nxlen);
+               DQUOT_FREE_BLOCK(ip, nxlen);
                up(&JFS_IP(ip)->commit_sem);
                return (rc);
        }
 
-       /* update the number of blocks allocated to the file */
-       ip->i_blocks += LBLK2PBLK(ip->i_sb, nxlen);
-
        /* set the results of the extent allocation */
        XADaddress(xp, nxaddr);
        XADlength(xp, nxlen);
@@ -254,6 +260,13 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, boolean_t abnr)
        if ((rc = extBrealloc(ip, xaddr, xlen, &nxlen, &nxaddr)))
                goto exit;
 
+       /* Allocat blocks to quota. */
+       if (DQUOT_ALLOC_BLOCK(ip, nxlen)) {
+               dbFree(ip, nxaddr, (s64) nxlen);
+               up(&JFS_IP(ip)->commit_sem);
+               return -EDQUOT;
+       }
+
        delta = nxlen - xlen;
 
        /* check if the extend page is not abnr but the request is abnr
@@ -289,6 +302,7 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, boolean_t abnr)
                /* extend the extent */
                if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
                        dbFree(ip, xaddr + xlen, delta);
+                       DQUOT_FREE_BLOCK(ip, nxlen);
                        goto exit;
                }
        } else {
@@ -299,6 +313,7 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, boolean_t abnr)
                 */
                if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
                        dbFree(ip, nxaddr, nxlen);
+                       DQUOT_FREE_BLOCK(ip, nxlen);
                        goto exit;
                }
        }
@@ -320,9 +335,6 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, boolean_t abnr)
                }
        }
 
-       /* update the inode with the number of blocks allocated */
-       ip->i_blocks += LBLK2PBLK(sb, delta);
-
        /* set the return results */
        XADaddress(xp, nxaddr);
        XADlength(xp, nxlen);