mirror of https://gitee.com/openkylin/linux.git
Switch may_open() and break_lease() to passing O_...
... instead of mixing FMODE_ and O_ Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
d208bbdda9
commit
8737c9305b
|
@ -140,7 +140,7 @@ void mconsole_proc(struct mc_request *req)
|
|||
goto out;
|
||||
}
|
||||
|
||||
err = may_open(&nd.path, MAY_READ, FMODE_READ);
|
||||
err = may_open(&nd.path, MAY_READ, O_RDONLY);
|
||||
if (result) {
|
||||
mconsole_reply(req, "Failed to open file", 1, 0);
|
||||
path_put(&nd.path);
|
||||
|
|
|
@ -2289,9 +2289,9 @@ cifs_oplock_break(struct slow_work *work)
|
|||
if (inode && S_ISREG(inode->i_mode)) {
|
||||
#ifdef CONFIG_CIFS_EXPERIMENTAL
|
||||
if (cinode->clientCanCacheAll == 0)
|
||||
break_lease(inode, FMODE_READ);
|
||||
break_lease(inode, O_RDONLY);
|
||||
else if (cinode->clientCanCacheRead == 0)
|
||||
break_lease(inode, FMODE_WRITE);
|
||||
break_lease(inode, O_WRONLY);
|
||||
#endif
|
||||
rc = filemap_fdatawrite(inode->i_mapping);
|
||||
if (cinode->clientCanCacheRead == 0) {
|
||||
|
|
|
@ -1182,8 +1182,9 @@ int __break_lease(struct inode *inode, unsigned int mode)
|
|||
struct file_lock *fl;
|
||||
unsigned long break_time;
|
||||
int i_have_this_lease = 0;
|
||||
int want_write = (mode & O_ACCMODE) != O_RDONLY;
|
||||
|
||||
new_fl = lease_alloc(NULL, mode & FMODE_WRITE ? F_WRLCK : F_RDLCK);
|
||||
new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK);
|
||||
|
||||
lock_kernel();
|
||||
|
||||
|
@ -1197,7 +1198,7 @@ int __break_lease(struct inode *inode, unsigned int mode)
|
|||
if (fl->fl_owner == current->files)
|
||||
i_have_this_lease = 1;
|
||||
|
||||
if (mode & FMODE_WRITE) {
|
||||
if (want_write) {
|
||||
/* If we want write access, we have to revoke any lease. */
|
||||
future = F_UNLCK | F_INPROGRESS;
|
||||
} else if (flock->fl_type & F_INPROGRESS) {
|
||||
|
|
10
fs/namei.c
10
fs/namei.c
|
@ -1503,7 +1503,7 @@ int may_open(struct path *path, int acc_mode, int flag)
|
|||
* An append-only file must be opened in append mode for writing.
|
||||
*/
|
||||
if (IS_APPEND(inode)) {
|
||||
if ((flag & FMODE_WRITE) && !(flag & O_APPEND))
|
||||
if ((flag & O_ACCMODE) != O_RDONLY && !(flag & O_APPEND))
|
||||
return -EPERM;
|
||||
if (flag & O_TRUNC)
|
||||
return -EPERM;
|
||||
|
@ -1547,7 +1547,7 @@ static int handle_truncate(struct path *path)
|
|||
* what get passed to sys_open().
|
||||
*/
|
||||
static int __open_namei_create(struct nameidata *nd, struct path *path,
|
||||
int flag, int mode)
|
||||
int open_flag, int mode)
|
||||
{
|
||||
int error;
|
||||
struct dentry *dir = nd->path.dentry;
|
||||
|
@ -1565,7 +1565,7 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
|
|||
if (error)
|
||||
return error;
|
||||
/* Don't check for write permission, don't truncate */
|
||||
return may_open(&nd->path, 0, flag & ~O_TRUNC);
|
||||
return may_open(&nd->path, 0, open_flag & ~O_TRUNC);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1736,7 +1736,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
|
|||
error = mnt_want_write(nd.path.mnt);
|
||||
if (error)
|
||||
goto exit_mutex_unlock;
|
||||
error = __open_namei_create(&nd, &path, flag, mode);
|
||||
error = __open_namei_create(&nd, &path, open_flag, mode);
|
||||
if (error) {
|
||||
mnt_drop_write(nd.path.mnt);
|
||||
goto exit;
|
||||
|
@ -1798,7 +1798,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
|
|||
if (error)
|
||||
goto exit;
|
||||
}
|
||||
error = may_open(&nd.path, acc_mode, flag);
|
||||
error = may_open(&nd.path, acc_mode, open_flag);
|
||||
if (error) {
|
||||
if (will_truncate)
|
||||
mnt_drop_write(nd.path.mnt);
|
||||
|
|
|
@ -36,10 +36,9 @@ static struct file *do_open(char *name, int flags)
|
|||
return ERR_PTR(error);
|
||||
|
||||
if (flags == O_RDWR)
|
||||
error = may_open(&nd.path, MAY_READ|MAY_WRITE,
|
||||
FMODE_READ|FMODE_WRITE);
|
||||
error = may_open(&nd.path, MAY_READ|MAY_WRITE, flags);
|
||||
else
|
||||
error = may_open(&nd.path, MAY_WRITE, FMODE_WRITE);
|
||||
error = may_open(&nd.path, MAY_WRITE, flags);
|
||||
|
||||
if (!error)
|
||||
return dentry_open(nd.path.dentry, nd.path.mnt, flags,
|
||||
|
|
|
@ -361,7 +361,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
|
|||
* If we are changing the size of the file, then
|
||||
* we need to break all leases.
|
||||
*/
|
||||
host_err = break_lease(inode, FMODE_WRITE | O_NONBLOCK);
|
||||
host_err = break_lease(inode, O_WRONLY | O_NONBLOCK);
|
||||
if (host_err == -EWOULDBLOCK)
|
||||
host_err = -ETIMEDOUT;
|
||||
if (host_err) /* ENOMEM or EWOULDBLOCK */
|
||||
|
@ -734,7 +734,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
|
|||
* Check to see if there are any leases on this file.
|
||||
* This may block while leases are broken.
|
||||
*/
|
||||
host_err = break_lease(inode, O_NONBLOCK | ((access & NFSD_MAY_WRITE) ? FMODE_WRITE : 0));
|
||||
host_err = break_lease(inode, O_NONBLOCK | ((access & NFSD_MAY_WRITE) ? O_WRONLY : 0));
|
||||
if (host_err == -EWOULDBLOCK)
|
||||
host_err = -ETIMEDOUT;
|
||||
if (host_err) /* NOMEM or WOULDBLOCK */
|
||||
|
|
|
@ -271,7 +271,7 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
|
|||
* Make sure that there are no leases. get_write_access() protects
|
||||
* against the truncate racing with a lease-granting setlease().
|
||||
*/
|
||||
error = break_lease(inode, FMODE_WRITE);
|
||||
error = break_lease(inode, O_WRONLY);
|
||||
if (error)
|
||||
goto put_write_and_out;
|
||||
|
||||
|
|
|
@ -1331,7 +1331,7 @@ static ssize_t binary_sysctl(const int *name, int nlen,
|
|||
ssize_t result;
|
||||
char *pathname;
|
||||
int flags;
|
||||
int acc_mode, fmode;
|
||||
int acc_mode;
|
||||
|
||||
pathname = sysctl_getname(name, nlen, &table);
|
||||
result = PTR_ERR(pathname);
|
||||
|
@ -1342,15 +1342,12 @@ static ssize_t binary_sysctl(const int *name, int nlen,
|
|||
if (oldval && oldlen && newval && newlen) {
|
||||
flags = O_RDWR;
|
||||
acc_mode = MAY_READ | MAY_WRITE;
|
||||
fmode = FMODE_READ | FMODE_WRITE;
|
||||
} else if (newval && newlen) {
|
||||
flags = O_WRONLY;
|
||||
acc_mode = MAY_WRITE;
|
||||
fmode = FMODE_WRITE;
|
||||
} else if (oldval && oldlen) {
|
||||
flags = O_RDONLY;
|
||||
acc_mode = MAY_READ;
|
||||
fmode = FMODE_READ;
|
||||
} else {
|
||||
result = 0;
|
||||
goto out_putname;
|
||||
|
@ -1361,7 +1358,7 @@ static ssize_t binary_sysctl(const int *name, int nlen,
|
|||
if (result)
|
||||
goto out_putname;
|
||||
|
||||
result = may_open(&nd.path, acc_mode, fmode);
|
||||
result = may_open(&nd.path, acc_mode, flags);
|
||||
if (result)
|
||||
goto out_putpath;
|
||||
|
||||
|
|
Loading…
Reference in New Issue