[patch-2.3.99-pre6-5] __put_unused_fd()/put_unused_fd() improved

From: Tigran Aivazian (tigran@veritas.com)
Date: Sun Apr 23 2000 - 13:49:26 EST


Hi Linus,

I have redone the previous patch "do_close optimization" in a
hopefully better way - namely, adding a 'struct task_struct *tsk' argument
to __put_unused_fd and making put_unused_fd(fd) call
__put_unused_fd(current, fd). I think it is a good idea to allow things
like __put_unused_fd() (see patch below) to be called outside of 'current'
context, e.g. when you want to mess with some other process' descriptors.

Strictly speaking there should be four things:

__put_unused_fd_task(tsk, fd)
__put_unused_fd(fd)
put_unused_fd_task(tsk, fd)
put_unused_fd(fd)

but only two seem immediately useful so I did not implement the other two.

Regards,
Tigran

--- linux/include/linux/fs.h Sat Apr 22 10:30:25 2000
+++ close/include/linux/fs.h Sun Apr 23 19:34:59 2000
@@ -25,6 +25,7 @@
 #include <asm/bitops.h>
 
 struct poll_table_struct;
+struct task_struct; /* for __put_unused_fd */
 
 
 /*
@@ -848,7 +849,8 @@
 extern int do_close(unsigned int, int); /* yes, it's really unsigned */
 extern int do_truncate(struct dentry *, loff_t start);
 extern int get_unused_fd(void);
-extern void put_unused_fd(unsigned int);
+extern void __put_unused_fd(struct task_struct *, unsigned int); /* locked by the caller */
+extern void put_unused_fd(unsigned int); /* locked internally */
 
 extern struct file *filp_open(const char *, int, int);
 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
--- linux/fs/open.c Sat Apr 22 10:30:24 2000
+++ close/fs/open.c Sun Apr 23 19:44:55 2000
@@ -756,12 +756,17 @@
         return error;
 }
 
+inline void __put_unused_fd(struct task_struct *tsk, unsigned int fd)
+{
+ FD_CLR(fd, tsk->files->open_fds);
+ if (fd < tsk->files->next_fd)
+ tsk->files->next_fd = fd;
+}
+
 inline void put_unused_fd(unsigned int fd)
 {
         write_lock(&current->files->file_lock);
- FD_CLR(fd, current->files->open_fds);
- if (fd < current->files->next_fd)
- current->files->next_fd = fd;
+ __put_unused_fd(current, fd);
         write_unlock(&current->files->file_lock);
 }
 
@@ -852,9 +857,9 @@
         if (!filp)
                 goto out_unlock;
         FD_CLR(fd, files->close_on_exec);
- write_unlock(&files->file_lock);
         if (release)
- put_unused_fd(fd);
+ __put_unused_fd(current, fd);
+ write_unlock(&files->file_lock);
         lock_kernel();
         error = filp_close(filp, files);
         unlock_kernel();

-
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 : Sun Apr 23 2000 - 21:00:22 EST