[stgt] [PATCH] 1/1 Honour media capacity
Mark Harvey
markh794 at gmail.com
Tue Oct 13 21:44:02 CEST 2009
>From 8838e603da133001d3284f0ee1f0a6c71f906d09 Mon Sep 17 00:00:00 2001
From: Mark Harvey <markh794 at gmail.com>
Date: Tue, 13 Oct 2009 18:36:15 +1100
Subject: Honour media capacity.
Return NO_SENSE with 'EOM' set once 'media capacity' number of bytes
written to backing store file.
Signed-off-by: Mark Harvey <markh794 at gmail.com>
---
usr/bs_ssc.c | 23 +++++++++++++++++++++--
1 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/usr/bs_ssc.c b/usr/bs_ssc.c
index ce5c3bf..b2ad7c7 100644
--- a/usr/bs_ssc.c
+++ b/usr/bs_ssc.c
@@ -40,6 +40,12 @@
#include "ssc.h"
#include "libssc.h"
+#define SENSE_FILEMARK 0x80
+#define SENSE_EOM 0x40
+#define SENSE_ILI 0X20
+
+static uint64_t media_capacity;
+
static void ssc_sense_data_build(struct scsi_cmd *cmd, uint8_t key,
uint16_t asc, uint8_t *info, int info_len)
{
@@ -109,6 +115,12 @@ static int resp_rewind(struct scsi_lu *lu)
return skip_next_header(lu);
}
+static unsigned long current_size(struct scsi_cmd *cmd)
+{
+ struct ssc_info *ssc = dtype_priv(cmd->dev);
+ return ssc->c_blk.curr;
+}
+
static int append_blk(struct scsi_cmd *cmd, uint8_t *data,
int size, int orig_sz, int type)
{
@@ -184,8 +196,6 @@ static int append_blk(struct scsi_cmd *cmd, uint8_t *data,
return SAM_STAT_GOOD;
}
-#define SENSE_FILEMARK 0x80
-
static int space_filemark_reverse(struct scsi_cmd *cmd, int32_t count)
{
struct ssc_info *ssc = dtype_priv(cmd->dev);
@@ -515,6 +525,14 @@ static void tape_rdwr_request(struct scsi_cmd *cmd)
count, length, ret, (fixed) ? "Yes" : "No",
block_length);
+ /* Check for end of media */
+ if (current_size(cmd) > media_capacity) {
+ sense_data_build(cmd, NO_SENSE|SENSE_EOM,
+ NO_ADDITIONAL_SENSE);
+ result = SAM_STAT_CHECK_CONDITION;
+ break;
+ }
+
if (ret != length) {
sense_data_build(cmd, MEDIUM_ERROR, ASC_WRITE_ERROR);
result = SAM_STAT_CHECK_CONDITION;
@@ -630,6 +648,7 @@ static int bs_ssc_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)
eprintf("Failed to read MAM: %d %m\n", (int)rd);
return -1;
}
+ media_capacity = ssc->mam.max_capacity;
rd = ssc_read_blkhdr(*fd, h, h->next);
if (rd) {
--
1.6.0.4
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list