All of lore.kernel.org
 help / color / mirror / Atom feed
* dummy scsi read or scsi command periodically for external USB Hard Disk
@ 2014-07-05 17:18 loody
  2014-07-07  9:20 ` Bryn M. Reeves
  0 siblings, 1 reply; 23+ messages in thread
From: loody @ 2014-07-05 17:18 UTC (permalink / raw)
  To: linux-usb, SCSI development list

hi all:
    we met a USB Hard Disk that will go to suspend if host stop
sending scsi command over 5mins.
    To save the IO, kernel will keep the file in page cache as much as
he can and under this circumstances, the scsi command may disappear
for a while longer enough to cause the device suspend.

    is there any kernel config or module parameter can do the dummy
read or scsi command periodically?

appreciate your help in advance,

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-05 17:18 dummy scsi read or scsi command periodically for external USB Hard Disk loody
@ 2014-07-07  9:20 ` Bryn M. Reeves
  2014-07-07 14:37   ` loody
  0 siblings, 1 reply; 23+ messages in thread
From: Bryn M. Reeves @ 2014-07-07  9:20 UTC (permalink / raw)
  To: loody; +Cc: linux-usb, SCSI development list

On Sun, Jul 06, 2014 at 01:18:03AM +0800, loody wrote:
> hi all:
>     we met a USB Hard Disk that will go to suspend if host stop
> sending scsi command over 5mins.
>     To save the IO, kernel will keep the file in page cache as much as
> he can and under this circumstances, the scsi command may disappear
> for a while longer enough to cause the device suspend.
> 
>     is there any kernel config or module parameter can do the dummy
> read or scsi command periodically?

No but you could set up a simple cron job to call an sg3_utils command.

E.g. issue an sg_read for one sector to the device every 4m:

  */4 * * * * sg_read count=1 if=/dev/<disk>

You'll probably want to disable mail notification for the job or have
it dropped or it'll get a bit noisy running that frequently.

Regards,
Bryn.


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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-07  9:20 ` Bryn M. Reeves
@ 2014-07-07 14:37   ` loody
  2014-07-07 14:59     ` Lars Melin
  2014-07-07 15:54     ` Alan Stern
  0 siblings, 2 replies; 23+ messages in thread
From: loody @ 2014-07-07 14:37 UTC (permalink / raw)
  To: Bryn M. Reeves; +Cc: linux-usb, SCSI development list

hi Bryn:

2014-07-07 17:20 GMT+08:00 Bryn M. Reeves <bmr@redhat.com>:
> On Sun, Jul 06, 2014 at 01:18:03AM +0800, loody wrote:
>> hi all:
>>     we met a USB Hard Disk that will go to suspend if host stop
>> sending scsi command over 5mins.
>>     To save the IO, kernel will keep the file in page cache as much as
>> he can and under this circumstances, the scsi command may disappear
>> for a while longer enough to cause the device suspend.
>>
>>     is there any kernel config or module parameter can do the dummy
>> read or scsi command periodically?
>
> No but you could set up a simple cron job to call an sg3_utils command.
>
> E.g. issue an sg_read for one sector to the device every 4m:
>
>   */4 * * * * sg_read count=1 if=/dev/<disk>
Since my target platform arm embedded system,
does that mean I should include sg_read in my Busybox
or
cross-compile sg_read from sg3_utils?

appreciate your kind help,

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-07 14:37   ` loody
@ 2014-07-07 14:59     ` Lars Melin
       [not found]       ` <53BAB5DF.5090606-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2014-07-07 15:54     ` Alan Stern
  1 sibling, 1 reply; 23+ messages in thread
From: Lars Melin @ 2014-07-07 14:59 UTC (permalink / raw)
  To: loody, Bryn M. Reeves; +Cc: linux-usb, SCSI development list

On 2014-07-07 21:37, loody wrote:
> hi Bryn:
>
> 2014-07-07 17:20 GMT+08:00 Bryn M. Reeves <bmr@redhat.com>:
>> On Sun, Jul 06, 2014 at 01:18:03AM +0800, loody wrote:
>>> hi all:
>>>      we met a USB Hard Disk that will go to suspend if host stop
>>> sending scsi command over 5mins.
>>>      To save the IO, kernel will keep the file in page cache as much as
>>> he can and under this circumstances, the scsi command may disappear
>>> for a while longer enough to cause the device suspend.
>>>
>>>      is there any kernel config or module parameter can do the dummy
>>> read or scsi command periodically?
>> No but you could set up a simple cron job to call an sg3_utils command.
>>
>> E.g. issue an sg_read for one sector to the device every 4m:
>>
>>    */4 * * * * sg_read count=1 if=/dev/<disk>
> Since my target platform arm embedded system,
> does that mean I should include sg_read in my Busybox
> or
> cross-compile sg_read from sg3_utils?
>
> appreciate your kind help,
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
sgread is not included in BusyBox but you should have "touch".
Create a dummy file on the disk and let cron touch it every 4 minutes.

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

* RE: dummy scsi read or scsi command periodically for external USB Hard Disk
       [not found]       ` <53BAB5DF.5090606-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-07-07 15:06         ` David Laight
  2014-07-07 15:39           ` loody
  0 siblings, 1 reply; 23+ messages in thread
From: David Laight @ 2014-07-07 15:06 UTC (permalink / raw)
  To: 'Lars Melin', loody, Bryn M. Reeves
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA, SCSI development list

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 549 bytes --]

From: Lars Melin
...
> sgread is not included in BusyBox but you should have "touch".
> Create a dummy file on the disk and let cron touch it every 4 minutes.

You don't need 'touch' a shell redirect eg ": >file" will do open(..., O_CREAT|O_TRUNC).
However that still might not force an actual disc access.

In any case you really only want to do a read, doing a write will kill the NAND memory.

	David

N‹§²æìr¸›yúèšØb²X¬¶Ç§vØ^–)Þº{.nÇ+‰·¥Š{±ºÆâžØ^n‡r¡ö¦zË\x1aëh™¨è­Ú&¢îý»\x05ËÛÔØï¦v¬Îf\x1dp)¹¹br	šê+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹\x1e®w¥¢¸?™¨è­Ú&¢)ߢ^[f

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-07 15:06         ` David Laight
@ 2014-07-07 15:39           ` loody
       [not found]             ` <CANudz+uOS3VVyz6FcHoui8z678R6Xc0CQrdqFRdS5NyfCB59Zw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2014-07-07 15:52             ` Bryn M. Reeves
  0 siblings, 2 replies; 23+ messages in thread
From: loody @ 2014-07-07 15:39 UTC (permalink / raw)
  To: David Laight; +Cc: Lars Melin, Bryn M. Reeves, linux-usb, SCSI development list

hi David:

2014-07-07 23:06 GMT+08:00 David Laight <David.Laight@aculab.com>:
> From: Lars Melin
> ...
>> sgread is not included in BusyBox but you should have "touch".
>> Create a dummy file on the disk and let cron touch it every 4 minutes.
>
> You don't need 'touch' a shell redirect eg ": >file" will do open(..., O_CREAT|O_TRUNC).
> However that still might not force an actual disc access.
>
> In any case you really only want to do a read, doing a write will kill the NAND memory.

actually I have searched the scsi/usb layer for possible dummy read,
even read sector 0 is fine, but in vain.

I found the read
a. determined by VFS -> block layer,
b. Block layer put it in queue
c. call scsi pre-queue function to usb layer.

That mean if I try to read sector from usb devices, I have to create a
queue and follow above b) and c) rule.
is there any already kernel API I can use?

sincerely appreciate all yours help,

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
       [not found]             ` <CANudz+uOS3VVyz6FcHoui8z678R6Xc0CQrdqFRdS5NyfCB59Zw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-07-07 15:51               ` Lars Melin
  0 siblings, 0 replies; 23+ messages in thread
From: Lars Melin @ 2014-07-07 15:51 UTC (permalink / raw)
  To: loody, David Laight
  Cc: Bryn M. Reeves, linux-usb-u79uwXL29TY76Z2rM5mHXA, SCSI development list

On 2014-07-07 22:39, loody wrote:
> hi David:
>
> 2014-07-07 23:06 GMT+08:00 David Laight <David.Laight-JxhZ9S5GRejQT0dZR+AlfA@public.gmane.org>:
>> From: Lars Melin
>> ...
>>> sgread is not included in BusyBox but you should have "touch".
>>> Create a dummy file on the disk and let cron touch it every 4 minutes.
>> You don't need 'touch' a shell redirect eg ": >file" will do open(..., O_CREAT|O_TRUNC).
>> However that still might not force an actual disc access.
>>
>> In any case you really only want to do a read, doing a write will kill the NAND memory.
> actually I have searched the scsi/usb layer for possible dummy read,
> even read sector 0 is fine, but in vain.
>
> I found the read
> a. determined by VFS -> block layer,
> b. Block layer put it in queue
> c. call scsi pre-queue function to usb layer.
>
> That mean if I try to read sector from usb devices, I have to create a
> queue and follow above b) and c) rule.
> is there any already kernel API I can use?
>
> sincerely appreciate all yours help,
dd if=/dev/sda of=/dev/null count=1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-07 15:39           ` loody
       [not found]             ` <CANudz+uOS3VVyz6FcHoui8z678R6Xc0CQrdqFRdS5NyfCB59Zw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-07-07 15:52             ` Bryn M. Reeves
       [not found]               ` <20140707155233.GD19630-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
  1 sibling, 1 reply; 23+ messages in thread
From: Bryn M. Reeves @ 2014-07-07 15:52 UTC (permalink / raw)
  To: loody; +Cc: David Laight, Lars Melin, linux-usb, SCSI development list

On Mon, Jul 07, 2014 at 11:39:05PM +0800, loody wrote:
> hi David:
> 
> 2014-07-07 23:06 GMT+08:00 David Laight <David.Laight@aculab.com>:
> > From: Lars Melin
> > ...
> >> sgread is not included in BusyBox but you should have "touch".
> >> Create a dummy file on the disk and let cron touch it every 4 minutes.
> >
> > You don't need 'touch' a shell redirect eg ": >file" will do open(..., O_CREAT|O_TRUNC).
> > However that still might not force an actual disc access.
> >
> > In any case you really only want to do a read, doing a write will kill the NAND memory.
> 
> actually I have searched the scsi/usb layer for possible dummy read,
> even read sector 0 is fine, but in vain.
> 
> I found the read
> a. determined by VFS -> block layer,
> b. Block layer put it in queue
> c. call scsi pre-queue function to usb layer.
> 
> That mean if I try to read sector from usb devices, I have to create a
> queue and follow above b) and c) rule.
> is there any already kernel API I can use?
> 
> sincerely appreciate all yours help,

If you don't want to put sg_read into your image you could just use a dd;
busybox includes an implementation that should be good enough.

Just make sure you use the right flags to use O_DIRECT access or you'll
just end up hammering on the page cache. Iirc that's "iflags=direct" (check
the busybox docs to make sure it's the same).

Regards,
Bryn.


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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-07 14:37   ` loody
  2014-07-07 14:59     ` Lars Melin
@ 2014-07-07 15:54     ` Alan Stern
       [not found]       ` <Pine.LNX.4.44L0.1407071147130.871-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
  1 sibling, 1 reply; 23+ messages in thread
From: Alan Stern @ 2014-07-07 15:54 UTC (permalink / raw)
  To: loody; +Cc: Bryn M. Reeves, linux-usb, SCSI development list

On Mon, 7 Jul 2014, loody wrote:

> hi Bryn:
> 
> 2014-07-07 17:20 GMT+08:00 Bryn M. Reeves <bmr@redhat.com>:
> > On Sun, Jul 06, 2014 at 01:18:03AM +0800, loody wrote:
> >> hi all:
> >>     we met a USB Hard Disk that will go to suspend if host stop
> >> sending scsi command over 5mins.
> >>     To save the IO, kernel will keep the file in page cache as much as
> >> he can and under this circumstances, the scsi command may disappear
> >> for a while longer enough to cause the device suspend.
> >>
> >>     is there any kernel config or module parameter can do the dummy
> >> read or scsi command periodically?
> >
> > No but you could set up a simple cron job to call an sg3_utils command.
> >
> > E.g. issue an sg_read for one sector to the device every 4m:
> >
> >   */4 * * * * sg_read count=1 if=/dev/<disk>
> Since my target platform arm embedded system,
> does that mean I should include sg_read in my Busybox
> or
> cross-compile sg_read from sg3_utils?

An alternative is to write a positive value, such as 240000, to 

	/sys/block/sdX/events_poll_msecs

where X is replaced with the proper drive letter.  (240000 ms = 240 s = 
4 m.)  I'm not sure this will work, but it's worth a try.

Alan Stern


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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
       [not found]       ` <Pine.LNX.4.44L0.1407071147130.871-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
@ 2014-07-07 16:13         ` loody
  2014-07-07 17:02           ` Alan Stern
  0 siblings, 1 reply; 23+ messages in thread
From: loody @ 2014-07-07 16:13 UTC (permalink / raw)
  To: Alan Stern
  Cc: Bryn M. Reeves, linux-usb-u79uwXL29TY76Z2rM5mHXA, SCSI development list

hi Alan:

>> > E.g. issue an sg_read for one sector to the device every 4m:
>> >
>> >   */4 * * * * sg_read count=1 if=/dev/<disk>
>> Since my target platform arm embedded system,
>> does that mean I should include sg_read in my Busybox
>> or
>> cross-compile sg_read from sg3_utils?
>
> An alternative is to write a positive value, such as 240000, to
>
>         /sys/block/sdX/events_poll_msecs
>
> where X is replaced with the proper drive letter.  (240000 ms = 240 s =
> 4 m.)  I'm not sure this will work, but it's worth a try.

I cannot find events_poll_msecs you mentioned in my system.
Is this capability related to kernel version?
( my kernel version is 2.6.38.8 )

Sincerely appreciate all yours kind help,

PS:
below is result of /sys/block/sdb/
/sys/block/sdb# ls -lht
total 0
-r--r--r-- 1 root root 4.0K 2014-07-08 00:08 alignment_offset
lrwxrwxrwx 1 root root    0 2014-07-08 00:08 bdi ->
../../../../../../../../../../virtual/bdi/8:16
-r--r--r-- 1 root root 4.0K 2014-07-08 00:08 capability
-r--r--r-- 1 root root 4.0K 2014-07-08 00:08 dev
lrwxrwxrwx 1 root root    0 2014-07-08 00:08 device -> ../../../3:0:0:0
-r--r--r-- 1 root root 4.0K 2014-07-08 00:08 discard_alignment
-r--r--r-- 1 root root 4.0K 2014-07-08 00:08 ext_range
-r--r--r-- 1 root root 4.0K 2014-07-08 00:08 inflight
drwxr-xr-x 2 root root    0 2014-07-08 00:08 power
-r--r--r-- 1 root root 4.0K 2014-07-08 00:08 stat
drwxr-xr-x 2 root root    0 2014-07-08 00:08 trace
drwxr-xr-x 2 root root    0 2014-07-08 00:05 holders
drwxr-xr-x 3 root root    0 2014-07-08 00:05 queue
-r--r--r-- 1 root root 4.0K 2014-07-08 00:05 range
-r--r--r-- 1 root root 4.0K 2014-07-08 00:05 ro
drwxr-xr-x 5 root root    0 2014-07-08 00:05 sdb1
-r--r--r-- 1 root root 4.0K 2014-07-08 00:05 size
drwxr-xr-x 2 root root    0 2014-07-08 00:05 slaves
-r--r--r-- 1 root root 4.0K 2014-07-08 00:05 removable
lrwxrwxrwx 1 root root    0 2014-07-08 00:05 subsystem ->
../../../../../../../../../../../class/block
-rw-r--r-- 1 root root 4.0K 2014-07-08 00:05 uevent
/sys/block/sdb#
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
       [not found]               ` <20140707155233.GD19630-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2014-07-07 16:15                 ` loody
       [not found]                   ` <CANudz+s8R3AnxEJ229EwAOOxEk2WZUjMjoE3rwdRM1YM5ZO=og-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 23+ messages in thread
From: loody @ 2014-07-07 16:15 UTC (permalink / raw)
  To: Bryn M. Reeves
  Cc: David Laight, Lars Melin, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	SCSI development list

hi Bryn:


2014-07-07 23:52 GMT+08:00 Bryn M. Reeves <bmr-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>:
> On Mon, Jul 07, 2014 at 11:39:05PM +0800, loody wrote:
>> hi David:
>>
>> 2014-07-07 23:06 GMT+08:00 David Laight <David.Laight-JxhZ9S5GRejQT0dZR+AlfA@public.gmane.org>:
>> > From: Lars Melin
>> > ...
>> >> sgread is not included in BusyBox but you should have "touch".
>> >> Create a dummy file on the disk and let cron touch it every 4 minutes.
>> >
>> > You don't need 'touch' a shell redirect eg ": >file" will do open(..., O_CREAT|O_TRUNC).
>> > However that still might not force an actual disc access.
>> >
>> > In any case you really only want to do a read, doing a write will kill the NAND memory.
>>
>> actually I have searched the scsi/usb layer for possible dummy read,
>> even read sector 0 is fine, but in vain.
>>
>> I found the read
>> a. determined by VFS -> block layer,
>> b. Block layer put it in queue
>> c. call scsi pre-queue function to usb layer.
>>
>> That mean if I try to read sector from usb devices, I have to create a
>> queue and follow above b) and c) rule.
>> is there any already kernel API I can use?
>>
>> sincerely appreciate all yours help,
>
> If you don't want to put sg_read into your image you could just use a dd;
> busybox includes an implementation that should be good enough.
>
> Just make sure you use the right flags to use O_DIRECT access or you'll
> just end up hammering on the page cache. Iirc that's "iflags=direct" (check
> the busybox docs to make sure it's the same).

so sg_read will not hammer on the page cache like dd without "iflags=direct"

thanks for your kind help,
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
       [not found]                   ` <CANudz+s8R3AnxEJ229EwAOOxEk2WZUjMjoE3rwdRM1YM5ZO=og-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-07-07 16:25                     ` Bryn M. Reeves
  2014-07-09 14:15                       ` loody
  0 siblings, 1 reply; 23+ messages in thread
From: Bryn M. Reeves @ 2014-07-07 16:25 UTC (permalink / raw)
  To: loody
  Cc: David Laight, Lars Melin, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	SCSI development list

On Tue, Jul 08, 2014 at 12:15:54AM +0800, loody wrote:
> so sg_read will not hammer on the page cache like dd without "iflags=direct"
> 
> thanks for your kind help,

The sg_read program (and other programs in sg3_utils) sends a command directly
to the device using an SG_IO ioctl. This bypasses all the caching layers in
the kernel and always results in IO to the device (if it succeeds).

Regards,
Bryn.

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-07 16:13         ` loody
@ 2014-07-07 17:02           ` Alan Stern
       [not found]             ` <Pine.LNX.4.44L0.1407071258360.871-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
  0 siblings, 1 reply; 23+ messages in thread
From: Alan Stern @ 2014-07-07 17:02 UTC (permalink / raw)
  To: loody; +Cc: Bryn M. Reeves, linux-usb, SCSI development list

On Tue, 8 Jul 2014, loody wrote:

> > An alternative is to write a positive value, such as 240000, to
> >
> >         /sys/block/sdX/events_poll_msecs
> >
> > where X is replaced with the proper drive letter.  (240000 ms = 240 s =
> > 4 m.)  I'm not sure this will work, but it's worth a try.
> 
> I cannot find events_poll_msecs you mentioned in my system.
> Is this capability related to kernel version?
> ( my kernel version is 2.6.38.8 )

Well, the in-kernel disk events mechanism was added in 2.6.38, but it 
may not have been implemented for your type of drive.

Probably you don't actually need to do a read.  Simply opening the 
device file ought to be sufficient.

Alan Stern


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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
       [not found]             ` <Pine.LNX.4.44L0.1407071258360.871-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
@ 2014-07-08 14:58               ` loody
       [not found]                 ` <CANudz+uRd3tRfPN-Fqcj5sSW-xkRSN-gERBP7HhUY_s5gEALbg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 23+ messages in thread
From: loody @ 2014-07-08 14:58 UTC (permalink / raw)
  To: Alan Stern
  Cc: Bryn M. Reeves, linux-usb-u79uwXL29TY76Z2rM5mHXA, SCSI development list

hi Alan:

2014-07-08 1:02 GMT+08:00 Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>:
> On Tue, 8 Jul 2014, loody wrote:
>
>> > An alternative is to write a positive value, such as 240000, to
>> >
>> >         /sys/block/sdX/events_poll_msecs
>> >
>> > where X is replaced with the proper drive letter.  (240000 ms = 240 s =
>> > 4 m.)  I'm not sure this will work, but it's worth a try.
>>
>> I cannot find events_poll_msecs you mentioned in my system.
>> Is this capability related to kernel version?
>> ( my kernel version is 2.6.38.8 )
>
> Well, the in-kernel disk events mechanism was added in 2.6.38, but it
> may not have been implemented for your type of drive.
You are correct.
i can see events_poll_msecs when I change my kernel to 3.8.0
But the device still disconnect.
I have some question.
1. when I cat  /sys/block/sdX/events, I get the answer as media_change.
    is there any events type we can choose, such as read capability or inquiry.
>
> Probably you don't actually need to do a read.  Simply opening the
> device file ought to be sufficient.
2. the open device you mean is like open(/dev/sda1)?

thanks for all your kind help,



-- 
Regards,
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
       [not found]                 ` <CANudz+uRd3tRfPN-Fqcj5sSW-xkRSN-gERBP7HhUY_s5gEALbg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-07-08 16:00                   ` Alan Stern
       [not found]                     ` <Pine.LNX.4.44L0.1407081149280.1283-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
  0 siblings, 1 reply; 23+ messages in thread
From: Alan Stern @ 2014-07-08 16:00 UTC (permalink / raw)
  To: loody
  Cc: Bryn M. Reeves, linux-usb-u79uwXL29TY76Z2rM5mHXA, SCSI development list

On Tue, 8 Jul 2014, loody wrote:

> You are correct.
> i can see events_poll_msecs when I change my kernel to 3.8.0
> But the device still disconnect.
> I have some question.
> 1. when I cat  /sys/block/sdX/events, I get the answer as media_change.
>     is there any events type we can choose, such as read capability or inquiry.

The only other event type is eject_request.  But that applies to CD
drives, not disk drives.

> > Probably you don't actually need to do a read.  Simply opening the
> > device file ought to be sufficient.
> 2. the open device you mean is like open(/dev/sda1)?

Yes.  That will send a SCSI TEST UNIT READY command, the same as disk
events polling.  You can use usbmon to verify this.

However, maybe TEST UNIT READY won't work.  Your drive might need to 
see a READ or WRITE command.  If that's the case then neither 
events_poll_msecs nor a simple open() will help.

Have you tried using hdparm with the -B or -S flag?

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
       [not found]                     ` <Pine.LNX.4.44L0.1407081149280.1283-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
@ 2014-07-08 19:04                       ` loody
  2014-07-08 19:26                         ` Alan Stern
  0 siblings, 1 reply; 23+ messages in thread
From: loody @ 2014-07-08 19:04 UTC (permalink / raw)
  To: Alan Stern
  Cc: Bryn M. Reeves, linux-usb-u79uwXL29TY76Z2rM5mHXA, SCSI development list

hi Alan:

2014-07-09 0:00 GMT+08:00 Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>:
> On Tue, 8 Jul 2014, loody wrote:
>
>> You are correct.
>> i can see events_poll_msecs when I change my kernel to 3.8.0
>> But the device still disconnect.
>> I have some question.
>> 1. when I cat  /sys/block/sdX/events, I get the answer as media_change.
>>     is there any events type we can choose, such as read capability or inquiry.
>
> The only other event type is eject_request.  But that applies to CD
> drives, not disk drives.
>
>> > Probably you don't actually need to do a read.  Simply opening the
>> > device file ought to be sufficient.
>> 2. the open device you mean is like open(/dev/sda1)?
>
> Yes.  That will send a SCSI TEST UNIT READY command, the same as disk
> events polling.  You can use usbmon to verify this.
>
> However, maybe TEST UNIT READY won't work.  Your drive might need to
> see a READ or WRITE command.  If that's the case then neither
> events_poll_msecs nor a simple open() will help.
>
> Have you tried using hdparm with the -B or -S flag?

there is one thing pop in my mind.
if events_poll_msecs is used for media_change, shouldn't we wrap is READ10?
the difference seems
1. change SCSI command
2. allocate 512 Byte for 1 sector dummy read
the periodically trigging flow should be the same.

if you think above is possible, where we should start from?
appreciate your help


-- 
Regards,
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-08 19:04                       ` loody
@ 2014-07-08 19:26                         ` Alan Stern
  2014-07-09  3:17                           ` loody
  0 siblings, 1 reply; 23+ messages in thread
From: Alan Stern @ 2014-07-08 19:26 UTC (permalink / raw)
  To: loody; +Cc: Bryn M. Reeves, linux-usb, SCSI development list

On Wed, 9 Jul 2014, loody wrote:

> there is one thing pop in my mind.
> if events_poll_msecs is used for media_change, shouldn't we wrap is READ10?

No.  Why should media change polling use READ(10)?  TEST UNIT READY 
does a good job of detecting media changes.

> the difference seems
> 1. change SCSI command
> 2. allocate 512 Byte for 1 sector dummy read
> the periodically trigging flow should be the same.
> 
> if you think above is possible, where we should start from?

Why do you want to make this change?

Alan Stern


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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-08 19:26                         ` Alan Stern
@ 2014-07-09  3:17                           ` loody
  2014-07-09  8:37                             ` David Laight
  2014-07-09 14:19                             ` Alan Stern
  0 siblings, 2 replies; 23+ messages in thread
From: loody @ 2014-07-09  3:17 UTC (permalink / raw)
  To: Alan Stern; +Cc: Bryn M. Reeves, linux-usb, SCSI development list

hi Alan:

2014-07-09 3:26 GMT+08:00 Alan Stern <stern@rowland.harvard.edu>:
> On Wed, 9 Jul 2014, loody wrote:
>
>> there is one thing pop in my mind.
>> if events_poll_msecs is used for media_change, shouldn't we wrap is READ10?
>
> No.  Why should media change polling use READ(10)?  TEST UNIT READY
> does a good job of detecting media changes.
>
>> the difference seems
>> 1. change SCSI command
>> 2. allocate 512 Byte for 1 sector dummy read
>> the periodically trigging flow should be the same.
>>
>> if you think above is possible, where we should start from?
>
> Why do you want to make this change?
on that usb hard disk, no matter media_change or TEST_UNIT_READY, keep
polling the device every 3mins.
the disconnection still happen.

So I am wondering, I can use the existence wheel, such as echo 40000 >
/sys/block/sda/events_poll_
msecs.
but what it really do is read sector, not media_change or test_unit_ready.

thanks for your kind help

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

* RE: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-09  3:17                           ` loody
@ 2014-07-09  8:37                             ` David Laight
  2014-07-09 13:27                               ` loody
  2014-07-09 14:19                             ` Alan Stern
  1 sibling, 1 reply; 23+ messages in thread
From: David Laight @ 2014-07-09  8:37 UTC (permalink / raw)
  To: 'loody', Alan Stern
  Cc: Bryn M. Reeves, linux-usb, SCSI development list

From: loody
...
> but what it really do is read sector, not media_change or test_unit_ready.

