Re: [PATCH] procfs: fix numbering in /proc/locks

From: Jerome Marchand
Date: Wed Sep 29 2010 - 07:42:40 EST


On 09/27/2010 05:24 PM, Pavel Emelyanov wrote:
> On 09/27/2010 07:13 PM, Jerome Marchand wrote:
>>
>> The lock number in /proc/locks (first field) is implemented by a counter
>> (private field of struct seq_file) which is incremented at each call of
>> locks_show(). Currently it is reset each time locks_start() is called,
>> that is each time we call the read() syscall on /proc/locks. Because of
>> that, the numbering erratically restarts at 1 several times when reading
>> a long /proc/locks file.
>> We want the counter to be initialized at opening time and then never
>> reset until we close the file. Fortunately, seq_open() memzeros the
>> seq_file structure, so we can just drop the reset in locks_start() and
>> move the increment the counter before actually printing the line so the
>> numbering still starts at 1.
>
> IMHO the implementation is wrong. If you want the proper sequence number
> while file is open you should increase on in the ->next callback of the
> seq_ops, not in show.

Good point. My implementation is definitely wrong. But I'm afraid that
moving the increment in locks_next() won't help either. It will fail when
a program do something more than just read the file sequentially (use
of lseek() for instance). We need a better way to keep track of the
current position in the list.

Thanks,
Jerome

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/