#include <linux/lustre_smfs.h>
#include "smfs_internal.h"
+#if 0
#define KML_BUF_REC_INIT(buffer, pbuf, len) \
do { \
pbuf = buffer + sizeof(int); \
exit:
RETURN(rc);
}
-
+#endif
#if 0
/* not used curently */
static smfs_pack_rec_func smfs_get_rec_pack_type(struct super_block *sb)
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)
}
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)
/* 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;
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);
{
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);
}
ENTRY;
INIT_LIST_HEAD(&smb->smsi_plg_list);
+ init_rwsem(&smb->plg_sem);
if (SMFS_IS(flags, SMFS_PLG_KML))
smfs_init_kml(sb);
}
/* 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)
//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))
if (plg->plg_pre_op)
plg->plg_pre_op(op, inode, msg, 0, plg->plg_private);
}
-
+ up_read(&smb->plg_sem);
//EXIT;
}
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))
if (plg->plg_post_op)
plg->plg_post_op(op, inode, msg, ret, plg->plg_private);
}
-
+ up_read(&smb->plg_sem);
//EXIT;
}
//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))
if (plg->plg_helper)
rc += plg->plg_helper(op, sb, msg, plg->plg_private);
}
-
+ up_read(&smb->plg_sem);
//EXIT;
return rc;