Skip to contentSkip to conversation

add label interface for cache device in sysfs

PATCH In review Dongbo Cao 2 participants 2 messages Sep 14, 2018 bcache (block layer cache)

lore
Share & tools
lore

Dongbo Cao

author
#0 lore raw

PATCH 1/1 add label interface for cache device in sysfs

label interface will be called by bcache tools in user space.

---
 drivers/md/bcache/sysfs.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/md/bcache/sysfs.c +19 -0
index 225b15aa..e64c718f 100644
@@ -950,6 +950,13 @@ SHOW(__bch_cache)
 		return ret;
 	}
 
+	if (attr == &sysfs_label) {
+		memcpy(buf, ca->sb.label, SB_LABEL_SIZE);
+		buf[SB_LABEL_SIZE + 1] = '\0';
+		strcat(buf, "\n");
+		return strlen(buf);
+	}
+
 	return 0;
 }
 SHOW_LOCKED(bch_cache)
@@ -993,6 +1000,17 @@ STORE(__bch_cache)
 		atomic_set(&ca->io_errors, 0);
 	}
 
+	if (attr == &sysfs_label) {
+		if (size > SB_LABEL_SIZE)
+			return -EINVAL;
+		memcpy(ca->sb.label, buf, size);
+		if (size < SB_LABEL_SIZE)
+			ca->sb.label[size] = '\0';
+		if (size && ca->sb.label[size - 1] == '\n')
+			ca->sb.label[size - 1] = '\0';
+		bcache_write_super(ca->set);
+	}
+
 	return size;
 }
 STORE_LOCKED(bch_cache)
@@ -1009,6 +1027,7 @@ static struct attribute *bch_cache_files[] = {
 	&sysfs_io_errors,
 	&sysfs_clear_stats,
 	&sysfs_cache_replacement_policy,
+	&sysfs_label,
 	NULL
 };
 KTYPE(bch_cache);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Dongbo Cao

label interface will be called by bcache tools in user space.

Hi Dongbo,

In your change I see you set superblock label to cache set. What is the use case for doing this ?

Thanks.

Coly Li

Quoted 48 lines
---
  drivers/md/bcache/sysfs.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
drivers/md/bcache/sysfs.c +19 -0
index 225b15aa..e64c718f 100644
@@ -950,6 +950,13 @@ SHOW(__bch_cache)
  		return ret;
  	}
 
+	if (attr == &sysfs_label) {
+		memcpy(buf, ca->sb.label, SB_LABEL_SIZE);
+		buf[SB_LABEL_SIZE + 1] = '\0';
+		strcat(buf, "\n");
+		return strlen(buf);
+	}
+
  	return 0;
  }
  SHOW_LOCKED(bch_cache)
@@ -993,6 +1000,17 @@ STORE(__bch_cache)
  		atomic_set(&ca->io_errors, 0);
  	}
 
+	if (attr == &sysfs_label) {
+		if (size > SB_LABEL_SIZE)
+			return -EINVAL;
+		memcpy(ca->sb.label, buf, size);
+		if (size < SB_LABEL_SIZE)
+			ca->sb.label[size] = '\0';
+		if (size && ca->sb.label[size - 1] == '\n')
+			ca->sb.label[size - 1] = '\0';
+		bcache_write_super(ca->set);
+	}
+
  	return size;
  }
  STORE_LOCKED(bch_cache)
@@ -1009,6 +1027,7 @@ static struct attribute *bch_cache_files[] = {
  	&sysfs_io_errors,
  	&sysfs_clear_stats,
  	&sysfs_cache_replacement_policy,
+	&sysfs_label,
  	NULL
  };
  KTYPE(bch_cache);