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

From: Tigran Aivazian (tigran@veritas.com)
Date: Mon Apr 24 2000 - 10:38:40 EST


On Sun, 23 Apr 2000, Linus Torvalds wrote:
> This is insane.
>
> It makes no sense to pass in "tsk". If you want to mess with somebodys
> files, you pass in "struct files_struct", not "struct task_struct". Which
> would clean up the code more, anyway.
>
> Linus

yes, you are right - struct task_struct is one extra level of abstraction
away so passing 'struct files_struct' doesn't restrict being as generic as
possible.

Patch remade, tested and attached. Also, I removed declarations of
connecting_fifo_ops and floppy_is_wp() from <linux/fs.h> as they are not
needed (any more).

Regards,
Tigran

diff -urN -X dontdiff linux/fs/open.c doclose/fs/open.c
--- linux/fs/open.c Sat Apr 22 10:30:24 2000
+++ doclose/fs/open.c Mon Apr 24 16:17:40 2000
@@ -756,13 +756,20 @@
         return error;
 }
 
+inline void __put_unused_fd(struct files_struct *files, unsigned int fd)
+{
+ FD_CLR(fd, files->open_fds);
+ if (fd < files->next_fd)
+ 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;
- write_unlock(&current->files->file_lock);
+ struct files_struct *files = current->files;
+
+ write_lock(&files->file_lock);
+ __put_unused_fd(files, fd);
+ write_unlock(&files->file_lock);
 }
 
 asmlinkage long sys_open(const char * filename, int flags, int mode)
@@ -852,9 +859,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(files, fd);
+ write_unlock(&files->file_lock);
         lock_kernel();
         error = filp_close(filp, files);
         unlock_kernel();
diff -urN -X dontdiff linux/include/linux/fs.h doclose/include/linux/fs.h
--- linux/include/linux/fs.h Sat Apr 22 10:30:25 2000
+++ doclose/include/linux/fs.h Mon Apr 24 16:29:33 2000
@@ -848,7 +848,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 files_struct *, unsigned int); /* locked outside */
+extern void put_unused_fd(unsigned int); /* locked inside */
 
 extern struct file *filp_open(const char *, int, int);
 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
@@ -886,7 +887,6 @@
 extern void make_bad_inode(struct inode *);
 extern int is_bad_inode(struct inode *);
 
-extern struct file_operations connecting_fifo_fops;
 extern struct file_operations read_fifo_fops;
 extern struct file_operations write_fifo_fops;
 extern struct file_operations rdwr_fifo_fops;
@@ -955,7 +955,6 @@
 #define invalidate_buffers(dev) __invalidate_buffers((dev), 0)
 #define destroy_buffers(dev) __invalidate_buffers((dev), 1)
 extern void __invalidate_buffers(kdev_t dev, int);
-extern int floppy_is_wp(int);
 extern void sync_inodes(kdev_t);
 extern void write_inode_now(struct inode *);
 extern void sync_dev(kdev_t);

-
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 30 2000 - 21:00:07 EST