From mboxrd@z Thu Jan 1 00:00:00 1970 From: NeilBrown Subject: Re: dummy file read periodically for external USB Hard Disk Date: Thu, 10 Jul 2014 10:47:04 +1000 Message-ID: <20140710104704.4c3fdb51@notabene.brown> References: <20140708130127.0f29a46f@notabene.brown> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/57mc.Yb4gj8pyTUGSEM3Vvw"; protocol="application/pgp-signature" Cc: Linux-FSDevel To: loody Return-path: Received: from cantor2.suse.de ([195.135.220.15]:54741 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751392AbaGJArK (ORCPT ); Wed, 9 Jul 2014 20:47:10 -0400 In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org List-ID: --Sig_/57mc.Yb4gj8pyTUGSEM3Vvw Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Wed, 9 Jul 2014 22:13:28 +0800 loody 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, >=20 > #include > #include > #include > #include > #include >=20 > char message[] =3D "/mnt/usb/4854344154343452/ > test.txt"; > int main() > { > int fd; > char buffer[5]; > int count =3D 0; > char *buf=3D"1234567890"; > if((fd=3Dopen(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=3D%d\n", fd); > write(fd, buf, strlen(buf)); > while(1){ > lseek(fd,0,SEEK_SET); > sleep(3); > count =3D 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 buffe= r 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=3D%d,%x,%x,%x\n", count,buffer[0],buffer[1],buffer[2= ]); > } >=20 > } >=20 > 2014-07-08 11:01 GMT+08:00 NeilBrown : > > On Mon, 7 Jul 2014 22:42:29 +0800 loody 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-fsdeve= l" 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 >=20 >=20 >=20 --Sig_/57mc.Yb4gj8pyTUGSEM3Vvw Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIVAwUBU73iiDnsnt1WYoG5AQJWcRAAh/2yUNw4fw80Le9U+p00DKVqF/V4JmXd NlodlCh9aYkJ8oKJA4x+5d5QVMPH6XuB37B6GRmYr4wJG9mEeQrvfzO1Md99mE/5 LHa93IZUdqc1V3+10hxu5mhzHJfSCEzgBD1zMTqkwcDJIL6yYuQ0LADeqeCMFcdL C1aSjEt+5oonU1XP6UfEYCOe/3qba0ll7wln2EXIua+h1VPp0kvEHjJQj+cGRSE0 GnHF1pOMDzXe5L2mfTCaEdFpq2V11ZVt3hd3LTWFRZ2SqkBEKQDLwKRlJmuJhI04 WCsV8v9mDnnBJgpIXlVHEloW/qdbToKlq2hmhkZOrqGwU6IMbQyxJw0ayzFJrMA6 xoL/SAkoVk/WvV6BPT9W+q2g63GF5cRAWKRoXHtl8tKZigkW3X/skla8wFv8QCRs wBKqfwaoEcDI2atl8cU39T5qhn9jygHYTM9+cGtUQlD+v97iovcJzTVdyWrUEL9T kSKKIOEd9KHW5NRCuZkM+bPinnXHP6otUj2ktjG37tf96ayTwOBmHjGoouSSBuRm 58/GbeYMzH4Oz8fso3aiKi4eMPq8DX5zOWlmBkCDLezqQRQ8fkmGvtjoftoDWNV2 +pqfpWNOLyTLdgIkT40i9bJRyQ0GnoisjMxMG+oHLSqDNzKZ5xxIGIt4U0SWZ1KS 3ER53duGHJU= =Vcmz -----END PGP SIGNATURE----- --Sig_/57mc.Yb4gj8pyTUGSEM3Vvw--