]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux...
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 27 Mar 2009 21:48:34 +0000 (14:48 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 27 Mar 2009 21:48:34 +0000 (14:48 -0700)
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-quota-2.6: (27 commits)
  ext2: Zero our b_size in ext2_quota_read()
  trivial: fix typos/grammar errors in fs/Kconfig
  quota: Coding style fixes
  quota: Remove superfluous inlines
  quota: Remove uppercase aliases for quota functions.
  nfsd: Use lowercase names of quota functions
  jfs: Use lowercase names of quota functions
  udf: Use lowercase names of quota functions
  ufs: Use lowercase names of quota functions
  reiserfs: Use lowercase names of quota functions
  ext4: Use lowercase names of quota functions
  ext3: Use lowercase names of quota functions
  ext2: Use lowercase names of quota functions
  ramfs: Remove quota call
  vfs: Use lowercase names of quota functions
  quota: Remove dqbuf_t and other cleanups
  quota: Remove NODQUOT macro
  quota: Make global quota locks cacheline aligned
  quota: Move quota files into separate directory
  ext4: quota reservation for delayed allocation
  ...

1  2 
fs/ext3/inode.c
fs/inode.c
fs/namei.c
fs/nfsd/vfs.c
fs/quota/dquot.c
fs/super.c
fs/sync.c

diff --combined fs/ext3/inode.c
index 05e5c2e5c0d77cb9de0d00cbf12782a7cbf86d11,c8f9bd308821ac7259fe47bab20bd55ed703e92a..4a09ff169870517b13f65e0d26507c6505e465b2
@@@ -1435,10 -1435,6 +1435,10 @@@ static int journal_dirty_data_fn(handle
        return 0;
  }
  
 +static int buffer_unmapped(handle_t *handle, struct buffer_head *bh)
 +{
 +      return !buffer_mapped(bh);
 +}
  /*
   * Note that we always start a transaction even if we're not journalling
   * data.  This is to preserve ordering: any hole instantiation within
@@@ -1509,15 -1505,6 +1509,15 @@@ static int ext3_ordered_writepage(struc
        if (ext3_journal_current_handle())
                goto out_fail;
  
 +      if (!page_has_buffers(page)) {
 +              create_empty_buffers(page, inode->i_sb->s_blocksize,
 +                              (1 << BH_Dirty)|(1 << BH_Uptodate));
 +      } else if (!walk_page_buffers(NULL, page_buffers(page), 0, PAGE_CACHE_SIZE, NULL, buffer_unmapped)) {
 +              /* Provide NULL instead of get_block so that we catch bugs if buffers weren't really mapped */
 +              return block_write_full_page(page, NULL, wbc);
 +      }
 +      page_bufs = page_buffers(page);
 +
        handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode));
  
        if (IS_ERR(handle)) {
                goto out_fail;
        }
  
 -      if (!page_has_buffers(page)) {
 -              create_empty_buffers(page, inode->i_sb->s_blocksize,
 -                              (1 << BH_Dirty)|(1 << BH_Uptodate));
 -      }
 -      page_bufs = page_buffers(page);
        walk_page_buffers(handle, page_bufs, 0,
                        PAGE_CACHE_SIZE, NULL, bget_one);
  
@@@ -3063,7 -3055,7 +3063,7 @@@ int ext3_setattr(struct dentry *dentry
                        error = PTR_ERR(handle);
                        goto err_out;
                }
-               error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
+               error = vfs_dq_transfer(inode, attr) ? -EDQUOT : 0;
                if (error) {
                        ext3_journal_stop(handle);
                        return error;
@@@ -3154,7 -3146,7 +3154,7 @@@ static int ext3_writepage_trans_blocks(
                ret = 2 * (bpp + indirects) + 2;
  
  #ifdef CONFIG_QUOTA
-       /* We know that structure was already allocated during DQUOT_INIT so
+       /* We know that structure was already allocated during vfs_dq_init so
         * we will be updating only the data blocks + inodes */
        ret += 2*EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb);
  #endif
@@@ -3245,7 -3237,7 +3245,7 @@@ int ext3_mark_inode_dirty(handle_t *han
   * i_size has been changed by generic_commit_write() and we thus need
   * to include the updated inode in the current transaction.
   *
-  * Also, DQUOT_ALLOC_SPACE() will always dirty the inode when blocks
+  * Also, vfs_dq_alloc_space() will always dirty the inode when blocks
   * are allocated to the file.
   *
   * If the inode is marked synchronous, we don't honour that here - doing
diff --combined fs/inode.c
index 643ac43e5a5c7d6f43fe938fd4c0df6c91e2e0ce,bb81bd515f858808159b8137fdadd87c84fee206..29df4a2974494d333353c0008b9e08026954c547
@@@ -17,7 -17,6 +17,7 @@@
  #include <linux/hash.h>
  #include <linux/swap.h>
  #include <linux/security.h>
 +#include <linux/ima.h>
  #include <linux/pagemap.h>
  #include <linux/cdev.h>
  #include <linux/bootmem.h>
@@@ -148,13 -147,13 +148,13 @@@ struct inode *inode_init_always(struct 
        inode->i_cdev = NULL;
        inode->i_rdev = 0;
        inode->dirtied_when = 0;
 -      if (security_inode_alloc(inode)) {
 -              if (inode->i_sb->s_op->destroy_inode)
 -                      inode->i_sb->s_op->destroy_inode(inode);
 -              else
 -                      kmem_cache_free(inode_cachep, (inode));
 -              return NULL;
 -      }
 +
 +      if (security_inode_alloc(inode))
 +              goto out_free_inode;
 +
 +      /* allocate and initialize an i_integrity */
 +      if (ima_inode_alloc(inode))
 +              goto out_free_security;
  
        spin_lock_init(&inode->i_lock);
        lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key);
        inode->i_mapping = mapping;
  
        return inode;
 +
 +out_free_security:
 +      security_inode_free(inode);
 +out_free_inode:
 +      if (inode->i_sb->s_op->destroy_inode)
 +              inode->i_sb->s_op->destroy_inode(inode);
 +      else
 +              kmem_cache_free(inode_cachep, (inode));
 +      return NULL;
  }
  EXPORT_SYMBOL(inode_init_always);
  
@@@ -294,7 -284,7 +294,7 @@@ void clear_inode(struct inode *inode
        BUG_ON(!(inode->i_state & I_FREEING));
        BUG_ON(inode->i_state & I_CLEAR);
        inode_sync_wait(inode);
-       DQUOT_DROP(inode);
+       vfs_dq_drop(inode);
        if (inode->i_sb->s_op->clear_inode)
                inode->i_sb->s_op->clear_inode(inode);
        if (S_ISBLK(inode->i_mode) && inode->i_bdev)
@@@ -1168,7 -1158,7 +1168,7 @@@ void generic_delete_inode(struct inode 
        if (op->delete_inode) {
                void (*delete)(struct inode *) = op->delete_inode;
                if (!is_bad_inode(inode))
-                       DQUOT_INIT(inode);
+                       vfs_dq_init(inode);
                /* Filesystems implementing their own
                 * s_op->delete_inode are required to call
                 * truncate_inode_pages and clear_inode()
@@@ -1300,40 -1290,6 +1300,40 @@@ sector_t bmap(struct inode * inode, sec
  }
  EXPORT_SYMBOL(bmap);
  
 +/*
 + * With relative atime, only update atime if the previous atime is
 + * earlier than either the ctime or mtime or if at least a day has
 + * passed since the last atime update.
 + */
 +static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
 +                           struct timespec now)
 +{
 +
 +      if (!(mnt->mnt_flags & MNT_RELATIME))
 +              return 1;
 +      /*
 +       * Is mtime younger than atime? If yes, update atime:
 +       */
 +      if (timespec_compare(&inode->i_mtime, &inode->i_atime) >= 0)
 +              return 1;
 +      /*
 +       * Is ctime younger than atime? If yes, update atime:
 +       */
 +      if (timespec_compare(&inode->i_ctime, &inode->i_atime) >= 0)
 +              return 1;
 +
 +      /*
 +       * Is the previous atime value older than a day? If yes,
 +       * update atime:
 +       */
 +      if ((long)(now.tv_sec - inode->i_atime.tv_sec) >= 24*60*60)
 +              return 1;
 +      /*
 +       * Good, we can skip the atime update:
 +       */
 +      return 0;
 +}
 +
  /**
   *    touch_atime     -       update the access time
   *    @mnt: mount the inode is accessed on
@@@ -1361,12 -1317,17 +1361,12 @@@ void touch_atime(struct vfsmount *mnt, 
                goto out;
        if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))
                goto out;
 -      if (mnt->mnt_flags & MNT_RELATIME) {
 -              /*
 -               * With relative atime, only update atime if the previous
 -               * atime is earlier than either the ctime or mtime.
 -               */
 -              if (timespec_compare(&inode->i_mtime, &inode->i_atime) < 0 &&
 -                  timespec_compare(&inode->i_ctime, &inode->i_atime) < 0)
 -                      goto out;
 -      }
  
        now = current_fs_time(inode->i_sb);
 +
 +      if (!relatime_need_update(mnt, inode, now))
 +              goto out;
 +
        if (timespec_equal(&inode->i_atime, &now))
                goto out;
  
diff --combined fs/namei.c
index 199317642ad6d731f47dd61693a2374145f99337,8937f4e78178a80c158e13df6f99ad9452311378..1928197b3874bd9589b3e9bad7335e52a41bd8df
@@@ -24,7 -24,6 +24,7 @@@
  #include <linux/fsnotify.h>
  #include <linux/personality.h>
  #include <linux/security.h>
 +#include <linux/ima.h>
  #include <linux/syscalls.h>
  #include <linux/mount.h>
  #include <linux/audit.h>
@@@ -851,8 -850,6 +851,8 @@@ static int __link_path_walk(const char 
                if (err == -EAGAIN)
                        err = inode_permission(nd->path.dentry->d_inode,
                                               MAY_EXEC);
 +              if (!err)
 +                      err = ima_path_check(&nd->path, MAY_EXEC);
                if (err)
                        break;
  
@@@ -1473,7 -1470,7 +1473,7 @@@ int vfs_create(struct inode *dir, struc
        error = security_inode_create(dir, dentry, mode);
        if (error)
                return error;
-       DQUOT_INIT(dir);
+       vfs_dq_init(dir);
        error = dir->i_op->create(dir, dentry, mode, nd);
        if (!error)
                fsnotify_create(dir, dentry);
@@@ -1512,11 -1509,6 +1512,11 @@@ int may_open(struct path *path, int acc
        error = inode_permission(inode, acc_mode);
        if (error)
                return error;
 +
 +      error = ima_path_check(path,
 +                             acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC));
 +      if (error)
 +              return error;
        /*
         * An append-only file must be opened in append mode for writing.
         */
                        error = security_path_truncate(path, 0,
                                               ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
                if (!error) {
-                       DQUOT_INIT(inode);
+                       vfs_dq_init(inode);
  
                        error = do_truncate(dentry, 0,
                                            ATTR_MTIME|ATTR_CTIME|ATTR_OPEN,
                        return error;
        } else
                if (flag & FMODE_WRITE)
-                       DQUOT_INIT(inode);
+                       vfs_dq_init(inode);
  
        return 0;
  }
@@@ -1946,7 -1938,7 +1946,7 @@@ int vfs_mknod(struct inode *dir, struc
        if (error)
                return error;
  
-       DQUOT_INIT(dir);
+       vfs_dq_init(dir);
        error = dir->i_op->mknod(dir, dentry, mode, dev);
        if (!error)
                fsnotify_create(dir, dentry);
@@@ -2045,7 -2037,7 +2045,7 @@@ int vfs_mkdir(struct inode *dir, struc
        if (error)
                return error;
  
-       DQUOT_INIT(dir);
+       vfs_dq_init(dir);
        error = dir->i_op->mkdir(dir, dentry, mode);
        if (!error)
                fsnotify_mkdir(dir, dentry);
@@@ -2131,7 -2123,7 +2131,7 @@@ int vfs_rmdir(struct inode *dir, struc
        if (!dir->i_op->rmdir)
                return -EPERM;
  
-       DQUOT_INIT(dir);
+       vfs_dq_init(dir);
  
        mutex_lock(&dentry->d_inode->i_mutex);
        dentry_unhash(dentry);
@@@ -2218,7 -2210,7 +2218,7 @@@ int vfs_unlink(struct inode *dir, struc
        if (!dir->i_op->unlink)
                return -EPERM;
  
-       DQUOT_INIT(dir);
+       vfs_dq_init(dir);
  
        mutex_lock(&dentry->d_inode->i_mutex);
        if (d_mountpoint(dentry))
@@@ -2329,7 -2321,7 +2329,7 @@@ int vfs_symlink(struct inode *dir, stru
        if (error)
                return error;
  
-       DQUOT_INIT(dir);
+       vfs_dq_init(dir);
        error = dir->i_op->symlink(dir, dentry, oldname);
        if (!error)
                fsnotify_create(dir, dentry);
@@@ -2413,7 -2405,7 +2413,7 @@@ int vfs_link(struct dentry *old_dentry
                return error;
  
        mutex_lock(&inode->i_mutex);
-       DQUOT_INIT(dir);
+       vfs_dq_init(dir);
        error = dir->i_op->link(old_dentry, dir, new_dentry);
        mutex_unlock(&inode->i_mutex);
        if (!error)
@@@ -2612,8 -2604,8 +2612,8 @@@ int vfs_rename(struct inode *old_dir, s
        if (!old_dir->i_op->rename)
                return -EPERM;
  
-       DQUOT_INIT(old_dir);
-       DQUOT_INIT(new_dir);
+       vfs_dq_init(old_dir);
+       vfs_dq_init(new_dir);
  
        old_name = fsnotify_oldname_init(old_dentry->d_name.name);
  
diff --combined fs/nfsd/vfs.c
index c165a6403df03e52219925b875ef420adcbd331a,ad38fc9e5816df447c8bcec881a82bca5caa6e07..78376b6c0236161009488e0bf4f3a2a707c3bc44
@@@ -356,7 -356,7 +356,7 @@@ nfsd_setattr(struct svc_rqst *rqstp, st
                        put_write_access(inode);
                        goto out_nfserr;
                }
-               DQUOT_INIT(inode);
+               vfs_dq_init(inode);
        }
  
        /* sanitize the mode change */
@@@ -723,7 -723,7 +723,7 @@@ nfsd_open(struct svc_rqst *rqstp, struc
                else
                        flags = O_WRONLY|O_LARGEFILE;
  
-               DQUOT_INIT(inode);
+               vfs_dq_init(inode);
        }
        *filp = dentry_open(dget(dentry), mntget(fhp->fh_export->ex_path.mnt),
                            flags, cred);
@@@ -998,11 -998,8 +998,11 @@@ nfsd_vfs_write(struct svc_rqst *rqstp, 
  
        if (!EX_ISSYNC(exp))
                stable = 0;
 -      if (stable && !EX_WGATHER(exp))
 +      if (stable && !EX_WGATHER(exp)) {
 +              spin_lock(&file->f_lock);
                file->f_flags |= O_SYNC;
 +              spin_unlock(&file->f_lock);
 +      }
  
        /* Write the data. */
        oldfs = get_fs(); set_fs(KERNEL_DS);
diff --combined fs/quota/dquot.c
index d6add0bf5ad3a9200ced2db449b0d6e1b049d146,a1bd5eabbe50d8d81a6a408f622bf6c7d27f3684..eb938015bd91a1983513c1c2a297a66467605dd8
   * i_mutex on quota files is special (it's below dqio_mutex)
   */
  
- static DEFINE_SPINLOCK(dq_list_lock);
- static DEFINE_SPINLOCK(dq_state_lock);
- DEFINE_SPINLOCK(dq_data_lock);
+ static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_list_lock);
+ static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_state_lock);
+ __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_data_lock);
+ EXPORT_SYMBOL(dq_data_lock);
  
  static char *quotatypes[] = INITQFNAMES;
  static struct quota_format_type *quota_formats;       /* List of registered formats */
@@@ -148,35 -149,46 +149,46 @@@ int register_quota_format(struct quota_
        spin_unlock(&dq_list_lock);
        return 0;
  }
+ EXPORT_SYMBOL(register_quota_format);
  
  void unregister_quota_format(struct quota_format_type *fmt)
  {
        struct quota_format_type **actqf;
  
        spin_lock(&dq_list_lock);
-       for (actqf = &quota_formats; *actqf && *actqf != fmt; actqf = &(*actqf)->qf_next);
+       for (actqf = &quota_formats; *actqf && *actqf != fmt;
+            actqf = &(*actqf)->qf_next)
+               ;
        if (*actqf)
                *actqf = (*actqf)->qf_next;
        spin_unlock(&dq_list_lock);
  }
+ EXPORT_SYMBOL(unregister_quota_format);
  
  static struct quota_format_type *find_quota_format(int id)
  {
        struct quota_format_type *actqf;
  
        spin_lock(&dq_list_lock);
-       for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id; actqf = actqf->qf_next);
+       for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id;
+            actqf = actqf->qf_next)
+               ;
        if (!actqf || !try_module_get(actqf->qf_owner)) {
                int qm;
  
                spin_unlock(&dq_list_lock);
                
-               for (qm = 0; module_names[qm].qm_fmt_id && module_names[qm].qm_fmt_id != id; qm++);
-               if (!module_names[qm].qm_fmt_id || request_module(module_names[qm].qm_mod_name))
+               for (qm = 0; module_names[qm].qm_fmt_id &&
+                            module_names[qm].qm_fmt_id != id; qm++)
+                       ;
+               if (!module_names[qm].qm_fmt_id ||
+                   request_module(module_names[qm].qm_mod_name))
                        return NULL;
  
                spin_lock(&dq_list_lock);
-               for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id; actqf = actqf->qf_next);
+               for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id;
+                    actqf = actqf->qf_next)
+                       ;
                if (actqf && !try_module_get(actqf->qf_owner))
                        actqf = NULL;
        }
@@@ -215,6 -227,7 +227,7 @@@ static unsigned int dq_hash_bits, dq_ha
  static struct hlist_head *dquot_hash;
  
  struct dqstats dqstats;
+ EXPORT_SYMBOL(dqstats);
  
  static inline unsigned int
  hashfn(const struct super_block *sb, unsigned int id, int type)
   */
  static inline void insert_dquot_hash(struct dquot *dquot)
  {
-       struct hlist_head *head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type);
+       struct hlist_head *head;
+       head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type);
        hlist_add_head(&dquot->dq_hash, head);
  }
  
@@@ -239,17 -253,19 +253,19 @@@ static inline void remove_dquot_hash(st
        hlist_del_init(&dquot->dq_hash);
  }
  
- static inline struct dquot *find_dquot(unsigned int hashent, struct super_block *sb, unsigned int id, int type)
+ static struct dquot *find_dquot(unsigned int hashent, struct super_block *sb,
+                               unsigned int id, int type)
  {
        struct hlist_node *node;
        struct dquot *dquot;
  
        hlist_for_each (node, dquot_hash+hashent) {
                dquot = hlist_entry(node, struct dquot, dq_hash);
-               if (dquot->dq_sb == sb && dquot->dq_id == id && dquot->dq_type == type)
+               if (dquot->dq_sb == sb && dquot->dq_id == id &&
+                   dquot->dq_type == type)
                        return dquot;
        }
-       return NODQUOT;
+       return NULL;
  }
  
  /* Add a dquot to the tail of the free list */
@@@ -309,6 -325,7 +325,7 @@@ int dquot_mark_dquot_dirty(struct dquo
        spin_unlock(&dq_list_lock);
        return 0;
  }
+ EXPORT_SYMBOL(dquot_mark_dquot_dirty);
  
  /* This function needs dq_list_lock */
  static inline int clear_dquot_dirty(struct dquot *dquot)
@@@ -345,8 -362,10 +362,10 @@@ int dquot_acquire(struct dquot *dquot
        if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) {
                ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
                /* Write the info if needed */
-               if (info_dirty(&dqopt->info[dquot->dq_type]))
-                       ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
+               if (info_dirty(&dqopt->info[dquot->dq_type])) {
+                       ret2 = dqopt->ops[dquot->dq_type]->write_file_info(
+                                               dquot->dq_sb, dquot->dq_type);
+               }
                if (ret < 0)
                        goto out_iolock;
                if (ret2 < 0) {
@@@ -360,6 -379,7 +379,7 @@@ out_iolock
        mutex_unlock(&dquot->dq_lock);
        return ret;
  }
+ EXPORT_SYMBOL(dquot_acquire);
  
  /*
   *    Write dquot to disk
@@@ -380,8 -400,10 +400,10 @@@ int dquot_commit(struct dquot *dquot
         * => we have better not writing it */
        if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
                ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
-               if (info_dirty(&dqopt->info[dquot->dq_type]))
-                       ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
+               if (info_dirty(&dqopt->info[dquot->dq_type])) {
+                       ret2 = dqopt->ops[dquot->dq_type]->write_file_info(
+                                               dquot->dq_sb, dquot->dq_type);
+               }
                if (ret >= 0)
                        ret = ret2;
        }
@@@ -389,6 -411,7 +411,7 @@@ out_sem
        mutex_unlock(&dqopt->dqio_mutex);
        return ret;
  }
+ EXPORT_SYMBOL(dquot_commit);
  
  /*
   *    Release dquot
@@@ -406,8 -429,10 +429,10 @@@ int dquot_release(struct dquot *dquot
        if (dqopt->ops[dquot->dq_type]->release_dqblk) {
                ret = dqopt->ops[dquot->dq_type]->release_dqblk(dquot);
                /* Write the info */
-               if (info_dirty(&dqopt->info[dquot->dq_type]))
-                       ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
+               if (info_dirty(&dqopt->info[dquot->dq_type])) {
+                       ret2 = dqopt->ops[dquot->dq_type]->write_file_info(
+                                               dquot->dq_sb, dquot->dq_type);
+               }
                if (ret >= 0)
                        ret = ret2;
        }
@@@ -417,6 -442,7 +442,7 @@@ out_dqlock
        mutex_unlock(&dquot->dq_lock);
        return ret;
  }
+ EXPORT_SYMBOL(dquot_release);
  
  void dquot_destroy(struct dquot *dquot)
  {
@@@ -516,6 -542,7 +542,7 @@@ out
        mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
        return ret;
  }
+ EXPORT_SYMBOL(dquot_scan_active);
  
  int vfs_quota_sync(struct super_block *sb, int type)
  {
                spin_lock(&dq_list_lock);
                dirty = &dqopt->info[cnt].dqi_dirty_list;
                while (!list_empty(dirty)) {
-                       dquot = list_first_entry(dirty, struct dquot, dq_dirty);
+                       dquot = list_first_entry(dirty, struct dquot,
+                                                dq_dirty);
                        /* Dirty and inactive can be only bad dquot... */
                        if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
                                clear_dquot_dirty(dquot);
  
        return 0;
  }
+ EXPORT_SYMBOL(vfs_quota_sync);
  
  /* Free unused dquots from cache */
  static void prune_dqcache(int count)
@@@ -672,6 -701,7 +701,7 @@@ we_slept
        put_dquot_last(dquot);
        spin_unlock(&dq_list_lock);
  }
+ EXPORT_SYMBOL(dqput);
  
  struct dquot *dquot_alloc(struct super_block *sb, int type)
  {
@@@ -685,7 -715,7 +715,7 @@@ static struct dquot *get_empty_dquot(st
  
        dquot = sb->dq_op->alloc_dquot(sb, type);
        if(!dquot)
-               return NODQUOT;
+               return NULL;
  
        mutex_init(&dquot->dq_lock);
        INIT_LIST_HEAD(&dquot->dq_free);
  struct dquot *dqget(struct super_block *sb, unsigned int id, int type)
  {
        unsigned int hashent = hashfn(sb, id, type);
-       struct dquot *dquot = NODQUOT, *empty = NODQUOT;
+       struct dquot *dquot = NULL, *empty = NULL;
  
          if (!sb_has_quota_active(sb, type))
-               return NODQUOT;
+               return NULL;
  we_slept:
        spin_lock(&dq_list_lock);
        spin_lock(&dq_state_lock);
        }
        spin_unlock(&dq_state_lock);
  
-       if ((dquot = find_dquot(hashent, sb, id, type)) == NODQUOT) {
-               if (empty == NODQUOT) {
+       dquot = find_dquot(hashent, sb, id, type);
+       if (!dquot) {
+               if (!empty) {
                        spin_unlock(&dq_list_lock);
-                       if ((empty = get_empty_dquot(sb, type)) == NODQUOT)
+                       empty = get_empty_dquot(sb, type);
+                       if (!empty)
                                schedule();     /* Try to wait for a moment... */
                        goto we_slept;
                }
                dquot = empty;
-               empty = NODQUOT;
+               empty = NULL;
                dquot->dq_id = id;
                /* all dquots go on the inuse_list */
                put_inuse(dquot);
                dqstats.lookups++;
                spin_unlock(&dq_list_lock);
        }
-       /* Wait for dq_lock - after this we know that either dquot_release() is already
-        * finished or it will be canceled due to dq_count > 1 test */
+       /* Wait for dq_lock - after this we know that either dquot_release() is
+        * already finished or it will be canceled due to dq_count > 1 test */
        wait_on_dquot(dquot);
-       /* Read the dquot and instantiate it (everything done only if needed) */
-       if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && sb->dq_op->acquire_dquot(dquot) < 0) {
+       /* Read the dquot / allocate space in quota file */
+       if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) &&
+           sb->dq_op->acquire_dquot(dquot) < 0) {
                dqput(dquot);
-               dquot = NODQUOT;
+               dquot = NULL;
                goto out;
        }
  #ifdef __DQUOT_PARANOIA
@@@ -767,6 -800,7 +800,7 @@@ out
  
        return dquot;
  }
+ EXPORT_SYMBOL(dqget);
  
  static int dqinit_needed(struct inode *inode, int type)
  {
        if (IS_NOQUOTA(inode))
                return 0;
        if (type != -1)
-               return inode->i_dquot[type] == NODQUOT;
+               return !inode->i_dquot[type];
        for (cnt = 0; cnt < MAXQUOTAS; cnt++)
-               if (inode->i_dquot[cnt] == NODQUOT)
+               if (!inode->i_dquot[cnt])
                        return 1;
        return 0;
  }
@@@ -813,7 -847,10 +847,10 @@@ static void add_dquot_ref(struct super_
        iput(old_inode);
  }
  
- /* Return 0 if dqput() won't block (note that 1 doesn't necessarily mean blocking) */
+ /*
+  * Return 0 if dqput() won't block.
+  * (note that 1 doesn't necessarily mean blocking)
+  */
  static inline int dqput_blocks(struct dquot *dquot)
  {
        if (atomic_read(&dquot->dq_count) <= 1)
        return 0;
  }
  
- /* Remove references to dquots from inode - add dquot to list for freeing if needed */
- /* We can't race with anybody because we hold dqptr_sem for writing... */
+ /*
+  * Remove references to dquots from inode and add dquot to list for freeing
+  * if we have the last referece to dquot
+  * We can't race with anybody because we hold dqptr_sem for writing...
+  */
  static int remove_inode_dquot_ref(struct inode *inode, int type,
                                  struct list_head *tofree_head)
  {
        struct dquot *dquot = inode->i_dquot[type];
  
-       inode->i_dquot[type] = NODQUOT;
-       if (dquot != NODQUOT) {
+       inode->i_dquot[type] = NULL;
+       if (dquot) {
                if (dqput_blocks(dquot)) {
  #ifdef __DQUOT_PARANOIA
                        if (atomic_read(&dquot->dq_count) != 1)
                                printk(KERN_WARNING "VFS: Adding dquot with dq_count %d to dispose list.\n", atomic_read(&dquot->dq_count));
  #endif
                        spin_lock(&dq_list_lock);
-                       list_add(&dquot->dq_free, tofree_head); /* As dquot must have currently users it can't be on the free list... */
+                       /* As dquot must have currently users it can't be on
+                        * the free list... */
+                       list_add(&dquot->dq_free, tofree_head);
                        spin_unlock(&dq_list_lock);
                        return 1;
                }
        return 0;
  }
  
- /* Free list of dquots - called from inode.c */
- /* dquots are removed from inodes, no new references can be got so we are the only ones holding reference */
+ /*
+  * Free list of dquots
+  * Dquots are removed from inodes and no new references can be got so we are
+  * the only ones holding reference
+  */
  static void put_dquot_list(struct list_head *tofree_head)
  {
        struct list_head *act_head;
        struct dquot *dquot;
  
        act_head = tofree_head->next;
-       /* So now we have dquots on the list... Just free them */
        while (act_head != tofree_head) {
                dquot = list_entry(act_head, struct dquot, dq_free);
                act_head = act_head->next;
-               list_del_init(&dquot->dq_free); /* Remove dquot from the list so we won't have problems... */
+               /* Remove dquot from the list so we won't have problems... */
+               list_del_init(&dquot->dq_free);
                dqput(dquot);
        }
  }
@@@ -899,7 -944,29 +944,29 @@@ static inline void dquot_incr_space(str
        dquot->dq_dqb.dqb_curspace += number;
  }
  
- static inline void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
+ static inline void dquot_resv_space(struct dquot *dquot, qsize_t number)
+ {
+       dquot->dq_dqb.dqb_rsvspace += number;
+ }
+ /*
+  * Claim reserved quota space
+  */
+ static void dquot_claim_reserved_space(struct dquot *dquot,
+                                               qsize_t number)
+ {
+       WARN_ON(dquot->dq_dqb.dqb_rsvspace < number);
+       dquot->dq_dqb.dqb_curspace += number;
+       dquot->dq_dqb.dqb_rsvspace -= number;
+ }
+ static inline
+ void dquot_free_reserved_space(struct dquot *dquot, qsize_t number)
+ {
+       dquot->dq_dqb.dqb_rsvspace -= number;
+ }
+ static void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
  {
        if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE ||
            dquot->dq_dqb.dqb_curinodes >= number)
        clear_bit(DQ_INODES_B, &dquot->dq_flags);
  }
  
- static inline void dquot_decr_space(struct dquot *dquot, qsize_t number)
+ static void dquot_decr_space(struct dquot *dquot, qsize_t number)
  {
        if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE ||
            dquot->dq_dqb.dqb_curspace >= number)
@@@ -938,7 -1005,7 +1005,7 @@@ static int warning_issued(struct dquot 
  #ifdef CONFIG_PRINT_QUOTA_WARNING
  static int flag_print_warnings = 1;
  
- static inline int need_print_warning(struct dquot *dquot)
+ static int need_print_warning(struct dquot *dquot)
  {
        if (!flag_print_warnings)
                return 0;
@@@ -1057,7 -1124,10 +1124,7 @@@ static void send_warning(const struct d
                goto attr_err_out;
        genlmsg_end(skb, msg_head);
  
 -      ret = genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
 -      if (ret < 0 && ret != -ESRCH)
 -              printk(KERN_ERR
 -                      "VFS: Failed to send notification message: %d\n", ret);
 +      genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
        return;
  attr_err_out:
        printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
@@@ -1065,13 -1135,17 +1132,17 @@@ err_out
        kfree_skb(skb);
  }
  #endif
- static inline void flush_warnings(struct dquot * const *dquots, char *warntype)
+ /*
+  * Write warnings to the console and send warning messages over netlink.
+  *
+  * Note that this function can sleep.
+  */
+ static void flush_warnings(struct dquot *const *dquots, char *warntype)
  {
        int i;
  
        for (i = 0; i < MAXQUOTAS; i++)
-               if (dquots[i] != NODQUOT && warntype[i] != QUOTA_NL_NOWARN &&
+               if (dquots[i] && warntype[i] != QUOTA_NL_NOWARN &&
                    !warning_issued(dquots[i], warntype[i])) {
  #ifdef CONFIG_PRINT_QUOTA_WARNING
                        print_warning(dquots[i], warntype[i]);
                }
  }
  
- static inline char ignore_hardlimit(struct dquot *dquot)
+ static int ignore_hardlimit(struct dquot *dquot)
  {
        struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
  
        return capable(CAP_SYS_RESOURCE) &&
-           (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD || !(info->dqi_flags & V1_DQF_RSQUASH));
+              (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD ||
+               !(info->dqi_flags & V1_DQF_RSQUASH));
  }
  
  /* needs dq_data_lock */
  static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
  {
+       qsize_t newinodes = dquot->dq_dqb.dqb_curinodes + inodes;
        *warntype = QUOTA_NL_NOWARN;
        if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) ||
            test_bit(DQ_FAKE_B, &dquot->dq_flags))
                return QUOTA_OK;
  
        if (dquot->dq_dqb.dqb_ihardlimit &&
-          (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_ihardlimit &&
+           newinodes > dquot->dq_dqb.dqb_ihardlimit &&
              !ignore_hardlimit(dquot)) {
                *warntype = QUOTA_NL_IHARDWARN;
                return NO_QUOTA;
        }
  
        if (dquot->dq_dqb.dqb_isoftlimit &&
-          (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
-           dquot->dq_dqb.dqb_itime && get_seconds() >= dquot->dq_dqb.dqb_itime &&
+           newinodes > dquot->dq_dqb.dqb_isoftlimit &&
+           dquot->dq_dqb.dqb_itime &&
+           get_seconds() >= dquot->dq_dqb.dqb_itime &&
              !ignore_hardlimit(dquot)) {
                *warntype = QUOTA_NL_ISOFTLONGWARN;
                return NO_QUOTA;
        }
  
        if (dquot->dq_dqb.dqb_isoftlimit &&
-          (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
+           newinodes > dquot->dq_dqb.dqb_isoftlimit &&
            dquot->dq_dqb.dqb_itime == 0) {
                *warntype = QUOTA_NL_ISOFTWARN;
-               dquot->dq_dqb.dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
+               dquot->dq_dqb.dqb_itime = get_seconds() +
+                   sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
        }
  
        return QUOTA_OK;
  /* needs dq_data_lock */
  static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype)
  {
+       qsize_t tspace;
+       struct super_block *sb = dquot->dq_sb;
        *warntype = QUOTA_NL_NOWARN;
-       if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) ||
+       if (!sb_has_quota_limits_enabled(sb, dquot->dq_type) ||
            test_bit(DQ_FAKE_B, &dquot->dq_flags))
                return QUOTA_OK;
  
+       tspace = dquot->dq_dqb.dqb_curspace + dquot->dq_dqb.dqb_rsvspace
+               + space;
        if (dquot->dq_dqb.dqb_bhardlimit &&
-           dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bhardlimit &&
+           tspace > dquot->dq_dqb.dqb_bhardlimit &&
              !ignore_hardlimit(dquot)) {
                if (!prealloc)
                        *warntype = QUOTA_NL_BHARDWARN;
        }
  
        if (dquot->dq_dqb.dqb_bsoftlimit &&
-           dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bsoftlimit &&
-           dquot->dq_dqb.dqb_btime && get_seconds() >= dquot->dq_dqb.dqb_btime &&
+           tspace > dquot->dq_dqb.dqb_bsoftlimit &&
+           dquot->dq_dqb.dqb_btime &&
+           get_seconds() >= dquot->dq_dqb.dqb_btime &&
              !ignore_hardlimit(dquot)) {
                if (!prealloc)
                        *warntype = QUOTA_NL_BSOFTLONGWARN;
        }
  
        if (dquot->dq_dqb.dqb_bsoftlimit &&
-           dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bsoftlimit &&
+           tspace > dquot->dq_dqb.dqb_bsoftlimit &&
            dquot->dq_dqb.dqb_btime == 0) {
                if (!prealloc) {
                        *warntype = QUOTA_NL_BSOFTWARN;
-                       dquot->dq_dqb.dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace;
+                       dquot->dq_dqb.dqb_btime = get_seconds() +
+                           sb_dqopt(sb)->info[dquot->dq_type].dqi_bgrace;
                }
                else
                        /*
  
  static int info_idq_free(struct dquot *dquot, qsize_t inodes)
  {
+       qsize_t newinodes;
        if (test_bit(DQ_FAKE_B, &dquot->dq_flags) ||
            dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit ||
            !sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type))
                return QUOTA_NL_NOWARN;
  
-       if (dquot->dq_dqb.dqb_curinodes - inodes <= dquot->dq_dqb.dqb_isoftlimit)
+       newinodes = dquot->dq_dqb.dqb_curinodes - inodes;
+       if (newinodes <= dquot->dq_dqb.dqb_isoftlimit)
                return QUOTA_NL_ISOFTBELOW;
        if (dquot->dq_dqb.dqb_curinodes >= dquot->dq_dqb.dqb_ihardlimit &&
-           dquot->dq_dqb.dqb_curinodes - inodes < dquot->dq_dqb.dqb_ihardlimit)
+           newinodes < dquot->dq_dqb.dqb_ihardlimit)
                return QUOTA_NL_IHARDBELOW;
        return QUOTA_NL_NOWARN;
  }
@@@ -1203,7 -1293,7 +1290,7 @@@ int dquot_initialize(struct inode *inod
  {
        unsigned int id = 0;
        int cnt, ret = 0;
-       struct dquot *got[MAXQUOTAS] = { NODQUOT, NODQUOT };
+       struct dquot *got[MAXQUOTAS] = { NULL, NULL };
        struct super_block *sb = inode->i_sb;
  
        /* First test before acquiring mutex - solves deadlocks when we
                /* Avoid races with quotaoff() */
                if (!sb_has_quota_active(sb, cnt))
                        continue;
-               if (inode->i_dquot[cnt] == NODQUOT) {
+               if (!inode->i_dquot[cnt]) {
                        inode->i_dquot[cnt] = got[cnt];
-                       got[cnt] = NODQUOT;
+                       got[cnt] = NULL;
                }
        }
  out_err:
                dqput(got[cnt]);
        return ret;
  }
+ EXPORT_SYMBOL(dquot_initialize);
  
  /*
   *    Release all quotas referenced by inode
@@@ -1260,7 -1351,7 +1348,7 @@@ int dquot_drop(struct inode *inode
        down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
        for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
                put[cnt] = inode->i_dquot[cnt];
-               inode->i_dquot[cnt] = NODQUOT;
+               inode->i_dquot[cnt] = NULL;
        }
        up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
  
                dqput(put[cnt]);
        return 0;
  }
+ EXPORT_SYMBOL(dquot_drop);
  
  /* Wrapper to remove references to quota structures from inode */
  void vfs_dq_drop(struct inode *inode)
                 * must assure that nobody can come after the DQUOT_DROP and
                 * add quota pointers back anyway */
                for (cnt = 0; cnt < MAXQUOTAS; cnt++)
-                       if (inode->i_dquot[cnt] != NODQUOT)
+                       if (inode->i_dquot[cnt])
                                break;
                if (cnt < MAXQUOTAS)
                        inode->i_sb->dq_op->drop(inode);
        }
  }
+ EXPORT_SYMBOL(vfs_dq_drop);
  
  /*
   * Following four functions update i_blocks+i_bytes fields and
  /*
   * This operation can block, but only after everything is updated
   */
- int dquot_alloc_space(struct inode *inode, qsize_t number, int warn)
+ int __dquot_alloc_space(struct inode *inode, qsize_t number,
+                       int warn, int reserve)
  {
-       int cnt, ret = NO_QUOTA;
+       int cnt, ret = QUOTA_OK;
        char warntype[MAXQUOTAS];
  
-       /* First test before acquiring mutex - solves deadlocks when we
-          * re-enter the quota code and are already holding the mutex */
-       if (IS_NOQUOTA(inode)) {
- out_add:
-               inode_add_bytes(inode, number);
-               return QUOTA_OK;
-       }
        for (cnt = 0; cnt < MAXQUOTAS; cnt++)
                warntype[cnt] = QUOTA_NL_NOWARN;
  
-       down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
-       if (IS_NOQUOTA(inode)) {        /* Now we can do reliable test... */
-               up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
-               goto out_add;
-       }
        spin_lock(&dq_data_lock);
        for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-               if (inode->i_dquot[cnt] == NODQUOT)
+               if (!inode->i_dquot[cnt])
                        continue;
-               if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) == NO_QUOTA)
-                       goto warn_put_all;
+               if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt)
+                   == NO_QUOTA) {
+                       ret = NO_QUOTA;
+                       goto out_unlock;
+               }
        }
        for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-               if (inode->i_dquot[cnt] == NODQUOT)
+               if (!inode->i_dquot[cnt])
                        continue;
-               dquot_incr_space(inode->i_dquot[cnt], number);
+               if (reserve)
+                       dquot_resv_space(inode->i_dquot[cnt], number);
+               else
+                       dquot_incr_space(inode->i_dquot[cnt], number);
        }
-       inode_add_bytes(inode, number);
-       ret = QUOTA_OK;
warn_put_all:
+       if (!reserve)
+               inode_add_bytes(inode, number);
out_unlock:
        spin_unlock(&dq_data_lock);
-       if (ret == QUOTA_OK)
-               /* Dirtify all the dquots - this can block when journalling */
-               for (cnt = 0; cnt < MAXQUOTAS; cnt++)
-                       if (inode->i_dquot[cnt])
-                               mark_dquot_dirty(inode->i_dquot[cnt]);
        flush_warnings(inode->i_dquot, warntype);
+       return ret;
+ }
+ int dquot_alloc_space(struct inode *inode, qsize_t number, int warn)
+ {
+       int cnt, ret = QUOTA_OK;
+       /*
+        * First test before acquiring mutex - solves deadlocks when we
+        * re-enter the quota code and are already holding the mutex
+        */
+       if (IS_NOQUOTA(inode)) {
+               inode_add_bytes(inode, number);
+               goto out;
+       }
+       down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+       if (IS_NOQUOTA(inode)) {
+               inode_add_bytes(inode, number);
+               goto out_unlock;
+       }
+       ret = __dquot_alloc_space(inode, number, warn, 0);
+       if (ret == NO_QUOTA)
+               goto out_unlock;
+       /* Dirtify all the dquots - this can block when journalling */
+       for (cnt = 0; cnt < MAXQUOTAS; cnt++)
+               if (inode->i_dquot[cnt])
+                       mark_dquot_dirty(inode->i_dquot[cnt]);
+ out_unlock:
+       up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+ out:
+       return ret;
+ }
+ EXPORT_SYMBOL(dquot_alloc_space);
+ int dquot_reserve_space(struct inode *inode, qsize_t number, int warn)
+ {
+       int ret = QUOTA_OK;
+       if (IS_NOQUOTA(inode))
+               goto out;
+       down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+       if (IS_NOQUOTA(inode))
+               goto out_unlock;
+       ret = __dquot_alloc_space(inode, number, warn, 1);
+ out_unlock:
        up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+ out:
        return ret;
  }
