Quota Hash Abstraction 2.4.22 cleanup
Subsystems (4)
Hi Everyone!
This is third patch, which can be considered a cleanup. (although some bugs where fixed ;)
Basically some routines (invalidate_dquots, new_dqhash) where adapted to the new hash abstraction, and a sane environment (dummy code) if CONFIG_QUOTA is disabled, was added.
please, if somebody has any quota tests, which he/she is willing to do on this code, or just want to do some testing with this code, do it and send me the results ...
attached a interdiff between 0.05 and 0.06 as well as the new 0.06 patch (for 2.4.22-pre7).
TIA,
Herbert
fs/dquot.c +45 -42
@@ -345,32 +345,33 @@* inuse list, we don't have to restart searching... */ static void invalidate_dquots (struct dqhash *hash,int type) { -struct dquot *dquot; -struct list_head *head; +int i; -restart: -/* this could be optimized! (easily?) */ -list_for_each (head, &inuse_list) { - dquot = list_entry(head, struct dquot, dq_inuse); -if (dquot->dq_dqh != hash) -continue ; -if (dquot->dq_type != type) -continue ; - dquot->dq_flags |=DQ_INVAL ; -if (dquot->dq_count) -/* -* Wait for any users of quota. As we have already cleared the flags in -* superblock and cleared all pointers from inodes we are assured -* that there will be no new users of this quota. -*/ -__wait_dquot_unused (dquot); -/* Quota now have no users and it has been written on last dqput() */ -remove_dquot_hash (dquot); -remove_free_dquot (dquot); -remove_inuse (dquot); -kmem_cache_free (dquot_cachep, dquot); -/* hmm, somebody changed his mind? */ - goto restart; +for (i=0 ; i<NR_DQHASH ; i++) { +struct list_head *head = &hash->dqh_hash[i]; + +while ((head = head->next) != &hash->dqh_hash[i]) { + struct dquot *dquot = list_entry(head, struct dquot, dq_hash); + +if (dquot->dq_type != type) +continue ; + dquot->dq_flags |=DQ_INVAL ; + +if (dquot->dq_count) +/* +* Wait for any users of quota. As we have already cleared the flags in +* superblock and cleared all pointers from inodes we are assured +* that there will be no new users of this quota. +*/ +__wait_dquot_unused (dquot); + +remove_dquot_hash (dquot); +remove_free_dquot (dquot); +remove_inuse (dquot); +kmem_cache_free (dquot_cachep, dquot); +/* now restart */ + head = &hash->dqh_hash[i]; + } } }
@@ -379,27 +380,30 @@static LIST_HEAD (dqhash_list); -struct dqhash *new_dqhash (unsigned int id) +struct dqhash *new_dqhash (struct super_block *sb,unsigned int id) { -struct dqhash *hash; +struct dqhash *hash;int i; hash =kmalloc (sizeof (struct dqhash ),GFP_USER ); -if (hash) { -memset (hash,0 ,sizeof (struct dqhash )); - hash->dqh_id = id; -INIT_LIST_HEAD (&hash->dqh_list); -for (i =0 ; i <NR_DQHASH ; i++) -INIT_LIST_HEAD (hash->dqh_hash + i); -sema_init (&hash->dqh_dquot.dqio_sem,1 ); -sema_init (&hash->dqh_dquot.dqoff_sem,1 ); - hash->dqh_qop = &dquot_operations; - hash->dqh_qcop = &vfs_quotactl_ops; - } +if (!hash) +return ERR_PTR (-ENOMEM ); + +memset (hash,0 ,sizeof (struct dqhash )); + hash->dqh_id = id; +INIT_LIST_HEAD (&hash->dqh_list); +for (i =0 ; i <NR_DQHASH ; i++) +INIT_LIST_HEAD (hash->dqh_hash + i); +sema_init (&hash->dqh_dqopt.dqio_sem,1 ); +sema_init (&hash->dqh_dqopt.dqoff_sem,1 ); + hash->dqh_qop = &dquot_operations; + hash->dqh_qcop = &vfs_quotactl_ops; + hash->dqh_sb = sb; +lock_kernel ();list_add (&hash->dqh_list, &dqhash_list);unlock_kernel (); -// printk ("new dqhash %p\n", hash); +dprintk ("··· new_dqhash: %p [#%d,#0x%lx]\n" , hash, hash->dqh_id, hash->dqh_dqdom);return hash; }
@@ -407,9 +411,9 @@ {int cnt; -// printk ("destroy dqhash %p\n", hash); +dprintk ("··· destroy_dqhash: %p [#%d,#0x%lx]\n" , hash, hash->dqh_id, hash->dqh_dqdom);lock_kernel (); -list_del (&hash->dqh_list); +list_del_init (&hash->dqh_list);unlock_kernel ();for (cnt =0 ; cnt <MAXQUOTAS ; cnt++)invalidate_dquots (hash, cnt);
@@ -747,7 +751,6 @@return 0 ; } -/*when, where and why is this called? */ static void add_dquot_ref (struct dqhash *hash,int type) {struct list_head *p;
fs/inode.c +3 -3
@@ -1213,7 +1213,7 @@struct super_block *sb = hash->dqh_sb;LIST_HEAD (tofree_head); -if (hash->dqh_qop) +if (!hash->dqh_qop)return ;/* nothing to do */ /* We have to be protected against other CPUs */ lock_kernel ();/* This lock is for quota code */
@@ -1231,12 +1231,12 @@ }list_for_each (act_head, &sb->s_dirty) { inode = list_entry(act_head, struct inode, i_list); -if (IS_QUOTAINIT (inode)) +if (inode->i_dqh == hash &&IS_QUOTAINIT (inode))remove_inode_dquot_ref (inode, type, &tofree_head); }list_for_each (act_head, &sb->s_locked_inodes) { inode = list_entry(act_head, struct inode, i_list); -if (IS_QUOTAINIT (inode)) +if (inode->i_dqh == hash &&IS_QUOTAINIT (inode))remove_inode_dquot_ref (inode, type, &tofree_head); }spin_unlock (&inode_lock);
fs/quota.c +7 -6
@@ -248,29 +248,29 @@switch (cmd) {case Q_COMP_QUOTAON : -if (!hash->dqh_qcop->quota_on) +if (!hash || !hash->dqh_qcop->quota_on)return -ENOSYS ;break ;case Q_COMP_QUOTAOFF : -if (!hash->dqh_qcop->quota_off) +if (!hash || !hash->dqh_qcop->quota_off)return -ENOSYS ;break ;case Q_COMP_SYNC : -if (hash && !hash->dqh_qcop->quota_sync) +if (!hash || !hash->dqh_qcop->quota_sync)return -ENOSYS ;break ;case Q_V1_SETQLIM :case Q_V1_SETUSE :case Q_V1_SETQUOTA : -if (!hash->dqh_qcop->set_dqblk) +if (!hash || !hash->dqh_qcop->set_dqblk)return -ENOSYS ;break ;case Q_V1_GETQUOTA : -if (!hash->dqh_qcop->get_dqblk) +if (!hash || !hash->dqh_qcop->get_dqblk)return -ENOSYS ;break ;case Q_V1_RSQUASH : -if (!hash->dqh_qcop->set_info) +if (!hash || !hash->dqh_qcop->set_info)return -ENOSYS ;break ;case Q_V1_GETSTATS :
@@ -301,6 +301,7 @@if (cmd !=Q_COMP_QUOTAON && cmd !=Q_COMP_QUOTAOFF && cmd !=Q_COMP_SYNC && + hash &&dqh_dqopt (hash)->info[type].dqi_format->qf_fmt_id !=QFMT_VFS_OLD )return -ESRCH ;
include/linux/quota.h +17 -6
@@ -182,7 +182,7 @@#define info_any_dirty (info) ((info)->dqi_flags & DQF_INFO_DIRTY ||\ (info)->dqi_flags & DQF_ANY_DQUOT_DIRTY) -#define dqh_dqopt (dqh) (&(dqh)->dqh_dquot) +#define dqh_dqopt (dqh) (&(dqh)->dqh_dqopt)struct dqstats {int lookups;
@@ -197,7 +197,7 @@extern struct dqstats dqstats; -#define NR_DQHASH 43/* Just an arbitrary number */ +#define NR_DQHASH 13/* Just an arbitrary number */ #define DQ_LOCKED 0x01/* dquot under IO */ #define DQ_MOD 0x02/* dquot modified since read */
@@ -312,16 +312,19 @@void init_dquot_operations (struct dquot_operations *fsdqops);struct dqhash { -unsigned int dqh_id;/* ID for hash */ -struct quota_info dqh_dquot;/* Diskquota specific options */ struct list_head dqh_list;/* List of all quota hashes */ +unsigned int dqh_id;/* ID for hash */ +struct quota_info dqh_dqopt;/* Diskquota specific options */ struct dquot_operations *dqh_qop;struct quotactl_ops *dqh_qcop; -struct super_block *dqh_sb;/* super block if applicable */ +struct super_block *dqh_sb;/* super block */ struct list_head dqh_hash[NR_DQHASH ]; }; -struct dqhash *new_dqhash (unsigned int ); +#if defined(CONFIG_QUOTA ) + + +struct dqhash *new_dqhash (struct super_block *,unsigned int );void destroy_dqhash (struct dqhash *);struct dqhash *find_dqhash (unsigned int );
@@ -331,6 +334,14 @@dqh_dqopt (dq->dq_dqh)->info[dq->dq_type].dqi_flags |=DQF_ANY_DQUOT_DIRTY ; } +#else /* CONFIG_QUOTA */ + +#define new_dqhash (sb, dqdom) (0) +#define find_dqhash (dqdom) (0) +#define destroy_dqhash (hash) do { } while(0) + +#endif /* CONFIG_QUOTA */ +#else # /* nodep */ include <sys/cdefs.h>
include/linux/quotaops.h +3 -0
@@ -17,6 +17,8 @@#include <linux/fs.h> +#define dprintk (...) +/* * declaration of quota_function calls in kernel. */
@@ -189,6 +191,7 @@#define DQUOT_SYNC_DQH (hash) do { } while(0)#define DQUOT_OFF (sb) do { } while(0)#define DQUOT_TRANSFER (inode, iattr) (0) +extern __inline__int DQUOT_PREALLOC_SPACE_NODIRTY (struct inode *inode,qsize_t nr) {lock_kernel ();
;
; Quota Hash Abstraction
;
; separate quota hashes per superblock to speed up ; hash lookups and generalize the quota hash interface. ;
; (C) 2003 Herbert Pötzl <[email protected]> ;
; Changelog:
;
; 0.04 - first public release ; 0.05 - trivial fix (lost temp variable) ; - some required locking added ; 0.06 - cleanup of invalidate_dquots ; - cleanup of new_dqhash ; - remove_dquot_ref restricted to hash ; - check_compat_quotactl_valid checks for hash ; - added dummy code for CONFIG_QUOTA disabled
;
; this patch 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 patch 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.
;
drivers/char/sysrq.c +1 -1
@@ -160,7 +160,7 @@ file->f_mode &= ~2 ; }file_list_unlock (); -DQUOT_OFF (sb); +DQUOT_OFF (sb->s_dqh);fsync_dev (sb->s_dev); flags =MS_RDONLY ;if (sb->s_op && sb->s_op->remount_fs) {
fs/buffer.c +1 -1
@@ -336,7 +336,7 @@lock_kernel ();sync_inodes_sb (sb); -DQUOT_SYNC_SB (sb); +DQUOT_SYNC_DQH (sb->s_dqh);lock_super (sb);if (sb->s_dirt && sb->s_op && sb->s_op->write_super) sb->s_op->write_super (sb);
fs/dquot.c +174 -103
621 lines not on this page · raw message
fs/ext3/super.c +2 -2
@@ -1131,7 +1131,7 @@* set up enough so that it can read an inode */ sb->s_op = &ext3_sops; - sb->dq_op = &ext3_qops; + sb->s_dqh->dqh_qop = &ext3_qops;INIT_LIST_HEAD (&sbi->s_orphan);/* unlinked but open files */ sb->s_root =0 ;
@@ -1783,7 +1783,7 @@ {int nblocks, ret;handle_t *handle; -struct quota_info *dqops =sb_dqopt (dquot->dq_sb); +struct quota_info *dqops =dqh_dqopt (dquot->dq_dqh);struct inode *qinode;switch (dqops->info[dquot->dq_type].dqi_format->qf_fmt_id) {
fs/inode.c +8 -6
@@ -95,6 +95,7 @@struct address_space *const mapping = &inode->i_data; inode->i_sb = sb; + inode->i_dqh = sb->s_dqh;/* this is the default */ inode->i_dev = sb->s_dev; inode->i_blkbits = sb->s_blocksize_bits; inode->i_flags =0 ;
@@ -1205,13 +1206,14 @@void put_dquot_list (struct list_head *);int remove_inode_dquot_ref (struct inode *,short ,struct list_head *); -void remove_dquot_ref (struct super_block *sb,short type) +void remove_dquot_ref (struct dqhash *hash,short type) {struct inode *inode;struct list_head *act_head; +struct super_block *sb = hash->dqh_sb;LIST_HEAD (tofree_head); -if (!sb->dq_op) +if (!hash->dqh_qop)return ;/* nothing to do */ /* We have to be protected against other CPUs */ lock_kernel ();/* This lock is for quota code */
@@ -1219,22 +1221,22 @@list_for_each (act_head, &inode_in_use) { inode = list_entry(act_head, struct inode, i_list); -if (inode->i_sb == sb &&IS_QUOTAINIT (inode)) +if (inode->i_dqh == hash &&IS_QUOTAINIT (inode))remove_inode_dquot_ref (inode, type, &tofree_head); }list_for_each (act_head, &inode_unused) { inode = list_entry(act_head, struct inode, i_list); -if (inode->i_sb == sb &&IS_QUOTAINIT (inode)) +if (inode->i_dqh == hash &&IS_QUOTAINIT (inode))remove_inode_dquot_ref (inode, type, &tofree_head); }list_for_each (act_head, &sb->s_dirty) { inode = list_entry(act_head, struct inode, i_list); -if (IS_QUOTAINIT (inode)) +if (inode->i_dqh == hash &&IS_QUOTAINIT (inode))remove_inode_dquot_ref (inode, type, &tofree_head); }list_for_each (act_head, &sb->s_locked_inodes) { inode = list_entry(act_head, struct inode, i_list); -if (IS_QUOTAINIT (inode)) +if (inode->i_dqh == hash &&IS_QUOTAINIT (inode))remove_inode_dquot_ref (inode, type, &tofree_head); }spin_unlock (&inode_lock);
fs/namespace.c +1 -1
@@ -337,7 +337,7 @@/* last instance - try to be smart */ spin_unlock (&dcache_lock);lock_kernel (); -DQUOT_OFF (sb); +DQUOT_OFF (sb->s_dqh);acct_auto_close (sb->s_dev);unlock_kernel ();spin_lock (&dcache_lock);
fs/quota.c +64 -59
376 lines not on this page · raw message
fs/quota_v1.c +11 -11
@@ -42,7 +42,7 @@loff_t offset;struct v1_disk_dqblk dqblk; - filp =sb_dqopt (dquot->dq_sb)->files[type]; + filp =dqh_dqopt (dquot->dq_dqh)->files[type];if (filp == (struct file *)NULL )return -EINVAL ;
@@ -71,7 +71,7 @@ssize_t ret;struct v1_disk_dqblk dqblk; - filp =sb_dqopt (dquot->dq_sb)->files[type]; + filp =dqh_dqopt (dquot->dq_dqh)->files[type]; offset =v1_dqoff (dquot->dq_id); fs =get_fs ();set_fs (KERNEL_DS );
@@ -83,8 +83,8 @@v1_mem2disk_dqblk (&dqblk, &dquot->dq_dqb); dquot->dq_flags &= ~DQ_MOD ;if (dquot->dq_id ==0 ) { - dqblk.dqb_btime =sb_dqopt (dquot->dq_sb)->info[type].dqi_bgrace; - dqblk.dqb_itime =sb_dqopt (dquot->dq_sb)->info[type].dqi_igrace; + dqblk.dqb_btime =dqh_dqopt (dquot->dq_dqh)->info[type].dqi_bgrace; + dqblk.dqb_itime =dqh_dqopt (dquot->dq_dqh)->info[type].dqi_igrace; } ret =0 ;if (filp)
@@ -117,9 +117,9 @@__u32 dqh_version;/* File version */ }; -static int v1_check_quota_file (struct super_block *sb,int type) +static int v1_check_quota_file (struct dqhash *hash,int type) { -struct file *f =sb_dqopt (sb)->files[type]; +struct file *f =dqh_dqopt (hash)->files[type];struct inode *inode = f->f_dentry->d_inode;ulong blocks;size_t off;
@@ -144,13 +144,13 @@return 1 ;/* Probably not new format */ if (le32_to_cpu (dqhead.dqh_magic) != quota_magics[type])return 1 ;/* Definitely not new format */ -printk (KERN_INFO "VFS: %s: Refusing to turn on old quota format on given file. It probably contains newer quota format.\n" ,kdevname (sb->s_dev)); +printk (KERN_INFO "VFS: %s: Refusing to turn on old quota format on given file. It probably contains newer quota format.\n" ,kdevname (hash->dqh_sb->s_dev));return 0 ;/* Seems like a new format file -> refuse it */ } -static int v1_read_file_info (struct super_block *sb,int type) +static int v1_read_file_info (struct dqhash *hash,int type) { -struct quota_info *dqopt =sb_dqopt (sb); +struct quota_info *dqopt =dqh_dqopt (hash);mm_segment_t fs;loff_t offset;struct file *filp = dqopt->files[type];
@@ -175,9 +175,9 @@return ret; } -static int v1_write_file_info (struct super_block *sb,int type) +static int v1_write_file_info (struct dqhash *hash,int type) { -struct quota_info *dqopt =sb_dqopt (sb); +struct quota_info *dqopt =dqh_dqopt (hash);mm_segment_t fs;struct file *filp = dqopt->files[type];struct v1_disk_dqblk dqblk;
fs/quota_v2.c +21 -21
118 lines not on this page · raw message
fs/super.c +3 -4
@@ -278,12 +278,10 @@atomic_set (&s->s_active,1 );sema_init (&s->s_vfs_rename_sem,1 );sema_init (&s->s_nfsd_free_path_sem,1 ); -sema_init (&s->s_dquot.dqio_sem,1 ); -sema_init (&s->s_dquot.dqoff_sem,1 ); s->s_maxbytes =MAX_NON_LFS ; s->s_op = &empty_sops; - s->dq_op = sb_dquot_ops; - s->s_qcop = sb_quotactl_ops; +/* quick hack to make dqhash id unique, sufficient for now */ + s->s_dqh =new_dqhash (s, (unsigned int )s); }return s; }
@@ -296,6 +294,7 @@*/ static inline void destroy_super (struct super_block *s) { +destroy_dqhash (s->s_dqh);kfree (s); }
fs/udf/super.c +1 -1
@@ -1435,7 +1435,7 @@/* Fill in the rest of the superblock */ sb->s_op = &udf_sb_ops; - sb->dq_op =NULL ; + sb->s_dqh->dqh_qop =NULL ; sb->s_dirt =0 ; sb->s_magic =UDF_SUPER_MAGIC ;
fs/ufs/super.c +1 -1
@@ -744,7 +744,7 @@ sb->s_blocksize =fs32_to_cpu (sb, usb1->fs_fsize); sb->s_blocksize_bits =fs32_to_cpu (sb, usb1->fs_fshift); sb->s_op = &ufs_super_ops; - sb->dq_op =NULL ;/***/ + sb->s_dqh->dqh_qop =NULL ;/***/ sb->s_magic =fs32_to_cpu (sb, usb3->fs_magic); uspi->s_sblkno =fs32_to_cpu (sb, usb1->fs_sblkno);
include/linux/fs.h +2 -3
@@ -469,6 +469,7 @@struct file_lock *i_flock;struct address_space *i_mapping;struct address_space i_data; +struct dqhash *i_dqh;struct dquot *i_dquot[MAXQUOTAS ];/* These three should probably be a union */ struct list_head i_devices;
@@ -744,8 +745,6 @@unsigned long long s_maxbytes;/* Max file size */ struct file_system_type *s_type;struct super_operations *s_op; -struct dquot_operations *dq_op; -struct quotactl_ops *s_qcop;unsigned long s_flags;unsigned long s_magic;struct dentry *s_root;
@@ -760,7 +759,7 @@struct block_device *s_bdev;struct list_head s_instances; -struct quota_info s_dquot;/* Diskquota specific options */ +struct dqhash *s_dqh;/* Diskquota hash */ union {struct minix_sb_info minix_sb;
include/linux/mount.h +1 -0
@@ -29,6 +29,7 @@int mnt_flags;char *mnt_devname;/* Name of device e.g. /dev/dsk/hda1 */ struct list_head mnt_list; +struct dqhash *mnt_dqh;/* Diskquota hash for mount */ };static inline struct vfsmount *mntget (struct vfsmount *mnt)
include/linux/quota.h +54 -27
129 lines not on this page · raw message
include/linux/quotaops.h +26 -28
146 lines not on this page · raw message