Whamcloud - gitweb
Commit OST AMD support to HEAD so we can being running with a common code base.
[fs/lustre-release.git] / lustre / llite / llite_lib.c
index 2e5e41f..906e978 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/lustre_ha.h>
 #include <linux/lustre_dlm.h>
 #include <linux/lprocfs_status.h>
+#include <linux/lustre_snap.h>
 #include "llite_internal.h"
 
 kmem_cache_t *ll_file_data_slab;
@@ -98,17 +99,11 @@ int lustre_init_ea_size(struct ll_sb_info *sbi)
         valsize = sizeof(desc);
         rc = obd_get_info(sbi->ll_osc_exp, strlen("lovdesc") + 1, "lovdesc", 
                           &valsize, &desc);
-        if (rc == 0) {
-                obd_init_ea_size(sbi->ll_mdc_exp,
-                                 obd_size_diskmd(sbi->ll_osc_exp, NULL),
-                                 desc.ld_tgt_count*sizeof(struct llog_cookie));
-
-                /* declare ourself as real client. not connection
-                 * from another MDS 
-                 * FIXME: remove fake valsize, mdsize --bzzz */
-                rc = obd_set_info(sbi->ll_mdc_exp, strlen("client"),
-                                  "client", valsize, &desc);
-        }
+        if (rc)
+                RETURN(rc);
+        obd_init_ea_size(sbi->ll_mdc_exp, obd_size_diskmd(sbi->ll_osc_exp, NULL),
+                         desc.ld_tgt_count*sizeof(struct llog_cookie));
+
         RETURN(rc);
 }
 
@@ -139,7 +134,7 @@ int lustre_common_fill_super(struct super_block *sb, char *mdc, char *osc)
                         CERROR("could not register mount in /proc/lustre");
         }
 
-        err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid);
+        err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, 0);
         if (err == -EBUSY) {
                 CERROR("An MDS (mdc %s) is performing recovery, of which this"
                        " client is not a part.  Please wait for recovery to "
@@ -172,7 +167,7 @@ int lustre_common_fill_super(struct super_block *sb, char *mdc, char *osc)
                 GOTO(out_mdc, err);
         }
 
-        err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid);
+        err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, 0);
         if (err == -EBUSY) {
                 CERROR("An OST (osc %s) is performing recovery, of which this"
                        " client is not a part.  Please wait for recovery to "
@@ -241,6 +236,12 @@ int lustre_common_fill_super(struct super_block *sb, char *mdc, char *osc)
 #endif
 
         sb->s_root = d_alloc_root(root);
+
+#ifdef S_PDIROPS
+        CWARN("Enabling PDIROPS\n");
+        sb->s_flags |= S_PDIROPS;
+#endif
+
         RETURN(err);
 
 out_root:
@@ -324,7 +325,8 @@ int ll_set_opt(const char *opt, char *data, int fl)
                 RETURN(fl);
 }
 
-void ll_options(char *options, char **ost, char **mdc, int *flags)
+void ll_options(char *options, char **ost, char **mdc, int *flags, 
+                char **clone_opts)
 {
         char *this_char;
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
@@ -349,12 +351,16 @@ void ll_options(char *options, char **ost, char **mdc, int *flags)
                         continue;
                 if (!*mdc && (*mdc = ll_read_opt("mdc", this_char)))
                         continue;
+                if (!*clone_opts && (*clone_opts = ll_read_opt("clone", 
+                                                                this_char))) 
+                        continue; 
                 if (!(*flags & LL_SBI_NOLCK) &&
                     ((*flags) = (*flags) |
                                 ll_set_opt("nolock", this_char,
                                            LL_SBI_NOLCK)))
                         continue;
         }
+        
         EXIT;
 }
 
@@ -365,6 +371,7 @@ void ll_lli_init(struct ll_inode_info *lli)
         lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
         spin_lock_init(&lli->lli_lock);
         INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
+        lli->lli_inode_magic = LLI_INODE_MAGIC;
 }
 
 int ll_fill_super(struct super_block *sb, void *data, int silent)
@@ -372,6 +379,7 @@ int ll_fill_super(struct super_block *sb, void *data, int silent)
         struct ll_sb_info *sbi;
         char *osc = NULL;
         char *mdc = NULL;
+        char *clone_opts = NULL;
         int err;
         ENTRY;
 
@@ -382,7 +390,7 @@ int ll_fill_super(struct super_block *sb, void *data, int silent)
                 RETURN(-ENOMEM);
 
         sbi->ll_flags |= LL_SBI_READAHEAD;
-        ll_options(data, &osc, &mdc, &sbi->ll_flags);
+        ll_options(data, &osc, &mdc, &sbi->ll_flags, &clone_opts);
 
         if (!osc) {
                 CERROR("no osc\n");
@@ -403,12 +411,14 @@ out:
                 OBD_FREE(mdc, strlen(mdc) + 1);
         if (osc)
                 OBD_FREE(osc, strlen(osc) + 1);
+        if (clone_opts)
+                OBD_FREE(clone_opts, strlen(clone_opts) + 1);
 
         RETURN(err);
 } /* ll_read_super */
 
-int lustre_process_log(struct lustre_mount_data *lmd, char * profile,
-                       struct config_llog_instance *cfg, int allow_recov)
+static int lustre_process_log(struct lustre_mount_data *lmd, char *profile,
+                              struct config_llog_instance *cfg, int allow_recov)
 {
         struct lustre_cfg lcfg;
         struct portals_cfg pcfg;
@@ -490,7 +500,7 @@ int lustre_process_log(struct lustre_mount_data *lmd, char * profile,
         if (err)
                 GOTO(out_cleanup, err);
 
-        err = obd_connect(&mdc_conn, obd, &mdc_uuid);
+        err = obd_connect(&mdc_conn, obd, &mdc_uuid, 0);
         if (err) {
                 CERROR("cannot connect to %s: rc = %d\n", lmd->lmd_mds, err);
                 GOTO(out_cleanup, err);
@@ -498,18 +508,10 @@ int lustre_process_log(struct lustre_mount_data *lmd, char * profile,
 
         exp = class_conn2export(&mdc_conn);
 
-        ctxt = llog_get_context(&exp->exp_obd->obd_llogs, LLOG_CONFIG_REPL_CTXT);
-#if 1
-        rc = class_config_parse_llog(ctxt, profile, cfg);
-#else
-        /*
-         * For debugging, it's useful to just dump the log
-         */
-        rc = class_config_dump_llog(ctxt, profile, cfg);
-#endif
-        if (rc) {
-                CERROR("class_config_parse_llog failed: rc = %d\n", rc);
-        }
+        ctxt = llog_get_context(&exp->exp_obd->obd_llogs,LLOG_CONFIG_REPL_CTXT);
+        rc = class_config_process_llog(ctxt, profile, cfg);
+        if (rc)
+                CERROR("class_config_process_llog failed: rc = %d\n", rc);
 
         err = obd_disconnect(exp, 0);
 
@@ -597,7 +599,6 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
                 err = lustre_process_log(lmd, lmd->lmd_profile, &cfg, 0);
                 if (err < 0) {
                         CERROR("Unable to process log: %s\n", lmd->lmd_profile);
-
                         GOTO(out_free, err);
                 }
 
@@ -633,7 +634,7 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
 
         if (err)
                 GOTO(out_free, err);
-
+        
 out_dev:
         if (mdc)
                 OBD_FREE(mdc, strlen(mdc) + 1);
@@ -648,6 +649,7 @@ out_free:
                 int err;
 
                 if (sbi->ll_instance != NULL) {
+                        struct lustre_mount_data *lmd = sbi->ll_lmd;
                         char * cln_prof;
                         struct config_llog_instance cfg;
 
@@ -655,10 +657,9 @@ out_free:
                         cfg.cfg_uuid = sbi->ll_sb_uuid;
 
                         OBD_ALLOC(cln_prof, len);
-                        sprintf(cln_prof, "%s-clean", sbi->ll_lmd->lmd_profile);
+                        sprintf(cln_prof, "%s-clean", lmd->lmd_profile);
 
-                        err = lustre_process_log(sbi->ll_lmd, cln_prof, &cfg,
-                                                 0);
+                        err = lustre_process_log(lmd, cln_prof, &cfg, 0);
                         if (err < 0)
                                 CERROR("Unable to process log: %s\n", cln_prof);
                         OBD_FREE(cln_prof, len);
@@ -714,7 +715,6 @@ void lustre_put_super(struct super_block *sb)
         obd = NULL;
 
         lustre_common_put_super(sb);
-
         if (sbi->ll_lmd != NULL) {
                 char * cln_prof;
                 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
@@ -751,26 +751,101 @@ void lustre_put_super(struct super_block *sb)
         EXIT;
 } /* lustre_put_super */
 
+int ll_process_config_update(struct ll_sb_info *sbi, int clean)
+{
+        struct obd_export *mdc_exp = sbi->ll_mdc_exp;
+        struct lustre_mount_data *lmd = sbi->ll_lmd;
+        struct llog_ctxt *ctxt;
+        struct config_llog_instance cfg;
+        char *profile = lmd->lmd_profile, *name = NULL;
+        int rc, namelen =  0, version;
+        ENTRY;
+
+        if (profile == NULL)
+                RETURN(0);
+        if (lmd == NULL) {
+                CERROR("Client not mounted with zero-conf; cannot process "
+                       "update log.\n");
+                RETURN(0);
+        }
+
+        rc = ldlm_cli_cancel_unused(mdc_exp->exp_obd->obd_namespace, NULL,
+                                    LDLM_FL_CONFIG_CHANGE, NULL);
+        if (rc != 0)
+                CWARN("ldlm_cli_cancel_unused(mdc): %d\n", rc);
+
+        rc = obd_cancel_unused(sbi->ll_osc_exp, NULL, LDLM_FL_CONFIG_CHANGE,
+                               NULL);
+        if (rc != 0)
+                CWARN("obd_cancel_unused(lov): %d\n", rc);
+
+        cfg.cfg_instance = sbi->ll_instance;
+        cfg.cfg_uuid = sbi->ll_sb_uuid;
+        cfg.cfg_local_nid = lmd->lmd_local_nid;
+
+        namelen = strlen(profile) + 20; /* -clean-######### */
+        OBD_ALLOC(name, namelen);
+        if (name == NULL)
+                RETURN(-ENOMEM);
+
+        if (clean) {
+                version = sbi->ll_config_version - 1;
+                sprintf(name, "%s-clean-%d", profile, version);
+        } else {
+                version = sbi->ll_config_version + 1;
+                sprintf(name, "%s-%d", profile, version);
+        }
+
+        CWARN("Applying configuration log %s\n", name);
+
+        ctxt = llog_get_context(&mdc_exp->exp_obd->obd_llogs,
+                                LLOG_CONFIG_REPL_CTXT);
+        rc = class_config_process_llog(ctxt, name, &cfg);
+        if (rc == 0)
+                sbi->ll_config_version = version;
+        CWARN("Finished applying configuration log %s: %d\n", name, rc);
+
+        if (rc == 0 && clean == 0) {
+                struct lov_desc desc;
+                int rc, valsize;
+                valsize = sizeof(desc);
+                rc = obd_get_info(sbi->ll_osc_exp, strlen("lovdesc") + 1,
+                                  "lovdesc", &valsize, &desc);
+
+                rc = obd_init_ea_size(mdc_exp,
+                                      obd_size_diskmd(sbi->ll_osc_exp, NULL),
+                                      (desc.ld_tgt_count *
+                                       sizeof(struct llog_cookie)));
+        }
+        OBD_FREE(name, namelen);
+        RETURN(rc);
+}
 
 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
 {
-        struct inode *inode;
+        struct inode *inode = NULL;
         l_lock(&lock->l_resource->lr_namespace->ns_lock);
-        if (lock->l_ast_data)
-                inode = igrab(lock->l_ast_data);
-        else
-                inode = NULL;
+        if (lock->l_ast_data) {
+                struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
+                if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
+                        inode = igrab(lock->l_ast_data);
+                } else {
+                        CERROR("DEBUG: l_ast_data %p is bogus: magic %x\n",
+                               lock->l_ast_data, lli->lli_inode_magic);
+                }
+        }
         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
         return inode;
 }
 
 int null_if_equal(struct ldlm_lock *lock, void *data)
 {
-        if (data == lock->l_ast_data)
+        if (data == lock->l_ast_data) {
                 lock->l_ast_data = NULL;
 
-        if (lock->l_req_mode != lock->l_granted_mode)
-                return LDLM_ITER_STOP;
+                if (lock->l_req_mode != lock->l_granted_mode)
+                        LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
+        }
 
         return LDLM_ITER_CONTINUE;
 }
@@ -785,6 +860,7 @@ void ll_clear_inode(struct inode *inode)
         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
                inode->i_generation, inode);
 
+        lli->lli_inode_magic = LLI_INODE_DEAD;
         ll_inode2fid(&fid, inode);
         clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(ll_i2info(inode)->lli_flags));
         md_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
@@ -1076,14 +1152,6 @@ int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
         return 0;
 }
 
-void dump_lsm(int level, struct lov_stripe_md *lsm)
-{
-        CDEBUG(level, "objid "LPX64", maxbytes "LPX64", magic 0x%08X, "
-               "stripe_size %u, stripe_count %u\n",
-               lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
-               lsm->lsm_stripe_size, lsm->lsm_stripe_count);
-}
-
 void ll_update_inode(struct inode *inode, struct lustre_md *md)
 {
         struct ll_inode_info *lli = ll_i2info(inode);
@@ -1102,6 +1170,7 @@ void ll_update_inode(struct inode *inode, struct lustre_md *md)
                         if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
                                 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
                 } else {
+                        int i;
                         if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
                                 CERROR("lsm mismatch for inode %ld\n",
                                        inode->i_ino);
@@ -1111,6 +1180,18 @@ void ll_update_inode(struct inode *inode, struct lustre_md *md)
                                 dump_lsm(D_ERROR, lsm);
                                 LBUG();
                         }
+                        /* XXX FIXME -- We should decide on a safer (atomic) and
+                         * more elegant way to update the lsm */
+                        for (i = 0; i < lsm->lsm_stripe_count; i++) {
+                                lli->lli_smd->lsm_oinfo[i].loi_id =
+                                        lsm->lsm_oinfo[i].loi_id;
+                                lli->lli_smd->lsm_oinfo[i].loi_gr =
+                                        lsm->lsm_oinfo[i].loi_gr;
+                                lli->lli_smd->lsm_oinfo[i].loi_ost_idx =
+                                        lsm->lsm_oinfo[i].loi_ost_idx;
+                                lli->lli_smd->lsm_oinfo[i].loi_ost_gen =
+                                        lsm->lsm_oinfo[i].loi_ost_gen;
+                        }
                 }
                 /* bug 2844 - limit i_blksize for broken user-space apps */
                 LASSERTF(lsm->lsm_xfersize != 0, "%lu\n", lsm->lsm_xfersize);
@@ -1261,6 +1342,25 @@ void ll_read_inode2(struct inode *inode, void *opaque)
         }
 }
 
+void ll_delete_inode(struct inode *inode)
+{
+        int rc;
+        struct ll_fid fid;
+        struct ll_sb_info *sbi = ll_i2sbi(inode);
+        ENTRY;
+        
+        ll_inode2fid(&fid, inode);
+
+        rc = md_delete_object(sbi->ll_mdc_exp, &fid);
+        if (rc) {
+                CERROR("md_delete_object() failed, error %d.\n",
+                       rc);
+        }
+
+        clear_inode(inode);
+        EXIT;
+}
+
 int ll_iocontrol(struct inode *inode, struct file *file,
                  unsigned int cmd, unsigned long arg)
 {