+ EXPORT_SYMBOL(dquot_reserve_space);
  
  /*
   * This operation can block, but only after everything is updated
@@@ -1370,14 -1505,15 +1502,15 @@@ int dquot_alloc_inode(const struct inod
        }
        spin_lock(&dq_data_lock);
        for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-               if (inode->i_dquot[cnt] == NODQUOT)
+               if (!inode->i_dquot[cnt])
                        continue;
-               if (check_idq(inode->i_dquot[cnt], number, warntype+cnt) == NO_QUOTA)
+               if (check_idq(inode->i_dquot[cnt], number, warntype+cnt)
+                   == NO_QUOTA)
                        goto warn_put_all;
        }
  
        for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-               if (inode->i_dquot[cnt] == NODQUOT)
+               if (!inode->i_dquot[cnt])
                        continue;
                dquot_incr_inodes(inode->i_dquot[cnt], number);
        }
@@@ -1393,6 -1529,73 +1526,73 @@@ warn_put_all
        up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
        return ret;
  }
+ EXPORT_SYMBOL(dquot_alloc_inode);
+ int dquot_claim_space(struct inode *inode, qsize_t number)
+ {
+       int cnt;
+       int ret = QUOTA_OK;
+       if (IS_NOQUOTA(inode)) {
+               inode_add_bytes(inode, number);
+               goto out;
+       }
+       down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+       if (IS_NOQUOTA(inode))  {
+               up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+               inode_add_bytes(inode, number);
+               goto out;
+       }
+       spin_lock(&dq_data_lock);
+       /* Claim reserved quotas to allocated quotas */
+       for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
+               if (inode->i_dquot[cnt])
+                       dquot_claim_reserved_space(inode->i_dquot[cnt],
+                                                       number);
+       }
+       /* Update inode bytes */
+       inode_add_bytes(inode, number);
+       spin_unlock(&dq_data_lock);
+       /* Dirtify all the dquots - this can block when journalling */
+       for (cnt = 0; cnt < MAXQUOTAS; cnt++)
+               if (inode->i_dquot[cnt])
+                       mark_dquot_dirty(inode->i_dquot[cnt]);
+       up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+ out:
+       return ret;
+ }
+ EXPORT_SYMBOL(dquot_claim_space);
+ /*
+  * Release reserved quota space
+  */
+ void dquot_release_reserved_space(struct inode *inode, qsize_t number)
+ {
+       int cnt;
+       if (IS_NOQUOTA(inode))
+               goto out;
+       down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+       if (IS_NOQUOTA(inode))
+               goto out_unlock;
+       spin_lock(&dq_data_lock);
+       /* Release reserved dquots */
+       for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
+               if (inode->i_dquot[cnt])
+                       dquot_free_reserved_space(inode->i_dquot[cnt], number);
+       }
+       spin_unlock(&dq_data_lock);
+ out_unlock:
+       up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+ out:
+       return;
+ }
+ EXPORT_SYMBOL(dquot_release_reserved_space);
  
  /*
   * This operation can block, but only after everything is updated
@@@ -1418,7 -1621,7 +1618,7 @@@ out_sub
        }
        spin_lock(&dq_data_lock);
        for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-               if (inode->i_dquot[cnt] == NODQUOT)
+               if (!inode->i_dquot[cnt])
                        continue;
                warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number);
                dquot_decr_space(inode->i_dquot[cnt], number);
        up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
        return QUOTA_OK;
  }
+ EXPORT_SYMBOL(dquot_free_space);
  
  /*
   * This operation can block, but only after everything is updated
@@@ -1455,7 -1659,7 +1656,7 @@@ int dquot_free_inode(const struct inod
        }
        spin_lock(&dq_data_lock);
        for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-               if (inode->i_dquot[cnt] == NODQUOT)
+               if (!inode->i_dquot[cnt])
                        continue;
                warntype[cnt] = info_idq_free(inode->i_dquot[cnt], number);
                dquot_decr_inodes(inode->i_dquot[cnt], number);
        up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
        return QUOTA_OK;
  }
+ EXPORT_SYMBOL(dquot_free_inode);
+ /*
+  * call back function, get reserved quota space from underlying fs
+  */
+ qsize_t dquot_get_reserved_space(struct inode *inode)
+ {
+       qsize_t reserved_space = 0;
+       if (sb_any_quota_active(inode->i_sb) &&
+           inode->i_sb->dq_op->get_reserved_space)
+               reserved_space = inode->i_sb->dq_op->get_reserved_space(inode);
+       return reserved_space;
+ }
  
  /*
   * Transfer the number of inode and blocks from one diskquota to an other.
   */
  int dquot_transfer(struct inode *inode, struct iattr *iattr)
  {
-       qsize_t space;
+       qsize_t space, cur_space;
+       qsize_t rsv_space = 0;
        struct dquot *transfer_from[MAXQUOTAS];
        struct dquot *transfer_to[MAXQUOTAS];
        int cnt, ret = QUOTA_OK;
                return QUOTA_OK;
        /* Initialize the arrays */
        for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-               transfer_from[cnt] = NODQUOT;
-               transfer_to[cnt] = NODQUOT;
+               transfer_from[cnt] = NULL;
+               transfer_to[cnt] = NULL;
                warntype_to[cnt] = QUOTA_NL_NOWARN;
-               switch (cnt) {
-                       case USRQUOTA:
-                               if (!chuid)
-                                       continue;
-                               transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_uid, cnt);
-                               break;
-                       case GRPQUOTA:
-                               if (!chgid)
-                                       continue;
-                               transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_gid, cnt);
-                               break;
-               }
        }
+       if (chuid)
+               transfer_to[USRQUOTA] = dqget(inode->i_sb, iattr->ia_uid,
+                                             USRQUOTA);
+       if (chgid)
+               transfer_to[GRPQUOTA] = dqget(inode->i_sb, iattr->ia_gid,
+                                             GRPQUOTA);
  
        down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
        /* Now recheck reliably when holding dqptr_sem */
                goto put_all;
        }
        spin_lock(&dq_data_lock);
-       space = inode_get_bytes(inode);
+       cur_space = inode_get_bytes(inode);
+       rsv_space = dquot_get_reserved_space(inode);
+       space = cur_space + rsv_space;
        /* Build the transfer_from list and check the limits */
        for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-               if (transfer_to[cnt] == NODQUOT)
+               if (!transfer_to[cnt])
                        continue;
                transfer_from[cnt] = inode->i_dquot[cnt];
                if (check_idq(transfer_to[cnt], 1, warntype_to + cnt) ==
                /*
                 * Skip changes for same uid or gid or for turned off quota-type.
                 */
-               if (transfer_to[cnt] == NODQUOT)
+               if (!transfer_to[cnt])
                        continue;
  
                /* Due to IO error we might not have transfer_from[] structure */
                        warntype_from_space[cnt] =
                                info_bdq_free(transfer_from[cnt], space);
                        dquot_decr_inodes(transfer_from[cnt], 1);
-                       dquot_decr_space(transfer_from[cnt], space);
+                       dquot_decr_space(transfer_from[cnt], cur_space);
+                       dquot_free_reserved_space(transfer_from[cnt],
+                                                 rsv_space);
                }
  
                dquot_incr_inodes(transfer_to[cnt], 1);
