Re: [PATCH] SSC: dont fsync() on each written block. Do one single fsync() when file is closed in FILEMARK

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

 



It is fine to not fsync() on write   but we should indicate we do so
by setting the proper "buffered-mode" in the device specific part of
mode sense.


>From SSC :



6.9 WRITE-FILEMARKS(6)
---
NOTE 37 Upon completion of any buffered write operation, the
application client may issue a WRITE
FILEMARKS(6) command with the IMMED bit set to zero and the FILEMARK
COUNT field set to zero to perform a
synchronize operation (see 4.2.10).
---

This indicates that writes may be buffered and to volatile memory only.
But when the WRITE-FILEMARK command is issued, this forces all data to
be written and synchronized to tape
even if the filemark count is zero. So that means we can do the fsync() here.


8.3.1 MODE PARAMETERS OVERVIEW
TABLE 90 - DEVICE-SPECIFIC PARAMETER
---
1h

The device server may report GOOD status on WRITE commands as soon as
  all the data specified in the WRITE command has been transferred to
the logical
 unit’s object buffer. One or more logical blocks may be buffered
prior to writing
  the logical block(s) to the medium.
---
Which means that since we do buffered writes, we should indicate this
to the initiator by setting
BUFFERED-MODE to 1.



So, doing this is fine according to SSC, but we have to indicate that
we do this by setting the buffered-mode to 1h in the mode-sense data.
I have attached an updated patch that both does the "fsync() on
write-filemark" as before but also modifies the mode-sense we send
back from ssc devices to indicate "buffered-mode==1 : we do buffered
writes."



regards
ronnie sahlberg


On Mon, Jan 23, 2012 at 10:01 AM, FUJITA Tomonori
<fujita.tomonori@xxxxxxxxxxxxx> wrote:
> On Sun, 22 Jan 2012 07:59:03 +1100
> ronnie sahlberg <ronniesahlberg@xxxxxxxxx> wrote:
>
>> Thanks Mark,
>>
>> That was my understanding from the SSC spec too, though I am not a tape guy.
>>
>>
>> So, this means that the behaviour in the patch is standards compliant,
>> and also what physical devices do.
>> Destage to physical medium is only guaranteed to be completed once the
>> WRITE-FILEMARK has finished.
>>
>>
>> So we dont need to add any controls to activate/deactivate this new behaviour.
>> We can just apply the current patch as-is  and that is all we need to do.
>
> I'd love the patch, but can anyone give me a pointer in the spec,
> please.
>
>
> Thanks,
From c023168b157f8b2a9f55a339cd245cd6fce04e5e Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
Date: Mon, 23 Jan 2012 12:42:14 +1100
Subject: [PATCH] Update bs_ssc.c to only fsync() on the final WRITE-FILEMARK but not for the individual WRITE6 calls.

Add a specific Mode_sense function for SSC devices so we can force the BUFFERED-MODE in the mode sense data to inidcate that we are doing buffered writes.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
---
 usr/bs_ssc.c |    3 ++-
 usr/ssc.c    |   24 ++++++++++++++++++++++--
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/usr/bs_ssc.c b/usr/bs_ssc.c
index 469057d..f21509c 100644
--- a/usr/bs_ssc.c
+++ b/usr/bs_ssc.c
@@ -189,7 +189,8 @@ static int append_blk(struct scsi_cmd *cmd, uint8_t *data,
 	}
 	/* Write new EOD blk header */
 
-	fsync(fd);
+	if (type == BLK_FILEMARK)
+		fsync(fd);
 
 	return SAM_STAT_GOOD;
 }
diff --git a/usr/ssc.c b/usr/ssc.c
index 94beda1..0c7d240 100644
--- a/usr/ssc.c
+++ b/usr/ssc.c
@@ -51,6 +51,26 @@ static int ssc_mode_page_update(struct scsi_cmd *cmd, uint8_t *data,
 	return 1;
 }
 
+static int ssc_mode_sense(int host_no, struct scsi_cmd *cmd)
+{
+	int ret;
+	uint8_t *data, mode6;
+
+	ret = spc_mode_sense(host_no, cmd);
+
+	mode6 = (cmd->scb[0] == 0x1a);
+	data = scsi_get_in_buffer(cmd);
+
+	/* set the device to report BUFFERED MODE for writes */
+	if (mode6)
+		data[2] |= 0x10;
+	else
+		data[3] |= 0x10;
+
+
+	return ret;
+}
+
 static int ssc_mode_select(int host_no, struct scsi_cmd *cmd)
 {
 	return spc_mode_select(host_no, cmd, ssc_mode_page_update);
@@ -196,7 +216,7 @@ static struct device_type_template ssc_template = {
 
 		{spc_illegal_op,},
 		{spc_illegal_op,},
-		{spc_mode_sense,},
+		{ssc_mode_sense,},
 		{spc_start_stop,},
 		{spc_illegal_op,},
 		{spc_illegal_op,},
@@ -255,7 +275,7 @@ static struct device_type_template ssc_template = {
 
 		{spc_illegal_op,},
 		{spc_illegal_op,},
-		{spc_mode_sense,},
+		{ssc_mode_sense,},
 		{spc_illegal_op,},
 		{spc_illegal_op,},
 		{spc_illegal_op,},
-- 
1.7.3.1

Attachment: 0001-Update-bs_ssc.c-to-only-fsync-on-the-final-WRITE-FIL.patch.gz
Description: GNU Zip compressed data


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux