Whamcloud - gitweb
LU-4629 obdclass: compile issues with variable not being initialized
[fs/lustre-release.git] / lustre / obdclass / obd_mount.c
index 25aae80..bfa1c12 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>
@@ -96,9 +95,11 @@ int lustre_process_log(struct super_block *sb, char *logname,
         lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
         lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
         lcfg = lustre_cfg_new(LCFG_LOG_START, bufs);
-        rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
-        lustre_cfg_free(lcfg);
-
+       if (lcfg == NULL)
+               GOTO(out, rc = -ENOMEM);
+       rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
+       lustre_cfg_free(lcfg);
+out:
         OBD_FREE_PTR(bufs);
 
         if (rc == -EINVAL)
@@ -107,8 +108,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 "
@@ -142,6 +142,8 @@ int lustre_end_log(struct super_block *sb, char *logname,
         if (cfg)
                 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
         lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
+       if (lcfg == NULL)
+               RETURN(-ENOMEM);
         rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
         lustre_cfg_free(lcfg);
         RETURN(rc);
@@ -174,6 +176,8 @@ int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
                 lustre_cfg_bufs_set_string(&bufs, 4, s4);
 
         lcfg = lustre_cfg_new(cmd, &bufs);
+       if (lcfg == NULL)
+               return -ENOMEM;
         lcfg->lcfg_nid = nid;
         rc = class_process_config(lcfg);
         lustre_cfg_free(lcfg);
@@ -222,7 +226,6 @@ int lustre_start_mgc(struct super_block *sb)
         lnet_nid_t nid;
         char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
         char *ptr;
-        int recov_bk;
         int rc = 0, i = 0, j, len;
         ENTRY;
 
@@ -273,6 +276,8 @@ int lustre_start_mgc(struct super_block *sb)
 
         obd = class_name2obd(mgcname);
         if (obd && !obd->obd_stopping) {
+               int recov_bk;
+
                 rc = obd_set_info_async(NULL, obd->obd_self_export,
                                         strlen(KEY_MGSSEC), KEY_MGSSEC,
                                         strlen(mgssec), mgssec, NULL);
@@ -280,7 +285,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)) {
@@ -443,17 +448,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);
-
-        /* Try all connections, but only once. */
-        recov_bk = 1;
-        rc = obd_set_info_async(NULL, obd->obd_self_export,
-                                sizeof(KEY_INIT_RECOV_BACKUP),
-                                KEY_INIT_RECOV_BACKUP,
-                                sizeof(recov_bk), &recov_bk, NULL);
-        if (rc)
-                /* nonfatal */
-                CWARN("can't set %s %d\n", KEY_INIT_RECOV_BACKUP, rc);
+       atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
 
        /* We connect to the MGS at setup, and don't disconnect until cleanup */
        data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
@@ -510,12 +505,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);
         }
 
@@ -586,12 +581,14 @@ 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;
+       INIT_LIST_HEAD(&lsi->lsi_lwp_list);
+       spin_lock_init(&lsi->lsi_lwp_lock);
 
-        RETURN(lsi);
+       RETURN(lsi);
 }
 
 static int lustre_free_lsi(struct super_block *sb)
@@ -603,7 +600,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)
@@ -645,13 +642,13 @@ static int lustre_free_lsi(struct super_block *sb)
    e.g. MDT, MGS, and potentially MGC */
 int lustre_put_lsi(struct super_block *sb)
 {
-        struct lustre_sb_info *lsi = s2lsi(sb);
-        ENTRY;
+       struct lustre_sb_info *lsi = s2lsi(sb);
+       ENTRY;
 
-        LASSERT(lsi != NULL);
+       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;
@@ -660,10 +657,10 @@ int lustre_put_lsi(struct super_block *sb)
                        /* wait till OSD is gone */
                        obd_zombie_barrier();
                }
-                lustre_free_lsi(sb);
-                RETURN(1);
-        }
-        RETURN(0);
+               lustre_free_lsi(sb);
+               RETURN(1);
+       }
+       RETURN(0);
 }
 
 /*** SERVER NAME ***
@@ -751,22 +748,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;
@@ -786,6 +776,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,
@@ -819,8 +831,8 @@ int lustre_common_put_super(struct super_block *sb)
         }
         /* Drop a ref to the mounted disk */
         lustre_put_lsi(sb);
-        lu_types_stop();
-        RETURN(rc);
+
+       RETURN(rc);
 }
 EXPORT_SYMBOL(lustre_common_put_super);
 
@@ -881,7 +893,8 @@ int lustre_check_exclusion(struct super_block *sb, char *svname)
 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
 {
        const char *s1 = ptr, *s2;
-       __u32 index, *exclude_list;
+       __u32 *exclude_list;
+       __u32 index = 0;
        int rc = 0, devmax;
        ENTRY;
 
@@ -1032,7 +1045,7 @@ static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
  */
 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
 {
-        char *s1, *s2, *devname = NULL;
+       char *s1, *s2, *s3, *devname = NULL;
         struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
         int rc = 0;
         ENTRY;
@@ -1068,6 +1081,7 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                 /* Skip whitespace and extra commas */
                 while (*s1 == ' ' || *s1 == ',')
                         s1++;
+               s3 = s1;
 
                 /* Client options are parsed in ll_options: eg. flock,
                    user_xattr, acl */
@@ -1105,6 +1119,7 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                        rc = lmd_parse_mgs(lmd, &s2);
                        if (rc)
                                goto invalid;
+                       s3 = s2;
                        clear++;
                 } else if (strncmp(s1, "writeconf", 9) == 0) {
                         lmd->lmd_flags |= LMD_FLG_WRITECONF;
@@ -1141,13 +1156,23 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                } else if (strncmp(s1, "param=", 6) == 0) {
                        int length;
                        char *tail = strchr(s1 + 6, ',');
-                       if (tail == NULL)
+                       if (tail == NULL) {
                                length = strlen(s1);
-                       else
-                               length = tail - s1;
+                       } else {
+                               lnet_nid_t nid;
+                               char      *param_str = tail + 1;
+                               int        supplementary = 1;
+
+                               while (class_parse_nid_quiet(param_str, &nid,
+                                                            &param_str) == 0) {
+                                       supplementary = 0;
+                               }
+                               length = param_str - s1 - supplementary;
+                       }
                        length -= 6;
                        strncat(lmd->lmd_params, s1 + 6, length);
                        strcat(lmd->lmd_params, " ");
+                       s3 = s1 + 6 + length;
                        clear++;
                } else if (strncmp(s1, "osd=", 4) == 0) {
                        rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
@@ -1165,8 +1190,8 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                         break;
                 }
 
-                /* Find next opt */
-                s2 = strchr(s1, ',');
+               /* Find next opt */
+               s2 = strchr(s3, ',');
                 if (s2 == NULL) {
                         if (clear)
                                 *s1 = '\0';
@@ -1270,7 +1295,9 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
 
         if (lmd_is_client(lmd)) {
                 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
-                if (!client_fill_super) {
+               if (client_fill_super == NULL)
+                       request_module("lustre");
+               if (client_fill_super == NULL) {
                         LCONSOLE_ERROR_MSG(0x165, "Nothing registered for "
                                            "client mount! Is the 'lustre' "
                                            "module loaded?\n");
@@ -1376,6 +1403,7 @@ struct file_system_type lustre_fs_type = {
        .fs_flags     = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV |
                        FS_HAS_FIEMAP | FS_RENAME_DOES_D_MOVE,
 };
+MODULE_ALIAS_FS("lustre");
 
 int lustre_register_fs(void)
 {