aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/lustre/lustre/llite/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/lustre/lustre/llite/file.c')
-rw-r--r--drivers/staging/lustre/lustre/llite/file.c158
1 files changed, 70 insertions, 88 deletions
diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c
index c99b74117152..a2ae9a68a9a0 100644
--- a/drivers/staging/lustre/lustre/llite/file.c
+++ b/drivers/staging/lustre/lustre/llite/file.c
@@ -266,6 +266,10 @@ static int ll_md_close(struct obd_export *md_exp, struct inode *inode,
{
struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
struct ll_inode_info *lli = ll_i2info(inode);
+ int lockmode;
+ __u64 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_TEST_LOCK;
+ struct lustre_handle lockh;
+ ldlm_policy_data_t policy = {.l_inodebits={MDS_INODELOCK_OPEN}};
int rc = 0;
/* clear group lock, if present */
@@ -292,39 +296,26 @@ static int ll_md_close(struct obd_export *md_exp, struct inode *inode,
/* Let's see if we have good enough OPEN lock on the file and if
we can skip talking to MDS */
- if (file->f_dentry->d_inode) { /* Can this ever be false? */
- int lockmode;
- __u64 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_TEST_LOCK;
- struct lustre_handle lockh;
- struct inode *inode = file->f_dentry->d_inode;
- ldlm_policy_data_t policy = {.l_inodebits={MDS_INODELOCK_OPEN}};
-
- mutex_lock(&lli->lli_och_mutex);
- if (fd->fd_omode & FMODE_WRITE) {
- lockmode = LCK_CW;
- LASSERT(lli->lli_open_fd_write_count);
- lli->lli_open_fd_write_count--;
- } else if (fd->fd_omode & FMODE_EXEC) {
- lockmode = LCK_PR;
- LASSERT(lli->lli_open_fd_exec_count);
- lli->lli_open_fd_exec_count--;
- } else {
- lockmode = LCK_CR;
- LASSERT(lli->lli_open_fd_read_count);
- lli->lli_open_fd_read_count--;
- }
- mutex_unlock(&lli->lli_och_mutex);
- if (!md_lock_match(md_exp, flags, ll_inode2fid(inode),
- LDLM_IBITS, &policy, lockmode,
- &lockh)) {
- rc = ll_md_real_close(file->f_dentry->d_inode,
- fd->fd_omode);
- }
+ mutex_lock(&lli->lli_och_mutex);
+ if (fd->fd_omode & FMODE_WRITE) {
+ lockmode = LCK_CW;
+ LASSERT(lli->lli_open_fd_write_count);
+ lli->lli_open_fd_write_count--;
+ } else if (fd->fd_omode & FMODE_EXEC) {
+ lockmode = LCK_PR;
+ LASSERT(lli->lli_open_fd_exec_count);
+ lli->lli_open_fd_exec_count--;
} else {
- CERROR("Releasing a file %p with negative dentry %p. Name %s",
- file, file->f_dentry, file->f_dentry->d_name.name);
+ lockmode = LCK_CR;
+ LASSERT(lli->lli_open_fd_read_count);
+ lli->lli_open_fd_read_count--;
}
+ mutex_unlock(&lli->lli_och_mutex);
+
+ if (!md_lock_match(md_exp, flags, ll_inode2fid(inode),
+ LDLM_IBITS, &policy, lockmode, &lockh))
+ rc = ll_md_real_close(inode, fd->fd_omode);
out:
LUSTRE_FPRIVATE(file) = NULL;
@@ -350,8 +341,7 @@ int ll_file_release(struct inode *inode, struct file *file)
inode->i_generation, inode);
#ifdef CONFIG_FS_POSIX_ACL
- if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
- inode == inode->i_sb->s_root->d_inode) {
+ if (sbi->ll_flags & LL_SBI_RMT_CLIENT && is_root_inode(inode)) {
struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
LASSERT(fd != NULL);
@@ -363,7 +353,7 @@ int ll_file_release(struct inode *inode, struct file *file)
}
#endif
- if (inode->i_sb->s_root != file->f_dentry)
+ if (!is_root_inode(inode))
ll_stats_ops_tally(sbi, LPROC_LL_RELEASE, 1);
fd = LUSTRE_FPRIVATE(file);
LASSERT(fd != NULL);
@@ -375,7 +365,7 @@ int ll_file_release(struct inode *inode, struct file *file)
lli->lli_opendir_pid != 0)
ll_stop_statahead(inode, lli->lli_opendir_key);
- if (inode->i_sb->s_root == file->f_dentry) {
+ if (is_root_inode(inode)) {
LUSTRE_FPRIVATE(file) = NULL;
ll_file_data_put(fd);
return 0;
@@ -394,21 +384,19 @@ int ll_file_release(struct inode *inode, struct file *file)
return rc;
}
-static int ll_intent_file_open(struct file *file, void *lmm,
+static int ll_intent_file_open(struct dentry *dentry, void *lmm,
int lmmsize, struct lookup_intent *itp)
{
- struct ll_sb_info *sbi = ll_i2sbi(file->f_dentry->d_inode);
- struct dentry *parent = file->f_dentry->d_parent;
- const char *name = file->f_dentry->d_name.name;
- const int len = file->f_dentry->d_name.len;
+ struct inode *inode = dentry->d_inode;
+ struct ll_sb_info *sbi = ll_i2sbi(inode);
+ struct dentry *parent = dentry->d_parent;
+ const char *name = dentry->d_name.name;
+ const int len = dentry->d_name.len;
struct md_op_data *op_data;
struct ptlrpc_request *req;
__u32 opc = LUSTRE_OPC_ANY;
int rc;
- if (!parent)
- return -ENOENT;
-
/* Usually we come here only for NFSD, and we want open lock.
But we can also get here with pre 2.6.15 patchless kernels, and in
that case that lock is also ok */
@@ -425,7 +413,7 @@ static int ll_intent_file_open(struct file *file, void *lmm,
}
op_data = ll_prep_md_op_data(NULL, parent->d_inode,
- file->f_dentry->d_inode, name, len,
+ inode, name, len,
O_RDWR, opc, NULL);
if (IS_ERR(op_data))
return PTR_ERR(op_data);
@@ -441,7 +429,7 @@ static int ll_intent_file_open(struct file *file, void *lmm,
if (!it_disposition(itp, DISP_OPEN_OPEN) ||
it_open_error(DISP_OPEN_OPEN, itp))
goto out;
- ll_release_openhandle(file->f_dentry, itp);
+ ll_release_openhandle(inode, itp);
goto out;
}
@@ -456,10 +444,9 @@ static int ll_intent_file_open(struct file *file, void *lmm,
goto out;
}
- rc = ll_prep_inode(&file->f_dentry->d_inode, req, NULL, itp);
+ rc = ll_prep_inode(&inode, req, NULL, itp);
if (!rc && itp->d.lustre.it_lock_mode)
- ll_set_lock_data(sbi->ll_md_exp, file->f_dentry->d_inode,
- itp, NULL);
+ ll_set_lock_data(sbi->ll_md_exp, inode, itp, NULL);
out:
ptlrpc_req_finished(req);
@@ -501,7 +488,7 @@ static int ll_och_fill(struct obd_export *md_exp, struct lookup_intent *it,
static int ll_local_open(struct file *file, struct lookup_intent *it,
struct ll_file_data *fd, struct obd_client_handle *och)
{
- struct inode *inode = file->f_dentry->d_inode;
+ struct inode *inode = file_inode(file);
struct ll_inode_info *lli = ll_i2info(inode);
LASSERT(!LUSTRE_FPRIVATE(file));
@@ -574,7 +561,7 @@ int ll_file_open(struct inode *inode, struct file *file)
spin_unlock(&lli->lli_sa_lock);
}
- if (inode->i_sb->s_root == file->f_dentry) {
+ if (is_root_inode(inode)) {
LUSTRE_FPRIVATE(file) = fd;
return 0;
}
@@ -632,7 +619,7 @@ restart:
goto out_openerr;
}
- ll_release_openhandle(file->f_dentry, it);
+ ll_release_openhandle(inode, it);
}
(*och_usecount)++;
@@ -652,7 +639,7 @@ restart:
result in a deadlock */
mutex_unlock(&lli->lli_och_mutex);
it->it_create_mode |= M_CHECK_STALE;
- rc = ll_intent_file_open(file, NULL, 0, it);
+ rc = ll_intent_file_open(file->f_path.dentry, NULL, 0, it);
it->it_create_mode &= ~M_CHECK_STALE;
if (rc)
goto out_openerr;
@@ -1065,7 +1052,7 @@ int ll_glimpse_ioctl(struct ll_sb_info *sbi, struct lov_stripe_md *lsm,
static bool file_is_noatime(const struct file *file)
{
const struct vfsmount *mnt = file->f_path.mnt;
- const struct inode *inode = file->f_path.dentry->d_inode;
+ const struct inode *inode = file_inode(file);
/* Adapted from file_accessed() and touch_atime().*/
if (file->f_flags & O_NOATIME)
@@ -1091,7 +1078,7 @@ static bool file_is_noatime(const struct file *file)
void ll_io_init(struct cl_io *io, const struct file *file, int write)
{
- struct inode *inode = file->f_dentry->d_inode;
+ struct inode *inode = file_inode(file);
io->u.ci_rw.crw_nonblock = file->f_flags & O_NONBLOCK;
if (write) {
@@ -1117,7 +1104,7 @@ ll_file_io_generic(const struct lu_env *env, struct vvp_io_args *args,
struct file *file, enum cl_io_type iot,
loff_t *ppos, size_t count)
{
- struct ll_inode_info *lli = ll_i2info(file->f_dentry->d_inode);
+ struct ll_inode_info *lli = ll_i2info(file_inode(file));
struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
struct cl_io *io;
ssize_t result;
@@ -1178,20 +1165,20 @@ out:
/* If any bit been read/written (result != 0), we just return
* short read/write instead of restart io. */
if ((result == 0 || result == -ENODATA) && io->ci_need_restart) {
- CDEBUG(D_VFSTRACE, "Restart %s on %s from %lld, count:%zd\n",
+ CDEBUG(D_VFSTRACE, "Restart %s on %pD from %lld, count:%zd\n",
iot == CIT_READ ? "read" : "write",
- file->f_dentry->d_name.name, *ppos, count);
+ file, *ppos, count);
LASSERTF(io->ci_nob == 0, "%zd", io->ci_nob);
goto restart;
}
if (iot == CIT_READ) {
if (result >= 0)
- ll_stats_ops_tally(ll_i2sbi(file->f_dentry->d_inode),
+ ll_stats_ops_tally(ll_i2sbi(file_inode(file)),
LPROC_LL_READ_BYTES, result);
} else if (iot == CIT_WRITE) {
if (result >= 0) {
- ll_stats_ops_tally(ll_i2sbi(file->f_dentry->d_inode),
+ ll_stats_ops_tally(ll_i2sbi(file_inode(file)),
LPROC_LL_WRITE_BYTES, result);
fd->fd_write_failed = false;
} else if (result != -ERESTARTSYS) {
@@ -1354,7 +1341,7 @@ static int ll_lov_recreate_fid(struct inode *inode, unsigned long arg)
return ll_lov_recreate(inode, &oi, ost_idx);
}
-int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
+int ll_lov_setstripe_ea_info(struct inode *inode, struct dentry *dentry,
int flags, struct lov_user_md *lum, int lum_size)
{
struct lov_stripe_md *lsm = NULL;
@@ -1371,21 +1358,20 @@ int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
}
ll_inode_size_lock(inode);
- rc = ll_intent_file_open(file, lum, lum_size, &oit);
+ rc = ll_intent_file_open(dentry, lum, lum_size, &oit);
if (rc)
goto out_unlock;
rc = oit.d.lustre.it_status;
if (rc < 0)
goto out_req_free;
- ll_release_openhandle(file->f_dentry, &oit);
+ ll_release_openhandle(inode, &oit);
out_unlock:
ll_inode_size_unlock(inode);
ll_intent_release(&oit);
ccc_inode_lsm_put(inode, lsm);
out:
- cl_lov_delay_create_clear(&file->f_flags);
return rc;
out_req_free:
ptlrpc_req_finished((struct ptlrpc_request *) oit.d.lustre.it_data);
@@ -1499,7 +1485,9 @@ static int ll_lov_setea(struct inode *inode, struct file *file,
return -EFAULT;
}
- rc = ll_lov_setstripe_ea_info(inode, file, flags, lump, lum_size);
+ rc = ll_lov_setstripe_ea_info(inode, file->f_path.dentry, flags, lump,
+ lum_size);
+ cl_lov_delay_create_clear(&file->f_flags);
OBD_FREE_LARGE(lump, lum_size);
return rc;
@@ -1526,7 +1514,9 @@ static int ll_lov_setstripe(struct inode *inode, struct file *file,
return -EFAULT;
}
- rc = ll_lov_setstripe_ea_info(inode, file, flags, lumv1, lum_size);
+ rc = ll_lov_setstripe_ea_info(inode, file->f_path.dentry, flags, lumv1,
+ lum_size);
+ cl_lov_delay_create_clear(&file->f_flags);
if (rc == 0) {
struct lov_stripe_md *lsm;
__u32 gen;
@@ -1631,22 +1621,21 @@ int ll_put_grouplock(struct inode *inode, struct file *file, unsigned long arg)
/**
* Close inode open handle
*
- * \param dentry [in] dentry which contains the inode
+ * \param inode [in] inode in question
* \param it [in,out] intent which contains open info and result
*
* \retval 0 success
* \retval <0 failure
*/
-int ll_release_openhandle(struct dentry *dentry, struct lookup_intent *it)
+int ll_release_openhandle(struct inode *inode, struct lookup_intent *it)
{
- struct inode *inode = dentry->d_inode;
struct obd_client_handle *och;
int rc;
LASSERT(inode);
/* Root ? Do nothing. */
- if (dentry->d_inode->i_sb->s_root == dentry)
+ if (is_root_inode(inode))
return 0;
/* No open handle to close? Move away */
@@ -1959,8 +1948,8 @@ static int ll_swap_layouts(struct file *file1, struct file *file2,
if (!llss)
return -ENOMEM;
- llss->inode1 = file1->f_dentry->d_inode;
- llss->inode2 = file2->f_dentry->d_inode;
+ llss->inode1 = file_inode(file1);
+ llss->inode2 = file_inode(file2);
if (!S_ISREG(llss->inode2->i_mode)) {
rc = -EINVAL;
@@ -2092,7 +2081,7 @@ putgl:
rc = 0;
if (llss->ia2.ia_valid != 0) {
mutex_lock(&llss->inode1->i_mutex);
- rc = ll_setattr(file1->f_dentry, &llss->ia2);
+ rc = ll_setattr(file1->f_path.dentry, &llss->ia2);
mutex_unlock(&llss->inode1->i_mutex);
}
@@ -2100,7 +2089,7 @@ putgl:
int rc1;
mutex_lock(&llss->inode2->i_mutex);
- rc1 = ll_setattr(file2->f_dentry, &llss->ia1);
+ rc1 = ll_setattr(file2->f_path.dentry, &llss->ia1);
mutex_unlock(&llss->inode2->i_mutex);
if (rc == 0)
rc = rc1;
@@ -2185,7 +2174,7 @@ static int ll_hsm_import(struct inode *inode, struct file *file,
mutex_lock(&inode->i_mutex);
- rc = ll_setattr_raw(file->f_dentry, attr, true);
+ rc = ll_setattr_raw(file->f_path.dentry, attr, true);
if (rc == -ENODATA)
rc = 0;
@@ -2204,7 +2193,7 @@ out:
static long
ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
- struct inode *inode = file->f_dentry->d_inode;
+ struct inode *inode = file_inode(file);
struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
int flags, rc;
@@ -2523,7 +2512,7 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
static loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
{
- struct inode *inode = file->f_dentry->d_inode;
+ struct inode *inode = file_inode(file);
loff_t retval, eof = 0;
retval = offset + ((origin == SEEK_END) ? i_size_read(inode) :
@@ -2547,7 +2536,7 @@ static loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
static int ll_flush(struct file *file, fl_owner_t id)
{
- struct inode *inode = file->f_dentry->d_inode;
+ struct inode *inode = file_inode(file);
struct ll_inode_info *lli = ll_i2info(inode);
struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
int rc, err;
@@ -2622,16 +2611,9 @@ int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
return result;
}
-/*
- * When dentry is provided (the 'else' case), *file->f_dentry may be
- * null and dentry must be used directly rather than pulled from
- * *file->f_dentry as is done otherwise.
- */
-
int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
{
- struct dentry *dentry = file->f_dentry;
- struct inode *inode = dentry->d_inode;
+ struct inode *inode = file_inode(file);
struct ll_inode_info *lli = ll_i2info(inode);
struct ptlrpc_request *req;
struct obd_capa *oc;
@@ -2684,7 +2666,7 @@ int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
static int
ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
{
- struct inode *inode = file->f_dentry->d_inode;
+ struct inode *inode = file_inode(file);
struct ll_sb_info *sbi = ll_i2sbi(inode);
struct ldlm_enqueue_info einfo = {
.ei_type = LDLM_FLOCK,
@@ -2908,8 +2890,8 @@ static int __ll_inode_revalidate(struct dentry *dentry, __u64 ibits)
LASSERT(inode != NULL);
- CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),name=%s\n",
- inode->i_ino, inode->i_generation, inode, dentry->d_name.name);
+ CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),name=%pd\n",
+ inode->i_ino, inode->i_generation, inode, dentry);
exp = ll_i2mdexp(inode);
@@ -3119,7 +3101,7 @@ int ll_inode_permission(struct inode *inode, int mask)
/* as root inode are NOT getting validated in lookup operation,
* need to do it before permission check. */
- if (inode == inode->i_sb->s_root->d_inode) {
+ if (is_root_inode(inode)) {
rc = __ll_inode_revalidate(inode->i_sb->s_root,
MDS_INODELOCK_LOOKUP);
if (rc)