Commit 3734a13b authored by Michael Kerrisk (man-pages)'s avatar Michael Kerrisk (man-pages) Committed by Linus Torvalds

pipe: refactor argument for account_pipe_buffers()

This is a preparatory patch for following work. account_pipe_buffers()
performs accounting in the 'user_struct'. There is no need to pass a
pointer to a 'pipe_inode_info' struct (which is then dereferenced to
obtain a pointer to the 'user' field). Instead, pass a pointer directly
to the 'user_struct'. This change is needed in preparation for a
subsequent patch that the fixes the limit checking in alloc_pipe_info()
(and the resulting code is a little more logical).

Link: http://lkml.kernel.org/r/7277bf8c-a6fc-4a7d-659c-f5b145c981ab@gmail.comSigned-off-by: default avatarMichael Kerrisk <mtk.manpages@gmail.com>
Reviewed-by: default avatarVegard Nossum <vegard.nossum@oracle.com>
Cc: Willy Tarreau <w@1wt.eu>
Cc: <socketpair@gmail.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Jens Axboe <axboe@fb.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d37d4166
...@@ -601,10 +601,10 @@ pipe_fasync(int fd, struct file *filp, int on) ...@@ -601,10 +601,10 @@ pipe_fasync(int fd, struct file *filp, int on)
return retval; return retval;
} }
static void account_pipe_buffers(struct pipe_inode_info *pipe, static void account_pipe_buffers(struct user_struct *user,
unsigned long old, unsigned long new) unsigned long old, unsigned long new)
{ {
atomic_long_add(new - old, &pipe->user->pipe_bufs); atomic_long_add(new - old, &user->pipe_bufs);
} }
static bool too_many_pipe_buffers_soft(struct user_struct *user) static bool too_many_pipe_buffers_soft(struct user_struct *user)
...@@ -641,7 +641,7 @@ struct pipe_inode_info *alloc_pipe_info(void) ...@@ -641,7 +641,7 @@ struct pipe_inode_info *alloc_pipe_info(void)
pipe->r_counter = pipe->w_counter = 1; pipe->r_counter = pipe->w_counter = 1;
pipe->buffers = pipe_bufs; pipe->buffers = pipe_bufs;
pipe->user = user; pipe->user = user;
account_pipe_buffers(pipe, 0, pipe_bufs); account_pipe_buffers(user, 0, pipe_bufs);
mutex_init(&pipe->mutex); mutex_init(&pipe->mutex);
return pipe; return pipe;
} }
...@@ -656,7 +656,7 @@ void free_pipe_info(struct pipe_inode_info *pipe) ...@@ -656,7 +656,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
{ {
int i; int i;
account_pipe_buffers(pipe, pipe->buffers, 0); account_pipe_buffers(pipe->user, pipe->buffers, 0);
free_uid(pipe->user); free_uid(pipe->user);
for (i = 0; i < pipe->buffers; i++) { for (i = 0; i < pipe->buffers; i++) {
struct pipe_buffer *buf = pipe->bufs + i; struct pipe_buffer *buf = pipe->bufs + i;
...@@ -1077,7 +1077,7 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long arg) ...@@ -1077,7 +1077,7 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long arg)
memcpy(bufs + head, pipe->bufs, tail * sizeof(struct pipe_buffer)); memcpy(bufs + head, pipe->bufs, tail * sizeof(struct pipe_buffer));
} }
account_pipe_buffers(pipe, pipe->buffers, nr_pages); account_pipe_buffers(pipe->user, pipe->buffers, nr_pages);
pipe->curbuf = 0; pipe->curbuf = 0;
kfree(pipe->bufs); kfree(pipe->bufs);
pipe->bufs = bufs; pipe->bufs = bufs;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment