(Please cc: me, I'm not subscribed.)
This experimental patch allows quotas to be used in /dev/pts filesystem, so
that the system administrator can limit number of ptys a user can allocate.
The inode freeing part is probably wrong, I got 'inode count wrapped' messages.
Any ideas?
The setup:
$ grep pts /etc/fstab
/dev/devpts /dev/pts devpts noatime,nosuid,noexec,gid=5,mode=600,us
rquota=/mnt/devpts.quota.user,rsquash,ro 0 0
$ ls -l /dev/devpts
brw------- 1 root root 0, 3 Jun 4 23:50 /dev/devpts
Example use:
$ quota -v |grep pts
/dev/devpts 0 0 0 10* 10 10 none
$ script
/dev/pts: write failed, user file limit reached
openpty failed
Terminated
The patch is against 2.2.15 + devfs.
-Topi
diff -ru fs/devpts/inode.c.orig fs/devpts/inode.c
--- fs/devpts/inode.c.orig Fri Aug 21 04:33:50 1998
+++ fs/devpts/inode.c Sun Jun 4 23:22:59 2000
@@ -21,6 +21,7 @@
#include <linux/malloc.h>
#include <linux/stat.h>
#include <linux/tty.h>
+#include <linux/quotaops.h>
#include <asm/bitops.h>
#include <asm/uaccess.h>
@@ -111,6 +112,11 @@
if (*value)
return 1;
}
+ else if (!strcmp(this_char,"usrquota")
+ || !strcmp(this_char,"grpquota")
+ || !strcmp(this_char,"rsquash")) {
+ ;
+ }
else
return 1;
}
@@ -302,7 +308,7 @@
NULL
};
-void devpts_pty_new(int number, kdev_t device)
+int devpts_pty_new(int number, kdev_t device)
{
struct super_block *sb;
struct devpts_sb_info *sbi;
@@ -324,8 +330,17 @@
inode->i_rdev = device;
inode->i_nlink++;
sbi->inodes[number] = inode;
+
+ if (DQUOT_ALLOC_INODE(sb, inode)) {
+ if (sb->dq_op)
+ sb->dq_op->drop(inode);
+ inode->i_nlink = 0;
+ iput(inode);
+ return -EDQUOT;
+ }
}
}
+ return 0;
}
void devpts_pty_kill(int number)
@@ -340,6 +355,8 @@
inode = sbi->inodes[number];
if ( inode ) {
+ DQUOT_FREE_INODE(sb, inode);
+ DQUOT_DROP(inode);
sbi->inodes[number] = NULL;
inode->i_nlink--;
iput(inode);
diff -ru include/linux/devpts_fs.h.orig include/linux/devpts_fs.h
--- include/linux/devpts_fs.h.orig Sat May 6 18:02:45 2000
+++ include/linux/devpts_fs.h Sun Jun 4 23:32:26 2000
@@ -25,14 +25,14 @@
#ifdef CONFIG_DEVPTS_FS
-void devpts_pty_new(int, kdev_t);
+int devpts_pty_new(int, kdev_t);
void devpts_pty_kill(int);
#define unix98_max_ptys NR_PTYS * UNIX98_NR_MAJORS;
#elif defined(CONFIG_DEVPTS_FS_MODULE)
#ifdef BUILDING_PTY_C
-void (*devpts_upcall_new)(int,kdev_t) = NULL;
+int (*devpts_upcall_new)(int,kdev_t) = NULL;
void (*devpts_upcall_kill)(int) = NULL;
unsigned int unix98_max_ptys = NR_PTYS * UNIX98_NR_MAJORS;
@@ -46,7 +46,7 @@
#endif
#ifndef BUILDING_DEVPTS
-extern inline void
+extern inline int
devpts_pty_new(int line, kdev_t device)
{
if ( devpts_upcall_new )
@@ -63,8 +63,8 @@
#else /* No /dev/pts filesystem at all */
-extern inline void
-devpts_pty_new(int line, kdev_t device) { }
+extern inline int
+devpts_pty_new(int line, kdev_t device) { return 0; }
extern inline void
devpts_pty_kill(int line) { }
diff -ru drivers/char/tty_io.c.orig drivers/char/tty_io.c
--- drivers/char/tty_io.c.orig Sat May 6 17:56:06 2000
+++ drivers/char/tty_io.c Sun Jun 4 23:41:37 2000
@@ -1331,7 +1331,12 @@
ptmx_found:
set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
minor -= driver->minor_start;
- devpts_pty_new(driver->other->name_base + minor, MKDEV(driver->other->
major, minor + driver->other->minor_start));
+ retval = devpts_pty_new(driver->other->name_base + minor, MKDEV(driver->
other->major, minor + driver->other->minor_start));
+ if (retval) {
+ filp->private_data = tty;
+ release_dev(filp);
+ return retval; /* quota exceeded */
+ }
tty_register_devfs(&pts_driver[major], 0,
pts_driver[major].minor_start + minor);
noctty = 1;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Wed Jun 07 2000 - 21:00:19 EST