Maybe one of the programs that reads the mbr partition table can
be persuaded to do a direct read?

	David


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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-09  8:37                             ` David Laight
@ 2014-07-09 13:27                               ` loody
       [not found]                                 ` <CANudz+tQ4pJFmLTRsHtL=VjuCg30Af+7CpK1qRQM5TwwShoQtA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 23+ messages in thread
From: loody @ 2014-07-09 13:27 UTC (permalink / raw)
  To: David Laight; +Cc: Alan Stern, Bryn M. Reeves, linux-usb, SCSI development list

hi all:
I try 2 methods today but there is no read command firing from usb
host to device
(I double check the existence of command by CATC protocol analyzer)
appreciate all your kind suggestion.

1. use busybox like below command
dd if=/dev/sda1 of=/dev/null bs=512 count=1 conv=sync
my dd in busybox doesn't have iflags option
# ./busybox.new dd help

BusyBox v1.19.2 (2014-07-09 13:43:36 CST) multi-call binary.
Usage: dd [if=FILE] [of=FILE] [ibs=N] [obs=N] [bs=N] [count=N] [skip=N]
        [seek=N] [conv=notrunc|noerror|sync|fsync]
Copy a file with converting and formatting
        if=FILE         Read from FILE instead of stdin
        of=FILE         Write to FILE instead of stdout
        bs=N            Read and write N bytes at a time
        ibs=N           Read N bytes at a time
        obs=N           Write N bytes at a time
        count=N         Copy only N input blocks
        skip=N          Skip N input blocks
        seek=N          Skip N output blocks
        conv=notrunc    Don't truncate output file
        conv=noerror    Continue after read errors
        conv=sync       Pad blocks with zeros
        conv=fsync      Physically write data out before finishing

2. write c source file and open with O_DIRECT flag.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

char message[] = "/mnt/usb/4854344154343452/test.txt";
int main()
{
   int fd;
   char buffer[5];
   int count = 0;
   char *buf="1234567890";
   if((fd=open(message,O_CREAT|O_TRUNC|O_RDWR|O_DIRECT, 0777))<0)
   {
       perror("open");
       return -1;
   }
   printf("fd=%d\n", fd);
   write(fd, buf, strlen(buf));
   while(1){
       lseek(fd,0,SEEK_SET);
       sleep(3);
       count = read(fd, buffer, 3);
       printf("count=%d,%x,%x,%x\n", count,buffer[0],buffer[1],buffer[2]);
   }

}

2014-07-09 16:37 GMT+08:00 David Laight <David.Laight@aculab.com>:
> From: loody
> ...
>> but what it really do is read sector, not media_change or test_unit_ready.
>
> Maybe one of the programs that reads the mbr partition table can
> be persuaded to do a direct read?
>
>         David
>



-- 
Regards,

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-07 16:25                     ` Bryn M. Reeves
@ 2014-07-09 14:15                       ` loody
  0 siblings, 0 replies; 23+ messages in thread
From: loody @ 2014-07-09 14:15 UTC (permalink / raw)
  To: Bryn M. Reeves; +Cc: David Laight, Lars Melin, linux-usb, SCSI development list

hi Bryn:

2014-07-08 0:25 GMT+08:00 Bryn M. Reeves <bmr@redhat.com>:
> On Tue, Jul 08, 2014 at 12:15:54AM +0800, loody wrote:
>> so sg_read will not hammer on the page cache like dd without "iflags=direct"
>>
>> thanks for your kind help,
>
> The sg_read program (and other programs in sg3_utils) sends a command directly
> to the device using an SG_IO ioctl. This bypasses all the caching layers in
> the kernel and always results in IO to the device (if it succeeds).
>
I download sg utility but I found if I need to use sg_read only, I
need to install sg_lig on my target system.
is there any simple source I can reference for just doing the scsi
read through IOCTL as you explained to us before?

appreciate your kind help,


-- 
Regards,

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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
  2014-07-09  3:17                           ` loody
  2014-07-09  8:37                             ` David Laight
@ 2014-07-09 14:19                             ` Alan Stern
  1 sibling, 0 replies; 23+ messages in thread
From: Alan Stern @ 2014-07-09 14:19 UTC (permalink / raw)
  To: loody; +Cc: Bryn M. Reeves, linux-usb, SCSI development list

On Wed, 9 Jul 2014, loody wrote:

> on that usb hard disk, no matter media_change or TEST_UNIT_READY, keep
> polling the device every 3mins.
> the disconnection still happen.
> 
> So I am wondering, I can use the existence wheel, such as echo 40000 >
> /sys/block/sda/events_poll_
> msecs.
> but what it really do is read sector, not media_change or test_unit_ready.

No, you cannot change the event polling code.  Doing so would mess up 
other drives.

Alan Stern


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

* Re: dummy scsi read or scsi command periodically for external USB Hard Disk
       [not found]                                 ` <CANudz+tQ4pJFmLTRsHtL=VjuCg30Af+7CpK1qRQM5TwwShoQtA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-07-09 14:25                                   ` Alan Stern
  0 siblings, 0 replies; 23+ messages in thread
