From: NeilBrown <neilb@suse.de>
To: loody <miloody@gmail.com>
Cc: Linux-FSDevel <linux-fsdevel@vger.kernel.org>
Subject: Re: dummy file read periodically for external USB Hard Disk
Date: Thu, 10 Jul 2014 10:47:04 +1000 [thread overview]
Message-ID: <20140710104704.4c3fdb51@notabene.brown> (raw)
In-Reply-To: <CANudz+sChmK0q9A+xFsCRfdj4Hf7Bj-wbWeRb=z0Tg17rLYiGw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2713 bytes --]
On Wed, 9 Jul 2014 22:13:28 +0800 loody <miloody@gmail.com> wrote:
> hi NeilBrown:
> we use below c source but there is no read command firing from usb
> host to device.
> except O_DIRECT, is there any flag we need to use?
> appreciate all your kind help,
>
> #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)
I said "Open the device with O_DIRECT". You are opening a file in the
filesystem which is mounted from the device. That is a different thing.
> {
> 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);
Did you do any research to understand how O_DIRECT works?
I recommend the man page for "open(2)".
You need to read thoroughly, but towards the end it says:
Under Linux 2.4, transfer sizes, and the alignment of the user buffer and the
file offset must all be multiples of the logical block size of the file sys-
tem. Under Linux 2.6, alignment to 512-byte boundaries suffices.
Neither your buffer nor your IO size is 512-byte aligned.
NeilBrown
> printf("count=%d,%x,%x,%x\n", count,buffer[0],buffer[1],buffer[2]);
> }
>
> }
>
> 2014-07-08 11:01 GMT+08:00 NeilBrown <neilb@suse.de>:
> > On Mon, 7 Jul 2014 22:42:29 +0800 loody <miloody@gmail.com> wrote:
> >
> >> hi all:
> >> we met a USB Hard Disk that will go to suspend if host stop
> >> sending scsi read 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 read 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 periodically, even the sector 0 (MBR) is fine.
> >> or is there any kernel api I can use to read sector 0(MBR) maybe
> >> every 4mins?
> >>
> >> appreciate your help in advance,
> >> --
> >> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> >> the body of a message to majordomo@vger.kernel.org
> >> More majordomo info at http://vger.kernel.org/majordomo-info.html
> >
> > Open the device with O_DIRECT and read a block every 4 minutes.
> > That should keep it awake.
> >
> > NeilBrown
>
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
next prev parent reply other threads:[~2014-07-10 0:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-07 14:42 dummy file read periodically for external USB Hard Disk loody
2014-07-08 3:01 ` NeilBrown
2014-07-08 3:17 ` Dave Jones
2014-07-08 15:00 ` loody
2014-07-09 14:13 ` loody
2014-07-10 0:47 ` NeilBrown [this message]
2014-07-11 9:04 ` loody
2014-07-12 3:01 ` Randy Dunlap
2014-07-18 17:31 ` loody
2014-07-18 18:13 ` Randy Dunlap
2014-07-19 10:59 ` loody
2014-07-19 11:02 ` loody
2014-07-19 21:19 ` Randy Dunlap
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=20140710104704.4c3fdb51@notabene.brown \
--to=neilb@suse.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miloody@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).