All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kai Makisara <Kai.Makisara@kolumbus.fi>
To: "Seymour, Shane M" <shane.seymour@hpe.com>
Cc: Laurence Oberman <loberman@redhat.com>,
	Emmanuel Florac <eflorac@intellique.com>,
	Laurence Oberman <oberman.l@gmail.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>
Subject: RE: What partition should the MTMKPART argument specify? Was: Re: st driver doesn't seem to grok LTO partitioning
Date: Fri, 29 Jan 2016 19:22:14 +0200 (EET)	[thread overview]
Message-ID: <alpine.LSU.2.11.1601291915010.22105@xnv.znxvfnen.cevingr> (raw)
In-Reply-To: <DDB9C85B850785449757F9914A034FCB44523469@G9W0766.americas.hpqcorp.net>

[-- Attachment #1: Type: text/plain, Size: 9161 bytes --]

On Friday 2016-01-29 01:12, Seymour, Shane M wrote:

>Date: Fri, 29 Jan 2016 01:12:41
>From: "Seymour, Shane M" <shane.seymour@hpe.com>
>To: "\"Kai Mäkisara (Kolumbus)\"" <kai.makisara@kolumbus.fi>
>Cc: Laurence Oberman <loberman@redhat.com>,
>    Emmanuel Florac <eflorac@intellique.com>,
>    Laurence Oberman <oberman.l@gmail.com>,
>    "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>
>Subject: RE: What partition should the MTMKPART argument specify? Was: Re: st
>    driver doesn't seem to grok LTO partitioning
>
>Hi Kai,
>
>$ pwd
>/sys/class/scsi_tape/st1/device
>$ cat scsi_level
>4
>
OK. The previous patch set the number of partition size descriptors to 
one for HP DATs only if the SCSI level was <= SCSI_2.

The patch below uses that logic for all drives that don't need FORMAT 
MEDIUM. For the drives needing FORMAT MEDIUM the value is set to 2. 
These drives include LTOs and other modern drives.

Thanks, Kai
---------------------------------8<----------------------------------
--- ref/drivers/scsi/st.c	2015-12-21 18:54:05.068882001 +0200
+++ new/drivers/scsi/st.c	2016-01-29 19:12:06.139738037 +0200
@@ -9,7 +9,7 @@
    Steve Hirsch, Andreas Koppenh"ofer, Michael Leodolter, Eyal Lebedinsky,
    Michael Schaefer, J"org Weule, and Eric Youngdale.
 
-   Copyright 1992 - 2010 Kai Makisara
+   Copyright 1992 - 2016 Kai Makisara
    email Kai.Makisara@kolumbus.fi
 
    Some small formal changes - aeb, 950809
@@ -17,7 +17,7 @@
    Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support
  */
 
-static const char *verstr = "20101219";
+static const char *verstr = "20160129";
 
 #include <linux/module.h>
 
@@ -3296,7 +3296,10 @@
 #define PP_OFF_RESERVED        7
 
 #define PP_BIT_IDP             0x20
+#define PP_BIT_FDP             0x80
 #define PP_MSK_PSUM_MB         0x10
+#define PP_MSK_PSUM_UNITS      0x18
+#define PP_MSK_POFM            0x04
 
 /* Get the number of partitions on the tape. As a side effect reads the
    mode page into the tape buffer. */
@@ -3322,6 +3325,29 @@
 }
 
 
+static int format_medium(struct scsi_tape *STp, int format)
+{
+	int result = 0;
+	int timeout = STp->long_timeout;
+	unsigned char scmd[MAX_COMMAND_SIZE];
+	struct st_request *SRpnt;
+
+	memset(scmd, 0, MAX_COMMAND_SIZE);
+	scmd[0] = FORMAT_UNIT;
+	scmd[2] = format;
+	if (STp->immediate) {
+		scmd[1] |= 1;		/* Don't wait for completion */
+		timeout = STp->device->request_queue->rq_timeout;
+	}
+	DEBC_printk(STp, "Sending FORMAT MEDIUM\n");
+	SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE,
+			   timeout, MAX_RETRIES, 1);
+	if (!SRpnt)
+		result = STp->buffer->syscall_result;
+	return result;
+}
+
+
 /* Partition the tape into two partitions if size > 0 or one partition if
    size == 0.
 
@@ -3340,11 +3366,16 @@
    and 10 when 1 partition is defined (information from Eric Lee Green). This is
    is acceptable also to some other old drives and enforced if the first partition
    size field is used for the first additional partition size.
+
+   For drives that advertize SCSI-3 or newer, use the SSC-3 methods.
  */
 static int partition_tape(struct scsi_tape *STp, int size)
 {
 	int result;
+	int target_partition;
+	bool scsi3 = STp->device->scsi_level >= SCSI_3, needs_format = false;
 	int pgo, psd_cnt, psdo;
+	int psum = PP_MSK_PSUM_MB, units = 0;
 	unsigned char *bp;
 
 	result = read_mode_page(STp, PART_PAGE, 0);
@@ -3352,16 +3383,72 @@
 		DEBC_printk(STp, "Can't read partition mode page.\n");
 		return result;
 	}
+	target_partition = 1;
+	if (size < 0) {
+		target_partition = 0;
+		size = -size;
+	}
+
 	/* The mode page is in the buffer. Let's modify it and write it. */
 	bp = (STp->buffer)->b_data;
 	pgo = MODE_HEADER_LENGTH + bp[MH_OFF_BDESCS_LENGTH];
 	DEBC_printk(STp, "Partition page length is %d bytes.\n",
 		    bp[pgo + MP_OFF_PAGE_LENGTH] + 2);
+	DEBC_printk(STp, "PP: max %u, add %u, xdp %u, psum %02x, pofmetc %u, "
+		    "rec %02x, units %02x, sizes: %u %u\n",
+		    bp[pgo + PP_OFF_MAX_ADD_PARTS],
+		    bp[pgo + PP_OFF_NBR_ADD_PARTS],
+		    (bp[pgo + PP_OFF_FLAGS] & 0xe0) >> 5,
+		    (bp[pgo + PP_OFF_FLAGS] & 0x18) >> 3,
+		    bp[pgo + PP_OFF_FLAGS] & 0x07,
+		    bp[pgo + 5],
+		    bp[pgo + PP_OFF_PART_UNITS],
+		    bp[pgo + 8] * 256 + bp[pgo + 9],
+		    bp[pgo + 10] * 256 + bp[pgo + 11]);
+	DEBC_printk(STp, "MP: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+		    bp[pgo], bp[pgo+1], bp[pgo+2], bp[pgo+3], bp[pgo+4], bp[pgo+5],
+		    bp[pgo+6], bp[pgo+7], bp[pgo+8], bp[pgo+9], bp[pgo+10], bp[pgo+11]);
 
 	psd_cnt = (bp[pgo + MP_OFF_PAGE_LENGTH] + 2 - PART_PAGE_FIXED_LENGTH) / 2;
+
+	if (scsi3) {
+		needs_format = (bp[pgo + PP_OFF_FLAGS] & PP_MSK_POFM) != 0;
+		if (needs_format && size == 0) {
+			/* No need to write the mode page when clearing partitioning */
+			result = format_medium(STp, 0);
+			goto out;
+		}
+		if (needs_format)  /* Leave the old value for HP DATs claiming SCSI_3 */
+			psd_cnt = 2;
+		if ((bp[pgo + PP_OFF_FLAGS] & PP_MSK_PSUM_UNITS) == PP_MSK_PSUM_UNITS) {
+			/* Use units scaling for large partitions if the device suggests
+			   it and no precision lost. Required for IBM TS1140/50 drives
+			   that don't support MB units. */
+			if (size >= 1000 && (size % 1000) == 0) {
+				size /= 1000;
+				psum = PP_MSK_PSUM_UNITS;
+				units = 9; /* GB */
+			}
+		}
+		/* Try it anyway if too large to specify in MB */
+		if (psum == PP_MSK_PSUM_MB && size >= 65534) {
+				size /= 1000;
+				psum = PP_MSK_PSUM_UNITS;
+				units = 9;  /* GB */
+		}
+	}
+
+	if (size >= 65535 ||  /* Does not fit into two bytes */
+	    (target_partition == 0 && psd_cnt < 2)) {
+		result = -EINVAL;
+		goto out;
+	}
+
 	psdo = pgo + PART_PAGE_FIXED_LENGTH;
-	if (psd_cnt > bp[pgo + PP_OFF_MAX_ADD_PARTS]) {
-		bp[psdo] = bp[psdo + 1] = 0xff;  /* Rest of the tape */
+	/* The second condition is for HP DDS which use only one partition size
+	   descriptor */
+	if (target_partition > 0 && psd_cnt > bp[pgo + PP_OFF_MAX_ADD_PARTS]) {
+		bp[psdo] = bp[psdo + 1] = 0xff;  /* Rest of the tape to partition 0 */
 		psdo += 2;
 	}
 	memset(bp + psdo, 0, bp[pgo + PP_OFF_NBR_ADD_PARTS] * 2);
@@ -3370,7 +3457,7 @@
 		    psd_cnt, bp[pgo + PP_OFF_MAX_ADD_PARTS],
 		    bp[pgo + PP_OFF_NBR_ADD_PARTS]);
 
-	if (size <= 0) {
+	if (size == 0) {
 		bp[pgo + PP_OFF_NBR_ADD_PARTS] = 0;
 		if (psd_cnt <= bp[pgo + PP_OFF_MAX_ADD_PARTS])
 		    bp[pgo + MP_OFF_PAGE_LENGTH] = 6;
@@ -3378,22 +3465,54 @@
 	} else {
 		bp[psdo] = (size >> 8) & 0xff;
 		bp[psdo + 1] = size & 0xff;
+		if (target_partition == 0)
+			bp[psdo + 2] = bp[psdo + 3] = 0xff;
 		bp[pgo + 3] = 1;
 		if (bp[pgo + MP_OFF_PAGE_LENGTH] < 8)
 		    bp[pgo + MP_OFF_PAGE_LENGTH] = 8;
 		DEBC_printk(STp, "Formatting tape with two partitions "
-			    "(1 = %d MB).\n", size);
+			    "(1 = %d MB).\n",
+			    units > 0 ? size * 1000 : size);
 	}
 	bp[pgo + PP_OFF_PART_UNITS] = 0;
 	bp[pgo + PP_OFF_RESERVED] = 0;
-	bp[pgo + PP_OFF_FLAGS] = PP_BIT_IDP | PP_MSK_PSUM_MB;
+	if (size != 1 || units != 0) {
+		bp[pgo + PP_OFF_FLAGS] = PP_BIT_IDP | psum |
+			(bp[pgo + PP_OFF_FLAGS] & 0x07);
+		bp[pgo + PP_OFF_PART_UNITS] = units;
+	} else
+		bp[pgo + PP_OFF_FLAGS] = PP_BIT_FDP |
+			(bp[pgo + PP_OFF_FLAGS] & 0x1f);
+	bp[pgo + MP_OFF_PAGE_LENGTH] = 6 + psd_cnt * 2;
+
+	DEBC_printk(STp, "Sent partition page length is %d bytes. needs_format: %d\n",
+		    bp[pgo + MP_OFF_PAGE_LENGTH] + 2, needs_format);
+	DEBC_printk(STp, "PP: max %u, add %u, xdp %u, psum %02x, pofmetc %u, "
+		    "rec %02x, units %02x, sizes: %u %u\n",
+		    bp[pgo + PP_OFF_MAX_ADD_PARTS],
+		    bp[pgo + PP_OFF_NBR_ADD_PARTS],
+		    (bp[pgo + PP_OFF_FLAGS] & 0xe0) >> 5,
+		    (bp[pgo + PP_OFF_FLAGS] & 0x18) >> 3,
+		    bp[pgo + PP_OFF_FLAGS] & 0x07,
+		    bp[pgo + 5],
+		    bp[pgo + PP_OFF_PART_UNITS],
+		    bp[pgo + 8] * 256 + bp[pgo + 9],
+		    bp[pgo + 10] * 256 + bp[pgo + 11]);
+	DEBC_printk(STp, "MP: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+		    bp[pgo], bp[pgo+1], bp[pgo+2], bp[pgo+3], bp[pgo+4], bp[pgo+5],
+		    bp[pgo+6], bp[pgo+7], bp[pgo+8], bp[pgo+9], bp[pgo+10], bp[pgo+11]);
 
 	result = write_mode_page(STp, PART_PAGE, 1);
+
+	if (!result && needs_format)
+		result = format_medium(STp, 1);
+
 	if (result) {
 		st_printk(KERN_INFO, STp, "Partitioning of tape failed.\n");
 		result = (-EIO);
 	}
 
+out:
 	return result;
 }
 \f
@@ -3570,7 +3689,7 @@
 				retval = (-EINVAL);
 				goto out;
 			}
-			if ((i = st_int_ioctl(STp, MTREW, 0)) < 0 ||
+			if ((i = do_load_unload(STp, file, 1)) < 0 ||
 			    (i = partition_tape(STp, mtc.mt_count)) < 0) {
 				retval = i;
 				goto out;
@@ -3581,7 +3700,7 @@
 				STp->ps[i].last_block_valid = 0;
 			}
 			STp->partition = STp->new_partition = 0;
-			STp->nbr_partitions = 1;	/* Bad guess ?-) */
+			STp->nbr_partitions = mtc.mt_count > 0 ? 2 : 1;
 			STps->drv_block = STps->drv_file = 0;
 			retval = 0;
 			goto out;

  parent reply	other threads:[~2016-01-29 17:22 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20151218170644.24167419@harpe.intellique.com>
2015-12-21 12:46 ` st driver doesn't seem to grok LTO partitioning Emmanuel Florac
2015-12-21 17:25   ` "Kai Mäkisara (Kolumbus)"
     [not found]     ` <20151221185759.38dd21d6@harpe.intellique.com>
2015-12-21 18:57       ` "Kai Mäkisara (Kolumbus)"
2015-12-22  5:51         ` Seymour, Shane M
2015-12-22  9:59           ` Emmanuel Florac
     [not found]           ` <CAAzz28i5=oz_BmcoEC2ApLN9zj_F4aDmGkCXkXaS48HR_Ockew@mail.gmail.com>
2015-12-22 10:04             ` Emmanuel Florac
2015-12-22 10:31               ` Laurence Oberman
2015-12-25 15:53         ` Kai Makisara
2015-12-25 17:47           ` Emmanuel Florac
2015-12-29 16:14           ` Emmanuel Florac
2015-12-29 16:58           ` Emmanuel Florac
2015-12-29 17:46             ` "Kai Mäkisara (Kolumbus)"
2015-12-29 17:58               ` Emmanuel Florac
     [not found]               ` <20151229191347.2e0e5f0e@harpe.intellique.com>
2015-12-30 17:54                 ` Kai Makisara
2015-12-30 18:33                   ` Emmanuel Florac
2015-12-30 19:21                     ` "Kai Mäkisara (Kolumbus)"
2015-12-30 21:24                       ` Emmanuel Florac
2015-12-31 16:08                         ` "Kai Mäkisara (Kolumbus)"
2016-01-04 10:22                           ` Kai Makisara
2016-01-04 10:54                             ` Emmanuel Florac
2016-01-04 11:05                             ` Emmanuel Florac
2016-01-04 11:46                             ` Emmanuel Florac
     [not found]                               ` <CAAzz28gW69rB-6h2fwxtwnTj5h7HZcn2qkJdx2GTgu3Y8SDNqQ@mail.gmail.com>
2016-01-04 15:32                                 ` Emmanuel Florac
     [not found]                               ` <CAAzz28iCoG-rjnL7EsjHXA7UtRJSCEXuwL3+27ZBo7fckcBAfg@mail.gmail.com>
2016-01-05 21:55                                 ` Laurence Oberman
2016-01-06 15:10                                   ` Emmanuel Florac
2016-01-06 15:23                                     ` Laurence Oberman
2016-01-06 15:25                                       ` Laurence Oberman
2016-01-06 15:32                                         ` Laurence Oberman
2016-01-06 15:48                                           ` Douglas Gilbert
2016-01-06 15:54                                             ` Laurence Oberman
2016-01-06 16:07                                       ` Emmanuel Florac
2016-01-14 20:12                                         ` Laurence Oberman
2016-01-15  0:21                                           ` Seymour, Shane M
2016-01-21 20:58                                             ` What partition should the MTMKPART argument specify? Was: " "Kai Mäkisara (Kolumbus)"
2016-01-21 22:06                                               ` Laurence Oberman
2016-01-22  2:10                                               ` Seymour, Shane M
2016-01-22  3:31                                                 ` Seymour, Shane M
2016-01-22 11:24                                                 ` Emmanuel Florac
2016-01-22 11:50                                                 ` Emmanuel Florac
2016-01-26 23:35                                                   ` Seymour, Shane M
2016-01-28 17:31                                                     ` "Kai Mäkisara (Kolumbus)"
2016-01-28 17:39                                                       ` Emmanuel Florac
2016-01-24 21:05                                                 ` Kai Makisara
2016-01-25 10:21                                                   ` Emmanuel Florac
2016-01-28  7:36                                                   ` Seymour, Shane M
2016-01-28 17:04                                                     ` "Kai Mäkisara (Kolumbus)"
2016-01-28 19:21                                                       ` Laurence Oberman
2016-01-28 19:56                                                         ` "Kai Mäkisara (Kolumbus)"
2016-01-28 23:12                                                       ` Seymour, Shane M
2016-01-28 23:23                                                         ` Laurence Oberman
2016-01-28 23:25                                                           ` Laurence Oberman
2016-01-29  0:54                                                             ` Seymour, Shane M
2016-01-29 17:22                                                         ` Kai Makisara [this message]
2016-02-01  6:31                                                           ` Seymour, Shane M
2016-02-01 18:43                                                             ` "Kai Mäkisara (Kolumbus)"
2016-02-01 19:02                                                               ` Laurence Oberman
2016-02-01 22:59                                                               ` Seymour, Shane M
2016-02-03  3:40                                                               ` Laurence Oberman
2016-02-03  2:18                                                           ` Seymour, Shane M
2016-02-03 18:36                                                             ` Kai Makisara
2016-02-04  1:43                                                               ` Seymour, Shane M
2016-02-04 17:54                                                                 ` "Kai Mäkisara (Kolumbus)"
2016-02-04 18:09                                                                   ` Douglas Gilbert
2016-02-04 19:25                                                                     ` Laurence Oberman
2016-02-04 18:12                                                                   ` Emmanuel Florac
2016-01-15 11:48                                           ` Emmanuel Florac
2016-01-22 10:17                                           ` Douglas Gilbert
2016-01-06 16:10                               ` Emmanuel Florac
2016-01-06 16:16                                 ` Emmanuel Florac
2016-01-06 16:44                             ` Emmanuel Florac
2015-12-29 16:59           ` Emmanuel Florac
2015-12-29 17:18             ` "Kai Mäkisara (Kolumbus)"
     [not found]   ` <CAAzz28gn2zwC5ZUTtPupDOTHekGspWh0vnWHV+jvbx52c=cq2Q@mail.gmail.com>
2015-12-21 17:49     ` Emmanuel Florac

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.11.1601291915010.22105@xnv.znxvfnen.cevingr \
    --to=kai.makisara@kolumbus.fi \
    --cc=eflorac@intellique.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=loberman@redhat.com \
    --cc=oberman.l@gmail.com \
    --cc=shane.seymour@hpe.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.