Whamcloud - gitweb
LU-4017 quota: cleanup codes of quota for new type
[fs/lustre-release.git] / lustre / include / lustre_param.h
index 9ccd63f..eb2f5fa 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2014, Intel Corporation.
+ * Copyright (c) 2011, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -123,4 +119,78 @@ int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
 
 /** @} param */
 
+#define LUSTRE_MAXFSNAME       8
+
+/**
+ * Check whether the name is valid.
+ *
+ * \param name [in]    the name to be checked
+ * \param minlen [in]  the minimum length of the name
+ * \param maxlen [in]  the maximum length of the name
+ *
+ * \retval 0   the name is valid
+ * \retval >0  the invalid character in the name
+ * \retval -1  the name is too short
+ * \retval -2  the name is too long
+ */
+static inline int lustre_is_name_valid(const char *name, const int minlen,
+                                      const int maxlen)
+{
+       const char      *tmp;
+       size_t          len;
+
+       len = strlen(name);
+
+       if (len < minlen)
+               return -1;
+
+       if (len > maxlen)
+               return -2;
+
+       for (tmp = name; *tmp != '\0'; ++tmp) {
+               if (isalnum(*tmp) || *tmp == '_' || *tmp == '-')
+                       continue;
+               else
+                       break;
+       }
+
+       return *tmp == '\0' ? 0 : *tmp;
+}
+
+/**
+ * Check whether the fsname is valid.
+ *
+ * \param fsname [in]  the fsname to be checked
+ * \param minlen [in]  the minimum length of the fsname
+ * \param maxlen [in]  the maximum length of the fsname
+ *
+ * \retval 0   the fsname is valid
+ * \retval >0  the invalid character in the fsname
+ * \retval -1  the fsname is too short
+ * \retval -2  the fsname is too long
+ */
+static inline int lustre_is_fsname_valid(const char *fsname, const int minlen,
+                                        const int maxlen)
+{
+       return lustre_is_name_valid(fsname, minlen, maxlen);
+}
+
+/**
+ * Check whether the poolname is valid.
+ *
+ * \param poolname [in]        the poolname to be checked
+ * \param minlen [in]  the minimum length of the poolname
+ * \param maxlen [in]  the maximum length of the poolname
+ *
+ * \retval 0   the poolname is valid
+ * \retval >0  the invalid character in the poolname
+ * \retval -1  the poolname is too short
+ * \retval -2  the poolname is too long
+ */
+static inline int lustre_is_poolname_valid(const char *poolname,
+                                          const int minlen, const int maxlen)
+{
+       return lustre_is_name_valid(poolname, minlen, maxlen);
+}
+
 #endif /* _LUSTRE_PARAM_H */