-               dquot_incr_space(transfer_to[cnt], space);
+               dquot_incr_space(transfer_to[cnt], cur_space);
+               dquot_resv_space(transfer_to[cnt], rsv_space);
  
                inode->i_dquot[cnt] = transfer_to[cnt];
        }
                if (transfer_to[cnt]) {
                        mark_dquot_dirty(transfer_to[cnt]);
                        /* The reference we got is transferred to the inode */
-                       transfer_to[cnt] = NODQUOT;
+                       transfer_to[cnt] = NULL;
                }
        }
  warn_put_all:
@@@ -1582,10 -1800,11 +1797,11 @@@ over_quota
        up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
        /* Clear dquot pointers we don't want to dqput() */
        for (cnt = 0; cnt < MAXQUOTAS; cnt++)
-               transfer_from[cnt] = NODQUOT;
+               transfer_from[cnt] = NULL;
        ret = NO_QUOTA;
        goto warn_put_all;
  }
+ EXPORT_SYMBOL(dquot_transfer);
  
  /* Wrapper for transferring ownership of an inode */
  int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
        }
        return 0;
  }
+ EXPORT_SYMBOL(vfs_dq_transfer);
  
  /*
   * Write info of quota file to disk
@@@ -1612,6 -1831,7 +1828,7 @@@ int dquot_commit_info(struct super_bloc
        mutex_unlock(&dqopt->dqio_mutex);
        return ret;
  }
+ EXPORT_SYMBOL(dquot_commit_info);
  
  /*
   * Definitions of diskquota operations.
@@@ -1697,8 -1917,8 +1914,8 @@@ int vfs_quota_disable(struct super_bloc
                drop_dquot_ref(sb, cnt);
                invalidate_dquots(sb, cnt);
                /*
-                * Now all dquots should be invalidated, all writes done so we should be only
-                * users of the info. No locks needed.
+                * Now all dquots should be invalidated, all writes done so we
+                * should be only users of the info. No locks needed.
                 */
                if (info_dirty(&dqopt->info[cnt]))
                        sb->dq_op->write_info(sb, cnt);
                        /* If quota was reenabled in the meantime, we have
                         * nothing to do */
                        if (!sb_has_quota_loaded(sb, cnt)) {
-                               mutex_lock_nested(&toputinode[cnt]->i_mutex, I_MUTEX_QUOTA);
+                               mutex_lock_nested(&toputinode[cnt]->i_mutex,
+                                                 I_MUTEX_QUOTA);
                                toputinode[cnt]->i_flags &= ~(S_IMMUTABLE |
                                  S_NOATIME | S_NOQUOTA);
-                               truncate_inode_pages(&toputinode[cnt]->i_data, 0);
+                               truncate_inode_pages(&toputinode[cnt]->i_data,
+                                                    0);
                                mutex_unlock(&toputinode[cnt]->i_mutex);
                                mark_inode_dirty(toputinode[cnt]);
                        }
