Whamcloud - gitweb
LU-12624 lod: alloc dir stripes by QoS
[fs/lustre-release.git] / lustre / obdclass / lprocfs_status.c
index 8894a38..7030e8e 100644 (file)
@@ -425,9 +425,7 @@ static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
                u32 blk_size = osfs.os_bsize >> 10;
                u64 result = osfs.os_blocks;
 
-               while (blk_size >>= 1)
-                       result <<= 1;
-
+               result *= rounddown_pow_of_two(blk_size ?: 1);
                return sprintf(buf, "%llu\n", result);
        }
 
@@ -776,15 +774,19 @@ static const char *obd_connect_names[] = {
        "file_secctx",  /* 0x01 */
        "lockaheadv2",  /* 0x02 */
        "dir_migrate",  /* 0x04 */
-       "unknown",      /* 0x08 */
-       "unknown",      /* 0x10 */
+       "sum_statfs",   /* 0x08 */
+       "overstriping", /* 0x10 */
        "flr",          /* 0x20 */
        "wbc",          /* 0x40 */
        "lock_convert",  /* 0x80 */
        "archive_id_array",     /* 0x100 */
-       "unknown",              /* 0x200 */
+       "increasing_xid",       /* 0x200 */
        "selinux_policy",       /* 0x400 */
        "lsom",                 /* 0x800 */
+       "pcc",                  /* 0x1000 */
+       "plain_layout",         /* 0x2000 */
+       "async_discard",        /* 0x4000 */
+       "client_encryption",    /* 0x8000 */
        NULL
 };
 
@@ -1202,7 +1204,7 @@ int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
        obd->obd_ktype.sysfs_ops = &lustre_sysfs_ops;
        obd->obd_ktype.release = obd_sysfs_release;
 
-       obd->obd_kset.kobj.parent = obd->obd_type->typ_kobj;
+       obd->obd_kset.kobj.parent = &obd->obd_type->typ_kobj;
        obd->obd_kset.kobj.ktype = &obd->obd_ktype;
        init_completion(&obd->obd_kobj_unregister);
        rc = kset_register(&obd->obd_kset);
@@ -1770,86 +1772,6 @@ __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
 }
 EXPORT_SYMBOL(lprocfs_read_helper);
 
-int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
-                             int mult)
-{
-       long decimal_val, frac_val;
-       int prtn;
-
-       if (count < 10)
-               return -EINVAL;
-
-       decimal_val = val / mult;
-       prtn = snprintf(buffer, count, "%ld", decimal_val);
-       frac_val = val % mult;
-
-       if (prtn < (count - 4) && frac_val > 0) {
-               long temp_frac;
-               int i, temp_mult = 1, frac_bits = 0;
-
-               temp_frac = frac_val * 10;
-               buffer[prtn++] = '.';
-               while (frac_bits < 2 && (temp_frac / mult) < 1) {
-                       /* only reserved 2 bits fraction */
-                       buffer[prtn++] = '0';
-                       temp_frac *= 10;
-                       frac_bits++;
-               }
-               /*
-                * Need to think these cases :
-                *      1. #echo x.00 > /proc/xxx       output result : x
-                *      2. #echo x.0x > /proc/xxx       output result : x.0x
-                *      3. #echo x.x0 > /proc/xxx       output result : x.x
-                *      4. #echo x.xx > /proc/xxx       output result : x.xx
-                *      Only reserved 2 bits fraction.
-                */
-               for (i = 0; i < (5 - prtn); i++)
-                       temp_mult *= 10;
-
-               frac_bits = min((int)count - prtn, 3 - frac_bits);
-               prtn += snprintf(buffer + prtn, frac_bits, "%ld",
-                                frac_val * temp_mult / mult);
-
-               prtn--;
-               while (buffer[prtn] < '1' || buffer[prtn] > '9') {
-                       prtn--;
-                       if (buffer[prtn] == '.') {
-                               prtn--;
-                               break;
-                       }
-               }
-               prtn++;
-       }
-       buffer[prtn++] = '\n';
-       return prtn;
-}
-EXPORT_SYMBOL(lprocfs_read_frac_helper);
-
-int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
-{
-       long decimal_val, frac_val;
-
-       decimal_val = val / mult;
-       seq_printf(m, "%ld", decimal_val);
-       frac_val = val % mult;
-
-       if (frac_val > 0) {
-               frac_val *= 100;
-               frac_val /= mult;
-       }
-       if (frac_val > 0) {
-               /* Three cases: x0, xx, 0x */
-               if ((frac_val % 10) != 0)
-                       seq_printf(m, ".%ld", frac_val);
-               else
-                       seq_printf(m, ".%ld", frac_val / 10);
-       }
-
-       seq_printf(m, "\n");
-       return 0;
-}
-EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
-
 /* Obtains the conversion factor for the unit specified */
 static int get_mult(char unit, __u64 *mult)
 {
@@ -1860,15 +1782,19 @@ static int get_mult(char unit, __u64 *mult)
        case 'p':
        case 'P':
                units <<= 10;
+               /* fallthrough */
        case 't':
        case 'T':
                units <<= 10;
+               /* fallthrough */
        case 'g':
        case 'G':
                units <<= 10;
+               /* fallthrough */
        case 'm':
        case 'M':
                units <<= 10;
+               /* fallthrough */
        case 'k':
        case 'K':
                units <<= 10;
@@ -2063,34 +1989,31 @@ static int str_to_u64_parse(char *buffer, unsigned long count,
  * have a unit as the last character. The function handles overflow/underflow
  * of the signed integer.
  */
-static int str_to_s64_internal(const char __user *buffer, unsigned long count,
-                              __s64 *val, __u64 def_mult, bool allow_units)
+int lu_str_to_s64(char *buffer, unsigned long count, __s64 *val, char defunit)
 {
-       char kernbuf[22];
+       __u64 mult = 1;
        __u64 tmp;
        unsigned int offset = 0;
        int signed sign = 1;
        __u64 max = LLONG_MAX;
        int rc = 0;
 
-       if (count > (sizeof(kernbuf) - 1))
-               return -EINVAL;
-
-       if (copy_from_user(kernbuf, buffer, count))
-               return -EFAULT;
-
-       kernbuf[count] = '\0';
+       if (defunit != '1') {
+               rc = get_mult(defunit, &mult);
+               if (rc)
+                       return rc;
+       }
 
        /* keep track of our sign */
-       if (*kernbuf == '-') {
+       if (*buffer == '-') {
                sign = -1;
                offset++;
                /* equivalent to max = -LLONG_MIN, avoids overflow */
                max++;
        }
 
-       rc = str_to_u64_parse(kernbuf + offset, count - offset,
-                             &tmp, def_mult, allow_units);
+       rc = str_to_u64_parse(buffer + offset, count - offset,
+                             &tmp, mult, true);
        if (rc)
                return rc;
 
@@ -2102,7 +2025,31 @@ static int str_to_s64_internal(const char __user *buffer, unsigned long count,
 
        return 0;
 }
+EXPORT_SYMBOL(lu_str_to_s64);
+
+/* identical to s64 version, but does not handle overflow */
+static int str_to_u64_internal(const char __user *buffer, unsigned long count,
+                              __u64 *val, __u64 def_mult, bool allow_units)
+{
+       char kernbuf[22];
+       unsigned int offset = 0;
+       int rc = 0;
+
+       if (count > (sizeof(kernbuf) - 1))
+               return -EINVAL;
+
+       if (copy_from_user(kernbuf, buffer, count))
+               return -EFAULT;
+
+       kernbuf[count] = '\0';
+
+       rc = str_to_u64_parse(kernbuf + offset, count - offset,
+                             val, def_mult, allow_units);
+       if (rc)
+               return rc;
 
+       return 0;
+}
 /**
  * Convert a user string into a signed 64 bit number. This function produces
  * an error when the value parsed from the string times multiplier underflows or
@@ -2123,6 +2070,24 @@ static int str_to_s64_internal(const char __user *buffer, unsigned long count,
 int lprocfs_str_with_units_to_s64(const char __user *buffer,
                                  unsigned long count, __s64 *val, char defunit)
 {
+       char kernbuf[22];
+
+       if (count > (sizeof(kernbuf) - 1))
+               return -EINVAL;
+
+       if (copy_from_user(kernbuf, buffer, count))
+               return -EFAULT;
+
+       kernbuf[count] = '\0';
+
+       return lu_str_to_s64(kernbuf, count, val, defunit);
+}
+EXPORT_SYMBOL(lprocfs_str_with_units_to_s64);
+
+/* identical to s64 version above, but does not handle overflow */
+int lprocfs_str_with_units_to_u64(const char __user *buffer,
+                                 unsigned long count, __u64 *val, char defunit)
+{
        __u64 mult = 1;
        int rc;
 
@@ -2132,9 +2097,9 @@ int lprocfs_str_with_units_to_s64(const char __user *buffer,
                        return rc;
        }
 
-       return str_to_s64_internal(buffer, count, val, mult, true);
+       return str_to_u64_internal(buffer, count, val, mult, true);
 }
-EXPORT_SYMBOL(lprocfs_str_with_units_to_s64);
+EXPORT_SYMBOL(lprocfs_str_with_units_to_u64);
 
 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
 {
@@ -2494,10 +2459,10 @@ int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
        if ((len == 4 && strncmp(kernbuf, "NONE", len) == 0) ||
            (len == 5 && strncmp(kernbuf, "clear", len) == 0)) {
                /* empty string is special case */
-               down_write(&squash->rsi_sem);
+               spin_lock(&squash->rsi_lock);
                if (!list_empty(&squash->rsi_nosquash_nids))
                        cfs_free_nidlist(&squash->rsi_nosquash_nids);
-               up_write(&squash->rsi_sem);
+               spin_unlock(&squash->rsi_lock);
                LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
                OBD_FREE(kernbuf, count + 1);
                RETURN(count);
@@ -2513,11 +2478,11 @@ int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
        OBD_FREE(kernbuf, count + 1);
        kernbuf = NULL;
 
-       down_write(&squash->rsi_sem);
+       spin_lock(&squash->rsi_lock);
        if (!list_empty(&squash->rsi_nosquash_nids))
                cfs_free_nidlist(&squash->rsi_nosquash_nids);
        list_splice(&tmp, &squash->rsi_nosquash_nids);
-       up_write(&squash->rsi_sem);
+       spin_unlock(&squash->rsi_lock);
 
        RETURN(count);