提交 38017d44 编写于 作者: M Miklos Szeredi

cachefiles: tmpfile error handling cleanup

Separate the error labels from the success path and use 'ret' to store the
error value before jumping to the error label.
Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
上级 19ee5345
...@@ -460,31 +460,27 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object) ...@@ -460,31 +460,27 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)
path.mnt = cache->mnt; path.mnt = cache->mnt;
ret = cachefiles_inject_write_error(); ret = cachefiles_inject_write_error();
if (ret == 0) if (ret == 0) {
path.dentry = vfs_tmpfile(&init_user_ns, fan, S_IFREG, O_RDWR); path.dentry = vfs_tmpfile(&init_user_ns, fan, S_IFREG, O_RDWR);
else ret = PTR_ERR_OR_ZERO(path.dentry);
path.dentry = ERR_PTR(ret); }
if (IS_ERR(path.dentry)) { if (ret) {
trace_cachefiles_vfs_error(object, d_inode(fan), PTR_ERR(path.dentry), trace_cachefiles_vfs_error(object, d_inode(fan), ret,
cachefiles_trace_tmpfile_error); cachefiles_trace_tmpfile_error);
if (PTR_ERR(path.dentry) == -EIO) if (ret == -EIO)
cachefiles_io_error_obj(object, "Failed to create tmpfile"); cachefiles_io_error_obj(object, "Failed to create tmpfile");
file = ERR_CAST(path.dentry); goto err;
goto out;
} }
trace_cachefiles_tmpfile(object, d_backing_inode(path.dentry)); trace_cachefiles_tmpfile(object, d_backing_inode(path.dentry));
if (!cachefiles_mark_inode_in_use(object, path.dentry)) { ret = -EBUSY;
file = ERR_PTR(-EBUSY); if (!cachefiles_mark_inode_in_use(object, path.dentry))
goto out_dput; goto err_dput;
}
ret = cachefiles_ondemand_init_object(object); ret = cachefiles_ondemand_init_object(object);
if (ret < 0) { if (ret < 0)
file = ERR_PTR(ret); goto err_unuse;
goto out_unuse;
}
ni_size = object->cookie->object_size; ni_size = object->cookie->object_size;
ni_size = round_up(ni_size, CACHEFILES_DIO_BLOCK_SIZE); ni_size = round_up(ni_size, CACHEFILES_DIO_BLOCK_SIZE);
...@@ -499,36 +495,37 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object) ...@@ -499,36 +495,37 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)
trace_cachefiles_vfs_error( trace_cachefiles_vfs_error(
object, d_backing_inode(path.dentry), ret, object, d_backing_inode(path.dentry), ret,
cachefiles_trace_trunc_error); cachefiles_trace_trunc_error);
file = ERR_PTR(ret); goto err_unuse;
goto out_unuse;
} }
} }
file = open_with_fake_path(&path, O_RDWR | O_LARGEFILE | O_DIRECT, file = open_with_fake_path(&path, O_RDWR | O_LARGEFILE | O_DIRECT,
d_backing_inode(path.dentry), cache->cache_cred); d_backing_inode(path.dentry), cache->cache_cred);
ret = PTR_ERR(file);
if (IS_ERR(file)) { if (IS_ERR(file)) {
trace_cachefiles_vfs_error(object, d_backing_inode(path.dentry), trace_cachefiles_vfs_error(object, d_backing_inode(path.dentry),
PTR_ERR(file), ret, cachefiles_trace_open_error);
cachefiles_trace_open_error); goto err_unuse;
goto out_unuse;
} }
ret = -EINVAL;
if (unlikely(!file->f_op->read_iter) || if (unlikely(!file->f_op->read_iter) ||
unlikely(!file->f_op->write_iter)) { unlikely(!file->f_op->write_iter)) {
fput(file); fput(file);
pr_notice("Cache does not support read_iter and write_iter\n"); pr_notice("Cache does not support read_iter and write_iter\n");
file = ERR_PTR(-EINVAL); goto err_unuse;
goto out_unuse;
} }
goto out_dput;
out_unuse:
cachefiles_do_unmark_inode_in_use(object, path.dentry);
out_dput:
dput(path.dentry); dput(path.dentry);
out: out:
cachefiles_end_secure(cache, saved_cred); cachefiles_end_secure(cache, saved_cred);
return file; return file;
err_unuse:
cachefiles_do_unmark_inode_in_use(object, path.dentry);
err_dput:
dput(path.dentry);
err:
file = ERR_PTR(ret);
goto out;
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册