Skip to contentSkip to conversation

Quota support for ocfs2-tools

PATCH New Jan Kara 3 participants 32 messages Jul 27, 2009 – Jul 30, 2009 OCFS2

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

cover Quota support for ocfs2-tools

Hi,

I'm sending a series of patches implementing quota support into ocfs2-tools.
It's the same as the original huge patch I've sent but now it's split as Joel asked. I've also realized that when disabling SPARSE feature, we should update quota information. That piece of code is missing, I'll implement it soon.
Comments welcome.

Honza

author
#1 lore raw

PATCH 1/8 Update ocfs2_fs.h to contain all necessary quota structures and constants

---
 include/ocfs2-kernel/ocfs2_fs.h |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
include/ocfs2-kernel/ocfs2_fs.h +26 -0
index 2140bb3..ad655dc 100644
@@ -344,6 +344,8 @@ enum {
 #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
 	HEARTBEAT_SYSTEM_INODE,
 	GLOBAL_BITMAP_SYSTEM_INODE,
+	USER_QUOTA_SYSTEM_INODE,
+	GROUP_QUOTA_SYSTEM_INODE,
 #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE
 	ORPHAN_DIR_SYSTEM_INODE,
 	EXTENT_ALLOC_SYSTEM_INODE,
@@ -351,6 +353,8 @@ enum {
 	JOURNAL_SYSTEM_INODE,
 	LOCAL_ALLOC_SYSTEM_INODE,
 	TRUNCATE_LOG_SYSTEM_INODE,
+	LOCAL_USER_QUOTA_SYSTEM_INODE,
+	LOCAL_GROUP_QUOTA_SYSTEM_INODE,
 	NUM_SYSTEM_INODES
 };
 
@@ -364,6 +368,8 @@ static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
 	[SLOT_MAP_SYSTEM_INODE]			= { "slot_map", 0, S_IFREG | 0644 },
 	[HEARTBEAT_SYSTEM_INODE]		= { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
 	[GLOBAL_BITMAP_SYSTEM_INODE]		= { "global_bitmap", 0, S_IFREG | 0644 },
+	[USER_QUOTA_SYSTEM_INODE]		= { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
+	[GROUP_QUOTA_SYSTEM_INODE]		= { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
 
 	/* Slot-specific system inodes (one copy per slot) */
 	[ORPHAN_DIR_SYSTEM_INODE]		= { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
@@ -372,6 +378,8 @@ static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
 	[JOURNAL_SYSTEM_INODE]			= { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
 	[LOCAL_ALLOC_SYSTEM_INODE]		= { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
 	[TRUNCATE_LOG_SYSTEM_INODE]		= { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
+	[LOCAL_USER_QUOTA_SYSTEM_INODE]		= { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
+	[LOCAL_GROUP_QUOTA_SYSTEM_INODE]	= { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
 };
 
 /* Parameter passed from mount.ocfs2 to module */
@@ -963,6 +971,7 @@ struct ocfs2_disk_dqheader {
 };
 
 #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
+#define OCFS2_GLOBAL_TREE_BLK 1
 
 /* Information header of global quota file (immediately follows the generic
  * header) */
@@ -977,6 +986,16 @@ struct ocfs2_global_disk_dqinfo {
 				 * file */
 };
 
+/* Header of leaf tree block */
+struct ocfs2_global_disk_dqdbheader {
+	__le32 dqdh_next_free;	/* Number of next block with free entry */
+	__le32 dqdh_prev_free;	/* Number of previous block with free entry */
+	__le16 dqdh_entries;	/* Number of valid entries in block */
+	__le16 dqdh_pad1;
+	__le32 dqdh_pad2;
+};
+
+
 /* Structure with global user / group information. We reserve some space
  * for future use. */
 struct ocfs2_global_disk_dqblk {
@@ -1187,6 +1206,13 @@ static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
 	return size / sizeof(struct ocfs2_extent_rec);
 }
 #else
+static inline int ocfs2_global_dqstr_in_blk(int blocksize)
+{
+	return (blocksize - OCFS2_QBLK_RESERVED_SPACE -
+		sizeof(struct ocfs2_global_disk_dqdbheader)) /
+		sizeof(struct ocfs2_global_disk_dqblk);
+}
+
 static inline int ocfs2_fast_symlink_chars(int blocksize)
 {
 	return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 1/8 Update ocfs2_fs.h to contain all necessary quota structures and constants

include/ocfs2-kernel/ocfs2_fs.h enum { · line 349

Quoted 11 lines · Jan Kara
include/ocfs2-kernel/ocfs2_fs.h +2 -0
index 2140bb3..ad655dc 100644
@@ -344,6 +344,8 @@ enum {
 #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
 	HEARTBEAT_SYSTEM_INODE,
 	GLOBAL_BITMAP_SYSTEM_INODE,
+	USER_QUOTA_SYSTEM_INODE,
+	GROUP_QUOTA_SYSTEM_INODE,
 #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE

You need to redefine OCFS2_LAST_GLOBAL_SYSTEM_INODE like it is
in the kernel.

include/ocfs2-kernel/ocfs2_fs.h struct ocfs2_disk_dqheader { · line 974

Quoted 2 lines
include/ocfs2-kernel/ocfs2_fs.h +1 -0
 #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
+#define OCFS2_GLOBAL_TREE_BLK 1

I don't see GLOBAL_TREE_BLK in the kernel.

Quoted 4 lines
include/ocfs2-kernel/ocfs2_fs.h +0 -0
 /* Information header of global quota file (immediately follows the generic
  * header) */
@@ -977,6 +986,16 @@ struct ocfs2_global_disk_dqinfo {
 				 * file */

include/ocfs2-kernel/ocfs2_fs.h struct ocfs2_global_disk_dqinfo { · line 996

Quoted 10 lines
include/ocfs2-kernel/ocfs2_fs.h +8 -0
 };
 
+/* Header of leaf tree block */
+struct ocfs2_global_disk_dqdbheader {
+	__le32 dqdh_next_free;	/* Number of next block with free entry */
+	__le32 dqdh_prev_free;	/* Number of previous block with free entry */
+	__le16 dqdh_entries;	/* Number of valid entries in block */
+	__le16 dqdh_pad1;
+	__le32 dqdh_pad2;
+};

Nor do I see ocfs2_global_disk_dqdbheader.

include/ocfs2-kernel/ocfs2_fs.h static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb) · line 1215

Quoted 7 lines
include/ocfs2-kernel/ocfs2_fs.h +7 -0
+static inline int ocfs2_global_dqstr_in_blk(int blocksize)
+{
+	return (blocksize - OCFS2_QBLK_RESERVED_SPACE -
+		sizeof(struct ocfs2_global_disk_dqdbheader)) /
+		sizeof(struct ocfs2_global_disk_dqblk);
+}
+

Nor ocfs2_global_dqstr_in_blk.

Joel

Signature · 8 lines
"Not being known doesn't stop the truth from being true."
        - Richard Bach

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
author
#3 lore raw

PATCH 1/8 Update ocfs2_fs.h to contain all necessary quota structures and constants

Quoted 15 lines · Joel Becker

include/ocfs2-kernel/ocfs2_fs.h enum { · line 349

Quoted 11 lines · Jan Kara
include/ocfs2-kernel/ocfs2_fs.h +2 -0
index 2140bb3..ad655dc 100644
@@ -344,6 +344,8 @@ enum {
 #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
 	HEARTBEAT_SYSTEM_INODE,
 	GLOBAL_BITMAP_SYSTEM_INODE,
+	USER_QUOTA_SYSTEM_INODE,
+	GROUP_QUOTA_SYSTEM_INODE,
 #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE

You need to redefine OCFS2_LAST_GLOBAL_SYSTEM_INODE like it is
in the kernel.

Ah, right. Will fix.

Quoted 4 lines

include/ocfs2-kernel/ocfs2_fs.h struct ocfs2_disk_dqheader { · line 974

Quoted 2 lines
include/ocfs2-kernel/ocfs2_fs.h +1 -0
 #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
+#define OCFS2_GLOBAL_TREE_BLK 1

I don't see GLOBAL_TREE_BLK in the kernel.

They are in the generic quota header fs/quota/quota_tree.h defining quota
file format. For global quota files we use generic quota code which also defines some parts of the disk format...

Quoted 17 lines
Quoted 4 lines
include/ocfs2-kernel/ocfs2_fs.h +0 -0
 /* Information header of global quota file (immediately follows the generic
  * header) */
@@ -977,6 +986,16 @@ struct ocfs2_global_disk_dqinfo {
 				 * file */

include/ocfs2-kernel/ocfs2_fs.h struct ocfs2_global_disk_dqinfo { · line 996

Quoted 10 lines
include/ocfs2-kernel/ocfs2_fs.h +8 -0
 };
 
+/* Header of leaf tree block */
+struct ocfs2_global_disk_dqdbheader {
+	__le32 dqdh_next_free;	/* Number of next block with free entry */
+	__le32 dqdh_prev_free;	/* Number of previous block with free entry */
+	__le16 dqdh_entries;	/* Number of valid entries in block */
+	__le16 dqdh_pad1;
+	__le32 dqdh_pad2;
+};

Nor do I see ocfs2_global_disk_dqdbheader.

Quoted 9 lines

include/ocfs2-kernel/ocfs2_fs.h static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb) · line 1215

Quoted 7 lines
include/ocfs2-kernel/ocfs2_fs.h +7 -0
+static inline int ocfs2_global_dqstr_in_blk(int blocksize)
+{
+	return (blocksize - OCFS2_QBLK_RESERVED_SPACE -
+		sizeof(struct ocfs2_global_disk_dqdbheader)) /
+		sizeof(struct ocfs2_global_disk_dqblk);
+}
+

Nor ocfs2_global_dqstr_in_blk.

These are the same cases. I can split them into a separate header file if
you like it better. But from the tools point of view, I felt that keeping all disk-format related things in one header makes sence.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#4 lore raw

PATCH 1/8 Update ocfs2_fs.h to contain all necessary quota structures and constants

Quoted 7 lines · Jan Kara
Quoted 4 lines
Quoted 2 lines

#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
+#define OCFS2_GLOBAL_TREE_BLK 1

I don't see GLOBAL_TREE_BLK in the kernel.

They are in the generic quota header fs/quota/quota_tree.h defining quota
file format. For global quota files we use generic quota code which also defines some parts of the disk format...

<snip>

Quoted 3 lines

These are the same cases. I can split them into a separate header file if
you like it better. But from the tools point of view, I felt that keeping all disk-format related things in one header makes sence.

ocfs2_fs.h is a shared header, though. It needs to have the
same contents in the tools and in the kernel (at any point where the feature set is identical, of course). Why can't you just put the quota_tree.h and quotaio_v2.h headers in include/ocfs2-kernel? This not only signifies that they aren't ocfs2-specific structures, it allows them to follow the kernel headers in an easier fashion. We do the same thing with ocfs1_fs_compat.h, which defines the ocfs header we deliberately break in ocfs2.

Joel

Signature · 9 lines
"When choosing between two evils, I always like to try the one
 I've never tried before."
        - Mae West

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
author
#5 lore raw

PATCH 1/8 Update ocfs2_fs.h to contain all necessary quota structures and constants

Quoted 15 lines · Joel Becker
Quoted 7 lines · Jan Kara
Quoted 4 lines
Quoted 2 lines

#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
+#define OCFS2_GLOBAL_TREE_BLK 1

I don't see GLOBAL_TREE_BLK in the kernel.

They are in the generic quota header fs/quota/quota_tree.h defining quota
file format. For global quota files we use generic quota code which also defines some parts of the disk format...

<snip>

Quoted 3 lines

These are the same cases. I can split them into a separate header file if
you like it better. But from the tools point of view, I felt that keeping all disk-format related things in one header makes sence.

Quoted 8 lines

ocfs2_fs.h is a shared header, though. It needs to have the
same contents in the tools and in the kernel (at any point where the feature set is identical, of course). Why can't you just put the quota_tree.h and quotaio_v2.h headers in include/ocfs2-kernel? This not only signifies that they aren't ocfs2-specific structures, it allows them to follow the kernel headers in an easier fashion. We do the same thing with ocfs1_fs_compat.h, which defines the ocfs header we deliberately break in ocfs2.

Ok. I'll create quota_tree.h and put there those defines with the same
names as they have in the kernel.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#6 lore raw

PATCH 2/8 Provide ocfs2_cached_inode_extend_allocation()

In reply to Jan Kara

So far we had only ocfs2_extend_allocation() which read the inode from disk. Provide also the cached variant.

---
 include/ocfs2/ocfs2.h  |    2 +
 libocfs2/extend_file.c |   51 ++++++++++++++++++++++++++---------------------
 2 files changed, 30 insertions(+), 23 deletions(-)
include/ocfs2/ocfs2.h +2 -0
index 4dbbf43..ac16823 100644
@@ -505,6 +505,8 @@ errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno);
  */
 errcode_t ocfs2_extend_allocation(ocfs2_filesys *fs, uint64_t ino,
 				  uint32_t new_clusters);
+/* Ditto for cached inode */
+errcode_t ocfs2_cached_inode_extend_allocation(ocfs2_cached_inode *ci, uint32_t new_clusters);
 /* Extend the file to the new size. No clusters will be allocated. */
 errcode_t ocfs2_extend_file(ocfs2_filesys *fs, uint64_t ino, uint64_t new_size);
 
libocfs2/extend_file.c +28 -23

80 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#7 lore raw

PATCH 2/8 Provide ocfs2_cached_inode_extend_allocation()

Quoted 14 lines · Jan Kara

So far we had only ocfs2_extend_allocation() which read the inode from disk. Provide also the cached variant.

---
 include/ocfs2/ocfs2.h  |    2 +
 libocfs2/extend_file.c |   51 ++++++++++++++++++++++++++---------------------
 2 files changed, 30 insertions(+), 23 deletions(-)
include/ocfs2/ocfs2.h +0 -0
index 4dbbf43..ac16823 100644

include/ocfs2/ocfs2.h errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno); · line 509

Quoted 5 lines
include/ocfs2/ocfs2.h +2 -0
@@ -505,6 +505,8 @@ errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno);
  */
 errcode_t ocfs2_extend_allocation(ocfs2_filesys *fs, uint64_t ino,
 				  uint32_t new_clusters);
+/* Ditto for cached inode */
+errcode_t ocfs2_cached_inode_extend_allocation(ocfs2_cached_inode *ci, uint32_t new_clusters);

Break the long line, but otherwise this patch looks good. I'm
assuming you want to work on cached inodes later.

Joel

Signature · 9 lines
Life's Little Instruction Book #313

	"Never underestimate the power of love."

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
author
#8 lore raw

PATCH 2/8 Provide ocfs2_cached_inode_extend_allocation()

Quoted 10 lines · Joel Becker
Quoted 9 lines · Jan Kara

So far we had only ocfs2_extend_allocation() which read the inode from disk. Provide also the cached variant.

---
 include/ocfs2/ocfs2.h  |    2 +
 libocfs2/extend_file.c |   51 ++++++++++++++++++++++++++---------------------
 2 files changed, 30 insertions(+), 23 deletions(-)
Quoted 12 lines

include/ocfs2/ocfs2.h errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno); · line 509

Quoted 10 lines
include/ocfs2/ocfs2.h +2 -0
index 4dbbf43..ac16823 100644
@@ -505,6 +505,8 @@ errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno);
  */
 errcode_t ocfs2_extend_allocation(ocfs2_filesys *fs, uint64_t ino,
 				  uint32_t new_clusters);
+/* Ditto for cached inode */
+errcode_t ocfs2_cached_inode_extend_allocation(ocfs2_cached_inode *ci, uint32_t new_clusters);

Break the long line, but otherwise this patch looks good. I'm

Fixed.

Quoted 1 line

assuming you want to work on cached inodes later.

Yes.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#9 lore raw

PATCH 3/8 Implement quota functions to libocfs2

In reply to Jan Kara
---
 include/ocfs2/ocfs2.h     |   80 +++
 libocfs2/Makefile         |    1 +
 libocfs2/feature_string.c |   18 +
 libocfs2/ocfs2_err.et     |    6 +
 libocfs2/quota.c          | 1208 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1313 insertions(+), 0 deletions(-)
 create mode 100644 libocfs2/quota.c
include/ocfs2/ocfs2.h +80 -0
index ac16823..7f136ca 100644
@@ -125,16 +125,36 @@
 #define OCFS2_CHB_WAITING	2
 #define OCFS2_CHB_COMPLETE	3
 
+/* Flags for global quotafile info */
+#define OCFS2_QF_INFO_DIRTY 1
+
 typedef void (*ocfs2_chb_notify)(int state, char *progress, void *data);
 
 typedef struct _ocfs2_filesys ocfs2_filesys;
 typedef struct _ocfs2_cached_inode ocfs2_cached_inode;
+typedef struct _ocfs2_cached_dquot ocfs2_cached_dquot;
 typedef struct _io_channel io_channel;
 typedef struct _ocfs2_inode_scan ocfs2_inode_scan;
 typedef struct _ocfs2_dir_scan ocfs2_dir_scan;
 typedef struct _ocfs2_bitmap ocfs2_bitmap;
 typedef struct _ocfs2_devices ocfs2_devices;
 
+#define MAXQUOTAS 2
+#define USRQUOTA 0
+#define GRPQUOTA 1
+
+#define OCFS2_DEF_BLOCK_GRACE 604800 /* 1 week */
+#define OCFS2_DEF_INODE_GRACE 604800 /* 1 week */
+#define OCFS2_DEF_QUOTA_SYNC 10000   /* 10 seconds */
+
+struct _ocfs2_quota_info {
+	ocfs2_cached_inode *qi_inode;
+	int flags;
+	struct ocfs2_global_disk_dqinfo qi_info;
+};
+
+typedef struct _ocfs2_quota_info ocfs2_quota_info;
+
 struct _ocfs2_filesys {
 	char *fs_devname;
 	uint32_t fs_flags;
@@ -161,6 +181,8 @@ struct _ocfs2_filesys {
 	struct o2dlm_ctxt *fs_dlm_ctxt;
 	struct ocfs2_image_state *ost;
 
+	ocfs2_quota_info qinfo[MAXQUOTAS];
+
 	/* Reserved for the use of the calling application. */
 	void *fs_private;
 };
@@ -172,6 +194,15 @@ struct _ocfs2_cached_inode {
 	ocfs2_bitmap *ci_chains;
 };
 
+typedef unsigned int qid_t;
+
+struct _ocfs2_cached_dquot {
+	loff_t d_off;	/* Offset of structure in the file */
+	struct _ocfs2_cached_dquot *d_next;	/* Next entry in hashchain */
+	struct _ocfs2_cached_dquot **d_pprev;	/* Previous pointer in hashchain */
+	struct ocfs2_global_disk_dqblk d_ddquot;	/* Quota entry */
+};
+
 struct ocfs2_slot_data {
 	int		sd_valid;
 	unsigned int	sd_node_num;
@@ -205,6 +236,14 @@ struct _ocfs2_fs_options {
 	uint32_t opt_ro_compat;
 };
 
+struct _ocfs2_quota_hash {
+	int alloc_entries;
+	int used_entries;
+	ocfs2_cached_dquot **hash;
+};
+
+typedef struct _ocfs2_quota_hash ocfs2_quota_hash;
+
 errcode_t ocfs2_malloc(unsigned long size, void *ptr);
 errcode_t ocfs2_malloc0(unsigned long size, void *ptr);
 errcode_t ocfs2_free(void *ptr);
@@ -580,6 +619,47 @@ errcode_t ocfs2_meta_lock(ocfs2_filesys *fs, ocfs2_cached_inode *inode,
 
 errcode_t ocfs2_meta_unlock(ocfs2_filesys *fs, ocfs2_cached_inode *ci);
 
+/* Quota operations */
+void ocfs2_swap_quota_header(struct ocfs2_disk_dqheader *header);
+void ocfs2_swap_quota_local_info(struct ocfs2_local_disk_dqinfo *info);
+void ocfs2_swap_quota_chunk_header(struct ocfs2_local_disk_chunk *chunk);
+void ocfs2_swap_quota_global_info(struct ocfs2_global_disk_dqinfo *info);
+void ocfs2_swap_quota_global_dqblk(struct ocfs2_global_disk_dqblk *dqblk);
+void ocfs2_swap_quota_leaf_block_header(struct ocfs2_global_disk_dqdbheader *bheader);
+errcode_t ocfs2_init_local_quota_file(ocfs2_filesys *fs, int type,
+				      uint64_t blkno);
+errcode_t ocfs2_init_local_quota_files(ocfs2_filesys *fs, int type);
+int ocfs2_qtree_depth(int blocksize);
+int ocfs2_qtree_entry_unused(struct ocfs2_global_disk_dqblk *ddquot);
+errcode_t ocfs2_init_global_quota_file(ocfs2_filesys *fs, int type);
+errcode_t ocfs2_init_fs_quota_info(ocfs2_filesys *fs, int type);
+errcode_t ocfs2_read_global_quota_info(ocfs2_filesys *fs, int type);
+errcode_t ocfs2_write_global_quota_info(ocfs2_filesys *fs, int type);
+errcode_t ocfs2_write_dquot(ocfs2_filesys *fs, int type,
+			    ocfs2_cached_dquot *dquot);
+errcode_t ocfs2_delete_dquot(ocfs2_filesys *fs, int type,
+			     ocfs2_cached_dquot *dquot);
+errcode_t ocfs2_read_dquot(ocfs2_filesys *fs, int type, qid_t id,
+			   ocfs2_cached_dquot **ret_dquot);
+errcode_t ocfs2_new_quota_hash(ocfs2_quota_hash **hashp);
+errcode_t ocfs2_free_quota_hash(ocfs2_quota_hash *hash);
+errcode_t ocfs2_insert_quota_hash(ocfs2_quota_hash *hash,
+				  ocfs2_cached_dquot *dquot);
+errcode_t ocfs2_remove_quota_hash(ocfs2_quota_hash *hash,
+				  ocfs2_cached_dquot *dquot);
+errcode_t ocfs2_find_quota_hash(ocfs2_quota_hash *hash, qid_t id,
+				ocfs2_cached_dquot **dquotp);
+errcode_t ocfs2_find_create_quota_hash(ocfs2_quota_hash *hash, qid_t id,
+				       ocfs2_cached_dquot **dquotp);
+errcode_t ocfs2_compute_quota_usage(ocfs2_filesys *fs,
+				    ocfs2_quota_hash *usr_hash,
+				    ocfs2_quota_hash *grp_hash);
+errcode_t ocfs2_iterate_quota_hash(ocfs2_quota_hash *hash,
+				   errcode_t (*f)(ocfs2_cached_dquot *, void *),
+				   void *data);
+errcode_t ocfs2_write_release_dquots(ocfs2_filesys *fs, int type,
+				     ocfs2_quota_hash *hash);
+
 /* Low level */
 void ocfs2_swap_slot_map(struct ocfs2_slot_map *sm, int num_slots);
 void ocfs2_swap_slot_map_extended(struct ocfs2_slot_map_extended *se,
libocfs2/Makefile +1 -0
index 48cfe80..eeb854a 100644
@@ -73,6 +73,7 @@ CFILES = 		\
 	lockid.c	\
 	backup_super.c	\
 	feature_string.c\
+	quota.c		\
 	image.c		\
 	xattr.c
 
libocfs2/feature_string.c +18 -0
index 17e2675..18ae6e9 100644
@@ -123,6 +123,16 @@ static struct fs_feature_flags ocfs2_supported_features[] = {
 		{0, OCFS2_FEATURE_INCOMPAT_XATTR, 0},
 	},
 	{
+		"usrquota",
+		{0, 0, OCFS2_FEATURE_RO_COMPAT_USRQUOTA},
+		{0, 0, OCFS2_FEATURE_RO_COMPAT_USRQUOTA},
+	},
+	{
+		"grpquota",
+		{0, 0, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA},
+		{0, 0, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA},
+	},
+	{
 		NULL,
 		{0, 0, 0},
 		{0, 0, 0}
@@ -190,6 +200,14 @@ static struct feature_name ocfs2_feature_names[] = {
 		.fn_flag = {0, OCFS2_FEATURE_INCOMPAT_XATTR, 0},
 	},
 	{
+		.fn_name = "usrquota",
+		.fn_flag = {0, 0, OCFS2_FEATURE_RO_COMPAT_USRQUOTA},
+	},
+	{
+		.fn_name = "grpquota",
+		.fn_flag = {0, 0, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA},
+	},
+	{
 		.fn_name = NULL,
 	},
 };
libocfs2/ocfs2_err.et +6 -0
index ddfa07c..13b03c4 100644
@@ -183,7 +183,13 @@ ec	OCFS2_ET_BAD_XATTR_BLOCK_MAGIC,
 ec	OCFS2_ET_UNKNOWN_FEATURE,
 	"Unknown feature"
 
+ec	OCFS2_ET_CORRUPT_QUOTA_FILE,
+	"Quota file is corrupted"
+
 ec	OCFS2_ET_CANNOT_DETERMINE_SECTOR_SIZE,
 	"Cannot determine sector size"
 
+ec	OCFS2_ET_NONEMTY_QUOTA_HASH,
+	"Freeing non-empty quota hash"
+
 	end
libocfs2/quota.c new file +1208 -0

1,208 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#10 lore raw

PATCH 3/8 Implement quota functions to libocfs2

Hi Jan,

Quoted 15 lines · Jan Kara
---
 include/ocfs2/ocfs2.h     |   80 +++
 libocfs2/Makefile         |    1 +
 libocfs2/feature_string.c |   18 +
 libocfs2/ocfs2_err.et     |    6 +
 libocfs2/quota.c          | 1208 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1313 insertions(+), 0 deletions(-)
 create mode 100644 libocfs2/quota.c
include/ocfs2/ocfs2.h +0 -0
index ac16823..7f136ca 100644

include/ocfs2/ocfs2.h line 132

Quoted 8 lines
include/ocfs2/ocfs2.h +5 -0
@@ -125,16 +125,36 @@
 #define OCFS2_CHB_WAITING	2
 #define OCFS2_CHB_COMPLETE	3
 
+/* Flags for global quotafile info */
+#define OCFS2_QF_INFO_DIRTY 1
+/* Should be power of two */
+#define DEFAULT_QUOTA_HASH_SIZE 8192
+#define MAX_QUOTA_HASH_SIZE (1<<21)	/* 16 MB on 64-bit arch*/

16MB is 1<<24?

Quoted 39 lines
include/ocfs2/ocfs2.h +39 -0
+errcode_t ocfs2_init_local_quota_file(ocfs2_filesys *fs, int type,
+				      uint64_t blkno)
+{
+	ocfs2_cached_inode *ci = NULL;
+	struct ocfs2_dinode *di;
+	struct ocfs2_disk_dqheader *header;
+	struct ocfs2_local_disk_dqinfo *info;
+	unsigned int magics[] = OCFS2_LOCAL_QMAGICS;
+	int versions[] = OCFS2_LOCAL_QVERSIONS;
+	char *buf = NULL;
+	unsigned int written;
+	errcode_t err;
+
+	err = ocfs2_read_cached_inode(fs, blkno, &ci);
+	if (err)
+		goto out;
+
+	if (!(ci->ci_inode->i_flags & OCFS2_VALID_FL) ||
+	    !(ci->ci_inode->i_flags & OCFS2_SYSTEM_FL) ||
+	    !(ci->ci_inode->i_flags & OCFS2_QUOTA_FL)) {
+		err = OCFS2_ET_INTERNAL_FAILURE;
+		goto out;
+	}
+	di = ci->ci_inode;
+
+	/* We need at least two blocks */
+	err = ocfs2_cached_inode_extend_allocation(ci, (2 * fs->fs_blocksize +
+			fs->fs_clustersize - 1) / fs->fs_clustersize);
+	if (err)
+		goto out;
+	di->i_size = 2 * fs->fs_blocksize;
+	di->i_mtime = time(NULL);
+	err = ocfs2_write_inode(fs, blkno, (char *)di);
+	if (err)
+		goto out;
+
+	err = ocfs2_malloc_blocks(fs->fs_io, fs->fs_blocksize * 2, &buf);
+	if (err)
+		goto out;

include/ocfs2/ocfs2.h

Quoted 10 lines
include/ocfs2/ocfs2.h +10 -0
+	memset(buf, 0, 2 * fs->fs_blocksize);
+
+	header = (struct ocfs2_disk_dqheader *)buf;
+	header->dqh_magic = magics[type];
+	header->dqh_version = versions[type];
+	ocfs2_swap_quota_header(header);
+
+	info = (struct ocfs2_local_disk_dqinfo *)(buf + OCFS2_LOCAL_INFO_OFF);
+	info->dqi_chunks = 1;
+	info->dqi_blocks = 2;

I see hardcoded "2" so many times in this function while in ocfs2_init_global_quota_file you define "int blocks = 2", so I just wonder if we can change it somehow like that function?

include/ocfs2/ocfs2.h

Quoted 12 lines
include/ocfs2/ocfs2.h +12 -0
+	info->dqi_flags = OLQF_CLEAN;
+	ocfs2_swap_quota_local_info(info);
+
+	/* There are no free chunks because there are no blocks allocated for
+	 * them yet. So chunk header is all-zero and needs no initialization */
+	ocfs2_checksum_quota_block(fs, buf);
+	ocfs2_checksum_quota_block(fs, buf + fs->fs_blocksize);
+	err = ocfs2_file_write(ci, buf, 2 * fs->fs_blocksize, 0, &written);
+	if (!err && written != 2 * fs->fs_blocksize) {
+		err = OCFS2_ET_INTERNAL_FAILURE;
+		goto out;
+	}

and here in ocfs2_init_global_quota_file you use write_blk which will calculate ocfs2_checksum_quota_block. So we can use that function also here?

Regards,
Tao

author
#11 lore raw

PATCH 3/8 Implement quota functions to libocfs2

Quoted 13 lines · Tao Ma

Hi Jan,

Quoted 10 lines · Jan Kara
---
 include/ocfs2/ocfs2.h     |   80 +++
 libocfs2/Makefile         |    1 +
 libocfs2/feature_string.c |   18 +
 libocfs2/ocfs2_err.et     |    6 +
 libocfs2/quota.c          | 1208 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1313 insertions(+), 0 deletions(-)
 create mode 100644 libocfs2/quota.c
Quoted 13 lines

include/ocfs2/ocfs2.h line 131

Quoted 12 lines
include/ocfs2/ocfs2.h +4 -0
index ac16823..7f136ca 100644
@@ -125,16 +125,36 @@
 #define OCFS2_CHB_WAITING	2
 #define OCFS2_CHB_COMPLETE	3
 +/* Flags for global quotafile info */
+#define OCFS2_QF_INFO_DIRTY 1
+/* Should be power of two */
+#define DEFAULT_QUOTA_HASH_SIZE 8192
+#define MAX_QUOTA_HASH_SIZE (1<<21)	/* 16 MB on 64-bit arch*/

16MB is 1<<24?

The comment is meant to say that the hash-table will occupy 16 MB on a
64-bit architecture where each pointer has 8 bytes... I'll expand the comment a bit.

Quoted 44 lines
Quoted 44 lines
include/ocfs2/ocfs2.h +44 -0
+errcode_t ocfs2_init_local_quota_file(ocfs2_filesys *fs, int type,
+				      uint64_t blkno)
+{
+	ocfs2_cached_inode *ci = NULL;
+	struct ocfs2_dinode *di;
+	struct ocfs2_disk_dqheader *header;
+	struct ocfs2_local_disk_dqinfo *info;
+	unsigned int magics[] = OCFS2_LOCAL_QMAGICS;
+	int versions[] = OCFS2_LOCAL_QVERSIONS;
+	char *buf = NULL;
+	unsigned int written;
+	errcode_t err;
+
+	err = ocfs2_read_cached_inode(fs, blkno, &ci);
+	if (err)
+		goto out;
+
+	if (!(ci->ci_inode->i_flags & OCFS2_VALID_FL) ||
+	    !(ci->ci_inode->i_flags & OCFS2_SYSTEM_FL) ||
+	    !(ci->ci_inode->i_flags & OCFS2_QUOTA_FL)) {
+		err = OCFS2_ET_INTERNAL_FAILURE;
+		goto out;
+	}
+	di = ci->ci_inode;
+
+	/* We need at least two blocks */
+	err = ocfs2_cached_inode_extend_allocation(ci, (2 * fs->fs_blocksize +
+			fs->fs_clustersize - 1) / fs->fs_clustersize);
+	if (err)
+		goto out;
+	di->i_size = 2 * fs->fs_blocksize;
+	di->i_mtime = time(NULL);
+	err = ocfs2_write_inode(fs, blkno, (char *)di);
+	if (err)
+		goto out;
+
+	err = ocfs2_malloc_blocks(fs->fs_io, fs->fs_blocksize * 2, &buf);
+	if (err)
+		goto out;
+	memset(buf, 0, 2 * fs->fs_blocksize);
+
+	header = (struct ocfs2_disk_dqheader *)buf;
+	header->dqh_magic = magics[type];
+	header->dqh_version = versions[type];
Quoted 8 lines

include/ocfs2/ocfs2.h

Quoted 5 lines
include/ocfs2/ocfs2.h +5 -0
+	ocfs2_swap_quota_header(header);
+
+	info = (struct ocfs2_local_disk_dqinfo *)(buf + OCFS2_LOCAL_INFO_OFF);
+	info->dqi_chunks = 1;
+	info->dqi_blocks = 2;

I see hardcoded "2" so many times in this function while in ocfs2_init_global_quota_file you define "int blocks = 2", so I just wonder if we can change it somehow like that function?

OK, will do.

Quoted 7 lines
Quoted 7 lines
include/ocfs2/ocfs2.h +7 -0
+	info->dqi_flags = OLQF_CLEAN;
+	ocfs2_swap_quota_local_info(info);
+
+	/* There are no free chunks because there are no blocks allocated for
+	 * them yet. So chunk header is all-zero and needs no initialization */
+	ocfs2_checksum_quota_block(fs, buf);
+	ocfs2_checksum_quota_block(fs, buf + fs->fs_blocksize);
Quoted 8 lines

include/ocfs2/ocfs2.h

Quoted 5 lines
include/ocfs2/ocfs2.h +5 -0
+	err = ocfs2_file_write(ci, buf, 2 * fs->fs_blocksize, 0, &written);
+	if (!err && written != 2 * fs->fs_blocksize) {
+		err = OCFS2_ET_INTERNAL_FAILURE;
+		goto out;
+	}

and here in ocfs2_init_global_quota_file you use write_blk which will calculate ocfs2_checksum_quota_block. So we can use that function also here?

No, we cannot since write_blk() writes to a global quota file. Here we
need to write to a node-local quota file. Since there's only this place, where we write to local quota file, I'd just leave the code as is.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#12 lore raw

PATCH 3/8 Implement quota functions to libocfs2

Quoted 27 lines · Jan Kara
Quoted 13 lines · Tao Ma

Hi Jan,

Quoted 10 lines · Jan Kara
---
 include/ocfs2/ocfs2.h     |   80 +++
 libocfs2/Makefile         |    1 +
 libocfs2/feature_string.c |   18 +
 libocfs2/ocfs2_err.et     |    6 +
 libocfs2/quota.c          | 1208 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1313 insertions(+), 0 deletions(-)
 create mode 100644 libocfs2/quota.c
Quoted 13 lines

include/ocfs2/ocfs2.h line 131

Quoted 12 lines
include/ocfs2/ocfs2.h +4 -0
index ac16823..7f136ca 100644
@@ -125,16 +125,36 @@
 #define OCFS2_CHB_WAITING	2
 #define OCFS2_CHB_COMPLETE	3
 +/* Flags for global quotafile info */
+#define OCFS2_QF_INFO_DIRTY 1
+/* Should be power of two */
+#define DEFAULT_QUOTA_HASH_SIZE 8192
+#define MAX_QUOTA_HASH_SIZE (1<<21)	/* 16 MB on 64-bit arch*/

16MB is 1<<24?

Quoted 3 lines

The comment is meant to say that the hash-table will occupy 16 MB on a
64-bit architecture where each pointer has 8 bytes... I'll expand the comment a bit.

got it.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
include/ocfs2/ocfs2.h +7 -0
+	info->dqi_flags = OLQF_CLEAN;
+	ocfs2_swap_quota_local_info(info);
+
+	/* There are no free chunks because there are no blocks allocated for
+	 * them yet. So chunk header is all-zero and needs no initialization */
+	ocfs2_checksum_quota_block(fs, buf);
+	ocfs2_checksum_quota_block(fs, buf + fs->fs_blocksize);
Quoted 8 lines

include/ocfs2/ocfs2.h line 143

Quoted 5 lines
include/ocfs2/ocfs2.h +5 -0
+	err = ocfs2_file_write(ci, buf, 2 * fs->fs_blocksize, 0, &written);
+	if (!err && written != 2 * fs->fs_blocksize) {
+		err = OCFS2_ET_INTERNAL_FAILURE;
+		goto out;
+	}

and here in ocfs2_init_global_quota_file you use write_blk which will calculate ocfs2_checksum_quota_block. So we can use that function also here?

Quoted 3 lines

No, we cannot since write_blk() writes to a global quota file. Here we
need to write to a node-local quota file. Since there's only this place, where we write to local quota file, I'd just leave the code as is.

Oh, I see. Thanks for the explanation.

Regards,
Tao

author
#13 lore raw

PATCH 3/8 Implement quota functions to libocfs2

Quoted 47 lines · Tao Ma
Quoted 27 lines · Jan Kara
Quoted 13 lines · Tao Ma

Hi Jan,

Quoted 10 lines · Jan Kara
---
 include/ocfs2/ocfs2.h     |   80 +++
 libocfs2/Makefile         |    1 +
 libocfs2/feature_string.c |   18 +
 libocfs2/ocfs2_err.et     |    6 +
 libocfs2/quota.c          | 1208 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1313 insertions(+), 0 deletions(-)
 create mode 100644 libocfs2/quota.c
Quoted 13 lines

include/ocfs2/ocfs2.h line 131

Quoted 12 lines
include/ocfs2/ocfs2.h +4 -0
index ac16823..7f136ca 100644
@@ -125,16 +125,36 @@
 #define OCFS2_CHB_WAITING	2
 #define OCFS2_CHB_COMPLETE	3
 +/* Flags for global quotafile info */
+#define OCFS2_QF_INFO_DIRTY 1
+/* Should be power of two */
+#define DEFAULT_QUOTA_HASH_SIZE 8192
+#define MAX_QUOTA_HASH_SIZE (1<<21)	/* 16 MB on 64-bit arch*/

16MB is 1<<24?

Quoted 3 lines

The comment is meant to say that the hash-table will occupy 16 MB on a
64-bit architecture where each pointer has 8 bytes... I'll expand the comment a bit.

got it.

Quoted 15 lines
Quoted 15 lines

include/ocfs2/ocfs2.h line 143

Quoted 12 lines
include/ocfs2/ocfs2.h +12 -0
+	info->dqi_flags = OLQF_CLEAN;
+	ocfs2_swap_quota_local_info(info);
+
+	/* There are no free chunks because there are no blocks allocated for
+	 * them yet. So chunk header is all-zero and needs no initialization */
+	ocfs2_checksum_quota_block(fs, buf);
+	ocfs2_checksum_quota_block(fs, buf + fs->fs_blocksize);
+	err = ocfs2_file_write(ci, buf, 2 * fs->fs_blocksize, 0, &written);
+	if (!err && written != 2 * fs->fs_blocksize) {
+		err = OCFS2_ET_INTERNAL_FAILURE;
+		goto out;
+	}

and here in ocfs2_init_global_quota_file you use write_blk which will calculate ocfs2_checksum_quota_block. So we can use that function also here?

Quoted 4 lines
Quoted 3 lines

No, we cannot since write_blk() writes to a global quota file. Here we
need to write to a node-local quota file. Since there's only this place, where we write to local quota file, I'd just leave the code as is.

Oh, I see. Thanks for the explanation.

Below is an updated patch.

Honza

Signature · 18 lines
Jan Kara <[email protected]>
SUSE Labs, CR
--

From eba8c4001513164c4d823d55976c0aa9a64c9615 Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Mon, 27 Jul 2009 19:22:55 +0200
Subject: [PATCH] Implement quota functions to libocfs2

Signed-off-by: Jan Kara <[email protected]>
---
 include/ocfs2/ocfs2.h     |   80 +++
 libocfs2/Makefile         |    1 +
 libocfs2/feature_string.c |   18 +
 libocfs2/ocfs2_err.et     |    6 +
 libocfs2/quota.c          | 1215 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1320 insertions(+), 0 deletions(-)
 create mode 100644 libocfs2/quota.c
include/ocfs2/ocfs2.h +80 -0
index ac16823..7f136ca 100644
@@ -125,16 +125,36 @@
 #define OCFS2_CHB_WAITING	2
 #define OCFS2_CHB_COMPLETE	3
 
+/* Flags for global quotafile info */
+#define OCFS2_QF_INFO_DIRTY 1
+
 typedef void (*ocfs2_chb_notify)(int state, char *progress, void *data);
 
 typedef struct _ocfs2_filesys ocfs2_filesys;
 typedef struct _ocfs2_cached_inode ocfs2_cached_inode;
+typedef struct _ocfs2_cached_dquot ocfs2_cached_dquot;
 typedef struct _io_channel io_channel;
 typedef struct _ocfs2_inode_scan ocfs2_inode_scan;
 typedef struct _ocfs2_dir_scan ocfs2_dir_scan;
 typedef struct _ocfs2_bitmap ocfs2_bitmap;
 typedef struct _ocfs2_devices ocfs2_devices;
 
+#define MAXQUOTAS 2
+#define USRQUOTA 0
+#define GRPQUOTA 1
+
+#define OCFS2_DEF_BLOCK_GRACE 604800 /* 1 week */
+#define OCFS2_DEF_INODE_GRACE 604800 /* 1 week */
+#define OCFS2_DEF_QUOTA_SYNC 10000   /* 10 seconds */
+
+struct _ocfs2_quota_info {
+	ocfs2_cached_inode *qi_inode;
+	int flags;
+	struct ocfs2_global_disk_dqinfo qi_info;
+};
+
+typedef struct _ocfs2_quota_info ocfs2_quota_info;
+
 struct _ocfs2_filesys {
 	char *fs_devname;
 	uint32_t fs_flags;
@@ -161,6 +181,8 @@ struct _ocfs2_filesys {
 	struct o2dlm_ctxt *fs_dlm_ctxt;
 	struct ocfs2_image_state *ost;
 
+	ocfs2_quota_info qinfo[MAXQUOTAS];
+
 	/* Reserved for the use of the calling application. */
 	void *fs_private;
 };
@@ -172,6 +194,15 @@ struct _ocfs2_cached_inode {
 	ocfs2_bitmap *ci_chains;
 };
 
+typedef unsigned int qid_t;
+
+struct _ocfs2_cached_dquot {
+	loff_t d_off;	/* Offset of structure in the file */
+	struct _ocfs2_cached_dquot *d_next;	/* Next entry in hashchain */
+	struct _ocfs2_cached_dquot **d_pprev;	/* Previous pointer in hashchain */
+	struct ocfs2_global_disk_dqblk d_ddquot;	/* Quota entry */
+};
+
 struct ocfs2_slot_data {
 	int		sd_valid;
 	unsigned int	sd_node_num;
@@ -205,6 +236,14 @@ struct _ocfs2_fs_options {
 	uint32_t opt_ro_compat;
 };
 
+struct _ocfs2_quota_hash {
+	int alloc_entries;
+	int used_entries;
+	ocfs2_cached_dquot **hash;
+};
+
+typedef struct _ocfs2_quota_hash ocfs2_quota_hash;
+
 errcode_t ocfs2_malloc(unsigned long size, void *ptr);
 errcode_t ocfs2_malloc0(unsigned long size, void *ptr);
 errcode_t ocfs2_free(void *ptr);
@@ -580,6 +619,47 @@ errcode_t ocfs2_meta_lock(ocfs2_filesys *fs, ocfs2_cached_inode *inode,
 
 errcode_t ocfs2_meta_unlock(ocfs2_filesys *fs, ocfs2_cached_inode *ci);
 
+/* Quota operations */
+void ocfs2_swap_quota_header(struct ocfs2_disk_dqheader *header);
+void ocfs2_swap_quota_local_info(struct ocfs2_local_disk_dqinfo *info);
+void ocfs2_swap_quota_chunk_header(struct ocfs2_local_disk_chunk *chunk);
+void ocfs2_swap_quota_global_info(struct ocfs2_global_disk_dqinfo *info);
+void ocfs2_swap_quota_global_dqblk(struct ocfs2_global_disk_dqblk *dqblk);
+void ocfs2_swap_quota_leaf_block_header(struct ocfs2_global_disk_dqdbheader *bheader);
+errcode_t ocfs2_init_local_quota_file(ocfs2_filesys *fs, int type,
+				      uint64_t blkno);
+errcode_t ocfs2_init_local_quota_files(ocfs2_filesys *fs, int type);
+int ocfs2_qtree_depth(int blocksize);
+int ocfs2_qtree_entry_unused(struct ocfs2_global_disk_dqblk *ddquot);
+errcode_t ocfs2_init_global_quota_file(ocfs2_filesys *fs, int type);
+errcode_t ocfs2_init_fs_quota_info(ocfs2_filesys *fs, int type);
+errcode_t ocfs2_read_global_quota_info(ocfs2_filesys *fs, int type);
+errcode_t ocfs2_write_global_quota_info(ocfs2_filesys *fs, int type);
+errcode_t ocfs2_write_dquot(ocfs2_filesys *fs, int type,
+			    ocfs2_cached_dquot *dquot);
+errcode_t ocfs2_delete_dquot(ocfs2_filesys *fs, int type,
+			     ocfs2_cached_dquot *dquot);
+errcode_t ocfs2_read_dquot(ocfs2_filesys *fs, int type, qid_t id,
+			   ocfs2_cached_dquot **ret_dquot);
+errcode_t ocfs2_new_quota_hash(ocfs2_quota_hash **hashp);
+errcode_t ocfs2_free_quota_hash(ocfs2_quota_hash *hash);
+errcode_t ocfs2_insert_quota_hash(ocfs2_quota_hash *hash,
+				  ocfs2_cached_dquot *dquot);
+errcode_t ocfs2_remove_quota_hash(ocfs2_quota_hash *hash,
+				  ocfs2_cached_dquot *dquot);
+errcode_t ocfs2_find_quota_hash(ocfs2_quota_hash *hash, qid_t id,
+				ocfs2_cached_dquot **dquotp);
+errcode_t ocfs2_find_create_quota_hash(ocfs2_quota_hash *hash, qid_t id,
+				       ocfs2_cached_dquot **dquotp);
+errcode_t ocfs2_compute_quota_usage(ocfs2_filesys *fs,
+				    ocfs2_quota_hash *usr_hash,
+				    ocfs2_quota_hash *grp_hash);
+errcode_t ocfs2_iterate_quota_hash(ocfs2_quota_hash *hash,
+				   errcode_t (*f)(ocfs2_cached_dquot *, void *),
+				   void *data);
+errcode_t ocfs2_write_release_dquots(ocfs2_filesys *fs, int type,
+				     ocfs2_quota_hash *hash);
+
 /* Low level */
 void ocfs2_swap_slot_map(struct ocfs2_slot_map *sm, int num_slots);
 void ocfs2_swap_slot_map_extended(struct ocfs2_slot_map_extended *se,
libocfs2/Makefile +1 -0
index 48cfe80..eeb854a 100644
@@ -73,6 +73,7 @@ CFILES = 		\
 	lockid.c	\
 	backup_super.c	\
 	feature_string.c\
+	quota.c		\
 	image.c		\
 	xattr.c
 
libocfs2/feature_string.c +18 -0
index 17e2675..18ae6e9 100644
@@ -123,6 +123,16 @@ static struct fs_feature_flags ocfs2_supported_features[] = {
 		{0, OCFS2_FEATURE_INCOMPAT_XATTR, 0},
 	},
 	{
+		"usrquota",
+		{0, 0, OCFS2_FEATURE_RO_COMPAT_USRQUOTA},
+		{0, 0, OCFS2_FEATURE_RO_COMPAT_USRQUOTA},
+	},
+	{
+		"grpquota",
+		{0, 0, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA},
+		{0, 0, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA},
+	},
+	{
 		NULL,
 		{0, 0, 0},
 		{0, 0, 0}
@@ -190,6 +200,14 @@ static struct feature_name ocfs2_feature_names[] = {
 		.fn_flag = {0, OCFS2_FEATURE_INCOMPAT_XATTR, 0},
 	},
 	{
+		.fn_name = "usrquota",
+		.fn_flag = {0, 0, OCFS2_FEATURE_RO_COMPAT_USRQUOTA},
+	},
+	{
+		.fn_name = "grpquota",
+		.fn_flag = {0, 0, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA},
+	},
+	{
 		.fn_name = NULL,
 	},
 };
libocfs2/ocfs2_err.et +6 -0
index ddfa07c..13b03c4 100644
@@ -183,7 +183,13 @@ ec	OCFS2_ET_BAD_XATTR_BLOCK_MAGIC,
 ec	OCFS2_ET_UNKNOWN_FEATURE,
 	"Unknown feature"
 
+ec	OCFS2_ET_CORRUPT_QUOTA_FILE,
+	"Quota file is corrupted"
+
 ec	OCFS2_ET_CANNOT_DETERMINE_SECTOR_SIZE,
 	"Cannot determine sector size"
 
+ec	OCFS2_ET_NONEMTY_QUOTA_HASH,
+	"Freeing non-empty quota hash"
+
 	end
libocfs2/quota.c new file +1215 -0

1,215 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#14 lore raw

PATCH 3/8 Implement quota functions to libocfs2

libocfs2/quota.c line 523

Quoted 2 lines · Jan Kara
libocfs2/quota.c new file +2 -0
+/* Read given block */
+static errcode_t read_blk(ocfs2_filesys *fs, int type, uint blk, char *buf)

You're sure quota files will never be larger than a uint? Also,
we tend to do 'unsigned int', not 'uint'.

Joel

Signature · 10 lines
"When I am working on a problem I never think about beauty. I
 only think about how to solve the problem. But when I have finished, if
 the solution is not beautiful, I know it is wrong."
         - Buckminster Fuller

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
author
#15 lore raw

PATCH 3/8 Implement quota functions to libocfs2

Quoted 6 lines · Joel Becker

libocfs2/quota.c line 523

Quoted 2 lines · Jan Kara
libocfs2/quota.c new file +2 -0
+/* Read given block */
+static errcode_t read_blk(ocfs2_filesys *fs, int type, uint blk, char *buf)

You're sure quota files will never be larger than a uint? Also,
we tend to do 'unsigned int', not 'uint'.

Well, the disk format is designed only for 32-bit uids and gids (which is
consistent with the rest of OCFS2). For 2^32 users tracked in the quota file, it is going to have around 2^29 blocks so yes, unsigned int should be safe :)
I'll substitute uint with unsigned int... although it's horribly long for
such a useful type ;).

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#16 lore raw

PATCH 4/8 Write out quota info changes on ocfs2_close()

In reply to Jan Kara

We don't write out change of information in quota file header on each change, we rather cache it in ocfs2_filesys structure. So write out all the information when ocfs2_close() is called.

---
 libocfs2/closefs.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
libocfs2/closefs.c +12 -0
index 54411da..290bfd1 100644
@@ -39,6 +39,7 @@ errcode_t ocfs2_flush(ocfs2_filesys *fs)
 errcode_t ocfs2_close(ocfs2_filesys *fs)
 {
 	errcode_t ret;
+	int type;
 
 	if (fs->fs_flags & OCFS2_FLAG_DIRTY) {
 		ret = ocfs2_flush(fs);
@@ -46,6 +47,17 @@ errcode_t ocfs2_close(ocfs2_filesys *fs)
 			return ret;
 	}
 
+	for (type = 0; type < MAXQUOTAS; type++)
+		if (fs->qinfo[type].flags & OCFS2_QF_INFO_DIRTY) {
+			ret = ocfs2_write_global_quota_info(fs, type);
+			if (ret)
+				return ret;
+			ret = ocfs2_write_cached_inode(fs,
+						fs->qinfo[type].qi_inode);
+			if (ret)
+				return ret;
+		}
+
 	ocfs2_freefs(fs);
 	return 0;
 }
Signature · 1 line
1.6.0.2
#17 lore raw

PATCH 4/8 Write out quota info changes on ocfs2_close()

Quoted 5 lines · Jan Kara

We don't write out change of information in quota file header on each change, we rather cache it in ocfs2_filesys structure. So write out all the information when ocfs2_close() is called.

This looks good as long as all quota ops keep those ocfs2_cached_inodes up to date.

Joel

Signature · 10 lines
"In the beginning, the universe was created. This has made a lot 
 of people very angry, and is generally considered to have been a 
 bad move."
        - Douglas Adams

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
author
#18 lore raw

PATCH 4/8 Write out quota info changes on ocfs2_close()

Quoted 9 lines · Joel Becker
Quoted 5 lines · Jan Kara

We don't write out change of information in quota file header on each change, we rather cache it in ocfs2_filesys structure. So write out all the information when ocfs2_close() is called.

This looks good as long as all quota ops keep those ocfs2_cached_inodes up to date.

Yes, all quota ops use only these cached inodes so it should be fine.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#19 lore raw

PATCH 5/8 Quota support for fsck.ocfs2

In reply to Jan Kara

After the filesystem is fixed, scan quota files and try to gather as much information about set limits as possible. Then scan the filesystem to compute correct quota usage and dump all the gathered information into freshly created quota files.

---
 fsck.ocfs2/Makefile               |    2 +
 fsck.ocfs2/fsck.c                 |    9 +
 fsck.ocfs2/fsck.ocfs2.checks.8.in |   30 ++
 fsck.ocfs2/include/pass5.h        |   32 +++
 fsck.ocfs2/pass5.c                |  534 +++++++++++++++++++++++++++++++++++++
 5 files changed, 607 insertions(+), 0 deletions(-)
 create mode 100644 fsck.ocfs2/include/pass5.h
 create mode 100644 fsck.ocfs2/pass5.c
fsck.ocfs2/Makefile +2 -0
index 7f6e547..850e106 100644
@@ -28,6 +28,7 @@ CFILES =	fsck.c		\
 		pass2.c 	\
 		pass3.c 	\
 		pass4.c 	\
+		pass5.c		\
 		problem.c 	\
 		slot_recovery.c \
 		strings.c 	\
@@ -46,6 +47,7 @@ HFILES = 	include/fsck.h		\
 		include/pass2.h		\
 		include/pass3.h		\
 		include/pass4.h		\
+		include/pass5.h		\
 		include/problem.h	\
 		include/slot_recovery.h	\
 		include/strings.h	\
fsck.ocfs2/fsck.c +9 -0
index a686886..fe15783 100644
@@ -30,6 +30,8 @@
  * pass2.c: verify directory entries, record some linkage metadata
  * pass3.c: make sure all dirs are reachable
  * pass4.c: resolve inode's link counts, move disconnected inodes to lost+found
+ * pass5.c: load global quota file, merge node-local quota files to global
+ *          quota file, recompute quota usage and recreate quota files
  *
  * When hacking on this keep the following in mind:
  *
@@ -64,6 +66,7 @@
 #include "pass2.h"
 #include "pass3.h"
 #include "pass4.h"
+#include "pass5.h"
 #include "problem.h"
 #include "util.h"
 #include "slot_recovery.h"
@@ -917,6 +920,12 @@ int main(int argc, char **argv)
 		goto done;
 	}
 
+	ret = o2fsck_pass5(ost);
+	if (ret) {
+		com_err(whoami, ret, "while performing pass 5");
+		goto done;
+	}
+
 done:
 	if (ret)
 		fsck_mask |= FSCK_ERROR;
fsck.ocfs2/fsck.ocfs2.checks.8.in +30 -0
index 739b867..f70f48d 100644
@@ -851,6 +851,36 @@ does not match the number of buckets found by fsck.
 
 Answering yes will change this to the correct count.
 
+\" pass5.c
+
+.SS "QMAGIC_INVALID"
+The magic number in the header of quota file does not match the proper
+number.
+
+Answering yes will make fsck use values in the quota file header anyway.
+
+.SS "QTREE_BLK_INVALID"
+Block with references to other blocks with quota data is corrupted.
+
+Answering yes will make fsck use references in the block.
+
+.SS "DQBLK_INVALID"
+The structure with quota limits was found in a corrupted block.
+
+Answering yes will use the values of limits for the user / group.
+
+.SS "DUP_DQBLK_INVALID"
+The structure with quota limits was found in a corrupted block
+and fsck has already found quota limits for this user / group.
+
+Answering yes will use new values of limits for the user / group.
+
+.SS "DUP_DQBLK_VALID"
+The structure with quota limits was found in a correct block
+but fsck has already found quota limits for this user / group.
+
+Answering yes will use new values of limits for the user / group.
+
 .SH "SEE ALSO"
 .BR fsck.ocfs2(8)
 
fsck.ocfs2/include/pass5.h new file +32 -0
new file mode 100644
index 0000000..dfd27cd
@@ -0,0 +1,32 @@
+/*
+ * pass5.h
+ *
+ * Copyright (C) 2009 Novell Corporation.  All rights reserved.
+ *
+ * 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 the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ * Author: Jan Kara
+ */
+
+#ifndef __O2FSCK_PASS5_H__
+#define __O2FSCK_PASS5_H__
+
+#include "fsck.h"
+
+errcode_t o2fsck_pass5(o2fsck_state *ost);
+
+#endif /* __O2FSCK_PASS4_H__ */
+
fsck.ocfs2/pass5.c new file +534 -0

534 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#20 lore raw

PATCH 5/8 Quota support for fsck.ocfs2

Quoted 6 lines · Jan Kara
fsck.ocfs2/include/pass5.h new file +0 -0
new file mode 100644
index 0000000..dfd27cd

fsck.ocfs2/include/pass5.h line 9

Quoted 9 lines
fsck.ocfs2/include/pass5.h new file +9 -0
@@ -0,0 +1,32 @@
+/*
+ * pass5.h
+ *
+ * Copyright (C) 2009 Novell Corporation.  All rights reserved.
+ *
+ * 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 the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.

We generally use GPL version 2 only, but you are welcome to
license this 2-or-later. I only mention this because...

fsck.ocfs2/include/pass5.h line 19

Quoted 9 lines
fsck.ocfs2/include/pass5.h new file +9 -0
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.

Can you check http://kernel.us.oracle.com/~smushran/license.txt
and update your header? The last paragraph is no longer recommended by the FSF, and we'd love for this header to have the emacs/vim lines at the top.

fsck.ocfs2/include/pass5.h line 22

Quoted 3 lines
fsck.ocfs2/include/pass5.h new file +3 -0
+ *
+ * Author: Jan Kara
+ */

Also, we deliberately drop author attribution from individual
source files. You can add yourself to MAINTAINERS.

Quoted 52 lines
fsck.ocfs2/include/pass5.h new file +52 -0
+errcode_t o2fsck_pass5(o2fsck_state *ost)
+{
+	errcode_t ret;
+	ocfs2_filesys *fs = ost->ost_fs;
+	struct ocfs2_super_block *super = OCFS2_RAW_SB(fs->fs_super);
+	int has_usrquota, has_grpquota;
+
+	has_usrquota = OCFS2_HAS_RO_COMPAT_FEATURE(super,
+				OCFS2_FEATURE_RO_COMPAT_USRQUOTA);
+	has_grpquota = OCFS2_HAS_RO_COMPAT_FEATURE(super,
+				OCFS2_FEATURE_RO_COMPAT_GRPQUOTA);
+	/* Nothing to check? */
+	if (!has_usrquota && !has_grpquota)
+		return 0;
+	printf("Pass 5: Checking quota information.\n");
+	if (has_usrquota) {
+		ret = ocfs2_new_quota_hash(qhash + USRQUOTA);
+		if (ret) {
+			com_err(whoami, ret,
+				"while allocating user quota hash");
+			goto out;
+		}
+		ret = load_quota_file(ost, USRQUOTA);
+		if (ret)
+			goto out;
+	}
+	if (has_grpquota) {
+		ret = ocfs2_new_quota_hash(qhash + GRPQUOTA);
+		if (ret) {
+			com_err(whoami, ret,
+				"while allocating group quota hash");
+			goto out;
+		}
+		ret = load_quota_file(ost, GRPQUOTA);
+		if (ret)
+			goto out;
+	}
+	ret = ocfs2_compute_quota_usage(fs, qhash[USRQUOTA], qhash[GRPQUOTA]);
+	if (ret) {
+		com_err(whoami, ret, "while computing quota usage");
+		goto out;
+	}
+	if (has_usrquota) {
+		ret = recreate_quota_files(fs, USRQUOTA);
+		if (ret)
+			goto out;
+		ret = ocfs2_free_quota_hash(qhash[USRQUOTA]);
+		if (ret) {
+			com_err(whoami, ret, "while release user quota hash");
+			goto out;
+		}
+	}

fsck.ocfs2/include/pass5.h

Quoted 10 lines
fsck.ocfs2/include/pass5.h new file +10 -0
+	if (has_grpquota) {
+		ret = recreate_quota_files(fs, GRPQUOTA);
+		if (ret)
+			goto out;
+		ret = ocfs2_free_quota_hash(qhash[GRPQUOTA]);
+		if (ret) {
+			com_err(whoami, ret, "while release group quota hash");
+			goto out;
+		}
+	}

The way I read this, you check the existing quota structures,
and then ignore them while recomputing the usage. You just do a full-on recompute. Then you write out the newly computed data. Am I correct?

Joel

Signature · 10 lines
You can use a screwdriver to screw in screws or to clean your ears,
however, the latter needs real skill, determination and a lack of fear
of injuring yourself.  It is much the same with JavaScript.
	- Chris Heilmann

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
author
#21 lore raw

PATCH 5/8 Quota support for fsck.ocfs2

Quoted 30 lines · Joel Becker
Quoted 6 lines · Jan Kara
fsck.ocfs2/include/pass5.h new file +0 -0
new file mode 100644
index 0000000..dfd27cd

fsck.ocfs2/include/pass5.h line 9

Quoted 9 lines
fsck.ocfs2/include/pass5.h new file +9 -0
@@ -0,0 +1,32 @@
+/*
+ * pass5.h
+ *
+ * Copyright (C) 2009 Novell Corporation.  All rights reserved.
+ *
+ * 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 the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.

We generally use GPL version 2 only, but you are welcome to
license this 2-or-later. I only mention this because...

fsck.ocfs2/include/pass5.h line 19

Quoted 9 lines
fsck.ocfs2/include/pass5.h new file +9 -0
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
Quoted 4 lines

Can you check http://kernel.us.oracle.com/~smushran/license.txt
and update your header? The last paragraph is no longer recommended by the FSF, and we'd love for this header to have the emacs/vim lines at the top.

I've just copy-pasted the header from pass4.h :) I'll happily update it
but the server you referenced doesn't seem to exist anymore.

Quoted 6 lines

fsck.ocfs2/include/pass5.h line 22

Quoted 3 lines
fsck.ocfs2/include/pass5.h new file +3 -0
+ *
+ * Author: Jan Kara
+ */

Also, we deliberately drop author attribution from individual
source files. You can add yourself to MAINTAINERS.

No problem with dropping it.

Quoted 58 lines
Quoted 58 lines
fsck.ocfs2/include/pass5.h new file +58 -0
+errcode_t o2fsck_pass5(o2fsck_state *ost)
+{
+	errcode_t ret;
+	ocfs2_filesys *fs = ost->ost_fs;
+	struct ocfs2_super_block *super = OCFS2_RAW_SB(fs->fs_super);
+	int has_usrquota, has_grpquota;
+
+	has_usrquota = OCFS2_HAS_RO_COMPAT_FEATURE(super,
+				OCFS2_FEATURE_RO_COMPAT_USRQUOTA);
+	has_grpquota = OCFS2_HAS_RO_COMPAT_FEATURE(super,
+				OCFS2_FEATURE_RO_COMPAT_GRPQUOTA);
+	/* Nothing to check? */
+	if (!has_usrquota && !has_grpquota)
+		return 0;
+	printf("Pass 5: Checking quota information.\n");
+	if (has_usrquota) {
+		ret = ocfs2_new_quota_hash(qhash + USRQUOTA);
+		if (ret) {
+			com_err(whoami, ret,
+				"while allocating user quota hash");
+			goto out;
+		}
+		ret = load_quota_file(ost, USRQUOTA);
+		if (ret)
+			goto out;
+	}
+	if (has_grpquota) {
+		ret = ocfs2_new_quota_hash(qhash + GRPQUOTA);
+		if (ret) {
+			com_err(whoami, ret,
+				"while allocating group quota hash");
+			goto out;
+		}
+		ret = load_quota_file(ost, GRPQUOTA);
+		if (ret)
+			goto out;
+	}
+	ret = ocfs2_compute_quota_usage(fs, qhash[USRQUOTA], qhash[GRPQUOTA]);
+	if (ret) {
+		com_err(whoami, ret, "while computing quota usage");
+		goto out;
+	}
+	if (has_usrquota) {
+		ret = recreate_quota_files(fs, USRQUOTA);
+		if (ret)
+			goto out;
+		ret = ocfs2_free_quota_hash(qhash[USRQUOTA]);
+		if (ret) {
+			com_err(whoami, ret, "while release user quota hash");
+			goto out;
+		}
+	}
+	if (has_grpquota) {
+		ret = recreate_quota_files(fs, GRPQUOTA);
+		if (ret)
+			goto out;
+		ret = ocfs2_free_quota_hash(qhash[GRPQUOTA]);
+		if (ret) {
Quoted 8 lines

fsck.ocfs2/include/pass5.h

Quoted 4 lines
fsck.ocfs2/include/pass5.h new file +4 -0
+			com_err(whoami, ret, "while release group quota hash");
+			goto out;
+		}
+	}

The way I read this, you check the existing quota structures,
and then ignore them while recomputing the usage. You just do a full-on recompute. Then you write out the newly computed data. Am I correct?

Yes, the point is: Quota *usage* is recomputed from scratch (and
basically there's not much better way because e.g. a corruption could have changed owners of files). Quota *limits* have to be loaded from old quota files and that's the whole point of our quota checking excercise.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#22 lore raw

PATCH 5/8 Quota support for fsck.ocfs2

Hi Jan,

Quoted 34 lines · Jan Kara
Quoted 32 lines · Joel Becker
Quoted 7 lines · Jan Kara
fsck.ocfs2/include/pass5.h new file +0 -0
new file mode 100644
index 0000000..dfd27cd

fsck.ocfs2/include/pass5.h line 9

Quoted 9 lines
fsck.ocfs2/include/pass5.h new file +9 -0
@@ -0,0 +1,32 @@
+/*
+ * pass5.h
+ *
+ * Copyright (C) 2009 Novell Corporation.  All rights reserved.
+ *
+ * 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 the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.

We generally use GPL version 2 only, but you are welcome to
license this 2-or-later. I only mention this because...

Quoted 10 lines
fsck.ocfs2/include/pass5.h new file +9 -0
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
Quoted 8 lines
Quoted 5 lines

Can you check http://kernel.us.oracle.com/~smushran/license.txt
and update your header? The last paragraph is no longer recommended by the FSF, and we'd love for this header to have the emacs/vim lines at the top.

I've just copy-pasted the header from pass4.h :) I'll happily update it
but the server you referenced doesn't seem to exist anymore.

You can copy/paste from libocfs2/xattr.c. It should have the right one.

Regards,
Tao

#23 lore raw

PATCH 5/8 Quota support for fsck.ocfs2

In reply to Jan Kara
Quoted 7 lines · Jan Kara
Quoted 4 lines · Joel Becker

Can you check http://kernel.us.oracle.com/~smushran/license.txt
and update your header? The last paragraph is no longer recommended by the FSF, and we'd love for this header to have the emacs/vim lines at the top.

I've just copy-pasted the header from pass4.h :) I'll happily update it
but the server you referenced doesn't seem to exist anymore.

Haha, that's our internal server. I'll attach that file :-)

Quoted 7 lines
Quoted 3 lines

The way I read this, you check the existing quota structures,
and then ignore them while recomputing the usage. You just do a full-on recompute. Then you write out the newly computed data. Am I correct?

Yes, the point is: Quota *usage* is recomputed from scratch (and
basically there's not much better way because e.g. a corruption could have changed owners of files). Quota *limits* have to be loaded from old quota files and that's the whole point of our quota checking excercise.

Ahh, I get it. I was thinking that the recompute of usage was
expensive, but there's no way to validate the usage in the quota files without running the recompute, and at that point the simple code is, as you have done, to just write the recomputed data.

Joel

Signature · 28 lines
"In a crisis, don't hide behind anything or anybody. They're going
 to find you anyway."
	- Paul "Bear" Bryant

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
-------------- next part --------------
/* -*- mode: c; c-basic-offset: 8; -*-
 * vim: noexpandtab sw=8 ts=8 sts=0:
 *
 * filename.c
 *
 * file description
 *
 * Copyright (C) 2004, 2008 Oracle.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */
author
#24 lore raw

PATCH 6/8 Quota support for mkfs.ocfs2

In reply to Jan Kara
---
 mkfs.ocfs2/mkfs.c          |  146 +++++++++++++++++++++++++++++++++++++++++++-
 mkfs.ocfs2/mkfs.h          |    1 +
 mkfs.ocfs2/mkfs.ocfs2.8.in |   16 +++++
 3 files changed, 162 insertions(+), 1 deletions(-)
mkfs.ocfs2/mkfs.c +145 -1
index 6acc6e6..8496d03 100644
@@ -98,12 +98,16 @@ static SystemFileInfo system_files[] = {
 	{ "slot_map", SFI_OTHER, 1, S_IFREG | 0644 },
 	{ "heartbeat", SFI_HEARTBEAT, 1, S_IFREG | 0644 },
 	{ "global_bitmap", SFI_CLUSTER, 1, S_IFREG | 0644 },
+	{ "aquota.user", SFI_QUOTA, 1, S_IFREG | 0644 },
+	{ "aquota.group", SFI_QUOTA, 1, S_IFREG | 0644 },
 	{ "orphan_dir:%04d", SFI_OTHER, 0, S_IFDIR | 0755 },
 	{ "extent_alloc:%04d", SFI_CHAIN, 0, S_IFREG | 0644 },
 	{ "inode_alloc:%04d", SFI_CHAIN, 0, S_IFREG | 0644 },
 	{ "journal:%04d", SFI_JOURNAL, 0, S_IFREG | 0644 },
 	{ "local_alloc:%04d", SFI_LOCAL_ALLOC, 0, S_IFREG | 0644 },
-	{ "truncate_log:%04d", SFI_TRUNCATE_LOG, 0, S_IFREG | 0644 }
+	{ "truncate_log:%04d", SFI_TRUNCATE_LOG, 0, S_IFREG | 0644 },
+	{ "aquota.user:%04d", SFI_QUOTA, 0, S_IFREG | 0644 },
+	{ "aquota.group:%04d", SFI_QUOTA, 0, S_IFREG | 0644 },
 };
 
 struct fs_type_translation {
@@ -226,6 +230,23 @@ static void mkfs_init_dir_trailer(State *s, DirData *dir, void *buf)
 	}
 }
 
+/* Should we skip this inode because of features enabled / disabled? */
+static int feature_skip(State *s, int system_inode)
+{
+	switch (system_inode) {
+		case USER_QUOTA_SYSTEM_INODE:
+		case LOCAL_USER_QUOTA_SYSTEM_INODE:
+			return !(s->feature_flags.opt_ro_compat &
+					OCFS2_FEATURE_RO_COMPAT_USRQUOTA);
+		case GROUP_QUOTA_SYSTEM_INODE:
+		case LOCAL_GROUP_QUOTA_SYSTEM_INODE:
+			return !(s->feature_flags.opt_ro_compat &
+					OCFS2_FEATURE_RO_COMPAT_GRPQUOTA);
+		default:
+			return 0;
+	}
+}
+
 static inline uint32_t system_dir_bytes_needed(State *s)
 {
 	int each = OCFS2_DIR_REC_LEN(SYSTEM_FILE_NAME_MAX);
@@ -233,6 +254,114 @@ static inline uint32_t system_dir_bytes_needed(State *s)
 	return each * sys_blocks_needed(s->initial_slots);
 }
 
+static void format_quota_files(State *s, ocfs2_filesys *fs)
+{
+	errcode_t ret;
+	ocfs2_quota_hash *usr_hash = NULL, *grp_hash = NULL;
+
+	/* Write correct data into quota files */
+	if (!feature_skip(s, USER_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global user quota file");
+			goto error;
+		}
+		fs->qinfo[USRQUOTA].flags = 0;
+		fs->qinfo[USRQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[USRQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[USRQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+
+		ret = ocfs2_new_quota_hash(&usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while creating user quota hash.");
+			goto error;
+		}
+		ret = ocfs2_init_global_quota_file(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret, "while creating global user "
+				"quota file");
+			goto error;
+		}
+		ret = ocfs2_init_local_quota_files(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while initializing local user quota files");
+			goto error;
+		}
+	}
+	if (!feature_skip(s, GROUP_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global group quota file");
+			goto error;
+		}
+		fs->qinfo[GRPQUOTA].flags = 0;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+		ret = ocfs2_new_quota_hash(&usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while creating group quota hash.");
+			goto error;
+		}
+		ret = ocfs2_init_global_quota_file(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret, "while creating global group "
+				"quota file");
+			goto error;
+		}
+
+		ret = ocfs2_init_local_quota_files(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while initializing local group quota files");
+			goto error;
+		}
+	}
+
+	ret = ocfs2_compute_quota_usage(fs, usr_hash, grp_hash);
+	if (ret) {
+		com_err(s->progname, ret, "while computing quota usage");
+		goto error;
+	}
+	if (usr_hash) {
+		ret = ocfs2_write_release_dquots(fs, USRQUOTA, usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while writing user quota usage");
+			goto error;
+		}
+		ret = ocfs2_free_quota_hash(usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while releasing user quota hash");
+			goto error;
+		}
+	}
+	if (grp_hash) {
+		ret = ocfs2_write_release_dquots(fs, GRPQUOTA, grp_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while writing group quota usage");
+			goto error;
+		}
+		ret = ocfs2_free_quota_hash(grp_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while releasing group quota hash");
+			goto error;
+		}
+	}
+	return;
+error:
+	clear_both_ends(s);
+	exit(1);
+}
+
 static void finish_normal_format(State *s)
 {
 	errcode_t ret;
@@ -304,6 +433,14 @@ static void finish_normal_format(State *s)
 	if (!s->quiet)
 		printf("done\n");
 
+	if (!s->quiet)
+		printf("Formatting quota files: ");
+
+	format_quota_files(s, fs);
+
+	if (!s->quiet)
+		printf("done\n");
+
 	ocfs2_close(fs);
 }
 
@@ -471,6 +608,8 @@ main(int argc, char **argv)
 	for (i = 0; i < NUM_SYSTEM_INODES; i++) {
 		if (hb_dev_skip(s, i))
 			continue;
+		if (feature_skip(s, i))
+			continue;
 
 		num = (system_files[i].global) ? 1 : s->initial_slots;
 		for (j = 0; j < num; j++) {
@@ -529,6 +668,8 @@ main(int argc, char **argv)
 	for (i = 0; i < NUM_SYSTEM_INODES; i++) {
 		if (hb_dev_skip(s, i))
 			continue;
+		if (feature_skip(s, i))
+			continue;
 
 		num = system_files[i].global ? 1 : s->initial_slots;
 		for (j = 0; j < num; j++) {
@@ -2432,6 +2573,9 @@ init_record(State *s, SystemFileDiskRecord *rec, int type, int mode)
 	case SFI_TRUNCATE_LOG:
 		rec->flags |= OCFS2_DEALLOC_FL;
 		break;
+	case SFI_QUOTA:
+		rec->flags |= OCFS2_QUOTA_FL;
+		break;
 	case SFI_OTHER:
 		break;
 	}
mkfs.ocfs2/mkfs.h +1 -0
index bd8ac45..969e4df 100644
@@ -96,6 +96,7 @@ enum {
 	SFI_HEARTBEAT,
 	SFI_CHAIN,
 	SFI_TRUNCATE_LOG,
+	SFI_QUOTA,
 	SFI_OTHER
 };
 
mkfs.ocfs2/mkfs.ocfs2.8.in +16 -0
index 38433ee..d1f4011 100644
@@ -146,6 +146,22 @@ arbitrary binary data. Attributes can be attached to all types of inodes: regula
 symbolic links, device nodes, etc. This feature is required for users wanting to use extended security
 facilities like POSIX ACLs or SELinux.
 .RE
+.RS 1.2i
+.TP
+\fBusrquota\fR
+Enable user quota support. With this feature enabled, filesystem will track amount of space
+and number of inodes (files, directories, symbolic links) each user owns. It is then possible
+to limit the maximum amount of space or inodes user can have. See a documentation of
+quota-tools package for more details.
+.RE
+.RS 1.2i
+.TP
+\fBgrpquota\fR
+Enable group quota support. With this feature enabled, filesystem will track amount of space
+and number of inodes (files, directories, symbolic links) each group owns. It is then possible
+to limit the maximum amount of space or inodes user can have. See a documentation of
+quota-tools package for more details.
+.RE
 
 .TP
 \fB\-\-fs\-feature\-level=\fR\fR\fIfeature\-level\fR
Signature · 1 line
1.6.0.2
#25 lore raw

PATCH 6/8 Quota support for mkfs.ocfs2

Hi Jan,

Quoted 50 lines · Jan Kara
---
 mkfs.ocfs2/mkfs.c          |  146 +++++++++++++++++++++++++++++++++++++++++++-
 mkfs.ocfs2/mkfs.h          |    1 +
 mkfs.ocfs2/mkfs.ocfs2.8.in |   16 +++++
 3 files changed, 162 insertions(+), 1 deletions(-)
mkfs.ocfs2/mkfs.c +39 -0
index 6acc6e6..8496d03 100644
+static void format_quota_files(State *s, ocfs2_filesys *fs)
+{
+	errcode_t ret;
+	ocfs2_quota_hash *usr_hash = NULL, *grp_hash = NULL;
+
+	/* Write correct data into quota files */
+	if (!feature_skip(s, USER_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global user quota file");
+			goto error;
+		}
+		fs->qinfo[USRQUOTA].flags = 0;
+		fs->qinfo[USRQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[USRQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[USRQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+
+		ret = ocfs2_new_quota_hash(&usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while creating user quota hash.");
+			goto error;
+		}
+		ret = ocfs2_init_global_quota_file(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret, "while creating global user "
+				"quota file");
+			goto error;
+		}
+		ret = ocfs2_init_local_quota_files(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while initializing local user quota files");
+			goto error;
+		}
+	}
+	if (!feature_skip(s, GROUP_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, GRPQUOTA);

mkfs.ocfs2/mkfs.c static inline uint32_t system_dir_bytes_needed(State *s) · line 305

Quoted 10 lines
mkfs.ocfs2/mkfs.c +10 -0
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global group quota file");
+			goto error;
+		}
+		fs->qinfo[GRPQUOTA].flags = 0;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+		ret = ocfs2_new_quota_hash(&usr_hash);

grp_hash here?

Regards,
Tao

author
#26 lore raw

PATCH 6/8 Quota support for mkfs.ocfs2

Hi,

Quoted 54 lines · Tao Ma
Quoted 53 lines · Jan Kara
---
 mkfs.ocfs2/mkfs.c          |  146 +++++++++++++++++++++++++++++++++++++++++++-
 mkfs.ocfs2/mkfs.h          |    1 +
 mkfs.ocfs2/mkfs.ocfs2.8.in |   16 +++++
 3 files changed, 162 insertions(+), 1 deletions(-)
mkfs.ocfs2/mkfs.c +42 -0
index 6acc6e6..8496d03 100644
+static void format_quota_files(State *s, ocfs2_filesys *fs)
+{
+	errcode_t ret;
+	ocfs2_quota_hash *usr_hash = NULL, *grp_hash = NULL;
+
+	/* Write correct data into quota files */
+	if (!feature_skip(s, USER_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global user quota file");
+			goto error;
+		}
+		fs->qinfo[USRQUOTA].flags = 0;
+		fs->qinfo[USRQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[USRQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[USRQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+
+		ret = ocfs2_new_quota_hash(&usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while creating user quota hash.");
+			goto error;
+		}
+		ret = ocfs2_init_global_quota_file(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret, "while creating global user "
+				"quota file");
+			goto error;
+		}
+		ret = ocfs2_init_local_quota_files(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while initializing local user quota files");
+			goto error;
+		}
+	}
+	if (!feature_skip(s, GROUP_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global group quota file");
Quoted 8 lines

mkfs.ocfs2/mkfs.c static inline uint32_t system_dir_bytes_needed(State *s) · line 305

Quoted 7 lines
mkfs.ocfs2/mkfs.c +7 -0
+			goto error;
+		}
+		fs->qinfo[GRPQUOTA].flags = 0;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+		ret = ocfs2_new_quota_hash(&usr_hash);

grp_hash here?

Good catch! Obviously I didn't check that the group usage was set correctly
:). Thanks for the review.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#27 lore raw

PATCH 6/8 Quota support for mkfs.ocfs2

Quoted 64 lines · Jan Kara

Hi,

Quoted 54 lines · Tao Ma
Quoted 53 lines · Jan Kara
---
 mkfs.ocfs2/mkfs.c          |  146 +++++++++++++++++++++++++++++++++++++++++++-
 mkfs.ocfs2/mkfs.h          |    1 +
 mkfs.ocfs2/mkfs.ocfs2.8.in |   16 +++++
 3 files changed, 162 insertions(+), 1 deletions(-)
mkfs.ocfs2/mkfs.c +42 -0
index 6acc6e6..8496d03 100644
+static void format_quota_files(State *s, ocfs2_filesys *fs)
+{
+	errcode_t ret;
+	ocfs2_quota_hash *usr_hash = NULL, *grp_hash = NULL;
+
+	/* Write correct data into quota files */
+	if (!feature_skip(s, USER_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global user quota file");
+			goto error;
+		}
+		fs->qinfo[USRQUOTA].flags = 0;
+		fs->qinfo[USRQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[USRQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[USRQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+
+		ret = ocfs2_new_quota_hash(&usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while creating user quota hash.");
+			goto error;
+		}
+		ret = ocfs2_init_global_quota_file(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret, "while creating global user "
+				"quota file");
+			goto error;
+		}
+		ret = ocfs2_init_local_quota_files(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while initializing local user quota files");
+			goto error;
+		}
+	}
+	if (!feature_skip(s, GROUP_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global group quota file");
Quoted 8 lines

mkfs.ocfs2/mkfs.c

Quoted 7 lines
mkfs.ocfs2/mkfs.c +7 -0
+			goto error;
+		}
+		fs->qinfo[GRPQUOTA].flags = 0;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+		ret = ocfs2_new_quota_hash(&usr_hash);

grp_hash here?

Quoted 2 lines

Good catch! Obviously I didn't check that the group usage was set correctly
:). Thanks for the review.

Below is an updated patch.

Signature · 15 lines
Jan Kara <[email protected]>
SUSE Labs, CR
---

From 148eb11dc3e1de1907bb6069b8d976451a5ff54a Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Mon, 27 Jul 2009 19:36:22 +0200
Subject: [PATCH 06/10] Quota support for mkfs.ocfs2

Signed-off-by: Jan Kara <[email protected]>
---
 mkfs.ocfs2/mkfs.c          |  146 +++++++++++++++++++++++++++++++++++++++++++-
 mkfs.ocfs2/mkfs.h          |    1 +
 mkfs.ocfs2/mkfs.ocfs2.8.in |   16 +++++
 3 files changed, 162 insertions(+), 1 deletions(-)
mkfs.ocfs2/mkfs.c +145 -1
index 6acc6e6..031b8a6 100644
@@ -98,12 +98,16 @@ static SystemFileInfo system_files[] = {
 	{ "slot_map", SFI_OTHER, 1, S_IFREG | 0644 },
 	{ "heartbeat", SFI_HEARTBEAT, 1, S_IFREG | 0644 },
 	{ "global_bitmap", SFI_CLUSTER, 1, S_IFREG | 0644 },
+	{ "aquota.user", SFI_QUOTA, 1, S_IFREG | 0644 },
+	{ "aquota.group", SFI_QUOTA, 1, S_IFREG | 0644 },
 	{ "orphan_dir:%04d", SFI_OTHER, 0, S_IFDIR | 0755 },
 	{ "extent_alloc:%04d", SFI_CHAIN, 0, S_IFREG | 0644 },
 	{ "inode_alloc:%04d", SFI_CHAIN, 0, S_IFREG | 0644 },
 	{ "journal:%04d", SFI_JOURNAL, 0, S_IFREG | 0644 },
 	{ "local_alloc:%04d", SFI_LOCAL_ALLOC, 0, S_IFREG | 0644 },
-	{ "truncate_log:%04d", SFI_TRUNCATE_LOG, 0, S_IFREG | 0644 }
+	{ "truncate_log:%04d", SFI_TRUNCATE_LOG, 0, S_IFREG | 0644 },
+	{ "aquota.user:%04d", SFI_QUOTA, 0, S_IFREG | 0644 },
+	{ "aquota.group:%04d", SFI_QUOTA, 0, S_IFREG | 0644 },
 };
 
 struct fs_type_translation {
@@ -226,6 +230,23 @@ static void mkfs_init_dir_trailer(State *s, DirData *dir, void *buf)
 	}
 }
 
+/* Should we skip this inode because of features enabled / disabled? */
+static int feature_skip(State *s, int system_inode)
+{
+	switch (system_inode) {
+		case USER_QUOTA_SYSTEM_INODE:
+		case LOCAL_USER_QUOTA_SYSTEM_INODE:
+			return !(s->feature_flags.opt_ro_compat &
+					OCFS2_FEATURE_RO_COMPAT_USRQUOTA);
+		case GROUP_QUOTA_SYSTEM_INODE:
+		case LOCAL_GROUP_QUOTA_SYSTEM_INODE:
+			return !(s->feature_flags.opt_ro_compat &
+					OCFS2_FEATURE_RO_COMPAT_GRPQUOTA);
+		default:
+			return 0;
+	}
+}
+
 static inline uint32_t system_dir_bytes_needed(State *s)
 {
 	int each = OCFS2_DIR_REC_LEN(SYSTEM_FILE_NAME_MAX);
@@ -233,6 +254,114 @@ static inline uint32_t system_dir_bytes_needed(State *s)
 	return each * sys_blocks_needed(s->initial_slots);
 }
 
+static void format_quota_files(State *s, ocfs2_filesys *fs)
+{
+	errcode_t ret;
+	ocfs2_quota_hash *usr_hash = NULL, *grp_hash = NULL;
+
+	/* Write correct data into quota files */
+	if (!feature_skip(s, USER_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global user quota file");
+			goto error;
+		}
+		fs->qinfo[USRQUOTA].flags = 0;
+		fs->qinfo[USRQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[USRQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[USRQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+
+		ret = ocfs2_new_quota_hash(&usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while creating user quota hash.");
+			goto error;
+		}
+		ret = ocfs2_init_global_quota_file(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret, "while creating global user "
+				"quota file");
+			goto error;
+		}
+		ret = ocfs2_init_local_quota_files(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while initializing local user quota files");
+			goto error;
+		}
+	}
+	if (!feature_skip(s, GROUP_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global group quota file");
+			goto error;
+		}
+		fs->qinfo[GRPQUOTA].flags = 0;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+		ret = ocfs2_new_quota_hash(&grp_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while creating group quota hash.");
+			goto error;
+		}
+		ret = ocfs2_init_global_quota_file(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret, "while creating global group "
+				"quota file");
+			goto error;
+		}
+
+		ret = ocfs2_init_local_quota_files(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while initializing local group quota files");
+			goto error;
+		}
+	}
+
+	ret = ocfs2_compute_quota_usage(fs, usr_hash, grp_hash);
+	if (ret) {
+		com_err(s->progname, ret, "while computing quota usage");
+		goto error;
+	}
+	if (usr_hash) {
+		ret = ocfs2_write_release_dquots(fs, USRQUOTA, usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while writing user quota usage");
+			goto error;
+		}
+		ret = ocfs2_free_quota_hash(usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while releasing user quota hash");
+			goto error;
+		}
+	}
+	if (grp_hash) {
+		ret = ocfs2_write_release_dquots(fs, GRPQUOTA, grp_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while writing group quota usage");
+			goto error;
+		}
+		ret = ocfs2_free_quota_hash(grp_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while releasing group quota hash");
+			goto error;
+		}
+	}
+	return;
+error:
+	clear_both_ends(s);
+	exit(1);
+}
+
 static void finish_normal_format(State *s)
 {
 	errcode_t ret;
@@ -304,6 +433,14 @@ static void finish_normal_format(State *s)
 	if (!s->quiet)
 		printf("done\n");
 
+	if (!s->quiet)
+		printf("Formatting quota files: ");
+
+	format_quota_files(s, fs);
+
+	if (!s->quiet)
+		printf("done\n");
+
 	ocfs2_close(fs);
 }
 
@@ -471,6 +608,8 @@ main(int argc, char **argv)
 	for (i = 0; i < NUM_SYSTEM_INODES; i++) {
 		if (hb_dev_skip(s, i))
 			continue;
+		if (feature_skip(s, i))
+			continue;
 
 		num = (system_files[i].global) ? 1 : s->initial_slots;
 		for (j = 0; j < num; j++) {
@@ -529,6 +668,8 @@ main(int argc, char **argv)
 	for (i = 0; i < NUM_SYSTEM_INODES; i++) {
 		if (hb_dev_skip(s, i))
 			continue;
+		if (feature_skip(s, i))
+			continue;
 
 		num = system_files[i].global ? 1 : s->initial_slots;
 		for (j = 0; j < num; j++) {
@@ -2432,6 +2573,9 @@ init_record(State *s, SystemFileDiskRecord *rec, int type, int mode)
 	case SFI_TRUNCATE_LOG:
 		rec->flags |= OCFS2_DEALLOC_FL;
 		break;
+	case SFI_QUOTA:
+		rec->flags |= OCFS2_QUOTA_FL;
+		break;
 	case SFI_OTHER:
 		break;
 	}
mkfs.ocfs2/mkfs.h +1 -0
index bd8ac45..969e4df 100644
@@ -96,6 +96,7 @@ enum {
 	SFI_HEARTBEAT,
 	SFI_CHAIN,
 	SFI_TRUNCATE_LOG,
+	SFI_QUOTA,
 	SFI_OTHER
 };
 
mkfs.ocfs2/mkfs.ocfs2.8.in +16 -0
index 38433ee..d1f4011 100644
@@ -146,6 +146,22 @@ arbitrary binary data. Attributes can be attached to all types of inodes: regula
 symbolic links, device nodes, etc. This feature is required for users wanting to use extended security
 facilities like POSIX ACLs or SELinux.
 .RE
+.RS 1.2i
+.TP
+\fBusrquota\fR
+Enable user quota support. With this feature enabled, filesystem will track amount of space
+and number of inodes (files, directories, symbolic links) each user owns. It is then possible
+to limit the maximum amount of space or inodes user can have. See a documentation of
+quota-tools package for more details.
+.RE
+.RS 1.2i
+.TP
+\fBgrpquota\fR
+Enable group quota support. With this feature enabled, filesystem will track amount of space
+and number of inodes (files, directories, symbolic links) each group owns. It is then possible
+to limit the maximum amount of space or inodes user can have. See a documentation of
+quota-tools package for more details.
+.RE
 
 .TP
 \fB\-\-fs\-feature\-level=\fR\fR\fIfeature\-level\fR
Signature · 1 line
1.6.0.2
#28 lore raw

PATCH 6/8 Quota support for mkfs.ocfs2

Looks good to me.

Quoted 332 lines · Jan Kara
Quoted 64 lines · Jan Kara

Hi,

Quoted 54 lines · Tao Ma
Quoted 53 lines · Jan Kara
---
 mkfs.ocfs2/mkfs.c          |  146 +++++++++++++++++++++++++++++++++++++++++++-
 mkfs.ocfs2/mkfs.h          |    1 +
 mkfs.ocfs2/mkfs.ocfs2.8.in |   16 +++++
 3 files changed, 162 insertions(+), 1 deletions(-)
mkfs.ocfs2/mkfs.c +42 -0
index 6acc6e6..8496d03 100644
+static void format_quota_files(State *s, ocfs2_filesys *fs)
+{
+	errcode_t ret;
+	ocfs2_quota_hash *usr_hash = NULL, *grp_hash = NULL;
+
+	/* Write correct data into quota files */
+	if (!feature_skip(s, USER_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global user quota file");
+			goto error;
+		}
+		fs->qinfo[USRQUOTA].flags = 0;
+		fs->qinfo[USRQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[USRQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[USRQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+
+		ret = ocfs2_new_quota_hash(&usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while creating user quota hash.");
+			goto error;
+		}
+		ret = ocfs2_init_global_quota_file(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret, "while creating global user "
+				"quota file");
+			goto error;
+		}
+		ret = ocfs2_init_local_quota_files(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while initializing local user quota files");
+			goto error;
+		}
+	}
+	if (!feature_skip(s, GROUP_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global group quota file");
Quoted 8 lines

mkfs.ocfs2/mkfs.c static inline uint32_t system_dir_bytes_needed(State *s)

Quoted 7 lines
mkfs.ocfs2/mkfs.c +7 -0
+			goto error;
+		}
+		fs->qinfo[GRPQUOTA].flags = 0;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+		ret = ocfs2_new_quota_hash(&usr_hash);

grp_hash here?

Quoted 2 lines

Good catch! Obviously I didn't check that the group usage was set correctly
:). Thanks for the review.

Below is an updated patch.

Signature · 3 lines
Jan Kara <[email protected]>
SUSE Labs, CR
---
Quoted 1 line

From 148eb11dc3e1de1907bb6069b8d976451a5ff54a Mon Sep 17 00:00:00 2001

From: Jan Kara <[email protected]>
Date: Mon, 27 Jul 2009 19:36:22 +0200
Subject: [PATCH 06/10] Quota support for mkfs.ocfs2

---
 mkfs.ocfs2/mkfs.c          |  146 +++++++++++++++++++++++++++++++++++++++++++-
 mkfs.ocfs2/mkfs.h          |    1 +
 mkfs.ocfs2/mkfs.ocfs2.8.in |   16 +++++
 3 files changed, 162 insertions(+), 1 deletions(-)
mkfs.ocfs2/mkfs.c +145 -1
index 6acc6e6..031b8a6 100644
@@ -98,12 +98,16 @@ static SystemFileInfo system_files[] = {
 	{ "slot_map", SFI_OTHER, 1, S_IFREG | 0644 },
 	{ "heartbeat", SFI_HEARTBEAT, 1, S_IFREG | 0644 },
 	{ "global_bitmap", SFI_CLUSTER, 1, S_IFREG | 0644 },
+	{ "aquota.user", SFI_QUOTA, 1, S_IFREG | 0644 },
+	{ "aquota.group", SFI_QUOTA, 1, S_IFREG | 0644 },
 	{ "orphan_dir:%04d", SFI_OTHER, 0, S_IFDIR | 0755 },
 	{ "extent_alloc:%04d", SFI_CHAIN, 0, S_IFREG | 0644 },
 	{ "inode_alloc:%04d", SFI_CHAIN, 0, S_IFREG | 0644 },
 	{ "journal:%04d", SFI_JOURNAL, 0, S_IFREG | 0644 },
 	{ "local_alloc:%04d", SFI_LOCAL_ALLOC, 0, S_IFREG | 0644 },
-	{ "truncate_log:%04d", SFI_TRUNCATE_LOG, 0, S_IFREG | 0644 }
+	{ "truncate_log:%04d", SFI_TRUNCATE_LOG, 0, S_IFREG | 0644 },
+	{ "aquota.user:%04d", SFI_QUOTA, 0, S_IFREG | 0644 },
+	{ "aquota.group:%04d", SFI_QUOTA, 0, S_IFREG | 0644 },
 };
 
 struct fs_type_translation {
@@ -226,6 +230,23 @@ static void mkfs_init_dir_trailer(State *s, DirData *dir, void *buf)
 	}
 }
 
+/* Should we skip this inode because of features enabled / disabled? */
+static int feature_skip(State *s, int system_inode)
+{
+	switch (system_inode) {
+		case USER_QUOTA_SYSTEM_INODE:
+		case LOCAL_USER_QUOTA_SYSTEM_INODE:
+			return !(s->feature_flags.opt_ro_compat &
+					OCFS2_FEATURE_RO_COMPAT_USRQUOTA);
+		case GROUP_QUOTA_SYSTEM_INODE:
+		case LOCAL_GROUP_QUOTA_SYSTEM_INODE:
+			return !(s->feature_flags.opt_ro_compat &
+					OCFS2_FEATURE_RO_COMPAT_GRPQUOTA);
+		default:
+			return 0;
+	}
+}
+
 static inline uint32_t system_dir_bytes_needed(State *s)
 {
 	int each = OCFS2_DIR_REC_LEN(SYSTEM_FILE_NAME_MAX);
@@ -233,6 +254,114 @@ static inline uint32_t system_dir_bytes_needed(State *s)
 	return each * sys_blocks_needed(s->initial_slots);
 }
 
+static void format_quota_files(State *s, ocfs2_filesys *fs)
+{
+	errcode_t ret;
+	ocfs2_quota_hash *usr_hash = NULL, *grp_hash = NULL;
+
+	/* Write correct data into quota files */
+	if (!feature_skip(s, USER_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global user quota file");
+			goto error;
+		}
+		fs->qinfo[USRQUOTA].flags = 0;
+		fs->qinfo[USRQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[USRQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[USRQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+
+		ret = ocfs2_new_quota_hash(&usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while creating user quota hash.");
+			goto error;
+		}
+		ret = ocfs2_init_global_quota_file(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret, "while creating global user "
+				"quota file");
+			goto error;
+		}
+		ret = ocfs2_init_local_quota_files(fs, USRQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while initializing local user quota files");
+			goto error;
+		}
+	}
+	if (!feature_skip(s, GROUP_QUOTA_SYSTEM_INODE)) {
+		ret = ocfs2_init_fs_quota_info(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while looking up global group quota file");
+			goto error;
+		}
+		fs->qinfo[GRPQUOTA].flags = 0;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_syncms = OCFS2_DEF_QUOTA_SYNC;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_bgrace = OCFS2_DEF_BLOCK_GRACE;
+		fs->qinfo[GRPQUOTA].qi_info.dqi_igrace = OCFS2_DEF_INODE_GRACE;
+		ret = ocfs2_new_quota_hash(&grp_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while creating group quota hash.");
+			goto error;
+		}
+		ret = ocfs2_init_global_quota_file(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret, "while creating global group "
+				"quota file");
+			goto error;
+		}
+
+		ret = ocfs2_init_local_quota_files(fs, GRPQUOTA);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while initializing local group quota files");
+			goto error;
+		}
+	}
+
+	ret = ocfs2_compute_quota_usage(fs, usr_hash, grp_hash);
+	if (ret) {
+		com_err(s->progname, ret, "while computing quota usage");
+		goto error;
+	}
+	if (usr_hash) {
+		ret = ocfs2_write_release_dquots(fs, USRQUOTA, usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while writing user quota usage");
+			goto error;
+		}
+		ret = ocfs2_free_quota_hash(usr_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while releasing user quota hash");
+			goto error;
+		}
+	}
+	if (grp_hash) {
+		ret = ocfs2_write_release_dquots(fs, GRPQUOTA, grp_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while writing group quota usage");
+			goto error;
+		}
+		ret = ocfs2_free_quota_hash(grp_hash);
+		if (ret) {
+			com_err(s->progname, ret,
+				"while releasing group quota hash");
+			goto error;
+		}
+	}
+	return;
+error:
+	clear_both_ends(s);
+	exit(1);
+}
+
 static void finish_normal_format(State *s)
 {
 	errcode_t ret;
@@ -304,6 +433,14 @@ static void finish_normal_format(State *s)
 	if (!s->quiet)
 		printf("done\n");
 
+	if (!s->quiet)
+		printf("Formatting quota files: ");
+
+	format_quota_files(s, fs);
+
+	if (!s->quiet)
+		printf("done\n");
+
 	ocfs2_close(fs);
 }
 
@@ -471,6 +608,8 @@ main(int argc, char **argv)
 	for (i = 0; i < NUM_SYSTEM_INODES; i++) {
 		if (hb_dev_skip(s, i))
 			continue;
+		if (feature_skip(s, i))
+			continue;
 
 		num = (system_files[i].global) ? 1 : s->initial_slots;
 		for (j = 0; j < num; j++) {
@@ -529,6 +668,8 @@ main(int argc, char **argv)
 	for (i = 0; i < NUM_SYSTEM_INODES; i++) {
 		if (hb_dev_skip(s, i))
 			continue;
+		if (feature_skip(s, i))
+			continue;
 
 		num = system_files[i].global ? 1 : s->initial_slots;
 		for (j = 0; j < num; j++) {
@@ -2432,6 +2573,9 @@ init_record(State *s, SystemFileDiskRecord *rec, int type, int mode)
 	case SFI_TRUNCATE_LOG:
 		rec->flags |= OCFS2_DEALLOC_FL;
 		break;
+	case SFI_QUOTA:
+		rec->flags |= OCFS2_QUOTA_FL;
+		break;
 	case SFI_OTHER:
 		break;
 	}
mkfs.ocfs2/mkfs.h +1 -0
index bd8ac45..969e4df 100644
@@ -96,6 +96,7 @@ enum {
 	SFI_HEARTBEAT,
 	SFI_CHAIN,
 	SFI_TRUNCATE_LOG,
+	SFI_QUOTA,
 	SFI_OTHER
 };
 
mkfs.ocfs2/mkfs.ocfs2.8.in +16 -0
index 38433ee..d1f4011 100644
@@ -146,6 +146,22 @@ arbitrary binary data. Attributes can be attached to all types of inodes: regula
 symbolic links, device nodes, etc. This feature is required for users wanting to use extended security
 facilities like POSIX ACLs or SELinux.
 .RE
+.RS 1.2i
+.TP
+\fBusrquota\fR
+Enable user quota support. With this feature enabled, filesystem will track amount of space
+and number of inodes (files, directories, symbolic links) each user owns. It is then possible
+to limit the maximum amount of space or inodes user can have. See a documentation of
+quota-tools package for more details.
+.RE
+.RS 1.2i
+.TP
+\fBgrpquota\fR
+Enable group quota support. With this feature enabled, filesystem will track amount of space
+and number of inodes (files, directories, symbolic links) each group owns. It is then possible
+to limit the maximum amount of space or inodes user can have. See a documentation of
+quota-tools package for more details.
+.RE
 
 .TP
 \fB\-\-fs\-feature\-level=\fR\fR\fIfeature\-level\fR
Signature · 1 line
1.6.0.2
Signature · 8 lines
"Behind every successful man there's a lot of unsuccessful years."
        - Bob Brown

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
author
#29 lore raw

PATCH 7/8 Add quota support to tunefs.ocfs2

In reply to Jan Kara

Implement setting of quota feature via tunefs.ocfs2 and also properly create / delete local quota files when number of slots increases / decreases. Implement setting of interval in which we sync changes in local quota file to the global quota file.

---
 tunefs.ocfs2/Makefile                     |    6 +-
 tunefs.ocfs2/feature_quota.c              |  418 +++++++++++++++++++++++++++++
 tunefs.ocfs2/ocfs2ne.c                    |   26 ++
 tunefs.ocfs2/op_features.c                |    4 +
 tunefs.ocfs2/op_set_quota_sync_interval.c |  170 ++++++++++++
 tunefs.ocfs2/op_set_slot_count.c          |   91 ++++++-
 6 files changed, 712 insertions(+), 3 deletions(-)
 create mode 100644 tunefs.ocfs2/feature_quota.c
 create mode 100644 tunefs.ocfs2/op_set_quota_sync_interval.c
tunefs.ocfs2/Makefile +4 -2
index fd244d8..d28da81 100644
@@ -24,7 +24,8 @@ OCFS2NE_FEATURES =			\
 	feature_metaecc			\
 	feature_sparse_files		\
 	feature_unwritten_extents	\
-	feature_xattr
+	feature_xattr			\
+	feature_quota
 
 OCFS2NE_OPERATIONS =			\
 	op_cloned_volume		\
@@ -36,7 +37,8 @@ OCFS2NE_OPERATIONS =			\
 	op_set_label			\
 	op_set_journal_size		\
 	op_set_slot_count		\
-	op_update_cluster_stack
+	op_update_cluster_stack		\
+	op_set_quota_sync_interval	\
 
 sbindir = $(root_sbindir)
 SBIN_PROGRAMS = tunefs.ocfs2
tunefs.ocfs2/feature_quota.c new file +418 -0

418 lines not on this page · raw message

tunefs.ocfs2/ocfs2ne.c +26 -0
index c9051a4..48760c6 100644
@@ -98,6 +98,8 @@ extern struct tunefs_operation set_label_op;
 extern struct tunefs_operation set_slot_count_op;
 extern struct tunefs_operation update_cluster_stack_op;
 extern struct tunefs_operation cloned_volume_op;
+extern struct tunefs_operation set_usrquota_sync_interval_op;
+extern struct tunefs_operation set_grpquota_sync_interval_op;
 
 /* List of operations we're going to run */
 static LIST_HEAD(tunefs_run_list);
@@ -583,6 +585,28 @@ static struct tunefs_option journal_option = {
 	.opt_handle	= handle_journal_arg,
 };
 
+static struct tunefs_option set_usrquota_sync_interval_option = {
+	.opt_option	= {
+		.name		= "usrquota-sync-interval",
+		.val		= 256,
+		.has_arg	= 1,
+	},
+	.opt_help	= "   --usrquota-sync-interval <interval>",
+	.opt_handle	= generic_handle_arg,
+	.opt_op		= &set_usrquota_sync_interval_op,
+};
+
+static struct tunefs_option set_grpquota_sync_interval_option = {
+	.opt_option	= {
+		.name		= "grpquota-sync-interval",
+		.val		= 257,
+		.has_arg	= 1,
+	},
+	.opt_help	= "   --grpquota-sync-interval <interval>",
+	.opt_handle	= generic_handle_arg,
+	.opt_op		= &set_grpquota_sync_interval_op,
+};
+
 /* The order here creates the order in print_usage() */
 static struct tunefs_option *options[] = {
 	&help_option,
@@ -603,6 +627,8 @@ static struct tunefs_option *options[] = {
 	&features_option,
 	&update_cluster_stack_option,
 	&cloned_volume_option,
+	&set_usrquota_sync_interval_option,
+	&set_grpquota_sync_interval_option,
 	&yes_option,
 	&no_option,
 	NULL,
tunefs.ocfs2/op_features.c +4 -0
index ee9442e..afcc1f4 100644
@@ -41,6 +41,8 @@ extern struct tunefs_feature metaecc_feature;
 extern struct tunefs_feature sparse_files_feature;
 extern struct tunefs_feature unwritten_extents_feature;
 extern struct tunefs_feature xattr_feature;
+extern struct tunefs_feature usrquota_feature;
+extern struct tunefs_feature grpquota_feature;
 
 /* List of features supported by ocfs2ne */
 static struct tunefs_feature *features[] = {
@@ -52,6 +54,8 @@ static struct tunefs_feature *features[] = {
 	&sparse_files_feature,
 	&unwritten_extents_feature,
 	&xattr_feature,
+	&usrquota_feature,
+	&grpquota_feature,
 	NULL,
 };
 
tunefs.ocfs2/op_set_quota_sync_interval.c new file +170 -0

170 lines not on this page · raw message

tunefs.ocfs2/op_set_slot_count.c +90 -1

127 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#30 lore raw

PATCH 7/8 Add quota support to tunefs.ocfs2

Quoted 6 lines · Jan Kara

Implement setting of quota feature via tunefs.ocfs2 and also properly create / delete local quota files when number of slots increases / decreases. Implement setting of interval in which we sync changes in local quota file to the global quota file.

Looks good, I think.

Signature · 10 lines
"Baby, even the losers
 Get luck sometimes.
 Even the losers
 Keep a little bit of pride."

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
author
#31 lore raw

PATCH 8/8 Change headers to reflect that quota is now fully supported.

In reply to Jan Kara
---
 include/ocfs2-kernel/ocfs2_fs.h |    4 +++-
 libocfs2/feature_string.c       |    4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
include/ocfs2-kernel/ocfs2_fs.h +3 -1
index ad655dc..32a4d91 100644
@@ -96,7 +96,9 @@
 					 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
 					 | OCFS2_FEATURE_INCOMPAT_META_ECC \
 					 | OCFS2_FEATURE_INCOMPAT_XATTR)
-#define OCFS2_FEATURE_RO_COMPAT_SUPP	OCFS2_FEATURE_RO_COMPAT_UNWRITTEN
+#define OCFS2_FEATURE_RO_COMPAT_SUPP	(OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
+					 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
+					 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
 
 /*
  * Heartbeat-only devices are missing journals and other files.  The
libocfs2/feature_string.c +3 -1
index 18ae6e9..cf3a0dd 100644
@@ -76,7 +76,9 @@ static ocfs2_fs_options feature_level_defaults[] = {
 	 OCFS2_FEATURE_INCOMPAT_INLINE_DATA |
 	 OCFS2_FEATURE_INCOMPAT_META_ECC |
 	 OCFS2_FEATURE_INCOMPAT_XATTR,
-	 OCFS2_FEATURE_RO_COMPAT_UNWRITTEN}, /* OCFS2_FEATURE_LEVEL_MAX_FEATURES */
+	 OCFS2_FEATURE_RO_COMPAT_UNWRITTEN |
+	 OCFS2_FEATURE_RO_COMPAT_USRQUOTA |
+	 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA }, /* OCFS2_FEATURE_LEVEL_MAX_FEATURES */
 };
 
 /* These are the features we support in mkfs/tunefs via --fs-features */
Signature · 1 line
1.6.0.2