Whamcloud - gitweb
LU-9679 lustre: avoid cast of file->private_data
[fs/lustre-release.git] / lustre / osc / lproc_osc.c
index b4c0e35..387ec7d 100644 (file)
@@ -210,9 +210,11 @@ static ssize_t osc_cached_mb_seq_write(struct file *file,
                                       const char __user *buffer,
                                       size_t count, loff_t *off)
 {
-       struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
+       struct seq_file *m = file->private_data;
+       struct obd_device *dev = m->private;
        struct client_obd *cli = &dev->u.cli;
-       __s64 pages_number;
+       u64 pages_number;
+       const char *tmp;
        long rc;
        char kernbuf[128];
 
@@ -223,17 +225,13 @@ static ssize_t osc_cached_mb_seq_write(struct file *file,
                return -EFAULT;
        kernbuf[count] = 0;
 
-       buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
-                 kernbuf;
-       rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
-       if (rc)
+       tmp = lprocfs_find_named_value(kernbuf, "used_mb:", &count);
+       rc = sysfs_memparse(tmp, count, &pages_number, "MiB");
+       if (rc < 0)
                return rc;
 
        pages_number >>= PAGE_SHIFT;
 
-       if (pages_number < 0)
-               return -ERANGE;
-
        rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
        if (rc > 0) {
                struct lu_env *env;
@@ -283,19 +281,26 @@ static ssize_t osc_cur_grant_bytes_seq_write(struct file *file,
                                             const char __user *buffer,
                                             size_t count, loff_t *off)
 {
-       struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
+       struct seq_file *m = file->private_data;
+       struct obd_device *obd = m->private;
        struct client_obd *cli = &obd->u.cli;
-       s64 val;
+       char kernbuf[22] = "";
+       u64 val;
        int rc;
 
        if (obd == NULL)
                return 0;
 
-       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
-       if (rc)
+       if (count >= sizeof(kernbuf))
+               return -EINVAL;
+
+       if (copy_from_user(kernbuf, buffer, count))
+               return -EFAULT;
+       kernbuf[count] = 0;
+
+       rc = sysfs_memparse(kernbuf, count, &val, "MiB");
+       if (rc < 0)
                return rc;
-       if (val < 0)
-               return val;
 
        /* this is only for shrinking grant */
        spin_lock(&cli->cl_loi_list_lock);
@@ -421,32 +426,39 @@ static ssize_t osc_checksum_type_seq_write(struct file *file,
                                           const char __user *buffer,
                                           size_t count, loff_t *off)
 {
-       struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
+       struct seq_file *m = file->private_data;
+       struct obd_device *obd = m->private;
        int i;
        DECLARE_CKSUM_NAME;
        char kernbuf[10];
+       int rc = -EINVAL;
 
-        if (obd == NULL)
-                return 0;
+       if (obd == NULL)
+               return 0;
 
-        if (count > sizeof(kernbuf) - 1)
-                return -EINVAL;
+       if (count > sizeof(kernbuf) - 1)
+               return -EINVAL;
        if (copy_from_user(kernbuf, buffer, count))
-                return -EFAULT;
-        if (count > 0 && kernbuf[count - 1] == '\n')
-                kernbuf[count - 1] = '\0';
-        else
-                kernbuf[count] = '\0';
-
-        for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
-                if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
-                        continue;
-                if (!strcmp(kernbuf, cksum_name[i])) {
-                       obd->u.cli.cl_cksum_type = 1 << i;
-                       return count;
-                }
-        }
-        return -EINVAL;
+               return -EFAULT;
+
+       if (count > 0 && kernbuf[count - 1] == '\n')
+               kernbuf[count - 1] = '\0';
+       else
+               kernbuf[count] = '\0';
+
+       for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
+               if (strcmp(kernbuf, cksum_name[i]) == 0) {
+                       obd->u.cli.cl_preferred_cksum_type = BIT(i);
+                       if (obd->u.cli.cl_supp_cksum_types & BIT(i)) {
+                               obd->u.cli.cl_cksum_type = BIT(i);
+                               rc = count;
+                       } else {
+                               rc = -ENOTSUPP;
+                       }
+                       break;
+               }
+       }
+       return rc;
 }
 LPROC_SEQ_FOPS(osc_checksum_type);
 
@@ -691,15 +703,14 @@ static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
-       struct client_obd *cli = &obd->u.cli;
-       struct obd_connect_data *ocd;
+       struct obd_import *imp;
        ssize_t len;
 
        LPROCFS_CLIMP_CHECK(obd);
-       ocd = &cli->cl_import->imp_connect_data;
-
-       len = snprintf(buf, PAGE_SIZE, "%d\n",
-                      !!OCD_HAS_FLAG(ocd, GRANT_SHRINK));
+       imp = obd->u.cli.cl_import;
+       len = scnprintf(buf, PAGE_SIZE, "%d\n",
+                       !imp->imp_grant_shrink_disabled &&
+                       OCD_HAS_FLAG(&imp->imp_connect_data, GRANT_SHRINK));
        LPROCFS_CLIMP_EXIT(obd);
 
        return len;
@@ -710,8 +721,7 @@ static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
 {
        struct obd_device *dev = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
-       struct client_obd *cli = &dev->u.cli;
-       struct obd_connect_data *ocd;
+       struct obd_import *imp;
        bool val;
        int rc;
 
@@ -723,22 +733,11 @@ static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
                return rc;
 
        LPROCFS_CLIMP_CHECK(dev);
-       ocd = &cli->cl_import->imp_connect_data;
 
-       if (!val) {
-               if (OCD_HAS_FLAG(ocd, GRANT_SHRINK))
-                       ocd->ocd_connect_flags &= ~OBD_CONNECT_GRANT_SHRINK;
-       } else {
-               /**
-                * server replied obd_connect_data is always bigger, so
-                * client's imp_connect_flags_orig are always supported
-                * by the server
-                */
-               if (!OCD_HAS_FLAG(ocd, GRANT_SHRINK) &&
-                   cli->cl_import->imp_connect_flags_orig &
-                   OBD_CONNECT_GRANT_SHRINK)
-                       ocd->ocd_connect_flags |= OBD_CONNECT_GRANT_SHRINK;
-       }
+       imp = dev->u.cli.cl_import;
+       spin_lock(&imp->imp_lock);
+       imp->imp_grant_shrink_disabled = !val;
+       spin_unlock(&imp->imp_lock);
 
        LPROCFS_CLIMP_EXIT(dev);