Commit fc5f499a authored by NeilBrown's avatar NeilBrown Committed by Greg Kroah-Hartman

staging: lustre: llite: use more private data in dump_pgcache

The dump_page_cache debugfs file allocates and frees an 'env' in each
call to vvp_pgcache_start,next,show.  This is likely to be fast, but
does introduce the need to check for errors.

It is reasonable to allocate a single 'env' when the file is opened,
and use that throughout.

So create 'seq_private' structure which stores the sbi, env, and
refcheck, and attach this to the seqfile.

Then use it throughout instead of allocating 'env' repeatedly.
Signed-off-by: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 775c4dc2
...@@ -390,6 +390,12 @@ struct vvp_pgcache_id { ...@@ -390,6 +390,12 @@ struct vvp_pgcache_id {
struct lu_object_header *vpi_obj; struct lu_object_header *vpi_obj;
}; };
struct seq_private {
struct ll_sb_info *sbi;
struct lu_env *env;
u16 refcheck;
};
static void vvp_pgcache_id_unpack(loff_t pos, struct vvp_pgcache_id *id) static void vvp_pgcache_id_unpack(loff_t pos, struct vvp_pgcache_id *id)
{ {
BUILD_BUG_ON(sizeof(pos) != sizeof(__u64)); BUILD_BUG_ON(sizeof(pos) != sizeof(__u64));
...@@ -531,95 +537,72 @@ static void vvp_pgcache_page_show(const struct lu_env *env, ...@@ -531,95 +537,72 @@ static void vvp_pgcache_page_show(const struct lu_env *env,
static int vvp_pgcache_show(struct seq_file *f, void *v) static int vvp_pgcache_show(struct seq_file *f, void *v)
{ {
struct seq_private *priv = f->private;
loff_t pos; loff_t pos;
struct ll_sb_info *sbi;
struct cl_object *clob; struct cl_object *clob;
struct lu_env *env;
struct vvp_pgcache_id id; struct vvp_pgcache_id id;
u16 refcheck;
int result;
env = cl_env_get(&refcheck); pos = *(loff_t *)v;
if (!IS_ERR(env)) { vvp_pgcache_id_unpack(pos, &id);
pos = *(loff_t *)v; clob = vvp_pgcache_obj(priv->env, &priv->sbi->ll_cl->cd_lu_dev, &id);
vvp_pgcache_id_unpack(pos, &id); if (clob) {
sbi = f->private; struct inode *inode = vvp_object_inode(clob);
clob = vvp_pgcache_obj(env, &sbi->ll_cl->cd_lu_dev, &id); struct cl_page *page = NULL;
if (clob) { struct page *vmpage;
struct inode *inode = vvp_object_inode(clob); int result;
struct cl_page *page = NULL;
struct page *vmpage; result = find_get_pages_contig(inode->i_mapping,
id.vpi_index, 1,
result = find_get_pages_contig(inode->i_mapping, &vmpage);
id.vpi_index, 1, if (result > 0) {
&vmpage); lock_page(vmpage);
if (result > 0) { page = cl_vmpage_page(vmpage, clob);
lock_page(vmpage); unlock_page(vmpage);
page = cl_vmpage_page(vmpage, clob); put_page(vmpage);
unlock_page(vmpage); }
put_page(vmpage);
}
seq_printf(f, "%8x@" DFID ": ", id.vpi_index, seq_printf(f, "%8x@" DFID ": ", id.vpi_index,
PFID(lu_object_fid(&clob->co_lu))); PFID(lu_object_fid(&clob->co_lu)));
if (page) { if (page) {
vvp_pgcache_page_show(env, f, page); vvp_pgcache_page_show(priv->env, f, page);
cl_page_put(env, page); cl_page_put(priv->env, page);
} else {
seq_puts(f, "missing\n");
}
lu_object_ref_del(&clob->co_lu, "dump", current);
cl_object_put(env, clob);
} else { } else {
seq_printf(f, "%llx missing\n", pos); seq_puts(f, "missing\n");
} }
cl_env_put(env, &refcheck); lu_object_ref_del(&clob->co_lu, "dump", current);
result = 0; cl_object_put(priv->env, clob);
} else { } else {
result = PTR_ERR(env); seq_printf(f, "%llx missing\n", pos);
} }
return result; return 0;
} }
static void *vvp_pgcache_start(struct seq_file *f, loff_t *pos) static void *vvp_pgcache_start(struct seq_file *f, loff_t *pos)
{ {
struct ll_sb_info *sbi; struct seq_private *priv = f->private;
struct lu_env *env;
u16 refcheck;
sbi = f->private;
env = cl_env_get(&refcheck); if (priv->sbi->ll_site->ls_obj_hash->hs_cur_bits >
if (!IS_ERR(env)) { 64 - PGC_OBJ_SHIFT) {
sbi = f->private; pos = ERR_PTR(-EFBIG);
if (sbi->ll_site->ls_obj_hash->hs_cur_bits > } else {
64 - PGC_OBJ_SHIFT) { *pos = vvp_pgcache_find(priv->env, &priv->sbi->ll_cl->cd_lu_dev,
pos = ERR_PTR(-EFBIG); *pos);
} else { if (*pos == ~0ULL)
*pos = vvp_pgcache_find(env, &sbi->ll_cl->cd_lu_dev, pos = NULL;
*pos);
if (*pos == ~0ULL)
pos = NULL;
}
cl_env_put(env, &refcheck);
} }
return pos; return pos;
} }
static void *vvp_pgcache_next(struct seq_file *f, void *v, loff_t *pos) static void *vvp_pgcache_next(struct seq_file *f, void *v, loff_t *pos)
{ {
struct ll_sb_info *sbi; struct seq_private *priv = f->private;
struct lu_env *env;
u16 refcheck; *pos = vvp_pgcache_find(priv->env, &priv->sbi->ll_cl->cd_lu_dev,
*pos + 1);
if (*pos == ~0ULL)
pos = NULL;
env = cl_env_get(&refcheck);
if (!IS_ERR(env)) {
sbi = f->private;
*pos = vvp_pgcache_find(env, &sbi->ll_cl->cd_lu_dev, *pos + 1);
if (*pos == ~0ULL)
pos = NULL;
cl_env_put(env, &refcheck);
}
return pos; return pos;
} }
...@@ -637,23 +620,36 @@ static const struct seq_operations vvp_pgcache_ops = { ...@@ -637,23 +620,36 @@ static const struct seq_operations vvp_pgcache_ops = {
static int vvp_dump_pgcache_seq_open(struct inode *inode, struct file *filp) static int vvp_dump_pgcache_seq_open(struct inode *inode, struct file *filp)
{ {
struct seq_file *seq; struct seq_private *priv;
int rc;
rc = seq_open(filp, &vvp_pgcache_ops); priv = __seq_open_private(filp, &vvp_pgcache_ops, sizeof(*priv));
if (rc) if (!priv)
return rc; return -ENOMEM;
seq = filp->private_data; priv->sbi = inode->i_private;
seq->private = inode->i_private; priv->env = cl_env_get(&priv->refcheck);
if (IS_ERR(priv->env)) {
int err = PTR_ERR(priv->env);
seq_release_private(inode, filp);
return err;
}
return 0; return 0;
} }
static int vvp_dump_pgcache_seq_release(struct inode *inode, struct file *file)
{
struct seq_file *seq = file->private_data;
struct seq_private *priv = seq->private;
cl_env_put(priv->env, &priv->refcheck);
return seq_release_private(inode, file);
}
const struct file_operations vvp_dump_pgcache_file_ops = { const struct file_operations vvp_dump_pgcache_file_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = vvp_dump_pgcache_seq_open, .open = vvp_dump_pgcache_seq_open,
.read = seq_read, .read = seq_read,
.llseek = seq_lseek, .llseek = seq_lseek,
.release = seq_release, .release = vvp_dump_pgcache_seq_release,
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment