* [PATCH] Rework /proc/locks via seq_files and seq_list helpers (v2)
@ 2007-09-20 8:45 Pavel Emelyanov
2007-09-20 8:46 ` Pavel Emelyanov
0 siblings, 1 reply; 2+ messages in thread
From: Pavel Emelyanov @ 2007-09-20 8:45 UTC (permalink / raw)
To: Andrew Morton; +Cc: J. Bruce Fields, Linux Kernel Mailing List, devel
Currently /proc/locks is shown with a proc_read function, but
its behavior is rather complex as it has to manually handle
current offset and buffer length. On the other hand, files
that show objects from lists can be easily reimplemented using
the sequential files and the seq_list_XXX() helpers.
This saves (as usually) 16 lines of code and more than 200 from
the .text section.
This patch looks rather ugly, as diff often uses curly braces
as not-changed lines, but I haven't managed to organize the
code to make diff look better. Except for move the whole proc
related stuff upper/lower in the locks.c file...
Fixed the problem, spotted by J. Bruce Fields, about the fl
variable reuse.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
---
diff --git a/fs/locks.c b/fs/locks.c
index a1c1c01..d5b9653 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1354,6 +1354,7 @@ int fcntl_getlease(struct file *filp)
int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
{
struct file_lock *fl, **before, **my_before = NULL, *lease;
+ struct file_lock *new_fl = NULL;
struct dentry *dentry = filp->f_path.dentry;
struct inode *inode = dentry->d_inode;
int error, rdlease_count = 0, wrlease_count = 0;
@@ -1380,6 +1381,11 @@ int generic_setlease(struct file *filp,
|| (atomic_read(&inode->i_count) > 1)))
goto out;
+ error = -ENOMEM;
+ new_fl = locks_alloc_lock();
+ if (new_fl == NULL)
+ goto out;
+
/*
* At this point, we know that if there is an exclusive
* lease on this file, then we hold it on this filp
@@ -1422,18 +1428,15 @@ int generic_setlease(struct file *filp,
if (!leases_enable)
goto out;
- error = -ENOMEM;
- fl = locks_alloc_lock();
- if (fl == NULL)
- goto out;
-
- locks_copy_lock(fl, lease);
-
- locks_insert_lock(before, fl);
+ locks_copy_lock(new_fl, lease);
+ locks_insert_lock(before, new_fl);
*flp = fl;
- error = 0;
+ return 0;
+
out:
+ if (new_fl != NULL)
+ locks_free_lock(new_fl);
return error;
}
EXPORT_SYMBOL(generic_setlease);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Rework /proc/locks via seq_files and seq_list helpers (v2)
2007-09-20 8:45 [PATCH] Rework /proc/locks via seq_files and seq_list helpers (v2) Pavel Emelyanov
@ 2007-09-20 8:46 ` Pavel Emelyanov
0 siblings, 0 replies; 2+ messages in thread
From: Pavel Emelyanov @ 2007-09-20 8:46 UTC (permalink / raw)
To: Andrew Morton; +Cc: J. Bruce Fields, Linux Kernel Mailing List, devel
Pavel Emelyanov wrote:
> Currently /proc/locks is shown with a proc_read function, but
> its behavior is rather complex as it has to manually handle
> current offset and buffer length. On the other hand, files
> that show objects from lists can be easily reimplemented using
> the sequential files and the seq_list_XXX() helpers.
>
> This saves (as usually) 16 lines of code and more than 200 from
> the .text section.
>
> This patch looks rather ugly, as diff often uses curly braces
> as not-changed lines, but I haven't managed to organize the
> code to make diff look better. Except for move the whole proc
> related stuff upper/lower in the locks.c file...
>
> Fixed the problem, spotted by J. Bruce Fields, about the fl
> variable reuse.
>
> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
OOPS! Please disregard, wrong comment was copied :(
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-09-20 8:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-20 8:45 [PATCH] Rework /proc/locks via seq_files and seq_list helpers (v2) Pavel Emelyanov
2007-09-20 8:46 ` Pavel Emelyanov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox