Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8880863ybl; Wed, 25 Dec 2019 08:21:26 -0800 (PST) X-Google-Smtp-Source: APXvYqz4JYtwOxqefcFb3XJkflhW8TZm8QjwjI1S3sSbUCgftTk/U/8zyAQrhTs7RZMvG7XIl5f8 X-Received: by 2002:a9d:8cb:: with SMTP id 69mr30037991otf.221.1577290886139; Wed, 25 Dec 2019 08:21:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577290886; cv=none; d=google.com; s=arc-20160816; b=fe+At8m7ccXjAQviDeD9Dpz7vOuRwjVRpWK098xWIqDyxYjBfxJZO9ja1a/3i4XECJ qViXLZ8nUhJFmtuxxsE2zr9B8by/JHnz7U8dcgYcf92cRG/FR47/qIK4PQwBCvM7p9Rd 7tUwoMlZshFSDH5oUKRvQ1oWm7AWzIbHVma9bFjvcoz75dlltrhG84Zjwji62C5tZxTi unurfImBYggDGYpc0vATycnaHFGlEpa31XWME9bB3PEIxGz3H3iOQ22BrTtX6/lp7miV bdVdv9WP8lLineS9oWXKWz7ZOI9j228zRJ9k5BlmhAWCdjO7ea2XjivPXELedJEldGq8 /qKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8s0w8TBgWM2nbjYBoNRR4RnivYkypQwA/VXobpZQpUY=; b=f1H4AwT/urHWoQJf6gQp4eGtqPpSV45lzG9rr/arB+GnOrfGuwnLn8gHSZccpazcnK dTqDLln3HBWXgLSf7ouSYK3dLXU8b4m50TSQgRUm3/2SHtn2/KvRrjbwr67lNbUuq3tv ztzOd/NoO6I40k4sDtMBtAcLzky2bHPhCf5hALcO4H2hozzs+G6XpLDMyc2cxWFD1I57 ibsH3JXKZ164ENdsrqK3gu/gNZOB7Bo2knd3pqGurIUhfV1jM3TayeFd+DIFV5jEDD+g TypJLDF6diWLJWxdh+VgXscBzl3G77y0Bz4NcWaf69eL37Sihtphev/3Dm5kh3DH/lxT TFLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si13021398oiv.267.2019.12.25.08.21.03; Wed, 25 Dec 2019 08:21:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726489AbfLYQTi (ORCPT + 99 others); Wed, 25 Dec 2019 11:19:38 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:56086 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726353AbfLYQTi (ORCPT ); Wed, 25 Dec 2019 11:19:38 -0500 Received: from p5b2a6d5f.dip0.t-ipconnect.de ([91.42.109.95] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ik9Nm-0002F2-HI; Wed, 25 Dec 2019 16:19:34 +0000 Date: Wed, 25 Dec 2019 17:19:33 +0100 From: Christian Brauner To: Sargun Dhillon Cc: linux-kernel@vger.kernel.org, containers@lists.linux-foundation.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, tycho@tycho.ws, jannh@google.com, cyphar@cyphar.com, oleg@redhat.com, luto@amacapital.net, viro@zeniv.linux.org.uk, gpascutto@mozilla.com, ealvarez@mozilla.com, fweimer@redhat.com, jld@mozilla.com, arnd@arndb.de Subject: Re: [PATCH v6 1/3] vfs, fdtable: Add get_task_file helper Message-ID: <20191225161932.fhvbgrcco36mhvaw@wittgenstein> References: <20191223210852.GA25101@ircssh-2.c.rugged-nimbus-611.internal> <20191223212645.3qw7my4u4rjihxjf@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191223212645.3qw7my4u4rjihxjf@wittgenstein> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 23, 2019 at 10:26:46PM +0100, Christian Brauner wrote: > On Mon, Dec 23, 2019 at 09:08:55PM +0000, Sargun Dhillon wrote: > > This introduces a function which can be used to fetch a file, given an > > arbitrary task. As long as the user holds a reference (refcnt) to the > > task_struct it is safe to call, and will either return NULL on failure, > > or a pointer to the file, with a refcnt. > > > > Signed-off-by: Sargun Dhillon Could you please add: Suggested-by: Oleg Nesterov and add a line like: "This is based on a patch sent by Oleg (cf. [1]) a while ago." [1]: Link: https://lore.kernel.org/r/20180915160423.GA31461@redhat.com apart from a few nits below: Acked-by: Christian Brauner > > --- > > fs/file.c | 22 ++++++++++++++++++++-- > > include/linux/file.h | 2 ++ > > 2 files changed, 22 insertions(+), 2 deletions(-) > > > > diff --git a/fs/file.c b/fs/file.c > > index 2f4fcf985079..0ceeb046f4f3 100644 > > --- a/fs/file.c > > +++ b/fs/file.c > > @@ -706,9 +706,9 @@ void do_close_on_exec(struct files_struct *files) > > spin_unlock(&files->file_lock); > > } > > > > -static struct file *__fget(unsigned int fd, fmode_t mask, unsigned int refs) > > +static struct file *__fget_files(struct files_struct *files, unsigned int fd, > > + fmode_t mask, unsigned int refs) > > { > > - struct files_struct *files = current->files; > > struct file *file; > > > > rcu_read_lock(); > > @@ -729,6 +729,11 @@ static struct file *__fget(unsigned int fd, fmode_t mask, unsigned int refs) > > return file; > > } > > > > +static struct file *__fget(unsigned int fd, fmode_t mask, unsigned int refs) This can be: static inline struct file *__fget(...) > > +{ > > + return __fget_files(current->files, fd, mask, refs); > > +} > > + > > struct file *fget_many(unsigned int fd, unsigned int refs) > > { > > return __fget(fd, FMODE_PATH, refs); > > @@ -746,6 +751,19 @@ struct file *fget_raw(unsigned int fd) > > } > > EXPORT_SYMBOL(fget_raw); > > > > +struct file *fget_task(struct task_struct *task, unsigned int fd) > > +{ > > + struct file *file = NULL; > > + > > + task_lock(task); > > + if (task->files) > > + file = __fget_files(task->files, fd, 0, 1); > > + > > + task_unlock(task); > > Nit: remove the \n: > > task_lock(task); > if (task->files) > file = __fget_files(task->files, fd, 0, 1); > task_unlock(task); > > Christian