Skip to content
Snippets Groups Projects
Commit 1baaf4fc authored by Yang Sheng's avatar Yang Sheng
Browse files

Branch b1_6

b=16208
i=johann, adilger

Bring down the stack usage
parent aff29f45
No related branches found
No related tags found
No related merge requests found
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
/* OBD Device Declarations */ /* OBD Device Declarations */
extern struct obd_device *obd_devs[MAX_OBD_DEVICES]; extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
extern spinlock_t obd_dev_lock; extern spinlock_t obd_dev_lock;
extern cfs_mem_cache_t *obd_lvfs_ctxt_cache;
/* OBD Operations Declarations */ /* OBD Operations Declarations */
extern struct obd_device *class_conn2obd(struct lustre_handle *); extern struct obd_device *class_conn2obd(struct lustre_handle *);
......
...@@ -177,12 +177,18 @@ int mds_client_add(struct obd_device *obd, struct obd_export *exp, ...@@ -177,12 +177,18 @@ int mds_client_add(struct obd_device *obd, struct obd_export *exp,
mds_export_stats_init(obd, exp, localdata); mds_export_stats_init(obd, exp, localdata);
if (new_client) { if (new_client) {
struct lvfs_run_ctxt saved; struct lvfs_run_ctxt *saved = NULL;
loff_t off = med->med_lr_off; loff_t off = med->med_lr_off;
struct file *file = mds->mds_rcvd_filp; struct file *file = mds->mds_rcvd_filp;
void *handle; void *handle;
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
if (saved == NULL) {
CERROR("cannot allocate memory for run ctxt\n");
RETURN(-ENOMEM);
}
push_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
handle = fsfilt_start(obd, file->f_dentry->d_inode, handle = fsfilt_start(obd, file->f_dentry->d_inode,
FSFILT_OP_SETATTR, NULL); FSFILT_OP_SETATTR, NULL);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
...@@ -202,7 +208,8 @@ int mds_client_add(struct obd_device *obd, struct obd_export *exp, ...@@ -202,7 +208,8 @@ int mds_client_add(struct obd_device *obd, struct obd_export *exp,
fsfilt_commit(obd, file->f_dentry->d_inode, handle, 0); fsfilt_commit(obd, file->f_dentry->d_inode, handle, 0);
} }
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); pop_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
if (rc) if (rc)
return rc; return rc;
...@@ -219,7 +226,7 @@ int mds_client_free(struct obd_export *exp) ...@@ -219,7 +226,7 @@ int mds_client_free(struct obd_export *exp)
struct mds_obd *mds = &exp->exp_obd->u.mds; struct mds_obd *mds = &exp->exp_obd->u.mds;
struct obd_device *obd = exp->exp_obd; struct obd_device *obd = exp->exp_obd;
struct lsd_client_data zero_lcd; struct lsd_client_data zero_lcd;
struct lvfs_run_ctxt saved; struct lvfs_run_ctxt *saved = NULL;
int rc; int rc;
loff_t off; loff_t off;
ENTRY; ENTRY;
...@@ -256,13 +263,18 @@ int mds_client_free(struct obd_export *exp) ...@@ -256,13 +263,18 @@ int mds_client_free(struct obd_export *exp)
} }
if (!(exp->exp_flags & OBD_OPT_FAILOVER)) { if (!(exp->exp_flags & OBD_OPT_FAILOVER)) {
OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
if (saved == NULL) {
CERROR("cannot allocate memory for run ctxt\n");
GOTO(free, rc = -ENOMEM);
}
memset(&zero_lcd, 0, sizeof(zero_lcd)); memset(&zero_lcd, 0, sizeof(zero_lcd));
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); push_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
rc = fsfilt_write_record(obd, mds->mds_rcvd_filp, &zero_lcd, rc = fsfilt_write_record(obd, mds->mds_rcvd_filp, &zero_lcd,
sizeof(zero_lcd), &off, sizeof(zero_lcd), &off,
(!exp->exp_libclient || (!exp->exp_libclient ||
exp->exp_need_sync)); exp->exp_need_sync));
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); pop_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
CDEBUG(rc == 0 ? D_INFO : D_ERROR, CDEBUG(rc == 0 ? D_INFO : D_ERROR,
"zeroing out client %s idx %u in %s rc %d\n", "zeroing out client %s idx %u in %s rc %d\n",
...@@ -282,7 +294,10 @@ int mds_client_free(struct obd_export *exp) ...@@ -282,7 +294,10 @@ int mds_client_free(struct obd_export *exp)
mds_update_server_data(exp->exp_obd, 0); mds_update_server_data(exp->exp_obd, 0);
EXIT; EXIT;
free: free:
if (saved)
OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
OBD_FREE_PTR(med->med_lcd); OBD_FREE_PTR(med->med_lcd);
med->med_lcd = NULL; med->med_lcd = NULL;
...@@ -523,7 +538,7 @@ err_msd: ...@@ -523,7 +538,7 @@ err_msd:
int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt) int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
{ {
struct mds_obd *mds = &obd->u.mds; struct mds_obd *mds = &obd->u.mds;
struct lvfs_run_ctxt saved; struct lvfs_run_ctxt *saved = NULL;
struct dentry *dentry; struct dentry *dentry;
struct file *file; struct file *file;
int rc; int rc;
...@@ -535,6 +550,12 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt) ...@@ -535,6 +550,12 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
if (rc) if (rc)
RETURN(rc); RETURN(rc);
OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
if (saved == NULL) {
CERROR("cannot allocate memory for run ctxt\n");
RETURN(-ENOMEM);
}
mds->mds_vfsmnt = mnt; mds->mds_vfsmnt = mnt;
/* why not mnt->mnt_sb instead of mnt->mnt_root->d_inode->i_sb? */ /* why not mnt->mnt_sb instead of mnt->mnt_root->d_inode->i_sb? */
obd->u.obt.obt_sb = mnt->mnt_root->d_inode->i_sb; obd->u.obt.obt_sb = mnt->mnt_root->d_inode->i_sb;
...@@ -550,7 +571,7 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt) ...@@ -550,7 +571,7 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
obd->obd_lvfs_ctxt.cb_ops = mds_lvfs_ops; obd->obd_lvfs_ctxt.cb_ops = mds_lvfs_ops;
/* setup the directory tree */ /* setup the directory tree */
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); push_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
dentry = simple_mkdir(current->fs->pwd, mnt, "ROOT", 0755, 0); dentry = simple_mkdir(current->fs->pwd, mnt, "ROOT", 0755, 0);
if (IS_ERR(dentry)) { if (IS_ERR(dentry)) {
rc = PTR_ERR(dentry); rc = PTR_ERR(dentry);
...@@ -649,8 +670,8 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt) ...@@ -649,8 +670,8 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
if (rc) if (rc)
GOTO(err_health_check, rc); GOTO(err_health_check, rc);
err_pop: err_pop:
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); pop_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
return rc; return rc;
err_health_check: err_health_check:
...@@ -678,9 +699,15 @@ err_fid: ...@@ -678,9 +699,15 @@ err_fid:
int mds_fs_cleanup(struct obd_device *obd) int mds_fs_cleanup(struct obd_device *obd)
{ {
struct mds_obd *mds = &obd->u.mds; struct mds_obd *mds = &obd->u.mds;
struct lvfs_run_ctxt saved; struct lvfs_run_ctxt *saved = NULL;
int rc = 0; int rc = 0;
OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
if (saved == NULL) {
CERROR("cannot allocate memory for run ctxt\n");
RETURN(-ENOMEM);
}
if (obd->obd_fail) if (obd->obd_fail)
LCONSOLE_WARN("%s: shutting down for failover; client state " LCONSOLE_WARN("%s: shutting down for failover; client state "
"will be preserved.\n", obd->obd_name); "will be preserved.\n", obd->obd_name);
...@@ -688,7 +715,7 @@ int mds_fs_cleanup(struct obd_device *obd) ...@@ -688,7 +715,7 @@ int mds_fs_cleanup(struct obd_device *obd)
class_disconnect_exports(obd); /* cleans up client info too */ class_disconnect_exports(obd); /* cleans up client info too */
mds_server_free_data(mds); mds_server_free_data(mds);
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); push_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
if (mds->mds_rcvd_filp) { if (mds->mds_rcvd_filp) {
rc = filp_close(mds->mds_rcvd_filp, 0); rc = filp_close(mds->mds_rcvd_filp, 0);
mds->mds_rcvd_filp = NULL; mds->mds_rcvd_filp = NULL;
...@@ -719,7 +746,8 @@ int mds_fs_cleanup(struct obd_device *obd) ...@@ -719,7 +746,8 @@ int mds_fs_cleanup(struct obd_device *obd)
lquota_fs_cleanup(mds_quota_interface_ref, obd); lquota_fs_cleanup(mds_quota_interface_ref, obd);
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); pop_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
shrink_dcache_parent(mds->mds_fid_de); shrink_dcache_parent(mds->mds_fid_de);
dput(mds->mds_fid_de); dput(mds->mds_fid_de);
LL_DQUOT_OFF(obd->u.obt.obt_sb); LL_DQUOT_OFF(obd->u.obt.obt_sb);
...@@ -738,17 +766,23 @@ int mds_obd_create(struct obd_export *exp, struct obdo *oa, ...@@ -738,17 +766,23 @@ int mds_obd_create(struct obd_export *exp, struct obdo *oa,
unsigned int tmpname = ll_rand(); unsigned int tmpname = ll_rand();
struct file *filp; struct file *filp;
struct dentry *new_child; struct dentry *new_child;
struct lvfs_run_ctxt saved; struct lvfs_run_ctxt *saved = NULL;
char fidname[LL_FID_NAMELEN]; char fidname[LL_FID_NAMELEN];
void *handle; void *handle;
struct lvfs_ucred ucred = { 0 }; struct lvfs_ucred ucred = { 0 };
int rc = 0, err, namelen; int rc = 0, err, namelen;
ENTRY; ENTRY;
OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
if (saved == NULL) {
CERROR("cannot allocate memory for run ctxt\n");
RETURN(-ENOMEM);
}
/* the owner of object file should always be root */ /* the owner of object file should always be root */
cap_raise(ucred.luc_cap, CAP_SYS_RESOURCE); cap_raise(ucred.luc_cap, CAP_SYS_RESOURCE);
push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, &ucred); push_ctxt(saved, &exp->exp_obd->obd_lvfs_ctxt, &ucred);
sprintf(fidname, "OBJECTS/%u.%u", tmpname, current->pid); sprintf(fidname, "OBJECTS/%u.%u", tmpname, current->pid);
filp = filp_open(fidname, O_CREAT | O_EXCL, 0666); filp = filp_open(fidname, O_CREAT | O_EXCL, 0666);
...@@ -813,7 +847,8 @@ out_close: ...@@ -813,7 +847,8 @@ out_close:
rc = err; rc = err;
} }
out_pop: out_pop:
pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, &ucred); pop_ctxt(saved, &exp->exp_obd->obd_lvfs_ctxt, &ucred);
OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
RETURN(rc); RETURN(rc);
} }
...@@ -824,7 +859,7 @@ int mds_obd_destroy(struct obd_export *exp, struct obdo *oa, ...@@ -824,7 +859,7 @@ int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
struct mds_obd *mds = &exp->exp_obd->u.mds; struct mds_obd *mds = &exp->exp_obd->u.mds;
struct inode *parent_inode = mds->mds_objects_dir->d_inode; struct inode *parent_inode = mds->mds_objects_dir->d_inode;
struct obd_device *obd = exp->exp_obd; struct obd_device *obd = exp->exp_obd;
struct lvfs_run_ctxt saved; struct lvfs_run_ctxt *saved = NULL;
struct lvfs_ucred ucred = { 0 }; struct lvfs_ucred ucred = { 0 };
char fidname[LL_FID_NAMELEN]; char fidname[LL_FID_NAMELEN];
struct inode *inode = NULL; struct inode *inode = NULL;
...@@ -833,8 +868,14 @@ int mds_obd_destroy(struct obd_export *exp, struct obdo *oa, ...@@ -833,8 +868,14 @@ int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
int err, namelen, rc = 0; int err, namelen, rc = 0;
ENTRY; ENTRY;
OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
if (saved == NULL) {
CERROR("cannot allocate memory for run ctxt\n");
RETURN(-ENOMEM);
}
cap_raise(ucred.luc_cap, CAP_SYS_RESOURCE); cap_raise(ucred.luc_cap, CAP_SYS_RESOURCE);
push_ctxt(&saved, &obd->obd_lvfs_ctxt, &ucred); push_ctxt(saved, &obd->obd_lvfs_ctxt, &ucred);
namelen = ll_fid2str(fidname, oa->o_id, oa->o_generation); namelen = ll_fid2str(fidname, oa->o_id, oa->o_generation);
...@@ -881,6 +922,7 @@ out_dput: ...@@ -881,6 +922,7 @@ out_dput:
if (inode) if (inode)
iput(inode); iput(inode);
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &ucred); pop_ctxt(saved, &obd->obd_lvfs_ctxt, &ucred);
OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
RETURN(rc); RETURN(rc);
} }
...@@ -58,6 +58,7 @@ atomic_t libcfs_kmemory = {0}; ...@@ -58,6 +58,7 @@ atomic_t libcfs_kmemory = {0};
struct obd_device *obd_devs[MAX_OBD_DEVICES]; struct obd_device *obd_devs[MAX_OBD_DEVICES];
struct list_head obd_types; struct list_head obd_types;
spinlock_t obd_dev_lock = SPIN_LOCK_UNLOCKED; spinlock_t obd_dev_lock = SPIN_LOCK_UNLOCKED;
cfs_mem_cache_t *obd_lvfs_ctxt_cache;
/* The following are visible and mutable through /proc/sys/lustre/. */ /* The following are visible and mutable through /proc/sys/lustre/. */
unsigned int obd_debug_peer_on_timeout; unsigned int obd_debug_peer_on_timeout;
...@@ -375,6 +376,7 @@ void *obd_psdev = NULL; ...@@ -375,6 +376,7 @@ void *obd_psdev = NULL;
#endif #endif
EXPORT_SYMBOL(obd_devs); EXPORT_SYMBOL(obd_devs);
EXPORT_SYMBOL(obd_lvfs_ctxt_cache);
EXPORT_SYMBOL(obd_print_fail_loc); EXPORT_SYMBOL(obd_print_fail_loc);
EXPORT_SYMBOL(obd_race_waitq); EXPORT_SYMBOL(obd_race_waitq);
EXPORT_SYMBOL(obd_race_state); EXPORT_SYMBOL(obd_race_state);
...@@ -548,6 +550,11 @@ int init_obdclass(void) ...@@ -548,6 +550,11 @@ int init_obdclass(void)
LPROCFS_CNTR_AVGMINMAX, LPROCFS_CNTR_AVGMINMAX,
"pagesused", "pages"); "pagesused", "pages");
#endif #endif
obd_lvfs_ctxt_cache = cfs_mem_cache_create("obd_lvfs_ctxt_cache",
sizeof(struct lvfs_run_ctxt), 0, 0);
if (obd_lvfs_ctxt_cache == NULL)
RETURN(-ENOMEM);
err = obd_init_checks(); err = obd_init_checks();
if (err == -EOVERFLOW) if (err == -EOVERFLOW)
return err; return err;
...@@ -630,6 +637,8 @@ static void cleanup_obdclass(void) ...@@ -630,6 +637,8 @@ static void cleanup_obdclass(void)
memory_max = obd_memory_max(); memory_max = obd_memory_max();
pages_max = obd_pages_max(); pages_max = obd_pages_max();
cfs_mem_cache_destroy(obd_lvfs_ctxt_cache);
lprocfs_free_stats(&obd_memory); lprocfs_free_stats(&obd_memory);
CDEBUG((memory_leaked | pages_leaked) ? D_ERROR : D_INFO, CDEBUG((memory_leaked | pages_leaked) ? D_ERROR : D_INFO,
"obd_memory max: "LPU64", leaked: "LPU64" " "obd_memory max: "LPU64", leaked: "LPU64" "
......
...@@ -292,13 +292,17 @@ int llog_obd_origin_setup(struct obd_device *obd, int index, ...@@ -292,13 +292,17 @@ int llog_obd_origin_setup(struct obd_device *obd, int index,
{ {
struct llog_ctxt *ctxt; struct llog_ctxt *ctxt;
struct llog_handle *handle; struct llog_handle *handle;
struct lvfs_run_ctxt saved; struct lvfs_run_ctxt *saved = NULL;
int rc; int rc;
ENTRY; ENTRY;
if (count == 0) if (count == 0)
RETURN(0); RETURN(0);
OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
if (saved == NULL)
RETURN(-ENOMEM);
LASSERT(count == 1); LASSERT(count == 1);
ctxt = llog_get_context(obd, index); ctxt = llog_get_context(obd, index);
...@@ -316,9 +320,9 @@ int llog_obd_origin_setup(struct obd_device *obd, int index, ...@@ -316,9 +320,9 @@ int llog_obd_origin_setup(struct obd_device *obd, int index,
GOTO(out, rc); GOTO(out, rc);
ctxt->loc_handle = handle; ctxt->loc_handle = handle;
push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL); push_ctxt(saved, &disk_obd->obd_lvfs_ctxt, NULL);
rc = llog_init_handle(handle, LLOG_F_IS_CAT, NULL); rc = llog_init_handle(handle, LLOG_F_IS_CAT, NULL);
pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL); pop_ctxt(saved, &disk_obd->obd_lvfs_ctxt, NULL);
if (rc) if (rc)
GOTO(out, rc); GOTO(out, rc);
...@@ -327,6 +331,7 @@ int llog_obd_origin_setup(struct obd_device *obd, int index, ...@@ -327,6 +331,7 @@ int llog_obd_origin_setup(struct obd_device *obd, int index,
CERROR("llog_process with cat_cancel_cb failed: %d\n", rc); CERROR("llog_process with cat_cancel_cb failed: %d\n", rc);
out: out:
llog_ctxt_put(ctxt); llog_ctxt_put(ctxt);
OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
RETURN(rc); RETURN(rc);
} }
EXPORT_SYMBOL(llog_obd_origin_setup); EXPORT_SYMBOL(llog_obd_origin_setup);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment