Re: [PATCH v7 3/5] btrfs: create read policy sysfs attribute, pid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19/5/20 6:07 pm, Johannes Thumshirn wrote:
On 06/04/2020 13:51, Anand Jain wrote:
+static ssize_t btrfs_read_policy_store(struct kobject *kobj,
+				       struct kobj_attribute *a,
+				       const char *buf, size_t len)
+{
+	int i;
+	struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj);
+
+	for (i = 0; i < BTRFS_NR_READ_POLICY; i++) {
+		if (btrfs_strmatch(buf, btrfs_read_policy_name[i]) == 0) {
+			if (i != fs_devices->read_policy) {
+				fs_devices->read_policy = i;
+				btrfs_info(fs_devices->fs_info,
+					   "read policy set to '%s'",
+					   btrfs_read_policy_name[i]);
+			}
+			return len;
+		}
+	}

Naive question, what's the advantage over sysfs_match_string()?

We strip both leading and trailing whitespaces, its not
possible to do the same with sysfs_match_string().

For example:
echo ==== These should pass ======
run_nocheck "echo ' pid' > $sysfs_path/read_policy"
run_nocheck "echo ' pid ' > $sysfs_path/read_policy"
run_nocheck "echo -n ' pid ' > $sysfs_path/read_policy"
run_nocheck "echo -n ' pid' > $sysfs_path/read_policy"
run_nocheck "echo 'pid ' > $sysfs_path/read_policy"
run_nocheck "echo -n 'pid ' > $sysfs_path/read_policy"
run_nocheck "echo -n pid > $sysfs_path/read_policy"
run_nocheck "echo pid > $sysfs_path/read_policy"

Thanks, Anand



[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux