Bug 11856 - seq_file does not handle pread()
Summary: seq_file does not handle pread()
Status: CLOSED CODE_FIX
Alias: None
Product: File System
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Alexey Dobriyan
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-25 17:40 UTC by Petr Vandrovec
Modified: 2012-04-04 15:04 UTC (History)
4 users (show)

See Also:
Kernel Version: 2.6.28-rc1
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Petr Vandrovec 2008-10-25 17:40:54 UTC
Latest working kernel version: 2.6.27
Earliest failing kernel version: commit 9617760287eec9091d26e6967bd3e4194de18f97
Distribution: Debian
Hardware Environment: 
Software Environment:
Problem Description:

pread() does not work on seq_file.  That makes some VMware utilities unhappy, as to save some opens & closes these apps open /proc/uptime on start, and keep it open until exit.  And because they are multithreaded, they are using pread()...  And it works until seq_file conversion, but not after.

Steps to reproduce:

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>

void main(void) {
  int fd = open("/proc/uptime", O_RDONLY);
  while (1) {
    char buffer[1234];
    int err = pread(fd, buffer, sizeof buffer - 1, 0);
    if (err == -1) {
      perror("Oops: %m\n");
    } else {
      buffer[err] = 0;
      printf("Another second, uptime info is %s\n", err);
    }
    sleep(1);
  }
}
Comment 1 Alexey Dobriyan 2008-10-25 18:15:59 UTC
BTW, does anything but 0 offset is used?
Comment 2 Alexey Dobriyan 2008-10-25 19:37:56 UTC
crap, ->read hook has absolutely no way of telling read from pread
Comment 3 Petr Vandrovec 2008-10-25 20:20:22 UTC
No, in real app it is used with offset 0 only.  

I've looked at code, and it looks to me like that modifying seq_file itself to handle pread is not that hard if you are OK with saying that if you mix read() and pread() you are on your own.  That's why I did not assign it to you...
Comment 4 Petr Vandrovec 2008-11-02 14:22:03 UTC
Well, /proc/uptime issue is fixed by moving /proc/uptime away from seq_file, so it is not regression anymore, but it does not fix what subject of this bug says - that seq_file does not handle pread, so issue may resurface at any time when some other file gets converted to seq_file...
Comment 5 Alexey Dobriyan 2009-02-19 12:31:38 UTC
commit 8f19d472935c83d823fa4cf02bcc0a7b9952db30
"seq_file: properly cope with pread" and previous patches.
Comment 6 earl_chew 2012-01-19 03:28:09 UTC
(In reply to comment #4)
> Well, /proc/uptime issue is fixed by moving /proc/uptime away from seq_file,
> so
> it is not regression anymore, but it does not fix what subject of this bug
> says
> - that seq_file does not handle pread, so issue may resurface at any time
> when
> some other file gets converted to seq_file...

https://lkml.org/lkml/2012/1/18/21
Comment 7 Florian Mickler 2012-04-04 15:04:55 UTC
A patch referencing this bug report has been merged in Linux v3.4-rc1:

commit 7904ac84244b59f536c2a5d1066a10f46df07b08
Author: Earl Chew <echew@ixiacom.com>
Date:   Wed Mar 21 16:33:43 2012 -0700

    seq_file: fix mishandling of consecutive pread() invocations.

Note You need to log in before you can comment on or make changes to this bug.