public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* f_op->read seems to be always NULL since Linux 4.1
@ 2015-06-27 17:32 Andreas Hartmann
  2015-06-27 18:10 ` Richard Weinberger
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Hartmann @ 2015-06-27 17:32 UTC (permalink / raw)
  To: linux-kernel

Hello!

Given is a module like the following snippet running fine w/ Linux 4.0
and ext4 fs - but doesn't work w/ Linux 4.1 because f->f_op->read is not
defined any more (= NULL). Is this the intended behavior now?

vfs_read(f, buf, 128, &f->f_pos) works fine.


module.c
--------------------------------------------------------------------
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <asm/uaccess.h>

int init_module(void)
{
    struct file *f;
    char buf[128];
    mm_segment_t fs;
    int i;
    int len=128;

    for(i=0;i<len;i++)
        buf[i] = 0;

    printk(KERN_INFO "My module is loaded\n");

    f = filp_open("/etc/fedora-release", O_RDONLY, 0);
    if(f == NULL)
        printk(KERN_ALERT "filp_open error!!.\n");
    else{
        fs = get_fs();
        set_fs(get_ds());

        if (f->f_op->read) {
            f->f_op->read(f, buf, len, &f->f_pos);
            printk(KERN_INFO "buf:%s\n",buf);
            }
        else {
            printk(KERN_INFO "No read method\n");
            }

        set_fs(fs);

    }
    filp_close(f,NULL);
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "My module is unloaded\n");
}
-----------------------------------------------------------

Makefile:
-----------------------------------------------------------
obj-m += module.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
------------------------------------------------------------



Regards,
Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: f_op->read seems to be always NULL since Linux 4.1
  2015-06-27 17:32 f_op->read seems to be always NULL since Linux 4.1 Andreas Hartmann
@ 2015-06-27 18:10 ` Richard Weinberger
  2015-06-28  6:36   ` Andreas Hartmann
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Weinberger @ 2015-06-27 18:10 UTC (permalink / raw)
  To: Andreas Hartmann; +Cc: LKML

On Sat, Jun 27, 2015 at 7:32 PM, Andreas Hartmann
<andihartmann@01019freenet.de> wrote:
> Hello!
>
> Given is a module like the following snippet running fine w/ Linux 4.0
> and ext4 fs - but doesn't work w/ Linux 4.1 because f->f_op->read is not
> defined any more (= NULL). Is this the intended behavior now?

See __vfs_read().
Your module most not rely on such internals.

-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: f_op->read seems to be always NULL since Linux 4.1
  2015-06-27 18:10 ` Richard Weinberger
@ 2015-06-28  6:36   ` Andreas Hartmann
  2015-06-28  7:38     ` Richard Weinberger
  2015-06-28  8:30     ` Al Viro
  0 siblings, 2 replies; 5+ messages in thread
From: Andreas Hartmann @ 2015-06-28  6:36 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: LKML

On Sat, Jun 27, 2015 at 8:10 PM, Richard Weinberger wrote:
> On Sat, Jun 27, 2015 at 7:32 PM, Andreas Hartmann
> <andihartmann@01019freenet.de> wrote:
[...]
> See __vfs_read().
> Your module most not rely on such internals.

Thanks for your hint to the function which exists since 3.19.

Is there a site out there which lists all relevant changes done for each 
kernel version and the recommendations how to correctly handle them?


Kind regards,
Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: f_op->read seems to be always NULL since Linux 4.1
  2015-06-28  6:36   ` Andreas Hartmann
@ 2015-06-28  7:38     ` Richard Weinberger
  2015-06-28  8:30     ` Al Viro
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Weinberger @ 2015-06-28  7:38 UTC (permalink / raw)
  To: Andreas Hartmann; +Cc: LKML

Am 28.06.2015 um 08:36 schrieb Andreas Hartmann:
> On Sat, Jun 27, 2015 at 8:10 PM, Richard Weinberger wrote:
>> On Sat, Jun 27, 2015 at 7:32 PM, Andreas Hartmann
>> <andihartmann@01019freenet.de> wrote:
> [...]
>> See __vfs_read().
>> Your module most not rely on such internals.
> 
> Thanks for your hint to the function which exists since 3.19.
> 
> Is there a site out there which lists all relevant changes done for each kernel version and the recommendations how to correctly handle them?

There is no such site.
The only way do deal with the ever changing in-kernel ABI is
bringing your code mainline.

Thanks,
//richard

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: f_op->read seems to be always NULL since Linux 4.1
  2015-06-28  6:36   ` Andreas Hartmann
  2015-06-28  7:38     ` Richard Weinberger
@ 2015-06-28  8:30     ` Al Viro
  1 sibling, 0 replies; 5+ messages in thread
From: Al Viro @ 2015-06-28  8:30 UTC (permalink / raw)
  To: Andreas Hartmann; +Cc: Richard Weinberger, LKML

On Sun, Jun 28, 2015 at 08:36:18AM +0200, Andreas Hartmann wrote:
> On Sat, Jun 27, 2015 at 8:10 PM, Richard Weinberger wrote:
> >On Sat, Jun 27, 2015 at 7:32 PM, Andreas Hartmann
> ><andihartmann@01019freenet.de> wrote:
> [...]
> >See __vfs_read().
> >Your module most not rely on such internals.
> 
> Thanks for your hint to the function which exists since 3.19.
> 
> Is there a site out there which lists all relevant changes done for
> each kernel version and the recommendations how to correctly handle
> them?

localhost.  It's in Documentation/filesystems/porting in the kernel
source.  To quote the relevant entry (not far from the end - they
are in chronological order):

[mandatory]
        never call ->read() and ->write() directly; use __vfs_{read,write} or
        wrappers; instead of checking for ->write or ->read being NULL, look for
        FMODE_CAN_{WRITE,READ} in file->f_mode.

Sometimes TFM to R _is_ in the natural place...

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-28  8:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-27 17:32 f_op->read seems to be always NULL since Linux 4.1 Andreas Hartmann
2015-06-27 18:10 ` Richard Weinberger
2015-06-28  6:36   ` Andreas Hartmann
2015-06-28  7:38     ` Richard Weinberger
2015-06-28  8:30     ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox