LKML Archive on lore.kernel.org
 help / Atom feed
* [PATCH] add label interface for cache device in sysfs
@ 2018-09-14  9:51 Dongbo Cao
  2018-09-14 10:00 ` Coly Li
  0 siblings, 1 reply; 2+ messages in thread
From: Dongbo Cao @ 2018-09-14  9:51 UTC (permalink / raw)
  To: colyli; +Cc: kent.overstreet, linux-bcache, linux-kernel, Dongbo Cao

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

Signed-off-by: Dongbo Cao <cdbdyx@163.com>
---
 drivers/md/bcache/sysfs.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index 225b15aa..e64c718f 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -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);
-- 
2.17.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] add label interface for cache device in sysfs
  2018-09-14  9:51 [PATCH] add label interface for cache device in sysfs Dongbo Cao
@ 2018-09-14 10:00 ` Coly Li
  0 siblings, 0 replies; 2+ messages in thread
From: Coly Li @ 2018-09-14 10:00 UTC (permalink / raw)
  To: Dongbo Cao; +Cc: kent.overstreet, linux-bcache, linux-kernel


On 9/14/18 5:51 PM, Dongbo Cao wrote:
> label interface will be called by bcache tools in user space.
>
> Signed-off-by: Dongbo Cao <cdbdyx@163.com>

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


> ---
>   drivers/md/bcache/sysfs.c | 19 +++++++++++++++++++
>   1 file changed, 19 insertions(+)
>
> diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
> index 225b15aa..e64c718f 100644
> --- a/drivers/md/bcache/sysfs.c
> +++ b/drivers/md/bcache/sysfs.c
> @@ -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);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-14  9:51 [PATCH] add label interface for cache device in sysfs Dongbo Cao
2018-09-14 10:00 ` Coly Li

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox