From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932107AbbI1IVP (ORCPT ); Mon, 28 Sep 2015 04:21:15 -0400 Received: from forward-corp1g.mail.yandex.net ([95.108.253.251]:51469 "EHLO forward-corp1g.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756816AbbI1IVN (ORCPT ); Mon, 28 Sep 2015 04:21:13 -0400 Authentication-Results: smtpcorp4.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: Re: [PATCH 0/1] ns: introduce proc_get_ns_by_fd() To: Oleg Nesterov References: <20150925135246.27620.97496.stgit@buzz> <20150925175654.GA12504@redhat.com> Cc: linux-api@vger.kernel.org, containers@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Roman Gushchin , Serge Hallyn , "Eric W. Biederman" , Chen Fan , Andrew Morton , Linus Torvalds , =?UTF-8?Q?St=c3=a9phane_Graber?= From: Konstantin Khlebnikov Message-ID: <5608F873.6050305@yandex-team.ru> Date: Mon, 28 Sep 2015 11:21:07 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20150925175654.GA12504@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25.09.2015 20:56, Oleg Nesterov wrote: > On 09/25, Konstantin Khlebnikov wrote: >> >> +struct ns_common *proc_ns_fdget(int fd, int nstype, struct fd *fd_ref) >> { >> - struct file *file; >> + struct ns_common *ns; >> + struct fd f; >> >> - file = fget(fd); >> - if (!file) >> + f = fdget(fd); >> + if (!f.file) >> return ERR_PTR(-EBADF); >> >> - if (file->f_op != &ns_file_operations) >> + if (f.file->f_op != &ns_file_operations) >> + goto out_invalid; >> + >> + ns = get_proc_ns(file_inode(f.file)); >> + if (nstype && (ns->ops->type != nstype)) >> goto out_invalid; >> >> - return file; >> + *fd_ref = f; >> + return ns; >> >> out_invalid: >> - fput(file); >> + fdput(f); >> return ERR_PTR(-EINVAL); >> } > > Well yes, fdget() makes sense but this is minor. > > Honestly, I do not really like the new helper... I understand this > is subjective, so I won't insist. But how about 1/1? We do not need > fd/file at all. With this patch your sys_getvpid() can just use > proc_get_ns_by_fd(fd, CLONE_NEWPID) and put_pid_ns(). Hmm. My version has 0 or 2 atomic ops per get-put sequence. Your version: 2 or 4 atomic ops. Plus even in worst case pinning by struct fd theoretically scales better because it touches refcount at struct file: there're might be many of them for one namespace. > > Eric, what do you think? > > See also "TODO" in the changelog. > > Oleg. > -- Konstantin