/proc does not accept new default_fops?

From: Ingo Oeser (ingo.oeser@informatik.tu-chemnitz.de)
Date: Mon Feb 28 2000 - 18:00:16 EST


Hi there,

procfs doesn't seem to allow later modifications of the
default_fops.

Kernel is 2.2.13aa6 (thats why you are CC'd Andrea ;)).

Problematic code follows

<source>
#define DSP_DIR "dsp"
#define DSP_CHIP_CLASSES "dsp/chip_classes"
#define DSP_CHIPS "dsp/chips"
#define DSP_CHIP_IO "io" /* For real device activity */

/* Permissions */
#define dspacc (S_IRUSR | S_IRGRP)
#define dspdir (S_IFDIR | S_IXUSR | S_IXGRP | dspacc)
#define dspfile (S_IWUSR | S_IWGRP | dspacc)
#define dspinfo dspacc
#define dspowner 0
extern unsigned int dspgrp;

struct dsp_proc_dir_entry {
        struct proc_dir_entry *dotfile;
        struct proc_dir_entry *io;
        struct proc_dir_entry *info;
};

/* DSP class data */
struct dsp_chip_class_struct {
        char *name;
#ifdef CONFIG_PROC_FS
        struct proc_dir_entry *info;
        /* Tool to increase module usage count */
        void (*fill_inode)(struct inode *, int);
#endif /* CONFIG_PROC_FS */
};

struct dsp_chip_struct {
        struct dsp_chip_class_struct *class;
#ifdef CONFIG_PROC_FS
        struct dsp_proc_dir_entry info;
#endif /* CONFIG_PROC_FS */
};

struct file_operations = dsp_chip_io_fops
{
        .ioctl = dsp_ioctl,
#ifdef CONFIG_PROC_FS
        .open = dsp_open_procfs,
#else /* CONFIG_PROC_FS */
        .open = dsp_open_dummy,
#endif /* CONFIG_PROC_FS */
        .release = dsp_release,
        .read = dsp_read,
        .write = dsp_write,
};

static struct proc_dir_entry *new_proc_entry(const char *name, mode_t mode,
                                             struct proc_dir_entry *parent,
                                             struct file_operations *fops)
{
        struct proc_dir_entry *ent;

        /* get translated name, if empty parent */
        ent=create_proc_entry(name,mode,parent);
        if (ent) {
      /* This seems to be ignored :( */
                if (fops) ent->ops->default_file_ops=fops;
                else DEBUG_MSG("No ops for %s\n",name);
                DEBUG_MSG("Created procfs-entry %s\n",ent->name);
        };
        return ent;
}

int register_dsp_class_proc(struct dsp_chip_class_struct *class) {
        int res=-EINVAL;

        if (!class) goto out;
        
        res=-ENOMEM;
        class->info=new_proc_entry(class->name,dspfile,chip_classes,NULL);
        if (!(class->info)) {
                DEBUG_MSG("Cannot register class info\n");
                goto out;
        };
        
        class->info->data=class;
        class->info->fill_inode=class->fill_inode;
   /* Problem below: new read_proc is never beeing called :( */
        class->info->read_proc=show_class_info;
                
        res=0;
out:
        DEBUG_MSG("out with res=%i\n",res);
        return res;
};

int register_dsp_proc(struct dsp_chip_struct *chip)
{
        int res=-EINVAL;
        char name[DSP_ENUM_STR_SIZE+1]="";
        
        if (!chip) goto out;
        
        res=-ENOMEM;
        spin_lock(&dspcount_lock);
        if ((dspcount++) > DSP_ENUM_MAX) dspcount--;
        else sprintf(name,DSP_ENUM_STR,dspcount);
        spin_unlock(&dspcount_lock);
        
#define ADD_PROC(f,n,acc,p,ops,fill) \
        f=new_proc_entry(n,acc,p,ops); \
        if (!(f)) { \
                DEBUG_MSG("Failed to register proc entry %s\n",n); \
                goto out_free; \
        }; \
        f->data=chip; \
        f->uid=dspowner; \
        f->gid=dspgrp; \
        f->fill_inode=fill

        ADD_PROC(chip->info.dotfile,name,dspdir,chips,NULL,NULL);
        ADD_PROC(chip->info.io,DSP_CHIP_IO,dspfile,chip->info.dotfile,
                        &dsp_chip_io_fops,chip->class->fill_inode);
#undef ADD_PROC(f,n,acc,p,ops,fill)

        res=0;
out:
        DEBUG_MSG("out with res=%i\n",res);
        return res;
out_free:
/* Failure path */
#define DEL_PROC(f,p) \
        if (f) destroy_proc_entry(p,&f)

        DEL_PROC(chip->info.io,chip->info.dotfile);
        DEL_PROC(chip->info.dotfile,chips);

        DEBUG_MSG("out with res=%i\n",res);
        return res;
#undef DEL_PROC(f,p)
};
</source>

The Problem is "register_dsp_proc", where I register a
procfs-entry which is saved as "chip->info.io" and has its new
file_operations assigend later. But they are _never_ called, if I
open/read/write from this procfs-entry, it seems, that no
operations are registered.

Same goes for show_class_info, which is also never called.

What is the problem? I debugged this since several days (as you
can see from DEBUG_MSG(), which result in simple pr_debug and,
yes code is compiled with "-DDEBUG" !

I even looked at the assembly output, for both: caller (the
sample code) and callee (linux/fs/proc/generic.s).

Any ideas? I have no more :(

Thanks in advance

Regards

Ingo Oeser

-- 
Feel the power of the penguin - run linux@your.pc
<esc>:x

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



This archive was generated by hypermail 2b29 : Tue Feb 29 2000 - 21:00:21 EST