Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 234262
b: refs/heads/master
c: 0f9d1a1
h: refs/heads/master
v: v3
  • Loading branch information
Al Viro committed Mar 14, 2011
1 parent 163e3be commit 26b7512
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 53 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5a202bcd75bbd2397136397961babbd8463416af
refs/heads/master: 0f9d1a10c341020617e5b1c7f9c16f6a070438ec
90 changes: 38 additions & 52 deletions trunk/fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -2111,64 +2111,14 @@ static int open_will_truncate(int flag, struct inode *inode)
return (flag & O_TRUNC);
}

static struct file *finish_open(struct nameidata *nd,
int open_flag, int acc_mode)
{
struct file *filp;
int will_truncate;
int error;

will_truncate = open_will_truncate(open_flag, nd->path.dentry->d_inode);
if (will_truncate) {
error = mnt_want_write(nd->path.mnt);
if (error)
goto exit;
}
error = may_open(&nd->path, acc_mode, open_flag);
if (error) {
if (will_truncate)
mnt_drop_write(nd->path.mnt);
goto exit;
}
filp = nameidata_to_filp(nd);
if (!IS_ERR(filp)) {
error = ima_file_check(filp, acc_mode);
if (error) {
fput(filp);
filp = ERR_PTR(error);
}
}
if (!IS_ERR(filp)) {
if (will_truncate) {
error = handle_truncate(filp);
if (error) {
fput(filp);
filp = ERR_PTR(error);
}
}
}
/*
* It is now safe to drop the mnt write
* because the filp has had a write taken
* on its behalf.
*/
if (will_truncate)
mnt_drop_write(nd->path.mnt);
path_put(&nd->path);
return filp;

exit:
path_put(&nd->path);
return ERR_PTR(error);
}

/*
* Handle the last step of open()
*/
static struct file *do_last(struct nameidata *nd, struct path *path,
const struct open_flags *op, const char *pathname)
{
struct dentry *dir = nd->path.dentry;
int will_truncate;
struct file *filp;
struct inode *inode;
int error;
Expand Down Expand Up @@ -2329,7 +2279,43 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
if (S_ISDIR(nd->inode->i_mode))
goto exit;
ok:
filp = finish_open(nd, op->open_flag, op->acc_mode);
will_truncate = open_will_truncate(op->open_flag, nd->path.dentry->d_inode);
if (will_truncate) {
error = mnt_want_write(nd->path.mnt);
if (error)
goto exit;
}
error = may_open(&nd->path, op->acc_mode, op->open_flag);
if (error) {
if (will_truncate)
mnt_drop_write(nd->path.mnt);
goto exit;
}
filp = nameidata_to_filp(nd);
if (!IS_ERR(filp)) {
error = ima_file_check(filp, op->acc_mode);
if (error) {
fput(filp);
filp = ERR_PTR(error);
}
}
if (!IS_ERR(filp)) {
if (will_truncate) {
error = handle_truncate(filp);
if (error) {
fput(filp);
filp = ERR_PTR(error);
}
}
}
/*
* It is now safe to drop the mnt write
* because the filp has had a write taken
* on its behalf.
*/
if (will_truncate)
mnt_drop_write(nd->path.mnt);
path_put(&nd->path);
return filp;

exit_mutex_unlock:
Expand Down

0 comments on commit 26b7512

Please sign in to comment.