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:
Родитель
d208bbdda9
Коммит
8737c9305b
|
@ -140,7 +140,7 @@ void mconsole_proc(struct mc_request *req)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = may_open(&nd.path, MAY_READ, FMODE_READ);
|
err = may_open(&nd.path, MAY_READ, O_RDONLY);
|
||||||
if (result) {
|
if (result) {
|
||||||
mconsole_reply(req, "Failed to open file", 1, 0);
|
mconsole_reply(req, "Failed to open file", 1, 0);
|
||||||
path_put(&nd.path);
|
path_put(&nd.path);
|
||||||
|
|
|
@ -2289,9 +2289,9 @@ cifs_oplock_break(struct slow_work *work)
|
||||||
if (inode && S_ISREG(inode->i_mode)) {
|
if (inode && S_ISREG(inode->i_mode)) {
|
||||||
#ifdef CONFIG_CIFS_EXPERIMENTAL
|
#ifdef CONFIG_CIFS_EXPERIMENTAL
|
||||||
if (cinode->clientCanCacheAll == 0)
|
if (cinode->clientCanCacheAll == 0)
|
||||||
break_lease(inode, FMODE_READ);
|
break_lease(inode, O_RDONLY);
|
||||||
else if (cinode->clientCanCacheRead == 0)
|
else if (cinode->clientCanCacheRead == 0)
|
||||||
break_lease(inode, FMODE_WRITE);
|
break_lease(inode, O_WRONLY);
|
||||||
#endif
|
#endif
|
||||||
rc = filemap_fdatawrite(inode->i_mapping);
|
rc = filemap_fdatawrite(inode->i_mapping);
|
||||||
if (cinode->clientCanCacheRead == 0) {
|
if (cinode->clientCanCacheRead == 0) {
|
||||||
|
|
|
@ -1182,8 +1182,9 @@ int __break_lease(struct inode *inode, unsigned int mode)
|
||||||
struct file_lock *fl;
|
struct file_lock *fl;
|
||||||
unsigned long break_time;
|
unsigned long break_time;
|
||||||
int i_have_this_lease = 0;
|
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();
|
lock_kernel();
|
||||||
|
|
||||||
|
@ -1197,7 +1198,7 @@ int __break_lease(struct inode *inode, unsigned int mode)
|
||||||
if (fl->fl_owner == current->files)
|
if (fl->fl_owner == current->files)
|
||||||
i_have_this_lease = 1;
|
i_have_this_lease = 1;
|
||||||
|
|
||||||
if (mode & FMODE_WRITE) {
|
if (want_write) {
|
||||||
/* If we want write access, we have to revoke any lease. */
|
/* If we want write access, we have to revoke any lease. */
|
||||||
future = F_UNLCK | F_INPROGRESS;
|
future = F_UNLCK | F_INPROGRESS;
|
||||||
} else if (flock->fl_type & 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.
|
* An append-only file must be opened in append mode for writing.
|
||||||
*/
|
*/
|
||||||
if (IS_APPEND(inode)) {
|
if (IS_APPEND(inode)) {
|
||||||
if ((flag & FMODE_WRITE) && !(flag & O_APPEND))
|
if ((flag & O_ACCMODE) != O_RDONLY && !(flag & O_APPEND))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
if (flag & O_TRUNC)
|
if (flag & O_TRUNC)
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
@ -1547,7 +1547,7 @@ static int handle_truncate(struct path *path)
|
||||||
* what get passed to sys_open().
|
* what get passed to sys_open().
|
||||||
*/
|
*/
|
||||||
static int __open_namei_create(struct nameidata *nd, struct path *path,
|
static int __open_namei_create(struct nameidata *nd, struct path *path,
|
||||||
int flag, int mode)
|
int open_flag, int mode)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
struct dentry *dir = nd->path.dentry;
|
struct dentry *dir = nd->path.dentry;
|
||||||
|
@ -1565,7 +1565,7 @@ out_unlock:
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
/* Don't check for write permission, don't truncate */
|
/* 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 @@ do_last:
|
||||||
error = mnt_want_write(nd.path.mnt);
|
error = mnt_want_write(nd.path.mnt);
|
||||||
if (error)
|
if (error)
|
||||||
goto exit_mutex_unlock;
|
goto exit_mutex_unlock;
|
||||||
error = __open_namei_create(&nd, &path, flag, mode);
|
error = __open_namei_create(&nd, &path, open_flag, mode);
|
||||||
if (error) {
|
if (error) {
|
||||||
mnt_drop_write(nd.path.mnt);
|
mnt_drop_write(nd.path.mnt);
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -1798,7 +1798,7 @@ ok:
|
||||||
if (error)
|
if (error)
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
error = may_open(&nd.path, acc_mode, flag);
|
error = may_open(&nd.path, acc_mode, open_flag);
|
||||||
if (error) {
|
if (error) {
|
||||||
if (will_truncate)
|
if (will_truncate)
|
||||||
mnt_drop_write(nd.path.mnt);
|
mnt_drop_write(nd.path.mnt);
|
||||||
|
|
|
@ -36,10 +36,9 @@ static struct file *do_open(char *name, int flags)
|
||||||
return ERR_PTR(error);
|
return ERR_PTR(error);
|
||||||
|
|
||||||
if (flags == O_RDWR)
|
if (flags == O_RDWR)
|
||||||
error = may_open(&nd.path, MAY_READ|MAY_WRITE,
|
error = may_open(&nd.path, MAY_READ|MAY_WRITE, flags);
|
||||||
FMODE_READ|FMODE_WRITE);
|
|
||||||
else
|
else
|
||||||
error = may_open(&nd.path, MAY_WRITE, FMODE_WRITE);
|
error = may_open(&nd.path, MAY_WRITE, flags);
|
||||||
|
|
||||||
if (!error)
|
if (!error)
|
||||||
return dentry_open(nd.path.dentry, nd.path.mnt, flags,
|
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
|
* If we are changing the size of the file, then
|
||||||
* we need to break all leases.
|
* 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)
|
if (host_err == -EWOULDBLOCK)
|
||||||
host_err = -ETIMEDOUT;
|
host_err = -ETIMEDOUT;
|
||||||
if (host_err) /* ENOMEM or EWOULDBLOCK */
|
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.
|
* Check to see if there are any leases on this file.
|
||||||
* This may block while leases are broken.
|
* 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)
|
if (host_err == -EWOULDBLOCK)
|
||||||
host_err = -ETIMEDOUT;
|
host_err = -ETIMEDOUT;
|
||||||
if (host_err) /* NOMEM or WOULDBLOCK */
|
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
|
* Make sure that there are no leases. get_write_access() protects
|
||||||
* against the truncate racing with a lease-granting setlease().
|
* against the truncate racing with a lease-granting setlease().
|
||||||
*/
|
*/
|
||||||
error = break_lease(inode, FMODE_WRITE);
|
error = break_lease(inode, O_WRONLY);
|
||||||
if (error)
|
if (error)
|
||||||
goto put_write_and_out;
|
goto put_write_and_out;
|
||||||
|
|
||||||
|
|
|
@ -1331,7 +1331,7 @@ static ssize_t binary_sysctl(const int *name, int nlen,
|
||||||
ssize_t result;
|
ssize_t result;
|
||||||
char *pathname;
|
char *pathname;
|
||||||
int flags;
|
int flags;
|
||||||
int acc_mode, fmode;
|
int acc_mode;
|
||||||
|
|
||||||
pathname = sysctl_getname(name, nlen, &table);
|
pathname = sysctl_getname(name, nlen, &table);
|
||||||
result = PTR_ERR(pathname);
|
result = PTR_ERR(pathname);
|
||||||
|
@ -1342,15 +1342,12 @@ static ssize_t binary_sysctl(const int *name, int nlen,
|
||||||
if (oldval && oldlen && newval && newlen) {
|
if (oldval && oldlen && newval && newlen) {
|
||||||
flags = O_RDWR;
|
flags = O_RDWR;
|
||||||
acc_mode = MAY_READ | MAY_WRITE;
|
acc_mode = MAY_READ | MAY_WRITE;
|
||||||
fmode = FMODE_READ | FMODE_WRITE;
|
|
||||||
} else if (newval && newlen) {
|
} else if (newval && newlen) {
|
||||||
flags = O_WRONLY;
|
flags = O_WRONLY;
|
||||||
acc_mode = MAY_WRITE;
|
acc_mode = MAY_WRITE;
|
||||||
fmode = FMODE_WRITE;
|
|
||||||
} else if (oldval && oldlen) {
|
} else if (oldval && oldlen) {
|
||||||
flags = O_RDONLY;
|
flags = O_RDONLY;
|
||||||
acc_mode = MAY_READ;
|
acc_mode = MAY_READ;
|
||||||
fmode = FMODE_READ;
|
|
||||||
} else {
|
} else {
|
||||||
result = 0;
|
result = 0;
|
||||||
goto out_putname;
|
goto out_putname;
|
||||||
|
@ -1361,7 +1358,7 @@ static ssize_t binary_sysctl(const int *name, int nlen,
|
||||||
if (result)
|
if (result)
|
||||||
goto out_putname;
|
goto out_putname;
|
||||||
|
|
||||||
result = may_open(&nd.path, acc_mode, fmode);
|
result = may_open(&nd.path, acc_mode, flags);
|
||||||
if (result)
|
if (result)
|
||||||
goto out_putpath;
|
goto out_putpath;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче