Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1659701

Re: [PATCH 3/3] fs/locks: Use fs-specific l_pid for remote locks

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Jeff Layton <jlayton@poochiereds.net>
Newsgroups linux.kernel
Subject Re: [PATCH 3/3] fs/locks: Use fs-specific l_pid for remote locks
Date Wed, 07 Jun 2017 13:50:02 +0200
Message-ID <tPHDk-64E-9@gated-at.bofh.it> (permalink)
References <tPtAl-5iT-5@gated-at.bofh.it> <tPtAm-5iT-15@gated-at.bofh.it>
X-Original-To Benjamin Coddington <bcodding@redhat.com>, bfields@fieldses.org, Alexander Viro <viro@zeniv.linux.org.uk>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=poochiereds-net.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=UJV+Ot6nb//m0HZx0tjiJS1y3G3Nc8cLKH7Gd444RCg=; b=UBnYtt2YqF5xbHGJEX0ZIgdUCKtzHvSZadOhyXMWuT2Lcv2QtUvASlChwb8nxXHiAY M21XpYJL0HNpcA44JVsgN+/z8x/qFO8GgntpW2loiT0Q8ossdluKjpRXCmDzBFAm0GfH 8zwxs+CJAn58O/i3b0WhcVoO1dGU7OCyK2tRq73J9Q46PYFO4qLuAEombPJ0S3BrII/Z VeYM4Hqug83n3z2Oub8ONR2EJAG0luVtxO1D2bcjzF6/LwBNImTT48ORC2QTfUST8Mip +GD4dW6NcMNOrpa1ki5ShKVwOi3Bn17FGTbhveqFL5gP4DKBEcsa+keiG+6NhUi56jGD dCSQ==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=UJV+Ot6nb//m0HZx0tjiJS1y3G3Nc8cLKH7Gd444RCg=; b=EORBrbp+V2ArK2XTgvQTsnuKqCXy55OU5EcIkVI7toc36FqqrA9W85+Hd1Uzb6PsAf 2NmY6QTvdtSZoRtfWq5j4EamMfE3VZWSnjht+hA9XbReGGPZYr0DpfhsoSsbmHrFdvcq 0BoKKIatMCEfHM+EYJXGH14QzLHYLCaz6Gf9rROQw3VCWpipkT/r6feHmhsjm0sR171Z Q6O11t+LP5Oo05prEMXs92wEQUNzvvMbQXA/zNQG2cjX5LQHk62S9jEvdc/4jWJb9hEJ 9eEgkM21YmiD9C/cz3ZRJcx/vca+T8P+nAdQr/AlcMd4IydmzdG0/VFzKKqkakobY/p0 Qlig==
X-Gm-Message-State AKS2vOwXc1UEmO5IG96MGttJxxwdfverVNY+ZGJfOXaFUDzWKlqvUsJH Ir5HdjCcIkAT1UTP
X-Received by 10.55.132.196 with SMTP id g187mr36907351qkd.12.1496835611607; Wed, 07 Jun 2017 04:40:11 -0700 (PDT)
Content-Type text/plain; charset="UTF-8"
X-Mailer Evolution 3.22.6 (3.22.6-2.fc25)
MIME-Version 1.0
Content-Transfer-Encoding 7bit
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 101
Organization linux.* mail to news gateway
X-Original-Cc linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
X-Original-Date Wed, 07 Jun 2017 07:40:07 -0400
X-Original-Message-ID <1496835607.3703.1.camel@poochiereds.net>
X-Original-References <cover.1496781719.git.bcodding@redhat.com> <f4908c50d34aed05a93f74302f1a6ce410ec9d15.1496781719.git.bcodding@redhat.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1659701

Show key headers only | View raw


On Tue, 2017-06-06 at 16:45 -0400, Benjamin Coddington wrote:
> Now that we're translating fl_pid for F_GETLK and /proc/locks, we need to
> handle the case where a remote filesystem directly sets fl_pid.  In that
> case, the fl_pid should not be translated into a local pid namespace.  If
> the filesystem implements the lock operation, set a flag to return the
> lock's fl_pid value directly, rather translate it.
> 

Actually, you're not translating anything for F_GETLK until we get to
this patch. Patch #2 in this series removes the fl_nspid field, but the
pid translation isn't fixed until here. That does mean a nominal
regression here in how fl_pid is reported between the two.

Would it be best to squash #2 and #3 together? Or maybe just go ahead
and universally translate the fl_pid field until you add the flag in
this patch?

Also to make sure I understand: task->tgid will always represent the
task's pid in the init_pid_ns, right?

Other than the minor bisectability concern, I think this looks good.
Nice work!

> Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
> ---
>  fs/locks.c         | 22 ++++++++++++++++++----
>  include/linux/fs.h |  1 +
>  2 files changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/locks.c b/fs/locks.c
> index 8d48e4c42ed3..206a46d28bbd 100644
> --- a/fs/locks.c
> +++ b/fs/locks.c
> @@ -2034,8 +2034,10 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
>   */
>  int vfs_test_lock(struct file *filp, struct file_lock *fl)
>  {
> -	if (filp->f_op->lock && is_remote_lock(filp))
> +	if (filp->f_op->lock && is_remote_lock(filp)) {
> +		fl->fl_flags |= FL_PID_PRIV;
>  		return filp->f_op->lock(filp, F_GETLK, fl);
> +	}
>  	posix_test_lock(filp, fl);
>  	return 0;
>  }
> @@ -2060,9 +2062,18 @@ static pid_t locks_translate_pid(int init_nr, struct pid_namespace *ns)
>  	return vnr;
>  }
>  
> +static pid_t flock_translate_pid(struct file_lock *fl)
> +{
> +	if (IS_OFDLCK(fl))
> +		return -1;
> +	if (fl->fl_flags & FL_PID_PRIV)
> +		return fl->fl_pid;
> +	return locks_translate_pid(fl->fl_pid,  task_active_pid_ns(current));
> +}
> +
>  static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl)
>  {
> -	flock->l_pid = IS_OFDLCK(fl) ? -1 : fl->fl_pid;
> +	flock->l_pid = flock_translate_pid(fl);
>  #if BITS_PER_LONG == 32
>  	/*
>  	 * Make sure we can represent the posix lock via
> @@ -2084,7 +2095,7 @@ static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl)
>  #if BITS_PER_LONG == 32
>  static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl)
>  {
> -	flock->l_pid = IS_OFDLCK(fl) ? -1 : fl->fl_pid;
> +	flock->l_pid = flock_translate_pid(fl);
>  	flock->l_start = fl->fl_start;
>  	flock->l_len = fl->fl_end == OFFSET_MAX ? 0 :
>  		fl->fl_end - fl->fl_start + 1;
> @@ -2598,7 +2609,10 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
>  	unsigned int fl_pid;
>  	struct pid_namespace *proc_pidns = file_inode(f->file)->i_sb->s_fs_info;
>  
> -	fl_pid = locks_translate_pid(fl->fl_pid, proc_pidns);
> +	if (fl->fl_flags & FL_PID_PRIV)
> +		fl_pid = fl->fl_pid;
> +	else
> +		fl_pid = locks_translate_pid(fl->fl_pid, proc_pidns);
>  	/*
>  	 * If there isn't a fl_pid don't display who is waiting on
>  	 * the lock if we are called from locks_show, or if we are
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index b013fac515f7..179496a9719d 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -908,6 +908,7 @@ static inline struct file *get_file(struct file *f)
>  #define FL_UNLOCK_PENDING	512 /* Lease is being broken */
>  #define FL_OFDLCK	1024	/* lock is "owned" by struct file */
>  #define FL_LAYOUT	2048	/* outstanding pNFS layout */
> +#define FL_PID_PRIV	4096	/* F_GETLK should report fl_pid */
>  
>  #define FL_CLOSE_POSIX (FL_POSIX | FL_CLOSE)
>  

-- 
Jeff Layton <jlayton@poochiereds.net>

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/3 v4] Fixups for l_pid Benjamin Coddington <bcodding@redhat.com> - 2017-06-06 22:50 +0200
  [PATCH 3/3] fs/locks: Use fs-specific l_pid for remote locks Benjamin Coddington <bcodding@redhat.com> - 2017-06-06 22:50 +0200
    Re: [PATCH 3/3] fs/locks: Use fs-specific l_pid for remote locks Jeff Layton <jlayton@poochiereds.net> - 2017-06-07 13:50 +0200
      Re: [PATCH 3/3] fs/locks: Use fs-specific l_pid for remote locks "Benjamin Coddington" <bcodding@redhat.com> - 2017-06-19 14:40 +0200
        Re: [PATCH 3/3] fs/locks: Use fs-specific l_pid for remote locks "Benjamin Coddington" <bcodding@redhat.com> - 2017-06-19 15:00 +0200
    Re: [PATCH 3/3] fs/locks: Use fs-specific l_pid for remote locks Jeff Layton <jlayton@poochiereds.net> - 2017-06-07 14:00 +0200
  [PATCH 2/3] fs/locks: Remove fl_nspid Benjamin Coddington <bcodding@redhat.com> - 2017-06-06 22:50 +0200

csiph-web