* [PATCH] block: Don't use static to define "void *p" in show_partition_start().
@ 2012-08-03 5:07 majianpeng
2012-08-03 8:41 ` Jens Axboe
0 siblings, 1 reply; 4+ messages in thread
From: majianpeng @ 2012-08-03 5:07 UTC (permalink / raw)
To: axboe; +Cc: linux-kernel
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb2312", Size: 1628 bytes --]
I met a odd prblem:read /proc/partitions may return zero.
I wrote a file test.c:
int main()
{
char buff[4096];
int ret;
int fd;
printf("pid=%d\n",getpid());
while (1) {
fd = open("/proc/partitions", O_RDONLY);
if (fd < 0) {
printf("open error %s\n", strerror(errno));
return 0;
}
ret = read(fd, buff, 4096);
if (ret <= 0)
printf("ret=%d, %s, %ld\n", ret,
strerror(errno), lseek(fd,0,SEEK_CUR));
close(fd);
}
exit(0);
}
You can reproduce by:
1:while true;do cat /proc/partitions > /dev/null ;done
2:./test
I reviewed the code and found:
>>static void *show_partition_start(struct seq_file *seqf, loff_t *pos)
>>{
>> static void *p;
>> p = disk_seqf_start(seqf, pos);
>> if (!IS_ERR_OR_NULL(p) && !*pos)
>> seq_puts(seqf, "major minor #blocks name\n\n");
>> return p;
>>}
test cat /proc/partitions
p = disk_seqf_start()(Not NULL)
p = disk_seqf_start()(NULL because pos)
if (!IS_ERR_OR_NULL(p) && !*pos)
Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
---
block/genhd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/genhd.c b/block/genhd.c
index cac7366..d839723 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -835,7 +835,7 @@ static void disk_seqf_stop(struct seq_file *seqf, void *v)
static void *show_partition_start(struct seq_file *seqf, loff_t *pos)
{
- static void *p;
+ void *p;
p = disk_seqf_start(seqf, pos);
if (!IS_ERR_OR_NULL(p) && !*pos)
--
1.7.9.5
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] block: Don't use static to define "void *p" in show_partition_start().
2012-08-03 5:07 [PATCH] block: Don't use static to define "void *p" in show_partition_start() majianpeng
@ 2012-08-03 8:41 ` Jens Axboe
2012-08-12 15:45 ` Michael Tokarev
0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2012-08-03 8:41 UTC (permalink / raw)
To: majianpeng; +Cc: linux-kernel
On 08/03/2012 07:07 AM, majianpeng wrote:
> I met a odd prblem:read /proc/partitions may return zero.
>
> I wrote a file test.c:
> int main()
> {
> char buff[4096];
> int ret;
> int fd;
> printf("pid=%d\n",getpid());
> while (1) {
> fd = open("/proc/partitions", O_RDONLY);
> if (fd < 0) {
> printf("open error %s\n", strerror(errno));
> return 0;
> }
> ret = read(fd, buff, 4096);
> if (ret <= 0)
> printf("ret=%d, %s, %ld\n", ret,
> strerror(errno), lseek(fd,0,SEEK_CUR));
> close(fd);
> }
> exit(0);
> }
>
> You can reproduce by:
> 1:while true;do cat /proc/partitions > /dev/null ;done
> 2:./test
>
> I reviewed the code and found:
>>> static void *show_partition_start(struct seq_file *seqf, loff_t *pos)
>>> {
>>> static void *p;
>
>>> p = disk_seqf_start(seqf, pos);
>>> if (!IS_ERR_OR_NULL(p) && !*pos)
>>> seq_puts(seqf, "major minor #blocks name\n\n");
>>> return p;
>>> }
> test cat /proc/partitions
> p = disk_seqf_start()(Not NULL)
> p = disk_seqf_start()(NULL because pos)
> if (!IS_ERR_OR_NULL(p) && !*pos)
>
> Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
> ---
> block/genhd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block/genhd.c b/block/genhd.c
> index cac7366..d839723 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -835,7 +835,7 @@ static void disk_seqf_stop(struct seq_file *seqf, void *v)
>
> static void *show_partition_start(struct seq_file *seqf, loff_t *pos)
> {
> - static void *p;
> + void *p;
>
> p = disk_seqf_start(seqf, pos);
> if (!IS_ERR_OR_NULL(p) && !*pos)
Huh, that looks like a clear bug. I've applied it, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] block: Don't use static to define "void *p" in show_partition_start().
2012-08-03 8:41 ` Jens Axboe
@ 2012-08-12 15:45 ` Michael Tokarev
2012-08-13 0:38 ` Jianpeng Ma
0 siblings, 1 reply; 4+ messages in thread
From: Michael Tokarev @ 2012-08-12 15:45 UTC (permalink / raw)
To: Jens Axboe; +Cc: majianpeng, linux-kernel
On 03.08.2012 12:41, Jens Axboe wrote:
> On 08/03/2012 07:07 AM, majianpeng wrote:
[]
>> diff --git a/block/genhd.c b/block/genhd.c
>> index cac7366..d839723 100644
>> --- a/block/genhd.c
>> +++ b/block/genhd.c
>> @@ -835,7 +835,7 @@ static void disk_seqf_stop(struct seq_file *seqf, void *v)
>>
>> static void *show_partition_start(struct seq_file *seqf, loff_t *pos)
>> {
>> - static void *p;
>> + void *p;
>>
>> p = disk_seqf_start(seqf, pos);
>> if (!IS_ERR_OR_NULL(p) && !*pos)
>
> Huh, that looks like a clear bug. I've applied it, thanks.
It also looks like a -stable material, don't you think?
Thanks,
/mjt
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [PATCH] block: Don't use static to define "void *p" in show_partition_start().
2012-08-12 15:45 ` Michael Tokarev
@ 2012-08-13 0:38 ` Jianpeng Ma
0 siblings, 0 replies; 4+ messages in thread
From: Jianpeng Ma @ 2012-08-13 0:38 UTC (permalink / raw)
To: Michael Tokarev, axboe; +Cc: linux-kernel
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb2312", Size: 955 bytes --]
On 2012-08-12 23:45 Michael Tokarev <mjt@tls.msk.ru> Wrote:
>On 03.08.2012 12:41, Jens Axboe wrote:
>> On 08/03/2012 07:07 AM, majianpeng wrote:
>[]
>>> diff --git a/block/genhd.c b/block/genhd.c
>>> index cac7366..d839723 100644
>>> --- a/block/genhd.c
>>> +++ b/block/genhd.c
>>> @@ -835,7 +835,7 @@ static void disk_seqf_stop(struct seq_file *seqf, void *v)
>>>
>>> static void *show_partition_start(struct seq_file *seqf, loff_t *pos)
>>> {
>>> - static void *p;
>>> + void *p;
>>>
>>> p = disk_seqf_start(seqf, pos);
>>> if (!IS_ERR_OR_NULL(p) && !*pos)
>>
>> Huh, that looks like a clear bug. I've applied it, thanks.
>
>It also looks like a -stable material, don't you think?
>
>Thanks,
>
>/mjt
>
Yes, all kernel before this patach had this problem and should apply this patch.ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-08-13 0:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-03 5:07 [PATCH] block: Don't use static to define "void *p" in show_partition_start() majianpeng
2012-08-03 8:41 ` Jens Axboe
2012-08-12 15:45 ` Michael Tokarev
2012-08-13 0:38 ` Jianpeng Ma
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).