X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fsmfs%2Fkml.c;h=9b34171ed37c509320ee4f4b0df1231230f0df6c;hb=1be8815591883160d12672342aef75034f67a6bd;hp=b314eafca8b5aa7724c2d983a3ed0d5f63bd6d7f;hpb=1fbf48379f446689d10bffd91022b5778e6b12ef;p=fs%2Flustre-release.git diff --git a/lustre/smfs/kml.c b/lustre/smfs/kml.c index b314eaf..9b34171 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); \ @@ -105,6 +106,7 @@ exit: RETURN(rc); } +/* not used curently */ static smfs_pack_rec_func smfs_get_rec_pack_type(struct super_block *sb) { int idx = 0; @@ -113,6 +115,7 @@ static smfs_pack_rec_func smfs_get_rec_pack_type(struct super_block *sb) idx = GET_REC_PACK_TYPE_INDEX(smsi->smsi_flags); return smsi->smsi_pack_rec[idx]; } +#endif static inline void copy_inode_attr(struct iattr *iattr, struct inode *inode) @@ -173,7 +176,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) @@ -237,11 +241,9 @@ 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, +/* smfs_path is gotten from intermezzo */ +static char *smfs_path(struct dentry *dentry, struct dentry *root, char *buffer, int buflen) { char * end = buffer + buflen; @@ -348,6 +350,7 @@ static int smfs_remove_all_extents_ea(struct inode *inode) rc = fsfilt->fs_remove_extents_ea(inode, 0, 0xffffffff); RETURN(rc); } + static int smfs_init_extents_ea(struct inode *inode) { struct fsfilt_operations *fsfilt = S2SMI(inode->i_sb)->sm_fsfilt; @@ -358,6 +361,7 @@ static int smfs_init_extents_ea(struct inode *inode) RETURN(rc); } + static int smfs_set_dirty_flags(struct inode *inode, int flags) { struct fsfilt_operations *fsfilt = S2SMI(inode->i_sb)->sm_fsfilt; @@ -421,7 +425,9 @@ static int kml_pack_path (char **buf, struct dentry * dentry) return length; } #endif -static int kml_create(struct inode * inode, void *arg, struct kml_priv * priv) + +static int kml_create(struct inode *inode, void *arg, + struct kml_priv *priv) { struct hook_msg * msg = arg; //return smfs_post_rec_create(inode, msg->dentry, NULL, NULL); @@ -456,12 +462,11 @@ exit: RETURN(rc); } -static int kml_link(struct inode * inode, void *arg, struct kml_priv * priv) +static int kml_link(struct inode *inode, void *arg, struct kml_priv *priv) { - struct hook_link_msg * msg = arg; - int rc = 0, length = 0, buf_len = 0; - char *buffer = NULL, *pbuf = NULL; - struct smfs_super_info *smb; + struct hook_link_msg *msg = arg; + int rc = 0, length = 0; + char *buffer = NULL; ENTRY; OBD_ALLOC(buffer, PAGE_SIZE); @@ -507,12 +512,12 @@ exit: RETURN(rc); } -static int kml_symlink(struct inode * inode, void *arg, struct kml_priv * priv) +static int kml_symlink(struct inode *inode, void *arg, struct kml_priv *priv) { - struct hook_symlink_msg * msg = arg; struct smfs_super_info *smb = S2SMI(inode->i_sb); - char *buffer = NULL, *pbuf; + struct hook_symlink_msg *msg = arg; int rc = 0, length = 0; + char *buffer = NULL; ENTRY; OBD_ALLOC(buffer, PAGE_SIZE); @@ -533,11 +538,11 @@ exit: RETURN(rc); } -static int kml_rename(struct inode * inode, void *arg, struct kml_priv * priv) +static int kml_rename(struct inode *inode, void *arg, struct kml_priv *priv) { - struct hook_rename_msg * msg = arg; - char *buffer = NULL, *pbuf = NULL; - int rc = 0, length = 0, buf_len = 0; + struct hook_rename_msg *msg = arg; + int rc = 0, length = 0; + char *buffer = NULL; ENTRY; OBD_ALLOC(buffer, PAGE_SIZE); @@ -557,11 +562,11 @@ exit: RETURN(rc); } -static int kml_setattr(struct inode * inode, void *arg, struct kml_priv * priv) +static int kml_setattr(struct inode *inode, void *arg, struct kml_priv *priv) { - struct hook_setattr_msg * msg = arg; - char *buffer = NULL, *pbuf; - int rc = 0, length = 0, buf_len = 0; + struct hook_attr_msg *msg = arg; + int rc = 0, length = 0; + char *buffer = NULL; ENTRY; OBD_ALLOC(buffer, PAGE_SIZE); @@ -574,7 +579,7 @@ static int kml_setattr(struct inode * inode, void *arg, struct kml_priv * priv) GOTO(exit, rc); length += rc; - rc = smfs_llog_add_rec(S2SMI(inode->i_sb), (void*)buffer, length); + rc = smfs_llog_add_rec(S2SMI(inode->i_sb), (void *)buffer, length); /* if (!rc) { if (attr && attr->ia_valid & ATTR_SIZE) { @@ -592,6 +597,47 @@ exit: OBD_FREE(buffer, PAGE_SIZE); RETURN(rc); } + +static int kml_setxattr(struct inode *inode, void *arg, struct kml_priv *priv) +{ + struct hook_xattr_msg *msg = arg; + struct kml_buffer kbuf; + int rc = 0, length = 0; + char *buffer = NULL; + ENTRY; + + OBD_ALLOC(buffer, PAGE_SIZE); + if (!buffer) + GOTO(exit, rc = -ENOMEM); + + kbuf.buf = msg->buffer; + kbuf.buf_size = msg->buffer_size; + + rc = priv->pack_fn(REINT_SETXATTR, buffer, NULL, inode, + msg->name, &kbuf); + if (rc <= 0) + GOTO(exit, rc); + + length += rc; + rc = smfs_llog_add_rec(S2SMI(inode->i_sb), (void *)buffer, length); + /* + if (!rc) { + if (attr && attr->ia_valid & ATTR_SIZE) { + smfs_remove_extents_ea(inode, attr->ia_size, + 0xffffffff); + if (attr->ia_size == 0) + smfs_set_dirty_flags(inode, SMFS_OVER_WRITE); + else + smfs_set_dirty_flags(inode, SMFS_DIRTY_WRITE); + } + } + */ +exit: + if (buffer) + OBD_FREE(buffer, PAGE_SIZE); + RETURN(rc); +} + /* static int kml_write(struct inode * inode, void *arg, struct kml_priv * priv) { @@ -660,7 +706,9 @@ exit: } */ -typedef int (*post_kml_op)(struct inode * inode, void *msg, struct kml_priv * priv); +typedef int (*post_kml_op)(struct inode *inode, void *msg, + struct kml_priv *priv); + static post_kml_op smfs_kml_post[HOOK_MAX] = { [HOOK_CREATE] kml_create, [HOOK_LOOKUP] NULL, @@ -674,21 +722,27 @@ static post_kml_op smfs_kml_post[HOOK_MAX] = { [HOOK_SETATTR] kml_setattr, [HOOK_WRITE] NULL, [HOOK_READDIR] NULL, + [HOOK_F_SETXATTR] kml_setxattr, }; -static int smfs_kml_post_op(int code, struct inode * inode, +static int smfs_kml_post_op(hook_op code, struct inode * inode, void * msg, int ret, void * priv) { int rc = 0; ENTRY; - + + //check if inode has flag for KML + if (!SMFS_IS(I2SMI(inode)->smi_flags, SMFS_PLG_KML)) + RETURN(0); + //KML don't handle failed ops if (ret) RETURN(0); - + if (smfs_kml_post[code]) { - CDEBUG(D_INODE,"KML: inode %lu, code: %u\n", inode->i_ino, code); + CDEBUG(D_INODE,"KML: inode %lu, code: %u\n", + inode->i_ino, code); rc = smfs_kml_post[code](inode, msg, priv); } @@ -696,66 +750,61 @@ 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) -{ - ENTRY; - - smfs_deregister_plugin(sb, SMFS_PLG_KML); - OBD_FREE(priv, sizeof(*priv)); - - EXIT; - return 0; -} - static int smfs_trans_kml (struct super_block *sb, void *arg, struct kml_priv * priv) { - int size; - - //TODO: pass fs opcode and see if kml can participate or not - //one record in log per operation - size = 1; + int size = 1; + ENTRY; - return size; -} + /* FIXME-MIKE: pass fs opcode and see if kml can participate or not one + * record in log per operation size = 1 */ -extern int mds_rec_pack(int, char*, struct dentry*, struct inode*, void*, void*); + RETURN(size); +} static int smfs_start_kml(struct super_block *sb, void *arg, - struct kml_priv * kml_p) + struct kml_priv *kml_p) { - int rc = 0; - struct smfs_super_info * smb = S2SMI(sb); + struct smfs_super_info *smb = S2SMI(sb); struct llog_ctxt **ctxt = &smb->smsi_kml_log; struct obd_device *obd = arg; - + int rc = 0; ENTRY; - //is plugin already activated + + /* is plugin already activated */ if (SMFS_IS(smb->plg_flags, SMFS_PLG_KML)) RETURN(0); - + if (obd && obd->obd_type && obd->obd_type->typ_name) { - if (strcmp(obd->obd_type->typ_name, "mds")) - RETURN(0); + if (!strcmp(obd->obd_type->typ_name, OBD_MDS_DEVICENAME)) { + kml_p->pack_fn = mds_rec_pack; + } else if (!strcmp(obd->obd_type->typ_name, OBD_FILTER_DEVICENAME)) { + kml_p->pack_fn = ost_rec_pack; + } else { + CWARN("unexpected device type: %s\n", obd->obd_type->typ_name); + } } - - kml_p->pack_fn = mds_rec_pack; - - //this will do OBD_ALLOC() for ctxt + + LASSERT(kml_p->pack_fn != NULL); + + /* this will do OBD_ALLOC() for ctxt */ rc = llog_catalog_setup(ctxt, KML_LOG_NAME, smb->smsi_exp, smb->smsi_ctxt, smb->sm_fsfilt, - smb->smsi_logs_dir, - smb->smsi_objects_dir); - + smb->smsi_logs_dir, smb->smsi_objects_dir); if (rc) { - CERROR("Failed to initialize kml log list catalog %d\n", rc); + CERROR("failed to initialize kml log list catalog %d\n", rc); RETURN(rc); } - (*ctxt)->llog_proc_cb = smfs_llog_process_rec_cb; + /* 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; + smb->smsi_kml_log->loc_llogs = &obd->obd_llogs; + obd->obd_llogs.llog_ctxt[LLOG_REINT_ORIG_CTXT] = smb->smsi_kml_log; + } SMFS_SET(smb->plg_flags, SMFS_PLG_KML); - RETURN(0); } @@ -764,6 +813,7 @@ int smfs_stop_kml(struct super_block *sb, void *arg, { struct smfs_super_info * smb = S2SMI(sb); struct llog_ctxt *ctxt = smb->smsi_kml_log; + struct obd_device * obd = ctxt->loc_obd; ENTRY; if (!SMFS_IS(smb->plg_flags, SMFS_PLG_KML)) @@ -772,6 +822,7 @@ int smfs_stop_kml(struct super_block *sb, void *arg, SMFS_CLEAR(smb->plg_flags, SMFS_PLG_KML); llog_catalog_cleanup(ctxt); + obd->obd_llogs.llog_ctxt[LLOG_REINT_ORIG_CTXT] = NULL; OBD_FREE(ctxt, sizeof(*ctxt)); RETURN(0); @@ -779,7 +830,6 @@ int smfs_stop_kml(struct super_block *sb, void *arg, typedef int (*kml_helper)(struct super_block * sb, void *msg, struct kml_priv *); static kml_helper smfs_kml_helpers[PLG_HELPER_MAX] = { - [PLG_EXIT] smfs_exit_kml, [PLG_START] smfs_start_kml, [PLG_STOP] smfs_stop_kml, [PLG_TRANS_SIZE] smfs_trans_kml, @@ -797,37 +847,62 @@ static int smfs_kml_help_op(int code, struct super_block * sb, return rc; } +static int smfs_exit_kml(struct super_block *sb, void * arg) +{ + struct smfs_plugin * plg = NULL; + struct kml_priv * priv = arg; + ENTRY; + + 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; +} + 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; + plg->plg_exit = smfs_exit_kml; + 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); }