[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-id: <1260324686-15863-1-git-send-email-dmonakhov@openvz.org>
Date: Wed, 09 Dec 2009 05:11:24 +0300
From: Dmitry Monakhov <dmonakhov@...nvz.org>
To: linux-ext4@...r.kernel.org
Cc: aneesh.kumar@...ux.vnet.ibm.com, jack@...e.cz, cmm@...ibm.com,
Dmitry Monakhov <dmonakhov@...nvz.org>,
linux-fsdevel@...r.kernel.org, Al Viro <viro@...IV.linux.org.uk>
Subject: [PATCH 1/3] [RFC] vfs: add generic reserved space management interface
Add new field "i_rsv_blocks" to generic inode. This value is
managed similar to i_blocks, i_bytes fileds (protected by i_lock).
This generic interface will be used by generic quota code similar
to i_blocks.
diff --git a/fs/inode.c b/fs/inode.c
index 4d8e3be..81eee5a 100644
Signed-off-by: Dmitry Monakhov <dmonakhov@...nvz.org>
---
fs/inode.c | 1 +
fs/stack.c | 1 +
fs/stat.c | 41 ++++++++++++++++++++++++++++++++++++++++-
include/linux/fs.h | 8 +++++++-
4 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index 4d8e3be..81eee5a 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -143,6 +143,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
inode->i_gid = 0;
atomic_set(&inode->i_writecount, 0);
inode->i_size = 0;
+ inode->i_rsv_blocks = 0;
inode->i_blocks = 0;
inode->i_bytes = 0;
inode->i_generation = 0;
diff --git a/fs/stack.c b/fs/stack.c
index 67716f6..b6c4aa7 100644
--- a/fs/stack.c
+++ b/fs/stack.c
@@ -11,6 +11,7 @@ void fsstack_copy_inode_size(struct inode *dst, const struct inode *src)
{
i_size_write(dst, i_size_read((struct inode *)src));
dst->i_blocks = src->i_blocks;
+ dst->i_rsv_blocks = src->i_rsv_blocks;
}
EXPORT_SYMBOL_GPL(fsstack_copy_inode_size);
diff --git a/fs/stat.c b/fs/stat.c
index 075694e..ea55419 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -31,7 +31,7 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
stat->mtime = inode->i_mtime;
stat->ctime = inode->i_ctime;
stat->size = i_size_read(inode);
- stat->blocks = inode->i_blocks;
+ stat->blocks = inode->i_blocks + inode->i_rsv_blocks;
stat->blksize = (1 << inode->i_blkbits);
}
@@ -452,3 +452,42 @@ void inode_set_bytes(struct inode *inode, loff_t bytes)
}
EXPORT_SYMBOL(inode_set_bytes);
+
+void inode_add_rsv_blocks(struct inode *inode, blkcnt_t blocks)
+{
+ spin_lock(&inode->i_lock);
+ inode->i_rsv_blocks += blocks;
+ spin_unlock(&inode->i_lock);
+}
+
+EXPORT_SYMBOL(inode_add_rsv_blocks);
+
+void inode_claim_rsv_blocks(struct inode *inode, blkcnt_t blocks)
+{
+ spin_lock(&inode->i_lock);
+ inode->i_rsv_blocks -= blocks;
+ inode->i_blocks += blocks;
+ spin_unlock(&inode->i_lock);
+}
+
+EXPORT_SYMBOL(inode_claim_rsv_blocks);
+
+void inode_sub_rsv_blocks(struct inode *inode, blkcnt_t blocks)
+{
+ spin_lock(&inode->i_lock);
+ inode->i_rsv_blocks -= blocks;
+ spin_unlock(&inode->i_lock);
+}
+
+EXPORT_SYMBOL(inode_sub_rsv_blocks);
+
+blkcnt_t inode_get_rsv_blocks(struct inode *inode)
+{
+ blkcnt_t ret;
+ spin_lock(&inode->i_lock);
+ ret = inode->i_rsv_blocks;
+ spin_unlock(&inode->i_lock);
+ return ret;
+}
+
+EXPORT_SYMBOL(inode_get_rsv_blocks);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 2620a8c..af19bdb 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -736,10 +736,12 @@ struct inode {
struct timespec i_mtime;
struct timespec i_ctime;
blkcnt_t i_blocks;
+ blkcnt_t i_rsv_blocks;
unsigned int i_blkbits;
unsigned short i_bytes;
umode_t i_mode;
- spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
+ spinlock_t i_lock; /* i_blocks, i_bytes, i_rsv_blocks
+ maybe i_size */
struct mutex i_mutex;
struct rw_semaphore i_alloc_sem;
const struct inode_operations *i_op;
@@ -2318,6 +2320,10 @@ void inode_add_bytes(struct inode *inode, loff_t bytes);
void inode_sub_bytes(struct inode *inode, loff_t bytes);
loff_t inode_get_bytes(struct inode *inode);
void inode_set_bytes(struct inode *inode, loff_t bytes);
+void inode_add_rsv_blocks(struct inode *inode, blkcnt_t blocks);
+void inode_claim_rsv_blocks(struct inode *inode, blkcnt_t blocks);
+void inode_sub_rsv_blocks(struct inode *inode, blkcnt_t blocks);
+blkcnt_t inode_get_rsv_blocks(struct inode *inode);
extern int vfs_readdir(struct file *, filldir_t, void *);
--
1.6.0.4
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists