Skip to contentSkip to conversation

Bind VFS Mount Quota (2.4.22)

PATCH Herbert Pötzl 1 participant 1 message Jul 22, 2003

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi Everyone!

This patch is based on the Quota Hash Abstraction patch and considered a simple foundation for further per mount point quota development.

for now, it only supports ext2 and simple propagation, although support for other filesystems should be trivial and straight forward (only one unused 32bit field is required to make it work)

also there are currently no tools available to get/set the quota information, but quotactl is extended to work on mountpoints as well as devices ...

enjoy,
Herbert

PS: if you have any questions regarding this patch, feel
free to contact me ...

;
; Bind VFS Mount Quota
;
; utilizing the quota hash abstraction done in mq-0.06 ; this patch adds per vfsmount (--bind) quota for ext2. ;
; how it works:
; each bind mount of type quota, creates his own quota domain, ; which is propagated down from the mnt_root to each entry ; below (currently not on lookup, only on create)
;
; # mount -t quota --bind /mnt/somedir /mnt/somedir
;
; for now only ext2 is supported, but support for other ; filesystems should be trivial and straight forward. ;
; (C) 2003 Herbert Pötzl <[email protected]>
;
; Changelog:
;
; 0.02 - first public release
;
; 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 +3 -0
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/drivers/char/sysrq.c linux-2.4.22-pre7-mq0.06-bq0.02/drivers/char/sysrq.c
@@ -146,6 +146,7 @@
 	if (remount_flag) { /* Remount R/O */
 		int ret, flags;
 		struct list_head *p;
+		struct dqhash *dqh;
 
 		if (sb->s_flags & MS_RDONLY) {
 			printk("R/O\n");
@@ -161,6 +162,8 @@
 		}
 		file_list_unlock();
 		DQUOT_OFF(sb->s_dqh);
+		list_for_each_entry(dqh, &sb->s_dqhashes, dqh_list)
+		    	DQUOT_OFF(dqh);
 		fsync_dev(sb->s_dev);
 		flags = MS_RDONLY;
 		if (sb->s_op && sb->s_op->remount_fs) {
fs/buffer.c +3 -0
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/fs/buffer.c linux-2.4.22-pre7-mq0.06-bq0.02/fs/buffer.c
@@ -331,12 +331,15 @@
 
 int fsync_super(struct super_block *sb)
 {
+	struct dqhash *dqh;
 	kdev_t dev = sb->s_dev;
 	sync_buffers(dev, 0);
 
 	lock_kernel();
 	sync_inodes_sb(sb);
 	DQUOT_SYNC_DQH(sb->s_dqh);
+	list_for_each_entry(dqh, &sb->s_dqhashes, dqh_list)
+	    	DQUOT_SYNC_DQH(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 +96 -43

251 lines not on this page · raw message

fs/ext2/ialloc.c +2 -0
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/fs/ext2/ialloc.c linux-2.4.22-pre7-mq0.06-bq0.02/fs/ext2/ialloc.c
@@ -392,6 +392,8 @@
 	inode->u.ext2_i.i_block_group = group;
 	ext2_set_inode_flags(inode);
 	insert_inode_hash(inode);
+	
+	dqdom_cond_modify(inode, dir->i_dqdom); /* is this wise? */
 	inode->i_generation = event++;
 	mark_inode_dirty(inode);
 
fs/ext2/inode.c +2 -0
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/fs/ext2/inode.c linux-2.4.22-pre7-mq0.06-bq0.02/fs/ext2/inode.c
@@ -969,6 +969,7 @@
 	inode->i_blksize = PAGE_SIZE;	/* This is the optimal IO size (for stat), not the fs block size */
 	inode->i_blocks = le32_to_cpu(raw_inode->i_blocks);
 	inode->i_version = ++event;
+    	inode->i_dqdom = le32_to_cpu(raw_inode->i_raw_dqdom);
 	inode->u.ext2_i.i_flags = le32_to_cpu(raw_inode->i_flags);
 	inode->u.ext2_i.i_faddr = le32_to_cpu(raw_inode->i_faddr);
 	inode->u.ext2_i.i_frag_no = raw_inode->i_frag;
@@ -1091,6 +1092,7 @@
 		raw_inode->i_uid_high = 0;
 		raw_inode->i_gid_high = 0;
 	}
+	raw_inode->i_raw_dqdom = cpu_to_le32(inode->i_dqdom);
 	raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
 	raw_inode->i_size = cpu_to_le32(inode->i_size);
 	raw_inode->i_atime = cpu_to_le32(inode->i_atime);
fs/ext2/ioctl.c +3 -0
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/fs/ext2/ioctl.c linux-2.4.22-pre7-mq0.06-bq0.02/fs/ext2/ioctl.c
@@ -70,6 +70,9 @@
 		inode->i_ctime = CURRENT_TIME;
 		mark_inode_dirty(inode);
 		return 0;
+	case EXT2_IOC_GETDQDOM:
+		/* fixme: if stealth, return -ENOTTY */
+		return put_user(inode->i_dqdom, (int *) arg);
 	default:
 		return -ENOTTY;
 	}
fs/inode.c +4 -1
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/fs/inode.c linux-2.4.22-pre7-mq0.06-bq0.02/fs/inode.c
@@ -95,7 +95,6 @@
 		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;
@@ -113,6 +112,8 @@
 		inode->i_pipe = NULL;
 		inode->i_bdev = NULL;
 		inode->i_cdev = NULL;
+		inode->i_dqh = dqhget(sb->s_dqh);   /* this is the default */
+		inode->i_dqdom = 0;
 
 		mapping->a_ops = &empty_aops;
 		mapping->host = inode;
@@ -124,6 +125,8 @@
 
 static void destroy_inode(struct inode *inode) 
 {
+    	if (inode->i_dqh)
+	    	dqhput(inode->i_dqh);
 	if (inode_has_buffers(inode))
 		BUG();
 	if (inode->i_sb->s_op->destroy_inode)
fs/namei.c +11 -0
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/fs/namei.c linux-2.4.22-pre7-mq0.06-bq0.02/fs/namei.c
@@ -306,6 +306,7 @@
 				dput(dentry);
 			else
 				result = dentry;
+			dqdom_lookup_update(dir, dentry);
 		}
 		up(&dir->i_sem);
 		return result;
@@ -974,6 +975,8 @@
 	DQUOT_INIT(dir);
 	lock_kernel();
 	error = dir->i_op->create(dir, dentry, mode);
+	if (!error)
+		dqdom_cond_update(dir, dentry);
 	unlock_kernel();
 exit_lock:
 	up(&dir->i_zombie);
@@ -1481,6 +1484,8 @@
 			else {
 				lock_kernel();
 				error = dir->i_op->unlink(dir, dentry);
+				if (!error)
+					dqdom_unlink_update(dir, dentry); /* special? */
 				unlock_kernel();
 				if (!error)
 					d_delete(dentry);
@@ -1551,6 +1556,8 @@
 	DQUOT_INIT(dir);
 	lock_kernel();
 	error = dir->i_op->symlink(dir, dentry, oldname);
+	if (!error)
+		dqdom_cond_update(dir, dentry);  /* not portable? */
 	unlock_kernel();
 
 exit_lock:
@@ -1624,6 +1631,8 @@
 	DQUOT_INIT(dir);
 	lock_kernel();
 	error = dir->i_op->link(old_dentry, dir, new_dentry);
+	if (!error)
+		dqdom_cond_update(dir, new_dentry);
 	unlock_kernel();
 
 exit_lock:
@@ -1899,6 +1908,8 @@
 	lock_kernel();
 	error = vfs_rename(old_dir->d_inode, old_dentry,
 				   new_dir->d_inode, new_dentry);
+	if (!error)
+		dqdom_cond_update(new_dir->d_inode, old_dentry);
 	unlock_kernel();
 
 	dput(new_dentry);
fs/namespace.c +17 -3
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/fs/namespace.c linux-2.4.22-pre7-mq0.06-bq0.02/fs/namespace.c
@@ -140,6 +140,7 @@
 		mnt->mnt_flags = old->mnt_flags;
 		atomic_inc(&sb->s_active);
 		mnt->mnt_sb = sb;
+		mnt->mnt_dqh = dqhget(sb->s_dqh);
 		mnt->mnt_root = dget(root);
 		mnt->mnt_mountpoint = mnt->mnt_root;
 		mnt->mnt_parent = mnt;
@@ -150,6 +151,7 @@
 void __mntput(struct vfsmount *mnt)
 {
 	struct super_block *sb = mnt->mnt_sb;
+    	dqhput(mnt->mnt_dqh);
 	dput(mnt->mnt_root);
 	free_vfsmnt(mnt);
 	kill_super(sb);
@@ -270,6 +272,7 @@
 		list_add(&p->mnt_list, &kill);
 	}
 
+	DQUOT_OFF(mnt->mnt_dqh);
 	while (!list_empty(&kill)) {
 		mnt = list_entry(kill.next, struct vfsmount, mnt_list);
 		list_del_init(&mnt->mnt_list);
@@ -337,7 +340,7 @@
 		/* last instance - try to be smart */
 		spin_unlock(&dcache_lock);
 		lock_kernel();
-		DQUOT_OFF(sb->s_dqh);
+		DQUOT_OFF(mnt->mnt_dqh);
 		acct_auto_close(sb->s_dev);
 		unlock_kernel();
 		spin_lock(&dcache_lock);
@@ -476,6 +479,7 @@
 		err = 0;
 	}
 	spin_unlock(&dcache_lock);
+	/* do we need something here? */
 out_unlock:
 	up(&nd->dentry->d_inode->i_zombie);
 	return err;
@@ -484,7 +488,7 @@
 /*
  * do loopback mount.
  */
-static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
+static int do_loopback(struct nameidata *nd, char *old_name, char *type, int recurse)
 {
 	struct nameidata old_nd;
 	struct vfsmount *mnt = NULL;
@@ -508,6 +512,16 @@
 	}
 
 	if (mnt) {
+		char *dom_info = strstr(type, "quota");
+		unsigned long dqdom = 0;
+		
+		/* disable if not capable? */
+		if (dom_info) { /* start new quota domain */
+		    	dqdom = mnt->mnt_mountpoint->d_inode->i_ino;
+			dqhput(mnt->mnt_dqh);
+			mnt->mnt_dqh = get_dqhash(mnt->mnt_sb, dqdom);
+	    	    	dqdom_modify(mnt->mnt_root->d_inode, dqdom);
+		}
 		err = graft_tree(mnt, nd);
 		if (err) {
 			spin_lock(&dcache_lock);
@@ -733,7 +747,7 @@
 		retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
 				    data_page);
 	else if (flags & MS_BIND)
-		retval = do_loopback(&nd, dev_name, flags & MS_REC);
+		retval = do_loopback(&nd, dev_name, type_page, flags & MS_REC);
 	else if (flags & MS_MOVE)
 		retval = do_move_mount(&nd, dev_name);
 	else
fs/quota.c +34 -1
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/fs/quota.c linux-2.4.22-pre7-mq0.06-bq0.02/fs/quota.c
@@ -133,6 +133,35 @@
 	return ERR_PTR(ret);
 }
 
+/* Resolve mount pathname to dqhash */
+static struct dqhash *resolve_mnt(const char *path)
+{
+	int ret;
+	mode_t mode;
+	struct nameidata nd;
+	kdev_t dev;
+	struct dqhash *dqh;
+
+	ret = user_path_walk(path, &nd);
+	if (ret)
+		goto out;
+
+	dev = nd.dentry->d_inode->i_rdev;
+	mode = nd.dentry->d_inode->i_mode;
+	path_release(&nd);
+
+	ret = -ENOTBLK;
+	if (!S_ISDIR(mode))
+		goto out;
+	ret = -ENODEV;	/* compatible, but correct? */
+	dqh = nd.dentry->d_inode->i_dqh;
+	if (!dqh)
+		goto out;
+	return dqh;
+out:
+	return ERR_PTR(ret);
+}
+
 /* Copy parameters and call proper function */
 static int do_quotactl(struct dqhash *hash, int type, int cmd, qid_t id, caddr_t addr)
 {
@@ -472,7 +501,11 @@
 	if (cmds != Q_V1_GETSTATS && cmds != Q_V2_GETSTATS && IS_ERR(sb = resolve_dev(special))) {
 		ret = PTR_ERR(sb);
 		sb = NULL;
-		goto out;
+		/* maybe only a mountpoint was specified? */
+		if (IS_ERR(dqh = resolve_mnt(special))) {
+		    	ret = PTR_ERR(dqh);
+	    	    	goto out;
+		}
 	}
 	else if (sb)
 	    	dqh = sb->s_dqh;
fs/super.c +7 -3
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/fs/super.c linux-2.4.22-pre7-mq0.06-bq0.02/fs/super.c
@@ -271,6 +271,7 @@
 		INIT_LIST_HEAD(&s->s_locked_inodes);
 		INIT_LIST_HEAD(&s->s_files);
 		INIT_LIST_HEAD(&s->s_instances);
+		INIT_LIST_HEAD(&s->s_dqhashes);
 		init_rwsem(&s->s_umount);
 		sema_init(&s->s_lock, 1);
 		down_write(&s->s_umount);
@@ -280,8 +281,7 @@
 		sema_init(&s->s_nfsd_free_path_sem,1);
 		s->s_maxbytes = MAX_NON_LFS;
 		s->s_op = &empty_sops;
-   	    	/* quick hack to make dqhash id unique, sufficient for now */
-		s->s_dqh = new_dqhash(s, (unsigned int)s);
+		s->s_dqh = new_dqhash(s, 0);
 	}
 	return s;
 }
@@ -294,7 +294,10 @@
  */
 static inline void destroy_super(struct super_block *s)
 {
-    	destroy_dqhash(s->s_dqh);
+    	dqhput(s->s_dqh);
+	
+	if (!list_empty(&s->s_dqhashes))
+	    	BUG();
 	kfree(s);
 }
 
@@ -810,6 +813,7 @@
 	if (type->fs_flags & FS_NOMOUNT)
 		sb->s_flags |= MS_NOUSER;
 	mnt->mnt_sb = sb;
+	mnt->mnt_dqh = dqhget(sb->s_dqh);
 	mnt->mnt_root = dget(sb->s_root);
 	mnt->mnt_mountpoint = sb->s_root;
 	mnt->mnt_parent = mnt;
include/linux/ext2_fs.h +3 -2
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/include/linux/ext2_fs.h linux-2.4.22-pre7-mq0.06-bq0.02/include/linux/ext2_fs.h
@@ -210,6 +210,7 @@
 #define	EXT2_IOC_SETFLAGS		_IOW('f', 2, long)
 #define	EXT2_IOC_GETVERSION		_IOR('v', 1, long)
 #define	EXT2_IOC_SETVERSION		_IOW('v', 2, long)
+#define	EXT2_IOC_GETDQDOM               _IOR('d', 1, long)
 
 /*
  * Structure of an inode on the disk
@@ -249,7 +250,7 @@
 			__u16	i_pad1;
 			__u16	l_i_uid_high;	/* these 2 fields    */
 			__u16	l_i_gid_high;	/* were reserved2[0] */
-			__u32	l_i_reserved2;
+			__u32	l_i_dqdom;
 		} linux2;
 		struct {
 			__u8	h_i_frag;	/* Fragment number */
@@ -278,7 +279,7 @@
 #define i_gid_low	i_gid
 #define i_uid_high	osd2.linux2.l_i_uid_high
 #define i_gid_high	osd2.linux2.l_i_gid_high
-#define i_reserved2	osd2.linux2.l_i_reserved2
+#define i_raw_dqdom	osd2.linux2.l_i_dqdom
 #endif
 
 #ifdef	__hurd__
include/linux/fs.h +3 -1
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/include/linux/fs.h linux-2.4.22-pre7-mq0.06-bq0.02/include/linux/fs.h
@@ -477,6 +477,7 @@
 	struct block_device	*i_bdev;
 	struct char_device	*i_cdev;
 
+	unsigned long		i_dqdom;          /* last diskquota domain */
 	unsigned long		i_dnotify_mask; /* Directory notify events */
 	struct dnotify_struct	*i_dnotify; /* for directory notifications */
 
@@ -759,7 +760,8 @@
 
 	struct block_device	*s_bdev;
 	struct list_head	s_instances;
-	struct dqhash	    	*s_dqh;	    	/* Diskquota hash */
+	struct dqhash	    	*s_dqh;
+	struct list_head	s_dqhashes;   	/* Diskquota hashes */
 
 	union {
 		struct minix_sb_info	minix_sb;
include/linux/quota.h +23 -4
diff -NurP --minimal linux-2.4.22-pre7-mq0.06/include/linux/quota.h linux-2.4.22-pre7-mq0.06-bq0.02/include/linux/quota.h
@@ -314,19 +314,35 @@
 struct dqhash {
 	struct list_head dqh_list;	/* List of all quota hashes */
 	unsigned int dqh_id;		/* ID for hash */
+	int dqh_count;			/* Use count */
 	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 */
     	struct list_head dqh_hash[NR_DQHASH];
+	unsigned long dqh_dqdom;	/* Diskquota domain */
 };
 
 #if defined(CONFIG_QUOTA)
 
-
-struct dqhash *new_dqhash(struct super_block *, unsigned int);
+struct dqhash *new_dqhash(struct super_block *, unsigned long);
+struct dqhash *get_dqhash(struct super_block *, unsigned long);
+struct dqhash *get_existing_dqhash(struct super_block *, unsigned long);
 void destroy_dqhash(struct dqhash *);
-struct dqhash *find_dqhash(unsigned int);
+
+static inline void dqhput(struct dqhash *hash)
+{
+	if (--hash->dqh_count > 0)
+	    	return;
+    	destroy_dqhash(hash);
+}
+
+static inline struct dqhash *dqhget(struct dqhash *hash)
+{
+	hash->dqh_count++;
+    	return hash; 
+}
+
 
 static inline void mark_dquot_dirty(struct dquot *dq)
 {
@@ -337,9 +353,12 @@
 #else /* CONFIG_QUOTA */
 
 #define new_dqhash(sb, dqdom)		(0)
-#define find_dqhash(dqdom)		(0)
+#define get_dqhash(sb, dqdom)		(0)
 #define destroy_dqhash(hash)		do { } while(0)
 
+#define dqhput(hash)			do { } while(0)
+#define dqhget(hash)			(hash)
+
 #endif /* CONFIG_QUOTA */
 
 #else
include/linux/quotaops.h +80 -0

98 lines not on this page · raw message