@@@ -1764,13 -1986,14 +1983,14 @@@ put_inodes
                }
        return ret;
  }
+ EXPORT_SYMBOL(vfs_quota_disable);
  
  int vfs_quota_off(struct super_block *sb, int type, int remount)
  {
        return vfs_quota_disable(sb, type, remount ? DQUOT_SUSPENDED :
                                 (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED));
  }
+ EXPORT_SYMBOL(vfs_quota_off);
  /*
   *    Turn quotas on on a device
   */
@@@ -1828,7 -2051,8 +2048,8 @@@ static int vfs_load_quota_inode(struct 
                 * possible) Also nobody should write to the file - we use
                 * special IO operations which ignore the immutable bit. */
                down_write(&dqopt->dqptr_sem);
-               oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE | S_NOQUOTA);
+               oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE |
+                                            S_NOQUOTA);
                inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE;
                up_write(&dqopt->dqptr_sem);
                sb->dq_op->drop(inode);
        dqopt->info[type].dqi_fmt_id = format_id;
        INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list);
        mutex_lock(&dqopt->dqio_mutex);
-       if ((error = dqopt->ops[type]->read_file_info(sb, type)) < 0) {
+       error = dqopt->ops[type]->read_file_info(sb, type);
+       if (error < 0) {
                mutex_unlock(&dqopt->dqio_mutex);
                goto out_file_init;
        }
@@@ -1927,6 -2152,7 +2149,7 @@@ int vfs_quota_on_path(struct super_bloc
                                             DQUOT_LIMITS_ENABLED);
        return error;
  }
+ EXPORT_SYMBOL(vfs_quota_on_path);
  
  int vfs_quota_on(struct super_block *sb, int type, int format_id, char *name,
                 int remount)
        }
        return error;
  }
+ EXPORT_SYMBOL(vfs_quota_on);
  
  /*
   * More powerful function for turning on quotas allowing setting
@@@ -1990,6 -2217,7 +2214,7 @@@ out_lock
  load_quota:
        return vfs_load_quota_inode(inode, type, format_id, flags);
  }
+ EXPORT_SYMBOL(vfs_quota_enable);
  
  /*
   * This function is used when filesystem needs to initialize quotas
@@@ -2019,6 -2247,7 +2244,7 @@@ out
        dput(dentry);
        return error;
  }
+ EXPORT_SYMBOL(vfs_quota_on_mount);
  
  /* Wrapper to turn on quotas when remounting rw */
  int vfs_dq_quota_on_remount(struct super_block *sb)
        }
        return ret;
  }
+ EXPORT_SYMBOL(vfs_dq_quota_on_remount);
  
  static inline qsize_t qbtos(qsize_t blocks)
  {
@@@ -2054,7 -2284,7 +2281,7 @@@ static void do_get_dqblk(struct dquot *
        spin_lock(&dq_data_lock);
        di->dqb_bhardlimit = stoqb(dm->dqb_bhardlimit);
        di->dqb_bsoftlimit = stoqb(dm->dqb_bsoftlimit);
-       di->dqb_curspace = dm->dqb_curspace;
+       di->dqb_curspace = dm->dqb_curspace + dm->dqb_rsvspace;
        di->dqb_ihardlimit = dm->dqb_ihardlimit;
        di->dqb_isoftlimit = dm->dqb_isoftlimit;
        di->dqb_curinodes = dm->dqb_curinodes;
        spin_unlock(&dq_data_lock);
  }
  
- int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di)
+ int vfs_get_dqblk(struct super_block *sb, int type, qid_t id,
+                 struct if_dqblk *di)
  {
        struct dquot *dquot;
  
        dquot = dqget(sb, id, type);
-       if (dquot == NODQUOT)
+       if (!dquot)
                return -ESRCH;
        do_get_dqblk(dquot, di);
        dqput(dquot);
  
        return 0;
  }
+ EXPORT_SYMBOL(vfs_get_dqblk);
  
  /* Generic routine for setting common part of quota structure */
  static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
  
        spin_lock(&dq_data_lock);
        if (di->dqb_valid & QIF_SPACE) {
-               dm->dqb_curspace = di->dqb_curspace;
+               dm->dqb_curspace = di->dqb_curspace - dm->dqb_rsvspace;
                check_blim = 1;
                __set_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags);
        }
        }
  
        if (check_blim) {
-               if (!dm->dqb_bsoftlimit || dm->dqb_curspace < dm->dqb_bsoftlimit) {
+               if (!dm->dqb_bsoftlimit ||
+                   dm->dqb_curspace < dm->dqb_bsoftlimit) {
                        dm->dqb_btime = 0;
                        clear_bit(DQ_BLKS_B, &dquot->dq_flags);
-               }
-               else if (!(di->dqb_valid & QIF_BTIME))  /* Set grace only if user hasn't provided his own... */
+               } else if (!(di->dqb_valid & QIF_BTIME))
+                       /* Set grace only if user hasn't provided his own... */
                        dm->dqb_btime = get_seconds() + dqi->dqi_bgrace;
        }
        if (check_ilim) {
-               if (!dm->dqb_isoftlimit || dm->dqb_curinodes < dm->dqb_isoftlimit) {
+               if (!dm->dqb_isoftlimit ||
+                   dm->dqb_curinodes < dm->dqb_isoftlimit) {
                        dm->dqb_itime = 0;
                        clear_bit(DQ_INODES_B, &dquot->dq_flags);
-               }
-               else if (!(di->dqb_valid & QIF_ITIME))  /* Set grace only if user hasn't provided his own... */
+               } else if (!(di->dqb_valid & QIF_ITIME))
+                       /* Set grace only if user hasn't provided his own... */
                        dm->dqb_itime = get_seconds() + dqi->dqi_igrace;
        }
