Whamcloud - gitweb
LU-1095 debug: clean up console messages
[fs/lustre-release.git] / lustre / obdclass / obd_mount.c
index dab4140..0fa0463 100644 (file)
@@ -46,7 +46,6 @@
 #define PRINT_CMD CDEBUG
 
 #include <obd.h>
-#include <lvfs.h>
 #include <obd_class.h>
 #include <lustre/lustre_user.h>
 #include <linux/version.h>
@@ -107,8 +106,7 @@ int lustre_process_log(struct super_block *sb, char *logname,
                                    "client and the MGS are running compatible "
                                    "versions of Lustre.\n",
                                    mgc->obd_name, logname, rc);
-
-        if (rc)
+       else if (rc != 0)
                 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' "
                                    "failed (%d). This may be the result of "
                                    "communication errors between this node and "
@@ -280,7 +278,7 @@ int lustre_start_mgc(struct super_block *sb)
                         GOTO(out_free, rc);
 
                 /* Re-using an existing MGC */
-                cfs_atomic_inc(&obd->u.cli.cl_mgc_refcount);
+               atomic_inc(&obd->u.cli.cl_mgc_refcount);
 
                 /* IR compatibility check, only for clients */
                 if (lmd_is_client(lsi->lsi_lmd)) {
@@ -336,36 +334,48 @@ int lustre_start_mgc(struct super_block *sb)
         sprintf(niduuid, "%s_%x", mgcname, i);
        if (IS_SERVER(lsi)) {
                ptr = lsi->lsi_lmd->lmd_mgs;
+               CDEBUG(D_MOUNT, "mgs nids %s.\n", ptr);
                if (IS_MGS(lsi)) {
-                        /* Use local nids (including LO) */
-                        lnet_process_id_t id;
-                        while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
-                                rc = do_lcfg(mgcname, id.nid,
-                                             LCFG_ADD_UUID, niduuid, 0,0,0);
-                        }
-                } else {
-                        /* Use mgsnode= nids */
+                       /* Use local nids (including LO) */
+                       lnet_process_id_t id;
+                       while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
+                               rc = do_lcfg(mgcname, id.nid, LCFG_ADD_UUID,
+                                            niduuid, 0, 0, 0);
+                       }
+               } else {
+                       /* Use mgsnode= nids */
                        /* mount -o mgsnode=nid */
                        if (lsi->lsi_lmd->lmd_mgs) {
                                ptr = lsi->lsi_lmd->lmd_mgs;
                        } else if (class_find_param(ptr, PARAM_MGSNODE,
                                                    &ptr) != 0) {
-                                CERROR("No MGS nids given.\n");
-                                GOTO(out_free, rc = -EINVAL);
-                        }
-                        while (class_parse_nid(ptr, &nid, &ptr) == 0) {
-                                rc = do_lcfg(mgcname, nid,
-                                             LCFG_ADD_UUID, niduuid, 0,0,0);
-                                i++;
-                        }
-                }
+                               CERROR("No MGS nids given.\n");
+                               GOTO(out_free, rc = -EINVAL);
+                       }
+                       /*
+                        * LU-3829.
+                        * Here we only take the first mgsnid as its primary
+                        * serving mgs node, the rest mgsnid will be taken as
+                        * failover mgs node, otherwise they would be takens
+                        * as multiple nids of a single mgs node.
+                        */
+                       while (class_parse_nid(ptr, &nid, &ptr) == 0) {
+                               rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
+                                            niduuid, 0, 0, 0);
+                               if (rc == 0) {
+                                       i = 1;
+                                       break;
+                               }
+                       }
+               }
         } else { /* client */
                 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
                 ptr = lsi->lsi_lmd->lmd_dev;
                 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
-                        rc = do_lcfg(mgcname, nid,
-                                     LCFG_ADD_UUID, niduuid, 0,0,0);
-                        i++;
+                       rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
+                                    niduuid, 0, 0, 0);
+                       if (rc == 0)
+                               ++i;
                         /* Stop at the first failover nid */
                         if (*ptr == ':')
                                 break;
