Whamcloud - gitweb
- b_hd_audit landing
[fs/lustre-release.git] / lustre / smfs / smfs_lib.c
index 9723e74..dce98e2 100644 (file)
@@ -80,6 +80,8 @@ int smfs_options(char *data, char **devstr, char **namestr,
                                 *namestr = pos + 5;
                 } else if (!strcmp(pos, "kml")) {
                         SMFS_SET(*flags, SMFS_PLG_KML);
+                } else if (!strcmp(pos, "audit")) {
+                        SMFS_SET(*flags, SMFS_PLG_AUDIT);
                 } else if (!strcmp(pos, "cache")) {
                         SMFS_SET(*flags, SMFS_PLG_LRU);
                 } else if (!strcmp(pos, "snap")) {
@@ -194,6 +196,9 @@ static void smfs_mds_flags(struct mds_obd * mds, struct inode * root)
 }
                         
 
+extern int (*audit_id2name_superhack) (struct obd_device *obd, char **name,
+                                       int *namelen, struct lustre_id *id);
+
 int smfs_post_setup(struct obd_device *obd, struct vfsmount *mnt,
                     struct dentry * root_dentry)
 {
@@ -202,6 +207,10 @@ int smfs_post_setup(struct obd_device *obd, struct vfsmount *mnt,
         int rc = 0;
         
         ENTRY;
+
+        /* XXX to register id2name function of mds in smfs */
+        //if (data != NULL)
+        //        audit_id2name_superhack = data;
  
         OBD_ALLOC(current_ctxt, sizeof(*current_ctxt));
         if (!current_ctxt)
@@ -216,20 +225,13 @@ int smfs_post_setup(struct obd_device *obd, struct vfsmount *mnt,
         
         push_ctxt(&saved, smb->smsi_ctxt, NULL);
 
-        rc = smfs_llog_setup(smb);
+        rc = smfs_llog_setup(&smb->smsi_logs_dir, &smb->smsi_objects_dir);
         if (!rc) {
-                rc = SMFS_PLG_HELP(mnt->mnt_sb, PLG_START, NULL);
+                rc = SMFS_PLG_HELP(mnt->mnt_sb, PLG_START, obd);
         }
 
         pop_ctxt(&saved, smb->smsi_ctxt, NULL);
 
-        /* connect KML ctxt to obd */
-        if (obd && smb->smsi_kml_log) {
-                smb->smsi_kml_log->loc_idx = LLOG_REINT_ORIG_CTXT;
-                smb->smsi_kml_log->loc_obd = obd;
-                obd->obd_llog_ctxt[LLOG_REINT_ORIG_CTXT] = smb->smsi_kml_log;
-        }
-        
         /* enable plugins for directories on MDS or OST */
         if (obd && obd->obd_type && obd->obd_type->typ_name) {
                 if (!strcmp(obd->obd_type->typ_name, "obdfilter")) {
@@ -241,6 +243,7 @@ int smfs_post_setup(struct obd_device *obd, struct vfsmount *mnt,
                         struct mds_obd * mds = &obd->u.mds;
                         
                         smfs_mds_flags(mds, root_dentry->d_inode);
+                        SMFS_SET_HND_IBLOCKS(smb);
                 }
                 else
                         CDEBUG(D_SUPER,"Unknown OBD (%s) post_setup\n",
@@ -278,6 +281,7 @@ static int smfs_mount_cache(struct smfs_super_info *smb, char *devstr,
         typelen = strlen(typestr);
 
         CDEBUG(D_INODE, "smfs: mounting %s at %s\n", typestr, devstr);
+        
         mnt = do_kern_mount(typestr, 0, devstr, (void *)opts);
         if (IS_ERR(mnt)) {
                 CERROR("do_kern_mount failed: rc = %ld\n", 
@@ -328,7 +332,10 @@ 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_AUDIT))
+                smfs_init_audit(sb);
         if (SMFS_IS(flags, SMFS_PLG_KML)) 
                 smfs_init_kml(sb);
         if (SMFS_IS(flags, SMFS_PLG_LRU)) 
@@ -342,9 +349,15 @@ static int smfs_init_plugins(struct super_block * sb, int flags)
 
 static void smfs_remove_plugins(struct super_block *sb)
 {
+        struct smfs_plugin * plg, *tmp;
+        struct smfs_super_info *smb = S2SMI(sb);
+        struct list_head * plist = &smb->smsi_plg_list;
+                
         ENTRY;
-
-        SMFS_PLG_HELP(sb, PLG_EXIT, (void*)sb);
+        
+        list_for_each_entry_safe(plg, tmp, plist, plg_list) {
+                plg->plg_exit(sb, plg->plg_private);
+        }
         
         EXIT;
 }
@@ -367,13 +380,14 @@ void smfs_put_super(struct super_block *sb)
 int smfs_fill_super(struct super_block *sb, void *data, int silent)
 {
         struct inode *root_inode = NULL;
+       struct inode *back_root_inode = NULL;
         struct smfs_super_info *smb = NULL;
-        char *devstr = NULL, *typestr = NULL; 
+        char *devstr = NULL, *typestr = NULL;
+        unsigned long page = 0;
         char *opts = NULL;
-        int err = 0;
         int flags = 0;
-        ino_t root_ino;
-
+        int err = 0;
+        
         ENTRY;
         
         if (!data) {
@@ -387,12 +401,16 @@ int smfs_fill_super(struct super_block *sb, void *data, int silent)
         smb = smfs_init_smb(sb);
         if (!smb)
                 RETURN(-ENOMEM);
+        
         lock_kernel();
-        OBD_ALLOC(opts, strlen(data) + 1);
-        if (!opts) {
+
+        /* 2.6.9 selinux wants a full option page for do_kern_mount (bug6471) */
+        page = get_zeroed_page(GFP_KERNEL);
+        if (!page) {
                 err = -ENOMEM;
                 goto out_err;
         }
+        opts = (char *)page;
         
         err = smfs_options(data, &devstr, &typestr, opts, &flags);
         if (err)
@@ -412,19 +430,19 @@ int smfs_fill_super(struct super_block *sb, void *data, int silent)
                 goto out_err;
         }
 
-        OBD_FREE(opts, strlen(data) + 1);
-        opts = NULL;
+        free_page(page);
+        page = 0;
         
         duplicate_sb(sb, smb->smsi_sb);
         sb->s_bdev = smb->smsi_sb->s_bdev;
         sm_set_sb_ops(smb->smsi_sb, sb);
 
         /* init the root_inode of smfs. */ 
-        root_ino = S2CSB(sb)->s_root->d_inode->i_ino;
-        root_inode = smfs_get_inode(sb, root_ino, NULL, 0);
+        back_root_inode = S2CSB(sb)->s_root->d_inode;
+        root_inode = smfs_get_inode(sb, back_root_inode, NULL, 0);
 
         CDEBUG(D_SUPER, "readinode %p, root ino %ld, root inode at %p\n",
-               sb->s_op->read_inode, root_ino, root_inode);
+               sb->s_op->read_inode, root_inode->i_ino, root_inode);
 
         sb->s_root = d_alloc_root(root_inode);
         if (!sb->s_root) {
@@ -450,8 +468,8 @@ out_err:
         if (smb->smsi_mnt)
                 smfs_umount_cache(smb);
 
-        if (opts)
-                OBD_FREE(opts, strlen(data) + 1);
+        if (page)
+                free_page(page);
 
         smfs_cleanup_smb(smb);
         unlock_kernel();
@@ -476,60 +494,49 @@ 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) 
+void smfs_pre_hook (struct inode * inode, hook_op op, void * msg) 
 {
         struct smfs_super_info *smb = S2SMI(inode->i_sb);    
         struct smfs_inode_info *smi = I2SMI(inode);
@@ -539,6 +546,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,31 +558,31 @@ 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;
 }
 
-void smfs_post_hook (struct inode * inode, int op, void * msg, int ret)
+void smfs_post_hook (struct inode * inode, hook_op op, void * msg, int ret)
 {
         struct smfs_super_info *smb = S2SMI(inode->i_sb);
-        struct smfs_inode_info *smi = I2SMI(inode);
+        //struct smfs_inode_info *smi = I2SMI(inode);
         struct list_head *hlist = &smb->smsi_plg_list;
         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))
                         continue;
-                //check that inode is allowed
+                /* this will be checked inside plg_post_op()
                 if (!SMFS_IS(smi->smi_flags, plg->plg_type))
                         continue;
-                
+                */
                 if (plg->plg_post_op)
                         plg->plg_post_op(op, inode, msg, ret, plg->plg_private);
         }
-
+        up_read(&smb->plg_sem);
         //EXIT;
 }
 
@@ -588,18 +596,36 @@ 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))
+                if(!SMFS_IS(smb->plg_flags, plg->plg_type) && 
+                   !(op == PLG_START || op == PLG_EXIT))
                         continue;
                
                 if (plg->plg_helper)
                        rc += plg->plg_helper(op, sb, msg, plg->plg_private);
         }
-
+        up_read(&smb->plg_sem);
         //EXIT;
         
         return rc;
 }
 
+void * smfs_get_plg_priv(struct smfs_super_info * smb, int type) 
+{
+        struct list_head *hlist = &smb->smsi_plg_list;
+        struct smfs_plugin *plg, *tmp;
+        
+        list_for_each_entry_safe(plg, tmp, hlist, plg_list) {
+                CERROR("found type %x, needed %x\n", plg->plg_type, type);
+                if (plg->plg_type == type) {
+                        return (plg->plg_private);
+                }
+        }
+        
+        EXIT;
+        
+        return NULL;
+}