From f3fb4f87f9fa8853c896bfa716e29df219f03c63 Mon Sep 17 00:00:00 2001 From: tappro Date: Sat, 25 Jun 2005 22:10:50 +0000 Subject: [PATCH] b=5881 - protect smfs plugins operations - alloc plugin before registration --- lustre/smfs/kml.c | 68 +++++++++++++++++++++++++++++--------------------- lustre/smfs/mds_kml.c | 1 + lustre/smfs/ost_kml.c | 3 ++- lustre/smfs/smfs_api.h | 2 +- lustre/smfs/smfs_lib.c | 60 +++++++++++++++++++------------------------- 5 files changed, 70 insertions(+), 64 deletions(-) diff --git a/lustre/smfs/kml.c b/lustre/smfs/kml.c index ccb3522..bcb416d 100644 --- a/lustre/smfs/kml.c +++ b/lustre/smfs/kml.c @@ -39,6 +39,7 @@ #include #include "smfs_internal.h" +#if 0 #define KML_BUF_REC_INIT(buffer, pbuf, len) \ do { \ pbuf = buffer + sizeof(int); \ @@ -104,7 +105,7 @@ static int smfs_llog_process_rec_cb(struct llog_handle *handle, exit: RETURN(rc); } - +#endif #if 0 /* not used curently */ static smfs_pack_rec_func smfs_get_rec_pack_type(struct super_block *sb) @@ -176,7 +177,8 @@ EXPORT_SYMBOL(smfs_rec_unpack); /* cmobd/cm_reint.c */ int smfs_write_extents(struct inode *dir, struct dentry *dentry, unsigned long from, unsigned long num) { - return 0;//smfs_post_rec_write(dir, dentry, &from, &num); + //smfs_post_rec_write(dir, dentry, &from, &num); + return 0; } #if 0 int smfs_rec_precreate(struct dentry *dentry, int *num, struct obdo *oa) @@ -240,9 +242,7 @@ int smfs_process_rec(struct super_block *sb, } RETURN(rc); } -#endif -#if 0 /*smfs_path is gotten from intermezzo*/ static char* smfs_path(struct dentry *dentry, struct dentry *root, char *buffer, int buflen) @@ -700,10 +700,17 @@ static int smfs_kml_post_op(int code, struct inode * inode, /* Helpers */ static int smfs_exit_kml(struct super_block *sb, void * arg, struct kml_priv * priv) { + struct smfs_plugin * plg = NULL; ENTRY; - smfs_deregister_plugin(sb, SMFS_PLG_KML); - OBD_FREE(priv, sizeof(*priv)); + plg = smfs_deregister_plugin(sb, SMFS_PLG_KML); + if (plg) + OBD_FREE(plg, sizeof(*plg)); + else + CERROR("Cannot find KLM plugin while unregistering\n"); + + if (priv) + OBD_FREE(priv, sizeof(*priv)); EXIT; return 0; @@ -754,7 +761,7 @@ static int smfs_start_kml(struct super_block *sb, void *arg, RETURN(rc); } - (*ctxt)->llog_proc_cb = smfs_llog_process_rec_cb; + (*ctxt)->llog_proc_cb = NULL;//smfs_llog_process_rec_cb; SMFS_SET(smb->plg_flags, SMFS_PLG_KML); @@ -803,33 +810,38 @@ int smfs_init_kml(struct super_block *sb) { int rc = 0; struct kml_priv * priv = NULL; - struct smfs_plugin plg = { - .plg_type = SMFS_PLG_KML, - .plg_pre_op = NULL, - .plg_post_op = &smfs_kml_post_op, - .plg_helper = &smfs_kml_help_op, - .plg_private = NULL, - }; - + struct smfs_plugin * plg = NULL; ENTRY; - + + OBD_ALLOC(plg, sizeof(*plg)); + if (!plg) { + rc = -ENOMEM; + goto exit; + } + + plg->plg_type = SMFS_PLG_KML; + plg->plg_pre_op = NULL; + plg->plg_post_op = &smfs_kml_post_op; + plg->plg_helper = &smfs_kml_help_op; + OBD_ALLOC(priv, sizeof(*priv)); if (!priv) { - RETURN(-ENOMEM); + rc = -ENOMEM; + goto exit; } - plg.plg_private = priv; - /* - rc = ost_rec_pack_init(smb); - if (rc) - return rc; - - rc = mds_rec_pack_init(smb); - if (rc) - return rc; - */ - rc = smfs_register_plugin(sb, &plg); + plg->plg_private = priv; + + rc = smfs_register_plugin(sb, plg); + if (!rc) + RETURN(0); +exit: + if (priv) + OBD_FREE(priv, sizeof(*priv)); + if (plg) + OBD_FREE(plg, sizeof(*plg)); + RETURN(rc); } diff --git a/lustre/smfs/mds_kml.c b/lustre/smfs/mds_kml.c index 2e8facf..d62350d 100644 --- a/lustre/smfs/mds_kml.c +++ b/lustre/smfs/mds_kml.c @@ -275,3 +275,4 @@ int mds_rec_pack(int op, char *buffer, struct dentry *dentry, } + diff --git a/lustre/smfs/ost_kml.c b/lustre/smfs/ost_kml.c index f2f48b0..b3a16df 100644 --- a/lustre/smfs/ost_kml.c +++ b/lustre/smfs/ost_kml.c @@ -187,10 +187,11 @@ int ost_rec_pack(char *buffer, struct dentry *dentry, struct inode *dir, } return 0; } - +#if 0 int ost_rec_pack_init(struct smfs_super_info *smsi) { smsi->smsi_pack_rec[PACK_OST] = ost_rec_pack; return 0; } +#endif diff --git a/lustre/smfs/smfs_api.h b/lustre/smfs/smfs_api.h index 25fb44f..d642da8 100644 --- a/lustre/smfs/smfs_api.h +++ b/lustre/smfs/smfs_api.h @@ -122,7 +122,7 @@ int smfs_helper (struct super_block *, int, void *); #define SMFS_PLG_HELP(sb, op, data) smfs_helper(sb, op, data) int smfs_register_plugin(struct super_block *, struct smfs_plugin *); -void * smfs_deregister_plugin(struct super_block *, int); +struct smfs_plugin * smfs_deregister_plugin(struct super_block *, int); int smfs_init_dummy(struct super_block *); int smfs_init_kml(struct super_block *); diff --git a/lustre/smfs/smfs_lib.c b/lustre/smfs/smfs_lib.c index b8144cf..68e2421 100644 --- a/lustre/smfs/smfs_lib.c +++ b/lustre/smfs/smfs_lib.c @@ -328,6 +328,7 @@ static int smfs_init_plugins(struct super_block * sb, int flags) ENTRY; INIT_LIST_HEAD(&smb->smsi_plg_list); + init_rwsem(&smb->plg_sem); if (SMFS_IS(flags, SMFS_PLG_KML)) smfs_init_kml(sb); @@ -476,57 +477,46 @@ void smfs_trans_commit(struct inode *inode, void *handle, int force_sync) } /* Plugin API */ int smfs_register_plugin(struct super_block * sb, - struct smfs_plugin * new_plugin) + struct smfs_plugin * plg) { + struct smfs_plugin * tmp = NULL; struct smfs_super_info * smb = S2SMI(sb); - struct smfs_plugin * plg = NULL; - struct list_head * plist = &S2SMI(sb)->smsi_plg_list; + struct list_head * plist = &smb->smsi_plg_list; + int rc = 0; ENTRY; - list_for_each_entry(plg, plist, plg_list) { - if (plg->plg_type == new_plugin->plg_type) { + down_write(&smb->plg_sem); + list_for_each_entry(tmp, plist, plg_list) { + if (tmp->plg_type == plg->plg_type) { CWARN("Plugin is already registered\n"); - RETURN(-EEXIST); + rc = -EEXIST; + goto exit; } } - - - if (SMFS_IS(smb->smsi_flags, new_plugin->plg_type)) { - CWARN("Plugin is already registered\n"); - RETURN(-EEXIST); - } - - OBD_ALLOC(plg, sizeof(*plg)); - if (!plg) { - CWARN("Cannot allocate memory for plugin\n"); - RETURN(-ENOMEM); - } - - memcpy(plg, new_plugin, sizeof(*plg)); + list_add_tail(&plg->plg_list, plist); - +exit: + up_write(&smb->plg_sem); RETURN(0); } -void * smfs_deregister_plugin(struct super_block *sb, int type) +struct smfs_plugin * smfs_deregister_plugin(struct super_block *sb, int type) { struct smfs_plugin * plg = NULL; - struct list_head * plist = &S2SMI(sb)->smsi_plg_list; - void * priv = NULL; - + struct smfs_super_info *smb = S2SMI(sb); + struct list_head * plist = &smb->smsi_plg_list; + ENTRY; - + down_write(&smb->plg_sem); list_for_each_entry(plg, plist, plg_list) { if (plg->plg_type == type) { list_del(&plg->plg_list); - priv = plg->plg_private; - OBD_FREE(plg, sizeof(*plg)); break; } } - - RETURN(priv); + up_write(&smb->plg_sem); + RETURN(plg); } void smfs_pre_hook (struct inode * inode, int op, void * msg) @@ -539,6 +529,7 @@ void smfs_pre_hook (struct inode * inode, int op, void * msg) //ENTRY; LASSERT(op < HOOK_MAX); //call hook operations + down_read(&smb->plg_sem); list_for_each_entry(plg, hlist, plg_list) { //check that plugin is active if(!SMFS_IS(smb->plg_flags, plg->plg_type)) @@ -550,7 +541,7 @@ void smfs_pre_hook (struct inode * inode, int op, void * msg) if (plg->plg_pre_op) plg->plg_pre_op(op, inode, msg, 0, plg->plg_private); } - + up_read(&smb->plg_sem); //EXIT; } @@ -562,7 +553,7 @@ void smfs_post_hook (struct inode * inode, int op, void * msg, int ret) struct smfs_plugin *plg; //ENTRY; - + down_read(&smb->plg_sem); list_for_each_entry(plg, hlist, plg_list) { //check that plugin is active if(!SMFS_IS(smb->plg_flags, plg->plg_type)) @@ -574,7 +565,7 @@ void smfs_post_hook (struct inode * inode, int op, void * msg, int ret) if (plg->plg_post_op) plg->plg_post_op(op, inode, msg, ret, plg->plg_private); } - + up_read(&smb->plg_sem); //EXIT; } @@ -588,6 +579,7 @@ int smfs_helper (struct super_block * sb, int op, void * msg) //ENTRY; LASSERT(op < PLG_HELPER_MAX); //call hook operations + down_read(&smb->plg_sem); list_for_each_entry_safe(plg, tmp, hlist, plg_list) { //check that plugin is active if(!SMFS_IS(smb->plg_flags, plg->plg_type) && (op != PLG_START)) @@ -596,7 +588,7 @@ int smfs_helper (struct super_block * sb, int op, void * msg) if (plg->plg_helper) rc += plg->plg_helper(op, sb, msg, plg->plg_private); } - + up_read(&smb->plg_sem); //EXIT; return rc; -- 1.8.3.1