All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dm writecache: flush metadata in single commit in init_memory
@ 2018-10-24 10:54 Shenghui Wang
  2018-10-24 14:38 ` Mikulas Patocka
  0 siblings, 1 reply; 3+ messages in thread
From: Shenghui Wang @ 2018-10-24 10:54 UTC (permalink / raw)
  To: mpatocka, agk, snitzer, dm-devel

Do not flush sb ->magic in second commit.

Signed-off-by: Shenghui Wang <shhuiw@foxmail.com>
---
 drivers/md/dm-writecache.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index d656bd1799ae..8e9e96a22f68 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -1749,6 +1749,8 @@ static int init_memory(struct dm_writecache *wc)
 
 	for (b = 0; b < ARRAY_SIZE(sb(wc)->padding); b++)
 		pmem_assign(sb(wc)->padding[b], cpu_to_le64(0));
+
+	pmem_assign(sb(wc)->magic, cpu_to_le32(MEMORY_SUPERBLOCK_MAGIC));
 	pmem_assign(sb(wc)->version, cpu_to_le32(MEMORY_SUPERBLOCK_VERSION));
 	pmem_assign(sb(wc)->block_size, cpu_to_le32(wc->block_size));
 	pmem_assign(sb(wc)->n_blocks, cpu_to_le64(wc->n_blocks));
@@ -1759,9 +1761,6 @@ static int init_memory(struct dm_writecache *wc)
 
 	writecache_flush_all_metadata(wc);
 	writecache_commit_flushed(wc);
-	pmem_assign(sb(wc)->magic, cpu_to_le32(MEMORY_SUPERBLOCK_MAGIC));
-	writecache_flush_region(wc, &sb(wc)->magic, sizeof sb(wc)->magic);
-	writecache_commit_flushed(wc);
 
 	return 0;
 }
-- 
2.18.0

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

* Re: [PATCH] dm writecache: flush metadata in single commit in init_memory
  2018-10-24 10:54 [PATCH] dm writecache: flush metadata in single commit in init_memory Shenghui Wang
@ 2018-10-24 14:38 ` Mikulas Patocka
  2018-10-25  0:28   ` shenghui
  0 siblings, 1 reply; 3+ messages in thread
From: Mikulas Patocka @ 2018-10-24 14:38 UTC (permalink / raw)
  To: Shenghui Wang; +Cc: dm-devel, snitzer, agk



On Wed, 24 Oct 2018, Shenghui Wang wrote:

> Do not flush sb ->magic in second commit.

This is intentional. The magic is written last, so that if the machine 
crashes while formatting the device, the incomplete superblock won't be 
misidentified as already formatted.

Mikulas

> Signed-off-by: Shenghui Wang <shhuiw@foxmail.com>
> ---
>  drivers/md/dm-writecache.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
> index d656bd1799ae..8e9e96a22f68 100644
> --- a/drivers/md/dm-writecache.c
> +++ b/drivers/md/dm-writecache.c
> @@ -1749,6 +1749,8 @@ static int init_memory(struct dm_writecache *wc)
>  
>  	for (b = 0; b < ARRAY_SIZE(sb(wc)->padding); b++)
>  		pmem_assign(sb(wc)->padding[b], cpu_to_le64(0));
> +
> +	pmem_assign(sb(wc)->magic, cpu_to_le32(MEMORY_SUPERBLOCK_MAGIC));
>  	pmem_assign(sb(wc)->version, cpu_to_le32(MEMORY_SUPERBLOCK_VERSION));
>  	pmem_assign(sb(wc)->block_size, cpu_to_le32(wc->block_size));
>  	pmem_assign(sb(wc)->n_blocks, cpu_to_le64(wc->n_blocks));
> @@ -1759,9 +1761,6 @@ static int init_memory(struct dm_writecache *wc)
>  
>  	writecache_flush_all_metadata(wc);
>  	writecache_commit_flushed(wc);
> -	pmem_assign(sb(wc)->magic, cpu_to_le32(MEMORY_SUPERBLOCK_MAGIC));
> -	writecache_flush_region(wc, &sb(wc)->magic, sizeof sb(wc)->magic);
> -	writecache_commit_flushed(wc);
>  
>  	return 0;
>  }
> -- 
> 2.18.0
> 
> 
> 

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

* Re: [PATCH] dm writecache: flush metadata in single commit in init_memory
  2018-10-24 14:38 ` Mikulas Patocka
@ 2018-10-25  0:28   ` shenghui
  0 siblings, 0 replies; 3+ messages in thread
From: shenghui @ 2018-10-25  0:28 UTC (permalink / raw)
  To: Mikulas Patocka; +Cc: dm-devel, snitzer, agk



On 10/24/2018 10:38 PM, Mikulas Patocka wrote:
> 
> 
> On Wed, 24 Oct 2018, Shenghui Wang wrote:
> 
>> Do not flush sb ->magic in second commit.
> 
> This is intentional. The magic is written last, so that if the machine 
> crashes while formatting the device, the incomplete superblock won't be 
> misidentified as already formatted.
> 
> Mikulas

Got it. Thanks,

-
shenghui

> 
>> Signed-off-by: Shenghui Wang <shhuiw@foxmail.com>
>> ---
>>  drivers/md/dm-writecache.c | 5 ++---
>>  1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
>> index d656bd1799ae..8e9e96a22f68 100644
>> --- a/drivers/md/dm-writecache.c
>> +++ b/drivers/md/dm-writecache.c
>> @@ -1749,6 +1749,8 @@ static int init_memory(struct dm_writecache *wc)
>>  
>>  	for (b = 0; b < ARRAY_SIZE(sb(wc)->padding); b++)
>>  		pmem_assign(sb(wc)->padding[b], cpu_to_le64(0));
>> +
>> +	pmem_assign(sb(wc)->magic, cpu_to_le32(MEMORY_SUPERBLOCK_MAGIC));
>>  	pmem_assign(sb(wc)->version, cpu_to_le32(MEMORY_SUPERBLOCK_VERSION));
>>  	pmem_assign(sb(wc)->block_size, cpu_to_le32(wc->block_size));
>>  	pmem_assign(sb(wc)->n_blocks, cpu_to_le64(wc->n_blocks));
>> @@ -1759,9 +1761,6 @@ static int init_memory(struct dm_writecache *wc)
>>  
>>  	writecache_flush_all_metadata(wc);
>>  	writecache_commit_flushed(wc);
>> -	pmem_assign(sb(wc)->magic, cpu_to_le32(MEMORY_SUPERBLOCK_MAGIC));
>> -	writecache_flush_region(wc, &sb(wc)->magic, sizeof sb(wc)->magic);
>> -	writecache_commit_flushed(wc);
>>  
>>  	return 0;
>>  }
>> -- 
>> 2.18.0
>>
>>
>>
> 
> 

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

end of thread, other threads:[~2018-10-25  0:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-24 10:54 [PATCH] dm writecache: flush metadata in single commit in init_memory Shenghui Wang
2018-10-24 14:38 ` Mikulas Patocka
2018-10-25  0:28   ` shenghui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.