patch-2.4.11-dontuse linux/include/linux/quotaops.h

Next file: linux/include/linux/reiserfs_fs.h
Previous file: linux/include/linux/quota.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.10/linux/include/linux/quotaops.h linux/include/linux/quotaops.h
@@ -11,10 +11,11 @@
 #define _LINUX_QUOTAOPS_
 
 #include <linux/config.h>
+#include <linux/smp_lock.h>
 
 #if defined(CONFIG_QUOTA)
 
-#include <linux/smp_lock.h>
+#include <linux/fs.h>
 
 /*
  * declaration of quota_function calls in kernel.
@@ -24,85 +25,138 @@
 extern int  quota_off(struct super_block *sb, short type);
 extern int  sync_dquots(kdev_t dev, short type);
 
-extern int  dquot_alloc_block(const struct inode *inode, unsigned long number, char prealloc);
+extern int  dquot_alloc_block(struct inode *inode, unsigned long number, char prealloc);
 extern int  dquot_alloc_inode(const struct inode *inode, unsigned long number);
 
-extern void dquot_free_block(const struct inode *inode, unsigned long number);
+extern void dquot_free_block(struct inode *inode, unsigned long number);
 extern void dquot_free_inode(const struct inode *inode, unsigned long number);
 
-extern int  dquot_transfer(struct dentry *dentry, struct iattr *iattr);
+extern int  dquot_transfer(struct inode *inode, struct iattr *iattr);
 
 /*
  * Operations supported for diskquotas.
  */
+#define sb_any_quota_enabled(sb) ((sb)->s_dquot.flags & (DQUOT_USR_ENABLED | DQUOT_GRP_ENABLED))
+
 static __inline__ void DQUOT_INIT(struct inode *inode)
 {
-	if (!IS_NOQUOTA(inode)) {
-		if (inode->i_sb && inode->i_sb->dq_op)
-			inode->i_sb->dq_op->initialize(inode, -1);
-	}
+	if (!inode->i_sb)
+		BUG();
+	lock_kernel();
+	if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
+		inode->i_sb->dq_op->initialize(inode, -1);
+	unlock_kernel();
 }
 
 static __inline__ void DQUOT_DROP(struct inode *inode)
 {
+	lock_kernel();
 	if (IS_QUOTAINIT(inode)) {
-		if (inode->i_sb && inode->i_sb->dq_op)
-			inode->i_sb->dq_op->drop(inode);
+		if (!inode->i_sb)
+			BUG();
+		inode->i_sb->dq_op->drop(inode);	/* Ops must be set when there's any quota... */
 	}
+	unlock_kernel();
 }
 
-static __inline__ int DQUOT_PREALLOC_BLOCK(struct super_block *sb, const struct inode *inode, int nr)
+static __inline__ int DQUOT_PREALLOC_BLOCK_NODIRTY(struct inode *inode, int nr)
 {
-	if (sb->dq_op) {
-		if (sb->dq_op->alloc_block(inode, fs_to_dq_blocks(nr, sb->s_blocksize), 1) == NO_QUOTA)
+	lock_kernel();
+	if (sb_any_quota_enabled(inode->i_sb)) {
+		/* Number of used blocks is updated in alloc_block() */
+		if (inode->i_sb->dq_op->alloc_block(inode, fs_to_dq_blocks(nr, inode->i_sb->s_blocksize), 1) == NO_QUOTA) {
+			unlock_kernel();
 			return 1;
+		}
 	}
+	else
+		inode->i_blocks += nr << (inode->i_sb->s_blocksize_bits - 9);
+	unlock_kernel();
 	return 0;
 }
 
-static __inline__ int DQUOT_ALLOC_BLOCK(struct super_block *sb, const struct inode *inode, int nr)
+static __inline__ int DQUOT_PREALLOC_BLOCK(struct inode *inode, int nr)
 {
-	if (sb->dq_op) {
-		if (sb->dq_op->alloc_block(inode, fs_to_dq_blocks(nr, sb->s_blocksize), 0) == NO_QUOTA)
+	int ret;
+        if (!(ret =  DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr)))
+		mark_inode_dirty(inode);
+	return ret;
+}
+
+static __inline__ int DQUOT_ALLOC_BLOCK_NODIRTY(struct inode *inode, int nr)
+{
+	lock_kernel();
+	if (sb_any_quota_enabled(inode->i_sb)) {
+		/* Number of used blocks is updated in alloc_block() */
+		if (inode->i_sb->dq_op->alloc_block(inode, fs_to_dq_blocks(nr, inode->i_sb->s_blocksize), 0) == NO_QUOTA) {
+			unlock_kernel();
 			return 1;
+		}
 	}
+	else
+		inode->i_blocks += nr << (inode->i_sb->s_blocksize_bits - 9);
+	unlock_kernel();
 	return 0;
 }
 
-static __inline__ int DQUOT_ALLOC_INODE(struct super_block *sb, struct inode *inode)
+static __inline__ int DQUOT_ALLOC_BLOCK(struct inode *inode, int nr)
+{
+	int ret;
+	if (!(ret = DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr)))
+		mark_inode_dirty(inode);
+	return ret;
+}
+
+static __inline__ int DQUOT_ALLOC_INODE(struct inode *inode)
 {
-	if (sb->dq_op) {
+	lock_kernel();
+	if (sb_any_quota_enabled(inode->i_sb)) {
 		DQUOT_INIT(inode);
-		if (sb->dq_op->alloc_inode (inode, 1))
+		if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
+			unlock_kernel();
 			return 1;
+		}
 	}
-	inode->i_flags |= S_QUOTA;
+	unlock_kernel();
 	return 0;
 }
 
-static __inline__ void DQUOT_FREE_BLOCK(struct super_block *sb, const struct inode *inode, int nr)
+static __inline__ void DQUOT_FREE_BLOCK_NODIRTY(struct inode *inode, int nr)
 {
-	if (sb->dq_op)
-		sb->dq_op->free_block(inode, fs_to_dq_blocks(nr, sb->s_blocksize));
+	lock_kernel();
+	if (sb_any_quota_enabled(inode->i_sb))
+		inode->i_sb->dq_op->free_block(inode, fs_to_dq_blocks(nr, inode->i_sb->s_blocksize));
+	else
+		inode->i_blocks -= nr << (inode->i_sb->s_blocksize_bits - 9);
+	unlock_kernel();
 }
 
-static __inline__ void DQUOT_FREE_INODE(struct super_block *sb, struct inode *inode)
+static __inline__ void DQUOT_FREE_BLOCK(struct inode *inode, int nr)
 {
-	if (sb->dq_op)
-		sb->dq_op->free_inode(inode, 1);
+	DQUOT_FREE_BLOCK_NODIRTY(inode, nr);
+	mark_inode_dirty(inode);
 }
 
-static __inline__ int DQUOT_TRANSFER(struct dentry *dentry, struct iattr *iattr)
+static __inline__ void DQUOT_FREE_INODE(struct inode *inode)
 {
-	int error = -EDQUOT;
+	lock_kernel();
+	if (sb_any_quota_enabled(inode->i_sb))
+		inode->i_sb->dq_op->free_inode(inode, 1);
+	unlock_kernel();
+}
 
-	if (dentry->d_inode->i_sb->dq_op && !IS_NOQUOTA(dentry->d_inode)) {
-		DQUOT_INIT(dentry->d_inode);
-		error = dentry->d_inode->i_sb->dq_op->transfer(dentry, iattr);
-	} else {
-		error = notify_change(dentry, iattr);
+static __inline__ int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
+{
+	lock_kernel();
+	if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
+		DQUOT_INIT(inode);
+		if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA) {
+			unlock_kernel();
+			return 1;
+		}
 	}
-	return error;
+	unlock_kernel();
+	return 0;
 }
 
 #define DQUOT_SYNC(dev)	sync_dquots(dev, -1)
@@ -115,18 +169,53 @@
  */
 #define DQUOT_INIT(inode)			do { } while(0)
 #define DQUOT_DROP(inode)			do { } while(0)
-#define DQUOT_PREALLOC_BLOCK(sb, inode, nr)	(0)
-#define DQUOT_ALLOC_BLOCK(sb, inode, nr)	(0)
-#define DQUOT_ALLOC_INODE(sb, inode)		(0)
-#define DQUOT_FREE_BLOCK(sb, inode, nr)		do { } while(0)
-#define DQUOT_FREE_INODE(sb, inode)		do { } while(0)
+#define DQUOT_ALLOC_INODE(inode)		(0)
+#define DQUOT_FREE_INODE(inode)			do { } while(0)
 #define DQUOT_SYNC(dev)				do { } while(0)
 #define DQUOT_OFF(sb)				do { } while(0)
+#define DQUOT_TRANSFER(inode, iattr)		(0)
+extern __inline__ int DQUOT_PREALLOC_BLOCK_NODIRTY(struct inode *inode, int nr)
+{
+	lock_kernel();
+	inode->i_blocks += nr << (inode->i_sb->s_blocksize_bits - 9);
+	unlock_kernel();
+	return 0;
+}
 
-/*
- * Special case expands to a simple notify_change.
- */
-#define DQUOT_TRANSFER(dentry, iattr) notify_change(dentry, iattr)
+extern __inline__ int DQUOT_PREALLOC_BLOCK(struct inode *inode, int nr)
+{
+	DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr);
+	mark_inode_dirty(inode);
+	return 0;
+}
+
+extern __inline__ int DQUOT_ALLOC_BLOCK_NODIRTY(struct inode *inode, int nr)
+{
+	lock_kernel();
+	inode->i_blocks += nr << (inode->i_sb->s_blocksize_bits - 9);
+	unlock_kernel();
+	return 0;
+}
+
+extern __inline__ int DQUOT_ALLOC_BLOCK(struct inode *inode, int nr)
+{
+	DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr);
+	mark_inode_dirty(inode);
+	return 0;
+}
+
+extern __inline__ void DQUOT_FREE_BLOCK_NODIRTY(struct inode *inode, int nr)
+{
+	lock_kernel();
+	inode->i_blocks -= nr << (inode->i_sb->s_blocksize_bits - 9);
+	unlock_kernel();
+}
+
+extern __inline__ void DQUOT_FREE_BLOCK(struct inode *inode, int nr)
+{
+	DQUOT_FREE_BLOCK_NODIRTY(inode, nr);
+	mark_inode_dirty(inode);
+}	
 
 #endif /* CONFIG_QUOTA */
 #endif /* _LINUX_QUOTAOPS_ */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)