Whamcloud - gitweb
Branch b1_4_mountconf
authornathan <nathan>
Thu, 9 Feb 2006 00:05:48 +0000 (00:05 +0000)
committernathan <nathan>
Thu, 9 Feb 2006 00:05:48 +0000 (00:05 +0000)
b=8007
- put a sem around log writing
- get a mgc ref during process log
- try harder to reactivate a failed-connect mgs import
- be smarter about when we try to copy the mgs logs locally
- make servers always register at startup, so mgs can do some sanity checking
- groundwork for "writeconf"-like regenerate logs

13 files changed:
lustre/include/linux/lustre_disk.h
lustre/include/linux/lustre_idl.h
lustre/include/linux/lustre_mgs.h
lustre/include/linux/obd.h
lustre/lov/lov_obd.c
lustre/mgc/mgc_request.c
lustre/mgs/mgs_handler.c
lustre/mgs/mgs_internal.h
lustre/mgs/mgs_llog.c
lustre/obdclass/obd_mount.c
lustre/utils/Makefile.am
lustre/utils/mkfs_lustre.c
lustre/utils/mount_lustre.c

index 3483b92..8b6f58d 100644 (file)
 #define LDD_F_SV_TYPE_MDT   0x0001
 #define LDD_F_SV_TYPE_OST   0x0002
 #define LDD_F_SV_TYPE_MGS   0x0004
-#define LDD_F_NEED_INDEX    0x0010
-#define LDD_F_NEED_REGISTER 0x0020
+#define LDD_F_NEED_INDEX    0x0010 /* we need an index assignment */
+#define LDD_F_NEED_REGISTER 0x0020 /* we have never registered  */
 #define LDD_F_UPGRADE14     0x0040 /* COMPAT_14 */
