Commit 5231f765 authored by Lai Siyao's avatar Lai Siyao Committed by Greg Kroah-Hartman

staging: lustre: statahead: small fixes and cleanup

small fixes:
 * when 'unplug' is set for ll_statahead(), sa_put() shouldn't kill
   the entry found, because its inflight RPC may not finish yet.
 * remove 'sai_generation', add 'lli_sa_generation' because the
   former one is not safe to access without lock.
 * revalidate_statahead_dentry() may fail to wait for statahead
   entry to become ready, in this case it should not release this
   entry, because it may be used by inflight statahead RPC.

cleanups:
 * rename ll_statahead_enter() to ll_statahead().
 * move dentry 'lld_sa_generation' update to ll_statahead() to
   simplify code and logic.
 * other small cleanups.
Signed-off-by: default avatarLai Siyao <lai.siyao@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-3270
Reviewed-on: http://review.whamcloud.com/9667
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6222
Reviewed-on: http://review.whamcloud.com/13708Reviewed-by: default avatarFan Yong <fan.yong@intel.com>
Reviewed-by: default avatarBobi Jam <bobijam@hotmail.com>
Reviewed-by: default avatarJames Simmons <uja.ornl@gmail.com>
Reviewed-by: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarJames Simmons <jsimmons@infradead.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9ca6fb12
...@@ -278,14 +278,13 @@ static int ll_revalidate_dentry(struct dentry *dentry, ...@@ -278,14 +278,13 @@ static int ll_revalidate_dentry(struct dentry *dentry,
if (lookup_flags & (LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE)) if (lookup_flags & (LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE))
return 1; return 1;
if (!dentry_need_statahead(dir, dentry)) if (!dentry_may_statahead(dir, dentry))
return 1; return 1;
if (lookup_flags & LOOKUP_RCU) if (lookup_flags & LOOKUP_RCU)
return -ECHILD; return -ECHILD;
do_statahead_enter(dir, &dentry, !d_inode(dentry)); ll_statahead(dir, &dentry, !d_inode(dentry));
ll_statahead_mark(dir, dentry);
return 1; return 1;
} }
......
...@@ -161,7 +161,7 @@ struct ll_inode_info { ...@@ -161,7 +161,7 @@ struct ll_inode_info {
/* for directory */ /* for directory */
struct { struct {
/* serialize normal readdir and statahead-readdir. */ /* serialize normal readdir and statahead-readdir. */
struct mutex d_readdir_mutex; struct mutex lli_readdir_mutex;
/* metadata statahead */ /* metadata statahead */
/* since parent-child threads can share the same @file /* since parent-child threads can share the same @file
...@@ -169,44 +169,35 @@ struct ll_inode_info { ...@@ -169,44 +169,35 @@ struct ll_inode_info {
* case of parent exit before child -- it is me should * case of parent exit before child -- it is me should
* cleanup the dir readahead. * cleanup the dir readahead.
*/ */
void *d_opendir_key; void *lli_opendir_key;
struct ll_statahead_info *d_sai; struct ll_statahead_info *lli_sai;
/* protect statahead stuff. */ /* protect statahead stuff. */
spinlock_t d_sa_lock; spinlock_t lli_sa_lock;
/* "opendir_pid" is the token when lookup/revalidate /* "opendir_pid" is the token when lookup/revalidate
* -- I am the owner of dir statahead. * -- I am the owner of dir statahead.
*/ */
pid_t d_opendir_pid; pid_t lli_opendir_pid;
/* stat will try to access statahead entries or start /* stat will try to access statahead entries or start
* statahead if this flag is set, and this flag will be * statahead if this flag is set, and this flag will be
* set upon dir open, and cleared when dir is closed, * set upon dir open, and cleared when dir is closed,
* statahead hit ratio is too low, or start statahead * statahead hit ratio is too low, or start statahead
* thread failed. * thread failed.
*/ */
unsigned int d_sa_enabled:1; unsigned int lli_sa_enabled:1;
/* generation for statahead */
unsigned int lli_sa_generation;
/* directory stripe information */ /* directory stripe information */
struct lmv_stripe_md *d_lsm_md; struct lmv_stripe_md *lli_lsm_md;
/* striped directory size */ /* striped directory size */
loff_t d_stripe_size; loff_t lli_stripe_dir_size;
/* striped directory nlink */ u64 lli_stripe_dir_nlink;
__u64 d_stripe_nlink; };
} d;
#define lli_readdir_mutex u.d.d_readdir_mutex
#define lli_opendir_key u.d.d_opendir_key
#define lli_sai u.d.d_sai
#define lli_sa_lock u.d.d_sa_lock
#define lli_sa_enabled u.d.d_sa_enabled
#define lli_opendir_pid u.d.d_opendir_pid
#define lli_lsm_md u.d.d_lsm_md
#define lli_stripe_dir_size u.d.d_stripe_size
#define lli_stripe_dir_nlink u.d.d_stripe_nlink
/* for non-directory */ /* for non-directory */
struct { struct {
struct mutex f_size_mutex; struct mutex lli_size_mutex;
char *f_symlink_name; char *lli_symlink_name;
__u64 f_maxbytes; __u64 lli_maxbytes;
/* /*
* struct rw_semaphore { * struct rw_semaphore {
* signed long count; // align d.d_def_acl * signed long count; // align d.d_def_acl
...@@ -214,16 +205,16 @@ struct ll_inode_info { ...@@ -214,16 +205,16 @@ struct ll_inode_info {
* struct list_head wait_list; * struct list_head wait_list;
* } * }
*/ */
struct rw_semaphore f_trunc_sem; struct rw_semaphore lli_trunc_sem;
struct range_lock_tree f_write_tree; struct range_lock_tree lli_write_tree;
struct rw_semaphore f_glimpse_sem; struct rw_semaphore lli_glimpse_sem;
unsigned long f_glimpse_time; unsigned long lli_glimpse_time;
struct list_head f_agl_list; struct list_head lli_agl_list;
__u64 f_agl_index; __u64 lli_agl_index;
/* for writepage() only to communicate to fsync */ /* for writepage() only to communicate to fsync */
int f_async_rc; int lli_async_rc;
/* /*
* whenever a process try to read/write the file, the * whenever a process try to read/write the file, the
...@@ -233,22 +224,9 @@ struct ll_inode_info { ...@@ -233,22 +224,9 @@ struct ll_inode_info {
* so the read/write statistics for jobid will not be * so the read/write statistics for jobid will not be
* accurate if the file is shared by different jobs. * accurate if the file is shared by different jobs.
*/ */
char f_jobid[LUSTRE_JOBID_SIZE]; char lli_jobid[LUSTRE_JOBID_SIZE];
} f; };
};
#define lli_size_mutex u.f.f_size_mutex
#define lli_symlink_name u.f.f_symlink_name
#define lli_maxbytes u.f.f_maxbytes
#define lli_trunc_sem u.f.f_trunc_sem
#define lli_write_tree u.f.f_write_tree
#define lli_glimpse_sem u.f.f_glimpse_sem
#define lli_glimpse_time u.f.f_glimpse_time
#define lli_agl_list u.f.f_agl_list
#define lli_agl_index u.f.f_agl_index
#define lli_async_rc u.f.f_async_rc
#define lli_jobid u.f.f_jobid
} u;
/* XXX: For following frequent used members, although they maybe special /* XXX: For following frequent used members, although they maybe special
* used for non-directory object, it is some time-wasting to check * used for non-directory object, it is some time-wasting to check
...@@ -1095,11 +1073,10 @@ void ll_ra_stats_inc(struct inode *inode, enum ra_stat which); ...@@ -1095,11 +1073,10 @@ void ll_ra_stats_inc(struct inode *inode, enum ra_stat which);
/* per inode struct, for dir only */ /* per inode struct, for dir only */
struct ll_statahead_info { struct ll_statahead_info {
struct inode *sai_inode; struct dentry *sai_dentry;
atomic_t sai_refcount; /* when access this struct, hold atomic_t sai_refcount; /* when access this struct, hold
* refcount * refcount
*/ */
unsigned int sai_generation; /* generation for statahead */
unsigned int sai_max; /* max ahead of lookup */ unsigned int sai_max; /* max ahead of lookup */
__u64 sai_sent; /* stat requests sent count */ __u64 sai_sent; /* stat requests sent count */
__u64 sai_replied; /* stat requests which received __u64 sai_replied; /* stat requests which received
...@@ -1142,8 +1119,7 @@ struct ll_statahead_info { ...@@ -1142,8 +1119,7 @@ struct ll_statahead_info {
atomic_t sai_cache_count; /* entry count in cache */ atomic_t sai_cache_count; /* entry count in cache */
}; };
int do_statahead_enter(struct inode *dir, struct dentry **dentry, int ll_statahead(struct inode *dir, struct dentry **dentry, bool unplug);
int only_unplug);
void ll_authorize_statahead(struct inode *dir, void *key); void ll_authorize_statahead(struct inode *dir, void *key);
void ll_deauthorize_statahead(struct inode *dir, void *key); void ll_deauthorize_statahead(struct inode *dir, void *key);
...@@ -1175,24 +1151,12 @@ static inline int ll_glimpse_size(struct inode *inode) ...@@ -1175,24 +1151,12 @@ static inline int ll_glimpse_size(struct inode *inode)
return rc; return rc;
} }
static inline void /*
ll_statahead_mark(struct inode *dir, struct dentry *dentry) * dentry may statahead when statahead is enabled and current process has opened
{ * parent directory, and this dentry hasn't accessed statahead cache before
struct ll_inode_info *lli = ll_i2info(dir); */
struct ll_statahead_info *sai = lli->lli_sai;
struct ll_dentry_data *ldd = ll_d2d(dentry);
/* not the same process, don't mark */
if (lli->lli_opendir_pid != current_pid())
return;
LASSERT(ldd);
if (sai)
ldd->lld_sa_generation = sai->sai_generation;
}
static inline bool static inline bool
dentry_need_statahead(struct inode *dir, struct dentry *dentry) dentry_may_statahead(struct inode *dir, struct dentry *dentry)
{ {
struct ll_inode_info *lli; struct ll_inode_info *lli;
struct ll_dentry_data *ldd; struct ll_dentry_data *ldd;
...@@ -1215,38 +1179,27 @@ dentry_need_statahead(struct inode *dir, struct dentry *dentry) ...@@ -1215,38 +1179,27 @@ dentry_need_statahead(struct inode *dir, struct dentry *dentry)
if (lli->lli_opendir_pid != current_pid()) if (lli->lli_opendir_pid != current_pid())
return false; return false;
ldd = ll_d2d(dentry);
/* /*
* When stats a dentry, the system trigger more than once "revalidate" * When stating a dentry, kernel may trigger 'revalidate' or 'lookup'
* or "lookup", for "getattr", for "getxattr", and maybe for others. * multiple times, eg. for 'getattr', 'getxattr' and etc.
* Under patchless client mode, the operation intent is not accurate, * For patchless client, lookup intent is not accurate, which may
* which maybe misguide the statahead thread. For example: * misguide statahead. For example:
* The "revalidate" call for "getattr" and "getxattr" of a dentry maybe * The 'revalidate' call for 'getattr' and 'getxattr' of a dentry will
* have the same operation intent -- "IT_GETATTR". * have the same intent -- IT_GETATTR, while one dentry should access
* In fact, one dentry should has only one chance to interact with the * statahead cache once, otherwise statahead windows is messed up.
* statahead thread, otherwise the statahead windows will be confused.
* The solution is as following: * The solution is as following:
* Assign "lld_sa_generation" with "sai_generation" when a dentry * Assign 'lld_sa_generation' with 'lli_sa_generation' when a dentry
* "IT_GETATTR" for the first time, and the subsequent "IT_GETATTR" * IT_GETATTR for the first time, and subsequent IT_GETATTR will
* will bypass interacting with statahead thread for checking: * bypass interacting with statahead cache by checking
* "lld_sa_generation == lli_sai->sai_generation" * 'lld_sa_generation == lli->lli_sa_generation'.
*/ */
if (ldd && lli->lli_sai && ldd = ll_d2d(dentry);
ldd->lld_sa_generation == lli->lli_sai->sai_generation) if (ldd && ldd->lld_sa_generation == lli->lli_sa_generation)
return false; return false;
return true; return true;
} }
static inline int
ll_statahead_enter(struct inode *dir, struct dentry **dentryp, int only_unplug)
{
if (!dentry_need_statahead(dir, *dentryp))
return -EAGAIN;
return do_statahead_enter(dir, dentryp, only_unplug);
}
/* llite ioctl register support routine */ /* llite ioctl register support routine */
enum llioc_iter { enum llioc_iter {
LLIOC_CONT = 0, LLIOC_CONT = 0,
......
...@@ -522,8 +522,8 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, ...@@ -522,8 +522,8 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
if (!it || it->it_op == IT_GETXATTR) if (!it || it->it_op == IT_GETXATTR)
it = &lookup_it; it = &lookup_it;
if (it->it_op == IT_GETATTR) { if (it->it_op == IT_GETATTR && dentry_may_statahead(parent, dentry)) {
rc = ll_statahead_enter(parent, &dentry, 0); rc = ll_statahead(parent, &dentry, 0);
if (rc == 1) { if (rc == 1) {
if (dentry == save) if (dentry == save)
retval = NULL; retval = NULL;
...@@ -574,11 +574,8 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, ...@@ -574,11 +574,8 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
retval = NULL; retval = NULL;
else else
retval = dentry; retval = dentry;
out: out:
if (req)
ptlrpc_req_finished(req); ptlrpc_req_finished(req);
if (it->it_op == IT_GETATTR && (!retval || retval == dentry))
ll_statahead_mark(parent, dentry);
return retval; return retval;
} }
......
...@@ -1367,7 +1367,7 @@ static int mdc_read_page(struct obd_export *exp, struct md_op_data *op_data, ...@@ -1367,7 +1367,7 @@ static int mdc_read_page(struct obd_export *exp, struct md_op_data *op_data,
page = mdc_page_locate(mapping, &rp_param.rp_off, &start, &end, page = mdc_page_locate(mapping, &rp_param.rp_off, &start, &end,
rp_param.rp_hash64); rp_param.rp_hash64);
if (IS_ERR(page)) { if (IS_ERR(page)) {
CERROR("%s: dir page locate: "DFID" at %llu: rc %ld\n", CDEBUG(D_INFO, "%s: dir page locate: " DFID " at %llu: rc %ld\n",
exp->exp_obd->obd_name, PFID(&op_data->op_fid1), exp->exp_obd->obd_name, PFID(&op_data->op_fid1),
rp_param.rp_off, PTR_ERR(page)); rp_param.rp_off, PTR_ERR(page));
rc = PTR_ERR(page); rc = PTR_ERR(page);
......
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