-       if (dm->dqb_bhardlimit || dm->dqb_bsoftlimit || dm->dqb_ihardlimit || dm->dqb_isoftlimit)
+       if (dm->dqb_bhardlimit || dm->dqb_bsoftlimit || dm->dqb_ihardlimit ||
+           dm->dqb_isoftlimit)
                clear_bit(DQ_FAKE_B, &dquot->dq_flags);
        else
                set_bit(DQ_FAKE_B, &dquot->dq_flags);
        return 0;
  }
  
- int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di)
+ int vfs_set_dqblk(struct super_block *sb, int type, qid_t id,
+                 struct if_dqblk *di)
  {
        struct dquot *dquot;
        int rc;
  out:
        return rc;
  }
+ EXPORT_SYMBOL(vfs_set_dqblk);
  
  /* Generic routine for getting common part of quota file information */
  int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
        mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
        return 0;
  }
+ EXPORT_SYMBOL(vfs_get_dqinfo);
  
  /* Generic routine for setting common part of quota file information */
  int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
        if (ii->dqi_valid & IIF_IGRACE)
                mi->dqi_igrace = ii->dqi_igrace;
        if (ii->dqi_valid & IIF_FLAGS)
-               mi->dqi_flags = (mi->dqi_flags & ~DQF_MASK) | (ii->dqi_flags & DQF_MASK);
+               mi->dqi_flags = (mi->dqi_flags & ~DQF_MASK) |
+                               (ii->dqi_flags & DQF_MASK);
        spin_unlock(&dq_data_lock);
        mark_info_dirty(sb, type);
        /* Force write to disk */
@@@ -2216,6 -2455,7 +2452,7 @@@ out
        mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
        return err;
  }
+ EXPORT_SYMBOL(vfs_set_dqinfo);
  
  struct quotactl_ops vfs_quotactl_ops = {
        .quota_on       = vfs_quota_on,
@@@ -2365,43 -2605,10 +2602,10 @@@ static int __init dquot_init(void
  
  #ifdef CONFIG_QUOTA_NETLINK_INTERFACE
        if (genl_register_family(&quota_genl_family) != 0)
-               printk(KERN_ERR "VFS: Failed to create quota netlink interface.\n");
+               printk(KERN_ERR
+                      "VFS: Failed to create quota netlink interface.\n");
  #endif
  
        return 0;
  }
  module_init(dquot_init);
- EXPORT_SYMBOL(register_quota_format);
- EXPORT_SYMBOL(unregister_quota_format);
- EXPORT_SYMBOL(dqstats);
- EXPORT_SYMBOL(dq_data_lock);
- EXPORT_SYMBOL(vfs_quota_enable);
- EXPORT_SYMBOL(vfs_quota_on);
- EXPORT_SYMBOL(vfs_quota_on_path);
- EXPORT_SYMBOL(vfs_quota_on_mount);
- EXPORT_SYMBOL(vfs_quota_disable);
- EXPORT_SYMBOL(vfs_quota_off);
- EXPORT_SYMBOL(dquot_scan_active);
- EXPORT_SYMBOL(vfs_quota_sync);
- EXPORT_SYMBOL(vfs_get_dqinfo);
- EXPORT_SYMBOL(vfs_set_dqinfo);
- EXPORT_SYMBOL(vfs_get_dqblk);
- EXPORT_SYMBOL(vfs_set_dqblk);
- EXPORT_SYMBOL(dquot_commit);
- EXPORT_SYMBOL(dquot_commit_info);
- EXPORT_SYMBOL(dquot_acquire);
- EXPORT_SYMBOL(dquot_release);
- EXPORT_SYMBOL(dquot_mark_dquot_dirty);
- EXPORT_SYMBOL(dquot_initialize);
- EXPORT_SYMBOL(dquot_drop);
- EXPORT_SYMBOL(vfs_dq_drop);
- EXPORT_SYMBOL(dqget);
- EXPORT_SYMBOL(dqput);
- EXPORT_SYMBOL(dquot_alloc_space);
- EXPORT_SYMBOL(dquot_alloc_inode);
- EXPORT_SYMBOL(dquot_free_space);
- EXPORT_SYMBOL(dquot_free_inode);
- EXPORT_SYMBOL(dquot_transfer);
- EXPORT_SYMBOL(vfs_dq_transfer);
- EXPORT_SYMBOL(vfs_dq_quota_on_remount);
diff --combined fs/super.c
index dd4acb158b5e6cee3c4b194c0934bebf994c137c,0f9d17f2c75442d21a2fbd62da3d6a4e7316425e..49d0bd32a5a7a3918c9f185bd6db21d3d1934f15
@@@ -197,7 -197,7 +197,7 @@@ void deactivate_super(struct super_bloc
        if (atomic_dec_and_lock(&s->s_active, &sb_lock)) {
                s->s_count -= S_BIAS-1;
                spin_unlock(&sb_lock);
-               DQUOT_OFF(s, 0);
+               vfs_dq_off(s, 0);
                down_write(&s->s_umount);
                fs->kill_sb(s);
                put_filesystem(fs);
@@@ -266,7 -266,7 +266,7 @@@ EXPORT_SYMBOL(unlock_super)
  void __fsync_super(struct super_block *sb)
  {
        sync_inodes_sb(sb, 0);
-       DQUOT_SYNC(sb);
+       vfs_dq_sync(sb);
        lock_super(sb);
        if (sb->s_dirt && sb->s_op->write_super)
                sb->s_op->write_super(sb);
@@@ -655,7 -655,7 +655,7 @@@ int do_remount_sb(struct super_block *s
                        mark_files_ro(sb);
                else if (!fs_may_remount_ro(sb))
                        return -EBUSY;
-               retval = DQUOT_OFF(sb, 1);
+               retval = vfs_dq_off(sb, 1);
                if (retval < 0 && retval != -ENOSYS)
                        return -EBUSY;
        }
        }
        sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK);
        if (remount_rw)
-               DQUOT_ON_REMOUNT(sb);
+               vfs_dq_quota_on_remount(sb);
        return 0;
  }
  
 -static void do_emergency_remount(unsigned long foo)
 +static void do_emergency_remount(struct work_struct *work)
  {
        struct super_block *sb;
  
                spin_lock(&sb_lock);
        }
        spin_unlock(&sb_lock);
 +      kfree(work);
        printk("Emergency Remount complete\n");
  }
  
  void emergency_remount(void)
  {
 -      pdflush_operation(do_emergency_remount, 0);
 +      struct work_struct *work;
 +
 +      work = kmalloc(sizeof(*work), GFP_ATOMIC);
 +      if (work) {
 +              INIT_WORK(work, do_emergency_remount);
 +              schedule_work(work);
 +      }
  }
  
  /*
diff --combined fs/sync.c
index ec95a69d17aa73e058bedd5c61e42d23f87a4f91,ef36bc921bf33a625391efc5a85be0e44f1b02f8..7abc65fbf21df8455400e9757751f8069cd29f28
+++ b/fs/sync.c
@@@ -25,7 -25,7 +25,7 @@@ static void do_sync(unsigned long wait
  {
        wakeup_pdflush(0);
        sync_inodes(0);         /* All mappings, inodes and their blockdevs */
-       DQUOT_SYNC(NULL);
+       vfs_dq_sync(NULL);
        sync_supers();          /* Write the superblocks */
        sync_filesystems(0);    /* Start syncing the filesystems */
        sync_filesystems(wait); /* Waitingly sync the filesystems */
@@@ -42,21 -42,9 +42,21 @@@ SYSCALL_DEFINE0(sync
        return 0;
  }
  
 +static void do_sync_work(struct work_struct *work)
 +{
 +      do_sync(0);
 +      kfree(work);
 +}
 +
  void emergency_sync(void)
  {
 -      pdflush_operation(do_sync, 0);
 +      struct work_struct *work;
 +
 +      work = kmalloc(sizeof(*work), GFP_ATOMIC);
 +      if (work) {
 +              INIT_WORK(work, do_sync_work);
 +              schedule_work(work);
 +      }
  }
  
  /*