+#define LDD_F_REWRITE       0x0080 /* rewrite the LDD */
+#define LDD_F_WRITECONF     0x0100 /* regenerate all logs for this fs */
 
 
 enum ldd_mount_type {
index 26215f0..1d0c738 100644 (file)
@@ -983,7 +983,7 @@ typedef enum {
         MGS_CONNECT = 250,
         MGS_DISCONNECT,
         MGS_EXCEPTION,         /* node died, etc. */
-        MGS_TARGET_ADD,
+        MGS_TARGET_ADD,        /* whenever target starts up */
         MGS_TARGET_DEL,
         MGS_LAST_OPC
 } mgs_cmd_t;
index 061a0d5..eac0b6c 100644 (file)
@@ -22,6 +22,8 @@
 #include <linux/lustre_log.h>
 #include <linux/lustre_export.h>
 
+#define FSDB_EMPTY 0x0001
+
 struct fs_db {
         char              fd_name[8];
         struct list_head  fd_list;
index 66bf44c..a022671 100644 (file)
@@ -387,9 +387,9 @@ struct mgs_obd {
         struct super_block              *mgs_sb;
         struct dentry                   *mgs_configs_dir;
         struct dentry                   *mgs_fid_de;
-        struct llog_handle              *mgs_cfg_llh;
         spinlock_t                       mgs_fs_db_lock;
         struct list_head                 mgs_fs_db_list;
+        struct semaphore                 mgs_log_sem;
 };
 
 struct mds_obd {
index 443b59e..5a6dfe9 100644 (file)
@@ -912,8 +912,7 @@ static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
                 if (ost_uuid && !obd_uuid_equals(ost_uuid, &lov->tgts[i].uuid))
                         continue;
 
-                // FIXME remove
-                CERROR("Clear orphans for %d:%s\n", i, ost_uuid->uuid);
+                CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i, ost_uuid->uuid);
 
                 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
 
index 471cec8..b9f3ab4 100644 (file)
@@ -343,9 +343,8 @@ static int mgc_process_log(struct obd_device *mgc,
                            struct config_llog_data *cld);
 
 /* FIXME I don't want a thread for every cld; make a list of cld's to requeue
-   and use only 1 thread. And take an obd ref to the mgc so thread stops before
-   mgc (the current one is unsafe). */
-/* reenqueue and parse _all_ logs that match the lock */
+   and use only 1 thread. */
+/* reenqueue the lock, reparse the log */
 static int mgc_async_requeue(void *data)
 {
         struct config_llog_data *cld = (struct config_llog_data *)data;
@@ -366,7 +365,11 @@ static int mgc_async_requeue(void *data)
         CDEBUG(D_MGC, "requeue "LPX64" %s:%s\n", 
                cld->cld_resid.name[0], cld->cld_logname, 
                cld->cld_cfg.cfg_instance);
+        
+        LASSERT(the_mgc);
+        class_export_get(the_mgc->obd_self_export);
         rc = mgc_process_log(the_mgc, cld);
+        class_export_put(the_mgc->obd_self_export);
         
         RETURN(rc);
 }
@@ -648,9 +651,14 @@ int mgc_set_info(struct obd_export *exp, obd_count keylen,
                        exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
                 if (imp->imp_invalid) {
                         /* Resurrect if we previously died */
-                        CDEBUG(D_MGC, "Reactivate %s\n", 
-                               imp->imp_obd->obd_name);
+                        CDEBUG(D_MGC, "Reactivate %s %d:%d:%d\n", 
+                               imp->imp_obd->obd_name,
+                               imp->imp_deactive, imp->imp_invalid, 
+                               imp->imp_state);
                         ptlrpc_activate_import(imp);
+                        // lustre_reconnect_mgc(obd);
+                        ptlrpc_set_import_active(imp, 1);
+                        //ptlrpc_recover_import(imp);
                 }
                 RETURN(0);
         }
@@ -751,6 +759,26 @@ static int mgc_llog_finish(struct obd_device *obd, int count)
         RETURN(rc);
 }
 
+/* identical to mgs_log_is_empty */
+static int mgc_llog_is_empty(struct obd_device *obd, struct llog_ctxt *ctxt,
+                            char *name)
+{
+        struct lvfs_run_ctxt saved;
+        struct llog_handle *llh;
+        int rc = 0;
+
+        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+        rc = llog_create(ctxt, &llh, NULL, name);
+        if (rc == 0) {
+                llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
+                rc = llog_get_size(llh);
+                llog_close(llh);
+        }
+        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+        /* header is record 1 */
+        return(rc <= 1);
+}
+
 static int mgc_copy_handler(struct llog_handle *llh, struct llog_rec_hdr *rec, 
                             void *data)
 {
@@ -865,12 +893,19 @@ static int mgc_process_log(struct obd_device *mgc,
             (class_name2obd(LUSTRE_MGS_OBDNAME) == NULL)) {
                 push_ctxt(&saved, &mgc->obd_lvfs_ctxt, NULL);
                 must_pop++;
-                if (!rcl
-                        /* Only try to copy log if we have the lock */
+                if (rcl == 0
+                        /* Only try to copy log if we have the lock. */
                         rc = mgc_copy_llog(mgc, ctxt, lctxt, cld->cld_logname);
-                if (rcl || rc) 
-                        LCONSOLE_WARN("Failed to get MGS log %s, using local "
-                                      "copy.\n", cld->cld_logname);
+                if (rcl || rc) {
+                        if (mgc_llog_is_empty(mgc, lctxt, cld->cld_logname)) {
+                                LCONSOLE_ERROR("Failed to get MGS log %s "
+                                               "and no local copy.\n",
+                                               cld->cld_logname);
+                                GOTO(out_pop, rc = -ENOTCONN);
+                        }
+                        LCONSOLE_WARN("Failed to get MGS log %s, using "
+                                      "local copy.\n", cld->cld_logname);
+                }
                 /* Now, whether we copied or not, start using the local llog.
                    If we failed to copy, we'll start using whatever the old 
                    log has. */
@@ -882,6 +917,7 @@ static int mgc_process_log(struct obd_device *mgc,
            be updated here. */
         rc = class_config_parse_llog(ctxt, cld->cld_logname, &cld->cld_cfg);
         
+ out_pop:
         if (must_pop) 
                 pop_ctxt(&saved, &mgc->obd_lvfs_ctxt, NULL);
 
@@ -894,9 +930,9 @@ static int mgc_process_log(struct obd_device *mgc,
         }
         
         if (rc) {
-                LCONSOLE_ERROR("%s: the configuration '%s' could not be read "
-                               "(%d) from the MGS.\n",
-                               mgc->obd_name, cld->cld_logname, rc);
+                CERROR("%s: the configuration '%s' could not be read "
+                       "(%d) from the MGS.\n",
+                       mgc->obd_name, cld->cld_logname, rc);
         }
         
         RETURN(rc);
index b36ec4f..f1087cf 100644 (file)
@@ -171,6 +171,7 @@ static int mgs_setup(struct obd_device *obd, obd_count len, void *buf)
 
         /* Internal mgs setup */
         mgs_init_db_list(obd);
+        sema_init(&mgs->mgs_log_sem, 1);
 
         /* Start the service threads */
         mgs->mgs_service =
@@ -294,18 +295,61 @@ static int mgs_put_cfg_lock(struct lustre_handle *lockh)
         return 0;
 }
 
+/* rc=0 means ok */
+static int mgs_check_target(struct obd_device *obd, struct mgs_target_info *mti)
+{
+        int rc;
+        ENTRY;
+
+        rc = mgs_check_index(obd, mti);
+        if (rc == 0) {
+                LCONSOLE_ERROR("Index for %s has disappeared!  "
+                               "Regenerating this portion of the logs."
+                               "\n", mti->mti_svname);
+                mti->mti_flags |= LDD_F_NEED_REGISTER;
+                rc = 1;
+        } else if (rc == -1) {
+                LCONSOLE_ERROR("Client log %s-client has disappeared! "
+                               "Regenerating all logs.\n",
+                               mti->mti_fsname);
+                mti->mti_flags |= LDD_F_WRITECONF;
+                rc = 1;
+        } else {
+                 /* index is correctly marked used */
+                rc = 0;  
+        }
+
+        /* FIXME If the logs don't contain the mti_nids then add 
+           them all as failover nids */       
+
+        RETURN(rc);
+}
+
+/* Called whenever a target starts up.  Flags indicate first connect, etc. */
 static int mgs_handle_target_add(struct ptlrpc_request *req)
 {    
         struct obd_device *obd = req->rq_export->exp_obd;
         struct lustre_handle lockh;
         struct mgs_target_info *mti, *rep_mti;
         int rep_size = sizeof(*mti);
-        int rc, lockrc;
+        int rc = 0, lockrc;
         ENTRY;
 
         mti = lustre_swab_reqbuf(req, 0, sizeof(*mti),
                                  lustre_swab_mgs_target_info);
         
+        if (!(mti->mti_flags & (LDD_F_WRITECONF | LDD_F_UPGRADE14 |
+                                LDD_F_NEED_REGISTER))) {
+                /* We're just here as a startup ping. */
+                CDEBUG(D_MGS, "Server %s has started on %s\n", mti->mti_svname,
+                       obd_export_nid2str(req->rq_export));
+                rc = mgs_check_target(obd, mti);
+                /* above will set appropriate mti flags */
+                if (!rc) 
+                        /* Nothing wrong, don't revoke lock */
+                        GOTO(out_nolock, rc);
+        }
+
         /* revoke the config lock so everyone will update */
         lockrc = mgs_get_cfg_lock(obd, mti->mti_fsname, &lockh);
         if (lockrc != ELDLM_OK) {
@@ -316,6 +360,23 @@ static int mgs_handle_target_add(struct ptlrpc_request *req)
                                lockrc);
         }
 
+        /* There can be only 1 server adding at a time - don't want log
+           writing contention. */
+        down(&obd->u.mgs.mgs_log_sem);
+
+        if (mti->mti_flags & LDD_F_WRITECONF) {
+                CERROR("regen all logs for fs %s\n", mti->mti_fsname);
+                rc = mgs_erase_logs(obd, mti->mti_fsname);
+                mti->mti_flags |= LDD_F_NEED_REGISTER;
+                /* FIXME regen the rest of the logs too.  Special lock revoke
+                flag? */
+                LCONSOLE_ERROR("All servers must be restarted in order to "
+                               "regenerate the configuration logs.\n");
+
+                mti->mti_flags &= ~LDD_F_WRITECONF;
+                mti->mti_flags |= LDD_F_REWRITE;
+        }
+
         /* COMPAT_146 */
         if (mti->mti_flags & LDD_F_UPGRADE14) {
                 CDEBUG(D_MGS, "upgrading fs %s from pre-1.6\n", 
@@ -328,8 +389,9 @@ static int mgs_handle_target_add(struct ptlrpc_request *req)
                         CERROR("Can't upgrade from 1.4 (%d)\n", rc);
                         GOTO(out, rc);
                 }
-
+                
                 mti->mti_flags &= ~LDD_F_UPGRADE14;
+                mti->mti_flags |= LDD_F_REWRITE;
         }
         /* end COMPAT_146 */
 
@@ -346,14 +408,16 @@ static int mgs_handle_target_add(struct ptlrpc_request *req)
                         GOTO(out, rc);
                 }
 
-                mti->mti_flags &= ~LDD_F_NEED_REGISTER;
+                mti->mti_flags &= ~(LDD_F_NEED_REGISTER | LDD_F_NEED_INDEX);
+                mti->mti_flags |= LDD_F_REWRITE;
         }
 
 out:
+        up(&obd->u.mgs.mgs_log_sem);
         /* done with log update */
         if (lockrc == ELDLM_OK)
                 mgs_put_cfg_lock(&lockh);
-
+out_nolock:
         CDEBUG(D_MGS, "replying with %s, index=%d, rc=%d\n", mti->mti_svname, 
                mti->mti_stripe_index, rc);
         lustre_pack_reply(req, 1, &rep_size, NULL); 
index ac5a890..2d2ae3c 100644 (file)
@@ -14,8 +14,11 @@ extern struct lvfs_callback_ops mgs_lvfs_ops;
 
 int mgs_init_db_list(struct obd_device *obd);
 int mgs_cleanup_db_list(struct obd_device *obd);
+int mgs_check_index(struct obd_device *obd, struct mgs_target_info *mti);
 int mgs_set_index(struct obd_device *obd, struct mgs_target_info *mti);
 int mgs_write_log_target(struct obd_device *obd, struct mgs_target_info *mti);
 int mgs_upgrade_sv_14(struct obd_device *obd, struct mgs_target_info *mti);
+int mgs_erase_logs(struct obd_device *obd, char *fsname);
+
 
 #endif
index a7359d7..c1929e0 100644 (file)
@@ -151,6 +151,9 @@ static int mgs_get_db_from_llog(struct obd_device *obd, char *logname,
         if (rc)
                 GOTO(out_close, rc);
 
+        if (llog_get_size(loghandle) <= 1)
+                db->fd_flags |= FSDB_EMPTY;
+
         rc = llog_process(loghandle, mgsdb_handler, (void *)db, NULL);
         CDEBUG(D_MGS, "get_db = %d\n", rc);
 out_close:
@@ -316,6 +319,40 @@ static int mgs_find_or_make_db(struct obd_device *obd, char *name,
         return 0;
 }
 
+/* 1 = index in use
+   0 = index unused 
+   -1= empty client log */
+int mgs_check_index(struct obd_device *obd, struct mgs_target_info *mti)
+{
+        struct fs_db *db;
+        void *imap;
+        int rc = 0;
+        ENTRY;
+
+        LASSERT(!(mti->mti_flags & LDD_F_NEED_INDEX));
+
+        rc = mgs_find_or_make_db(obd, mti->mti_fsname, &db); 
+        if (rc) {
+                CERROR("Can't get db for %s\n", mti->mti_fsname);
+                RETURN(rc);
+        }
+
+        if (db->fd_flags & FSDB_EMPTY) 
+                RETURN(-1);
+
+        if (mti->mti_flags & LDD_F_SV_TYPE_OST) 
+                imap = db->fd_ost_index_map;
+        else if (mti->mti_flags & LDD_F_SV_TYPE_MDT) 
+                imap = db->fd_mdt_index_map;
+        else
+                RETURN(-EINVAL);
+
+        if (test_bit(mti->mti_stripe_index, imap)) 
+                RETURN(1);
+        RETURN(0);
+}
+
+
 int mgs_set_index(struct obd_device *obd, struct mgs_target_info *mti)
 {
         struct fs_db *db;
@@ -944,6 +981,10 @@ int mgs_write_log_target(struct obd_device *obd,
                 CERROR("Unknown target type %#x, can't create log for %s\n",
                        mti->mti_flags, mti->mti_svname);
         }
+        
+        if (!rc) 
+                db->fd_flags &= ~FSDB_EMPTY;
+
         return rc;
 }
 
@@ -1088,6 +1129,92 @@ int mgs_upgrade_sv_14(struct obd_device *obd, struct mgs_target_info *mti)
 }
 /* end COMPAT_146 */
 
+static int mgs_clear_log(struct obd_device *obd, char *name)
+{
+        struct lvfs_run_ctxt saved;
+        struct llog_handle *llh;
+        int rc = 0;
+
+        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+        rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
+                         &llh, NULL, name);
+        if (rc == 0) {
+                llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
+                rc = llog_destroy(llh);
+                llog_free_handle(llh);
+        }
+        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+
+        if (rc)
+                CERROR("failed to clear log %s: %d\n", name, rc);
+
+        return(rc);
+}
+
+static int dentry_readdir(struct obd_device *obd, struct dentry *dir,
+                          struct vfsmount *inmnt, 
+                          struct list_head *dentry_list){
+        /* see mds_cleanup_pending */
+        struct lvfs_run_ctxt saved;
+        struct file *file;
+        struct dentry *dentry;
+        struct vfsmount *mnt;
+        int rc = 0;
+        ENTRY;
+                                                                                
+        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+        dentry = dget(dir);
+        if (IS_ERR(dentry))
+                GOTO(out_pop, rc = PTR_ERR(dentry));
+        mnt = mntget(inmnt);
+        if (IS_ERR(mnt)) {
+                l_dput(dentry);
+                GOTO(out_pop, rc = PTR_ERR(mnt));
+        }
+
+        file = dentry_open(dentry, mnt, O_RDONLY);
+        if (IS_ERR(file))
+                /* dentry_open_it() drops the dentry, mnt refs */
+                GOTO(out_pop, rc = PTR_ERR(file));
+                                                                                
+        INIT_LIST_HEAD(dentry_list);
+        rc = l_readdir(file, dentry_list);
+        filp_close(file, 0);
+        /*  filp_close->fput() drops the dentry, mnt refs */
+                                                                                
+out_pop:
+        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+        RETURN(rc);
+}
+
+/* erase all logs for the given fs */
+int mgs_erase_logs(struct obd_device *obd, char *fsname)
+{
+        struct mgs_obd *mgs = &obd->u.mgs;
+        struct list_head dentry_list;
+        struct l_linux_dirent *dirent, *n;
+        int rc, len = strlen(fsname);
+        ENTRY;
+
+        /* Find all the logs in the CONFIGS directory */
+        rc = dentry_readdir(obd, mgs->mgs_configs_dir,
+                             mgs->mgs_vfsmnt, &dentry_list);
+        if (rc) {
+                CERROR("Can't read %s dir\n", MOUNT_CONFIGS_DIR);
+                RETURN(rc);
+        }
+                                                                                
+        list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
+                list_del(&dirent->lld_list);
+                if (strncmp(fsname, dirent->lld_name, len) == 0) {
+                        CDEBUG(D_MGS, "Removing log %s\n", dirent->lld_name);
+                        mgs_clear_log(obd, dirent->lld_name);
+                }
+                OBD_FREE(dirent, sizeof(*dirent));
+        }
+        RETURN(rc);
+}
+
 
 #if 0
 /******************** unused *********************/
@@ -1148,28 +1275,6 @@ out:
         return rc;
 }
 
-static int mgs_clear_log(struct obd_device *obd, char *name)
-{
-        struct lvfs_run_ctxt saved;
-        struct llog_handle *llh;
-        int rc = 0;
-
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
-                         &llh, NULL, name);
-        if (rc == 0) {
-                llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
-                rc = llog_destroy(llh);
-                llog_free_handle(llh);
-        }
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-
-        if (rc)
-                CERROR("failed to clear log %s: %d\n", name, rc);
-
-        return(rc);
-}
-
 /* from mdt_iocontrol */
 int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                   void *karg, void *uarg)
index cda8aa4..329a7e5 100644 (file)
@@ -32,7 +32,6 @@
 #include <linux/obd.h>
 #include <linux/lvfs.h>
 #include <linux/lustre_fsfilt.h>
-//#include <linux/lustre_mgs.h>
 #include <linux/obd_class.h>
 #include <lustre/lustre_user.h>
 #include <linux/version.h> 
@@ -369,54 +368,6 @@ out:
         RETURN(rc);
 }
 
-#if 0
-int parse_last_rcvd(struct obd_device *obd, char *uuid, int *first_mount)
-{
-        struct lvfs_run_ctxt saved;
-        struct file *file;
-        struct lr_server_data *lsd;
-        loff_t off = 0;
-        int rc;
-        OBD_ALLOC_WAIT(lsd, sizeof(*lsd));
-        if (!lsd)
-                return -ENOMEM;
-        /* requires a mounted device */
-        LASSERT(obd);
-         /*setup llog ctxt*/
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-
-        /* open and test the last rcvd file */
-        file = filp_open(LAST_RCVD, O_RDONLY, 0644);
-        if (IS_ERR(file)) {
-                rc = PTR_ERR(file);
-                CERROR("cannot open %s file: rc = %d\n", LAST_RCVD, rc);
-                goto out;
-        }
-        CDEBUG(D_MOUNT, "Have last_rcvd, size %lu\n",
-               (unsigned long)file->f_dentry->d_inode->i_size);
-        rc = fsfilt_read_record(obd, file, lsd, sizeof(*lsd), &off);
-        if (rc) {
-                CERROR("error reading %s: rc %d\n", LAST_RCVD, rc);
-                goto out_close;
-        }
-        strcpy(uuid, lsd->lsd_uuid);
-        *first_mount = (lsd->lsd_mount_count == 0);
-        CDEBUG(D_MOUNT, "UUID from %s: %s, init=%d\n",
-               LAST_RCVD, uuid, *first_mount);
-out_close:
-        filp_close(file, 0);
-out:
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        OBD_FREE(lsd, sizeof(*lsd));
-        return(rc);
-}
-#endif
-
 
 /**************** config llog ********************/
 