From: Alan Stern @ 2014-07-09 14:25 UTC (permalink / raw)
  To: loody
  Cc: David Laight, Bryn M. Reeves, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	SCSI development list

On Wed, 9 Jul 2014, loody wrote:

> hi all:
> I try 2 methods today but there is no read command firing from usb
> host to device
> (I double check the existence of command by CATC protocol analyzer)
> appreciate all your kind suggestion.
> 
> 1. use busybox like below command
> dd if=/dev/sda1 of=/dev/null bs=512 count=1 conv=sync
> my dd in busybox doesn't have iflags option
> # ./busybox.new dd help
> 
> BusyBox v1.19.2 (2014-07-09 13:43:36 CST) multi-call binary.
> Usage: dd [if=FILE] [of=FILE] [ibs=N] [obs=N] [bs=N] [count=N] [skip=N]
>         [seek=N] [conv=notrunc|noerror|sync|fsync]
> Copy a file with converting and formatting
>         if=FILE         Read from FILE instead of stdin
>         of=FILE         Write to FILE instead of stdout
>         bs=N            Read and write N bytes at a time
>         ibs=N           Read N bytes at a time
>         obs=N           Write N bytes at a time
>         count=N         Copy only N input blocks
>         skip=N          Skip N input blocks
>         seek=N          Skip N output blocks
>         conv=notrunc    Don't truncate output file
>         conv=noerror    Continue after read errors
>         conv=sync       Pad blocks with zeros
>         conv=fsync      Physically write data out before finishing
> 
> 2. write c source file and open with O_DIRECT flag.
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> 
> char message[] = "/mnt/usb/4854344154343452/test.txt";
> int main()
> {
>    int fd;
>    char buffer[5];
>    int count = 0;
>    char *buf="1234567890";
>    if((fd=open(message,O_CREAT|O_TRUNC|O_RDWR|O_DIRECT, 0777))<0)
>    {
>        perror("open");
>        return -1;
>    }
>    printf("fd=%d\n", fd);
>    write(fd, buf, strlen(buf));
>    while(1){
>        lseek(fd,0,SEEK_SET);
>        sleep(3);
>        count = read(fd, buffer, 3);
>        printf("count=%d,%x,%x,%x\n", count,buffer[0],buffer[1],buffer[2]);
>    }
> 
> }

You can do what you want by using the SCSI Generic API.  See the Linux 
SCSI Generic (sg) HOWTO:

	http://tldp.org/HOWTO/SCSI-Generic-HOWTO/

With the proper ioctl call, you can send a READ(10) command telling the 
drive to read one block starting from block 0.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2014-07-09 14:25 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-05 17:18 dummy scsi read or scsi command periodically for external USB Hard Disk loody
2014-07-07  9:20 ` Bryn M. Reeves
2014-07-07 14:37   ` loody
2014-07-07 14:59     ` Lars Melin
     [not found]       ` <53BAB5DF.5090606-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-07-07 15:06         ` David Laight
2014-07-07 15:39           ` loody
     [not found]             ` <CANudz+uOS3VVyz6FcHoui8z678R6Xc0CQrdqFRdS5NyfCB59Zw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-07 15:51               ` Lars Melin
2014-07-07 15:52             ` Bryn M. Reeves
     [not found]               ` <20140707155233.GD19630-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2014-07-07 16:15                 ` loody
     [not found]                   ` <CANudz+s8R3AnxEJ229EwAOOxEk2WZUjMjoE3rwdRM1YM5ZO=og-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-07 16:25                     ` Bryn M. Reeves
2014-07-09 14:15                       ` loody
2014-07-07 15:54     ` Alan Stern
     [not found]       ` <Pine.LNX.4.44L0.1407071147130.871-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-07-07 16:13         ` loody
2014-07-07 17:02           ` Alan Stern
     [not found]             ` <Pine.LNX.4.44L0.1407071258360.871-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-07-08 14:58               ` loody
     [not found]                 ` <CANudz+uRd3tRfPN-Fqcj5sSW-xkRSN-gERBP7HhUY_s5gEALbg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-08 16:00                   ` Alan Stern
     [not found]                     ` <Pine.LNX.4.44L0.1407081149280.1283-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-07-08 19:04                       ` loody
2014-07-08 19:26                         ` Alan Stern
2014-07-09  3:17                           ` loody
2014-07-09  8:37                             ` David Laight
2014-07-09 13:27                               ` loody
     [not found]                                 ` <CANudz+tQ4pJFmLTRsHtL=VjuCg30Af+7CpK1qRQM5TwwShoQtA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-09 14:25                                   ` Alan Stern
2014-07-09 14:19                             ` Alan Stern

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.