From: Jeff Layton <jlayton@kernel.org>
To: yangerkun <yangerkun@huawei.com>, miklos@szeredi.hu, amir73il@gmail.com
Cc: linux-unionfs@vger.kernel.org, yi.zhang@huawei.com, miaoxie@huawei.com
Subject: Re: [RFC PATCH 1/2] fs/locks: add flock_setlk to help set flock
Date: Fri, 30 Mar 2018 06:46:09 -0400 [thread overview]
Message-ID: <1522406769.4339.6.camel@kernel.org> (raw)
In-Reply-To: <20180329090845.39911-1-yangerkun@huawei.com>
On Thu, 2018-03-29 at 17:08 +0800, yangerkun wrote:
> Split sys_flock(), add flock_setlk() routine to help kernel set
> flock easily.
>
> Signed-off-by: yangerkun <yangerkun@huawei.com>
> ---
> fs/locks.c | 29 +++++++++++++++++------------
> include/linux/fs.h | 1 +
> 2 files changed, 18 insertions(+), 12 deletions(-)
>
> diff --git a/fs/locks.c b/fs/locks.c
> index d6ff4be..aeef6cf 100644
> --- a/fs/locks.c
> +++ b/fs/locks.c
> @@ -1974,6 +1974,22 @@ int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl)
> }
> EXPORT_SYMBOL(locks_lock_inode_wait);
>
> +int flock_setlk(struct file *filp, struct file_lock *lock)
> +{
> + int err;
> +
> + err = security_file_lock(filp, lock->fl_type);
> + if (err)
> + return err;
> +
> + if (filp->f_op->flock && is_remote_lock(filp))
> + return filp->f_op->flock(filp,
> + (lock->fl_flags & FL_SLEEP) ? F_SETLKW : F_SETLK,
> + lock);
> + else
> + return locks_lock_file_wait(filp, lock);
> +}
> +
> /**
> * sys_flock: - flock() system call.
> * @fd: the file descriptor to lock.
> @@ -2019,18 +2035,7 @@ int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl)
> if (can_sleep)
> lock->fl_flags |= FL_SLEEP;
>
> - error = security_file_lock(f.file, lock->fl_type);
> - if (error)
> - goto out_free;
> -
> - if (f.file->f_op->flock && is_remote_lock(f.file))
> - error = f.file->f_op->flock(f.file,
> - (can_sleep) ? F_SETLKW : F_SETLK,
> - lock);
> - else
> - error = locks_lock_file_wait(f.file, lock);
> -
> - out_free:
> + error = flock_setlk(f.file, lock);
> locks_free_lock(lock);
>
> out_putf:
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 2a81556..3dab90c 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -1090,6 +1090,7 @@ extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
> extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
> extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
> extern int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl);
> +extern int flock_setlk(struct file *filp, struct file_lock *fl);
> extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int type);
> extern void lease_get_mtime(struct inode *, struct timespec *time);
> extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
Looks reasonable, but I'm not sure I understand the overall rationale
for wanting to do this: What problem are you trying to fix?
Note that FL_FLOCK interaction on NFS can be a little odd (the client
translates those to posix locks before sending them off to the server).
If you're going to do this with overlay files then you probably need to
consider how all of that is going to work. It may be better to use OFD
locks here.
--
Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2018-03-30 10:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-29 9:08 [RFC PATCH 1/2] fs/locks: add flock_setlk to help set flock yangerkun
2018-03-29 9:36 ` Amir Goldstein
2018-03-30 10:46 ` Jeff Layton [this message]
2018-03-30 11:25 ` Amir Goldstein
2018-03-30 13:40 ` Jeff Layton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1522406769.4339.6.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=amir73il@gmail.com \
--cc=linux-unionfs@vger.kernel.org \
--cc=miaoxie@huawei.com \
--cc=miklos@szeredi.hu \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox