diff mbox series

[v2] lightnvm: pblk: Switch to use new generic UUID API

Message ID 20190124143137.13880-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v2] lightnvm: pblk: Switch to use new generic UUID API | expand

Commit Message

Andy Shevchenko Jan. 24, 2019, 2:31 p.m. UTC
There are new types and helpers that are supposed to be used in new code.

As a preparation to get rid of legacy types and API functions do
the conversion here.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---

v2:
- convert instance_uuid to guid_t and get rid of pblk_setup_uuid()
- fix subject line to show subsystem

 drivers/lightnvm/pblk-core.c     |  4 ++--
 drivers/lightnvm/pblk-init.c     |  2 +-
 drivers/lightnvm/pblk-recovery.c |  8 +++++---
 drivers/lightnvm/pblk.h          | 10 +---------
 4 files changed, 9 insertions(+), 15 deletions(-)

Comments

Javier González Jan. 24, 2019, 2:48 p.m. UTC | #1
> On 24 Jan 2019, at 15.31, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> There are new types and helpers that are supposed to be used in new code.
> 
> As a preparation to get rid of legacy types and API functions do
> the conversion here.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> 
> v2:
> - convert instance_uuid to guid_t and get rid of pblk_setup_uuid()
> - fix subject line to show subsystem
> 
> drivers/lightnvm/pblk-core.c     |  4 ++--
> drivers/lightnvm/pblk-init.c     |  2 +-
> drivers/lightnvm/pblk-recovery.c |  8 +++++---
> drivers/lightnvm/pblk.h          | 10 +---------
> 4 files changed, 9 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c
> index 1ff165351180..189339965957 100644
> --- a/drivers/lightnvm/pblk-core.c
> +++ b/drivers/lightnvm/pblk-core.c
> @@ -1065,7 +1065,7 @@ static int pblk_line_init_metadata(struct pblk *pblk, struct pblk_line *line,
> 	bitmap_set(line->lun_bitmap, 0, lm->lun_bitmap_len);
> 
> 	smeta_buf->header.identifier = cpu_to_le32(PBLK_MAGIC);
> -	memcpy(smeta_buf->header.uuid, pblk->instance_uuid, 16);
> +	guid_copy((guid_t *)&smeta_buf->header.uuid, &pblk->instance_uuid);
> 	smeta_buf->header.id = cpu_to_le32(line->id);
> 	smeta_buf->header.type = cpu_to_le16(line->type);
> 	smeta_buf->header.version_major = SMETA_VERSION_MAJOR;
> @@ -1874,7 +1874,7 @@ void pblk_line_close_meta(struct pblk *pblk, struct pblk_line *line)
> 
> 	if (le32_to_cpu(emeta_buf->header.identifier) != PBLK_MAGIC) {
> 		emeta_buf->header.identifier = cpu_to_le32(PBLK_MAGIC);
> -		memcpy(emeta_buf->header.uuid, pblk->instance_uuid, 16);
> +		guid_copy((guid_t *)&emeta_buf->header.uuid, &pblk->instance_uuid);
> 		emeta_buf->header.id = cpu_to_le32(line->id);
> 		emeta_buf->header.type = cpu_to_le16(line->type);
> 		emeta_buf->header.version_major = EMETA_VERSION_MAJOR;
> diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
> index f9a3e47b6a93..5768333d103f 100644
> --- a/drivers/lightnvm/pblk-init.c
> +++ b/drivers/lightnvm/pblk-init.c
> @@ -130,7 +130,7 @@ static int pblk_l2p_recover(struct pblk *pblk, bool factory_init)
> 	struct pblk_line *line = NULL;
> 
> 	if (factory_init) {
> -		pblk_setup_uuid(pblk);
> +		guid_gen(&pblk->instance_uuid);
> 	} else {
> 		line = pblk_recov_l2p(pblk);
> 		if (IS_ERR(line)) {
> diff --git a/drivers/lightnvm/pblk-recovery.c b/drivers/lightnvm/pblk-recovery.c
> index 5ee20da7bdb3..6761d2afa4d0 100644
> --- a/drivers/lightnvm/pblk-recovery.c
> +++ b/drivers/lightnvm/pblk-recovery.c
> @@ -703,11 +703,13 @@ struct pblk_line *pblk_recov_l2p(struct pblk *pblk)
> 
> 		/* The first valid instance uuid is used for initialization */
> 		if (!valid_uuid) {
> -			memcpy(pblk->instance_uuid, smeta_buf->header.uuid, 16);
> +			guid_copy(&pblk->instance_uuid,
> +				  (guid_t *)&smeta_buf->header.uuid);
> 			valid_uuid = 1;
> 		}
> 
> -		if (memcmp(pblk->instance_uuid, smeta_buf->header.uuid, 16)) {
> +		if (!guid_equal(&pblk->instance_uuid,
> +				(guid_t *)&smeta_buf->header.uuid)) {
> 			pblk_debug(pblk, "ignore line %u due to uuid mismatch\n",
> 					i);
> 			continue;
> @@ -737,7 +739,7 @@ struct pblk_line *pblk_recov_l2p(struct pblk *pblk)
> 	}
> 
> 	if (!found_lines) {
> -		pblk_setup_uuid(pblk);
> +		guid_gen(&pblk->instance_uuid);
> 
> 		spin_lock(&l_mg->free_lock);
> 		WARN_ON_ONCE(!test_and_clear_bit(meta_line,
> diff --git a/drivers/lightnvm/pblk.h b/drivers/lightnvm/pblk.h
> index 85e38ed62f85..12bf02df4204 100644
> --- a/drivers/lightnvm/pblk.h
> +++ b/drivers/lightnvm/pblk.h
> @@ -646,7 +646,7 @@ struct pblk {
> 
> 	int sec_per_write;
> 
> -	unsigned char instance_uuid[16];
> +	guid_t instance_uuid;
> 
> 	/* Persistent write amplification counters, 4kb sector I/Os */
> 	atomic64_t user_wa;		/* Sectors written by user */
> @@ -1360,14 +1360,6 @@ static inline unsigned int pblk_get_secs(struct bio *bio)
> 	return  bio->bi_iter.bi_size / PBLK_EXPOSED_PAGE_SIZE;
> }
> 
> -static inline void pblk_setup_uuid(struct pblk *pblk)
> -{
> -	uuid_le uuid;
> -
> -	uuid_le_gen(&uuid);
> -	memcpy(pblk->instance_uuid, uuid.b, 16);
> -}
> -
> static inline char *pblk_disk_name(struct pblk *pblk)
> {
> 	struct gendisk *disk = pblk->disk;
> --
> 2.20.1

Looks good to me. Thanks Andy.


Reviewed-by: Javier González <javier@javigon.com>
Matias Bjorling Jan. 24, 2019, 6:18 p.m. UTC | #2
On 1/24/19 3:31 PM, Andy Shevchenko wrote:
> There are new types and helpers that are supposed to be used in new code.
> 
> As a preparation to get rid of legacy types and API functions do
> the conversion here.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> 
> v2:
> - convert instance_uuid to guid_t and get rid of pblk_setup_uuid()
> - fix subject line to show subsystem
> 
>   drivers/lightnvm/pblk-core.c     |  4 ++--
>   drivers/lightnvm/pblk-init.c     |  2 +-
>   drivers/lightnvm/pblk-recovery.c |  8 +++++---
>   drivers/lightnvm/pblk.h          | 10 +---------
>   4 files changed, 9 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c
> index 1ff165351180..189339965957 100644
> --- a/drivers/lightnvm/pblk-core.c
> +++ b/drivers/lightnvm/pblk-core.c
> @@ -1065,7 +1065,7 @@ static int pblk_line_init_metadata(struct pblk *pblk, struct pblk_line *line,
>   	bitmap_set(line->lun_bitmap, 0, lm->lun_bitmap_len);
>   
>   	smeta_buf->header.identifier = cpu_to_le32(PBLK_MAGIC);
> -	memcpy(smeta_buf->header.uuid, pblk->instance_uuid, 16);
> +	guid_copy((guid_t *)&smeta_buf->header.uuid, &pblk->instance_uuid);
>   	smeta_buf->header.id = cpu_to_le32(line->id);
>   	smeta_buf->header.type = cpu_to_le16(line->type);
>   	smeta_buf->header.version_major = SMETA_VERSION_MAJOR;
> @@ -1874,7 +1874,7 @@ void pblk_line_close_meta(struct pblk *pblk, struct pblk_line *line)
>   
>   	if (le32_to_cpu(emeta_buf->header.identifier) != PBLK_MAGIC) {
>   		emeta_buf->header.identifier = cpu_to_le32(PBLK_MAGIC);
> -		memcpy(emeta_buf->header.uuid, pblk->instance_uuid, 16);
> +		guid_copy((guid_t *)&emeta_buf->header.uuid, &pblk->instance_uuid);
>   		emeta_buf->header.id = cpu_to_le32(line->id);
>   		emeta_buf->header.type = cpu_to_le16(line->type);
>   		emeta_buf->header.version_major = EMETA_VERSION_MAJOR;
> diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
> index f9a3e47b6a93..5768333d103f 100644
> --- a/drivers/lightnvm/pblk-init.c
> +++ b/drivers/lightnvm/pblk-init.c
> @@ -130,7 +130,7 @@ static int pblk_l2p_recover(struct pblk *pblk, bool factory_init)
>   	struct pblk_line *line = NULL;
>   
>   	if (factory_init) {
> -		pblk_setup_uuid(pblk);
> +		guid_gen(&pblk->instance_uuid);
>   	} else {
>   		line = pblk_recov_l2p(pblk);
>   		if (IS_ERR(line)) {
> diff --git a/drivers/lightnvm/pblk-recovery.c b/drivers/lightnvm/pblk-recovery.c
> index 5ee20da7bdb3..6761d2afa4d0 100644
> --- a/drivers/lightnvm/pblk-recovery.c
> +++ b/drivers/lightnvm/pblk-recovery.c
> @@ -703,11 +703,13 @@ struct pblk_line *pblk_recov_l2p(struct pblk *pblk)
>   
>   		/* The first valid instance uuid is used for initialization */
>   		if (!valid_uuid) {
> -			memcpy(pblk->instance_uuid, smeta_buf->header.uuid, 16);
> +			guid_copy(&pblk->instance_uuid,
> +				  (guid_t *)&smeta_buf->header.uuid);
>   			valid_uuid = 1;
>   		}
>   
> -		if (memcmp(pblk->instance_uuid, smeta_buf->header.uuid, 16)) {
> +		if (!guid_equal(&pblk->instance_uuid,
> +				(guid_t *)&smeta_buf->header.uuid)) {
>   			pblk_debug(pblk, "ignore line %u due to uuid mismatch\n",
>   					i);
>   			continue;
> @@ -737,7 +739,7 @@ struct pblk_line *pblk_recov_l2p(struct pblk *pblk)
>   	}
>   
>   	if (!found_lines) {
> -		pblk_setup_uuid(pblk);
> +		guid_gen(&pblk->instance_uuid);
>   
>   		spin_lock(&l_mg->free_lock);
>   		WARN_ON_ONCE(!test_and_clear_bit(meta_line,
> diff --git a/drivers/lightnvm/pblk.h b/drivers/lightnvm/pblk.h
> index 85e38ed62f85..12bf02df4204 100644
> --- a/drivers/lightnvm/pblk.h
> +++ b/drivers/lightnvm/pblk.h
> @@ -646,7 +646,7 @@ struct pblk {
>   
>   	int sec_per_write;
>   
> -	unsigned char instance_uuid[16];
> +	guid_t instance_uuid;
>   
>   	/* Persistent write amplification counters, 4kb sector I/Os */
>   	atomic64_t user_wa;		/* Sectors written by user */
> @@ -1360,14 +1360,6 @@ static inline unsigned int pblk_get_secs(struct bio *bio)
>   	return  bio->bi_iter.bi_size / PBLK_EXPOSED_PAGE_SIZE;
>   }
>   
> -static inline void pblk_setup_uuid(struct pblk *pblk)
> -{
> -	uuid_le uuid;
> -
> -	uuid_le_gen(&uuid);
> -	memcpy(pblk->instance_uuid, uuid.b, 16);
> -}
> -
>   static inline char *pblk_disk_name(struct pblk *pblk)
>   {
>   	struct gendisk *disk = pblk->disk;
> 

Thanks Andy. I've applied it for 5.1.
diff mbox series

Patch

diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c
index 1ff165351180..189339965957 100644
--- a/drivers/lightnvm/pblk-core.c
+++ b/drivers/lightnvm/pblk-core.c
@@ -1065,7 +1065,7 @@  static int pblk_line_init_metadata(struct pblk *pblk, struct pblk_line *line,
 	bitmap_set(line->lun_bitmap, 0, lm->lun_bitmap_len);
 
 	smeta_buf->header.identifier = cpu_to_le32(PBLK_MAGIC);
-	memcpy(smeta_buf->header.uuid, pblk->instance_uuid, 16);
+	guid_copy((guid_t *)&smeta_buf->header.uuid, &pblk->instance_uuid);
 	smeta_buf->header.id = cpu_to_le32(line->id);
 	smeta_buf->header.type = cpu_to_le16(line->type);
 	smeta_buf->header.version_major = SMETA_VERSION_MAJOR;
@@ -1874,7 +1874,7 @@  void pblk_line_close_meta(struct pblk *pblk, struct pblk_line *line)
 
 	if (le32_to_cpu(emeta_buf->header.identifier) != PBLK_MAGIC) {
 		emeta_buf->header.identifier = cpu_to_le32(PBLK_MAGIC);
-		memcpy(emeta_buf->header.uuid, pblk->instance_uuid, 16);
+		guid_copy((guid_t *)&emeta_buf->header.uuid, &pblk->instance_uuid);
 		emeta_buf->header.id = cpu_to_le32(line->id);
 		emeta_buf->header.type = cpu_to_le16(line->type);
 		emeta_buf->header.version_major = EMETA_VERSION_MAJOR;
diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index f9a3e47b6a93..5768333d103f 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -130,7 +130,7 @@  static int pblk_l2p_recover(struct pblk *pblk, bool factory_init)
 	struct pblk_line *line = NULL;
 
 	if (factory_init) {
-		pblk_setup_uuid(pblk);
+		guid_gen(&pblk->instance_uuid);
 	} else {
 		line = pblk_recov_l2p(pblk);
 		if (IS_ERR(line)) {
diff --git a/drivers/lightnvm/pblk-recovery.c b/drivers/lightnvm/pblk-recovery.c
index 5ee20da7bdb3..6761d2afa4d0 100644
--- a/drivers/lightnvm/pblk-recovery.c
+++ b/drivers/lightnvm/pblk-recovery.c
@@ -703,11 +703,13 @@  struct pblk_line *pblk_recov_l2p(struct pblk *pblk)
 
 		/* The first valid instance uuid is used for initialization */
 		if (!valid_uuid) {
-			memcpy(pblk->instance_uuid, smeta_buf->header.uuid, 16);
+			guid_copy(&pblk->instance_uuid,
+				  (guid_t *)&smeta_buf->header.uuid);
 			valid_uuid = 1;
 		}
 
-		if (memcmp(pblk->instance_uuid, smeta_buf->header.uuid, 16)) {
+		if (!guid_equal(&pblk->instance_uuid,
+				(guid_t *)&smeta_buf->header.uuid)) {
 			pblk_debug(pblk, "ignore line %u due to uuid mismatch\n",
 					i);
 			continue;
@@ -737,7 +739,7 @@  struct pblk_line *pblk_recov_l2p(struct pblk *pblk)
 	}
 
 	if (!found_lines) {
-		pblk_setup_uuid(pblk);
+		guid_gen(&pblk->instance_uuid);
 
 		spin_lock(&l_mg->free_lock);
 		WARN_ON_ONCE(!test_and_clear_bit(meta_line,
diff --git a/drivers/lightnvm/pblk.h b/drivers/lightnvm/pblk.h
index 85e38ed62f85..12bf02df4204 100644
--- a/drivers/lightnvm/pblk.h
+++ b/drivers/lightnvm/pblk.h
@@ -646,7 +646,7 @@  struct pblk {
 
 	int sec_per_write;
 
-	unsigned char instance_uuid[16];
+	guid_t instance_uuid;
 
 	/* Persistent write amplification counters, 4kb sector I/Os */
 	atomic64_t user_wa;		/* Sectors written by user */
@@ -1360,14 +1360,6 @@  static inline unsigned int pblk_get_secs(struct bio *bio)
 	return  bio->bi_iter.bi_size / PBLK_EXPOSED_PAGE_SIZE;
 }
 
-static inline void pblk_setup_uuid(struct pblk *pblk)
-{
-	uuid_le uuid;
-
-	uuid_le_gen(&uuid);
-	memcpy(pblk->instance_uuid, uuid.b, 16);
-}
-
 static inline char *pblk_disk_name(struct pblk *pblk)
 {
 	struct gendisk *disk = pblk->disk;