@@ -618,6 +569,20 @@ static int lustre_start_mgc(struct super_block *sb)
                                   KEY_INIT_RECOV_BACKUP,
                                   sizeof(recov_bk), &recov_bk);
 
+#if 0
+                /* induces a module loop with ptlrpc */
+                if (imp->imp_invalid) {
+                        /* Resurrect if we previously died */
+                        CDEBUG(D_MOUNT, "Reactivate %s %d:%d:%d\n", 
+                               imp->imp_obd->obd_name,
+                               imp->imp_deactive, imp->imp_invalid, 
+                               imp->imp_state);
+                        ptlrpc_activate_import(imp);
+                        // lustre_reconnect_mgc(obd);
+                        ptlrpc_set_import_active(imp, 1);
+                        //ptlrpc_recover_import(imp);
+                }
+#endif
                 GOTO(out, rc = 0);
         }
 
@@ -825,8 +790,9 @@ static int server_stop_servers(struct super_block *sb)
         RETURN(rc);
 }
 
-/* Add this target to the fs, get a new index if needed */
-static int server_add_target(struct super_block *sb, struct vfsmount *mnt)
+/* Register an old or new target with the MGS. If needed MGS will construct
+   startup logs and assign index */
+static int server_register_target(struct super_block *sb, struct vfsmount *mnt)
 {       
         struct lustre_sb_info *lsi = s2lsi(sb);
         struct obd_device *mgc = lsi->lsi_mgc;
@@ -839,9 +805,6 @@ static int server_add_target(struct super_block *sb, struct vfsmount *mnt)
 
         LASSERT(mgc);
 
-        /* send MGS_TARGET_ADD rpc via MGC, MGS should reply with an 
-           index number. */
-        
         OBD_ALLOC(mti, sizeof(*mti));
         if (!mti) {
                 RETURN(-ENOMEM);
@@ -874,24 +837,25 @@ static int server_add_target(struct super_block *sb, struct vfsmount *mnt)
         mti->mti_stripe_size = ldd->ldd_stripe_sz; 
         mti->mti_stripe_offset = ldd->ldd_stripe_offset;  
 
-        CDEBUG(D_MOUNT, "Initial registration %s, fs=%s, %s, index=%04x\n",
+        CDEBUG(D_MOUNT, "%sregistration %s, fs=%s, %s, index=%04x, flags=%#x\n",
+               mti->mti_flags & LDD_F_NEED_REGISTER ? "Initial " : "",
                mti->mti_svname, mti->mti_fsname,
-               libcfs_nid2str(mti->mti_nids[0]), mti->mti_stripe_index);
+               libcfs_nid2str(mti->mti_nids[0]), mti->mti_stripe_index,
+               mti->mti_flags);
 
         /* Register the target */
         /* FIXME use mdc_process_config instead */
         rc = obd_set_info(mgc->u.cli.cl_mgc_mgsexp,
                           strlen("add_target"), "add_target",
                           sizeof(*mti), mti);
-        CDEBUG(D_MOUNT, "disconnect");
         if (rc) {
-                CERROR("add_target failed %d\n", rc);
+                CERROR("registration with the MGS failed (%d)\n", rc);
                 GOTO(out, rc);
         }
 
-        /* If this flag is still set, it means we need to change our on-disk
-           index to what the mgs assigned us. */
-        if (mti->mti_flags & LDD_F_NEED_INDEX) {
+        /* If this flag is set, it means the MGS wants us to change our
+           on-disk data. (So far this means just the index.) */
+        if (mti->mti_flags & LDD_F_REWRITE) {
                 CDEBUG(D_MOUNT, "Must change on-disk index from %#x to %#x for "
                        " %s\n",
                        ldd->ldd_svindex, mti->mti_stripe_index, 
@@ -900,14 +864,12 @@ static int server_add_target(struct super_block *sb, struct vfsmount *mnt)
                 strncpy(ldd->ldd_svname, mti->mti_svname, 
                         sizeof(ldd->ldd_svname));
                 /* or ldd_make_sv_name(ldd); */
+                ldd->ldd_flags = mti->mti_flags & ~LDD_F_REWRITE;
+                ldd_write(&mgc->obd_lvfs_ctxt, ldd);
+                
                 /* FIXME write last_rcvd?, disk label? */
-                mti->mti_flags &= ~LDD_F_NEED_INDEX;
         }
 
-        /* Always write out the new flags */
-        ldd->ldd_flags = mti->mti_flags;
-        ldd_write(&mgc->obd_lvfs_ctxt, ldd);
-
 out:
         if (mti)        
                 OBD_FREE(mti, sizeof(*mti));
@@ -958,16 +920,13 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
            to read and write configs locally. */
         server_mgc_set_fs(lsi->lsi_mgc, sb);
 
-        /* Register if needed */
-        if (lsi->lsi_ldd->ldd_flags & 
-            (LDD_F_NEED_INDEX | LDD_F_NEED_REGISTER | LDD_F_UPGRADE14)) {
-                CDEBUG(D_MOUNT, "Need new target index from MGS\n");
-                rc = server_add_target(sb, mnt);
-                if (rc) {
-                        CERROR("Initial connect failed for %s: %d\n", 
-                               lsi->lsi_ldd->ldd_svname, rc);
-                        GOTO(out, rc);
-                }
+        /* Register with MGS */
+        rc = server_register_target(sb, mnt);
+        if (rc && (lsi->lsi_ldd->ldd_flags & 
+                   (LDD_F_NEED_INDEX | LDD_F_NEED_REGISTER | LDD_F_UPGRADE14))){
+                CERROR("Required refistration failed for %s: %d\n", 
+                       lsi->lsi_ldd->ldd_svname, rc);
+                GOTO(out, rc);
         }
 
         if (class_name2obd(lsi->lsi_ldd->ldd_svname)) {
index a9c905e..0ec6b46 100644 (file)
@@ -8,16 +8,17 @@ AM_LDFLAGS := -L$(top_builddir)/lnet/utils
 
 LIBPTLCTL := $(top_builddir)/lnet/utils/libptlctl.a
 
-sbin_scripts = lconf lmc llanalyze llstat.pl llobdstat.pl lactive      \
+sbin_scripts = llanalyze llstat.pl llobdstat.pl lactive        \
        load_ldap.sh lrun 
 bin_scripts = lfind lstripe
 
 if UTILS
-rootsbin_SCRIPTS =
+# mount only finds helpers in /sbin
+rootsbin_PROGRAMS = mount.lustre
 sbin_PROGRAMS = lctl obdio obdbarrier lload wirecheck wiretest \
-       mount_lustre mount.lustre mkfs_lustre mkfs.lustre \
-       tunefs_lustre tunefs.lustre l_getgroups 
-bin_PROGRAMS = lfs llog_reader
+       mount_lustre mkfs_lustre mkfs.lustre \
+       tunefs_lustre tunefs.lustre l_getgroups llog_reader
+bin_PROGRAMS = lfs
 lib_LIBRARIES = liblustreapi.a
 sbin_SCRIPTS = $(sbin_scripts)
 bin_SCRIPTS = $(bin_scripts)
@@ -69,6 +70,7 @@ newwiretest: wirehdr.c wirecheck
        cp wirehdr.c wiretest.c
        ./wirecheck >> wiretest.c
 
+# Apparently I can't use .'s in automake names
 mount.lustre$(EXEEXT): mount_lustre
        cp $< $@
 
index 49ba5c8..b07e233 100644 (file)
@@ -87,6 +87,7 @@ void usage(FILE *out)
                 "\t\t--reformat: overwrite an existing disk\n"
 #else
                 "\t\t--nomgs: turn off MGS service on this MDT\n"
+                "\t\t--writeconf: erase all config logs for this fs.\n"
 #endif
                 "\t\t--print: just report what we would do; don't write to "
                 "disk\n"
@@ -788,6 +789,7 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                 {"index", 1, 0, 'i'},
                 {"timeout", 1, 0, 't'},
                 {"verbose", 0, 0, 'v'},
+                {"writeconf", 1, 0, 'w'},
                 {0, 0, 0, 0}
         };
         char *optstring = "b:C:d:n:f:hI:MGm:k:No:Opqrw:c:s:i:t:v";
@@ -934,6 +936,9 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                 case 'v':
                         verbose++;
                         break;
+                case 'w':
+                        mop->mo_ldd.ldd_flags |= LDD_F_WRITECONF;
+                        break;
                 default:
                         if (opt != '?') {
                                 fatal();
index 7ffd3b1..7093b97 100644 (file)
@@ -323,7 +323,7 @@ int main(int argc, char *const argv[])
                 usage(stderr);
         }
 
-        if (verbose) {
+        if (verbose > 1) {
                 for (i = 0; i < argc; i++)
                         printf("arg[%d] = %s\n", i, argv[i]);
                 printf("source = %s, target = %s\n", source, target);