@@ -394,20 +404,22 @@ int lustre_start_mgc(struct super_block *sb)
         i = 1;
        while (ptr && ((*ptr == ':' ||
               class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
-                /* New failover node */
-                sprintf(niduuid, "%s_%x", mgcname, i);
-                j = 0;
+               /* New failover node */
+               sprintf(niduuid, "%s_%x", mgcname, i);
+               j = 0;
                while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
-                        j++;
-                        rc = do_lcfg(mgcname, nid,
-                                     LCFG_ADD_UUID, niduuid, 0,0,0);
-                        if (*ptr == ':')
-                                break;
-                }
-                if (j > 0) {
-                        rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
-                                     niduuid, 0, 0, 0);
-                        i++;
+                       rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
+                                    niduuid, 0, 0, 0);
+                       if (rc == 0)
+                               ++j;
+                       if (*ptr == ':')
+                               break;
+               }
+               if (j > 0) {
+                       rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
+                                    niduuid, 0, 0, 0);
+                       if (rc == 0)
+                               ++i;
                 } else {
                         /* at ":/fsname" */
                         break;
@@ -429,7 +441,7 @@ int lustre_start_mgc(struct super_block *sb)
 
         /* Keep a refcount of servers/clients who started with "mount",
            so we know when we can get rid of the mgc. */
-        cfs_atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
+       atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
 
         /* Try all connections, but only once. */
         recov_bk = 1;
@@ -496,12 +508,12 @@ static int lustre_stop_mgc(struct super_block *sb)
         lsi->lsi_mgc = NULL;
 
        mutex_lock(&mgc_start_lock);
-        LASSERT(cfs_atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
-        if (!cfs_atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
+       LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
+       if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
                 /* This is not fatal, every client that stops
                    will call in here. */
                 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
-                       cfs_atomic_read(&obd->u.cli.cl_mgc_refcount));
+                      atomic_read(&obd->u.cli.cl_mgc_refcount));
                 GOTO(out, rc = -EBUSY);
         }
 
@@ -572,7 +584,7 @@ struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
         lsi->lsi_lmd->lmd_recovery_time_hard = 0;
         s2lsi_nocast(sb) = lsi;
         /* we take 1 extra ref for our setup */
-        cfs_atomic_set(&lsi->lsi_mounts, 1);
+       atomic_set(&lsi->lsi_mounts, 1);
 
         /* Default umount style */
         lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
@@ -589,7 +601,7 @@ static int lustre_free_lsi(struct super_block *sb)
         CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
 
         /* someone didn't call server_put_mount. */
-        LASSERT(cfs_atomic_read(&lsi->lsi_mounts) == 0);
+       LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
 
         if (lsi->lsi_lmd != NULL) {
                 if (lsi->lsi_lmd->lmd_dev != NULL)
@@ -636,8 +648,8 @@ int lustre_put_lsi(struct super_block *sb)
 
         LASSERT(lsi != NULL);
 
-        CDEBUG(D_MOUNT, "put %p %d\n", sb, cfs_atomic_read(&lsi->lsi_mounts));
-        if (cfs_atomic_dec_and_test(&lsi->lsi_mounts)) {
+       CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
+       if (atomic_dec_and_test(&lsi->lsi_mounts)) {
                if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
                        lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
                        lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
@@ -737,22 +749,15 @@ int server_name_is_ost(const char *svname)
 }
 EXPORT_SYMBOL(server_name_is_ost);
 
-/* Get the index from the obd name.
-   rc = server type, or
  rc < 0  on error
  if endptr isn't NULL it is set to end of name */
-int server_name2index(const char *svname, __u32 *idx, const char **endptr)
+/**
+ * Get the index from the target name MDTXXXX/OSTXXXX
* rc = server type, or rc < 0  on error
**/
+int target_name2index(const char *tgtname, __u32 *idx, const char **endptr)
 {
+       const char *dash = tgtname;
        unsigned long index;
        int rc;
-       const char *dash;
-
-       /* We use server_name2fsname() just for parsing */
-       rc = server_name2fsname(svname, NULL, &dash);
-       if (rc != 0)
-               return rc;
-
-       dash++;
 
        if (strncmp(dash, "MDT", 3) == 0)
                rc = LDD_F_SV_TYPE_MDT;
@@ -772,6 +777,28 @@ int server_name2index(const char *svname, __u32 *idx, const char **endptr)
        index = simple_strtoul(dash, (char **)endptr, 16);
        if (idx != NULL)
                *idx = index;
+       return rc;
+}
+EXPORT_SYMBOL(target_name2index);
+
+/* Get the index from the obd name.
+   rc = server type, or
+   rc < 0  on error
+   if endptr isn't NULL it is set to end of name */
+int server_name2index(const char *svname, __u32 *idx, const char **endptr)
+{
+       const char *dash;
+       int rc;
+
+       /* We use server_name2fsname() just for parsing */
+       rc = server_name2fsname(svname, NULL, &dash);
+       if (rc != 0)
+               return rc;
+
+       dash++;
+       rc = target_name2index(dash, idx, endptr);
+       if (rc < 0)
+               return rc;
 
        /* Account for -mdc after index that is possible when specifying mdt */
        if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,