Whamcloud - gitweb
LU-3126 osd: remove fld lookup during configuration
[fs/lustre-release.git] / lustre / obdclass / obd_mount.c
index 1c99179..dab4140 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -47,7 +47,6 @@
 
 #include <obd.h>
 #include <lvfs.h>
-#include <lustre_fsfilt.h>
 #include <obd_class.h>
 #include <lustre/lustre_user.h>
 #include <linux/version.h>
@@ -640,6 +639,9 @@ int lustre_put_lsi(struct super_block *sb)
         CDEBUG(D_MOUNT, "put %p %d\n", sb, cfs_atomic_read(&lsi->lsi_mounts));
         if (cfs_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;
+                       lsi->lsi_dt_dev = NULL;
                        obd_disconnect(lsi->lsi_osd_exp);
                        /* wait till OSD is gone */
                        obd_zombie_barrier();
@@ -650,6 +652,15 @@ int lustre_put_lsi(struct super_block *sb)
         RETURN(0);
 }
 
+/*** SERVER NAME ***
+ * <FSNAME><SEPERATOR><TYPE><INDEX>
+ * FSNAME is between 1 and 8 characters (inclusive).
+ *     Excluded characters are '/' and ':'
+ * SEPERATOR is either ':' or '-'
+ * TYPE: "OST", "MDT", etc.
+ * INDEX: Hex representation of the index
+ */
+
 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
  * @param [in] svname server name including type and index
  * @param [out] fsname Buffer to copy filesystem name prefix into.
@@ -659,22 +670,13 @@ int lustre_put_lsi(struct super_block *sb)
  */
 int server_name2fsname(const char *svname, char *fsname, const char **endptr)
 {
-       const char *dash = strrchr(svname, '-');
-       if (!dash) {
-               dash = strrchr(svname, ':');
-               if (!dash)
-                       return -EINVAL;
-       }
+       const char *dash;
 
-       /* interpret <fsname>-MDTXXXXX-mdc as mdt, the better way is to pass
-        * in the fsname, then determine the server index */
-       if (!strcmp(LUSTRE_MDC_NAME, dash + 1)) {
-               dash--;
-               for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
-                       ;
-               if (dash == svname)
-                       return -EINVAL;
-       }
+       dash = svname + strnlen(svname, 8); /* max fsname length is 8 */
+       for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
+               ;
+       if (dash == svname)
+               return -EINVAL;
 
        if (fsname != NULL) {
                strncpy(fsname, svname, dash - svname);
@@ -697,15 +699,15 @@ int server_name2svname(const char *label, char *svname, const char **endptr,
                       size_t svsize)
 {
        int rc;
-       const const char *dash;
+       const char *dash;
 
        /* We use server_name2fsname() just for parsing */
        rc = server_name2fsname(label, NULL, &dash);
        if (rc != 0)
                return rc;
 
-       if (*dash != '-')
-               return -1;
+       if (endptr != NULL)
+               *endptr = dash;
 
        if (strlcpy(svname, dash + 1, svsize) >= svsize)
                return -E2BIG;
@@ -714,6 +716,26 @@ int server_name2svname(const char *label, char *svname, const char **endptr,
 }
 EXPORT_SYMBOL(server_name2svname);
 
+/**
+ * check server name is OST.
+ **/
+int server_name_is_ost(const char *svname)
+{
+       const char *dash;
+       int rc;
+
+       /* We use server_name2fsname() just for parsing */
+       rc = server_name2fsname(svname, NULL, &dash);
+       if (rc != 0)
+               return rc;
+
+       dash++;
+
+       if (strncmp(dash, "OST", 3) == 0)
+               return 1;
+       return 0;
+}
+EXPORT_SYMBOL(server_name_is_ost);
 
 /* Get the index from the obd name.
    rc = server type, or
@@ -730,9 +752,6 @@ int server_name2index(const char *svname, __u32 *idx, const char **endptr)
        if (rc != 0)
                return rc;
 
-       if (*dash != '-')
-               return -EINVAL;
-
        dash++;
 
        if (strncmp(dash, "MDT", 3) == 0)
@@ -744,11 +763,20 @@ int server_name2index(const char *svname, __u32 *idx, const char **endptr)
 
        dash += 3;
 
-       if (strcmp(dash, "all") == 0)
+       if (strncmp(dash, "all", 3) == 0) {
+               if (endptr != NULL)
+                       *endptr = dash + 3;
                return rc | LDD_F_SV_ALL;
+       }
 
        index = simple_strtoul(dash, (char **)endptr, 16);
-       *idx = index;
+       if (idx != NULL)
+               *idx = index;
+
+       /* Account for -mdc after index that is possible when specifying mdt */
+       if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
+                                     sizeof(LUSTRE_MDC_NAME)-1) == 0)
+               *endptr += sizeof(LUSTRE_MDC_NAME);
 
        return rc;
 }
@@ -839,55 +867,57 @@ 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;
-        int rc = 0, devmax;
-        ENTRY;
-
-        /* The shortest an ost name can be is 8 chars: -OST0000.
-           We don't actually know the fsname at this time, so in fact
-           a user could specify any fsname. */
-        devmax = strlen(ptr) / 8 + 1;
-
-        /* temp storage until we figure out how many we have */
-        OBD_ALLOC(exclude_list, sizeof(index) * devmax);
-        if (!exclude_list)
-                RETURN(-ENOMEM);
+       __u32 index, *exclude_list;
+       int rc = 0, devmax;
+       ENTRY;
+
+       /* The shortest an ost name can be is 8 chars: -OST0000.
+          We don't actually know the fsname at this time, so in fact
+          a user could specify any fsname. */
+       devmax = strlen(ptr) / 8 + 1;
+
+       /* temp storage until we figure out how many we have */
+       OBD_ALLOC(exclude_list, sizeof(index) * devmax);
+       if (!exclude_list)
+               RETURN(-ENOMEM);
 
-        /* we enter this fn pointing at the '=' */
-        while (*s1 && *s1 != ' ' && *s1 != ',') {
-                s1++;
-                rc = server_name2index(s1, &index, &s2);
-                if (rc < 0) {
-                        CERROR("Can't parse server name '%s'\n", s1);
-                        break;
-                }
-                if (rc == LDD_F_SV_TYPE_OST)
-                        exclude_list[lmd->lmd_exclude_count++] = index;
-                else
-                        CDEBUG(D_MOUNT, "ignoring exclude %.7s\n", s1);
-                s1 = s2;
-                /* now we are pointing at ':' (next exclude)
-                   or ',' (end of excludes) */
-                if (lmd->lmd_exclude_count >= devmax)
-                        break;
-        }
-        if (rc >= 0) /* non-err */
-                rc = 0;
-
-        if (lmd->lmd_exclude_count) {
-                /* permanent, freed in lustre_free_lsi */
-                OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
-                          lmd->lmd_exclude_count);
-                if (lmd->lmd_exclude) {
-                        memcpy(lmd->lmd_exclude, exclude_list,
-                               sizeof(index) * lmd->lmd_exclude_count);
-                } else {
-                        rc = -ENOMEM;
-                        lmd->lmd_exclude_count = 0;
-                }
-        }
-        OBD_FREE(exclude_list, sizeof(index) * devmax);
-        RETURN(rc);
+       /* we enter this fn pointing at the '=' */
+       while (*s1 && *s1 != ' ' && *s1 != ',') {
+               s1++;
+               rc = server_name2index(s1, &index, &s2);
+               if (rc < 0) {
+                       CERROR("Can't parse server name '%s': rc = %d\n",
+                              s1, rc);
+                       break;
+               }
+               if (rc == LDD_F_SV_TYPE_OST)
+                       exclude_list[lmd->lmd_exclude_count++] = index;
+               else
+                       CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
+                              (uint)(s2-s1), s1, rc);
+               s1 = s2;
+               /* now we are pointing at ':' (next exclude)
+                  or ',' (end of excludes) */
+               if (lmd->lmd_exclude_count >= devmax)
+                       break;
+       }
+       if (rc >= 0) /* non-err */
+               rc = 0;
+
+       if (lmd->lmd_exclude_count) {
+               /* permanent, freed in lustre_free_lsi */
+               OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
+                         lmd->lmd_exclude_count);
+               if (lmd->lmd_exclude) {
+                       memcpy(lmd->lmd_exclude, exclude_list,
+                              sizeof(index) * lmd->lmd_exclude_count);
+               } else {
+                       rc = -ENOMEM;
+                       lmd->lmd_exclude_count = 0;
+               }
+       }
+       OBD_FREE(exclude_list, sizeof(index) * devmax);
+       RETURN(rc);
 }
 
 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)